diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-15 03:18:26 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-15 03:18:26 -0400 |
commit | bce8d0687f44def4b0171cd84bf1441fc4390e58 (patch) | |
tree | 0449aacaa3b6847aa65cbed6cf9b3ae417e76bed | |
parent | b19978a1100bf86086901e1410f2e7ad1358278b (diff) |
Added event subsection of code
-rw-r--r-- | Scripts/world.lua | 3 | ||||
-rw-r--r-- | src/engine.cpp | 2 | ||||
-rw-r--r-- | src/events/world.hpp | 39 | ||||
-rw-r--r-- | src/render.cpp | 4 | ||||
-rw-r--r-- | src/world.cpp | 7 |
5 files changed, 51 insertions, 4 deletions
diff --git a/Scripts/world.lua b/Scripts/world.lua index 6a526dd..8fb3136 100644 --- a/Scripts/world.lua +++ b/Scripts/world.lua @@ -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 diff --git a/src/engine.cpp b/src/engine.cpp index 191493e..e38020d 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -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 index 0000000..41b9569 --- /dev/null +++ b/src/events/world.hpp @@ -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 diff --git a/src/render.cpp b/src/render.cpp index 5efccce..0c60b00 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -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; diff --git a/src/world.cpp b/src/world.cpp index 3fb5b6b..9e45d60 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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; + } } |