aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-02 01:42:36 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-02 01:42:36 -0400
commitb52920a35eb69d1a258c737e3114fbe5cfe9aca5 (patch)
treeb3a7363b6f4bae8cda513a54ef84069103e6388b
parentea35ad60506407040f7b9fae65c5bdc18f9576bb (diff)
Changed Lua Idle function names
-rw-r--r--Scripts/init.lua4
-rw-r--r--src/components/Script.hpp15
-rw-r--r--src/engine.cpp12
-rw-r--r--src/render.cpp13
-rw-r--r--src/script.cpp2
5 files changed, 29 insertions, 17 deletions
diff --git a/Scripts/init.lua b/Scripts/init.lua
index 26b2aa7..4a874b2 100644
--- a/Scripts/init.lua
+++ b/Scripts/init.lua
@@ -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
diff --git a/src/components/Script.hpp b/src/components/Script.hpp
index 069fea9..b3c89f3 100644
--- a/src/components/Script.hpp
+++ b/src/components/Script.hpp
@@ -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);
}
};
diff --git a/src/engine.cpp b/src/engine.cpp
index aa3ccc5..2916a6e 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -30,6 +30,10 @@
#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);
}
}
diff --git a/src/render.cpp b/src/render.cpp
index 4990955..65b8441 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -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;
diff --git a/src/script.cpp b/src/script.cpp
index a886ca3..fa485bc 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -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();
});
}