From 1f914561b2049ac779d8a729d9e910c4915b280b Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 29 Jul 2012 02:07:04 +0100 Subject: [PATCH] Better syncing for elementCount, fixes issue #21 --- src/simulation/Simulation.cpp | 22 ++++++++++++++++++++++ src/simulation/Simulation.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index f899ff3ff..41af624cc 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -76,6 +76,8 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) //Replace existing parts[r>>8] = tempPart; pmap[y][x] = 0; + elementCount[parts[r>>8].type]--; + elementCount[tempPart.type]++; } else { @@ -86,6 +88,8 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) pfree = parts[i].life; if (i>parts_lastActiveIndex) parts_lastActiveIndex = i; parts[i] = tempPart; + + elementCount[tempPart.type]++; } } parts_lastActiveIndex = NPART-1; @@ -1779,6 +1783,7 @@ void Simulation::clear_sim(void) { int i, x, y; signs.clear(); + currentTick = 0; memset(bmap, 0, sizeof(bmap)); memset(emap, 0, sizeof(emap)); memset(parts, 0, sizeof(Particle)*NPART); @@ -1803,6 +1808,7 @@ void Simulation::clear_sim(void) memset(gol2, 0, sizeof(gol2)); memset(portalp, 0, sizeof(portalp)); memset(fighters, 0, sizeof(fighters)); + std::fill(elementCount, elementCount+PT_NUM, 0); fighcount = 0; player.spwn = 0; player2.spwn = 0; @@ -3070,6 +3076,9 @@ void Simulation::update_particles_i(int start, int inc) float pGravX, pGravY, pGravD; int excessive_stacking_found = 0; + currentTick++; + currentTick %= 3600; + if (lighting_recreate>0) { for (i=0; i<=parts_lastActiveIndex; i++) @@ -3260,6 +3269,13 @@ void Simulation::update_particles_i(int start, int inc) } ISWIRE--; } + + bool elementRecount = !(currentTick%180); + if(elementRecount) + { + std::fill(elementCount, elementCount+PT_NUM, 0); + } + for (i=0; i<=parts_lastActiveIndex; i++) if (parts[i].type) { @@ -3270,6 +3286,9 @@ void Simulation::update_particles_i(int start, int inc) continue; } + + elementCount[t]++; + elem_properties = elements[t].Properties; if (parts[i].life>0 && (elem_properties&PROP_LIFE_DEC)) { @@ -4431,6 +4450,9 @@ Simulation::Simulation(): memcpy(portal_rx, tportal_rx, sizeof(tportal_rx)); memcpy(portal_ry, tportal_ry, sizeof(tportal_ry)); + currentTick = 0; + std::fill(elementCount, elementCount+PT_NUM, 0); + //Create and attach gravity simulation grav = new Gravity(); //Give air sim references to our data diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 7095c66f6..ff59a92f8 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -55,6 +55,8 @@ public: int grule[NGOL+1][10]; menu_section msections[SC_TOTAL]; + int currentTick; + playerst player; playerst player2; playerst fighters[256]; //255 is the maximum number of fighters