diff options
author | sanine <sanine.not@pm.me> | 2023-04-07 00:53:03 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-04-07 00:53:03 -0500 |
commit | 3c9ba50944f1b136125e1191ccbc49fda1381123 (patch) | |
tree | f52a32da115d02eaeefe616122f607c92c62e57c /honey.bak/ecs-systems.lua | |
parent | f91a730b3a9ddd532c2ba9ff4f8b120a8ca2fa81 (diff) |
renormalize line endings
Diffstat (limited to 'honey.bak/ecs-systems.lua')
-rw-r--r-- | honey.bak/ecs-systems.lua | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/honey.bak/ecs-systems.lua b/honey.bak/ecs-systems.lua index 5dec159..e3f9d56 100644 --- a/honey.bak/ecs-systems.lua +++ b/honey.bak/ecs-systems.lua @@ -1,76 +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
+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 |