Now systems.cpp is disconnected from levelmanager. That leaves the GUIs and then to completely remove it and clean up the api.

This commit is contained in:
Zed A. Shaw 2025-08-19 11:05:32 -04:00
parent 81e25f73bb
commit d5ff57e025
9 changed files with 106 additions and 89 deletions

View file

@ -17,6 +17,7 @@
#include "shaders.hpp"
#include "inventory.hpp"
#include "game_level.hpp"
#include "levelmanager.hpp"
using std::string;
using namespace fmt;
@ -32,10 +33,11 @@ void System::set_position(World& world, SpatialMap& collision, Entity entity, Po
collision.insert(pos.location, entity, has_collision);
}
void System::lighting(GameLevel &level) {
auto &light = *level.lights;
auto &world = *level.world;
auto &map = *level.map;
void System::lighting() {
auto& level = Game::current();
auto& light = *level.lights;
auto& world = *level.world;
auto& map = *level.map;
light.reset_light();
@ -55,16 +57,18 @@ void System::lighting(GameLevel &level) {
}
void System::generate_paths(GameLevel &level) {
void System::generate_paths() {
auto& level = Game::current();
const auto &player_pos = Game::player_position();
level.map->set_target(player_pos.location);
level.map->make_paths();
}
void System::enemy_ai_initialize(GameLevel &level) {
auto &world = *level.world;
auto &map = *level.map;
void System::enemy_ai_initialize() {
auto& level = Game::current();
auto& world = *level.world;
auto& map = *level.map;
world.query<Position, EnemyConfig>([&](const auto ent, auto& pos, auto& config) {
if(world.has<ai::EntityAI>(ent)) {
@ -89,9 +93,10 @@ void System::enemy_ai_initialize(GameLevel &level) {
});
}
void System::enemy_pathing(GameLevel &level) {
auto &world = *level.world;
auto &map = *level.map;
void System::enemy_pathing() {
auto& level = Game::current();
auto& world = *level.world;
auto& map = *level.map;
const auto &player_pos = Game::player_position();
world.query<Position, Motion>([&](auto ent, auto &position, auto &motion) {
@ -130,7 +135,8 @@ inline void move_entity(SpatialMap &collider, Map &game_map, Position &position,
position.location = move_to;
}
void System::motion(GameLevel &level) {
void System::motion() {
auto& level = Game::current();
level.world->query<Position, Motion>(
[&](auto ent, auto &position, auto &motion) {
// don't process entities that don't move
@ -140,7 +146,8 @@ void System::motion(GameLevel &level) {
});
}
void System::distribute_loot(GameLevel &level, Position target_pos) {
void System::distribute_loot(Position target_pos) {
auto& level = Game::current();
auto& world = *level.world;
auto& config = world.get_the<GameConfig>();
int inventory_count = Random::uniform(0, 3);
@ -164,8 +171,9 @@ void System::distribute_loot(GameLevel &level, Position target_pos) {
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, loot_entity, {});
}
void System::death(GameLevel &level) {
auto &world = *level.world;
void System::death() {
auto& level = Game::current();
auto& world = *level.world;
auto player = world.get_the<Player>();
std::vector<Entity> dead_things;
@ -204,7 +212,7 @@ void System::death(GameLevel &level) {
level.collision->remove(pos.location, ent);
// distribute_loot is then responsible for putting something there
System::distribute_loot(level, pos);
System::distribute_loot(pos);
world.destroy(ent);
}
@ -221,9 +229,10 @@ inline void animate_entity(World &world, Entity entity) {
}
}
void System::combat(GameLevel &level, int attack_id) {
auto &collider = *level.collision;
auto &world = *level.world;
void System::combat(int attack_id) {
auto& level = Game::current();
auto& collider = *level.collision;
auto& world = *level.world;
auto& the_belt = world.get_the<ritual::Belt>();
if(!the_belt.has(attack_id)) return;
@ -277,9 +286,10 @@ void System::combat(GameLevel &level, int attack_id) {
}
void System::collision(GameLevel &level) {
auto &collider = *level.collision;
auto &world = *level.world;
void System::collision() {
auto& level = Game::current();
auto& collider = *level.collision;
auto& world = *level.world;
const auto& player_pos = Game::player_position();
// this is guaranteed to not return the given position
@ -309,7 +319,8 @@ void System::collision(GameLevel &level) {
* This isn't for destroying something, but just removing it
* from the world for say, putting into a container or inventory.
*/
void System::remove_from_world(GameLevel &level, Entity entity) {
void System::remove_from_world(Entity entity) {
auto& level = Game::current();
auto& item_pos = level.world->get<Position>(entity);
level.collision->remove(item_pos.location, entity);
// if you don't do this you get the bug that you can pickup
@ -317,9 +328,10 @@ void System::remove_from_world(GameLevel &level, Entity entity) {
level.world->remove<Position>(entity);
}
void System::pickup(GameLevel &level) {
auto &world = *level.world;
auto &collision = *level.collision;
void System::pickup() {
auto& level = Game::current();
auto& world = *level.world;
auto& collision = *level.collision;
auto pos = Game::player_position();
if(!collision.something_there(pos.aiming_at)) return;
@ -337,7 +349,7 @@ void System::pickup(GameLevel &level) {
// use spatial find to find an item with inventory...
if(world.has<InventoryItem>(entity)) {
// NOTE: this might need to be a separate system so that people can leave stuff alone
remove_from_world(level, entity);
remove_from_world(entity);
if(world.has<ritual::JunkPile>(entity)) {
auto& pile = world.get<ritual::JunkPile>(entity);
@ -381,7 +393,8 @@ void System::device(World &world, Entity actor, Entity item) {
}
}
void System::plan_motion(GameLevel& level, Position move_to) {
void System::plan_motion(Position move_to) {
auto& level = Game::current();
auto& player_pos = Game::player_position();
player_pos.aiming_at = move_to.aiming_at;
@ -392,7 +405,8 @@ void System::plan_motion(GameLevel& level, Position move_to) {
}
void System::player_status(GameLevel &level) {
void System::player_status() {
auto& level = Game::current();
auto& combat = level.world->get<Combat>(level.player);
float percent = float(combat.hp) / float(combat.max_hp);
@ -409,15 +423,16 @@ void System::player_status(GameLevel &level) {
}
}
std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, Entity entity) {
if(level.world->has<SpriteEffect>(entity)) {
auto& se = level.world->get<SpriteEffect>(entity);
std::shared_ptr<sf::Shader> System::sprite_effect(Entity entity) {
auto world = Game::current_world();
if(world->has<SpriteEffect>(entity)) {
auto& se = world->get<SpriteEffect>(entity);
if(se.frames > 0) {
se.frames--;
return se.effect;
} else {
level.world->remove<SpriteEffect>(entity);
world->remove<SpriteEffect>(entity);
return nullptr;
}
} else {
@ -435,11 +450,11 @@ Entity System::spawn_item(World& world, const std::string& name) {
return item_id;
}
void System::drop_item(GameLevel& level, Entity item) {
void System::drop_item(Entity item) {
auto& level = Game::current();
auto& world = *level.world;
auto& map = *level.map;
auto player_pos = world.get<Position>(level.player);
auto player_pos = Game::player_position();
dbc::check(map.can_move(player_pos.location), "impossible, the player can't be in a wall");
@ -481,7 +496,8 @@ void System::remove_from_container(World& world, Entity cont_id, const std::stri
}
void System::inventory_swap(GameLevel &level, 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();
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);
@ -491,14 +507,16 @@ void System::inventory_swap(GameLevel &level, Entity container_id, const std::st
inventory.swap(a_ent, b_ent);
}
bool System::inventory_occupied(GameLevel& level, Entity container_id, const std::string& name) {
auto& inventory = level.world->get<inventory::Model>(container_id);
bool System::inventory_occupied(Entity container_id, const std::string& name) {
auto world = Game::current_world();
auto& inventory = world->get<inventory::Model>(container_id);
return inventory.has(name);
}
void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) {
World &world = *level.world;
void System::draw_map(Matrix& grid, EntityGrid& entity_map) {
auto& level = Game::current();
auto& world = *level.world;
Map &map = *level.map;
Matrix &fow = level.lights->$fow;
size_t view_x = matrix::width(grid) - 1;
@ -586,7 +604,8 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
render.display();
}
bool System::use_item(GameLevel& level, const string& slot_name) {
bool System::use_item(const string& slot_name) {
auto& level = Game::current();
auto& world = *level.world;
auto& inventory = world.get<inventory::Model>(level.player);
auto& player_combat = world.get<Combat>(level.player);