summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-04-13 15:13:46 -0500
committersanine-a <sanine.not@pm.me>2023-04-13 15:13:46 -0500
commit64be3e5d5788e5e866d7f5fb7b1c6f754735f2f4 (patch)
tree87a7460e054ebc9f3ae04cdc09fb336ad2a1495d
parentc09372fa140308194d2615ed97864a4ded54d626 (diff)
add message-passing
-rw-r--r--main.lua22
1 files changed, 18 insertions, 4 deletions
diff --git a/main.lua b/main.lua
index f5512b0..5ef09dd 100644
--- a/main.lua
+++ b/main.lua
@@ -43,9 +43,18 @@ package.loaded['baseRotationScript'] = function(db, id, dt)
transform.matrix:rotateZ(math.pi * dt)
end
package.loaded['cameraRotationScript'] = function(db, id, dt)
- local transform = db:getComponent(id, "transform")
- transform.matrix:identity():translate(Vec3{0, 0, -6 + math.sin(math.pi * glfw.GetTime())})
+ local transform = db:getComponent(id, "transform")
+ transform.matrix:identity():translate(Vec3{0, 0, -6 + math.sin(math.pi * glfw.GetTime())})
+end
+
+
+function transmitMessage(msg, data)
+ local query = db:queryComponent(msg)
+ for id, handler in pairs(query) do
+ local f = require(handler.scriptName)
+ f(db, id, data)
end
+end
local id = db:createEntity()
@@ -87,11 +96,16 @@ end)
-- resize window correctly
window:setFramebufferSizeCallback(function(_, width, height)
gl.Viewport(0, 0, width, height)
- local cameraParams = db:getComponent(camera, "camera")
- cameraParams.projection:perspectiveResize(width/height)
vw, vh = width, height
+ transmitMessage("onWindowResize", { width=width, height=height })
end)
+package.loaded["cameraHandleResize"] = function(db, id, data)
+ local camera = db:getComponent(id, "camera")
+ camera.projection:perspectiveResize(data.width/data.height)
+end
+db:addComponent(camera, "onWindowResize", { scriptName = "cameraHandleResize" })
+
-- averager (for fps)
function averager(memory)
local buf = {}