Expose debug constants to lua

Also clean up related resource management code a bit.
This commit is contained in:
Tamás Bálint Misius 2023-10-22 09:28:09 +02:00
parent ac99fb8a11
commit dda3e8a9c7
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
3 changed files with 29 additions and 15 deletions

View File

@ -92,10 +92,10 @@ 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 DebugLines(0x4, gameView, this));
debugInfo.push_back(new ParticleDebug(0x8, gameModel->GetSimulation(), gameModel));
debugInfo.push_back(std::make_unique<DebugParts >(DEBUG_PARTS , gameModel->GetSimulation()));
debugInfo.push_back(std::make_unique<ElementPopulationDebug>(DEBUG_ELEMENTPOP, gameModel->GetSimulation()));
debugInfo.push_back(std::make_unique<DebugLines >(DEBUG_LINES , gameView, this));
debugInfo.push_back(std::make_unique<ParticleDebug >(DEBUG_PARTICLE , gameModel->GetSimulation(), gameModel));
}
GameController::~GameController()
@ -132,10 +132,7 @@ GameController::~GameController()
{
delete options;
}
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
{
delete *iter;
}
debugInfo.clear();
std::vector<QuickOption*> quickOptions = gameModel->GetQuickOptions();
for(std::vector<QuickOption*>::iterator iter = quickOptions.begin(), end = quickOptions.end(); iter != end; ++iter)
{
@ -645,13 +642,17 @@ bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool c
}
}
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
for (auto &debug : debugInfo)
{
if (debug->debugID & debugFlags)
{
if (!debug->KeyPress(key, scan, shift, ctrl, alt, gameView->GetMousePosition()))
{
if ((*iter)->debugID & debugFlags)
if (!(*iter)->KeyPress(key, scan, shift, ctrl, alt, gameView->GetMousePosition()))
ret = false;
}
}
}
}
return ret;
}
@ -715,10 +716,12 @@ void GameController::Tick()
gameModel->SetActiveTool(gameModel->SelectNextTool, gameModel->GetToolFromIdentifier(gameModel->SelectNextIdentifier));
gameModel->SelectNextIdentifier.clear();
}
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
for (auto &debug : debugInfo)
{
if ((*iter)->debugID & debugFlags)
(*iter)->Draw();
if (debug->debugID & debugFlags)
{
debug->Draw();
}
}
commandInterface->OnTick();
}

View File

@ -11,6 +11,11 @@
#include <utility>
#include <memory>
constexpr auto DEBUG_PARTS = 0x0001;
constexpr auto DEBUG_ELEMENTPOP = 0x0002;
constexpr auto DEBUG_LINES = 0x0004;
constexpr auto DEBUG_PARTICLE = 0x0008;
class DebugInfo;
class SaveFile;
class Notification;
@ -47,7 +52,7 @@ private:
TagsController * tagsWindow;
LocalBrowserController * localBrowser;
OptionsController * options;
std::vector<DebugInfo*> debugInfo;
std::vector<std::unique_ptr<DebugInfo>> debugInfo;
std::unique_ptr<Snapshot> beforeRestore;
unsigned int debugFlags;

View File

@ -512,6 +512,12 @@ tpt.partsdata = nil");
}
lua_setfield(l, tptProperties, "eltransition");
SETCONST(l, DEBUG_PARTS);
SETCONST(l, DEBUG_ELEMENTPOP);
SETCONST(l, DEBUG_LINES);
SETCONST(l, DEBUG_PARTICLE);
SETCONST(l, DEBUG_SURFNORM);
lua_gr_func_v = std::vector<LuaSmartRef>(PT_NUM);
lua_gr_func = &lua_gr_func_v[0];
lua_el_func_v = std::vector<LuaSmartRef>(PT_NUM);