From 07ce8a414871fb0ff4622cc6dd2c411455e375c0 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 5 Apr 2025 12:09:19 -0400 Subject: [PATCH] New debug_ui that shows perf data, other debug info, and allows spawning enemies. --- combat_ui.cpp | 4 +++ combat_ui.hpp | 1 + events.hpp | 2 +- guecs.hpp | 9 +++++-- gui_fsm.cpp | 29 ++++++++++++++------ gui_fsm.hpp | 2 ++ main_ui.cpp | 67 +++------------------------------------------- main_ui.hpp | 6 ++--- meson.build | 3 ++- overlay_ui.cpp | 8 +++--- overlay_ui.hpp | 2 -- tools/arena_ui.cpp | 2 +- 12 files changed, 49 insertions(+), 86 deletions(-) diff --git a/combat_ui.cpp b/combat_ui.cpp index 1676661..ca47b1e 100644 --- a/combat_ui.cpp +++ b/combat_ui.cpp @@ -44,4 +44,8 @@ namespace gui { $level = level; init(); } + + bool CombatUI::mouse(float x, float y) { + return $gui.mouse(x, y); + } } diff --git a/combat_ui.hpp b/combat_ui.hpp index 906f414..a0cbc56 100644 --- a/combat_ui.hpp +++ b/combat_ui.hpp @@ -16,5 +16,6 @@ namespace gui { void render(sf::RenderWindow& window); void update_level(GameLevel &level); void set_damage(float percent); + bool mouse(float x, float y); }; } diff --git a/events.hpp b/events.hpp index a561c13..8a470ae 100644 --- a/events.hpp +++ b/events.hpp @@ -3,7 +3,7 @@ namespace Events { enum GUI { START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP, - COMBAT_START, NO_NEIGHBORS, ATTACK, UPDATE_SPRITE, NOOP + COMBAT_START, NO_NEIGHBORS, ATTACK, UPDATE_SPRITE, ENEMY_SPAWN, NOOP }; struct Combat { diff --git a/guecs.hpp b/guecs.hpp index 6947953..841dc03 100644 --- a/guecs.hpp +++ b/guecs.hpp @@ -142,8 +142,13 @@ namespace guecs { $world.set(ent, val); } - lel::Cell& cell_for(DinkyECS::Entity entity) { - return $world.get(entity); + lel::Cell& cell_for(DinkyECS::Entity ent) { + return $world.get(ent); + } + + lel::Cell& cell_for(std::string name) { + DinkyECS::Entity ent = entity(name); + return $world.get(ent); } template diff --git a/gui_fsm.cpp b/gui_fsm.cpp index 5557041..9c7d277 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -15,6 +15,7 @@ namespace gui { FSM::FSM() : $window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"), + $debug_ui($levels), $main_ui($window), $level($levels.current()), $combat_ui($level), @@ -43,6 +44,12 @@ namespace gui { $main_ui.update_level($level); $level.world->set_the({}); $main_ui.init(); + + // BUG: maybe this is a function on main_ui? + auto cell = $main_ui.$overlay_ui.$gui.cell_for("left"); + $debug_ui.init(cell); + $debug_ui.update_level($level); + $combat_ui.init(); $status_ui.init(); @@ -234,7 +241,8 @@ namespace gui { event(Event::STAIRS_DOWN); } } else { - $combat_ui.$gui.mouse(pos.x, pos.y); + $debug_ui.mouse(pos.x, pos.y); + $combat_ui.mouse(pos.x, pos.y); $status_ui.mouse(pos.x, pos.y); $main_ui.mouse(pos.x, pos.y); } @@ -264,7 +272,7 @@ namespace gui { event(Event::MOVE_LEFT); break; case KEY::R: - $main_ui.$stats.reset(); + dbc::log("HEY! DIPSHIT! You need to move debug ui so you can rest stats."); break; case KEY::M: event(Event::MAP_OPEN); @@ -277,16 +285,11 @@ namespace gui { break; case KEY::P: sound::mute(false); - $main_ui.debug(); + $debug_ui.debug(); break; case KEY::O: autowalking = true; break; - case KEY::Equal: - $levels.spawn_enemy("KNIGHT"); - $main_ui.update_level($level); - run_systems(); - break; case KEY::L: event(Event::STAIRS_DOWN); break; @@ -301,7 +304,11 @@ namespace gui { if(in_state(State::NEXT_LEVEL)) { $boss_fight_ui->render($window); } else { + // BUG: maybe pass the stats to main_ui for this? + auto start = $debug_ui.time_start(); $main_ui.render(); + $debug_ui.sample_time(start); + $debug_ui.render($window); $status_ui.render($window); $combat_ui.render($window); if($map_open) { @@ -365,6 +372,11 @@ namespace gui { case eGUI::COMBAT_START: event(Event::START_COMBAT); break; + case eGUI::ENEMY_SPAWN: + $debug_ui.update_level($level); + $main_ui.update_level($level); + run_systems(); + break; case eGUI::NO_NEIGHBORS: event(Event::STOP_COMBAT); break; @@ -402,6 +414,7 @@ namespace gui { $levels.create_level($level.world); $level = $levels.next(); + $debug_ui.update_level($level); $status_ui.update_level($level); $map_ui.update_level($level); $mini_map.update_level($level); diff --git a/gui_fsm.hpp b/gui_fsm.hpp index ea1c8cb..e6667d2 100644 --- a/gui_fsm.hpp +++ b/gui_fsm.hpp @@ -3,6 +3,7 @@ #include "stats.hpp" #include "levelmanager.hpp" #include "fsm.hpp" +#include "debug_ui.hpp" #include "main_ui.hpp" #include "combat_ui.hpp" #include "status_ui.hpp" @@ -48,6 +49,7 @@ namespace gui { bool autowalking = false; bool $map_open = false; LevelManager $levels; + DebugUI $debug_ui; MainUI $main_ui; GameLevel $level; shared_ptr $boss_fight_ui = nullptr; diff --git a/main_ui.cpp b/main_ui.cpp index ece4108..3baa1f9 100644 --- a/main_ui.cpp +++ b/main_ui.cpp @@ -18,58 +18,6 @@ namespace gui { $needs_render = true; } - void MainUI::debug() { - auto& dbg = $level.world->get_the(); - dbg.FPS = !dbg.FPS; - dbg.PATHS = !dbg.PATHS; - - if(dbg.FPS) { - // it's on now, enable things - auto player = $level.world->get_the(); - auto& player_combat = $level.world->get(player.entity); - player_combat.hp = player_combat.max_hp; - $overlay_ui.show_text("top_left", L"STATS"); - } else { - // it's off now, close it - $overlay_ui.close_text("top_left"); - } - } - - void MainUI::draw_stats() { - auto player = $level.world->get_the(); - auto player_combat = $level.world->get(player.entity); - auto map = $level.map; - std::wstring stats = fmt::format(L"STATS\n" - L"HP: {}\n" - L"mean:{:>8.5}\n" - L"sdev: {:>8.5}\n" - L"min: {:>8.5}\n" - L"max: {:>8.5}\n" - L"count:{:<10}\n" - L"level: {} size: {}x{}\n\n" - L"dir: {:0.2},{:0.2}\n\n" - L"VSync? {}\n" - L"FR Limit: {}\n" - L"Debug? {}\n\n", - player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min, - $stats.max, $stats.n, $level.index, map->width(), map->height(), - $rayview.$dir_x, $rayview.$dir_y, - VSYNC, FRAME_LIMIT, DEBUG_BUILD); - - $overlay_ui.show_text("top_left", stats); - } - - void MainUI::draw_blood() { - auto player = $level.world->get_the(); - auto player_combat = $level.world->get(player.entity); - - if(float(player_combat.hp) / float(player_combat.max_hp) < 0.5) { - $overlay_ui.show_sprite("middle", "blood_splatter"); - } else { - $overlay_ui.close_sprite("middle"); - } - } - void MainUI::init() { auto& player_position = $level.world->get($level.player); auto player = player_position.location; @@ -78,7 +26,7 @@ namespace gui { $rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y); $rayview.position_camera(player.x + 0.5, player.y + 0.5); - $overlay_ui.show_label("top_left", $compass[$compass_dir]); + $overlay_ui.show_text("left", $compass[$compass_dir]); auto st = textures::get("down_the_well"); auto bounds = st.sprite->getLocalBounds(); @@ -94,7 +42,6 @@ namespace gui { } void MainUI::render() { - auto start = $stats.time_start(); if($show_level) { auto time = $clock.getElapsedTime(); @@ -110,14 +57,7 @@ namespace gui { $rayview.draw($window); } - $stats.sample_time(start); - $overlay_ui.render($window); - - auto debug = $level.world->get_the(); - if(debug.FPS) draw_stats(); - - // draw_blood(); } bool MainUI::play_rotate() { @@ -144,7 +84,7 @@ namespace gui { void MainUI::plan_rotate(int dir) { // -1 is left, 1 is right $compass_dir = ($compass_dir + dir) % $compass.size(); - $overlay_ui.show_label("top_left", $compass[$compass_dir]); + $overlay_ui.show_text("left", $compass[$compass_dir]); $camera.plan_rotate($rayview, dir); } @@ -170,7 +110,8 @@ namespace gui { $rayview.position_camera(player.x + 0.5, player.y + 0.5); $compass_dir = 0; - $overlay_ui.show_label("top_left", $compass[$compass_dir]); + $overlay_ui.show_text("left", $compass[$compass_dir]); + dirty(); } diff --git a/main_ui.hpp b/main_ui.hpp index fd67a09..52faee0 100644 --- a/main_ui.hpp +++ b/main_ui.hpp @@ -4,9 +4,11 @@ #include #include "stats.hpp" #include "overlay_ui.hpp" +#include "debug_ui.hpp" #include "raycaster.hpp" #include "camera.hpp" #include +#include "guecs.hpp" namespace gui { @@ -18,7 +20,6 @@ namespace gui { }; bool $show_level = false; bool $needs_render = true; - Stats $stats; sf::Clock $clock; sf::RenderWindow& $window; GameLevel $level; @@ -30,8 +31,7 @@ namespace gui { void mouse(int x, int y); void debug(); - void draw_stats(); - void draw_blood(); + void render_debug(); void plan_rotate(int dir); bool play_rotate(); diff --git a/meson.build b/meson.build index f4a0bff..911c118 100644 --- a/meson.build +++ b/meson.build @@ -91,6 +91,7 @@ sources = [ 'components.cpp', 'config.cpp', 'dbc.cpp', + 'debug_ui.cpp', 'devices.cpp', 'goap.cpp', 'guecs.cpp', @@ -102,9 +103,9 @@ sources = [ 'main_ui.cpp', 'map.cpp', 'map_view.cpp', - 'mini_map.cpp', 'matrix.cpp', 'matrix.cpp', + 'mini_map.cpp', 'overlay_ui.cpp', 'pathing.cpp', 'rand.cpp', diff --git a/overlay_ui.cpp b/overlay_ui.cpp index a1d30dc..94977e2 100644 --- a/overlay_ui.cpp +++ b/overlay_ui.cpp @@ -10,11 +10,9 @@ namespace gui { OverlayUI::OverlayUI() { $gui.position(RAY_VIEW_X, RAY_VIEW_Y, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT); $gui.layout( - "[top_left|top|>(170)top_right]" - "[*%(300,300)middle|_|_]" - "[_|_|_]" - "[_|_|_]" - "[bottom_left|bottom|bottom_right]" + "[*%(100,300)left|top|>(170,170)top_right]" + "[_|middle|middle_right]" + "[_|bottom|bottom_right]" ); } diff --git a/overlay_ui.hpp b/overlay_ui.hpp index be3f252..76873d0 100644 --- a/overlay_ui.hpp +++ b/overlay_ui.hpp @@ -1,5 +1,4 @@ #pragma once -#include "levelmanager.hpp" #include #include #include "guecs.hpp" @@ -13,7 +12,6 @@ namespace gui { void init(); void render(sf::RenderWindow& window); - void click(int x, int y); void show_sprite(string region, string sprite_name); void close_sprite(string region); void show_text(std::string region, std::wstring content); diff --git a/tools/arena_ui.cpp b/tools/arena_ui.cpp index d38a6ff..447e4ce 100644 --- a/tools/arena_ui.cpp +++ b/tools/arena_ui.cpp @@ -21,7 +21,7 @@ namespace arena { $overlay.position(BOSS_VIEW_X, BOSS_VIEW_Y, BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT); - $overlay.layout("[_|=*%(200)enemy|_|_]"); + $overlay.layout("[_|=(256,256)enemy|_]"); $sounds = $world->get($entity_id); $combat = $world->get($entity_id);