Fix pavg loading behaviour of QRTZ/GLAS/TUNG (fixes #607)
Those particles now save/load pavg if pressure is being saved/loaded. This means they won't ever break again when being loaded as part of a stamp. They actually save pavg01 * 64 because pavg is saved as an integer and these elements are too sensitive to pressure changes for integer pavg values to be adequate.
This commit is contained in:
parent
d22d22e662
commit
3de92f5ef4
@ -2254,14 +2254,37 @@ char * GameSave::serialiseOPS(unsigned int & dataLength)
|
||||
}
|
||||
|
||||
//Pavg, 4 bytes
|
||||
//Don't save pavg for things that break under pressure, because then they will break when the save is loaded, since pressure isn't also loaded
|
||||
if ((particles[i].pavg[0] || particles[i].pavg[1]) && !(particles[i].type == PT_QRTZ || particles[i].type == PT_GLAS || particles[i].type == PT_TUNG))
|
||||
// save pavg if there's useful pavg to save
|
||||
// and either we save pressure data too
|
||||
// or the current particle is not one that cares about pressure
|
||||
if (particles[i].pavg[0] || particles[i].pavg[1])
|
||||
{
|
||||
fieldDesc |= 1 << 13;
|
||||
partsData[partsDataLen++] = (int)particles[i].pavg[0];
|
||||
partsData[partsDataLen++] = ((int)particles[i].pavg[0])>>8;
|
||||
partsData[partsDataLen++] = (int)particles[i].pavg[1];
|
||||
partsData[partsDataLen++] = ((int)particles[i].pavg[1])>>8;
|
||||
float pavg0 = particles[i].pavg[0];
|
||||
float pavg1 = particles[i].pavg[1];
|
||||
switch (particles[i].type)
|
||||
{
|
||||
// List of elements that save pavg with a multiplicative bias of 2**6
|
||||
// (or not at all if pressure is not saved).
|
||||
// If you change this list, change it in Simulation::Load too!
|
||||
case PT_QRTZ:
|
||||
case PT_GLAS:
|
||||
case PT_TUNG:
|
||||
if (!hasPressure)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pavg0 *= 64;
|
||||
pavg1 *= 64;
|
||||
// fallthrough!
|
||||
|
||||
default:
|
||||
fieldDesc |= 1 << 13;
|
||||
partsData[partsDataLen++] = (int)pavg0;
|
||||
partsData[partsDataLen++] = ((int)pavg0)>>8;
|
||||
partsData[partsDataLen++] = (int)pavg1;
|
||||
partsData[partsDataLen++] = ((int)pavg1)>>8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Write the field descriptor
|
||||
|
@ -233,6 +233,24 @@ int Simulation::Load(int fullX, int fullY, GameSave * save, bool includePressure
|
||||
case PT_SOAP:
|
||||
soapList.insert(std::pair<unsigned int, unsigned int>(n, i));
|
||||
break;
|
||||
|
||||
// List of elements that load pavg with a multiplicative bias of 2**6
|
||||
// (or not at all if pressure is not loaded).
|
||||
// If you change this list, change it in GameSave::serialiseOPS too!
|
||||
case PT_QRTZ:
|
||||
case PT_GLAS:
|
||||
case PT_TUNG:
|
||||
if (!includePressure)
|
||||
{
|
||||
parts[i].pavg[0] = 0;
|
||||
parts[i].pavg[1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
parts[i].pavg[0] /= 64;
|
||||
parts[i].pavg[1] /= 64;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
parts_lastActiveIndex = NPART-1;
|
||||
@ -437,11 +455,14 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2, bool i
|
||||
newSave->velocityX[saveBlockY][saveBlockX] = vx[saveBlockY+blockY][saveBlockX+blockX];
|
||||
newSave->velocityY[saveBlockY][saveBlockX] = vy[saveBlockY+blockY][saveBlockX+blockX];
|
||||
newSave->ambientHeat[saveBlockY][saveBlockX] = hv[saveBlockY+blockY][saveBlockX+blockX];
|
||||
newSave->hasPressure = true;
|
||||
newSave->hasAmbientHeat = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (includePressure)
|
||||
{
|
||||
newSave->hasPressure = true;
|
||||
newSave->hasAmbientHeat = true;
|
||||
}
|
||||
|
||||
newSave->stkm.rocketBoots1 = player.rocketBoots;
|
||||
newSave->stkm.rocketBoots2 = player2.rocketBoots;
|
||||
|
Reference in New Issue
Block a user