diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-14 02:51:20 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-14 02:51:20 -0400 |
commit | 4bf539d953871dbddddcc00275ffdcaddece5091 (patch) | |
tree | f2871e27fce45b89c93054b9930f2c458a1f5e51 | |
parent | 9583f32bc760576d250e78a79a812ec95ebd0f8e (diff) |
Updated world texture loading in Lua
-rw-r--r-- | Scripts/world.lua | 52 | ||||
-rw-r--r-- | src/world.cpp | 2 | ||||
-rw-r--r-- | src/world.hpp | 12 |
3 files changed, 51 insertions, 15 deletions
diff --git a/Scripts/world.lua b/Scripts/world.lua index f87f108..246ece0 100644 --- a/Scripts/world.lua +++ b/Scripts/world.lua @@ -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, diff --git a/src/world.cpp b/src/world.cpp index 1dca763..3fb5b6b 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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}; diff --git a/src/world.hpp b/src/world.hpp index cea599b..81e5b9d 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -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"]; |