From: Mikko Rasa Date: Sat, 29 Oct 2022 18:30:25 +0000 (+0300) Subject: Add resource container references to Director and Stage X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=41fa4483d8f017175800992d8fdacd7ee312d0c3;p=libs%2Fgame.git Add resource container references to Director and Stage --- diff --git a/Build b/Build index beae8cd..837d2a2 100644 --- a/Build +++ b/Build @@ -3,6 +3,7 @@ package "mspgame" version "0.1"; require "mspcore"; + require "mspdatafile"; require "mspmath"; build_info diff --git a/source/game/director.cpp b/source/game/director.cpp index 28d86e7..96bd143 100644 --- a/source/game/director.cpp +++ b/source/game/director.cpp @@ -7,13 +7,14 @@ using namespace std; namespace Msp::Game { -Director::Director(): +Director::Director(DataFile::Collection &r): + resources(r), event_source(event_bus) { } Stage &Director::create_stage() { - stages.emplace_back(std::make_unique()); + stages.emplace_back(std::make_unique(std::ref(resources))); event_source.emit(std::ref(*stages.back())); return *stages.back(); } diff --git a/source/game/director.h b/source/game/director.h index 5f33aef..05be9f7 100644 --- a/source/game/director.h +++ b/source/game/director.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include "eventbus.h" @@ -19,6 +20,7 @@ public: using EventSource = Game::EventSource; private: + DataFile::Collection &resources; EventBus event_bus; EventSource event_source; std::vector> stages; @@ -30,8 +32,9 @@ private: unsigned max_backlog_steps = 600; public: - Director(); + Director(DataFile::Collection &); + DataFile::Collection &get_resources() const { return resources; } EventBus &get_event_bus() { return event_bus; } EventSource &get_event_source() { return event_source; } const std::vector> &get_stages() const { return stages; } diff --git a/source/game/resources.cpp b/source/game/resources.cpp new file mode 100644 index 0000000..0893f97 --- /dev/null +++ b/source/game/resources.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include "resources.h" + +using namespace std; + +namespace Msp::Game { + +ApplicationResources::ApplicationResources() +{ + FS::Path data_dir = FS::get_sys_data_dir()/"data"; +#ifdef DEBUG + if(FS::exists(data_dir)) + dir_src.add_directory(data_dir); + add_source(dir_src); +#endif + + FS::Path main_pack = FS::get_sys_data_dir()/(Application::get_name()+".mdp"); + if(FS::exists(main_pack)) + pack_src.add_pack_file(main_pack.str()); + if(FS::exists(data_dir)) + { + for(const string &f: FS::list_filtered(data_dir, "\\.mdp$")) + pack_src.add_pack_file((data_dir/f).str()); + } + add_source(pack_src); +} + +} // namespace Msp::Game diff --git a/source/game/resources.h b/source/game/resources.h new file mode 100644 index 0000000..b8f10b0 --- /dev/null +++ b/source/game/resources.h @@ -0,0 +1,27 @@ +#ifndef MSP_GAME_RESOURCES_H_ +#define MSP_GAME_RESOURCES_H_ + +#include +#include +#include + +namespace Msp::Game { + +class Resources: virtual public DataFile::Collection +{ +public: +}; + +class ApplicationResources: public Resources +{ +private: + DataFile::DirectorySource dir_src; + DataFile::PackSource pack_src; + +public: + ApplicationResources(); +}; + +} // namespace Msp::Game + +#endif diff --git a/source/game/stage.cpp b/source/game/stage.cpp index 8d781f2..779be6e 100644 --- a/source/game/stage.cpp +++ b/source/game/stage.cpp @@ -4,7 +4,8 @@ namespace Msp::Game { -Stage::Stage(): +Stage::Stage(DataFile::Collection &r): + resources(r), event_source(event_bus), root(std::make_unique(*this)) { } diff --git a/source/game/stage.h b/source/game/stage.h index d7793e2..6af3b60 100644 --- a/source/game/stage.h +++ b/source/game/stage.h @@ -2,6 +2,7 @@ #define MSP_GAME_STAGE_H_ #include +#include #include #include "eventbus.h" #include "events.h" @@ -20,6 +21,7 @@ public: Events::ComponentCreated, Events::ComponentDestroyed>; private: + DataFile::Collection &resources; PoolPool pools; EventBus event_bus; EventSource event_source; @@ -29,9 +31,10 @@ private: std::vector> systems; public: - Stage(); + Stage(DataFile::Collection &); ~Stage(); + DataFile::Collection &get_resources() const { return resources; } PoolPool &get_pools() { return pools; } EventBus &get_event_bus() { return event_bus; } EventSource &get_event_source() { return event_source; }