No more red DEUT

Prevent some integer overflows in DEUT graphics and interactions.
This commit is contained in:
jacksonmj
2013-11-07 21:36:36 +00:00
parent 75b7b85703
commit 186f8a1742
2 changed files with 13 additions and 7 deletions

View File

@@ -68,7 +68,9 @@ int Element_DEUT::update(UPDATE_FUNC_ARGS)
continue; continue;
if ((r&0xFF)==PT_DEUT&& !(rand()%3)) if ((r&0xFF)==PT_DEUT&& !(rand()%3))
{ {
if ((parts[i].life + parts[r>>8].life + 1) <= maxlife) // If neighbour life+1 fits in the free capacity for this particle, absorb neighbour
// Condition is written in this way so that large neighbour life values don't cause integer overflow
if (parts[r>>8].life <= maxlife - parts[i].life - 1)
{ {
parts[i].life += parts[r>>8].life + 1; parts[i].life += parts[r>>8].life + 1;
sim->kill_part(r>>8); sim->kill_part(r>>8);
@@ -130,18 +132,22 @@ int Element_DEUT::graphics(GRAPHICS_FUNC_ARGS)
if(cpart->life>=700) if(cpart->life>=700)
{ {
*firea = 60; *firea = 60;
*firer = *colr += cpart->life*1; *firer = *colr += 255;
*fireg = *colg += cpart->life*2; *fireg = *colg += 255;
*fireb = *colb += cpart->life*3; *fireb = *colb += 255;
*pixel_mode |= PMODE_GLOW | FIRE_ADD; *pixel_mode |= PMODE_GLOW | FIRE_ADD;
} }
else else if(cpart->life>0)
{ {
*colr += cpart->life*1; *colr += cpart->life*1;
*colg += cpart->life*2; *colg += cpart->life*2;
*colb += cpart->life*3; *colb += cpart->life*3;
*pixel_mode |= PMODE_BLUR; *pixel_mode |= PMODE_BLUR;
} }
else
{
*pixel_mode |= PMODE_BLUR;
}
return 0; return 0;
} }

View File

@@ -92,7 +92,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
case PT_DEUT: case PT_DEUT:
if ((pressureFactor+1+(parts[r>>8].life/100))>(rand()%1000)) if ((pressureFactor+1+(parts[r>>8].life/100))>(rand()%1000))
{ {
DeutExplosion(sim, parts[r>>8].life, x+rx, y+ry, restrict_flt(parts[r>>8].temp + parts[r>>8].life*500, MIN_TEMP, MAX_TEMP), PT_NEUT); DeutExplosion(sim, parts[r>>8].life, x+rx, y+ry, restrict_flt(parts[r>>8].temp + parts[r>>8].life*500.0f, MIN_TEMP, MAX_TEMP), PT_NEUT);
sim->kill_part(r>>8); sim->kill_part(r>>8);
} }
break; break;
@@ -104,7 +104,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx; parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx;
parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy; parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy;
parts[r>>8].life --; parts[r>>8].life --;
parts[r>>8].temp = restrict_flt(parts[r>>8].temp + parts[r>>8].life*17, MIN_TEMP, MAX_TEMP); parts[r>>8].temp = restrict_flt(parts[r>>8].temp + parts[r>>8].life*17.0f, MIN_TEMP, MAX_TEMP);
pv[y/CELL][x/CELL] += 6.0f * CFDS; pv[y/CELL][x/CELL] += 6.0f * CFDS;
} }