summaryrefslogtreecommitdiff
path: root/honey.bak/ecs-systems.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-03-28 16:35:22 -0500
committersanine-a <sanine.not@pm.me>2023-03-28 16:35:22 -0500
commit45dbe47d17303050cbea7c2c51e838acfe21c2fb (patch)
treec2827c7aae6cf29286766209af942f16f91ee4c8 /honey.bak/ecs-systems.lua
parentd1c2a881f55b80603f6a7772a2c32394d23e795a (diff)
add cached mesh loading
Diffstat (limited to 'honey.bak/ecs-systems.lua')
-rw-r--r--honey.bak/ecs-systems.lua76
1 files changed, 76 insertions, 0 deletions
diff --git a/honey.bak/ecs-systems.lua b/honey.bak/ecs-systems.lua
new file mode 100644
index 0000000..5dec159
--- /dev/null
+++ b/honey.bak/ecs-systems.lua
@@ -0,0 +1,76 @@
+local ecs = require 'honey.ecs'
+
+
+local module = {}
+setmetatable(module, {__index=_G})
+setfenv(1, module)
+
+
+
+--===== transform cascading =====--
+
+local function recursiveComputeTransform(entity)
+ if entity._transformComputed then
+ return entity._transform
+ end
+ if entity.parent == false then
+ entity._transformComputed = true
+ entity._transform = entity.transform
+ return entity.transform
+ end
+
+ entity._transformComputed = true
+ local parentTransform = recursiveComputeTransform(entity.parent)
+ entity._transform = parentTransform * entity.transform
+ return entity._transform
+end
+
+-- update transforms
+transformCascade = {
+ filter=ecs.Filter.AND{"transform", "parent"},
+ prepareEntity=function(self, entity)
+ entity._transform = nil
+ entity._transformComputed = false
+ end,
+ update=function(self, entity, dt)
+ recursiveComputeTransform(entity)
+ end,
+ priority=98,
+}
+
+
+--===== rendering =====--
+
+function renderCam(camera, priority)
+ local priority = priority or 99
+ return {
+ filter=ecs.Filter.AND{"mesh", "shader", "transform"},
+ update=function(self, entity, dt)
+ entity.shader:use()
+ entity.shader:configure{
+ matrix={
+ model=entity._transform,
+ view=camera.view,
+ projection=camera.projection,
+ },
+ }
+ entity.mesh:drawElements()
+ end,
+ nopause=true,
+ priority=priority,
+ }
+end
+
+--===== update functions =====--
+
+update = {
+ filter=ecs.Filter.AND{"update"},
+ update=function(self, entity, dt)
+ entity.update(entity, dt)
+ end,
+ priority=50,
+}
+
+
+
+return module