summaryrefslogtreecommitdiff
path: root/src/particles.cpp
diff options
context:
space:
mode:
authorDániel Juhász <juhdanad@gmail.com>2017-01-12 15:46:30 +0100
committerEkdohibs <nathanael.courant@laposte.net>2017-01-23 07:27:12 +0100
commitd04d8aba7029a2501854a2838fd282b81358a54e (patch)
treefd1a5515e17b2dd2da0a8ffe7f82f445e7fb48de /src/particles.cpp
parent43822de5c6b35646feced5ac65331313f82f78ce (diff)
downloadminetest-d04d8aba7029a2501854a2838fd282b81358a54e.tar.gz
minetest-d04d8aba7029a2501854a2838fd282b81358a54e.tar.bz2
minetest-d04d8aba7029a2501854a2838fd282b81358a54e.zip
Add hardware node coloring. Includes:
- Increase ContentFeatures serialization version - Color property and palettes for nodes - paramtype2 = "color", "colored facedir" or "colored wallmounted"
Diffstat (limited to 'src/particles.cpp')
-rw-r--r--src/particles.cpp65
1 files changed, 42 insertions, 23 deletions
diff --git a/src/particles.cpp b/src/particles.cpp
index 5f17763e0..e1f292fb6 100644
--- a/src/particles.cpp
+++ b/src/particles.cpp
@@ -56,7 +56,8 @@ Particle::Particle(
v2f texpos,
v2f texsize,
const struct TileAnimationParams &anim,
- u8 glow
+ u8 glow,
+ video::SColor color
):
scene::ISceneNode(smgr->getRootSceneNode(), smgr)
{
@@ -77,6 +78,10 @@ Particle::Particle(
m_animation_frame = 0;
m_animation_time = 0.0;
+ // Color
+ m_base_color = color;
+ m_color = color;
+
// Particle related
m_pos = pos;
m_velocity = velocity;
@@ -183,12 +188,15 @@ void Particle::updateLight()
else
light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);
- m_light = decode_light(light + m_glow);
+ u8 m_light = decode_light(light + m_glow);
+ m_color.set(255,
+ m_light * m_base_color.getRed() / 255,
+ m_light * m_base_color.getGreen() / 255,
+ m_light * m_base_color.getBlue() / 255);
}
void Particle::updateVertices()
{
- video::SColor c(255, m_light, m_light, m_light);
f32 tx0, tx1, ty0, ty1;
if (m_animation.type != TAT_NONE) {
@@ -210,14 +218,14 @@ void Particle::updateVertices()
ty1 = m_texpos.Y + m_texsize.Y;
}
- m_vertices[0] = video::S3DVertex(-m_size/2,-m_size/2,0, 0,0,0,
- c, tx0, ty1);
- m_vertices[1] = video::S3DVertex(m_size/2,-m_size/2,0, 0,0,0,
- c, tx1, ty1);
- m_vertices[2] = video::S3DVertex(m_size/2,m_size/2,0, 0,0,0,
- c, tx1, ty0);
- m_vertices[3] = video::S3DVertex(-m_size/2,m_size/2,0, 0,0,0,
- c, tx0, ty0);
+ m_vertices[0] = video::S3DVertex(-m_size / 2, -m_size / 2,
+ 0, 0, 0, 0, m_color, tx0, ty1);
+ m_vertices[1] = video::S3DVertex(m_size / 2, -m_size / 2,
+ 0, 0, 0, 0, m_color, tx1, ty1);
+ m_vertices[2] = video::S3DVertex(m_size / 2, m_size / 2,
+ 0, 0, 0, 0, m_color, tx1, ty0);
+ m_vertices[3] = video::S3DVertex(-m_size / 2, m_size / 2,
+ 0, 0, 0, 0, m_color, tx0, ty0);
v3s16 camera_offset = m_env->getCameraOffset();
for(u16 i=0; i<4; i++)
@@ -589,35 +597,39 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
}
}
-void ParticleManager::addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
- LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+void ParticleManager::addDiggingParticles(IGameDef* gamedef,
+ scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
+ const MapNode &n, const ContentFeatures &f)
{
for (u16 j = 0; j < 32; j++) // set the amount of particles here
{
- addNodeParticle(gamedef, smgr, player, pos, tiles);
+ addNodeParticle(gamedef, smgr, player, pos, n, f);
}
}
-void ParticleManager::addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
- LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+void ParticleManager::addPunchingParticles(IGameDef* gamedef,
+ scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
+ const MapNode &n, const ContentFeatures &f)
{
- addNodeParticle(gamedef, smgr, player, pos, tiles);
+ addNodeParticle(gamedef, smgr, player, pos, n, f);
}
-void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
- LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+void ParticleManager::addNodeParticle(IGameDef* gamedef,
+ scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
+ const MapNode &n, const ContentFeatures &f)
{
// Texture
u8 texid = myrand_range(0, 5);
+ const TileSpec &tile = f.tiles[texid];
video::ITexture *texture;
struct TileAnimationParams anim;
anim.type = TAT_NONE;
// Only use first frame of animated texture
- if (tiles[texid].material_flags & MATERIAL_FLAG_ANIMATION)
- texture = tiles[texid].frames[0].texture;
+ if (tile.material_flags & MATERIAL_FLAG_ANIMATION)
+ texture = tile.frames[0].texture;
else
- texture = tiles[texid].texture;
+ texture = tile.texture;
float size = rand() % 64 / 512.;
float visual_size = BS * size;
@@ -638,6 +650,12 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* s
(f32) pos.Z + rand() %100 /200. - 0.25
);
+ video::SColor color;
+ if (tile.has_color)
+ color = tile.color;
+ else
+ n.getColor(f, &color);
+
Particle* toadd = new Particle(
gamedef,
smgr,
@@ -655,7 +673,8 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* s
texpos,
texsize,
anim,
- 0);
+ 0,
+ color);
addParticle(toadd);
}