]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Updated world texture loading in Lua
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Sat, 14 Sep 2019 06:51:20 +0000 (02:51 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Sat, 14 Sep 2019 06:51:20 +0000 (02:51 -0400)
Scripts/world.lua
src/world.cpp
src/world.hpp

index f87f1087ca262ada0639aabf937394395cd1c34a..246ece0de4accbe810fd482f31b31b6e2279af3b 100644 (file)
@@ -5,21 +5,57 @@ world = {
     -- 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", {
-            texture = "Assets/grass.png",
-            normal = "Assets/grass_normal"
+            -- TODO combine both of these into 1
+            texture = {
+                file = "Assets/world.png",
+                offset = { x = 0, y = 0 },
+                size = { x = 8, y = 8 }
+            },
+            normal = {
+                file = "Assets/world_normal.png",
+                offset = { x = 0, y = 0 },
+                size = { x = 8, y = 8 }
+            }
         });
         self:registerMaterial("dirt", {
-            texture = "Assets/dirt.png",
-            normal = "Assets/dirt_normal.png"
+            texture = {
+                file = "Assets/world.png",
+                offset = { x = 8, y = 0 },
+                size = { x = 8, y = 8 }
+            },
+            normal = {
+                file = "Assets/world_normal.png",
+                offset = { x = 8, y = 0 },
+                size = { x = 8, y = 8 }
+            }
         });
         self:registerMaterial("stone", {
-            texture = "Assets/stone.png",
-            normal = "Assets/dirt_normal.png"
+            texture = {
+                file = "Assets/world.png",
+                offset = { x = 16, y = 0 },
+                size = { x = 8, y = 8 }
+            },
+            normal = {
+                file = "Assets/world_normal.png",
+                offset = { x = 16, y = 0 },
+                size = { x = 8, y = 8 }
+            }
         });
         self:registerMaterial("flower", {
-            texture = "Assets/flower.png",
-            normal = "Assets/flower_normal.png",
+            texture = {
+                file = "Assets/world.png",
+                offset = { x = 24, y = 0 },
+                size = { x = 8, y = 8 }
+            },
+            normal = {
+                file = "Assets/world_normal.png",
+                offset = { x = 24, y = 0 },
+                size = { x = 8, y = 8 }
+            },
             passable = true
         });
     end,
index 1dca763944298f3c03434a658b51e270fe791175..3fb5b6b00a001ea3305e38526dffbc464c73851a 100644 (file)
@@ -144,7 +144,7 @@ void World::generateMesh()
 
                 Texture &t = registry.at(d).texture;
                 glm::vec2& to = t.offset;
-                glm::vec2& ts = t.offsetSize;
+                glm::vec2& ts = t.size;
 
                 mesh += {X  , Y  , Z, to.x     , to.y+ts.y, 1.0};
                 mesh += {X+1, Y  , Z, to.x+ts.x, to.y+ts.y, 1.0};
index cea599b76954d40180152b0740af8ebdfb1f9a46..81e5b9d46ac9892dbadc9d95024084121f8b8606 100644 (file)
@@ -43,13 +43,13 @@ struct WorldMaterial
     Texture normal;
 
     WorldMaterial(sol::table tab) {
-        if (tab["texture"] == sol::type::string) {
-            std::string tex = tab["texture"];
-            texture = Texture(tex);
+        if (tab["texture"] != nullptr) {
+            sol::object t = tab["texture"];
+            texture = Texture(t);
         }
-        if (tab["normal"] == sol::type::string) {
-            std::string nor = tab["normal"];
-            normal = Texture(nor);
+        if (tab["normal"] != nullptr) {
+            sol::object n = tab["normal"];
+            normal = Texture(n);
         }
         if (tab["passable"] == sol::type::boolean) {
             passable = tab["passable"];