levelmanager.* is now gone, but the code is just moved over to game_level. Now to clean up the api and give it a new name.

master
Zed A. Shaw 6 days ago
parent 5aca2fb56a
commit a83ee77eea
  1. 130
      game_level.cpp
  2. 18
      game_level.hpp
  3. 9
      gui/debug_ui.cpp
  4. 5
      gui/debug_ui.hpp
  5. 1
      gui/fsm.cpp
  6. 2
      gui/fsm.hpp
  7. 1
      gui/status_ui.cpp
  8. 100
      levelmanager.cpp
  9. 45
      levelmanager.hpp
  10. 1
      meson.build
  11. 2
      raycaster.cpp
  12. 4
      raycaster.hpp
  13. 1
      systems.cpp
  14. 1
      tests/lighting.cpp
  15. 1
      tests/map.cpp
  16. 3
      tests/matrix.cpp
  17. 1
      tools/arena_fsm.hpp

@ -1,6 +1,129 @@
#include "game_level.hpp"
#include "levelmanager.hpp"
#include "components.hpp"
#include "worldbuilder.hpp"
#include "constants.hpp"
#include "save.hpp"
#include "systems.hpp"
#include "components.hpp"
#include "rituals.hpp"
using lighting::LightRender;
using std::shared_ptr, std::make_shared;
using namespace components;
struct LevelScaling {
int map_width=20;
int map_height=20;
};
class LevelManager {
public:
std::vector<GameLevel> $levels;
size_t $current_level = 0;
LevelManager();
shared_ptr<gui::BossFightUI> create_bossfight(shared_ptr<DinkyECS::World> prev_world);
size_t create_level(shared_ptr<DinkyECS::World> prev_world = nullptr);
GameLevel &next();
GameLevel &previous();
GameLevel &current();
size_t current_index() { return $current_level; }
GameLevel &get(size_t index);
LevelScaling scale_level();
DinkyECS::Entity spawn_enemy(const std::string& named);
};
LevelManager::LevelManager() {
create_level();
}
LevelScaling LevelManager::scale_level() {
return {
INITIAL_MAP_W + int($current_level * 2),
INITIAL_MAP_H + int($current_level * 2)
};
}
inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world)
{
auto world = make_shared<DinkyECS::World>();
if(prev_world != nullptr) {
prev_world->clone_into(*world);
} else {
save::load_configs(*world);
}
return world;
}
shared_ptr<gui::BossFightUI> LevelManager::create_bossfight(shared_ptr<DinkyECS::World> prev_world) {
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
auto world = clone_load_world(prev_world);
auto& config = prev_world->get_the<GameConfig>();
// BUG: the jank is too strong here
auto boss_names = config.bosses.keys();
auto& level_name = boss_names[$current_level % boss_names.size()];
auto& boss_data = config.bosses[level_name];
auto boss_id = world->entity();
components::configure_entity(*world, boss_id, boss_data["components"]);
return make_shared<gui::BossFightUI>(world, boss_id);
}
DinkyECS::Entity LevelManager::spawn_enemy(const std::string& named) {
(void)named;
dbc::log("THIS FUNCTION NEEDS A REWRITE");
return 0;
}
size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
auto world = clone_load_world(prev_world);
auto scaling = scale_level();
auto map = make_shared<Map>(scaling.map_width, scaling.map_height);
auto collision = std::make_shared<SpatialMap>();
WorldBuilder builder(*map, *collision);
builder.generate(*world);
size_t index = $levels.size();
auto player = world->get_the<Player>();
$levels.emplace_back(index, player.entity, map, world,
make_shared<LightRender>(map->tiles()), collision);
dbc::check(index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error");
return index;
}
GameLevel &LevelManager::next() {
dbc::check($current_level < $levels.size(), "attempt to get next level when at end");
$current_level++;
return $levels.at($current_level);
}
GameLevel &LevelManager::previous() {
dbc::check($current_level > 0, "attempt to go to previous level when at 0");
$current_level--;
return $levels.at($current_level);
}
GameLevel &LevelManager::current() {
return $levels.at($current_level);
}
GameLevel &LevelManager::get(size_t index) {
return $levels.at(index);
}
namespace Game {
using std::shared_ptr, std::string, std::make_shared;
@ -15,11 +138,6 @@ namespace Game {
}
}
LevelManager& get_the_manager() {
dbc::check(initialized, "Forgot to call Game::init()");
return *LEVELS;
}
shared_ptr<DinkyECS::World> current_world() {
dbc::check(initialized, "Forgot to call Game::init()");
return current().world;

@ -2,19 +2,31 @@
#include "dinkyecs.hpp"
#include "gui/boss_fight_ui.hpp"
#include "dinkyecs.hpp"
#include "lights.hpp"
#include "map.hpp"
#include <memory>
#include "spatialmap.hpp"
struct GameLevel;
struct LevelManager;
namespace components {
struct Position;
}
struct GameLevel {
size_t index;
DinkyECS::Entity player;
std::shared_ptr<Map> map = nullptr;
std::shared_ptr<DinkyECS::World> world = nullptr;
std::shared_ptr<lighting::LightRender> lights = nullptr;
std::shared_ptr<SpatialMap> collision = nullptr;
};
namespace Game {
std::shared_ptr<gui::BossFightUI> create_bossfight();
GameLevel& create_level();
void init();
LevelManager& get_the_manager();
GameLevel &next();
GameLevel &previous();
GameLevel &current();

@ -9,11 +9,6 @@
namespace gui {
using namespace guecs;
DebugUI::DebugUI(LevelManager& level_mgr) :
$level_mgr(level_mgr)
{
}
void DebugUI::init(lel::Cell cell) {
$gui.position(cell.x, cell.y, cell.w, cell.h);
$gui.layout(
@ -51,7 +46,7 @@ namespace gui {
void DebugUI::render(sf::RenderWindow& window) {
if(active) {
auto& level = $level_mgr.current();
auto& level = Game::current();
auto player = level.world->get_the<components::Player>();
auto player_combat = level.world->get<components::Combat>(player.entity);
auto map = level.map;
@ -81,7 +76,7 @@ namespace gui {
active = !active;
if(active) {
auto& level = $level_mgr.current();
auto& level = Game::current();
// it's on now, enable things
auto player = level.world->get_the<components::Player>();
auto& player_combat = level.world->get<components::Combat>(player.entity);

@ -1,5 +1,5 @@
#pragma once
#include "levelmanager.hpp"
#include "game_level.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Font.hpp>
#include <guecs/ui.hpp>
@ -10,11 +10,8 @@ namespace gui {
public:
Stats $stats;
guecs::UI $gui;
LevelManager& $level_mgr;
bool active = false;
DebugUI(LevelManager& level_mgr);
void init(lel::Cell cell);
void render(sf::RenderWindow& window);
bool mouse(float x, float y, guecs::Modifiers mods);

@ -19,7 +19,6 @@ namespace gui {
FSM::FSM() :
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
$debug_ui(Game::get_the_manager()),
$main_ui($window),
$font{FONT_FILE_NAME},
$dnd_loot($status_ui, $loot_ui, $window, $router)

@ -36,7 +36,7 @@ namespace gui {
int $temp_attack_id = 0;
DebugUI $debug_ui;
MainUI $main_ui;
shared_ptr<BossFightUI> $boss_fight_ui = nullptr;
std::shared_ptr<BossFightUI> $boss_fight_ui = nullptr;
CombatUI $combat_ui;
StatusUI $status_ui;
MapViewUI $map_ui;

@ -7,7 +7,6 @@
#include "systems.hpp"
#include "inventory.hpp"
#include "game_level.hpp"
#include "levelmanager.hpp"
namespace gui {
using namespace guecs;

@ -1,100 +0,0 @@
#include "levelmanager.hpp"
#include "worldbuilder.hpp"
#include "constants.hpp"
#include "save.hpp"
#include "systems.hpp"
#include "components.hpp"
#include "rituals.hpp"
using lighting::LightRender;
using std::shared_ptr, std::make_shared;
using namespace components;
LevelManager::LevelManager() {
create_level();
}
LevelScaling LevelManager::scale_level() {
return {
INITIAL_MAP_W + int($current_level * 2),
INITIAL_MAP_H + int($current_level * 2)
};
}
inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world)
{
auto world = make_shared<DinkyECS::World>();
if(prev_world != nullptr) {
prev_world->clone_into(*world);
} else {
save::load_configs(*world);
}
return world;
}
shared_ptr<gui::BossFightUI> LevelManager::create_bossfight(shared_ptr<DinkyECS::World> prev_world) {
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
auto world = clone_load_world(prev_world);
auto& config = prev_world->get_the<GameConfig>();
// BUG: the jank is too strong here
auto boss_names = config.bosses.keys();
auto& level_name = boss_names[$current_level % boss_names.size()];
auto& boss_data = config.bosses[level_name];
auto boss_id = world->entity();
components::configure_entity(*world, boss_id, boss_data["components"]);
return make_shared<gui::BossFightUI>(world, boss_id);
}
DinkyECS::Entity LevelManager::spawn_enemy(const std::string& named) {
(void)named;
dbc::log("THIS FUNCTION NEEDS A REWRITE");
return 0;
}
size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
auto world = clone_load_world(prev_world);
auto scaling = scale_level();
auto map = make_shared<Map>(scaling.map_width, scaling.map_height);
auto collision = std::make_shared<SpatialMap>();
WorldBuilder builder(*map, *collision);
builder.generate(*world);
size_t index = $levels.size();
auto player = world->get_the<Player>();
$levels.emplace_back(index, player.entity, map, world,
make_shared<LightRender>(map->tiles()), collision);
dbc::check(index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error");
return index;
}
GameLevel &LevelManager::next() {
dbc::check($current_level < $levels.size(), "attempt to get next level when at end");
$current_level++;
return $levels.at($current_level);
}
GameLevel &LevelManager::previous() {
dbc::check($current_level > 0, "attempt to go to previous level when at 0");
$current_level--;
return $levels.at($current_level);
}
GameLevel &LevelManager::current() {
return $levels.at($current_level);
}
GameLevel &LevelManager::get(size_t index) {
return $levels.at(index);
}

@ -1,45 +0,0 @@
#pragma once
#include "dinkyecs.hpp"
#include "lights.hpp"
#include "map.hpp"
#include <vector>
#include <memory>
#include "spatialmap.hpp"
#include "components.hpp"
#include "gui/boss_fight_ui.hpp"
using std::shared_ptr;
struct GameLevel {
size_t index;
DinkyECS::Entity player;
shared_ptr<Map> map = nullptr;
shared_ptr<DinkyECS::World> world = nullptr;
shared_ptr<lighting::LightRender> lights = nullptr;
shared_ptr<SpatialMap> collision = nullptr;
};
struct LevelScaling {
int map_width=20;
int map_height=20;
};
class LevelManager {
public:
std::vector<GameLevel> $levels;
size_t $current_level = 0;
LevelManager();
shared_ptr<gui::BossFightUI> create_bossfight(shared_ptr<DinkyECS::World> prev_world);
size_t create_level(shared_ptr<DinkyECS::World> prev_world = nullptr);
GameLevel &next();
GameLevel &previous();
GameLevel &current();
size_t current_index() { return $current_level; }
GameLevel &get(size_t index);
LevelScaling scale_level();
DinkyECS::Entity spawn_enemy(const std::string& named);
};

@ -107,7 +107,6 @@ sources = [
'gui/ritual_ui.cpp',
'gui/status_ui.cpp',
'inventory.cpp',
'levelmanager.cpp',
'lights.cpp',
'map.cpp',
'matrix.cpp',

@ -13,7 +13,7 @@
#include "shaders.hpp"
using namespace fmt;
using std::make_unique;
using std::make_unique, std::shared_ptr;
union ColorConv {
struct {

@ -3,7 +3,7 @@
#include <SFML/Graphics.hpp>
#include <SFML/System/Clock.hpp>
#include "spatialmap.hpp"
#include "levelmanager.hpp"
#include "game_level.hpp"
#include "textures.hpp"
#include "camera.hpp"
@ -62,7 +62,7 @@ struct Raycaster {
void update_level(GameLevel level);
void update_sprite(DinkyECS::Entity ent, components::Sprite& sprite);
void init_shaders();
void apply_sprite_effect(shared_ptr<sf::Shader> effect, float width, float height);
void apply_sprite_effect(std::shared_ptr<sf::Shader> effect, float width, float height);
// camera things?
void position_camera(float player_x, float player_y);

@ -17,7 +17,6 @@
#include "shaders.hpp"
#include "inventory.hpp"
#include "game_level.hpp"
#include "levelmanager.hpp"
using std::string;
using namespace fmt;

@ -3,7 +3,6 @@
#include <nlohmann/json.hpp>
#include <fstream>
#include "map.hpp"
#include "levelmanager.hpp"
#include "game_level.hpp"
#include "lights.hpp"
#include "point.hpp"

@ -3,7 +3,6 @@
#include <nlohmann/json.hpp>
#include <fstream>
#include "map.hpp"
#include "levelmanager.hpp"
#include "game_level.hpp"
#include "systems.hpp."

@ -9,11 +9,10 @@
#include <fstream>
#include "map.hpp"
#include <memory>
#include "levelmanager.hpp"
using namespace nlohmann;
using namespace fmt;
using std::string;
using std::string, std::shared_ptr;
using matrix::Matrix;
std::shared_ptr<Map> make_map() {

@ -1,7 +1,6 @@
#pragma once
#include "constants.hpp"
#include "stats.hpp"
#include "levelmanager.hpp"
#include "fsm.hpp"
#include "main_ui.hpp"
#include "combat_ui.hpp"

Loading…
Cancel
Save