Skip to content

Commit

Permalink
also add back DebugParts
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Sep 28, 2014
1 parent 32328ad commit 717408c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/debug/DebugLines.cpp
Expand Up @@ -3,15 +3,15 @@
#include "gui/game/GameView.h"
#include "gui/game/GameController.h"

LineDebug::LineDebug(unsigned int id, GameView * view, GameController * controller):
DebugLines::DebugLines(unsigned int id, GameView * view, GameController * controller):
DebugInfo(id),
view(view),
controller(controller)
{

}

void LineDebug::Draw()
void DebugLines::Draw()
{
Graphics * g = ui::Engine::Ref().g;

Expand All @@ -28,7 +28,7 @@ void LineDebug::Draw()
g->draw_line(0, drawPoint2.Y, XRES, drawPoint2.Y, 255, 255, 255, 120);
g->draw_line(drawPoint2.X, 0, drawPoint2.X, YRES, 255, 255, 255, 120);

stringstream info;
std::stringstream info;
info << drawPoint2.X << " x " << drawPoint2.Y;
g->drawtext_outline(drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-g->textwidth(info.str().c_str())-3), drawPoint2.Y+(drawPoint2.Y<drawPoint1.Y?-10:3), info.str().c_str(), 255, 255, 255, 200);

Expand All @@ -46,7 +46,7 @@ void LineDebug::Draw()
}
}

LineDebug::~LineDebug()
DebugLines::~DebugLines()
{

}
6 changes: 3 additions & 3 deletions src/debug/DebugLines.h
Expand Up @@ -4,12 +4,12 @@

class GameView;
class GameController;
class LineDebug : public DebugInfo
class DebugLines : public DebugInfo
{
GameView * view;
GameController * controller;
public:
LineDebug(unsigned int id, GameView * view, GameController * controller);
DebugLines(unsigned int id, GameView * view, GameController * controller);
virtual void Draw();
virtual ~LineDebug();
virtual ~DebugLines();
};
55 changes: 55 additions & 0 deletions src/debug/DebugParts.cpp
@@ -0,0 +1,55 @@
#include "DebugParts.h"
#include "gui/interface/Engine.h"
#include "simulation/Simulation.h"
#include <iomanip>

DebugParts::DebugParts(unsigned int id, Simulation * sim):
DebugInfo(id),
sim(sim)
{

}

void DebugParts::Draw()
{
Graphics * g = ui::Engine::Ref().g;

int x = 0, y = 0, lpx = 0, lpy = 0;
std::stringstream info;
info << sim->parts_lastActiveIndex << "/" << NPART << " (" << std::fixed << std::setprecision(2) << (float)sim->parts_lastActiveIndex/(NPART)*100.0f << "%)";
for (int i = 0; i < NPART; i++)
{
if (sim->parts[i].type)
g->addpixel(x, y, 255, 255, 255, 180);
else
g->addpixel(x, y, 0, 0, 0, 180);

if (i == sim->parts_lastActiveIndex)
{
lpx = x;
lpy = y;
}
x++;
if(x >= XRES)
{
y++;
x = 0;
}
}
g->draw_line(0, lpy, XRES, lpy, 0, 255, 120, 255);
g->draw_line(lpx, 0, lpx, YRES, 0, 255, 120, 255);
g->addpixel(lpx, lpy, 255, 50, 50, 220);

g->addpixel(lpx+1, lpy, 255, 50, 50, 120);
g->addpixel(lpx-1, lpy, 255, 50, 50, 120);
g->addpixel(lpx, lpy+1, 255, 50, 50, 120);
g->addpixel(lpx, lpy-1, 255, 50, 50, 120);

g->fillrect(7, YRES-26, g->textwidth(info.str().c_str())+5, 14, 0, 0, 0, 180);
g->drawtext(10, YRES-22, info.str().c_str(), 255, 255, 255, 255);
}

DebugParts::~DebugParts()
{

}
13 changes: 13 additions & 0 deletions src/debug/DebugParts.h
@@ -0,0 +1,13 @@
#pragma once

#include "DebugInfo.h"

class Simulation;
class DebugParts : public DebugInfo
{
Simulation * sim;
public:
DebugParts(unsigned int id, Simulation * sim);
virtual void Draw();
virtual ~DebugParts();
};
4 changes: 3 additions & 1 deletion src/gui/game/GameController.cpp
Expand Up @@ -26,6 +26,7 @@
#include "gui/interface/Keys.h"
#include "simulation/Snapshot.h"
#include "debug/DebugInfo.h"
#include "debug/DebugParts.h"
#include "debug/ElementPopulation.h"
#include "debug/DebugLines.h"
#ifdef LUACONSOLE
Expand Down Expand Up @@ -155,8 +156,9 @@ GameController::GameController():

Client::Ref().AddListener(this);

debugInfo.push_back(new DebugParts(0x1, gameModel->GetSimulation()));
debugInfo.push_back(new ElementPopulationDebug(0x2, gameModel->GetSimulation()));
debugInfo.push_back(new LineDebug(0x4, gameView, this));
debugInfo.push_back(new DebugLines(0x4, gameView, this));
}

GameController::~GameController()
Expand Down

0 comments on commit 717408c

Please sign in to comment.