Skip to content

Commit

Permalink
Fix gravity sometimes persisting a frame after ctrl+z / clearing sim, f…
Browse files Browse the repository at this point in the history
…ixes #571
  • Loading branch information
jacob1 committed Jan 15, 2019
1 parent 50a88c9 commit e8b4256
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/simulation/Gravity.cpp
Expand Up @@ -31,13 +31,16 @@ void Gravity::bilinear_interpolation(float *src, float *dst, int sw, int sh, int
}
}

bool ignoreNextResult = false;
void Gravity::Clear()
{
std::fill(gravy, gravy+((XRES/CELL)*(YRES/CELL)), 0.0f);
std::fill(gravx, gravx+((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(gravmask, gravmask+((XRES/CELL)*(YRES/CELL)), 0xFFFFFFFF);

ignoreNextResult = true;
}

void Gravity::gravity_init()
Expand Down Expand Up @@ -90,7 +93,7 @@ void Gravity::gravity_update_async()
//Switch the full size gravmaps, we don't really need the two above any more
float *tmpf;

if(th_gravchanged)
if (th_gravchanged && !ignoreNextResult)
{
#if !defined(GRAVFFT) && defined(GRAV_DIFF)
memcpy(gravy, th_gravy, (XRES/CELL)*(YRES/CELL)*sizeof(float));
Expand All @@ -110,6 +113,7 @@ void Gravity::gravity_update_async()
th_gravp = tmpf;
#endif
}
ignoreNextResult = false;

tmpf = gravmap;
gravmap = th_gravmap;
Expand Down
1 change: 1 addition & 0 deletions src/simulation/Simulation.cpp
Expand Up @@ -517,6 +517,7 @@ void Simulation::Restore(const Snapshot & snap)
std::copy(snap.WirelessData.begin(), snap.WirelessData.end(), &wireless[0][0]);
if (grav->ngrav_enable)
{
grav->Clear();
std::copy(snap.GravVelocityX.begin(), snap.GravVelocityX.end(), gravx);
std::copy(snap.GravVelocityY.begin(), snap.GravVelocityY.end(), gravy);
std::copy(snap.GravValue.begin(), snap.GravValue.end(), gravp);
Expand Down

0 comments on commit e8b4256

Please sign in to comment.