]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Started texture based world definitions
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Tue, 1 Oct 2019 06:01:20 +0000 (02:01 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Tue, 1 Oct 2019 06:01:20 +0000 (02:01 -0400)
13 files changed:
Assets/world/world1/layers/0/hitbox.png [new file with mode: 0644]
Assets/world/world1/layers/0/normal.png [new file with mode: 0644]
Assets/world/world1/layers/0/texture.png [new file with mode: 0644]
Assets/world/world1/layers/1/hitbox.png [new file with mode: 0644]
Assets/world/world1/layers/1/normal.png [new file with mode: 0644]
Assets/world/world1/layers/1/texture.png [new file with mode: 0644]
Assets/world/world1/layers/deco/normal.png [new file with mode: 0644]
Assets/world/world1/layers/deco/texture.png [new file with mode: 0644]
Makefile
Scripts/world.lua
src/script.cpp
src/world.cpp
src/world.hpp

diff --git a/Assets/world/world1/layers/0/hitbox.png b/Assets/world/world1/layers/0/hitbox.png
new file mode 100644 (file)
index 0000000..0a9a37e
Binary files /dev/null and b/Assets/world/world1/layers/0/hitbox.png differ
diff --git a/Assets/world/world1/layers/0/normal.png b/Assets/world/world1/layers/0/normal.png
new file mode 100644 (file)
index 0000000..bc2ede6
Binary files /dev/null and b/Assets/world/world1/layers/0/normal.png differ
diff --git a/Assets/world/world1/layers/0/texture.png b/Assets/world/world1/layers/0/texture.png
new file mode 100644 (file)
index 0000000..149273f
Binary files /dev/null and b/Assets/world/world1/layers/0/texture.png differ
diff --git a/Assets/world/world1/layers/1/hitbox.png b/Assets/world/world1/layers/1/hitbox.png
new file mode 100644 (file)
index 0000000..0a9a37e
Binary files /dev/null and b/Assets/world/world1/layers/1/hitbox.png differ
diff --git a/Assets/world/world1/layers/1/normal.png b/Assets/world/world1/layers/1/normal.png
new file mode 100644 (file)
index 0000000..bc2ede6
Binary files /dev/null and b/Assets/world/world1/layers/1/normal.png differ
diff --git a/Assets/world/world1/layers/1/texture.png b/Assets/world/world1/layers/1/texture.png
new file mode 100644 (file)
index 0000000..149273f
Binary files /dev/null and b/Assets/world/world1/layers/1/texture.png differ
diff --git a/Assets/world/world1/layers/deco/normal.png b/Assets/world/world1/layers/deco/normal.png
new file mode 100644 (file)
index 0000000..c0aab94
Binary files /dev/null and b/Assets/world/world1/layers/deco/normal.png differ
diff --git a/Assets/world/world1/layers/deco/texture.png b/Assets/world/world1/layers/deco/texture.png
new file mode 100644 (file)
index 0000000..ce37a03
Binary files /dev/null and b/Assets/world/world1/layers/deco/texture.png differ
index dcbac2bea5f759dbf1b205c93e230104500bd3f8..e5861100cccda8e995cf009841b50e4a8857b9e6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -83,4 +83,3 @@ $(OUTDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
        @rm -f $(OUTDIR)/$*.$(DEPEXT).tmp
 
 .PHONY: all remake clean cleaner resources
-
index 3b56d9ae9ef86c1f8e1aa3c11d201188eeea8952..40d72187352c9a9308420b5b999648622611b2d8 100644 (file)
@@ -7,7 +7,6 @@ world = {
     Register = function(self)
 
         -- TODO make world have global textures to speed up rendering
-
         self:registerMaterial("grass", {
             -- TODO combine both of these into 1
             texture = {
@@ -110,3 +109,25 @@ world = {
 
 --world:Generate()
 game.worldRegister(world)
+
+newWorld = {
+    Register = function(self)
+        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 = { file = "Assets/world/world1/layers/0/hitbox.png" }
+        });
+        self:createLayer(1, {
+            texture = { file = "Assets/world/world1/layers/1/texture.png" },
+            normal = { file = "Assets/world/world1/layers/1/normal.png" },
+            hitbox = { file = "Assets/world/world1/layers/1/hitbox.png" }
+        });
+        self:createDecoLayer(10, {
+            texture = { file = "Assets/world/world1/layers/deco/texture.png" },
+            normal = { file = "Assets/world/world1/layers/deco/normal.png" },
+        });
+    end,
+    Generate = function(self) end
+}
+game.worldRegister(newWorld);
index 6cda627d2d8f41418ef1ea2c17c275bc8f068040..629baa9d9c22a22b10f2c019789dd8e782c610fd 100644 (file)
@@ -134,7 +134,12 @@ void ScriptSystem::scriptExport(void)
             "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);
index cd89a220e665196cc75c9f2c91ee91440660a10a..8cfd906e702a24a2d6d26b589e92b9f4ba409f0e 100644 (file)
@@ -134,6 +134,8 @@ World::getSize()
 void World::generateMesh()
 {
     //const unsigned int voxelLength = 6; // 2 triangles @ 3 points each
+    if (!data.size())
+        return;
 
     // Preallocate size of vertexes
     mesh = std::basic_string<WorldMeshData>();
@@ -221,6 +223,29 @@ double World::getHeight(double x, double y, double z)
     return Y;
 }
 
+/*********
+*  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));
+    } else {
+        throw std::string("Layer must receive a table");
+    }
+}
+
+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));
+    } else {
+        throw std::string("Layer must receive a table");
+    }
+}
+
 
 /******************
 *  WORLD SYSTEM  *
index 9314fa6d1bdb145ff5868c4f9e2637adb82930a4..acdb53365a7d5d82052459af43beeaa5d6fc537f 100644 (file)
@@ -57,6 +57,41 @@ struct WorldMaterial
     }
 };
 
+class Layer
+{
+private:
+    Texture texture;
+    Texture normal;
+
+    float drawLayer = 0.0f;
+
+public:
+
+    Layer(float z, sol::table tab) {
+        drawLayer = z;
+        if (tab["texture"] != nullptr) {
+            sol::object t = tab["texture"];
+            texture = Texture(t);
+        }
+        if (tab["normal"] != nullptr) {
+            sol::object n = tab["normal"];
+            normal = Texture(n);
+        }
+    }
+};
+
+class SolidLayer : public Layer
+{
+private:
+    // hitbox something something
+public:
+    SolidLayer(float z, sol::table tab) : Layer(z, tab) {
+        if (tab["hitbox"] != nullptr) {
+            std::cout << "hitbox: " << std::string(tab["hitbox"]) << std::endl;
+        }
+    }
+};
+
 class World
 {
     friend class WorldSystem;
@@ -72,6 +107,11 @@ private:
     std::unordered_map<std::string, int> string_registry;
     std::vector<WorldMaterial> registry;
 
+    // NEW
+    unsigned int unitSize;
+    std::vector<SolidLayer> solidLayers;
+    std::vector<Layer> drawLayers;
+
 protected:
     // RENDER
     std::basic_string<WorldMeshData> mesh;
@@ -115,6 +155,13 @@ public:
 
     /* PHYSICS */
     double getHeight(double x, double y, double z);
+
+    // NEW
+    unsigned int getUnitSize() {return unitSize;}
+    void setUnitSize(unsigned int u) {unitSize = u;}
+
+    void registerLayer(float, sol::object);
+    void registerDecoLayer(float, sol::object);
 };
 
 /**