mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-30 19:29:52 +02:00
Element population histogram debug info display - has to be enabled by adding debugInfo.push_back(new ElementPopulationDebug(gameModel->GetSimulation())); somewhere in GameController
This commit is contained in:
9
src/debug/DebugInfo.h
Normal file
9
src/debug/DebugInfo.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "interface/Point.h"
|
||||||
|
|
||||||
|
class DebugInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Draw(ui::Point position) {}
|
||||||
|
};
|
84
src/debug/ElementPopulation.cpp
Normal file
84
src/debug/ElementPopulation.cpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ElementPopulation.h"
|
||||||
|
#include "interface/Engine.h"
|
||||||
|
#include "simulation/Simulation.h"
|
||||||
|
#include "Format.h"
|
||||||
|
|
||||||
|
ElementPopulationDebug::ElementPopulationDebug(Simulation * sim):
|
||||||
|
sim(sim),
|
||||||
|
maxAverage(255.0f)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementPopulationDebug::Draw(ui::Point position)
|
||||||
|
{
|
||||||
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
//g->drawtext(10, 10, "Arse", 255, 255, 255, 255);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
ElementPopulationDebug::~ElementPopulationDebug()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
14
src/debug/ElementPopulation.h
Normal file
14
src/debug/ElementPopulation.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DebugInfo.h"
|
||||||
|
|
||||||
|
class Simulation;
|
||||||
|
class ElementPopulationDebug : public DebugInfo
|
||||||
|
{
|
||||||
|
Simulation * sim;
|
||||||
|
float maxAverage;
|
||||||
|
public:
|
||||||
|
ElementPopulationDebug(Simulation * sim);
|
||||||
|
virtual void Draw(ui::Point position);
|
||||||
|
virtual ~ElementPopulationDebug();
|
||||||
|
};
|
@@ -25,6 +25,8 @@
|
|||||||
#include "save/ServerSaveActivity.h"
|
#include "save/ServerSaveActivity.h"
|
||||||
#include "interface/Keys.h"
|
#include "interface/Keys.h"
|
||||||
#include "simulation/Snapshot.h"
|
#include "simulation/Snapshot.h"
|
||||||
|
#include "debug/DebugInfo.h"
|
||||||
|
//#include "debug/ElementPopulation.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -145,6 +147,8 @@ GameController::GameController():
|
|||||||
|
|
||||||
//sim = new Simulation();
|
//sim = new Simulation();
|
||||||
Client::Ref().AddListener(this);
|
Client::Ref().AddListener(this);
|
||||||
|
|
||||||
|
//debugInfo.push_back(new ElementPopulationDebug(gameModel->GetSimulation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController::~GameController()
|
GameController::~GameController()
|
||||||
@@ -677,6 +681,10 @@ void GameController::Tick()
|
|||||||
((LuaScriptInterface*)commandInterface)->Init();
|
((LuaScriptInterface*)commandInterface)->Init();
|
||||||
firstTick = false;
|
firstTick = false;
|
||||||
}
|
}
|
||||||
|
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
|
||||||
|
{
|
||||||
|
(*iter)->Draw(ui::Point(10, 10));
|
||||||
|
}
|
||||||
commandInterface->OnTick();
|
commandInterface->OnTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
class DebugInfo;
|
||||||
class Notification;
|
class Notification;
|
||||||
class GameModel;
|
class GameModel;
|
||||||
class GameView;
|
class GameView;
|
||||||
@@ -44,6 +45,7 @@ private:
|
|||||||
LocalBrowserController * localBrowser;
|
LocalBrowserController * localBrowser;
|
||||||
OptionsController * options;
|
OptionsController * options;
|
||||||
CommandInterface * commandInterface;
|
CommandInterface * commandInterface;
|
||||||
|
vector<DebugInfo*> debugInfo;
|
||||||
public:
|
public:
|
||||||
bool HasDone;
|
bool HasDone;
|
||||||
class SearchCallback;
|
class SearchCallback;
|
||||||
|
Reference in New Issue
Block a user