Permalink
Browse files

remove PARTICLEDEBUG define and replace it with tpt.setdebug(0x8) to …

…activate the key shortcuts
  • Loading branch information...
jacob1 committed Feb 25, 2016
1 parent 983ed4e commit 10262b87daa3ebc3267c9a92b805d22ff4aa263c
@@ -1,6 +1,7 @@
#pragma once
#include "gui/interface/Point.h"
#include "Config.h"
class DebugInfo
{
@@ -9,4 +10,6 @@ class DebugInfo
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; }
};
@@ -0,0 +1,106 @@
#include <sstream>
#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()
{
}
@@ -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
@@ -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,14 +693,21 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl,
break;
}
}
for(std::vector<DebugInfo*>::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;
}
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())
@@ -132,9 +132,6 @@ class GameController: public ClientListener
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();
@@ -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)

0 comments on commit 10262b8

Please sign in to comment.