From 32328ad4fe07048e5b2b39db759a45f51af53510 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 27 Sep 2014 22:25:15 -0400 Subject: [PATCH] re-implement tpt.setdebug --- src/debug/DebugInfo.h | 2 ++ src/debug/DebugLines.cpp | 62 ++------------------------------- src/debug/DebugLines.h | 2 +- src/debug/ElementPopulation.cpp | 3 +- src/debug/ElementPopulation.h | 2 +- src/gui/game/GameController.cpp | 8 ++--- src/gui/game/GameController.h | 2 ++ src/lua/LegacyLuaAPI.cpp | 4 ++- 8 files changed, 17 insertions(+), 68 deletions(-) diff --git a/src/debug/DebugInfo.h b/src/debug/DebugInfo.h index 5a7f00500b..9266b87fe7 100644 --- a/src/debug/DebugInfo.h +++ b/src/debug/DebugInfo.h @@ -5,5 +5,7 @@ class DebugInfo { public: + DebugInfo(unsigned int id):ID(id) { } + unsigned int ID; virtual void Draw() {} }; diff --git a/src/debug/DebugLines.cpp b/src/debug/DebugLines.cpp index 3f2da84913..5174e88685 100644 --- a/src/debug/DebugLines.cpp +++ b/src/debug/DebugLines.cpp @@ -3,7 +3,8 @@ #include "gui/game/GameView.h" #include "gui/game/GameController.h" -LineDebug::LineDebug(GameView * view, GameController * controller): +LineDebug::LineDebug(unsigned int id, GameView * view, GameController * controller): + DebugInfo(id), view(view), controller(controller) { @@ -43,65 +44,6 @@ void LineDebug::Draw() info << std::abs(drawPoint2.Y-drawPoint1.Y); g->drawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(info.str().c_str())-2), (drawPoint1.Y+drawPoint2.Y)/2-3, info.str().c_str(), 255, 255, 255, 200); } - /*int yBottom = YRES-10; - int xStart = 10; - - std::string maxValString; - std::string halfValString; - - - float maxVal = 255; - float scale = 1.0f; - int bars = 0; - for(int i = 0; i < PT_NUM; i++) - { - if(sim->elements[i].Enabled) - { - if(maxVal < sim->elementCount[i]) - maxVal = sim->elementCount[i]; - bars++; - } - } - maxAverage = (maxAverage*(1.0f-0.015f)) + (0.015f*maxVal); - scale = 255.0f/maxAverage; - - maxValString = format::NumberToString(maxAverage); - halfValString = format::NumberToString(maxAverage/2); - - - g->fillrect(xStart-5, yBottom - 263, bars+10+Graphics::textwidth(maxValString.c_str())+10, 255 + 13, 0, 0, 0, 180); - - bars = 0; - for(int i = 0; i < PT_NUM; i++) - { - if(sim->elements[i].Enabled) - { - float count = sim->elementCount[i]; - int barSize = (count * scale - 0.5f); - int barX = bars;//*2; - - g->draw_line(xStart+barX, yBottom+3, xStart+barX, yBottom+2, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255); - if(sim->elementCount[i]) - { - if(barSize > 256) - { - barSize = 256; - g->blendpixel(xStart+barX, yBottom-barSize-3, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255); - g->blendpixel(xStart+barX, yBottom-barSize-5, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255); - g->blendpixel(xStart+barX, yBottom-barSize-7, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255); - } else { - - g->draw_line(xStart+barX, yBottom-barSize-3, xStart+barX, yBottom-barSize-2, 255, 255, 255, 180); - } - g->draw_line(xStart+barX, yBottom-barSize, xStart+barX, yBottom, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255); - } - bars++; - } - } - - g->drawtext(xStart + bars + 5, yBottom-5, "0", 255, 255, 255, 255); - g->drawtext(xStart + bars + 5, yBottom-132, halfValString, 255, 255, 255, 255); - g->drawtext(xStart + bars + 5, yBottom-260, maxValString, 255, 255, 255, 255);*/ } LineDebug::~LineDebug() diff --git a/src/debug/DebugLines.h b/src/debug/DebugLines.h index 302408921f..007689998e 100644 --- a/src/debug/DebugLines.h +++ b/src/debug/DebugLines.h @@ -9,7 +9,7 @@ class LineDebug : public DebugInfo GameView * view; GameController * controller; public: - LineDebug(GameView * view, GameController * controller); + LineDebug(unsigned int id, GameView * view, GameController * controller); virtual void Draw(); virtual ~LineDebug(); }; diff --git a/src/debug/ElementPopulation.cpp b/src/debug/ElementPopulation.cpp index e01de6e203..1cfd9c5d83 100644 --- a/src/debug/ElementPopulation.cpp +++ b/src/debug/ElementPopulation.cpp @@ -3,7 +3,8 @@ #include "simulation/Simulation.h" #include "Format.h" -ElementPopulationDebug::ElementPopulationDebug(Simulation * sim): +ElementPopulationDebug::ElementPopulationDebug(unsigned int id, Simulation * sim): + DebugInfo(id), sim(sim), maxAverage(255.0f) { diff --git a/src/debug/ElementPopulation.h b/src/debug/ElementPopulation.h index dfd679e62e..64de0674f1 100644 --- a/src/debug/ElementPopulation.h +++ b/src/debug/ElementPopulation.h @@ -8,7 +8,7 @@ class ElementPopulationDebug : public DebugInfo Simulation * sim; float maxAverage; public: - ElementPopulationDebug(Simulation * sim); + ElementPopulationDebug(unsigned int id, Simulation * sim); virtual void Draw(); virtual ~ElementPopulationDebug(); }; diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 8f7cbe9889..9cc7503703 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -153,11 +153,10 @@ GameController::GameController(): ActiveToolChanged(2, gameModel->GetActiveTool(2)); ActiveToolChanged(3, gameModel->GetActiveTool(3)); - //sim = new Simulation(); Client::Ref().AddListener(this); - //debugInfo.push_back(new ElementPopulationDebug(gameModel->GetSimulation())); - //debugInfo.push_back(new LineDebug(gameView, this)); + debugInfo.push_back(new ElementPopulationDebug(0x2, gameModel->GetSimulation())); + debugInfo.push_back(new LineDebug(0x4, gameView, this)); } GameController::~GameController() @@ -743,7 +742,8 @@ void GameController::Tick() } for(std::vector::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++) { - (*iter)->Draw(); + if ((*iter)->ID & debugFlags) + (*iter)->Draw(); } commandInterface->OnTick(); } diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index a7cdfc94b0..c436c9dadc 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -46,6 +46,7 @@ class GameController: public ClientListener OptionsController * options; CommandInterface * commandInterface; vector debugInfo; + unsigned int debugFlags; public: bool HasDone; class SearchCallback; @@ -101,6 +102,7 @@ class GameController: public ClientListener bool GetHudEnable(); void SetDebugHUD(bool hudState); bool GetDebugHUD(); + void SetDebugFlags(unsigned int flags) { debugFlags = flags; } void SetActiveMenu(int menuID); std::vector GetMenuList(); Tool * GetActiveTool(int selection); diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index ca67c89192..17fd59453a 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -1885,7 +1885,9 @@ int luatpt_setfire(lua_State* l) int luatpt_setdebug(lua_State* l) { - return luaL_error(l, "setdebug: Deprecated"); //TODO: maybe use the debugInfo thing in GameController to implement this + int debugFlags = luaL_optint(l, 1, 0); + luacon_controller->SetDebugFlags(debugFlags); + return 0; } int luatpt_setfpscap(lua_State* l)