aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-03-10 21:17:48 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-03-10 21:17:48 +0000
commit52fb7104141eab51e6f5fbd54027b042ca7c1e08 (patch)
tree5a6b82cb4aa762e5b67137ae29f2e47cc3e11689
parent84b1f965b52ffd071c873a497d4139ad4baa9c6b (diff)
parent8248e49a9f7c2f4a8331491efeb7c80cadf2bfc1 (diff)
downloadYAGE-52fb7104141eab51e6f5fbd54027b042ca7c1e08.tar.gz
YAGE-52fb7104141eab51e6f5fbd54027b042ca7c1e08.zip
Merge branch 'master' of github.com:ymherklotz/YAGE
-rw-r--r--examples/shooter/main.cpp2
-rw-r--r--examples/simplegame/main.cpp3
-rw-r--r--yage/entity/engine.cpp14
-rw-r--r--yage/entity/engine.h6
-rw-r--r--yage/entity/space.h3
-rw-r--r--yage/entity/system.h52
-rw-r--r--yage/entity/systemmanager.h15
7 files changed, 39 insertions, 56 deletions
diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp
index e38bf53b..5d80c350 100644
--- a/examples/shooter/main.cpp
+++ b/examples/shooter/main.cpp
@@ -11,6 +11,7 @@ using std::cout;
int main(int argc, char **argv)
{
+ yage::init();
yage::Window window;
window.create("Shooter example", 800, 600);
@@ -166,4 +167,5 @@ int main(int argc, char **argv)
window.swapBuffer();
}
+ yage::quit();
}
diff --git a/examples/simplegame/main.cpp b/examples/simplegame/main.cpp
index ed6b78f3..bea3bc8d 100644
--- a/examples/simplegame/main.cpp
+++ b/examples/simplegame/main.cpp
@@ -18,7 +18,7 @@ using namespace yage;
int main()
{
-
+ yage::init();
Logger logger;
srand(time(nullptr));
Window window;
@@ -109,4 +109,5 @@ int main()
}
i = (i + 1) % 30;
}
+ yage::quit();
}
diff --git a/yage/entity/engine.cpp b/yage/entity/engine.cpp
index cf6f73b7..919cff7c 100644
--- a/yage/entity/engine.cpp
+++ b/yage/entity/engine.cpp
@@ -14,10 +14,6 @@ namespace yage
void Engine::init()
{
window_.create("Game Engine", 800, 640);
-
- for (auto &system : systems_) {
- system->init();
- }
}
void Engine::mainLoop()
@@ -33,16 +29,6 @@ void Engine::mainLoop()
void Engine::update()
{
- const double dt = 1.0 / 60.0;
-
- for (auto &system : systems_) {
- system->update(dt);
- }
-}
-
-void Engine::addSystem(System *system)
-{
- systems_.push_back(system);
}
Engine &Engine::instance()
diff --git a/yage/entity/engine.h b/yage/entity/engine.h
index 147769e5..6e1bf49a 100644
--- a/yage/entity/engine.h
+++ b/yage/entity/engine.h
@@ -31,17 +31,11 @@ public:
/// Updates the systems.
void update();
- /// Adds a system to the engine.
- void addSystem(System *system);
-
/// Returns the instance of the engine, as there is only one instance of the
/// engine.
static Engine &instance();
private:
- /// Vector of all the systems in the engine.
- std::vector<System *> systems_;
-
/// Window
Window window_;
};
diff --git a/yage/entity/space.h b/yage/entity/space.h
index e69df37a..96154ffc 100644
--- a/yage/entity/space.h
+++ b/yage/entity/space.h
@@ -16,8 +16,6 @@
namespace yage
{
-class System;
-
/**
* Space that keeps track of all the entities, componenets and runs the systems
* on the data to update them. There can be multiple instances of a space, which
@@ -47,7 +45,6 @@ private:
* component. These are specific to the Space, as other spaces might have
* different Systems and not act on the same entities.
*/
- std::vector<System *> systems_;
/**
* Manages all the entities in the system, can create them for the current
diff --git a/yage/entity/system.h b/yage/entity/system.h
index 9100fa17..47d176c9 100644
--- a/yage/entity/system.h
+++ b/yage/entity/system.h
@@ -9,48 +9,36 @@
#ifndef YAGE_ENGINE_SYSTEM_H
#define YAGE_ENGINE_SYSTEM_H
+#include <cstddef>
+
+#include "../util/noncopyable.h"
+
namespace yage
{
+class BaseSystem : public yage::NonCopyable
+{
+public:
+ typedef std::size_t Identifier;
+
+ virtual void update() = 0;
+
+protected:
+ Identifier id_;
+};
+
/**
* System interface for the different systems in the engine.
*/
-class System
+template <typename Derived>
+class System : public BaseSystem
{
public:
- /**
- * Virtual destructor to destroy all the objects that implement this
- * properly.
- */
- virtual ~System() = 0;
-
- /**
- * Initializes the system. Good practice to have this function instead
- * using the constructor.
- */
- virtual void init() = 0;
-
- /**
- * Updates the system at each interval using the time step.
- *
- * @param dt The time difference between the previous frame and the current one.
- */
- virtual void update(double dt) = 0;
-
- /**
- * Destroy the system and the components that are contained in it.
- */
- virtual void destroy() = 0;
};
-/**
- * Implement the default destructor, but leaving it as purely virtual in the
- * definition of the abstract class. This is so that the classes that implement
- * the abstract class have to implement a desctructor, but at the same time,
- * that there is no undefined behavious when the stack unwinds to the system and
- * calls the system destructor.
- */
-inline System::~System() {}
+class SystemManager : public yage::NonCopyable {
+
+};
} // namespace yage
diff --git a/yage/entity/systemmanager.h b/yage/entity/systemmanager.h
new file mode 100644
index 00000000..5351e4bb
--- /dev/null
+++ b/yage/entity/systemmanager.h
@@ -0,0 +1,15 @@
+#ifndef YAGE_ENTITY_SYSTEMMANAGER_H
+#define YAGE_ENTITY_SYSTEMMANAGER_H
+
+#include <unordered_map>
+
+namespace yage {
+
+class SystemManager {
+private:
+ std::unordered_map
+};
+
+} // namespace yage
+
+#endif