remove PARTICLEDEBUG define and replace it with tpt.setdebug(0x8) to activate the key shortcuts

This commit is contained in:
jacob1 2016-02-24 22:05:54 -05:00
parent 983ed4eb53
commit 10262b87da
6 changed files with 139 additions and 65 deletions

View File

@ -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; }
};

106
src/debug/ParticleDebug.cpp Normal file
View File

@ -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()
{
}

19
src/debug/ParticleDebug.h Normal file
View File

@ -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

View File

@ -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()
@ -691,6 +693,13 @@ 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;
}
@ -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())

View File

@ -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();

View File

@ -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)