]> git.localhorst.tv Git - blank.git/commitdiff
moved entity spawn and control into its own class
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 4 Aug 2015 16:48:19 +0000 (18:48 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 4 Aug 2015 16:48:19 +0000 (18:48 +0200)
called "Spawner" if that is somehow non-obvious

src/ai/Spawner.cpp [new file with mode: 0644]
src/ai/Spawner.hpp [new file with mode: 0644]
src/app/Application.hpp
src/app/app.cpp

diff --git a/src/ai/Spawner.cpp b/src/ai/Spawner.cpp
new file mode 100644 (file)
index 0000000..d97aa86
--- /dev/null
@@ -0,0 +1,41 @@
+#include "Spawner.hpp"
+
+#include "RandomWalk.hpp"
+#include "../world/BlockType.hpp"
+#include "../world/BlockTypeRegistry.hpp"
+#include "../world/Entity.hpp"
+#include "../world/World.hpp"
+
+
+namespace blank {
+
+Spawner::Spawner(World &world)
+: world(world)
+, controllers() {
+       Spawn({ 0.0f, 0.0f, 0.0f });
+}
+
+Spawner::~Spawner() {
+
+}
+
+
+void Spawner::Update(int dt) {
+       for (auto &ctrl : controllers) {
+               ctrl.Update(dt);
+       }
+}
+
+
+void Spawner::Spawn(const glm::vec3 &pos) {
+       Entity &e = world.AddEntity();
+       e.Name("test");
+       e.Position(pos);
+       e.Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } });
+       e.WorldCollidable(true);
+       e.SetShape(world.BlockTypes()[1].shape, { 1.0f, 1.0f, 0.0f });
+       e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
+       controllers.emplace_back(e);
+}
+
+}
diff --git a/src/ai/Spawner.hpp b/src/ai/Spawner.hpp
new file mode 100644 (file)
index 0000000..e3e8f24
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef BLANK_AI_SPAWNER_HPP_
+#define BLANK_AI_SPAWNER_HPP_
+
+#include <list>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class RandomWalk;
+class World;
+
+class Spawner {
+
+public:
+       explicit Spawner(World &);
+       ~Spawner();
+
+       void Update(int dt);
+
+private:
+       void Spawn(const glm::vec3 &);
+
+private:
+       World &world;
+       std::list<RandomWalk> controllers;
+
+};
+
+}
+
+#endif
index 9644794c1e7d54a9ff5bade9b0c9a0f9c155a5d5..973234916a3afa541c2f2e41a544ef455e340521 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "Assets.hpp"
 #include "FrameCounter.hpp"
-#include "../ai/RandomWalk.hpp"
+#include "../ai/Spawner.hpp"
 #include "../audio/Audio.hpp"
 #include "../graphics/Viewport.hpp"
 #include "../ui/Interface.hpp"
@@ -54,8 +54,6 @@ public:
        /// push the current state to display
        void Render();
 
-       static Entity &MakeTestEntity(World &);
-
 private:
        Window &window;
        Viewport viewport;
@@ -66,7 +64,7 @@ private:
        World world;
        Interface interface;
 
-       RandomWalk test_controller;
+       Spawner spawner;
 
        bool running;
 
index 3111091377afe0fd0ccd25fa75b6a18bd5952e45..86c90d83f043d644f83a25fcfecc2b8ce99a0872 100644 (file)
@@ -36,7 +36,7 @@ Application::Application(Window &win, const Config &config)
 , counter()
 , world(config.world)
 , interface(config.interface, assets, audio, counter, world)
-, test_controller(MakeTestEntity(world))
+, spawner(world)
 , running(false) {
        viewport.VSync(config.vsync);
 }
@@ -45,17 +45,6 @@ Application::~Application() {
        audio.StopAll();
 }
 
-Entity &Application::MakeTestEntity(World &world) {
-       Entity &e = world.AddEntity();
-       e.Name("test");
-       e.Position({ 0.0f, 0.0f, 0.0f });
-       e.Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } });
-       e.WorldCollidable(true);
-       e.SetShape(world.BlockTypes()[1].shape, { 1.0f, 1.0f, 0.0f });
-       e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
-       return e;
-}
-
 
 void Application::RunN(size_t n) {
        Uint32 last = SDL_GetTicks();
@@ -161,7 +150,7 @@ void Application::Handle(const SDL_WindowEvent &event) {
 void Application::Update(int dt) {
        counter.EnterUpdate();
        interface.Update(dt);
-       test_controller.Update(dt);
+       spawner.Update(dt);
        world.Update(dt);
 
        glm::mat4 trans = world.Player().Transform(Chunk::Pos(0, 0, 0));