Rename to GameDB and GameDB::Level.

master
Zed A. Shaw 5 days ago
parent c46927ea10
commit a20d701096
  1. 22
      autowalker.cpp
  2. 88
      game_level.cpp
  3. 19
      game_level.hpp
  4. 2
      gui/combat_ui.cpp
  5. 4
      gui/debug_ui.cpp
  6. 16
      gui/fsm.cpp
  7. 4
      gui/guecstra.cpp
  8. 6
      gui/loot_ui.cpp
  9. 10
      gui/main_ui.cpp
  10. 1
      gui/main_ui.hpp
  11. 4
      gui/map_view.cpp
  12. 2
      gui/overlay_ui.cpp
  13. 6
      gui/ritual_ui.cpp
  14. 10
      gui/status_ui.cpp
  15. 2
      main.cpp
  16. 2
      raycaster.cpp
  17. 4
      raycaster.hpp
  18. 56
      systems.cpp
  19. 4
      tests/lighting.cpp
  20. 12
      tests/map.cpp
  21. 6
      tests/matrix.cpp
  22. 1
      tools/arena_fsm.cpp
  23. 2
      tools/arena_fsm.hpp

@ -7,9 +7,9 @@ template<typename Comp>
int number_left() { int number_left() {
int count = 0; int count = 0;
Game::current_world()->query<components::Position, Comp>( GameDB::current_world()->query<components::Position, Comp>(
[&](const auto ent, auto&, auto&) { [&](const auto ent, auto&, auto&) {
if(ent != Game::current().player) { if(ent != GameDB::current().player) {
count++; count++;
} }
}); });
@ -19,15 +19,15 @@ int number_left() {
template<typename Comp> template<typename Comp>
Pathing compute_paths() { Pathing compute_paths() {
auto& walls_original = Game::current().map->$walls; auto& walls_original = GameDB::current().map->$walls;
auto walls_copy = walls_original; auto walls_copy = walls_original;
Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)}; Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)};
Game::current().world->query<components::Position>( GameDB::current().world->query<components::Position>(
[&](const auto ent, auto& position) { [&](const auto ent, auto& position) {
if(ent != Game::current().player) { if(ent != GameDB::current().player) {
if(Game::current().world->has<Comp>(ent)) { if(GameDB::current().world->has<Comp>(ent)) {
paths.set_target(position.location); paths.set_target(position.location);
} else { } else {
// this will mark that spot as a wall so we don't path there temporarily // 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() { Point Autowalker::get_current_position() {
return Game::player_position().location; return GameDB::player_position().location;
} }
void Autowalker::path_fail(Matrix& bad_paths, Point pos) { 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); path_fail(paths.$paths, target_out);
return false; return false;
} }
@ -330,7 +330,7 @@ void Autowalker::process_move(Pathing& paths) {
// what are we aiming at? // what are we aiming at?
auto aimed_at = fsm.$main_ui.camera_aim(); auto aimed_at = fsm.$main_ui.camera_aim();
if(aimed_at && Game::current_world()->has<components::InventoryItem>(aimed_at)) { if(aimed_at && GameDB::current_world()->has<components::InventoryItem>(aimed_at)) {
// NOTE: if we're aiming at an item then pick it up // 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 // for now just loot it then close to get it off the map
send_event(gui::Event::LOOT_ITEM); send_event(gui::Event::LOOT_ITEM);
@ -349,8 +349,8 @@ void Autowalker::send_event(gui::Event ev) {
} }
bool Autowalker::player_health_good() { bool Autowalker::player_health_good() {
auto world = Game::current_world(); auto world = GameDB::current_world();
auto combat = world->get<components::Combat>(Game::the_player()); auto combat = world->get<components::Combat>(GameDB::the_player());
return float(combat.hp) / float(combat.max_hp) > 0.5f; return float(combat.hp) / float(combat.max_hp) > 0.5f;
} }

@ -16,12 +16,6 @@ struct LevelScaling {
int map_height=20; int map_height=20;
}; };
struct LevelManager {
public:
std::vector<GameLevel> levels;
size_t current_level = 0;
};
inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world) inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world)
{ {
auto world = make_shared<DinkyECS::World>(); auto world = make_shared<DinkyECS::World>();
@ -35,10 +29,16 @@ inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World>
return world; return world;
} }
namespace Game { namespace GameDB {
using std::shared_ptr, std::string, std::make_shared; using std::shared_ptr, std::string, std::make_shared;
shared_ptr<LevelManager> LMGR; struct LevelDB {
public:
std::vector<GameDB::Level> levels;
size_t current_level = 0;
};
shared_ptr<LevelDB> LDB;
bool initialized = false; bool initialized = false;
void init() { void init() {
@ -46,7 +46,7 @@ namespace Game {
textures::init(); textures::init();
if(!initialized) { if(!initialized) {
LMGR = make_shared<LevelManager>(); LDB = make_shared<LevelDB>();
initialized = true; initialized = true;
new_level(NULL); new_level(NULL);
} }
@ -54,18 +54,18 @@ namespace Game {
LevelScaling scale_level() { LevelScaling scale_level() {
return { return {
INITIAL_MAP_W + int(LMGR->current_level * 2), INITIAL_MAP_W + int(LDB->current_level * 2),
INITIAL_MAP_H + int(LMGR->current_level * 2) INITIAL_MAP_H + int(LDB->current_level * 2)
}; };
} }
shared_ptr<DinkyECS::World> current_world() { shared_ptr<DinkyECS::World> current_world() {
dbc::check(initialized, "Forgot to call Game::init()"); dbc::check(initialized, "Forgot to call GameDB::init()");
return current().world; return current().world;
} }
shared_ptr<gui::BossFightUI> create_bossfight() { shared_ptr<gui::BossFightUI> create_bossfight() {
dbc::check(initialized, "Forgot to call Game::init()"); dbc::check(initialized, "Forgot to call GameDB::init()");
auto prev_world = current_world(); auto prev_world = current_world();
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null."); dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
auto world = clone_load_world(prev_world); auto world = clone_load_world(prev_world);
@ -73,7 +73,7 @@ namespace Game {
// BUG: the jank is too strong here // BUG: the jank is too strong here
auto boss_names = config.bosses.keys(); 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_data = config.bosses[level_name];
auto boss_id = world->entity(); auto boss_id = world->entity();
@ -83,7 +83,7 @@ namespace Game {
} }
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world) { size_t new_level(std::shared_ptr<DinkyECS::World> 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 world = clone_load_world(prev_world);
auto scaling = scale_level(); auto scaling = scale_level();
@ -94,71 +94,65 @@ namespace Game {
WorldBuilder builder(*map, *collision); WorldBuilder builder(*map, *collision);
builder.generate(*world); builder.generate(*world);
size_t index = LMGR->levels.size(); size_t index = LDB->levels.size();
auto player = world->get_the<Player>(); auto player = world->get_the<Player>();
LMGR->levels.emplace_back(index, player.entity, map, world, LDB->levels.emplace_back(index, player.entity, map, world,
make_shared<LightRender>(map->tiles()), collision); make_shared<LightRender>(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; return index;
} }
GameLevel& create_level() { Level& create_level() {
dbc::log("current_level"); dbc::log("current_level");
size_t level = new_level(current_world()); 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(); 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; return the_level;
} }
GameLevel &next() { Level &next() {
dbc::check(initialized, "Forgot to call Game::init()"); dbc::check(initialized, "Forgot to call GameDB::init()");
dbc::check(LMGR->current_level < LMGR->levels.size(), "attempt to get next level when at end"); dbc::check(LDB->current_level < LDB->levels.size(), "attempt to get next level when at end");
LMGR->current_level++; LDB->current_level++;
return LMGR->levels.at(LMGR->current_level); return LDB->levels.at(LDB->current_level);
} }
GameLevel &previous() { Level &previous() {
dbc::check(initialized, "Forgot to call Game::init()"); dbc::check(initialized, "Forgot to call GameDB::init()");
dbc::check(LMGR->current_level > 0, "attempt to go to previous level when at 0"); dbc::check(LDB->current_level > 0, "attempt to go to previous level when at 0");
LMGR->current_level--; LDB->current_level--;
return LMGR->levels.at(LMGR->current_level); return LDB->levels.at(LDB->current_level);
} }
GameLevel &current() { Level &current() {
dbc::check(initialized, "Forgot to call Game::init()"); dbc::check(initialized, "Forgot to call GameDB::init()");
return LMGR->levels.at(LMGR->current_level); return LDB->levels.at(LDB->current_level);
} }
size_t current_index() { size_t current_index() {
dbc::check(initialized, "Forgot to call Game::init()"); dbc::check(initialized, "Forgot to call GameDB::init()");
return LMGR->current_level; return LDB->current_level;
}
GameLevel &get(size_t index) {
dbc::check(initialized, "Forgot to call Game::init()");
return LMGR->levels.at(index);
} }
DinkyECS::Entity spawn_enemy(const std::string& named) { Level &get(size_t index) {
(void)named; dbc::check(initialized, "Forgot to call GameDB::init()");
dbc::check(initialized, "Forgot to call Game::init()"); return LDB->levels.at(index);
dbc::sentinel("THIS IS BROKEN");
} }
components::Position& player_position() { 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 world = current_world();
auto& player = world->get_the<components::Player>(); auto& player = world->get_the<components::Player>();
return world->get<components::Position>(player.entity); return world->get<components::Position>(player.entity);
} }
DinkyECS::Entity the_player() { DinkyECS::Entity the_player() {
dbc::check(initialized, "Forgot to call Game::init()"); dbc::check(initialized, "Forgot to call GameDB::init()");
return current().player; return current().player;
} }
} }

@ -12,29 +12,28 @@ namespace components {
struct Position; struct Position;
} }
struct GameLevel {
namespace GameDB {
struct Level {
size_t index; size_t index;
DinkyECS::Entity player; DinkyECS::Entity player;
std::shared_ptr<Map> map = nullptr; std::shared_ptr<Map> map = nullptr;
std::shared_ptr<DinkyECS::World> world = nullptr; std::shared_ptr<DinkyECS::World> world = nullptr;
std::shared_ptr<lighting::LightRender> lights = nullptr; std::shared_ptr<lighting::LightRender> lights = nullptr;
std::shared_ptr<SpatialMap> collision = nullptr; std::shared_ptr<SpatialMap> collision = nullptr;
}; };
namespace Game {
std::shared_ptr<gui::BossFightUI> create_bossfight(); std::shared_ptr<gui::BossFightUI> create_bossfight();
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world); size_t new_level(std::shared_ptr<DinkyECS::World> prev_world);
GameLevel& create_level(); Level& create_level();
void init(); void init();
GameLevel &next(); Level &next();
GameLevel &previous(); Level &previous();
GameLevel &current(); Level &current();
size_t current_index(); size_t current_index();
std::shared_ptr<DinkyECS::World> current_world(); std::shared_ptr<DinkyECS::World> current_world();
GameLevel &get(size_t index); Level &get(size_t index);
DinkyECS::Entity spawn_enemy(const std::string& named);
components::Position& player_position(); components::Position& player_position();
DinkyECS::Entity the_player(); DinkyECS::Entity the_player();
} }

@ -37,7 +37,7 @@ namespace gui {
} }
void CombatUI::init() { void CombatUI::init() {
auto world = Game::current_world(); auto world = GameDB::current_world();
using guecs::THEME; using guecs::THEME;
$gui.set<Background>($gui.MAIN, {$gui.$parser, THEME.DARK_MID}); $gui.set<Background>($gui.MAIN, {$gui.$parser, THEME.DARK_MID});
auto& the_belt = world->get_the<ritual::Belt>(); auto& the_belt = world->get_the<ritual::Belt>();

@ -46,7 +46,7 @@ namespace gui {
void DebugUI::render(sf::RenderWindow& window) { void DebugUI::render(sf::RenderWindow& window) {
if(active) { if(active) {
auto& level = Game::current(); auto& level = GameDB::current();
auto player = level.world->get_the<components::Player>(); auto player = level.world->get_the<components::Player>();
auto player_combat = level.world->get<components::Combat>(player.entity); auto player_combat = level.world->get<components::Combat>(player.entity);
auto map = level.map; auto map = level.map;
@ -76,7 +76,7 @@ namespace gui {
active = !active; active = !active;
if(active) { if(active) {
auto& level = Game::current(); auto& level = GameDB::current();
// it's on now, enable things // it's on now, enable things
auto player = level.world->get_the<components::Player>(); auto player = level.world->get_the<components::Player>();
auto& player_combat = level.world->get<components::Combat>(player.entity); auto& player_combat = level.world->get<components::Combat>(player.entity);

@ -53,7 +53,7 @@ namespace gui {
$combat_ui.init(); $combat_ui.init();
$status_ui.init(); $status_ui.init();
$boss_fight_ui = Game::create_bossfight(); $boss_fight_ui = GameDB::create_bossfight();
$boss_fight_ui->init(); $boss_fight_ui->init();
$map_ui.init(); $map_ui.init();
@ -96,7 +96,7 @@ namespace gui {
void FSM::ROTATING(Event) { void FSM::ROTATING(Event) {
if(auto aim = $main_ui.play_rotate()) { if(auto aim = $main_ui.play_rotate()) {
auto& player_pos = Game::player_position(); auto& player_pos = GameDB::player_position();
player_pos.aiming_at = *aim; player_pos.aiming_at = *aim;
state(State::IDLE); state(State::IDLE);
} }
@ -104,7 +104,7 @@ namespace gui {
void FSM::COMBAT_ROTATE(Event) { void FSM::COMBAT_ROTATE(Event) {
if(auto aim = $main_ui.play_rotate()) { if(auto aim = $main_ui.play_rotate()) {
auto& player_pos = Game::player_position(); auto& player_pos = GameDB::player_position();
player_pos.aiming_at = *aim; player_pos.aiming_at = *aim;
state(State::IN_COMBAT); state(State::IN_COMBAT);
} }
@ -267,7 +267,7 @@ namespace gui {
} }
void FSM::try_move(int dir, bool strafe) { void FSM::try_move(int dir, bool strafe) {
auto& level = Game::current(); auto& level = GameDB::current();
using enum State; using enum State;
// prevent moving into occupied space // prevent moving into occupied space
Point move_to = $main_ui.plan_move(dir, strafe); Point move_to = $main_ui.plan_move(dir, strafe);
@ -356,7 +356,7 @@ namespace gui {
event(Event::LOOT_OPEN); event(Event::LOOT_OPEN);
break; break;
case KEY::Z: { case KEY::Z: {
auto& player_pos = Game::player_position(); auto& player_pos = GameDB::player_position();
System::distribute_loot({player_pos.aiming_at}); System::distribute_loot({player_pos.aiming_at});
} break; } break;
case KEY::X: case KEY::X:
@ -430,7 +430,7 @@ namespace gui {
void FSM::handle_world_events() { void FSM::handle_world_events() {
using eGUI = Events::GUI; using eGUI = Events::GUI;
auto world = Game::current_world(); auto world = GameDB::current_world();
while(world->has_event<eGUI>()) { while(world->has_event<eGUI>()) {
auto [evt, entity, data] = world->recv<eGUI>(); auto [evt, entity, data] = world->recv<eGUI>();
@ -540,14 +540,14 @@ namespace gui {
void FSM::next_level() { void FSM::next_level() {
dbc::log("current_level: Yep, next is called..."); dbc::log("current_level: Yep, next is called...");
Game::create_level(); GameDB::create_level();
$status_ui.update_level(); $status_ui.update_level();
$combat_ui.update_level(); $combat_ui.update_level();
$main_ui.update_level(); $main_ui.update_level();
$loot_ui.update_level(); $loot_ui.update_level();
$boss_fight_ui = Game::create_bossfight(); $boss_fight_ui = GameDB::create_bossfight();
$boss_fight_ui->init(); $boss_fight_ui->init();
run_systems(); run_systems();

@ -5,14 +5,14 @@ namespace guecs {
Clickable make_action(guecs::Entity gui_id, Events::GUI event) { Clickable make_action(guecs::Entity gui_id, Events::GUI event) {
return {[&, gui_id, event](auto){ return {[&, gui_id, event](auto){
auto world = Game::current_world(); auto world = GameDB::current_world();
world->send<Events::GUI>(event, gui_id, {}); world->send<Events::GUI>(event, gui_id, {});
}}; }};
} }
Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data) { Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data) {
return {[&, event, data](auto){ return {[&, event, data](auto){
auto world = Game::current_world(); auto world = GameDB::current_world();
world->send<Events::GUI>(event, gui_id, data); world->send<Events::GUI>(event, gui_id, data);
}}; }};
} }

@ -8,7 +8,7 @@ namespace gui {
using namespace guecs; using namespace guecs;
LootUI::LootUI() : LootUI::LootUI() :
$temp_loot(Game::current_world()->entity()), $temp_loot(GameDB::current_world()->entity()),
$target($temp_loot) $target($temp_loot)
{ {
$gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200, $gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200,
@ -21,7 +21,7 @@ namespace gui {
"[=item_12| =item_13|=item_14|=item_15 ]" "[=item_12| =item_13|=item_14|=item_15 ]"
"[ =take_all | =close| =destroy]"); "[ =take_all | =close| =destroy]");
auto world = Game::current_world(); auto world = GameDB::current_world();
world->set<inventory::Model>($temp_loot, {}); world->set<inventory::Model>($temp_loot, {});
world->make_constant($temp_loot); world->make_constant($temp_loot);
} }
@ -62,7 +62,7 @@ namespace gui {
} }
void LootUI::update() { void LootUI::update() {
auto world = Game::current_world(); auto world = GameDB::current_world();
dbc::check(world->has<inventory::Model>($target), dbc::check(world->has<inventory::Model>($target),
"update called but $target isn't in world"); "update called but $target isn't in world");

@ -21,7 +21,7 @@ namespace gui {
} }
void MainUI::init() { void MainUI::init() {
auto& player_position = Game::player_position(); auto& player_position = GameDB::player_position();
auto player = player_position.location; auto player = player_position.location;
$rayview->init_shaders(); $rayview->init_shaders();
@ -32,7 +32,7 @@ namespace gui {
} }
DinkyECS::Entity MainUI::camera_aim() { DinkyECS::Entity MainUI::camera_aim() {
auto& level = Game::current(); auto& level = GameDB::current();
// what happens if there's two things at that spot // what happens if there's two things at that spot
if(level.collision->something_there($rayview->aiming_at)) { if(level.collision->something_there($rayview->aiming_at)) {
return level.collision->get($rayview->aiming_at); return level.collision->get($rayview->aiming_at);
@ -90,7 +90,7 @@ namespace gui {
} }
void MainUI::dead_entity(DinkyECS::Entity entity) { void MainUI::dead_entity(DinkyECS::Entity entity) {
auto world = Game::current_world(); auto world = GameDB::current_world();
if(world->has<components::Sprite>(entity)) { if(world->has<components::Sprite>(entity)) {
auto &sprite = world->get<components::Sprite>(entity); auto &sprite = world->get<components::Sprite>(entity);
$rayview->update_sprite(entity, sprite); $rayview->update_sprite(entity, sprite);
@ -98,8 +98,8 @@ namespace gui {
} }
void MainUI::update_level() { void MainUI::update_level() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& player_position = Game::player_position(); auto& player_position = GameDB::player_position();
auto player = player_position.location; auto player = player_position.location;
$rayview->update_level(level); $rayview->update_level(level);

@ -16,7 +16,6 @@ namespace gui {
bool $needs_render = true; bool $needs_render = true;
sf::Clock $clock; sf::Clock $clock;
sf::RenderWindow& $window; sf::RenderWindow& $window;
GameLevel $level;
OverlayUI $overlay_ui; OverlayUI $overlay_ui;
std::shared_ptr<Raycaster> $rayview; std::shared_ptr<Raycaster> $rayview;

@ -26,8 +26,8 @@ namespace gui {
$map_sprite($map_render->getTexture()), $map_sprite($map_render->getTexture()),
$map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT)) $map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT))
{ {
auto world = Game::current_world(); auto world = GameDB::current_world();
auto player = Game::the_player(); auto player = GameDB::the_player();
$player_display = world->get<Tile>(player).display; $player_display = world->get<Tile>(player).display;
} }

@ -23,7 +23,7 @@ namespace gui {
gui.set<Clickable>(area, { gui.set<Clickable>(area, {
[&](auto) { [&](auto) {
auto world = Game::current_world(); auto world = GameDB::current_world();
world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {}); world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {});
} }
}); });

@ -185,8 +185,8 @@ namespace gui {
} }
void UI::complete_combine() { void UI::complete_combine() {
auto world = Game::current_world(); auto world = GameDB::current_world();
auto player = Game::the_player(); auto player = GameDB::the_player();
if($craft_state.is_combined()) { if($craft_state.is_combined()) {
auto ritual = $ritual_engine.finalize($craft_state); auto ritual = $ritual_engine.finalize($craft_state);
@ -249,7 +249,7 @@ namespace gui {
} }
::ritual::Blanket& UI::blanket() { ::ritual::Blanket& UI::blanket() {
auto world = Game::current_world(); auto world = GameDB::current_world();
return world->get_the<::ritual::Blanket>(); return world->get_the<::ritual::Blanket>();
} }
} }

@ -74,7 +74,7 @@ namespace gui {
} }
void StatusUI::update() { void StatusUI::update() {
auto world = Game::current_world(); auto world = GameDB::current_world();
auto player = world->get_the<components::Player>(); auto player = world->get_the<components::Player>();
auto& inventory = world->get<inventory::Model>(player.entity); auto& inventory = world->get<inventory::Model>(player.entity);
@ -112,7 +112,7 @@ namespace gui {
} }
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) { 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& slot_name = $gui.name_for(gui_id);
auto& inventory = level.world->get<inventory::Model>(level.player); auto& inventory = level.world->get<inventory::Model>(level.player);
@ -133,7 +133,7 @@ namespace gui {
// NOTE: do I need this or how does it relate to drop_item? // NOTE: do I need this or how does it relate to drop_item?
void StatusUI::remove_slot(guecs::Entity slot_id) { 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); auto& slot_name = $gui.name_for(slot_id);
System::remove_from_container(player, slot_name); System::remove_from_container(player, slot_name);
update(); update();
@ -141,7 +141,7 @@ namespace gui {
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) { void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
if(gui_a != 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& a_name = $gui.name_for(gui_a);
auto& b_name = $gui.name_for(gui_b); auto& b_name = $gui.name_for(gui_b);
System::inventory_swap(player, a_name, b_name); System::inventory_swap(player, a_name, b_name);
@ -151,7 +151,7 @@ namespace gui {
} }
bool StatusUI::occupied(guecs::Entity slot) { 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)); return System::inventory_occupied(player, $gui.name_for(slot));
} }
} }

@ -16,7 +16,7 @@ int main(int argc, char* argv[]) {
guecs::init(&backend); guecs::init(&backend);
ai::init("assets/ai.json"); ai::init("assets/ai.json");
animation::init(); animation::init();
Game::init(); GameDB::init();
if(DEBUG_BUILD) sound::mute(true); if(DEBUG_BUILD) sound::mute(true);

@ -422,7 +422,7 @@ void Raycaster::update_sprite(DinkyECS::Entity ent, components::Sprite& sprite)
$sprites.insert_or_assign(ent, sprite_txt); $sprites.insert_or_assign(ent, sprite_txt);
} }
void Raycaster::update_level(GameLevel level) { void Raycaster::update_level(GameDB::Level& level) {
$sprites.clear(); $sprites.clear();
$sprite_order.clear(); $sprite_order.clear();

@ -38,7 +38,7 @@ struct Raycaster {
std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites; std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites;
SortedEntities $sprite_order; SortedEntities $sprite_order;
GameLevel $level; GameDB::Level $level;
Matrix $tiles; Matrix $tiles;
Matrix $walls; Matrix $walls;
std::vector<double> $zbuffer; // width std::vector<double> $zbuffer; // width
@ -59,7 +59,7 @@ struct Raycaster {
return ((y) * $width) + (x); 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 update_sprite(DinkyECS::Entity ent, components::Sprite& sprite);
void init_shaders(); void init_shaders();
void apply_sprite_effect(std::shared_ptr<sf::Shader> effect, float width, float height); void apply_sprite_effect(std::shared_ptr<sf::Shader> effect, float width, float height);

@ -33,7 +33,7 @@ void System::set_position(World& world, SpatialMap& collision, Entity entity, Po
} }
void System::lighting() { void System::lighting() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& light = *level.lights; auto& light = *level.lights;
auto& world = *level.world; auto& world = *level.world;
auto& map = *level.map; auto& map = *level.map;
@ -57,15 +57,15 @@ void System::lighting() {
} }
void System::generate_paths() { void System::generate_paths() {
auto& level = Game::current(); auto& level = GameDB::current();
const auto &player_pos = Game::player_position(); const auto &player_pos = GameDB::player_position();
level.map->set_target(player_pos.location); level.map->set_target(player_pos.location);
level.map->make_paths(); level.map->make_paths();
} }
void System::enemy_ai_initialize() { void System::enemy_ai_initialize() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
auto& map = *level.map; auto& map = *level.map;
@ -93,10 +93,10 @@ void System::enemy_ai_initialize() {
} }
void System::enemy_pathing() { void System::enemy_pathing() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
auto& map = *level.map; auto& map = *level.map;
const auto &player_pos = Game::player_position(); const auto &player_pos = GameDB::player_position();
world.query<Position, Motion>([&](auto ent, auto &position, auto &motion) { world.query<Position, Motion>([&](auto ent, auto &position, auto &motion) {
if(ent != level.player) { if(ent != level.player) {
@ -135,7 +135,7 @@ inline void move_entity(SpatialMap &collider, Map &game_map, Position &position,
} }
void System::motion() { void System::motion() {
auto& level = Game::current(); auto& level = GameDB::current();
level.world->query<Position, Motion>( level.world->query<Position, Motion>(
[&](auto ent, auto &position, auto &motion) { [&](auto ent, auto &position, auto &motion) {
// don't process entities that don't move // don't process entities that don't move
@ -146,7 +146,7 @@ void System::motion() {
} }
void System::distribute_loot(Position target_pos) { void System::distribute_loot(Position target_pos) {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
auto& config = world.get_the<GameConfig>(); auto& config = world.get_the<GameConfig>();
int inventory_count = Random::uniform(0, 3); int inventory_count = Random::uniform(0, 3);
@ -171,7 +171,7 @@ void System::distribute_loot(Position target_pos) {
} }
void System::death() { void System::death() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
auto player = world.get_the<Player>(); auto player = world.get_the<Player>();
std::vector<Entity> dead_things; std::vector<Entity> dead_things;
@ -229,7 +229,7 @@ inline void animate_entity(World &world, Entity entity) {
} }
void System::combat(int attack_id) { void System::combat(int attack_id) {
auto& level = Game::current(); auto& level = GameDB::current();
auto& collider = *level.collision; auto& collider = *level.collision;
auto& world = *level.world; auto& world = *level.world;
auto& the_belt = world.get_the<ritual::Belt>(); auto& the_belt = world.get_the<ritual::Belt>();
@ -237,7 +237,7 @@ void System::combat(int attack_id) {
if(!the_belt.has(attack_id)) return; if(!the_belt.has(attack_id)) return;
auto& ritual = the_belt.get(attack_id); 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<Combat>(level.player); auto& player_combat = world.get<Combat>(level.player);
// this is guaranteed to not return the given position // this is guaranteed to not return the given position
@ -286,10 +286,10 @@ void System::combat(int attack_id) {
void System::collision() { void System::collision() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& collider = *level.collision; auto& collider = *level.collision;
auto& world = *level.world; 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 // this is guaranteed to not return the given position
auto [found, nearby] = collider.neighbors(player_pos.location); 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. * from the world for say, putting into a container or inventory.
*/ */
void System::remove_from_world(Entity entity) { void System::remove_from_world(Entity entity) {
auto& level = Game::current(); auto& level = GameDB::current();
auto& item_pos = level.world->get<Position>(entity); auto& item_pos = level.world->get<Position>(entity);
level.collision->remove(item_pos.location, entity); level.collision->remove(item_pos.location, entity);
// if you don't do this you get the bug that you can pickup // 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() { void System::pickup() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
auto& collision = *level.collision; auto& collision = *level.collision;
auto pos = Game::player_position(); auto pos = GameDB::player_position();
if(!collision.something_there(pos.aiming_at)) return; 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) { void System::plan_motion(Position move_to) {
auto& level = Game::current(); auto& level = GameDB::current();
auto& player_pos = Game::player_position(); auto& player_pos = GameDB::player_position();
player_pos.aiming_at = move_to.aiming_at; player_pos.aiming_at = move_to.aiming_at;
@ -405,7 +405,7 @@ void System::plan_motion(Position move_to) {
void System::player_status() { void System::player_status() {
auto& level = Game::current(); auto& level = GameDB::current();
auto& combat = level.world->get<Combat>(level.player); auto& combat = level.world->get<Combat>(level.player);
float percent = float(combat.hp) / float(combat.max_hp); float percent = float(combat.hp) / float(combat.max_hp);
@ -423,7 +423,7 @@ void System::player_status() {
} }
std::shared_ptr<sf::Shader> System::sprite_effect(Entity entity) { std::shared_ptr<sf::Shader> System::sprite_effect(Entity entity) {
auto world = Game::current_world(); auto world = GameDB::current_world();
if(world->has<SpriteEffect>(entity)) { if(world->has<SpriteEffect>(entity)) {
auto& se = world->get<SpriteEffect>(entity); auto& se = world->get<SpriteEffect>(entity);
@ -450,10 +450,10 @@ Entity System::spawn_item(World& world, const std::string& name) {
} }
void System::drop_item(Entity item) { void System::drop_item(Entity item) {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
auto& map = *level.map; 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"); 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 // 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) { 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<inventory::Model>(cont_id); auto& container = world->get<inventory::Model>(cont_id);
if(container.has(world_entity)) { 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) { 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<inventory::Model>(cont_id); auto& container = world->get<inventory::Model>(cont_id);
auto entity = container.get(slot_id); auto entity = container.get(slot_id);
container.remove(entity); 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) { 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."); 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<inventory::Model>(container_id); auto& inventory = level.world->get<inventory::Model>(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) { 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<inventory::Model>(container_id); auto& inventory = world->get<inventory::Model>(container_id);
return inventory.has(name); return inventory.has(name);
} }
void System::draw_map(Matrix& grid, EntityGrid& entity_map) { void System::draw_map(Matrix& grid, EntityGrid& entity_map) {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
Map &map = *level.map; Map &map = *level.map;
Matrix &fow = level.lights->$fow; 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) { bool System::use_item(const string& slot_name) {
auto& level = Game::current(); auto& level = GameDB::current();
auto& world = *level.world; auto& world = *level.world;
auto& inventory = world.get<inventory::Model>(level.player); auto& inventory = world.get<inventory::Model>(level.player);
auto& player_combat = world.get<Combat>(level.player); auto& player_combat = world.get<Combat>(level.player);

@ -10,8 +10,8 @@
using namespace lighting; using namespace lighting;
TEST_CASE("lighting a map works", "[lighting]") { TEST_CASE("lighting a map works", "[lighting]") {
Game::init(); GameDB::init();
auto& level = Game::current(); auto& level = GameDB::current();
auto& map = *level.map; auto& map = *level.map;
Point light1, light2; Point light1, light2;

@ -16,9 +16,9 @@ json load_test_data(const string &fname) {
} }
TEST_CASE("camera control", "[map]") { TEST_CASE("camera control", "[map]") {
Game::init(); GameDB::init();
auto& level = Game::current(); auto& level = GameDB::current();
auto& map = *level.map; auto& map = *level.map;
Point center = map.center_camera({10,10}, 5, 5); 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]") { TEST_CASE("map placement test", "[map-fail]") {
Game::init(); GameDB::init();
for(int i = 0; i < 5; i++) { 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++) { for(size_t rnum = 0; rnum < level.map->room_count(); rnum++) {
Point pos; Point pos;
@ -79,9 +79,9 @@ TEST_CASE("dijkstra algo test", "[map]") {
} }
TEST_CASE("map image 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); Matrix map_tiles = matrix::make(7,7);
EntityGrid entity_map; EntityGrid entity_map;

@ -16,8 +16,8 @@ using std::string, std::shared_ptr;
using matrix::Matrix; using matrix::Matrix;
std::shared_ptr<Map> make_map() { std::shared_ptr<Map> make_map() {
Game::init(); GameDB::init();
return Game::current().map; return GameDB::current().map;
} }
TEST_CASE("basic matrix iterator", "[matrix]") { TEST_CASE("basic matrix iterator", "[matrix]") {
@ -259,7 +259,7 @@ TEST_CASE("prototype circle algorithm", "[matrix]") {
TEST_CASE("viewport iterator", "[matrix]") { TEST_CASE("viewport iterator", "[matrix]") {
components::init(); components::init();
textures::init(); textures::init();
Game::init(); GameDB::init();
size_t width = Random::uniform<size_t>(20, 22); size_t width = Random::uniform<size_t>(20, 22);
size_t height = Random::uniform<size_t>(21, 25); size_t height = Random::uniform<size_t>(21, 25);
shared_ptr<Map> map = make_map(); shared_ptr<Map> map = make_map();

@ -31,6 +31,7 @@ namespace arena {
void FSM::START(Event ) { void FSM::START(Event ) {
run_systems(); run_systems();
dbc::sentinel("THIS IS FUCKED");
$level = $level_mgr.current(); $level = $level_mgr.current();
auto entity_id = $level_mgr.spawn_enemy($enemy_name); auto entity_id = $level_mgr.spawn_enemy($enemy_name);

@ -29,8 +29,6 @@ namespace arena {
std::string $enemy_name; std::string $enemy_name;
sf::RenderWindow $window; sf::RenderWindow $window;
sf::Font $font; sf::Font $font;
LevelManager $level_mgr;
GameLevel $level;
shared_ptr<arena::ArenaUI> $arena_ui = nullptr; shared_ptr<arena::ArenaUI> $arena_ui = nullptr;
FSM(std::string enemy_name); FSM(std::string enemy_name);

Loading…
Cancel
Save