]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Using polymorphism for world layer storage now, and added demo backdrops
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Tue, 8 Oct 2019 07:03:16 +0000 (03:03 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Tue, 8 Oct 2019 07:03:16 +0000 (03:03 -0400)
14 files changed:
1  2 
Assets/world/world1/layers/0/forestTileBack.png
Assets/world/world1/layers/deco/forestTileBack.png
Assets/world/world1/layers/deco/forestTileFront.png
Assets/world/world1/layers/deco/forestTileMid.png
Assets/world/world1/layers/deco/normal.png
Makefile
Scripts/init.lua
Scripts/world.lua
src/components/Physics.hpp
src/components/Position.hpp
src/render.cpp
src/script.cpp
src/world.cpp
src/world.hpp

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..f1c1a8bd388977574c84269f4213b21ba3a2f5b4
new file mode 100644 (file)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..c5e9dac2109403776ffbebea9c790db8b86e1d1d
new file mode 100644 (file)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..234520ccac3c806349ce542261f032614fcfba19
new file mode 100644 (file)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b51d0bc9dc47b9e7565a38a14c45ad7a88624ea4
new file mode 100644 (file)
Binary files differ
index c0aab9434f4c0caaa4c23c47a3292c4602532406,0000000000000000000000000000000000000000..767f7e3dc2d6cb05b7f183b4924d985abccde8a0
mode 100644,000000..100644
Binary files differ
diff --cc Makefile
index 9c9fafe9663e110a5290fec1e8f3beb8890cf795,dcbac2bea5f759dbf1b205c93e230104500bd3f8..f79435c0c337b1cfdd6cddb5834a2022a80f67fc
+++ b/Makefile
@@@ -82,4 -82,5 +82,7 @@@ $(OUTDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SR
        @sed -e 's/.*://' -e 's/\\$$//' < $(OUTDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(OUTDIR)/$*.$(DEPEXT)
        @rm -f $(OUTDIR)/$*.$(DEPEXT).tmp
  
--.PHONY: all remake clean cleaner resources
++mem: $(EXEC)
++      valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(EXEC)
++.PHONY: all remake clean cleaner resources mem
index 46fe040f6948966a868ca58fc3182aa55759ab7b,ec9e35071460ba81a74c5432e03c9289711387f8..da2517fd0954890628f350a204b89626d5906020
@@@ -34,25 -35,13 +34,24 @@@ player = 
          x = 0.0,
          y = 0.0
      },
 -    Physics = 0,
 +    Physics = {
-         gravity = true,
 +        hitbox = {
-             {x = -0.5, y = -0.8},
-             {x = 0.5, y = -0.8},
-             {x = -0.5, y = 0.8},
-             {x = 0.5, y = 0.8},
++            ll = {x = -0.5, y = -0.8},
++            lr = {x = 0.5, y = -0.8},
++            ul = {x = -0.5, y = 0.8},
++            ur = {x = 0.5, y = 0.8},
 +        }
 +    },
      Name = "bord",
 -    hellotrue = true,
 -    hellofalse = false,
      Render = {
          texture = "Assets/player.png",
 -        visible = true
 +        visible = true,
 +        offset = {
 +            ll = {x = -0.5, y = -0.8},
 +            lr = {x = 0.5, y = -0.8},
 +            ul = {x = -0.5, y = 0.8},
 +            ur = {x = 0.5, y = 0.8},
 +        }
      },
      Light = {
          r = 1.0,
index f1d2b665fe737905c7c11b54135f6b67b2b101fd,bb6c61ea52973b5a2d5a13997a6e54c45efbb780..1fb74d24bcaeb85f329a4fc9795977f51095ab59
 -world = {
 -    Seed = 5345345,
 -    Layers = 2,
 -
 -    -- This is run when the world is registered and not after,
 -    -- although it is possible to register materials later
 +newWorld = {
      Register = function(self)
 -
 -        -- TODO make world have global textures to speed up rendering
 -
 -        self:registerMaterial("grass", {
 -            -- TODO combine both of these into 1
 -            texture = {
 -                file = "Assets/world.png",
 -                offset = { x = 0, y = 0 },
 -                size = { x = 64, y = 64 }
 -            },
 -            normal = {
 -                file = "Assets/world_normal.png",
 -                offset = { x = 0, y = 0 },
 -                size = { x = 64, y = 64 }
 -            }
 +        self.unitSize = 8;
 +        self:createLayer(0, {
 +            texture = { file = "Assets/world/world1/layers/0/texture.png" },
 +            normal = { file = "Assets/world/world1/layers/0/normal.png" },
 +            hitbox =  "Assets/world/world1/layers/0/hitbox.png"
          });
 -        self:registerMaterial("dirt", {
 -            texture = {
 -                file = "Assets/world.png",
 -                offset = { x = 64, y = 0 },
 -                size = { x = 64, y = 64 }
 -            },
 -            normal = {
 -                file = "Assets/world_normal.png",
 -                offset = { x = 64, y = 0 },
 -                size = { x = 64, y = 64 }
 -            }
 +        self:createLayer(1, {
 +            texture = { file = "Assets/world/world1/layers/1/texture.png" },
 +            normal = { file = "Assets/world/world1/layers/1/normal.png" },
 +            hitbox = "Assets/world/world1/layers/1/hitbox.png"
          });
-         self:createDecoLayer(10, {
-             texture = { file = "Assets/world/world1/layers/deco/texture.png" },
 -        self:registerMaterial("stone", {
 -            texture = {
 -                file = "Assets/world.png",
 -                offset = { x = 128, y = 0 },
 -                size = { x = 64, y = 64 }
 -            },
 -            normal = {
 -                file = "Assets/world_normal.png",
 -                offset = { x = 128, y = 0 },
 -                size = { x = 64, y = 64 }
 -            }
++        self:createDecoLayer(7, {
++            texture = { file = "Assets/world/world1/layers/deco/forestTileBack.png" },
++            normal = { file = "Assets/world/world1/layers/deco/normal.png" },
+         });
 -        self:registerMaterial("flower", {
 -            texture = {
 -                file = "Assets/world.png",
 -                offset = { x = 192, y = 0 },
 -                size = { x = 64, y = 64 }
 -            },
 -            normal = {
 -                file = "Assets/world_normal.png",
 -                offset = { x = 192, y = 0 },
 -                size = { x = 64, y = 64 }
 -            },
 -            passable = true
++        self:createDecoLayer(5.5, {
++            texture = { file = "Assets/world/world1/layers/deco/forestTileMid.png" },
++            normal = { file = "Assets/world/world1/layers/deco/normal.png" },
+         });
 -        self:registerMaterial("trunk", {
 -            texture = {
 -                file = "Assets/world.png",
 -                offset = { x = 256, y = 0 },
 -                size = { x = 64, y = 64 }
 -            },
 -            normal = {
 -                file = "Assets/world_normal.png",
 -                offset = { x = 256, y = 0 },
 -                size = { x = 64, y = 64 }
 -            }
++        self:createDecoLayer(4, {
++            texture = { file = "Assets/world/world1/layers/deco/forestTileFront.png" },
 +            normal = { file = "Assets/world/world1/layers/deco/normal.png" },
          });
      end,
 -
      Generate = function(self)
-         print("Generating");
 -        math.randomseed(self.Seed)
 -        xsize, ysize, zsize = self:setSize(250, 128, 3)
 -        for Z = 0,zsize-1 do
 -            for X = 0,xsize-1 do
 -                if Z == 0 then
 -                    YGen = math.floor(6*math.sin(X/20)) + 64
 -                elseif Z == 1 then
 -                    YGen = math.floor(9*math.sin(X/20)) + 64
 -                else
 -                    YGen = math.floor(15*math.sin(X/20)) + 64
 -                end
 -                YDepth = math.random(3,5)
 -                for Y = 0,ysize-1 do
 -                    if Y == YGen then
 -                        self:setData(X, Y, Z, "grass");
 -                    elseif Y < YGen and Y > (YGen - YDepth) then
 -                        self:setData(X, Y, Z, "dirt");
 -                    elseif Y < YGen then
 -                        self:setData(X, Y, Z, "stone");
 -                    elseif Y == YGen + 1 then
 -                        if math.random(0, 100) == 53 then
 -                            self:setData(X, Y, Z, "flower");
 -                        elseif math.random(0, 100) == 45 then
 -                            self:setData(X, Y, Z, "trunk");
 -                        end
 -                    end
 -                    --print(X..","..Y..","..Z);
 -                end
 -            end
 -        end
 -        --self:setData(1000, 1345, 5, "grass"); -- Test error checking
 -        print("Done with world gen");
      end
  }
  
 ---world:Generate()
 -game.worldRegister(world)
 +game.worldRegister(newWorld);
- --world = {
- --    Seed = 5345345,
- --    Layers = 2,
- --
- --    -- This is run when the world is registered and not after,
- --    -- although it is possible to register materials later
- --    Register = function(self)
- --
- --        -- TODO make world have global textures to speed up rendering
- --        self:registerMaterial("grass", {
- --            -- TODO combine both of these into 1
- --            texture = {
- --                file = "Assets/world.png",
- --                offset = { x = 0, y = 0 },
- --                size = { x = 64, y = 64 }
- --            },
- --            normal = {
- --                file = "Assets/world_normal.png",
- --                offset = { x = 0, y = 0 },
- --                size = { x = 64, y = 64 }
- --            }
- --        });
- --        self:registerMaterial("dirt", {
- --            texture = {
- --                file = "Assets/world.png",
- --                offset = { x = 64, y = 0 },
- --                size = { x = 64, y = 64 }
- --            },
- --            normal = {
- --                file = "Assets/world_normal.png",
- --                offset = { x = 64, y = 0 },
- --                size = { x = 64, y = 64 }
- --            }
- --        });
- --        self:registerMaterial("stone", {
- --            texture = {
- --                file = "Assets/world.png",
- --                offset = { x = 128, y = 0 },
- --                size = { x = 64, y = 64 }
- --            },
- --            normal = {
- --                file = "Assets/world_normal.png",
- --                offset = { x = 128, y = 0 },
- --                size = { x = 64, y = 64 }
- --            }
- --        });
- --        self:registerMaterial("flower", {
- --            texture = {
- --                file = "Assets/world.png",
- --                offset = { x = 192, y = 0 },
- --                size = { x = 64, y = 64 }
- --            },
- --            normal = {
- --                file = "Assets/world_normal.png",
- --                offset = { x = 192, y = 0 },
- --                size = { x = 64, y = 64 }
- --            },
- --            passable = true
- --        });
- --        self:registerMaterial("trunk", {
- --            texture = {
- --                file = "Assets/world.png",
- --                offset = { x = 256, y = 0 },
- --                size = { x = 64, y = 64 }
- --            },
- --            normal = {
- --                file = "Assets/world_normal.png",
- --                offset = { x = 256, y = 0 },
- --                size = { x = 64, y = 64 }
- --            }
- --        });
- --    end,
- --
- --    Generate = function(self)
- --        math.randomseed(self.Seed)
- --        xsize, ysize, zsize = self:setSize(250, 128, 3)
- --        for Z = 0,zsize-1 do
- --            for X = 0,xsize-1 do
- --                if Z == 0 then
- --                    YGen = math.floor(6*math.sin(X/20)) + 64
- --                elseif Z == 1 then
- --                    YGen = math.floor(9*math.sin(X/20)) + 64
- --                else
- --                    YGen = math.floor(15*math.sin(X/20)) + 64
- --                end
- --                YDepth = math.random(3,5)
- --                for Y = 0,ysize-1 do
- --                    if Y == YGen then
- --                        self:setData(X, Y, Z, "grass");
- --                    elseif Y < YGen and Y > (YGen - YDepth) then
- --                        self:setData(X, Y, Z, "dirt");
- --                    elseif Y < YGen then
- --                        self:setData(X, Y, Z, "stone");
- --                    elseif Y == YGen + 1 then
- --                        if math.random(0, 100) == 53 then
- --                            self:setData(X, Y, Z, "flower");
- --                        elseif math.random(0, 100) == 45 then
- --                            self:setData(X, Y, Z, "trunk");
- --                        end
- --                    end
- --                    --print(X..","..Y..","..Z);
- --                end
- --            end
- --        end
- --        self:setData(1000, 1345, 5, "grass"); -- Test error checking
- --        print("Done with world gen");
- --    end
- --}
- --world:Generate()
- --game.worldRegister(world)
index 378e87f0a136b061babf5e78e74864972eb1d865,378e87f0a136b061babf5e78e74864972eb1d865..cb4d08a308a33699a9d327e7091fb16059c15860
@@@ -25,8 -25,8 +25,38 @@@ struct Physics : Component<Physics
  {
  public:
      bool standing = true;
++    bool gravity = true;
++    glm::vec2 corners[4] = {
++        glm::vec2(-0.5, -0.5), // lower left
++        glm::vec2( 0.5, -0.5), // lower right
++        glm::vec2(-0.5,  0.5), // upper left
++        glm::vec2( 0.5,  0.5)  // upper right
++    };
++
      Physics FromLua([[maybe_unused]] sol::object ref)
      {
++        if (ref.get_type() == sol::type::table) {
++            sol::table tab = ref;
++
++            if (tab["gravity"].get_type() == sol::type::boolean)
++                this->gravity = tab["gravity"];
++
++            if (tab["hitbox"].get_type() == sol::type::table) {
++                sol::table hitbox = tab["hitbox"];
++                if (hitbox["ll"] == sol::type::table)
++                    corners[0] = Script::to<glm::vec2>(hitbox["ll"]);
++                if (hitbox["lr"] == sol::type::table)
++                    corners[1] = Script::to<glm::vec2>(hitbox["lr"]);
++                if (hitbox["ul"] == sol::type::table)
++                    corners[2] = Script::to<glm::vec2>(hitbox["ul"]);
++                if (hitbox["ur"] == sol::type::table)
++                    corners[3] = Script::to<glm::vec2>(hitbox["ur"]);
++            }
++        } else {
++            throw std::string(
++                "Physics component table formatted incorrectly"
++            );
++        }
          return *this;
      }
  
index fc5cb9ac11dbe620bfa50a50dedbabcd67cbb0f7,56e8707653bc8210a3db5c5ac1b62279286f71af..bfa4b41f15e7b767d6260299982627f3776eb6be
  struct Position : Component<Position>
  {
  public:
-     float x, y;
 -    double x, y;
++    float x, y, z;
  
-     Position(float _x = 0, float _y = 0) :
 -    Position(double _x = 0, double _y = 0) :
--        x(_x), y(_y) {}
++    Position(float _x = 0, float _y = 0, float _z = 0) :
++        x(_x), y(_y), z(_z) {}
  
      Position FromLua(sol::object ref)
      {
-         glm::vec2 vec = Script::to<glm::vec2>(ref);
 -        if (ref.get_type() == sol::type::table) {
 -            sol::table tab = ref;
 -            if (tab["x"] != nullptr)
 -                this->x = tab["x"];
 -            if (tab["y"] != nullptr)
 -                this->y = tab["y"];
 -        } else {
 -            throw std::string("Position table not formatted properly");
 -        }
++        glm::vec3 vec = Script::to<glm::vec3>(ref);
 +        this->x = vec.x;
 +        this->y = vec.y;
++        this->z = vec.z;
 +
          return *this;
      }
  
-     glm::vec2 vec()
++    glm::vec3 vec()
 +    {
-         return glm::vec2(x, y);
++        return glm::vec3(x, y, z);
 +    }
 +
      void serialize(cereal::JSONOutputArchive& ar) final {
          ar(CEREAL_NVP(x), CEREAL_NVP(y));
      }
diff --cc src/render.cpp
Simple merge
diff --cc src/script.cpp
index 4cfcdddbaaaaa1fc1c89391ff3bfe42036660db3,0f940d3f0515f188f149c5b37ba07401c0d530c2..4fda54358ca13fcb79c6db2088f8ba028787013c
@@@ -87,16 -87,10 +87,11 @@@ void ScriptSystem::doFile(void
  
  void ScriptSystem::scriptExport(void)
  {
-     std::function<sol::table(sol::table)> entitySpawn = 
-         [this](sol::table t){ return spawn(t);};
-     std::function<World* (sol::object)> worldRegister =
-         [this](sol::object t){ return worldSystem.addWorld(t); };
      lua.new_usertype<Position>("Position",
-             sol::constructors<Position(float x, float y), Position()>(),
 -            sol::constructors<Position(double x, double y), Position()>(),
++            sol::constructors<Position(float x, float y, float z), Position()>(),
              "x", &Position::x,
--            "y", &Position::y);
++            "y", &Position::y,
++            "z", &Position::z);
  
      lua.new_usertype<Name>("Name",
              sol::constructors<Name(std::string), Name()>(),
  
      lua.new_usertype<Physics>("Physics",
              sol::constructors<Physics(void), Physics()>(),
--            "standing", &Physics::standing);
++            "standing", &Physics::standing,
++            "gravity", &Physics::gravity);
  
      lua.new_usertype<World>("World",
              sol::constructors<World(sol::object), World(void)>(),
              "Generate", &World::generate,
              "Seed", sol::property(&World::setSeed, &World::getSeed),
 -            "setData", &World::setData,
 -            "registerMaterial", &World::registerMaterial,
 -            "setSize", &World::setSize,
 -            "getSize", &World::getSize);
 +            "getSize", &World::getSize,
 +
 +            // New stuff
 +            "unitSize", sol::property(&World::setUnitSize, &World::getUnitSize),
 +            "createLayer", &World::registerLayer,
 +            "createDecoLayer", &World::registerDecoLayer);
  
      game = lua["game"].get_or_create<sol::table>();
-     game.set_function("spawn", entitySpawn);
-     game.set_function("worldRegister", worldRegister);
+     game.set_function("spawn", bindInstance(&ScriptSystem::spawn, this));
+     game.set_function("worldRegister", bindInstance(&WorldSystem::addWorld,
+                                                     &worldSystem));
  }
  
  sol::table ScriptSystem::spawn(sol::object param)
diff --cc src/world.cpp
index fb846eb594d922e31e4cd956436c7692ab270882,cd89a220e665196cc75c9f2c91ee91440660a10a..8987eacfc0a4de15ff84f88d3bee501b16f5a63f
@@@ -68,41 -133,53 +68,37 @@@ World::getSize(
  /* RENDERING */
  void World::generateMesh()
  {
-     for (auto &l : solidLayers) {
 -    //const unsigned int voxelLength = 6; // 2 triangles @ 3 points each
 -
 -    // Preallocate size of vertexes
 -    mesh = std::basic_string<WorldMeshData>();
 -    for (float Z = data.size() - 1; Z >= 0; Z--) {
 -        for (float X = 0; X < data.at(Z).size(); X++) {
 -            for (float Y = 0; Y < data.at(Z).at(X).size(); Y++) {
 -                int d = data.at(Z).at(X).at(Y);
 -
 -                if (d == -1) // Don't make a mesh for air of course
 -                    continue;
 -
 -                Texture &t = registry.at(d).texture;
 -                glm::vec2& to = t.offset;
 -                glm::vec2& ts = t.size;
 -
 -                float tr = 1.0f;
 -
 -                // TODO play with this a bit so it only goes trans
 -                //  if player is behind the front layer
 -                try {
 -                    if (Z < data.size() - 1 && Z >= 0) {
 -                        if (data.at(Z+1).at(X).at(Y) == -1)
 -                            tr = 1.0f;
 -                    }
 -                } catch (...) {
 -                    tr = 1.0f;
 -                }
 -
 -                mesh += {X  , Y  , Z, to.x     , to.y+ts.y, tr};
 -                mesh += {X+1, Y  , Z, to.x+ts.x, to.y+ts.y, tr};
 -                mesh += {X  , Y+1, Z, to.x     , to.y     , tr};
 -
 -                mesh += {X+1, Y  , Z, to.x+ts.x, to.y+ts.y, tr};
 -                mesh += {X+1, Y+1, Z, to.x+ts.x, to.y     , tr};
 -                mesh += {X  , Y+1, Z, to.x     , to.y     , tr};
 -            }
 -        }
++    for (auto &l : drawLayers) {
 +        
 +        // Preallocate size of vertexes
 +
-         float Z = l.drawLayer;
-         auto to = l.texture.offset;
-         auto ts = l.texture.size;
++        float Z = l->drawLayer;
++        auto to = l->texture.offset;
++        auto ts = l->texture.size;
 +        float tr = 1.0f;
 +
-         float w = l.texture.width/unitSize;
-         float h = l.texture.height/unitSize;
++        float w = l->texture.width/unitSize;
++        float h = l->texture.height/unitSize;
 +
 +        GLfloat mesh[36] = {0  , 0  , Z, to.x     , to.y+ts.y, tr,
 +                            0+w, 0  , Z, to.x+ts.x, to.y+ts.y, tr,
 +                            0  , 0+h, Z, to.x     , to.y     , tr,
 +
 +                            0+w, 0  , Z, to.x+ts.x, to.y+ts.y, tr,
 +                            0+w, 0+h, Z, to.x+ts.x, to.y     , tr,
 +                            0  , 0+h, Z, to.x     , to.y     , tr};
 +
-         glBindBuffer(GL_ARRAY_BUFFER, l.layerVBO);
++        glBindBuffer(GL_ARRAY_BUFFER, l->layerVBO);
 +        glBufferData(GL_ARRAY_BUFFER, 
 +                     36 * sizeof(GLfloat), 
 +                     mesh, 
 +                     GL_STATIC_DRAW);
 +
-         meshAdd.push_back(WorldMeshUpdateEvent(l.layerVBO,
-                                                l.texture.tex,
-                                                l.normal.tex,
++        meshAdd.push_back(WorldMeshUpdateEvent(l->layerVBO,
++                                               l->texture.tex,
++                                               l->normal.tex,
 +                                               36));
      }
--
-     for (auto &l : drawLayers) {
-         (void)l;
-     }
 -    glBindBuffer(GL_ARRAY_BUFFER, worldVBO);
 -    glBufferData(GL_ARRAY_BUFFER, 
 -                 mesh.size() * sizeof(WorldMeshData), 
 -                 mesh.data(), 
 -                 GL_STATIC_DRAW);
 -
 -    meshUpdated = true;
  }
  
  /* SEED */
@@@ -120,47 -197,28 +116,101 @@@ unsigned int World::setSeed(unsigned in
  /* PHYSICS */
  double World::getHeight(double x, double y, double z)
  {
 -    unsigned int X = static_cast<unsigned int>(x);
 -    unsigned int Z = static_cast<unsigned int>(z);
 -
 -    double Y = 0.0;
 -    try {
 -        auto &d = data.at(Z).at(X);
 -        for (int yi = d.size()-1; yi >= 0; yi--) {
 -            if (d.at(yi) >= 0) {
 -                if (!registry.at(d.at(yi)).passable) {
 -                    Y = static_cast<double>(yi);
 -                    Y += 1;
 -                    break;
 +    (void)y;
 +    double Y = 0.0f;
 +    for (auto &l : solidLayers) {
-         if (z == l.drawLayer) {
++        if (z == l->drawLayer) {
 +            int wx = x*unitSize;
 +
 +            int h = 0.0;
-             for (auto b : l.hitbox[wx]) {
++            for (auto b : l->hitbox[wx]) {
 +                if (b == true)
 +                    Y = h;
 +                h++;
 +            }
-             return (Y/unitSize);
++            return ((Y+1)/unitSize);
 +        }
 +    }
 +    return 0;
 +}
 +
++std::vector<std::pair<glm::vec2, glm::vec2>> 
++World::getIntersectingPlanes(glm::vec2 origin, glm::vec2 dest)
++{
++    (void)origin;
++    (void)dest;
++    //glm::ivec2 worldOrigin = origin*unitSize;
++    //glm::ivec2 worldDest = dest*unitSize;
++
++    return std::vector<std::pair<glm::vec2, glm::vec2>>();
++}
++
++glm::vec3 World::collide(glm::vec3 &start, glm::vec3 &end, Physics &phys)
++{
++    (void)start;
++    (void)end;
++    (void)phys;
++    for (auto &l : solidLayers) {
++        if (end.z == l->drawLayer) {
++            glm::vec2 len = end-start;
++            glm::vec2 dir = glm::normalize(len);
++            float step = 1.0f/unitSize;
++
++            // TODO move this
++            glm::vec2 pos = start;
++
++            for (float i = 0; i < len.length(); i+=step) {
++                pos += dir;
++
++                if (dir.x > 0.0f) {
++                // Moving to the right
++                    //glm::vec2 origin = pos + phys.corners[1]; // bottom right
++                    //glm::vec2 orDir = glm::vec2(0, 1);
++
++                } else if (dir.x < 0.0f) {
++                // Moving to the left
++
++                }
++
++                if (dir.y > 0.0f) {
++                // Moving upwards
++
++                } else if (dir.y < 0.0f) {
++                // Moving downwards
++
+                 }
+             }
+         }
 -    } catch (...) { // If we get any errors, just let the character 
 -        //return y;
 -        (void)y;
 -        return 0.0;
+     }
++    return glm::vec3(0);
++}
++
++
 +/*********
 +*  NEW  *
 +*********/
 +void World::registerLayer(float z, sol::object obj)
 +{
 +    if (obj.get_type() == sol::type::table) {
 +        sol::table tab = obj;
-         solidLayers.push_back(SolidLayer(z, tab));
++        SolidLayer s(z, tab);
++        solidLayers.push_back(std::make_shared<SolidLayer>(s));
++        drawLayers.push_back(std::make_shared<Layer>(s));
 +    } else {
 +        throw std::string("Layer must receive a table");
 +    }
 +    generateMesh();
 +}
  
 -    return Y;
 +void World::registerDecoLayer(float z, sol::object obj)
 +{
 +    if (obj.get_type() == sol::type::table) {
 +        sol::table tab = obj;
-         drawLayers.push_back(Layer(z, tab));
++        drawLayers.push_back(std::make_shared<Layer>(Layer(z, tab)));
 +    } else {
 +        throw std::string("Layer must receive a table");
 +    }
 +    generateMesh();
  }
  
  
diff --cc src/world.hpp
index 66d9e3f13ef4aba90e8fa01a98a97017ee28ad62,9314fa6d1bdb145ff5868c4f9e2637adb82930a4..0c1275e33edbac0f04b5d179e6f229bfc7b70a52
  #include <entityx/entityx.h>
  #include <sol/sol.hpp>
  
 +#include <soil/SOIL.h>
 +
  #include "texture.hpp"
 -struct WorldMeshData
 -{
 -    float posX, posY, posZ;
 -    float texX, texY;
 -    float transparency;
 -}__attribute__((packed));
 +#include "events/render.hpp"
 +
++#include <components/Position.hpp> // For entity position
++#include <components/Velocity.hpp> // For entity velocity
++#include <components/Physics.hpp>  // For entity hitbox(es)
  struct WorldMaterial
  {
      bool passable = false;
@@@ -119,9 -64,13 +124,12 @@@ private
      unsigned int seed;
      unsigned int layers;
  
 -    unsigned int height;
 -    unsigned int width;
 -
 -    std::vector<std::vector<std::vector<int>>> data;
 +    unsigned int unitSize;
-     std::vector<SolidLayer> solidLayers;
-     std::vector<Layer> drawLayers;
++    std::vector<std::shared_ptr<SolidLayer>> solidLayers;
++    std::vector<std::shared_ptr<Layer>> drawLayers;
 -    std::unordered_map<std::string, int> string_registry;
 -    std::vector<WorldMaterial> registry;
++    std::vector<std::pair<glm::vec2, glm::vec2>>
++        getIntersectingPlanes(glm::vec2 origin, glm::vec2 dir);
  
  protected:
      // RENDER
@@@ -150,13 -115,6 +158,14 @@@ public
  
      /* PHYSICS */
      double getHeight(double x, double y, double z);
++    glm::vec3 collide(glm::vec3 &start, glm::vec3 &end, Physics &phys);
 +
 +    // NEW
 +    unsigned int getUnitSize() {return unitSize;}
 +    void setUnitSize(unsigned int u) {unitSize = u;}
 +
 +    void registerLayer(float, sol::object);
 +    void registerDecoLayer(float, sol::object);
  };
  
  /**