From a2ae7aae8357c8c2684d85fd58b0c5a0563ebab9 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 9 May 2023 11:31:17 -0500 Subject: refactor: split ecs systems into multiple files --- main.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index 71ef11b..efee1a2 100644 --- a/main.lua +++ b/main.lua @@ -7,7 +7,6 @@ local Mat4 = honey.Mat4 local Quaternion = honey.Quaternion local ecs = honey.ecs local sys = honey.standardSystems -local dispatch = sys.dispatch local ode = honey.ode local nvg = honey.nvg @@ -35,12 +34,12 @@ end) -- setup ecs local entities = ecs.EntityDb() local systems = ecs.SystemDb(entities) - -systems:addSystem(sys.node) -systems:addSystem(sys.renderCamera) -systems:addSystem(sys.script) -systems:addSystem(sys.collision, {space=space}) -systems:addSystem(sys.physics, {space=space, world=world}) +local script = ecs.script +systems:addSystem(ecs.node.system) +systems:addSystem(ecs.render.system) +systems:addSystem(ecs.script.system) +systems:addSystem(ecs.collision.system, {space=space}) +systems:addSystem(ecs.physics.system, {space=space, world=world}) package.loaded['baseRotationScript'] = function(entities, id, dt) local node = entities:getComponent(id, "node") node.matrix:rotateZ(math.pi * dt) @@ -299,7 +298,7 @@ setupEntities() -- close window on ESCAPE key window:setKeyCallback(function(_, key, scancode, action) - dispatch(entities, "onKey", {key=key, scancode=scancode, action=action}) + script.dispatch(entities, "onKey", {key=key, scancode=scancode, action=action}) if action == glfw.PRESS then if key == glfw.KEY_ESCAPE then window:setShouldClose(true) @@ -313,14 +312,14 @@ end) window:setCursorPosCallback(function(_, xpos, ypos) - dispatch(entities, "onCursorPos", {xpos=xpos, ypos=ypos}) + script.dispatch(entities, "onCursorPos", {xpos=xpos, ypos=ypos}) end) -- resize window correctly window:setFramebufferSizeCallback(function(_, width, height) gl.Viewport(0, 0, width, height) vw, vh = width, height - dispatch(entities, "onWindowResize", { width=width, height=height }) + script.dispatch(entities, "onWindowResize", { width=width, height=height }) end) package.loaded["cameraHandleResize"] = function(entities, id, data) -- cgit v1.2.1