summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-03-24 19:19:21 -0500
committersanine <sanine.not@pm.me>2023-03-24 19:19:21 -0500
commit627ca789065bfcbce53a51887be4e8f8fb20d26b (patch)
treeaf37f0075b88799a323e602ee215b0f95d02a2da
parentd31a57c0afc8769cef8af82321c07cbc14c0474b (diff)
add pausing
-rw-r--r--honey/ecs-systems.lua1
-rw-r--r--honey/ecs.lua29
-rw-r--r--main.lua51
3 files changed, 56 insertions, 25 deletions
diff --git a/honey/ecs-systems.lua b/honey/ecs-systems.lua
index 237aa78..5dec159 100644
--- a/honey/ecs-systems.lua
+++ b/honey/ecs-systems.lua
@@ -56,6 +56,7 @@ function renderCam(camera, priority)
}
entity.mesh:drawElements()
end,
+ nopause=true,
priority=priority,
}
end
diff --git a/honey/ecs.lua b/honey/ecs.lua
index d611b37..b7806f9 100644
--- a/honey/ecs.lua
+++ b/honey/ecs.lua
@@ -195,23 +195,26 @@ function Level.reconfigureAllEntities(self)
end
-function Level.update(self, dt)
+function Level.update(self, dt, paused)
+ local paused = paused or false
for _, system in ipairs(self.systems) do
- if system.preUpdate then
- system:preUpdate()
- end
- if system.prepareEntity then
+ if (not paused) or (paused and system.nopause) then
+ if system.preUpdate then
+ system:preUpdate()
+ end
+ if system.prepareEntity then
+ for id in pairs(system.entities) do
+ local entity = self.entities[id]
+ system:prepareEntity(entity)
+ end
+ end
for id in pairs(system.entities) do
local entity = self.entities[id]
- system:prepareEntity(entity)
+ system:update(entity, dt)
+ end
+ if system.postUpdate then
+ system:postUpdate()
end
- end
- for id in pairs(system.entities) do
- local entity = self.entities[id]
- system:update(entity, dt)
- end
- if system.postUpdate then
- system:postUpdate()
end
end
end
diff --git a/main.lua b/main.lua
index 9f39825..6718cf9 100644
--- a/main.lua
+++ b/main.lua
@@ -1,4 +1,27 @@
require 'honey.std'
+local paused = true
+
+local function formatize(f)
+ return function(fmt, ...)
+ f(string.format(fmt, ...))
+ end
+end
+local printf = formatize(print)
+local log = honey.log
+log.fatal = formatize(log.fatal)
+log.error = formatize(log.error)
+log.warn = formatize(log.warn)
+log.info = formatize(log.info)
+log.debug = formatize(log.debug)
+log.trace = formatize(log.trace)
+
+log.info(
+ "honey v%d.%d.%d -- %s",
+ honey.version.major,
+ honey.version.minor,
+ honey.version.patch,
+ honey.version.string
+)
local glfw = honey.glfw
local gl = honey.gl
@@ -21,7 +44,7 @@ local vw, vh = 640, 480
-- create camera matrices
local camera = {
- view=Mat4():identity():translate(Vec3{0, 0, -60}),
+ view=Mat4():identity():translate(Vec3{0, 0, -20}),
projection=Mat4():perspective(math.rad(45), 640/480, 0.1, 100),
}
@@ -129,11 +152,11 @@ local leaf = {
mesh=tetra,
shader=shader,
}
-local root = growLine(leaf, 24)
-root.update = function(self, dt)
- self.transform:rotateY(0.2 * math.pi * dt)
-end
-level:addEntity(root)
+--local root = growLine(leaf, 24)
+--root.update = function(self, dt)
+-- self.transform:rotateY(0.2 * math.pi * dt)
+--end
+--level:addEntity(root)
local groundPlane = {
transform=Mat4():identity():translate(Vec3{0, -2, 0}):scale(Vec3{10, 10, 10}),
@@ -158,15 +181,19 @@ local mass = ode.MassCreate()
ode.MassSetSphere(mass, 1, 0.5)
ode.BodySetMass(ball.physicsBody, mass)
ode.GeomSetBody(ball.collisionShape, ball.physicsBody)
-ode.BodySetPosition(ball.physicsBody, 0, 3, 0)
-ode.BodySetLinearVel(ball.physicsBody, 1, 0, 0)
+ode.BodySetPosition(ball.physicsBody, -5, 3, 0)
+ode.BodySetLinearVel(ball.physicsBody, 3, 0, 0)
ode.CreatePlane(space, 0, 1, 0, -2)
-- close window on ESCAPE key
-window:setKeyCallback(function(_, key)
- if key == glfw.KEY_ESCAPE then
- window:setShouldClose(true)
+window:setKeyCallback(function(_, key, scancode, action)
+ if action == glfw.PRESS then
+ if key == glfw.KEY_ESCAPE then
+ window:setShouldClose(true)
+ elseif key == glfw.KEY_SPACE then
+ paused = not paused
+ end
end
end)
@@ -199,7 +226,7 @@ honey.loop(window, function(dt)
gl.UseProgram(0)
gl.Enable(gl.DEPTH_TEST)
- level:update(dt)
+ level:update(dt, paused)
nvg.BeginFrame(vg, vw, vh, 1.0)
nvg.StrokeColor(vg, nvg.RGBf(1, 1, 1))
nvg.FontFace(vg, "November")