aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-10-01 02:01:20 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-10-01 02:01:20 -0400
commita62d96ad0521b064e6ef61a6f80888e27966502b (patch)
treed56045d4330314d608c39b5b1f304a4b99f17975
parent5cceca5ec696e6626cea0ec07f9db1b28bb3b875 (diff)
Started texture based world definitions
-rw-r--r--Assets/world/world1/layers/0/hitbox.pngbin0 -> 3972 bytes
-rw-r--r--Assets/world/world1/layers/0/normal.pngbin0 -> 4196 bytes
-rw-r--r--Assets/world/world1/layers/0/texture.pngbin0 -> 4573 bytes
-rw-r--r--Assets/world/world1/layers/1/hitbox.pngbin0 -> 3972 bytes
-rw-r--r--Assets/world/world1/layers/1/normal.pngbin0 -> 4196 bytes
-rw-r--r--Assets/world/world1/layers/1/texture.pngbin0 -> 4573 bytes
-rw-r--r--Assets/world/world1/layers/deco/normal.pngbin0 -> 4243 bytes
-rw-r--r--Assets/world/world1/layers/deco/texture.pngbin0 -> 7285 bytes
-rw-r--r--Makefile1
-rw-r--r--Scripts/world.lua23
-rw-r--r--src/script.cpp7
-rw-r--r--src/world.cpp25
-rw-r--r--src/world.hpp47
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
new file mode 100644
index 0000000..0a9a37e
--- /dev/null
+++ b/Assets/world/world1/layers/0/hitbox.png
Binary files differ
diff --git a/Assets/world/world1/layers/0/normal.png b/Assets/world/world1/layers/0/normal.png
new file mode 100644
index 0000000..bc2ede6
--- /dev/null
+++ b/Assets/world/world1/layers/0/normal.png
Binary files differ
diff --git a/Assets/world/world1/layers/0/texture.png b/Assets/world/world1/layers/0/texture.png
new file mode 100644
index 0000000..149273f
--- /dev/null
+++ b/Assets/world/world1/layers/0/texture.png
Binary files differ
diff --git a/Assets/world/world1/layers/1/hitbox.png b/Assets/world/world1/layers/1/hitbox.png
new file mode 100644
index 0000000..0a9a37e
--- /dev/null
+++ b/Assets/world/world1/layers/1/hitbox.png
Binary files differ
diff --git a/Assets/world/world1/layers/1/normal.png b/Assets/world/world1/layers/1/normal.png
new file mode 100644
index 0000000..bc2ede6
--- /dev/null
+++ b/Assets/world/world1/layers/1/normal.png
Binary files differ
diff --git a/Assets/world/world1/layers/1/texture.png b/Assets/world/world1/layers/1/texture.png
new file mode 100644
index 0000000..149273f
--- /dev/null
+++ b/Assets/world/world1/layers/1/texture.png
Binary files differ
diff --git a/Assets/world/world1/layers/deco/normal.png b/Assets/world/world1/layers/deco/normal.png
new file mode 100644
index 0000000..c0aab94
--- /dev/null
+++ b/Assets/world/world1/layers/deco/normal.png
Binary files differ
diff --git a/Assets/world/world1/layers/deco/texture.png b/Assets/world/world1/layers/deco/texture.png
new file mode 100644
index 0000000..ce37a03
--- /dev/null
+++ b/Assets/world/world1/layers/deco/texture.png
Binary files differ
diff --git a/Makefile b/Makefile
index dcbac2b..e586110 100644
--- a/Makefile
+++ b/Makefile
@@ -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);
};
/**