mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-10 18:34:21 +02:00
Fix gravity sometimes persisting a frame after ctrl+z / clearing sim, fixes #571
This commit is contained in:
@@ -31,6 +31,7 @@ void Gravity::bilinear_interpolation(float *src, float *dst, int sw, int sh, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ignoreNextResult = false;
|
||||||
void Gravity::Clear()
|
void Gravity::Clear()
|
||||||
{
|
{
|
||||||
std::fill(gravy, gravy+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
std::fill(gravy, gravy+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||||
@@ -38,6 +39,8 @@ void Gravity::Clear()
|
|||||||
std::fill(gravp, gravp+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
std::fill(gravp, gravp+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||||
std::fill(gravmap, gravmap+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
std::fill(gravmap, gravmap+((XRES/CELL)*(YRES/CELL)), 0.0f);
|
||||||
std::fill(gravmask, gravmask+((XRES/CELL)*(YRES/CELL)), 0xFFFFFFFF);
|
std::fill(gravmask, gravmask+((XRES/CELL)*(YRES/CELL)), 0xFFFFFFFF);
|
||||||
|
|
||||||
|
ignoreNextResult = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gravity::gravity_init()
|
void Gravity::gravity_init()
|
||||||
@@ -90,7 +93,7 @@ void Gravity::gravity_update_async()
|
|||||||
//Switch the full size gravmaps, we don't really need the two above any more
|
//Switch the full size gravmaps, we don't really need the two above any more
|
||||||
float *tmpf;
|
float *tmpf;
|
||||||
|
|
||||||
if(th_gravchanged)
|
if (th_gravchanged && !ignoreNextResult)
|
||||||
{
|
{
|
||||||
#if !defined(GRAVFFT) && defined(GRAV_DIFF)
|
#if !defined(GRAVFFT) && defined(GRAV_DIFF)
|
||||||
memcpy(gravy, th_gravy, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
memcpy(gravy, th_gravy, (XRES/CELL)*(YRES/CELL)*sizeof(float));
|
||||||
@@ -110,6 +113,7 @@ void Gravity::gravity_update_async()
|
|||||||
th_gravp = tmpf;
|
th_gravp = tmpf;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
ignoreNextResult = false;
|
||||||
|
|
||||||
tmpf = gravmap;
|
tmpf = gravmap;
|
||||||
gravmap = th_gravmap;
|
gravmap = th_gravmap;
|
||||||
|
@@ -517,6 +517,7 @@ void Simulation::Restore(const Snapshot & snap)
|
|||||||
std::copy(snap.WirelessData.begin(), snap.WirelessData.end(), &wireless[0][0]);
|
std::copy(snap.WirelessData.begin(), snap.WirelessData.end(), &wireless[0][0]);
|
||||||
if (grav->ngrav_enable)
|
if (grav->ngrav_enable)
|
||||||
{
|
{
|
||||||
|
grav->Clear();
|
||||||
std::copy(snap.GravVelocityX.begin(), snap.GravVelocityX.end(), gravx);
|
std::copy(snap.GravVelocityX.begin(), snap.GravVelocityX.end(), gravx);
|
||||||
std::copy(snap.GravVelocityY.begin(), snap.GravVelocityY.end(), gravy);
|
std::copy(snap.GravVelocityY.begin(), snap.GravVelocityY.end(), gravy);
|
||||||
std::copy(snap.GravValue.begin(), snap.GravValue.end(), gravp);
|
std::copy(snap.GravValue.begin(), snap.GravValue.end(), gravp);
|
||||||
|
Reference in New Issue
Block a user