Skip to content
Permalink
Browse files

Dig particles: Various improvements (#7714)

Improve codestyle.
Add clarifying comments.
Use 'movement_gravity' setting and physics override instead of hardcoded value.
Halve number of particles in final 'node dug' burst.
Avoid extremely small, near-invisible particles.
Increase velocity to increase number emerging from within a cubic node.
  • Loading branch information...
paramat committed Oct 4, 2018
1 parent 84a5fa0 commit 1413b722a72d475e8f6cc6febbb5479504b90c04
Showing with 25 additions and 15 deletions.
  1. +25 −15 src/particles.cpp
@@ -584,19 +584,24 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
}
}

// The final burst of particles when a node is finally dug, *not* particles
// spawned during the digging of a node.

void ParticleManager::addDiggingParticles(IGameDef* gamedef,
LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
{
// No particles for "airlike" nodes
if (f.drawtype == NDT_AIRLIKE)
return;

// set the amount of particles here
for (u16 j = 0; j < 32; j++) {
for (u16 j = 0; j < 16; j++) {
addNodeParticle(gamedef, player, pos, n, f);
}
}

// During the digging of a node particles are spawned individually by this
// function, called from Game::handleDigging() in game.cpp.

void ParticleManager::addNodeParticle(IGameDef* gamedef,
LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
{
@@ -617,25 +622,30 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef,
else
texture = tile.texture;

float size = rand() % 64 / 512.;
float size = (rand() % 8) / 64.0f;
float visual_size = BS * size;
if (tile.scale)
size /= tile.scale;
v2f texsize(size * 2, size * 2);
v2f texsize(size * 2.0f, size * 2.0f);
v2f texpos;
texpos.X = ((rand() % 64) / 64. - texsize.X);
texpos.Y = ((rand() % 64) / 64. - texsize.Y);
texpos.X = (rand() % 64) / 64.0f - texsize.X;
texpos.Y = (rand() % 64) / 64.0f - texsize.Y;

// Physics
v3f velocity((rand() % 100 / 50. - 1) / 1.5,
rand() % 100 / 35.,
(rand() % 100 / 50. - 1) / 1.5);

v3f acceleration(0,-9,0);
v3f velocity(
(rand() % 150) / 50.0f - 1.5f,
(rand() % 150) / 50.0f,
(rand() % 150) / 50.0f - 1.5f
);
v3f acceleration(
0.0f,
-player->movement_gravity * player->physics_override_gravity / BS,
0.0f
);
v3f particlepos = v3f(
(f32) pos.X + rand() %100 /200. - 0.25,
(f32) pos.Y + rand() %100 /200. - 0.25,
(f32) pos.Z + rand() %100 /200. - 0.25
(f32)pos.X + (rand() % 100) / 200.0f - 0.25f,
(f32)pos.Y + (rand() % 100) / 200.0f - 0.25f,
(f32)pos.Z + (rand() % 100) / 200.0f - 0.25f
);

video::SColor color;
@@ -651,7 +661,7 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef,
particlepos,
velocity,
acceleration,
rand() % 100 / 100., // expiration time
(rand() % 100) / 100.0f, // expiration time
visual_size,
true,
false,

0 comments on commit 1413b72

Please sign in to comment.
You can’t perform that action at this time.