summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-03-22 12:12:31 -0500
committersanine-a <sanine.not@pm.me>2023-03-22 12:12:31 -0500
commit16bcc6daab84373cac0f4125c1580d3cb1261baf (patch)
tree7a6156e204579264ce867c4771c35265f680e84b /main.lua
parenta45f73c7388b3f5a5901bfcc66fd2d1df58d3001 (diff)
move ecs systems into separate module
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua76
1 files changed, 10 insertions, 66 deletions
diff --git a/main.lua b/main.lua
index 251f466..8dd9207 100644
--- a/main.lua
+++ b/main.lua
@@ -6,77 +6,21 @@ local gl = honey.gl
local Vec3 = honey.Vec3
local Mat4 = honey.Mat4
local ecs = honey.ecs
+local systems = honey.standardSystems
-- camera matrices
local camera = {
- view=Mat4.Identity(),
- projection=Mat4(),
+ view=Mat4():identity():translate(Vec3{0, 0, -60}),
+ projection=Mat4():perspective(math.rad(45), 640/480, 0.1, 100),
}
-camera.view:translate(Vec3{0, 0, -60})
-camera.projection:perspective(math.rad(45), 640/480, 0.1, 100)
-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
-
local level = ecs.Level()
--- update transforms
-level:addSystem{
- filter=ecs.Filter.AND{"transform", "parent"},
- update=function(entity, dt)
- recursiveComputeTransform(entity)
- end,
- priority=1,
-}
-level:addSystem{
- filter=ecs.Filter.AND{"transform", "parent"},
- update=function(entity, dt)
- entity._transform = nil
- entity._transformComputed = false
- end,
- priority=0,
-}
-
--- render objects
-level:addSystem{
- filter=ecs.Filter.AND{"mesh", "shader", "transform"},
- update=function(entity, dt)
- entity.shader:use()
- entity.shader:configure{
- matrix={
- model=entity._transform,
- view=camera.view,
- projection=camera.projection,
- },
- }
- entity.mesh:drawElements()
- end,
- priority=99,
-}
-
--- run custom scripts
-level:addSystem{
- filter=ecs.Filter.AND{"update"},
- update=function(entity, dt)
- entity.update(entity, dt)
- end,
- priority=50,
-}
+level:addSystem(systems.transformCascade)
+level:addSystem(systems.renderCam(camera))
+level:addSystem(systems.update)
@@ -149,12 +93,12 @@ function growLine(prev, depth)
if depth == 0 then return prev end
local entity = {
- transform=Mat4.Identity(),
+ transform=Mat4():identity():translate(Vec3{2, 0, 0}),
+ parent=false,
mesh=octa,
shader=shader,
update=updateTransform,
}
- entity.transform:translate(Vec3{2, 0, 0})
prev.parent = entity
level:addEntity(prev)
return growLine(entity, depth-1)
@@ -162,12 +106,12 @@ end
local leaf = {
- transform=Mat4.Identity(),
+ transform=Mat4():identity():translate(Vec3{2, 0, 0}),
+ parent=false,
mesh=tetra,
shader=shader,
}
local root = growLine(leaf, 24)
-root.parent = false
level:addEntity(root)