diff --git a/src/debug/DebugInfo.h b/src/debug/DebugInfo.h index 74af41da2..f4b816278 100644 --- a/src/debug/DebugInfo.h +++ b/src/debug/DebugInfo.h @@ -1,6 +1,7 @@ #pragma once #include "gui/interface/Point.h" +#include "Config.h" class DebugInfo { @@ -9,4 +10,6 @@ public: virtual ~DebugInfo() { } unsigned int ID; virtual void Draw() {} + // currentMouse doesn't belong but I don't want to create more hooks at the moment + virtual bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt, ui::Point currentMouse) { return true; } }; diff --git a/src/debug/ParticleDebug.cpp b/src/debug/ParticleDebug.cpp new file mode 100644 index 000000000..ce7788367 --- /dev/null +++ b/src/debug/ParticleDebug.cpp @@ -0,0 +1,106 @@ +#include +#include "ParticleDebug.h" +#include "gui/interface/Engine.h" +#include "gui/game/GameView.h" +#include "gui/game/GameController.h" + +ParticleDebug::ParticleDebug(unsigned int id, Simulation * sim, GameModel * model): + DebugInfo(id), + sim(sim), + model(model) +{ + +} + +void ParticleDebug::Debug(int mode, int x, int y) +{ + 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; + } + model->Log(logmessage.str(), false); + + sim->UpdateParticles(debug_currentParticle, i); + if (i < NPART-1) + sim->debug_currentParticle = i+1; + else + { + sim->AfterSim(); + sim->framerender = 1; + sim->BeforeSim(); + sim->framerender = 0; + sim->debug_currentParticle = 0; + } +} + +bool ParticleDebug::KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt, ui::Point currentMouse) +{ + if (key == 'f') + { + if (alt) + { + Debug(0, 0, 0); + } + else if (shift) + { + ui::Point mouse = currentMouse; + if (mouse.X >= XRES) + mouse.X = XRES-1; + else if (mouse.X < 0) + mouse.X = 0; + if (mouse.Y >= YRES) + mouse.Y = YRES-1; + else if (mouse.Y < 0) + mouse.Y = 0; + + mouse = model->AdjustZoomCoords(mouse); + Debug(1, mouse.X, mouse.Y); + } + else + { + if (sim->debug_currentParticle > 0) + { + sim->UpdateParticles(sim->debug_currentParticle, NPART); + sim->AfterSim(); + std::stringstream logmessage; + logmessage << "Updated particles from #" << sim->debug_currentParticle << " to end, updated sim"; + model->Log(logmessage.str(), false); + sim->debug_currentParticle = 0; + } + else + { + model->FrameStep(1); + } + model->SetPaused(1); + } + return false; + } + return true; +} + +ParticleDebug::~ParticleDebug() +{ + +} diff --git a/src/debug/ParticleDebug.h b/src/debug/ParticleDebug.h new file mode 100644 index 000000000..719941615 --- /dev/null +++ b/src/debug/ParticleDebug.h @@ -0,0 +1,19 @@ +#ifndef PARTICLE_DEBUG_H +#define PARTICLE_DEBUG_H + +#include "DebugInfo.h" + +class Simulation; +class GameModel; +class ParticleDebug : public DebugInfo +{ + Simulation * sim; + GameModel * model; +public: + ParticleDebug(unsigned int id, Simulation * sim, GameModel * model); + void Debug(int mode, int x, int y); + virtual bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt, ui::Point currentMouse); + virtual ~ParticleDebug(); +}; + +#endif diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 4f9a5fcc4..45b4823f7 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -30,6 +30,7 @@ #include "debug/DebugParts.h" #include "debug/ElementPopulation.h" #include "debug/DebugLines.h" +#include "debug/ParticleDebug.h" #ifdef LUACONSOLE #include "lua/LuaScriptInterface.h" #else @@ -162,6 +163,7 @@ GameController::GameController(): debugInfo.push_back(new DebugParts(0x1, gameModel->GetSimulation())); debugInfo.push_back(new ElementPopulationDebug(0x2, gameModel->GetSimulation())); debugInfo.push_back(new DebugLines(0x4, gameView, this)); + debugInfo.push_back(new ParticleDebug(0x8, gameModel->GetSimulation(), gameModel)); } GameController::~GameController() @@ -639,7 +641,7 @@ bool GameController::MouseWheel(int x, int y, int d) bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { bool ret = commandInterface->OnKeyPress(key, character, shift, ctrl, alt); - if(ret) + if (ret) { Simulation * sim = gameModel->GetSimulation(); if (key == KEY_RIGHT) @@ -691,6 +693,13 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl, break; } } + + for(std::vector::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++) + { + if ((*iter)->ID & debugFlags) + if (!(*iter)->KeyPress(key, character, shift, ctrl, alt, gameView->GetMousePosition())) + ret = false; + } } return ret; } @@ -698,7 +707,7 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) { bool ret = commandInterface->OnKeyRelease(key, character, shift, ctrl, alt); - if(ret) + if (ret) { Simulation * sim = gameModel->GetSimulation(); if (key == KEY_RIGHT || key == KEY_LEFT) @@ -1425,52 +1434,6 @@ 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(), false); - - sim->UpdateParticles(debug_currentParticle, i); - if (i < NPART-1) - sim->debug_currentParticle = i+1; - else - { - sim->Aftersim(); - sim->framerender = 1; - sim->BeforeSim(); - 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 c3fb71274..6028c5608 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -132,9 +132,6 @@ 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 aa669b83d..7222c8014 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1431,19 +1431,6 @@ 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 if (ctrl) { Tool *active = c->GetActiveTool(0); @@ -1454,7 +1441,6 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool } else c->FrameStep(); -#endif break; case 'g': if (ctrl)