]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Added event subsection of code
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Sun, 15 Sep 2019 07:18:26 +0000 (03:18 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Sun, 15 Sep 2019 07:18:26 +0000 (03:18 -0400)
Scripts/world.lua
src/engine.cpp
src/events/world.hpp [new file with mode: 0644]
src/render.cpp
src/world.cpp

index 6a526ddfbd6479b288392112702c94ab6b67f709..8fb31367f1e1e9aff2d211d23e79bc69d4c1a94d 100644 (file)
@@ -76,7 +76,8 @@ world = {
                     elseif Y < YGen and Y > (YGen - YDepth) then
                         self:setData(X, Y, Z, "dirt");
                     elseif Y < YGen then
-                        self:setData(X, Y, Z, "stone");
+                        --self:setData(X, Y, Z, "stone");
+                        self:setData(X, Y, Z, "grass");
                     end
                     --print(X..","..Y..","..Z);
                 end
index 191493e8bfdb96f6e889d070ce4bd5e4dc7e63bb..e38020d60ec50876178a2d879ead951ad8bcd91d 100644 (file)
@@ -78,6 +78,8 @@ void Engine::logicLoop(void)
         // Update 20 times a second
         if (elapsed > 50) {
             elapsed = 0;
+
+            systems.update<WorldSystem>(dt);
             
             // All entities with an idle function should be run here
             entities.each<Scripted>([](entityx::Entity, Scripted &f){
diff --git a/src/events/world.hpp b/src/events/world.hpp
new file mode 100644 (file)
index 0000000..41b9569
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2019  Belle-Isle, Andrew <drumsetmonkey@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EVENTS_WORLD_HPP_
+#define EVENTS_WORLD_HPP_
+
+#include "world.hpp"
+
+struct WorldChangeEvent
+{
+    World* newWorld;
+
+    WorldChangeEvent(World* w) :
+        newWorld(w) {}
+};
+
+struct WorldMeshUpdateEvent
+{
+    GLuint worldVBO;
+
+    WorldMeshUpdateEvent(GLuint v) :
+        worldVBO(v) {}
+};
+
+#endif//EVENTS_WORLD_HPP
index 5efccce4864cd3f9f381ce5e1369e139cbd185b9..0c60b0004fc4998b9f64af11a8eabcfe14aa44b7 100644 (file)
@@ -69,7 +69,7 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
                                      );
 
     glm::mat4 model = glm::mat4(1.0f);
-    model = glm::scale(model, glm::vec3(8.0f));
+    model = glm::scale(model, glm::vec3(20.0f, 20.0f, 1.0f));
 
     glUseProgram(s);
 
@@ -282,7 +282,7 @@ int RenderSystem::init(void)
 
     //glClearColor(0.6, 0.8, 1.0, 0.0);
     
-    camPos = glm::vec3(0.0f, 0.0f, 0.5f);
+    camPos = glm::vec3(0.0f, 0.0f, 5.0f);
     glGenBuffers(1, &world_vbo);
 
     return 0;
index 3fb5b6b00a001ea3305e38526dffbc464c73851a..9e45d6061da0f2aabf02910cac10991d57b2e011 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "world.hpp"
+#include "events/world.hpp"
 
 /*****************
 *  WORLD CLASS  *
@@ -193,5 +194,9 @@ void WorldSystem::update([[maybe_unused]]entityx::EntityManager& entities,
                          [[maybe_unused]]entityx::EventManager& events,
                          [[maybe_unused]]entityx::TimeDelta dt)
 {
-
+    if (currentWorld == nullptr) {
+        currentWorld = &(worlds.front());
+        events.emit<WorldChangeEvent>(currentWorld);
+        std::cout << "Emitted" << std::endl;
+    }
 }