diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-10-01 02:01:20 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-10-01 02:01:20 -0400 |
commit | a62d96ad0521b064e6ef61a6f80888e27966502b (patch) | |
tree | d56045d4330314d608c39b5b1f304a4b99f17975 | |
parent | 5cceca5ec696e6626cea0ec07f9db1b28bb3b875 (diff) |
Started texture based world definitions
-rw-r--r-- | Assets/world/world1/layers/0/hitbox.png | bin | 0 -> 3972 bytes | |||
-rw-r--r-- | Assets/world/world1/layers/0/normal.png | bin | 0 -> 4196 bytes | |||
-rw-r--r-- | Assets/world/world1/layers/0/texture.png | bin | 0 -> 4573 bytes | |||
-rw-r--r-- | Assets/world/world1/layers/1/hitbox.png | bin | 0 -> 3972 bytes | |||
-rw-r--r-- | Assets/world/world1/layers/1/normal.png | bin | 0 -> 4196 bytes | |||
-rw-r--r-- | Assets/world/world1/layers/1/texture.png | bin | 0 -> 4573 bytes | |||
-rw-r--r-- | Assets/world/world1/layers/deco/normal.png | bin | 0 -> 4243 bytes | |||
-rw-r--r-- | Assets/world/world1/layers/deco/texture.png | bin | 0 -> 7285 bytes | |||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | Scripts/world.lua | 23 | ||||
-rw-r--r-- | src/script.cpp | 7 | ||||
-rw-r--r-- | src/world.cpp | 25 | ||||
-rw-r--r-- | src/world.hpp | 47 |
13 files changed, 100 insertions, 3 deletions
diff --git a/Assets/world/world1/layers/0/hitbox.png b/Assets/world/world1/layers/0/hitbox.png Binary files differnew file mode 100644 index 0000000..0a9a37e --- /dev/null +++ b/Assets/world/world1/layers/0/hitbox.png diff --git a/Assets/world/world1/layers/0/normal.png b/Assets/world/world1/layers/0/normal.png Binary files differnew file mode 100644 index 0000000..bc2ede6 --- /dev/null +++ b/Assets/world/world1/layers/0/normal.png diff --git a/Assets/world/world1/layers/0/texture.png b/Assets/world/world1/layers/0/texture.png Binary files differnew file mode 100644 index 0000000..149273f --- /dev/null +++ b/Assets/world/world1/layers/0/texture.png diff --git a/Assets/world/world1/layers/1/hitbox.png b/Assets/world/world1/layers/1/hitbox.png Binary files differnew file mode 100644 index 0000000..0a9a37e --- /dev/null +++ b/Assets/world/world1/layers/1/hitbox.png diff --git a/Assets/world/world1/layers/1/normal.png b/Assets/world/world1/layers/1/normal.png Binary files differnew file mode 100644 index 0000000..bc2ede6 --- /dev/null +++ b/Assets/world/world1/layers/1/normal.png diff --git a/Assets/world/world1/layers/1/texture.png b/Assets/world/world1/layers/1/texture.png Binary files differnew file mode 100644 index 0000000..149273f --- /dev/null +++ b/Assets/world/world1/layers/1/texture.png diff --git a/Assets/world/world1/layers/deco/normal.png b/Assets/world/world1/layers/deco/normal.png Binary files differnew file mode 100644 index 0000000..c0aab94 --- /dev/null +++ b/Assets/world/world1/layers/deco/normal.png diff --git a/Assets/world/world1/layers/deco/texture.png b/Assets/world/world1/layers/deco/texture.png Binary files differnew file mode 100644 index 0000000..ce37a03 --- /dev/null +++ b/Assets/world/world1/layers/deco/texture.png @@ -83,4 +83,3 @@ $(OUTDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT) @rm -f $(OUTDIR)/$*.$(DEPEXT).tmp .PHONY: all remake clean cleaner resources - diff --git a/Scripts/world.lua b/Scripts/world.lua index 3b56d9a..40d7218 100644 --- a/Scripts/world.lua +++ b/Scripts/world.lua @@ -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); diff --git a/src/script.cpp b/src/script.cpp index 6cda627..629baa9 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -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); diff --git a/src/world.cpp b/src/world.cpp index cd89a22..8cfd906 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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 * diff --git a/src/world.hpp b/src/world.hpp index 9314fa6..acdb533 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -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); }; /** |