No more red DEUT
Prevent some integer overflows in DEUT graphics and interactions.
This commit is contained in:
parent
75b7b85703
commit
186f8a1742
@ -68,7 +68,9 @@ int Element_DEUT::update(UPDATE_FUNC_ARGS)
|
||||
continue;
|
||||
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;
|
||||
sim->kill_part(r>>8);
|
||||
@ -130,18 +132,22 @@ int Element_DEUT::graphics(GRAPHICS_FUNC_ARGS)
|
||||
if(cpart->life>=700)
|
||||
{
|
||||
*firea = 60;
|
||||
*firer = *colr += cpart->life*1;
|
||||
*fireg = *colg += cpart->life*2;
|
||||
*fireb = *colb += cpart->life*3;
|
||||
*firer = *colr += 255;
|
||||
*fireg = *colg += 255;
|
||||
*fireb = *colb += 255;
|
||||
*pixel_mode |= PMODE_GLOW | FIRE_ADD;
|
||||
}
|
||||
else
|
||||
else if(cpart->life>0)
|
||||
{
|
||||
*colr += cpart->life*1;
|
||||
*colg += cpart->life*2;
|
||||
*colb += cpart->life*3;
|
||||
*pixel_mode |= PMODE_BLUR;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pixel_mode |= PMODE_BLUR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
|
||||
case PT_DEUT:
|
||||
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);
|
||||
}
|
||||
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].vy = 0.25f*parts[r>>8].vy + parts[i].vy;
|
||||
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;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user