]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Merge remote-tracking branch 'origin/lib-cleanup' into world
authorAndy Belle-Isle <abelleisle@protonmail.com>
Sun, 13 Nov 2022 19:55:26 +0000 (13:55 -0600)
committerAndy Belle-Isle <abelleisle@protonmail.com>
Sun, 13 Nov 2022 19:55:26 +0000 (13:55 -0600)
13 files changed:
1  2 
Makefile
Scripts/init.lua
Scripts/world.lua
lib/entityx
lib/sol2
src/components/Component.hpp
src/components/Physics.hpp
src/components/Position.hpp
src/components/Render.hpp
src/components/Velocity.hpp
src/engine.cpp
src/script.cpp
src/world.cpp

diff --cc Makefile
index f79435c0c337b1cfdd6cddb5834a2022a80f67fc,a14fb2bf14677d37d9ea90eabc49f9e61e18c598..c590bab58b0c6296078d2356289d6b2d15766ba5
+++ b/Makefile
@@@ -82,7 -88,18 +88,20 @@@ $(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
 +mem: $(EXEC)
 +      valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(EXEC)
 +
 -.PHONY: all remake clean cleaner cleanall resources
 -
+ lib/libentityx.a:
+       @cmake -S lib/entityx -B lib/entityx -DENTITYX_BUILD_SHARED=FALSE
+       @make -Clib/entityx -j4 entityx
+       @cp lib/entityx/libentityx.a lib/libentityx.a
+ lib/libluajit.a:
+       @make -Clib/luajit -j4
+       @cp lib/luajit/src/libluajit.a lib/libluajit.a
+ lib/libsoil.a:
+       @make -Clib/soil -j4
+       @cp lib/soil/libsoil.a lib/libsoil.a
++.PHONY: all remake clean cleaner cleanall resources mem
index 80fee320a452b85548310587c0d43494af034cac,66fbcb11fe0a4472316acdee10906c771cde454d..60f21c6d8ff032f6356b7c9318d2db86b8826c91
@@@ -38,24 -36,16 +39,29 @@@ player = 
          x = 0.0,
          y = 0.0
      },
 -    Physics = 0,
 +    Physics = {
 +        hitbox = {
 +            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",
+     Audio = {
+         file = "Assets/jump.wav"
+     },
+     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 1fb74d24bcaeb85f329a4fc9795977f51095ab59,bb6c61ea52973b5a2d5a13997a6e54c45efbb780..ec430259a778e0da3f11bbefafc030e00cad7f50
- 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
++local 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: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)
 -        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
  }
  
diff --cc lib/entityx
index 0000000000000000000000000000000000000000,e04b856006cfe6b7e8ba5d6c1434331351cc791a..3989cf4cf81da1077a501a1d53e6114f55b812f9
mode 000000,160000..160000
--- /dev/null
@@@ -1,0 -1,1 +1,1 @@@
 -Subproject commit e04b856006cfe6b7e8ba5d6c1434331351cc791a
++Subproject commit 3989cf4cf81da1077a501a1d53e6114f55b812f9
diff --cc lib/sol2
index 0000000000000000000000000000000000000000,4de99c5b41b64b7e654bf8e48b177e8414a756b7..50b62c9346750b7c2c406c9e4c546f96b0bf021d
mode 000000,160000..160000
--- /dev/null
+++ b/lib/sol2
@@@ -1,0 -1,1 +1,1 @@@
 -Subproject commit 4de99c5b41b64b7e654bf8e48b177e8414a756b7
++Subproject commit 50b62c9346750b7c2c406c9e4c546f96b0bf021d
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc src/engine.cpp
Simple merge
diff --cc src/script.cpp
index 4fda54358ca13fcb79c6db2088f8ba028787013c,9fae1c9e95d2280d6b7c0745e4539a33b78644a5..b1d82e97da5b6a4a98b727d8fb17feab782e588f
@@@ -120,9 -120,12 +121,13 @@@ void ScriptSystem::scriptExport(void
  
      lua.new_usertype<Physics>("Physics",
              sol::constructors<Physics(void), Physics()>(),
 -            "standing", &Physics::standing);
 +            "standing", &Physics::standing,
 +            "gravity", &Physics::gravity);
  
+     lua.new_usertype<Audio>("Audio",
+             sol::constructors<Audio(std::string)>(),
+             "file", &Audio::fileName);
      lua.new_usertype<World>("World",
              sol::constructors<World(sol::object), World(void)>(),
              "Generate", &World::generate,
diff --cc src/world.cpp
index 61a30de6c76504edc08cf2da1feb416e5b6c2ae3,cd89a220e665196cc75c9f2c91ee91440660a10a..48e54e36c575584399a36dbeba7bda35642f0480
@@@ -116,123 -197,18 +116,127 @@@ 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) {
 +            int wx = x*unitSize;
 +
 +            int h = 0.0;
 +            for (auto b : l->hitbox[wx]) {
 +                if (b == true)
 +                    Y = h;
 +                h++;
 +            }
 +            return ((Y+1)/unitSize);
 +        }
 +    }
 +    return 0;
 +}
 +
 +bool World::isSolid(glm::vec3 pos)
 +{
 +    for (auto &l : solidLayers) {
 +        if (pos.z == l->drawLayer) {
 +            int wx = pos.x * unitSize;
 +            int wy = pos.y * unitSize;
 +            if (wx < 0 || wy < 0) return true;
 +
 +            return l->hitbox[wx][wy];
 +        }
 +    }
 +    return false;
 +}
 +
 +std::vector<glm::vec3>
 +World::getIntersectingPlanes(glm::vec3 origin, Physics &phys)
 +{
 +    std::vector<glm::vec3> planes;
 +
 +    glm::vec3 goal = origin;
 +
 +    origin.x += phys.corners[0].x;
 +    origin.y += phys.corners[0].y;
 +
 +    goal.x += phys.corners[3].x;
 +    goal.y += phys.corners[3].y;
 +
 +    float step = 1.0f/unitSize;
 +    for (;origin.y <= goal.y; origin.y += step){
 +        for (;origin.x <= goal.x; origin.x += step) {
 +            if (isSolid(origin)) {
 +                planes.push_back(origin);
 +            }
 +        }
 +    }
 +
 +    return planes;
 +}
 +
 +glm::vec3 World::collide(glm::vec3 &start, glm::vec3 &end, Physics &phys)
 +{
 +    // How far to push the entity to unintersect with the world
 +    glm::vec3 push(0);
 +    for (auto &l : solidLayers) {
 +        if (start.z == l->drawLayer) {
 +            glm::vec3 len = end-start;
 +            glm::vec3 dir = glm::normalize(len);
 +            float step = 1.0f/unitSize;
 +
 +            glm::vec3 pos = start;
 +
 +            for (float i = 0.0f; i < glm::length(len); i+=step, pos+=dir) {
 +                // Get all colliding world spaces
 +                std::vector<glm::vec3> inter = getIntersectingPlanes(pos, phys);
 +
-                 if (i == 0.0f)
++                if (i == 0.0f) {
 +                    std::cout << inter.size() << std::endl;
++                    if (inter.size()) {
++                        p.standing = true;
++                    }
++                }
 +
 +                // If there are no colliding world spaces, don't bother
 +                if (inter.size()) {
 +                    if (dir.x > 0.0f) {
 +                    // Moving to the right
 +                        int closest = inter.at(0).x;
 +                        for (auto &p : inter) {
 +                            if (p.x < closest)
 +                                closest = p.x;
 +                        }
 +                        push.x -= abs(closest - (pos.x + phys.corners[1].x));
 +
 +                    } else if (dir.x < 0.0f) {
 +                    // Moving to the left
 +                        int closest = inter.at(0).x;
 +                        for (auto &p : inter) {
 +                            if (p.x > closest)
 +                                closest = p.x;
 +                        }
 +                        push.x += abs(closest - (pos.x + phys.corners[0].x));
 +                    }
 +
 +                    if (dir.y > 0.0f) {
 +                    // Moving upwards
 +                        int closest = inter.at(0).y;
 +                        for (auto &p : inter) {
 +                            if (p.y < closest)
 +                                closest = p.y;
 +                        }
 +                        push.y -= abs(closest - (pos.y + phys.corners[2].y));
 +                    } else if (dir.y < 0.0f) {
 +                    // Moving downwards
 +                        int closest = inter.at(0).y;
 +                        for (auto &p : inter) {
 +                            if (p.y > closest)
 +                                closest = p.y;
 +                        }
 +                        push.y += abs(closest - (pos.y + phys.corners[0].y));
 +                    }
 +
 +                    if (push != glm::vec3(0.0f))
 +                        return pos + push;
                  }
              }
          }