Skip to content

Commit

Permalink
re-implement tpt.setdebug
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Sep 28, 2014
1 parent 507ba35 commit 32328ad
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 68 deletions.
2 changes: 2 additions & 0 deletions src/debug/DebugInfo.h
Expand Up @@ -5,5 +5,7 @@
class DebugInfo
{
public:
DebugInfo(unsigned int id):ID(id) { }
unsigned int ID;
virtual void Draw() {}
};
62 changes: 2 additions & 60 deletions src/debug/DebugLines.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -43,65 +44,6 @@ void LineDebug::Draw()
info << std::abs(drawPoint2.Y-drawPoint1.Y);
g->drawtext_outline(drawPoint1.X+(drawPoint2.X<drawPoint1.X?3:-g->textwidth(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<int>(maxAverage);
halfValString = format::NumberToString<int>(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()
Expand Down
2 changes: 1 addition & 1 deletion src/debug/DebugLines.h
Expand Up @@ -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();
};
3 changes: 2 additions & 1 deletion src/debug/ElementPopulation.cpp
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/debug/ElementPopulation.h
Expand Up @@ -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();
};
8 changes: 4 additions & 4 deletions src/gui/game/GameController.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -743,7 +742,8 @@ void GameController::Tick()
}
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
{
(*iter)->Draw();
if ((*iter)->ID & debugFlags)
(*iter)->Draw();
}
commandInterface->OnTick();
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/game/GameController.h
Expand Up @@ -46,6 +46,7 @@ class GameController: public ClientListener
OptionsController * options;
CommandInterface * commandInterface;
vector<DebugInfo*> debugInfo;
unsigned int debugFlags;
public:
bool HasDone;
class SearchCallback;
Expand Down Expand Up @@ -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<Menu*> GetMenuList();
Tool * GetActiveTool(int selection);
Expand Down
4 changes: 3 additions & 1 deletion src/lua/LegacyLuaAPI.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 32328ad

Please sign in to comment.