From: Clyne Sullivan Date: Wed, 18 Sep 2019 16:10:25 +0000 (-0400) Subject: adjust for world changes X-Git-Tag: v0.2-alpha~5^2~4 X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=0e7f7791fd592f0240a30168a9a570c57b0f5880;p=clyne%2Fgamedev2.git adjust for world changes --- 0e7f7791fd592f0240a30168a9a570c57b0f5880 diff --cc Scripts/init.lua index da9ba14,84d2073..d2abb00 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@@ -1,6 -1,4 +1,6 @@@ +game.loadFont("default", "Assets/FreePixel.ttf", 16) + - bird = { + player = { Player = 0, EventListeners = { MoveLeftPressed = function(self) @@@ -8,11 -6,10 +8,11 @@@ self.Render.flipx = true; end, MoveLeftReleased = function(self) - self.Velocity.x = self.Velocity.x + 100 + game.puts("default", self.Position.x, self.Position.y, "Hey.") + self.Velocity.x = self.Velocity.x + 3 end, MoveRightPressed = function(self) - self.Velocity.x = self.Velocity.x + 100 + self.Velocity.x = self.Velocity.x + 3 self.Render.flipx = false; end, MoveRightReleased = function(self) diff --cc src/render.cpp index 2a51b70,2b49b2c..3eea57b --- a/src/render.cpp +++ b/src/render.cpp @@@ -27,7 -27,8 +27,10 @@@ void RenderSystem::configure([[maybe_unused]] entityx::EntityManager& entities, [[maybe_unused]] entityx::EventManager& events) { + events.subscribe(*this); + events.subscribe(*this); + events.subscribe>(*this); ++ init(); } @@@ -179,28 -196,31 +198,52 @@@ void RenderSystem::update([[maybe_unuse 5*sizeof(float), (void*)(3*sizeof(float))); glDrawArrays(GL_TRIANGLES, 0, 6); }); + glUniform1i(f, 0); + + // If we were given a world VBO render it + if (worldVBO) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, worldTexture); + glUniform1i(q, 0); + + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, worldNormal); + glUniform1i(n, 1); + + glBindBuffer(GL_ARRAY_BUFFER, worldVBO); + //glBufferData(GL_ARRAY_BUFFER, + // wm.size() * sizeof(WorldMeshData), + // &wm.front(), + // GL_STREAM_DRAW); - // Update all given VBOs - for (auto& r : renders) { + glVertexAttribPointer(a, 3, GL_FLOAT, GL_FALSE, + 6*sizeof(float), 0); + glVertexAttribPointer(t, 2, GL_FLOAT, GL_FALSE, + 6*sizeof(float), (void*)(3*sizeof(float))); + glDrawArrays(GL_TRIANGLES, 0, worldVertex); + } + ++ // Update all UI VBOs ++ for (auto& r : uiRenders) { + auto& render = r.second; + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, render.tex); + glUniform1i(q, 0); + + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, render.normal); + glUniform1i(n, 1); + + glBindBuffer(GL_ARRAY_BUFFER, r.first); + + glVertexAttribPointer(a, 3, GL_FLOAT, GL_FALSE, + 6*sizeof(float), 0); + glVertexAttribPointer(t, 2, GL_FLOAT, GL_FALSE, + 6*sizeof(float), (void*)(3*sizeof(float))); + glDrawArrays(GL_TRIANGLES, 0, render.vertex); + } + /************* * CLEANUP * *************/ @@@ -290,10 -310,15 +333,23 @@@ int RenderSystem::init(void /************ * EVENTS * ************/ + +void RenderSystem::receive(const NewRenderEvent &nre) +{ - renders.insert_or_assign(nre.vbo, - RenderData(nre.tex, nre.normal, nre.vertex)); ++ uiRenders.insert_or_assign(nre.vbo, ++ UIRenderData(nre.tex, nre.normal, nre.vertex)); ++} ++ + void RenderSystem::receive(const WorldMeshUpdateEvent &wmu) + { + worldVBO = wmu.worldVBO; + worldVertex = wmu.numVertex; + worldTexture = wmu.worldTexture; + worldNormal = wmu.worldNormal; + } + + void RenderSystem::receive(const entityx::ComponentAddedEvent &cae) + { + player = cae.entity; } + diff --cc src/render.hpp index 3f632f1,f3064d1..eabf4be --- a/src/render.hpp +++ b/src/render.hpp @@@ -36,20 -36,9 +36,21 @@@ #include "shader.hpp" #include "world.hpp" ++#include "components/Player.hpp" +#include "events/render.hpp" #include "events/world.hpp" -#include "components/Player.hpp" +#include + - struct RenderData ++struct UIRenderData +{ + GLuint tex; + GLuint normal; + unsigned int vertex; + - RenderData(GLuint _tex, GLuint _normal, unsigned int _vertex) : ++ UIRenderData(GLuint _tex, GLuint _normal, unsigned int _vertex) : + tex(_tex), normal(_normal), vertex(_vertex) {} +}; class RenderSystem : public entityx::System, public entityx::Receiver @@@ -65,9 -54,11 +66,15 @@@ private Shader worldShader; glm::vec3 camPos; + // Map of VBOs and their render data - std::map renders; ++ std::map uiRenders; ++ + GLuint worldVBO = 0; + unsigned int worldVertex = 0; + GLuint worldTexture = 0; + GLuint worldNormal = 0; + entityx::Entity player; // Save the player so we can track the camera + public: RenderSystem() : window(nullptr, SDL_DestroyWindow) {} @@@ -100,9 -91,9 +107,9 @@@ /************ * EVENTS * ************/ - //void receive(const WorldMeshUpdateEvent &wmu); - + void receive(const WorldMeshUpdateEvent &wmu); + void receive(const NewRenderEvent &nre); + void receive(const entityx::ComponentAddedEvent &cae); - }; #endif // SYSTEM_RENDER_HPP_