version "0.1";
require "mspcore";
+ require "mspdatafile";
require "mspmath";
build_info
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<Stage>());
+ stages.emplace_back(std::make_unique<Stage>(std::ref(resources)));
event_source.emit<Events::StageCreated>(std::ref(*stages.back()));
return *stages.back();
}
#include <memory>
#include <vector>
+#include <msp/datafile/collection.h>
#include <msp/time/timedelta.h>
#include <msp/time/timestamp.h>
#include "eventbus.h"
using EventSource = Game::EventSource<Events::StageCreated, Events::StageActivated, Events::StageDeactivated>;
private:
+ DataFile::Collection &resources;
EventBus event_bus;
EventSource event_source;
std::vector<std::unique_ptr<Stage>> stages;
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<std::unique_ptr<Stage>> &get_stages() const { return stages; }
--- /dev/null
+#include <msp/core/application.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#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
--- /dev/null
+#ifndef MSP_GAME_RESOURCES_H_
+#define MSP_GAME_RESOURCES_H_
+
+#include <msp/datafile/collection.h>
+#include <msp/datafile/directorysource.h>
+#include <msp/datafile/packsource.h>
+
+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
namespace Msp::Game {
-Stage::Stage():
+Stage::Stage(DataFile::Collection &r):
+ resources(r),
event_source(event_bus),
root(std::make_unique<Root>(*this))
{ }
#define MSP_GAME_STAGE_H_
#include <memory>
+#include <msp/datafile/collection.h>
#include <msp/time/timedelta.h>
#include "eventbus.h"
#include "events.h"
Events::ComponentCreated, Events::ComponentDestroyed>;
private:
+ DataFile::Collection &resources;
PoolPool pools;
EventBus event_bus;
EventSource event_source;
std::vector<std::unique_ptr<System>> 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; }