Now all of the old LevelManager code is gone. Next phase is to rename the Game:: to something better then test the shit out of it.
This commit is contained in:
parent
a83ee77eea
commit
c46927ea10
7 changed files with 91 additions and 126 deletions
2
Makefile
2
Makefile
|
@ -60,7 +60,7 @@ clean:
|
|||
meson compile --clean -C builddir
|
||||
|
||||
debug_test: build
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[map]"
|
||||
|
||||
win_installer:
|
||||
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'
|
||||
|
|
158
game_level.cpp
158
game_level.cpp
|
@ -16,58 +16,64 @@ struct LevelScaling {
|
|||
int map_height=20;
|
||||
};
|
||||
|
||||
class LevelManager {
|
||||
struct 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 ¤t();
|
||||
size_t current_index() { return $current_level; }
|
||||
GameLevel &get(size_t index);
|
||||
LevelScaling scale_level();
|
||||
|
||||
DinkyECS::Entity spawn_enemy(const std::string& named);
|
||||
std::vector<GameLevel> levels;
|
||||
size_t current_level = 0;
|
||||
};
|
||||
|
||||
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 {
|
||||
if(prev_world == nullptr) {
|
||||
save::load_configs(*world);
|
||||
} else {
|
||||
prev_world->clone_into(*world);
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
shared_ptr<gui::BossFightUI> LevelManager::create_bossfight(shared_ptr<DinkyECS::World> prev_world) {
|
||||
namespace Game {
|
||||
using std::shared_ptr, std::string, std::make_shared;
|
||||
|
||||
shared_ptr<LevelManager> LMGR;
|
||||
bool initialized = false;
|
||||
|
||||
void init() {
|
||||
components::init();
|
||||
textures::init();
|
||||
|
||||
if(!initialized) {
|
||||
LMGR = make_shared<LevelManager>();
|
||||
initialized = true;
|
||||
new_level(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
LevelScaling scale_level() {
|
||||
return {
|
||||
INITIAL_MAP_W + int(LMGR->current_level * 2),
|
||||
INITIAL_MAP_H + int(LMGR->current_level * 2)
|
||||
};
|
||||
}
|
||||
|
||||
shared_ptr<DinkyECS::World> current_world() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return current().world;
|
||||
}
|
||||
|
||||
shared_ptr<gui::BossFightUI> create_bossfight() {
|
||||
dbc::check(initialized, "Forgot to call Game::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);
|
||||
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& level_name = boss_names[LMGR->current_level % boss_names.size()];
|
||||
auto& boss_data = config.bosses[level_name];
|
||||
|
||||
auto boss_id = world->entity();
|
||||
|
@ -76,13 +82,8 @@ shared_ptr<gui::BossFightUI> LevelManager::create_bossfight(shared_ptr<DinkyECS:
|
|||
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) {
|
||||
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
auto world = clone_load_world(prev_world);
|
||||
|
||||
auto scaling = scale_level();
|
||||
|
@ -93,95 +94,60 @@ size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
|
|||
WorldBuilder builder(*map, *collision);
|
||||
builder.generate(*world);
|
||||
|
||||
size_t index = $levels.size();
|
||||
size_t index = LMGR->levels.size();
|
||||
|
||||
auto player = world->get_the<Player>();
|
||||
|
||||
$levels.emplace_back(index, player.entity, map, world,
|
||||
LMGR->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");
|
||||
dbc::check(index == LMGR->levels.size() - 1, "Level index is not the same as LMGR->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;
|
||||
|
||||
shared_ptr<LevelManager> LEVELS;
|
||||
bool initialized = false;
|
||||
|
||||
void init() {
|
||||
if(!initialized) {
|
||||
LEVELS = make_shared<LevelManager>();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<DinkyECS::World> current_world() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return current().world;
|
||||
}
|
||||
|
||||
shared_ptr<gui::BossFightUI> create_bossfight() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->create_bossfight(current_world());
|
||||
}
|
||||
|
||||
GameLevel& create_level() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
LEVELS->create_level(current_world());
|
||||
return next();
|
||||
dbc::log("current_level");
|
||||
size_t level = new_level(current_world());
|
||||
dbc::check(level == LMGR->current_level + 1, "new level index is wrong");
|
||||
auto& the_level = next();
|
||||
dbc::check(level == LMGR->current_level, "level didn't update?!");
|
||||
return the_level;
|
||||
}
|
||||
|
||||
GameLevel &next() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->next();
|
||||
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);
|
||||
}
|
||||
|
||||
GameLevel &previous() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->previous();
|
||||
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);
|
||||
}
|
||||
|
||||
GameLevel ¤t() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->current();
|
||||
return LMGR->levels.at(LMGR->current_level);
|
||||
}
|
||||
|
||||
size_t current_index() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->current_index();
|
||||
return LMGR->current_level;
|
||||
}
|
||||
|
||||
GameLevel &get(size_t index) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->get(index);
|
||||
return LMGR->levels.at(index);
|
||||
}
|
||||
|
||||
DinkyECS::Entity spawn_enemy(const std::string& named) {
|
||||
(void)named;
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LEVELS->spawn_enemy(named);
|
||||
dbc::sentinel("THIS IS BROKEN");
|
||||
}
|
||||
|
||||
components::Position& player_position() {
|
||||
|
|
|
@ -24,6 +24,7 @@ struct GameLevel {
|
|||
|
||||
namespace Game {
|
||||
std::shared_ptr<gui::BossFightUI> create_bossfight();
|
||||
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world);
|
||||
GameLevel& create_level();
|
||||
|
||||
void init();
|
||||
|
|
|
@ -539,6 +539,9 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::next_level() {
|
||||
dbc::log("current_level: Yep, next is called...");
|
||||
Game::create_level();
|
||||
|
||||
$status_ui.update_level();
|
||||
$combat_ui.update_level();
|
||||
$main_ui.update_level();
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace gui {
|
|||
public:
|
||||
bool active = false;
|
||||
guecs::UI $gui;
|
||||
DinkyECS::Entity $temp_loot;
|
||||
DinkyECS::Entity $target;
|
||||
DinkyECS::Entity $temp_loot = DinkyECS::NONE;
|
||||
DinkyECS::Entity $target = DinkyECS::NONE;
|
||||
|
||||
LootUI();
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ json load_test_data(const string &fname) {
|
|||
}
|
||||
|
||||
TEST_CASE("camera control", "[map]") {
|
||||
textures::init();
|
||||
components::init();
|
||||
Game::init();
|
||||
|
||||
auto& level = Game::current();
|
||||
|
@ -36,11 +34,8 @@ TEST_CASE("camera control", "[map]") {
|
|||
}
|
||||
|
||||
TEST_CASE("map placement test", "[map-fail]") {
|
||||
textures::init();
|
||||
components::init();
|
||||
Game::init();
|
||||
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
auto& level = Game::create_level();
|
||||
|
||||
|
@ -84,8 +79,6 @@ TEST_CASE("dijkstra algo test", "[map]") {
|
|||
}
|
||||
|
||||
TEST_CASE("map image test", "[map]") {
|
||||
components::init();
|
||||
textures::init();
|
||||
Game::init();
|
||||
|
||||
auto& level = Game::current();
|
||||
|
|
|
@ -20,7 +20,7 @@ std::shared_ptr<Map> make_map() {
|
|||
return Game::current().map;
|
||||
}
|
||||
|
||||
TEST_CASE("basic matrix iterator", "[matrix:basic]") {
|
||||
TEST_CASE("basic matrix iterator", "[matrix]") {
|
||||
std::ifstream infile("./tests/dijkstra.json");
|
||||
json data = json::parse(infile);
|
||||
auto test = data[0];
|
||||
|
@ -107,7 +107,7 @@ TEST_CASE("thrash matrix iterators", "[matrix]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("thrash box distance iterators", "[matrix:distance]") {
|
||||
TEST_CASE("thrash box distance iterators", "[matrix]") {
|
||||
size_t width = Random::uniform<size_t>(10, 21);
|
||||
size_t height = Random::uniform<size_t>(10, 25);
|
||||
|
||||
|
@ -159,7 +159,7 @@ TEST_CASE("thrash box iterators", "[matrix]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("thrash compass iterators", "[matrix:compass]") {
|
||||
TEST_CASE("thrash compass iterators", "[matrix]") {
|
||||
for(int count = 0; count < 5; count++) {
|
||||
size_t width = Random::uniform<size_t>(1, 25);
|
||||
size_t height = Random::uniform<size_t>(1, 33);
|
||||
|
@ -189,7 +189,7 @@ TEST_CASE("thrash compass iterators", "[matrix:compass]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("prototype line algorithm", "[matrix:line]") {
|
||||
TEST_CASE("prototype line algorithm", "[matrix]") {
|
||||
size_t width = Random::uniform<size_t>(10, 12);
|
||||
size_t height = Random::uniform<size_t>(10, 15);
|
||||
Map map(width,height);
|
||||
|
@ -225,7 +225,7 @@ TEST_CASE("prototype line algorithm", "[matrix:line]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("prototype circle algorithm", "[matrix:circle]") {
|
||||
TEST_CASE("prototype circle algorithm", "[matrix]") {
|
||||
for(int count = 0; count < 5; count++) {
|
||||
size_t width = Random::uniform<size_t>(10, 13);
|
||||
size_t height = Random::uniform<size_t>(10, 15);
|
||||
|
@ -256,8 +256,10 @@ TEST_CASE("prototype circle algorithm", "[matrix:circle]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("viewport iterator", "[matrix:viewport]") {
|
||||
TEST_CASE("viewport iterator", "[matrix]") {
|
||||
components::init();
|
||||
textures::init();
|
||||
Game::init();
|
||||
size_t width = Random::uniform<size_t>(20, 22);
|
||||
size_t height = Random::uniform<size_t>(21, 25);
|
||||
shared_ptr<Map> map = make_map();
|
||||
|
@ -280,7 +282,7 @@ TEST_CASE("viewport iterator", "[matrix:viewport]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("random rectangle", "[matrix:rando_rect]") {
|
||||
TEST_CASE("random rectangle", "[matrix]") {
|
||||
components::init();
|
||||
for(int i = 0; i < 5; i++) {
|
||||
shared_ptr<Map> map = make_map();
|
||||
|
@ -305,7 +307,7 @@ TEST_CASE("random rectangle", "[matrix:rando_rect]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("standard rectangle", "[matrix:rectangle]") {
|
||||
TEST_CASE("standard rectangle", "[matrix]") {
|
||||
components::init();
|
||||
for(int i = 0; i < 5; i++) {
|
||||
shared_ptr<Map> map = make_map();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue