summaryrefslogtreecommitdiff
path: root/honey/ecs/node.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-09 11:31:17 -0500
committersanine-a <sanine.not@pm.me>2023-05-09 11:31:17 -0500
commita2ae7aae8357c8c2684d85fd58b0c5a0563ebab9 (patch)
tree5050161547408c80b521c9f4708bb9f7a9d0fa71 /honey/ecs/node.lua
parent2a14abecaee073aef1f1966bb397d6086b2e4785 (diff)
refactor: split ecs systems into multiple files
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