Particle man removes more particles than expected
FreeSlave opened this issue · 2 comments
I've made a test branch master...FreeSlave:halflife-updated:particleman-test
It draws a particle in front of the player every 0.2 seconds, and each particle lives for 1 second, but it looks like after the one second not only the first spawned particle is getting deleted, but also all other particles. I suspect something wrong with deletion code.
Looks like the problem is in this line https://github.com/SamVanheer/halflife-updated/blob/603b2f7c1568c66208bb5e31bf6235556fbad1c8/cl_dll/particleman/CMiniMem.cpp#L45
It erases the range instead of the one element.
Looks like i wrote it like i was writing the erase-remove idiom. I'll make it remove only the particle being removed.
For future reference, test code to confirm this behavior:
gEngfuncs.pfnAddCommand("test_particles",
[]() {
auto player = gEngfuncs.GetLocalPlayer();
auto origin = player->origin;
Vector forward;
AngleVectors(player->angles, forward, nullptr, nullptr);
auto model = gEngfuncs.CL_LoadModel("sprites/blood.spr", nullptr);
for (int i = 0; i < 10; ++i)
{
auto particle = g_pParticleMan->CreateParticle(origin + forward * 64 + Vector(0, 0, 8 * i), g_vecZero, model, 32, 255, "test_particle");
particle->m_flDieTime = gEngfuncs.GetClientTime() + 5 * ((10 - i) + 1);
}
});
Added to Initialize
.