diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 131ca70e2..792120643 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -882,7 +882,9 @@ void GameController::Update() gameView->SetSample(gameModel->GetSimulation()->GetSample(pos.X, pos.Y)); Simulation * sim = gameModel->GetSimulation(); - sim->Update(); + sim->UpdateSim(); + if (!sim->sys_pause || sim->framerender) + sim->UpdateParticles(0, NPART); //if either STKM or STK2 isn't out, reset it's selected element. Defaults to PT_DUST unless right selected is something else //This won't run if the stickmen dies in a frame, since it respawns instantly @@ -1413,6 +1415,51 @@ void GameController::ReloadSim() } } +#ifdef PARTICLEDEBUG +void GameController::ParticleDebug(int mode, int x, int y) +{ + Simulation *sim = gameModel->GetSimulation(); + int debug_currentParticle = sim->debug_currentParticle; + int i; + std::stringstream logmessage; + + if (mode == 0) + { + if (!sim->NUM_PARTS) + return; + i = debug_currentParticle; + while (i < NPART && !sim->parts[i].type) + i++; + if (i == NPART) + logmessage << "End of particles reached, updated sim"; + else + logmessage << "Updated particle #" << i; + } + else if (mode == 1) + { + if (x < 0 || x >= XRES || y < 0 || y >= YRES || !(i = (sim->pmap[y][x]>>8)) || i < debug_currentParticle) + { + i = NPART; + logmessage << "Updated particles from #" << debug_currentParticle << " to end, updated sim"; + } + else + logmessage << "Updated particles #" << debug_currentParticle << " through #" << i; + } + gameModel->Log(logmessage.str()); + + sim->UpdateParticles(debug_currentParticle, i); + if (i < NPART-1) + sim->debug_currentParticle = i+1; + else + { + sim->framerender = 1; + sim->UpdateSim(); + sim->framerender = 0; + sim->debug_currentParticle = 0; + } +} +#endif + std::string GameController::ElementResolve(int type, int ctype) { if(gameModel && gameModel->GetSimulation()) diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index f816249ab..7cbab12ee 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -132,6 +132,9 @@ public: void PlaceSave(ui::Point position); void ClearSim(); void ReloadSim(); +#ifdef PARTICLEDEBUG + void ParticleDebug(int mode, int x, int y); +#endif void Vote(int direction); void ChangeBrush(); void ShowConsole(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index df1f70818..30236162b 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1412,7 +1412,21 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool c->OpenElementSearch(); break; case 'f': +#ifdef PARTICLEDEBUG + if (ctrl) + { + c->ParticleDebug(0, 0, 0); + } + else if (shift) + { + ui::Point mouse = c->PointTranslate(currentMouse); + c->ParticleDebug(1, mouse.X, mouse.Y); + } + else + c->FrameStep(); +#else c->FrameStep(); +#endif break; case 'g': if (ctrl) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 3a6eac3db..d88e54ec2 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3234,7 +3234,7 @@ void Simulation::UpdateParticles(int start, int end) bool transitionOccurred; //the main particle loop function, goes over all particles. - for (i = start; i <= end; i++) + for (i = start; i <= end && i <= parts_lastActiveIndex; i++) if (parts[i].type) { t = parts[i].type; @@ -4393,6 +4393,10 @@ killed: movedone: continue; } + + //'f' was pressed (single frame) + if (framerender) + framerender--; } int Simulation::GetParticleType(std::string type) @@ -4580,8 +4584,8 @@ void Simulation::CheckStacking() } } -//updates pmap, gol, and some other simulation stuff (then calls UpdateParticles) -void Simulation::Update() +//updates pmap, gol, and some other simulation stuff (but not particles) +void Simulation::UpdateSim() { int i, x, y, t; int lastPartUsed = 0; @@ -4706,8 +4710,9 @@ void Simulation::Update() else parts[lastPartUnused].life = parts_lastActiveIndex+1; } parts_lastActiveIndex = lastPartUsed; - if (!sys_pause||framerender) + if (!sys_pause || framerender) { + // decrease wall conduction, make walls block air and ambient heat for (y=0; ybmap_blockairh[y][x] = (bmap[y][x]==WL_WALL || bmap[y][x]==WL_WALLELEC || bmap[y][x]==WL_BLOCKAIR || bmap[y][x]==WL_GRAV || (bmap[y][x]==WL_EWALL && !emap[y][x])) ? 0x8:0; } } - } - if (!sys_pause||framerender) - { + // check for stacking and create BHOL if found if (force_stacking_check || (rand()%10)==0) { CheckStacking(); } - if (elementCount[PT_LOVE] > 0 || elementCount[PT_LOLZ] > 0) //LOVE and LOLZ element handling + // LOVE and LOLZ element handling + if (elementCount[PT_LOVE] > 0 || elementCount[PT_LOLZ] > 0) { int nx, nnx, ny, nny, r, rt; for (ny=0; ny 0) { for (int nx = 0; nx < XRES; nx++) @@ -4812,6 +4816,7 @@ void Simulation::Update() } } + // update PPIP tmp? if (Element_PPIP::ppip_changed) { for (i=0; i<=parts_lastActiveIndex; i++) @@ -4825,13 +4830,15 @@ void Simulation::Update() Element_PPIP::ppip_changed = 0; } - //game of life! - if (elementCount[PT_LIFE]>0 && ++CGOL>=GSPEED)//GSPEED is frames per generation + // Simulate GoL + // GSPEED is frames per generation + if (elementCount[PT_LIFE]>0 && ++CGOL>=GSPEED) { SimulateGoL(); } - if (ISWIRE>0)//wifi channel reseting + // wifi channel reseting + if (ISWIRE>0) { for (int q = 0; q < (int)(MAX_TEMP-73.15f)/100+2; q++) { @@ -4841,16 +4848,14 @@ void Simulation::Update() ISWIRE--; } + // spawn STKM and STK2 if (!player.spwn && player.spawnID >= 0) create_part(-1, (int)parts[player.spawnID].x, (int)parts[player.spawnID].y, PT_STKM); else if (!player2.spwn && player2.spawnID >= 0) create_part(-1, (int)parts[player2.spawnID].x, (int)parts[player2.spawnID].y, PT_STKM2); - UpdateParticles(0, parts_lastActiveIndex); + // particle update happens right after this function (called separately) } - - if(framerender) - framerender--; } Simulation::~Simulation() @@ -4865,6 +4870,7 @@ Simulation::~Simulation() Simulation::Simulation(): replaceModeSelected(0), replaceModeFlags(0), + debug_currentParticle(0), ISWIRE(0), force_stacking_check(0), emp_decor(0), diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index ecbdc28b6..54742eddf 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -53,6 +53,7 @@ public: int replaceModeFlags; char can_move[PT_NUM][PT_NUM]; + int debug_currentParticle; int parts_lastActiveIndex; int pfree; int NUM_PARTS; @@ -154,7 +155,7 @@ public: void UpdateParticles(int start, int end); void SimulateGoL(); void CheckStacking(); - void Update(); + void UpdateSim(); void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert); void clear_area(int area_x, int area_y, int area_w, int area_h);