--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
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
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);
}
};
#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>();
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;
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);
}
}
#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)
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);
/**************
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));
* 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;
[[maybe_unused]] entityx::TimeDelta dt)
{
entities.each<Scripted>([](entityx::Entity, Scripted &s){
- s.update();
+ s.updatePhysics();
});
}