reduce ctrl+z snapshot memory usage
This commit is contained in:
parent
9445c24611
commit
8f4e3a56bd
@ -320,7 +320,7 @@ Snapshot * Simulation::CreateSnapshot()
|
||||
snap->AirVelocityX.insert(snap->AirVelocityX.begin(), &vx[0][0], &vx[0][0]+((XRES/CELL)*(YRES/CELL)));
|
||||
snap->AirVelocityY.insert(snap->AirVelocityY.begin(), &vy[0][0], &vy[0][0]+((XRES/CELL)*(YRES/CELL)));
|
||||
snap->AmbientHeat.insert(snap->AmbientHeat.begin(), &hv[0][0], &hv[0][0]+((XRES/CELL)*(YRES/CELL)));
|
||||
snap->Particles.insert(snap->Particles.begin(), parts, parts+NPART);
|
||||
snap->Particles.insert(snap->Particles.begin(), parts, parts+parts_lastActiveIndex+1);
|
||||
snap->PortalParticles.insert(snap->PortalParticles.begin(), &portalp[0][0][0], &portalp[CHANNELS-1][8-1][80-1]);
|
||||
snap->WirelessData.insert(snap->WirelessData.begin(), &wireless[0][0], &wireless[CHANNELS-1][2-1]);
|
||||
snap->GravVelocityX.insert(snap->GravVelocityX.begin(), gravx, gravx+((XRES/CELL)*(YRES/CELL)));
|
||||
@ -348,7 +348,11 @@ void Simulation::Restore(const Snapshot & snap)
|
||||
std::copy(snap.AirVelocityX.begin(), snap.AirVelocityX.end(), &vx[0][0]);
|
||||
std::copy(snap.AirVelocityY.begin(), snap.AirVelocityY.end(), &vy[0][0]);
|
||||
std::copy(snap.AmbientHeat.begin(), snap.AmbientHeat.end(), &hv[0][0]);
|
||||
for (int i = 0; i < NPART; i++)
|
||||
parts[i].type = 0;
|
||||
std::copy(snap.Particles.begin(), snap.Particles.end(), parts);
|
||||
parts_lastActiveIndex = NPART-1;
|
||||
RecalcFreeParticles();
|
||||
std::copy(snap.PortalParticles.begin(), snap.PortalParticles.end(), &portalp[0][0][0]);
|
||||
std::copy(snap.WirelessData.begin(), snap.WirelessData.end(), &wireless[0][0]);
|
||||
if (grav->ngrav_enable)
|
||||
@ -4744,121 +4748,19 @@ void Simulation::SimulateGoL()
|
||||
//memset(gol2, 0, sizeof(gol2));
|
||||
}
|
||||
|
||||
void Simulation::CheckStacking()
|
||||
void Simulation::RecalcFreeParticles()
|
||||
{
|
||||
bool excessive_stacking_found = false;
|
||||
force_stacking_check = false;
|
||||
for (int y = 0; y < YRES; y++)
|
||||
{
|
||||
for (int x = 0; x < XRES; x++)
|
||||
{
|
||||
// Use a threshold, since some particle stacking can be normal (e.g. BIZR + FILT)
|
||||
// Setting pmap_count[y][x] > NPART means BHOL will form in that spot
|
||||
if (pmap_count[y][x]>5)
|
||||
{
|
||||
if (bmap[y/CELL][x/CELL]==WL_EHOLE)
|
||||
{
|
||||
// Allow more stacking in E-hole
|
||||
if (pmap_count[y][x]>1500)
|
||||
{
|
||||
pmap_count[y][x] = pmap_count[y][x] + NPART;
|
||||
excessive_stacking_found = 1;
|
||||
}
|
||||
}
|
||||
else if (pmap_count[y][x]>1500 || (rand()%1600)<=(pmap_count[y][x]+100))
|
||||
{
|
||||
pmap_count[y][x] = pmap_count[y][x] + NPART;
|
||||
excessive_stacking_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excessive_stacking_found)
|
||||
{
|
||||
for (int i = 0; i <= parts_lastActiveIndex; i++)
|
||||
{
|
||||
if (parts[i].type)
|
||||
{
|
||||
int t = parts[i].type;
|
||||
int x = (int)(parts[i].x+0.5f);
|
||||
int y = (int)(parts[i].y+0.5f);
|
||||
if (x>=0 && y>=0 && x<XRES && y<YRES && !(elements[t].Properties&TYPE_ENERGY))
|
||||
{
|
||||
if (pmap_count[y][x]>=NPART)
|
||||
{
|
||||
if (pmap_count[y][x]>NPART)
|
||||
{
|
||||
create_part(i, x, y, PT_NBHL);
|
||||
parts[i].temp = MAX_TEMP;
|
||||
parts[i].tmp = pmap_count[y][x]-NPART;//strength of grav field
|
||||
if (parts[i].tmp>51200) parts[i].tmp = 51200;
|
||||
pmap_count[y][x] = NPART;
|
||||
}
|
||||
else
|
||||
{
|
||||
kill_part(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//updates pmap, gol, and some other simulation stuff (but not particles)
|
||||
void Simulation::BeforeSim()
|
||||
{
|
||||
int i, x, y, t;
|
||||
int x, y, t;
|
||||
int lastPartUsed = 0;
|
||||
int lastPartUnused = -1;
|
||||
#ifdef MT
|
||||
int pt = 0, pc = 0;
|
||||
pthread_t *InterThreads;
|
||||
#endif
|
||||
|
||||
if(!sys_pause||framerender)
|
||||
{
|
||||
air->update_air();
|
||||
|
||||
if(aheat_enable)
|
||||
air->update_airh();
|
||||
|
||||
if(grav->ngrav_enable)
|
||||
{
|
||||
grav->gravity_update_async();
|
||||
|
||||
//Get updated buffer pointers for gravity
|
||||
gravx = grav->gravx;
|
||||
gravy = grav->gravy;
|
||||
gravp = grav->gravp;
|
||||
gravmap = grav->gravmap;
|
||||
}
|
||||
if(gravWallChanged)
|
||||
{
|
||||
grav->gravity_mask();
|
||||
gravWallChanged = false;
|
||||
}
|
||||
if(emp_decor>0)
|
||||
emp_decor -= emp_decor/25+2;
|
||||
if(emp_decor < 0)
|
||||
emp_decor = 0;
|
||||
etrd_count_valid = false;
|
||||
etrd_life0_count = 0;
|
||||
|
||||
currentTick++;
|
||||
|
||||
elementRecount |= !(currentTick%180);
|
||||
if (elementRecount)
|
||||
std::fill(elementCount, elementCount+PT_NUM, 0);
|
||||
}
|
||||
sandcolour = (int)(20.0f*sin((float)sandcolour_frame*(M_PI/180.0f)));
|
||||
sandcolour_frame = (sandcolour_frame+1)%360;
|
||||
|
||||
memset(pmap, 0, sizeof(pmap));
|
||||
memset(pmap_count, 0, sizeof(pmap_count));
|
||||
memset(photons, 0, sizeof(photons));
|
||||
|
||||
NUM_PARTS = 0;
|
||||
for (i=0; i<=parts_lastActiveIndex; i++)//the particle loop that resets the pmap/photon maps every frame, to update them.
|
||||
//the particle loop that resets the pmap/photon maps every frame, to update them.
|
||||
for (int i = 0; i <= parts_lastActiveIndex; i++)
|
||||
{
|
||||
if (parts[i].type)
|
||||
{
|
||||
@ -4924,18 +4826,129 @@ void Simulation::BeforeSim()
|
||||
}
|
||||
if (lastPartUnused == -1)
|
||||
{
|
||||
if (parts_lastActiveIndex>=NPART-1) pfree = -1;
|
||||
else pfree = parts_lastActiveIndex+1;
|
||||
if (parts_lastActiveIndex>=NPART-1)
|
||||
pfree = -1;
|
||||
else
|
||||
pfree = parts_lastActiveIndex+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parts_lastActiveIndex>=NPART-1) parts[lastPartUnused].life = -1;
|
||||
else parts[lastPartUnused].life = parts_lastActiveIndex+1;
|
||||
if (parts_lastActiveIndex>=NPART-1)
|
||||
parts[lastPartUnused].life = -1;
|
||||
else
|
||||
parts[lastPartUnused].life = parts_lastActiveIndex+1;
|
||||
}
|
||||
parts_lastActiveIndex = lastPartUsed;
|
||||
}
|
||||
|
||||
void Simulation::CheckStacking()
|
||||
{
|
||||
bool excessive_stacking_found = false;
|
||||
force_stacking_check = false;
|
||||
for (int y = 0; y < YRES; y++)
|
||||
{
|
||||
for (int x = 0; x < XRES; x++)
|
||||
{
|
||||
// Use a threshold, since some particle stacking can be normal (e.g. BIZR + FILT)
|
||||
// Setting pmap_count[y][x] > NPART means BHOL will form in that spot
|
||||
if (pmap_count[y][x]>5)
|
||||
{
|
||||
if (bmap[y/CELL][x/CELL]==WL_EHOLE)
|
||||
{
|
||||
// Allow more stacking in E-hole
|
||||
if (pmap_count[y][x]>1500)
|
||||
{
|
||||
pmap_count[y][x] = pmap_count[y][x] + NPART;
|
||||
excessive_stacking_found = 1;
|
||||
}
|
||||
}
|
||||
else if (pmap_count[y][x]>1500 || (rand()%1600)<=(pmap_count[y][x]+100))
|
||||
{
|
||||
pmap_count[y][x] = pmap_count[y][x] + NPART;
|
||||
excessive_stacking_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excessive_stacking_found)
|
||||
{
|
||||
for (int i = 0; i <= parts_lastActiveIndex; i++)
|
||||
{
|
||||
if (parts[i].type)
|
||||
{
|
||||
int t = parts[i].type;
|
||||
int x = (int)(parts[i].x+0.5f);
|
||||
int y = (int)(parts[i].y+0.5f);
|
||||
if (x>=0 && y>=0 && x<XRES && y<YRES && !(elements[t].Properties&TYPE_ENERGY))
|
||||
{
|
||||
if (pmap_count[y][x]>=NPART)
|
||||
{
|
||||
if (pmap_count[y][x]>NPART)
|
||||
{
|
||||
create_part(i, x, y, PT_NBHL);
|
||||
parts[i].temp = MAX_TEMP;
|
||||
parts[i].tmp = pmap_count[y][x]-NPART;//strength of grav field
|
||||
if (parts[i].tmp>51200) parts[i].tmp = 51200;
|
||||
pmap_count[y][x] = NPART;
|
||||
}
|
||||
else
|
||||
{
|
||||
kill_part(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//updates pmap, gol, and some other simulation stuff (but not particles)
|
||||
void Simulation::BeforeSim()
|
||||
{
|
||||
if (!sys_pause||framerender)
|
||||
{
|
||||
air->update_air();
|
||||
|
||||
if(aheat_enable)
|
||||
air->update_airh();
|
||||
|
||||
if(grav->ngrav_enable)
|
||||
{
|
||||
grav->gravity_update_async();
|
||||
|
||||
//Get updated buffer pointers for gravity
|
||||
gravx = grav->gravx;
|
||||
gravy = grav->gravy;
|
||||
gravp = grav->gravp;
|
||||
gravmap = grav->gravmap;
|
||||
}
|
||||
if(gravWallChanged)
|
||||
{
|
||||
grav->gravity_mask();
|
||||
gravWallChanged = false;
|
||||
}
|
||||
if(emp_decor>0)
|
||||
emp_decor -= emp_decor/25+2;
|
||||
if(emp_decor < 0)
|
||||
emp_decor = 0;
|
||||
etrd_count_valid = false;
|
||||
etrd_life0_count = 0;
|
||||
|
||||
currentTick++;
|
||||
|
||||
elementRecount |= !(currentTick%180);
|
||||
if (elementRecount)
|
||||
std::fill(elementCount, elementCount+PT_NUM, 0);
|
||||
}
|
||||
sandcolour = (int)(20.0f*sin((float)sandcolour_frame*(M_PI/180.0f)));
|
||||
sandcolour_frame = (sandcolour_frame+1)%360;
|
||||
|
||||
RecalcFreeParticles();
|
||||
|
||||
if (!sys_pause || framerender)
|
||||
{
|
||||
// decrease wall conduction, make walls block air and ambient heat
|
||||
int x, y;
|
||||
for (y = 0; y < YRES/CELL; y++)
|
||||
{
|
||||
for (x = 0; x < XRES/CELL; x++)
|
||||
@ -5042,7 +5055,7 @@ void Simulation::BeforeSim()
|
||||
// update PPIP tmp?
|
||||
if (Element_PPIP::ppip_changed)
|
||||
{
|
||||
for (i=0; i<=parts_lastActiveIndex; i++)
|
||||
for (int i = 0; i <= parts_lastActiveIndex; i++)
|
||||
{
|
||||
if (parts[i].type==PT_PPIP)
|
||||
{
|
||||
|
@ -160,6 +160,7 @@ public:
|
||||
void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type, int flags);
|
||||
void UpdateParticles(int start, int end);
|
||||
void SimulateGoL();
|
||||
void RecalcFreeParticles();
|
||||
void CheckStacking();
|
||||
void BeforeSim();
|
||||
void AfterSim();
|
||||
|
@ -13,9 +13,6 @@ public:
|
||||
std::vector<float> AmbientHeat;
|
||||
|
||||
std::vector<Particle> Particles;
|
||||
std::vector<Particle> PortalParticles;
|
||||
|
||||
std::vector<int> WirelessData;
|
||||
|
||||
std::vector<float> GravVelocityX;
|
||||
std::vector<float> GravVelocityY;
|
||||
@ -28,6 +25,9 @@ public:
|
||||
std::vector<float> FanVelocityX;
|
||||
std::vector<float> FanVelocityY;
|
||||
|
||||
|
||||
std::vector<Particle> PortalParticles;
|
||||
std::vector<int> WirelessData;
|
||||
std::vector<playerst> stickmen;
|
||||
std::vector<sign> signs;
|
||||
|
||||
@ -37,8 +37,6 @@ public:
|
||||
AirVelocityY(),
|
||||
AmbientHeat(),
|
||||
Particles(),
|
||||
PortalParticles(),
|
||||
WirelessData(),
|
||||
GravVelocityX(),
|
||||
GravVelocityY(),
|
||||
GravValue(),
|
||||
@ -47,6 +45,8 @@ public:
|
||||
ElecMap(),
|
||||
FanVelocityX(),
|
||||
FanVelocityY(),
|
||||
PortalParticles(),
|
||||
WirelessData(),
|
||||
stickmen(),
|
||||
signs()
|
||||
{
|
||||
|
Reference in New Issue
Block a user