summaryrefslogtreecommitdiff
path: root/honey/ecs/node.lua
diff options
context:
space:
mode:
Diffstat (limited to 'honey/ecs/node.lua')
-rw-r--r--honey/ecs/node.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/honey/ecs/node.lua b/honey/ecs/node.lua
new file mode 100644
index 0000000..39f1898
--- /dev/null
+++ b/honey/ecs/node.lua
@@ -0,0 +1,47 @@
+local module = {}
+setmetatable(module, {__index=_G})
+setfenv(1, module)
+
+--===== transform cascading =====--
+
+system = function(params)
+ return {
+ db = params.db,
+
+ priority = 2,
+ update = function(self, dt)
+ local nodes = self.db:queryComponent("node")
+
+ -- prepare nodes
+ for id, node in pairs(nodes) do
+ node._visited = false
+ end
+
+ -- helper function
+ local function recursiveTransform(node)
+ if node._visited then
+ return node._matrix
+ end
+
+ if not node.parent then
+ node._matrix = node.matrix
+ else
+ local parentTransform = self.db:getComponent(node.parent, "node")
+ local parentMatrix = recursiveTransform(parentTransform)
+ node._matrix = parentMatrix * node.matrix
+ end
+ node._visited = true
+ return node._matrix
+ end
+
+ -- compute nodes
+ for id, node in pairs(nodes) do
+ recursiveTransform(node)
+ end
+ end,
+ }
+end
+
+
+
+return module