]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Changed Lua Idle function names
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Mon, 2 Sep 2019 05:42:36 +0000 (01:42 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Mon, 2 Sep 2019 05:42:36 +0000 (01:42 -0400)
Scripts/init.lua
src/components/Script.hpp
src/engine.cpp
src/render.cpp
src/script.cpp

index 26b2aa7113afa5a82ff04436cfc091ef61461240..4a874b2eb49bb983577048291652a969f3838d6a 100644 (file)
@@ -26,7 +26,7 @@ bird = {
         --end
         --self.visibleTick = self.visibleTick + 1
     end,
-    Update = function(self)
+    PhysicsIdle = function(self)
         if self.Velocity.x < 0 then
             self.Render.flipx = true
         elseif self.Velocity.x > 0 then
@@ -56,7 +56,7 @@ cat = {
         self.Velocity.y =  100 * math.cos(math.rad(self.counter));
         self.counter = self.counter + 5;
     end,
-    Update = function(self)
+    PhysicsIdle = function(self)
         if self.Velocity.x < 0 then
             self.Render.flipx = true
         elseif self.Velocity.x > 0 then
index 069fea9952e065fc3041574296cd29cbd63f5979..b3c89f300735c838cc05b5cd4ec384f26e5f9284 100644 (file)
@@ -42,16 +42,23 @@ public:
         return *this;
     }
 
-    void exec(void) {
+    void exec(void)
+    {
         if (caller["Idle"] == sol::type::function)
             caller["Idle"](caller); // Call idle function and pass itself
                                     //  in or to fulfill the 'self' param
     }
 
-    void update(void)
+    void updatePhysics(void)
+    {
+        if (caller["PhysicsIdle"] == sol::type::function)
+            caller["PhysicsIdle"](caller);
+    }
+
+    void updateRender(void)
     {
-        if (caller["Update"] == sol::type::function)
-            caller["Update"](caller);
+        if (caller["RenderIdle"] == sol::type::function)
+            caller["RenderIdle"](caller);
     }
 };
 
index aa3ccc5babd5c2f23ccc4758240fb67d5152f921..2916a6e001bc37c3e1c7c1f199513af7f8d4efe0 100644 (file)
 #include "components/Position.hpp"
 #include "components/Velocity.hpp"
 
+using namespace std::chrono_literals;
+namespace cr = std::chrono;
+typedef std::chrono::high_resolution_clock mc;
+
 int Engine::init(void)
 {
     systems.add<GameRunSystem>();
@@ -46,10 +50,6 @@ int Engine::init(void)
 
 void Engine::logicLoop(void)
 {
-    using namespace std::chrono_literals;
-    namespace cr = std::chrono;
-    typedef std::chrono::high_resolution_clock mc;
-
     entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */
     double elapsed = 0;
 
@@ -98,9 +98,9 @@ void Engine::logicLoop(void)
 
 void Engine::renderLoop(void)
 {
+    entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */
     while (shouldRun()) {
-        systems.update<RenderSystem>(0);
-        std::this_thread::yield();
+        systems.update<RenderSystem>(dt);
     }
 }
 
index 4990955e3a38781bb4dc7f2206faab2bef00ed74..65b8441e437b3bbca8e5a8049cea545fe840f643 100644 (file)
@@ -22,6 +22,7 @@
 #include <components/Render.hpp>
 #include <components/Position.hpp>
 #include <components/Light.hpp>
+#include <components/Script.hpp>
 
 void RenderSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
                              [[maybe_unused]] entityx::EventManager& events)
@@ -84,8 +85,8 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
     glEnableVertexAttribArray(a);
     glEnableVertexAttribArray(t);
 
+    // Ambient light, for now this is static
     GLfloat amb[4] = {1.0f, 1.0f, 1.0f, 0.0f};
-
     glUniform4fv(b, 1, amb);
 
     /**************
@@ -97,8 +98,7 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
     std::vector<glm::vec4> lightColor;
     int lightNum = 0;
 
-    entities.each<Light, Position>(
-        [&]
+    entities.each<Light, Position>([&]
         (entityx::Entity, Light &l, Position &p){
 
         lightPos.push_back(glm::vec3(p.x, p.y,-10.0));
@@ -118,13 +118,18 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
     *  DRAWING  *
     *************/
 
-
     entities.each<Render, Position>(
         [this, a, q, t, n](entityx::Entity, Render &r, Position &p) {
 
         if (!r.visible)
             return;
 
+        // If our component was created via script, call the entity's
+        //  RenderIdle function
+        //if (e.has_component<Scripted>()) {
+        //    e.component<Scripted>()->updateRender();
+        //}
+
         float w = r.texture.width/2.0f;
         float h = r.texture.height;
 
index a886ca3e955579d9c07e3cbd184d6f0ef1de6a07..fa485bcb778de9319b133d8bcd797690903961d9 100644 (file)
@@ -42,7 +42,7 @@ void ScriptSystem::update([[maybe_unused]] entityx::EntityManager& entities,
                           [[maybe_unused]] entityx::TimeDelta dt)
 {
     entities.each<Scripted>([](entityx::Entity, Scripted &s){
-        s.update();
+        s.updatePhysics();
     });
 }