]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
adjust for world changes
authorClyne Sullivan <clyne@bitgloo.com>
Wed, 18 Sep 2019 16:10:25 +0000 (12:10 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Wed, 18 Sep 2019 16:10:25 +0000 (12:10 -0400)
1  2 
Scripts/init.lua
src/render.cpp
src/render.hpp
src/script.cpp
src/world.cpp

index da9ba14a42b62d534170a0cd8c35fcc0592cd525,84d20731bf7ecc020c8b28f7eba97f00632ee0fe..d2abb006f64e92f173348d142dded4c3cd484052
@@@ -1,6 -1,4 +1,6 @@@
- bird = {
 +game.loadFont("default", "Assets/FreePixel.ttf", 16)
 +
+ 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 2a51b70742429784f845edd3b305d89d1e769592,2b49b2c6844e5d2abbb67ad71d8e136977c7b4e6..3eea57b242cfb61b4eab1f4ed3da50819aa3982d
  void RenderSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
                               [[maybe_unused]] entityx::EventManager& events)
  {
 +    events.subscribe<NewRenderEvent>(*this);
+     events.subscribe<WorldMeshUpdateEvent>(*this);
+     events.subscribe<entityx::ComponentAddedEvent<Player>>(*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  *
  ************/
-     renders.insert_or_assign(nre.vbo,
-                              RenderData(nre.tex, nre.normal, nre.vertex));
 +
 +void RenderSystem::receive(const NewRenderEvent &nre)
 +{
++    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<Player> &cae)
+ {
+     player = cae.entity;
  }
 +
diff --cc src/render.hpp
index 3f632f142b3926d707bf280d7db8c0145f9e151e,f3064d155c55b793db558863dfc02ee1fcdfae1f..eabf4becf4b519040af30b75ea6c076314ae5abb
  
  #include "shader.hpp"
  #include "world.hpp"
++#include "components/Player.hpp"
 +#include "events/render.hpp"
  #include "events/world.hpp"
  
 -#include "components/Player.hpp"
 +#include <map>
 +
- 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<RenderSystem>,
                       public entityx::Receiver<RenderSystem>
@@@ -65,9 -54,11 +66,15 @@@ private
      Shader worldShader;
      glm::vec3 camPos;
  
-     std::map<GLuint, RenderData> renders;
 +    // Map of VBOs and their render data
++    std::map<GLuint, UIRenderData> 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) {}
      /************
      *  EVENTS  *
      ************/
-     //void receive(const WorldMeshUpdateEvent &wmu);
-     
+     void receive(const WorldMeshUpdateEvent &wmu);
 +    void receive(const NewRenderEvent &nre);
+     void receive(const entityx::ComponentAddedEvent<Player> &cae);
 -    
  };
  
  #endif // SYSTEM_RENDER_HPP_
diff --cc src/script.cpp
Simple merge
diff --cc src/world.cpp
Simple merge