feat: added debug information toggle to UI

This commit is contained in:
Sara Gerretsen 2025-09-22 13:35:23 +02:00
parent 847c0bded5
commit 34a289d36b
3 changed files with 8 additions and 0 deletions

View file

@ -69,6 +69,7 @@ static void PrimaryControls() {
if (!isSimulating) { if (!isSimulating) {
elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton); elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton);
} }
elements::Toggle(CLAY_STRING("Debug Info"), style::actionButton, simulation::drawDebugInfo);
} }
} }
} }

View file

@ -9,6 +9,8 @@
#include <vector> #include <vector>
namespace simulation { namespace simulation {
bool drawDebugInfo{ true };
static std::set<Cell> living{}; static std::set<Cell> living{};
static std::vector<Cell> overpopulated{}; static std::vector<Cell> overpopulated{};
static std::vector<Cell> underpopulated{}; static std::vector<Cell> underpopulated{};
@ -145,6 +147,9 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
cellRect.y = (viewOffset.y + cell.y) * cellRect.h; cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
SDL_RenderFillRect(renderer, &cellRect); SDL_RenderFillRect(renderer, &cellRect);
} }
if (!drawDebugInfo) {
return;
}
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
for (Cell const &cell : overpopulated) { for (Cell const &cell : overpopulated) {
cellRect.x = (viewOffset.x + cell.x) * cellRect.w; cellRect.x = (viewOffset.x + cell.x) * cellRect.w;

View file

@ -33,6 +33,8 @@ public: CellRange(Cell begin, Cell end) : beginCell{ begin }, endCell{ end } {}
CellIterator end() { return CellIterator{ beginCell, endCell, endCell }; } CellIterator end() { return CellIterator{ beginCell, endCell, endCell }; }
}; };
extern bool drawDebugInfo;
void InitializeRandom(size_t livingChance, int64_t fillArea); void InitializeRandom(size_t livingChance, int64_t fillArea);
void Step(); void Step();
void Draw(SDL_Renderer *renderer, double cellSizePercent); void Draw(SDL_Renderer *renderer, double cellSizePercent);