From a20d7010965554212975c19502d625860add6a46 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Wed, 20 Aug 2025 23:20:36 -0400 Subject: [PATCH] Rename to GameDB and GameDB::Level. --- autowalker.cpp | 22 ++++++------ game_level.cpp | 88 +++++++++++++++++++++------------------------ game_level.hpp | 29 ++++++++------- gui/combat_ui.cpp | 2 +- gui/debug_ui.cpp | 4 +-- gui/fsm.cpp | 16 ++++----- gui/guecstra.cpp | 4 +-- gui/loot_ui.cpp | 6 ++-- gui/main_ui.cpp | 10 +++--- gui/main_ui.hpp | 1 - gui/map_view.cpp | 4 +-- gui/overlay_ui.cpp | 2 +- gui/ritual_ui.cpp | 6 ++-- gui/status_ui.cpp | 10 +++--- main.cpp | 2 +- raycaster.cpp | 2 +- raycaster.hpp | 4 +-- systems.cpp | 56 ++++++++++++++--------------- tests/lighting.cpp | 4 +-- tests/map.cpp | 12 +++---- tests/matrix.cpp | 6 ++-- tools/arena_fsm.cpp | 1 + tools/arena_fsm.hpp | 2 -- 23 files changed, 142 insertions(+), 151 deletions(-) diff --git a/autowalker.cpp b/autowalker.cpp index a3ec249..84fde14 100644 --- a/autowalker.cpp +++ b/autowalker.cpp @@ -7,9 +7,9 @@ template int number_left() { int count = 0; - Game::current_world()->query( + GameDB::current_world()->query( [&](const auto ent, auto&, auto&) { - if(ent != Game::current().player) { + if(ent != GameDB::current().player) { count++; } }); @@ -19,15 +19,15 @@ int number_left() { template Pathing compute_paths() { - auto& walls_original = Game::current().map->$walls; + auto& walls_original = GameDB::current().map->$walls; auto walls_copy = walls_original; Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)}; - Game::current().world->query( + GameDB::current().world->query( [&](const auto ent, auto& position) { - if(ent != Game::current().player) { - if(Game::current().world->has(ent)) { + if(ent != GameDB::current().player) { + if(GameDB::current().world->has(ent)) { paths.set_target(position.location); } else { // this will mark that spot as a wall so we don't path there temporarily @@ -89,7 +89,7 @@ void Autowalker::process_combat() { } Point Autowalker::get_current_position() { - return Game::player_position().location; + return GameDB::player_position().location; } void Autowalker::path_fail(Matrix& bad_paths, Point pos) { @@ -110,7 +110,7 @@ bool Autowalker::path_player(Pathing& paths, Point& target_out) { } } - if(!Game::current().map->can_move(target_out)) { + if(!GameDB::current().map->can_move(target_out)) { path_fail(paths.$paths, target_out); return false; } @@ -330,7 +330,7 @@ void Autowalker::process_move(Pathing& paths) { // what are we aiming at? auto aimed_at = fsm.$main_ui.camera_aim(); - if(aimed_at && Game::current_world()->has(aimed_at)) { + if(aimed_at && GameDB::current_world()->has(aimed_at)) { // NOTE: if we're aiming at an item then pick it up // for now just loot it then close to get it off the map send_event(gui::Event::LOOT_ITEM); @@ -349,8 +349,8 @@ void Autowalker::send_event(gui::Event ev) { } bool Autowalker::player_health_good() { - auto world = Game::current_world(); - auto combat = world->get(Game::the_player()); + auto world = GameDB::current_world(); + auto combat = world->get(GameDB::the_player()); return float(combat.hp) / float(combat.max_hp) > 0.5f; } diff --git a/game_level.cpp b/game_level.cpp index 62daa8e..caa1905 100644 --- a/game_level.cpp +++ b/game_level.cpp @@ -16,12 +16,6 @@ struct LevelScaling { int map_height=20; }; -struct LevelManager { - public: - std::vector levels; - size_t current_level = 0; -}; - inline shared_ptr clone_load_world(shared_ptr prev_world) { auto world = make_shared(); @@ -35,10 +29,16 @@ inline shared_ptr clone_load_world(shared_ptr return world; } -namespace Game { +namespace GameDB { using std::shared_ptr, std::string, std::make_shared; - shared_ptr LMGR; + struct LevelDB { + public: + std::vector levels; + size_t current_level = 0; + }; + + shared_ptr LDB; bool initialized = false; void init() { @@ -46,7 +46,7 @@ namespace Game { textures::init(); if(!initialized) { - LMGR = make_shared(); + LDB = make_shared(); initialized = true; new_level(NULL); } @@ -54,18 +54,18 @@ namespace Game { LevelScaling scale_level() { return { - INITIAL_MAP_W + int(LMGR->current_level * 2), - INITIAL_MAP_H + int(LMGR->current_level * 2) + INITIAL_MAP_W + int(LDB->current_level * 2), + INITIAL_MAP_H + int(LDB->current_level * 2) }; } shared_ptr current_world() { - dbc::check(initialized, "Forgot to call Game::init()"); + dbc::check(initialized, "Forgot to call GameDB::init()"); return current().world; } shared_ptr create_bossfight() { - dbc::check(initialized, "Forgot to call Game::init()"); + dbc::check(initialized, "Forgot to call GameDB::init()"); auto prev_world = current_world(); dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null."); auto world = clone_load_world(prev_world); @@ -73,7 +73,7 @@ namespace Game { // BUG: the jank is too strong here auto boss_names = config.bosses.keys(); - auto& level_name = boss_names[LMGR->current_level % boss_names.size()]; + auto& level_name = boss_names[LDB->current_level % boss_names.size()]; auto& boss_data = config.bosses[level_name]; auto boss_id = world->entity(); @@ -83,7 +83,7 @@ namespace Game { } size_t new_level(std::shared_ptr prev_world) { - dbc::check(initialized, "Forgot to call Game::init()"); + dbc::check(initialized, "Forgot to call GameDB::init()"); auto world = clone_load_world(prev_world); auto scaling = scale_level(); @@ -94,71 +94,65 @@ namespace Game { WorldBuilder builder(*map, *collision); builder.generate(*world); - size_t index = LMGR->levels.size(); + size_t index = LDB->levels.size(); auto player = world->get_the(); - LMGR->levels.emplace_back(index, player.entity, map, world, + LDB->levels.emplace_back(index, player.entity, map, world, make_shared(map->tiles()), collision); - dbc::check(index == LMGR->levels.size() - 1, "Level index is not the same as LMGR->levels.size() - 1, off by one error"); + dbc::check(index == LDB->levels.size() - 1, "Level index is not the same as LDB->levels.size() - 1, off by one error"); return index; } - GameLevel& create_level() { + Level& create_level() { dbc::log("current_level"); size_t level = new_level(current_world()); - dbc::check(level == LMGR->current_level + 1, "new level index is wrong"); + dbc::check(level == LDB->current_level + 1, "new level index is wrong"); auto& the_level = next(); - dbc::check(level == LMGR->current_level, "level didn't update?!"); + dbc::check(level == LDB->current_level, "level didn't update?!"); return the_level; } - GameLevel &next() { - dbc::check(initialized, "Forgot to call Game::init()"); - dbc::check(LMGR->current_level < LMGR->levels.size(), "attempt to get next level when at end"); - LMGR->current_level++; - return LMGR->levels.at(LMGR->current_level); + Level &next() { + dbc::check(initialized, "Forgot to call GameDB::init()"); + dbc::check(LDB->current_level < LDB->levels.size(), "attempt to get next level when at end"); + LDB->current_level++; + return LDB->levels.at(LDB->current_level); } - GameLevel &previous() { - dbc::check(initialized, "Forgot to call Game::init()"); - dbc::check(LMGR->current_level > 0, "attempt to go to previous level when at 0"); - LMGR->current_level--; - return LMGR->levels.at(LMGR->current_level); + Level &previous() { + dbc::check(initialized, "Forgot to call GameDB::init()"); + dbc::check(LDB->current_level > 0, "attempt to go to previous level when at 0"); + LDB->current_level--; + return LDB->levels.at(LDB->current_level); } - GameLevel ¤t() { - dbc::check(initialized, "Forgot to call Game::init()"); - return LMGR->levels.at(LMGR->current_level); + Level ¤t() { + dbc::check(initialized, "Forgot to call GameDB::init()"); + return LDB->levels.at(LDB->current_level); } size_t current_index() { - dbc::check(initialized, "Forgot to call Game::init()"); - return LMGR->current_level; - } - - GameLevel &get(size_t index) { - dbc::check(initialized, "Forgot to call Game::init()"); - return LMGR->levels.at(index); + dbc::check(initialized, "Forgot to call GameDB::init()"); + return LDB->current_level; } - DinkyECS::Entity spawn_enemy(const std::string& named) { - (void)named; - dbc::check(initialized, "Forgot to call Game::init()"); - dbc::sentinel("THIS IS BROKEN"); + Level &get(size_t index) { + dbc::check(initialized, "Forgot to call GameDB::init()"); + return LDB->levels.at(index); } components::Position& player_position() { - dbc::check(initialized, "Forgot to call Game::init()"); + dbc::check(initialized, "Forgot to call GameDB::init()"); auto world = current_world(); auto& player = world->get_the(); return world->get(player.entity); } DinkyECS::Entity the_player() { - dbc::check(initialized, "Forgot to call Game::init()"); + dbc::check(initialized, "Forgot to call GameDB::init()"); return current().player; } } diff --git a/game_level.hpp b/game_level.hpp index 9dbee73..82cf82c 100644 --- a/game_level.hpp +++ b/game_level.hpp @@ -12,29 +12,28 @@ namespace components { struct Position; } -struct GameLevel { - size_t index; - DinkyECS::Entity player; - std::shared_ptr map = nullptr; - std::shared_ptr world = nullptr; - std::shared_ptr lights = nullptr; - std::shared_ptr collision = nullptr; -}; +namespace GameDB { + struct Level { + size_t index; + DinkyECS::Entity player; + std::shared_ptr map = nullptr; + std::shared_ptr world = nullptr; + std::shared_ptr lights = nullptr; + std::shared_ptr collision = nullptr; + }; -namespace Game { std::shared_ptr create_bossfight(); size_t new_level(std::shared_ptr prev_world); - GameLevel& create_level(); + Level& create_level(); void init(); - GameLevel &next(); - GameLevel &previous(); - GameLevel ¤t(); + Level &next(); + Level &previous(); + Level ¤t(); size_t current_index(); std::shared_ptr current_world(); - GameLevel &get(size_t index); - DinkyECS::Entity spawn_enemy(const std::string& named); + Level &get(size_t index); components::Position& player_position(); DinkyECS::Entity the_player(); } diff --git a/gui/combat_ui.cpp b/gui/combat_ui.cpp index 8713333..1f351fc 100644 --- a/gui/combat_ui.cpp +++ b/gui/combat_ui.cpp @@ -37,7 +37,7 @@ namespace gui { } void CombatUI::init() { - auto world = Game::current_world(); + auto world = GameDB::current_world(); using guecs::THEME; $gui.set($gui.MAIN, {$gui.$parser, THEME.DARK_MID}); auto& the_belt = world->get_the(); diff --git a/gui/debug_ui.cpp b/gui/debug_ui.cpp index 6380d8f..98e4b6c 100644 --- a/gui/debug_ui.cpp +++ b/gui/debug_ui.cpp @@ -46,7 +46,7 @@ namespace gui { void DebugUI::render(sf::RenderWindow& window) { if(active) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto player = level.world->get_the(); auto player_combat = level.world->get(player.entity); auto map = level.map; @@ -76,7 +76,7 @@ namespace gui { active = !active; if(active) { - auto& level = Game::current(); + auto& level = GameDB::current(); // it's on now, enable things auto player = level.world->get_the(); auto& player_combat = level.world->get(player.entity); diff --git a/gui/fsm.cpp b/gui/fsm.cpp index ae766ea..48b8166 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -53,7 +53,7 @@ namespace gui { $combat_ui.init(); $status_ui.init(); - $boss_fight_ui = Game::create_bossfight(); + $boss_fight_ui = GameDB::create_bossfight(); $boss_fight_ui->init(); $map_ui.init(); @@ -96,7 +96,7 @@ namespace gui { void FSM::ROTATING(Event) { if(auto aim = $main_ui.play_rotate()) { - auto& player_pos = Game::player_position(); + auto& player_pos = GameDB::player_position(); player_pos.aiming_at = *aim; state(State::IDLE); } @@ -104,7 +104,7 @@ namespace gui { void FSM::COMBAT_ROTATE(Event) { if(auto aim = $main_ui.play_rotate()) { - auto& player_pos = Game::player_position(); + auto& player_pos = GameDB::player_position(); player_pos.aiming_at = *aim; state(State::IN_COMBAT); } @@ -267,7 +267,7 @@ namespace gui { } void FSM::try_move(int dir, bool strafe) { - auto& level = Game::current(); + auto& level = GameDB::current(); using enum State; // prevent moving into occupied space Point move_to = $main_ui.plan_move(dir, strafe); @@ -356,7 +356,7 @@ namespace gui { event(Event::LOOT_OPEN); break; case KEY::Z: { - auto& player_pos = Game::player_position(); + auto& player_pos = GameDB::player_position(); System::distribute_loot({player_pos.aiming_at}); } break; case KEY::X: @@ -430,7 +430,7 @@ namespace gui { void FSM::handle_world_events() { using eGUI = Events::GUI; - auto world = Game::current_world(); + auto world = GameDB::current_world(); while(world->has_event()) { auto [evt, entity, data] = world->recv(); @@ -540,14 +540,14 @@ namespace gui { void FSM::next_level() { dbc::log("current_level: Yep, next is called..."); - Game::create_level(); + GameDB::create_level(); $status_ui.update_level(); $combat_ui.update_level(); $main_ui.update_level(); $loot_ui.update_level(); - $boss_fight_ui = Game::create_bossfight(); + $boss_fight_ui = GameDB::create_bossfight(); $boss_fight_ui->init(); run_systems(); diff --git a/gui/guecstra.cpp b/gui/guecstra.cpp index 6967210..9358cf8 100644 --- a/gui/guecstra.cpp +++ b/gui/guecstra.cpp @@ -5,14 +5,14 @@ namespace guecs { Clickable make_action(guecs::Entity gui_id, Events::GUI event) { return {[&, gui_id, event](auto){ - auto world = Game::current_world(); + auto world = GameDB::current_world(); world->send(event, gui_id, {}); }}; } Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data) { return {[&, event, data](auto){ - auto world = Game::current_world(); + auto world = GameDB::current_world(); world->send(event, gui_id, data); }}; } diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index 1ffe6c7..86df098 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -8,7 +8,7 @@ namespace gui { using namespace guecs; LootUI::LootUI() : - $temp_loot(Game::current_world()->entity()), + $temp_loot(GameDB::current_world()->entity()), $target($temp_loot) { $gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200, @@ -21,7 +21,7 @@ namespace gui { "[=item_12| =item_13|=item_14|=item_15 ]" "[ =take_all | =close| =destroy]"); - auto world = Game::current_world(); + auto world = GameDB::current_world(); world->set($temp_loot, {}); world->make_constant($temp_loot); } @@ -62,7 +62,7 @@ namespace gui { } void LootUI::update() { - auto world = Game::current_world(); + auto world = GameDB::current_world(); dbc::check(world->has($target), "update called but $target isn't in world"); diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 5aa2cd1..fe7f353 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -21,7 +21,7 @@ namespace gui { } void MainUI::init() { - auto& player_position = Game::player_position(); + auto& player_position = GameDB::player_position(); auto player = player_position.location; $rayview->init_shaders(); @@ -32,7 +32,7 @@ namespace gui { } DinkyECS::Entity MainUI::camera_aim() { - auto& level = Game::current(); + auto& level = GameDB::current(); // what happens if there's two things at that spot if(level.collision->something_there($rayview->aiming_at)) { return level.collision->get($rayview->aiming_at); @@ -90,7 +90,7 @@ namespace gui { } void MainUI::dead_entity(DinkyECS::Entity entity) { - auto world = Game::current_world(); + auto world = GameDB::current_world(); if(world->has(entity)) { auto &sprite = world->get(entity); $rayview->update_sprite(entity, sprite); @@ -98,8 +98,8 @@ namespace gui { } void MainUI::update_level() { - auto& level = Game::current(); - auto& player_position = Game::player_position(); + auto& level = GameDB::current(); + auto& player_position = GameDB::player_position(); auto player = player_position.location; $rayview->update_level(level); diff --git a/gui/main_ui.hpp b/gui/main_ui.hpp index 0382595..fde4ab4 100644 --- a/gui/main_ui.hpp +++ b/gui/main_ui.hpp @@ -16,7 +16,6 @@ namespace gui { bool $needs_render = true; sf::Clock $clock; sf::RenderWindow& $window; - GameLevel $level; OverlayUI $overlay_ui; std::shared_ptr $rayview; diff --git a/gui/map_view.cpp b/gui/map_view.cpp index d6cf196..3dcf99a 100644 --- a/gui/map_view.cpp +++ b/gui/map_view.cpp @@ -26,8 +26,8 @@ namespace gui { $map_sprite($map_render->getTexture()), $map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT)) { - auto world = Game::current_world(); - auto player = Game::the_player(); + auto world = GameDB::current_world(); + auto player = GameDB::the_player(); $player_display = world->get(player).display; } diff --git a/gui/overlay_ui.cpp b/gui/overlay_ui.cpp index 313eabe..cf9016c 100644 --- a/gui/overlay_ui.cpp +++ b/gui/overlay_ui.cpp @@ -23,7 +23,7 @@ namespace gui { gui.set(area, { [&](auto) { - auto world = Game::current_world(); + auto world = GameDB::current_world(); world->send(Events::GUI::AIM_CLICK, area, {}); } }); diff --git a/gui/ritual_ui.cpp b/gui/ritual_ui.cpp index ae8d389..e535bc5 100644 --- a/gui/ritual_ui.cpp +++ b/gui/ritual_ui.cpp @@ -185,8 +185,8 @@ namespace gui { } void UI::complete_combine() { - auto world = Game::current_world(); - auto player = Game::the_player(); + auto world = GameDB::current_world(); + auto player = GameDB::the_player(); if($craft_state.is_combined()) { auto ritual = $ritual_engine.finalize($craft_state); @@ -249,7 +249,7 @@ namespace gui { } ::ritual::Blanket& UI::blanket() { - auto world = Game::current_world(); + auto world = GameDB::current_world(); return world->get_the<::ritual::Blanket>(); } } diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index 54b6cb5..d0f65ce 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -74,7 +74,7 @@ namespace gui { } void StatusUI::update() { - auto world = Game::current_world(); + auto world = GameDB::current_world(); auto player = world->get_the(); auto& inventory = world->get(player.entity); @@ -112,7 +112,7 @@ namespace gui { } bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& slot_name = $gui.name_for(gui_id); auto& inventory = level.world->get(level.player); @@ -133,7 +133,7 @@ namespace gui { // NOTE: do I need this or how does it relate to drop_item? void StatusUI::remove_slot(guecs::Entity slot_id) { - auto player = Game::the_player(); + auto player = GameDB::the_player(); auto& slot_name = $gui.name_for(slot_id); System::remove_from_container(player, slot_name); update(); @@ -141,7 +141,7 @@ namespace gui { void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) { if(gui_a != gui_b) { - auto player = Game::the_player(); + auto player = GameDB::the_player(); auto& a_name = $gui.name_for(gui_a); auto& b_name = $gui.name_for(gui_b); System::inventory_swap(player, a_name, b_name); @@ -151,7 +151,7 @@ namespace gui { } bool StatusUI::occupied(guecs::Entity slot) { - auto player = Game::the_player(); + auto player = GameDB::the_player(); return System::inventory_occupied(player, $gui.name_for(slot)); } } diff --git a/main.cpp b/main.cpp index 003b34a..20ee840 100644 --- a/main.cpp +++ b/main.cpp @@ -16,7 +16,7 @@ int main(int argc, char* argv[]) { guecs::init(&backend); ai::init("assets/ai.json"); animation::init(); - Game::init(); + GameDB::init(); if(DEBUG_BUILD) sound::mute(true); diff --git a/raycaster.cpp b/raycaster.cpp index 582ca14..9f7c13c 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -422,7 +422,7 @@ void Raycaster::update_sprite(DinkyECS::Entity ent, components::Sprite& sprite) $sprites.insert_or_assign(ent, sprite_txt); } -void Raycaster::update_level(GameLevel level) { +void Raycaster::update_level(GameDB::Level& level) { $sprites.clear(); $sprite_order.clear(); diff --git a/raycaster.hpp b/raycaster.hpp index 6a73f86..b9e7bff 100644 --- a/raycaster.hpp +++ b/raycaster.hpp @@ -38,7 +38,7 @@ struct Raycaster { std::unordered_map $sprites; SortedEntities $sprite_order; - GameLevel $level; + GameDB::Level $level; Matrix $tiles; Matrix $walls; std::vector $zbuffer; // width @@ -59,7 +59,7 @@ struct Raycaster { return ((y) * $width) + (x); } - void update_level(GameLevel level); + void update_level(GameDB::Level& level); void update_sprite(DinkyECS::Entity ent, components::Sprite& sprite); void init_shaders(); void apply_sprite_effect(std::shared_ptr effect, float width, float height); diff --git a/systems.cpp b/systems.cpp index 59fb222..fb7f6f8 100644 --- a/systems.cpp +++ b/systems.cpp @@ -33,7 +33,7 @@ void System::set_position(World& world, SpatialMap& collision, Entity entity, Po } void System::lighting() { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& light = *level.lights; auto& world = *level.world; auto& map = *level.map; @@ -57,15 +57,15 @@ void System::lighting() { } void System::generate_paths() { - auto& level = Game::current(); - const auto &player_pos = Game::player_position(); + auto& level = GameDB::current(); + const auto &player_pos = GameDB::player_position(); level.map->set_target(player_pos.location); level.map->make_paths(); } void System::enemy_ai_initialize() { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; auto& map = *level.map; @@ -93,10 +93,10 @@ void System::enemy_ai_initialize() { } void System::enemy_pathing() { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; auto& map = *level.map; - const auto &player_pos = Game::player_position(); + const auto &player_pos = GameDB::player_position(); world.query([&](auto ent, auto &position, auto &motion) { if(ent != level.player) { @@ -135,7 +135,7 @@ inline void move_entity(SpatialMap &collider, Map &game_map, Position &position, } void System::motion() { - auto& level = Game::current(); + auto& level = GameDB::current(); level.world->query( [&](auto ent, auto &position, auto &motion) { // don't process entities that don't move @@ -146,7 +146,7 @@ void System::motion() { } void System::distribute_loot(Position target_pos) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; auto& config = world.get_the(); int inventory_count = Random::uniform(0, 3); @@ -171,7 +171,7 @@ void System::distribute_loot(Position target_pos) { } void System::death() { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; auto player = world.get_the(); std::vector dead_things; @@ -229,7 +229,7 @@ inline void animate_entity(World &world, Entity entity) { } void System::combat(int attack_id) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& collider = *level.collision; auto& world = *level.world; auto& the_belt = world.get_the(); @@ -237,7 +237,7 @@ void System::combat(int attack_id) { if(!the_belt.has(attack_id)) return; auto& ritual = the_belt.get(attack_id); - const auto& player_pos = Game::player_position(); + const auto& player_pos = GameDB::player_position(); auto& player_combat = world.get(level.player); // this is guaranteed to not return the given position @@ -286,10 +286,10 @@ void System::combat(int attack_id) { void System::collision() { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& collider = *level.collision; auto& world = *level.world; - const auto& player_pos = Game::player_position(); + const auto& player_pos = GameDB::player_position(); // this is guaranteed to not return the given position auto [found, nearby] = collider.neighbors(player_pos.location); @@ -319,7 +319,7 @@ void System::collision() { * from the world for say, putting into a container or inventory. */ void System::remove_from_world(Entity entity) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& item_pos = level.world->get(entity); level.collision->remove(item_pos.location, entity); // if you don't do this you get the bug that you can pickup @@ -328,10 +328,10 @@ void System::remove_from_world(Entity entity) { } void System::pickup() { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; auto& collision = *level.collision; - auto pos = Game::player_position(); + auto pos = GameDB::player_position(); if(!collision.something_there(pos.aiming_at)) return; @@ -393,8 +393,8 @@ void System::device(World &world, Entity actor, Entity item) { } void System::plan_motion(Position move_to) { - auto& level = Game::current(); - auto& player_pos = Game::player_position(); + auto& level = GameDB::current(); + auto& player_pos = GameDB::player_position(); player_pos.aiming_at = move_to.aiming_at; @@ -405,7 +405,7 @@ void System::plan_motion(Position move_to) { void System::player_status() { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& combat = level.world->get(level.player); float percent = float(combat.hp) / float(combat.max_hp); @@ -423,7 +423,7 @@ void System::player_status() { } std::shared_ptr System::sprite_effect(Entity entity) { - auto world = Game::current_world(); + auto world = GameDB::current_world(); if(world->has(entity)) { auto& se = world->get(entity); @@ -450,10 +450,10 @@ Entity System::spawn_item(World& world, const std::string& name) { } void System::drop_item(Entity item) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; auto& map = *level.map; - auto player_pos = Game::player_position(); + auto player_pos = GameDB::player_position(); dbc::check(map.can_move(player_pos.location), "impossible, the player can't be in a wall"); @@ -470,7 +470,7 @@ void System::drop_item(Entity item) { // NOTE: I think pickup and this need to be different bool System::place_in_container(Entity cont_id, const std::string& name, Entity world_entity) { - auto world = Game::current_world(); + auto world = GameDB::current_world(); auto& container = world->get(cont_id); if(container.has(world_entity)) { @@ -490,7 +490,7 @@ bool System::place_in_container(Entity cont_id, const std::string& name, Entity } void System::remove_from_container(Entity cont_id, const std::string& slot_id) { - auto world = Game::current_world(); + auto world = GameDB::current_world(); auto& container = world->get(cont_id); auto entity = container.get(slot_id); container.remove(entity); @@ -498,7 +498,7 @@ void System::remove_from_container(Entity cont_id, const std::string& slot_id) { void System::inventory_swap(Entity container_id, const std::string& a_name, const std::string &b_name) { - auto& level = Game::current(); + auto& level = GameDB::current(); dbc::check(a_name != b_name, "Attempt to inventory swap the same slot, you should check this and avoid calling me."); auto& inventory = level.world->get(container_id); @@ -509,14 +509,14 @@ void System::inventory_swap(Entity container_id, const std::string& a_name, cons } bool System::inventory_occupied(Entity container_id, const std::string& name) { - auto world = Game::current_world(); + auto world = GameDB::current_world(); auto& inventory = world->get(container_id); return inventory.has(name); } void System::draw_map(Matrix& grid, EntityGrid& entity_map) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; Map &map = *level.map; Matrix &fow = level.lights->$fow; @@ -606,7 +606,7 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture } bool System::use_item(const string& slot_name) { - auto& level = Game::current(); + auto& level = GameDB::current(); auto& world = *level.world; auto& inventory = world.get(level.player); auto& player_combat = world.get(level.player); diff --git a/tests/lighting.cpp b/tests/lighting.cpp index a30e3d2..d72cb3c 100644 --- a/tests/lighting.cpp +++ b/tests/lighting.cpp @@ -10,8 +10,8 @@ using namespace lighting; TEST_CASE("lighting a map works", "[lighting]") { - Game::init(); - auto& level = Game::current(); + GameDB::init(); + auto& level = GameDB::current(); auto& map = *level.map; Point light1, light2; diff --git a/tests/map.cpp b/tests/map.cpp index d6bcf5e..e669901 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -16,9 +16,9 @@ json load_test_data(const string &fname) { } TEST_CASE("camera control", "[map]") { - Game::init(); + GameDB::init(); - auto& level = Game::current(); + auto& level = GameDB::current(); auto& map = *level.map; Point center = map.center_camera({10,10}, 5, 5); @@ -34,10 +34,10 @@ TEST_CASE("camera control", "[map]") { } TEST_CASE("map placement test", "[map-fail]") { - Game::init(); + GameDB::init(); for(int i = 0; i < 5; i++) { - auto& level = Game::create_level(); + auto& level = GameDB::create_level(); for(size_t rnum = 0; rnum < level.map->room_count(); rnum++) { Point pos; @@ -79,9 +79,9 @@ TEST_CASE("dijkstra algo test", "[map]") { } TEST_CASE("map image test", "[map]") { - Game::init(); + GameDB::init(); - auto& level = Game::current(); + auto& level = GameDB::current(); Matrix map_tiles = matrix::make(7,7); EntityGrid entity_map; diff --git a/tests/matrix.cpp b/tests/matrix.cpp index 745c55d..aa4d9bb 100644 --- a/tests/matrix.cpp +++ b/tests/matrix.cpp @@ -16,8 +16,8 @@ using std::string, std::shared_ptr; using matrix::Matrix; std::shared_ptr make_map() { - Game::init(); - return Game::current().map; + GameDB::init(); + return GameDB::current().map; } TEST_CASE("basic matrix iterator", "[matrix]") { @@ -259,7 +259,7 @@ TEST_CASE("prototype circle algorithm", "[matrix]") { TEST_CASE("viewport iterator", "[matrix]") { components::init(); textures::init(); - Game::init(); + GameDB::init(); size_t width = Random::uniform(20, 22); size_t height = Random::uniform(21, 25); shared_ptr map = make_map(); diff --git a/tools/arena_fsm.cpp b/tools/arena_fsm.cpp index 90c8ecf..6219070 100644 --- a/tools/arena_fsm.cpp +++ b/tools/arena_fsm.cpp @@ -31,6 +31,7 @@ namespace arena { void FSM::START(Event ) { run_systems(); + dbc::sentinel("THIS IS FUCKED"); $level = $level_mgr.current(); auto entity_id = $level_mgr.spawn_enemy($enemy_name); diff --git a/tools/arena_fsm.hpp b/tools/arena_fsm.hpp index 1f6acce..40d4afd 100644 --- a/tools/arena_fsm.hpp +++ b/tools/arena_fsm.hpp @@ -29,8 +29,6 @@ namespace arena { std::string $enemy_name; sf::RenderWindow $window; sf::Font $font; - LevelManager $level_mgr; - GameLevel $level; shared_ptr $arena_ui = nullptr; FSM(std::string enemy_name);