Bug fix - Framerate-independent Damage and Bonus shifts
Posted: Wed Jun 06, 2012 12:11 am
When damage and bonus shifts drop their percentages each frame the timing can be all wrong because the percent member is an int - no matter what speed you're running at you'll get something incorrect for the drop rate owing to rounding-off.
Add these two to the cshift_t struct:
In V_ParseDamage, pop this somewhere near the bottom:
And this in V_BonusFlash_f:
Add this somewhere above your V_UpdatePalette:
And replace the old drop-off code for these two shifts with this:
They'll now drop at the correct rate no matter what speed you're running at.
You can also do the same with dynamic lights - store spawntime as cl.time in CL_AllocDlight, set initialradius to the same as radius for each light, then radius in CL_DecayLights becomes "dl->radius = dl->initialradius - (cl.time - dl->spawntime) * dl->decay;"
Add these two to the cshift_t struct:
Code: Select all
double time;
int initialpct;
Code: Select all
cl.cshifts[CSHIFT_DAMAGE].initialpct = cl.cshifts[CSHIFT_DAMAGE].percent;
cl.cshifts[CSHIFT_DAMAGE].time = cl.time;
Code: Select all
cl.cshifts[CSHIFT_BONUS].initialpct = 50;
cl.cshifts[CSHIFT_BONUS].time = cl.time;
Code: Select all
void V_DropCShift (cshift_t *cs, float droprate)
{
if (cs->time < 0)
cs->percent = 0;
else if ((cs->percent = cs->initialpct - (cl.time - cs->time) * droprate) <= 0)
{
cs->percent = 0;
cs->time = -1;
}
}
Code: Select all
// drop the damage and bonus values
V_DropCShift (&cl.cshifts[CSHIFT_DAMAGE], 150);
V_DropCShift (&cl.cshifts[CSHIFT_BONUS], 100);
You can also do the same with dynamic lights - store spawntime as cl.time in CL_AllocDlight, set initialradius to the same as radius for each light, then radius in CL_DecayLights becomes "dl->radius = dl->initialradius - (cl.time - dl->spawntime) * dl->decay;"