Some slightly noisier tiny debugging.
Fully optional and/or only on rarely-called functions
This commit is contained in:
parent
cedf7cb945
commit
a278e30c74
|
@ -0,0 +1,6 @@
|
|||
getCurrentTimeMilliseconds = playdate.getCurrentTimeMilliseconds
|
||||
|
||||
tinyTrackEntityAges = true
|
||||
ENTITY_INIT_MS = { "ENTITY_INIT_MS" }
|
||||
|
||||
tinyLogSystemUpdateTime = false
|
31
lib/tiny.lua
31
lib/tiny.lua
|
@ -484,9 +484,20 @@ function tiny.addEntity(world, entity)
|
|||
end
|
||||
tiny_addEntity = tiny.addEntity
|
||||
|
||||
if tinyTrackEntityAges then
|
||||
local wrapped = tiny.addEntity
|
||||
function tiny.addEntity(world, entity)
|
||||
local added = wrapped(world, entity)
|
||||
added[ENTITY_INIT_MS] = getCurrentTimeMilliseconds()
|
||||
end
|
||||
tiny_addEntity = tiny.addEntity
|
||||
end
|
||||
|
||||
--- Adds a System to the world. Returns the System.
|
||||
function tiny.addSystem(world, system)
|
||||
assert(system.world == nil, "System already belongs to a World.")
|
||||
if system.world ~= nil then
|
||||
error("System " .. system.name .. " already belongs to a World.")
|
||||
end
|
||||
local s2a = world.systemsToAdd
|
||||
s2a[#s2a + 1] = system
|
||||
system.world = world
|
||||
|
@ -521,7 +532,9 @@ tiny_removeEntity = tiny.removeEntity
|
|||
|
||||
--- Removes a System from the world. Returns the System.
|
||||
function tiny.removeSystem(world, system)
|
||||
assert(system.world == world, "System does not belong to this World.")
|
||||
if system.world ~= world then
|
||||
error("System " .. system.name .. " does not belong to this World.")
|
||||
end
|
||||
local s2r = world.systemsToRemove
|
||||
s2r[#s2r + 1] = system
|
||||
return system
|
||||
|
@ -778,15 +791,15 @@ function tiny.update(world, dt, filter)
|
|||
end
|
||||
end
|
||||
|
||||
local tinyLogSystemUpdateTime = tinyLogSystemUpdateTime
|
||||
-- Iterate through Systems IN ORDER
|
||||
for i = 1, #systems do
|
||||
local system = systems[i]
|
||||
if system.active and ((not filter) or filter(world, system)) then
|
||||
-- TODO: Track how long each system runs for during any given frame.
|
||||
-- Update Systems that have an update method (most Systems)
|
||||
local update = system.update
|
||||
if update then
|
||||
--local currentMs = playdate.getCurrentTimeMilliseconds()
|
||||
local currentMs = tinyLogSystemUpdateTime and getCurrentTimeMilliseconds()
|
||||
local interval = system.interval
|
||||
if interval then
|
||||
local bufferedTime = (system.bufferedTime or 0) + dt
|
||||
|
@ -798,14 +811,18 @@ function tiny.update(world, dt, filter)
|
|||
else
|
||||
update(system, dt)
|
||||
end
|
||||
--local endTimeMs = playdate.getCurrentTimeMilliseconds()
|
||||
--print(tostring(endTimeMs - currentMs) .. "ms taken to update " .. system.name)
|
||||
if tinyLogSystemUpdateTime then
|
||||
local endTimeMs = getCurrentTimeMilliseconds()
|
||||
print(tostring(endTimeMs - currentMs) .. "ms taken to update system '" .. system.name .. "'")
|
||||
end
|
||||
end
|
||||
|
||||
system.modified = false
|
||||
end
|
||||
end
|
||||
--print("")
|
||||
if tinyLogSystemUpdateTime then
|
||||
print("")
|
||||
end
|
||||
|
||||
-- Iterate through Systems IN ORDER AGAIN
|
||||
for i = 1, #systems do
|
||||
|
|
|
@ -7,6 +7,7 @@ import("CoreLibs/timer.lua")
|
|||
import("CoreLibs/ui.lua")
|
||||
import("CoreLibs/utilities/where.lua")
|
||||
|
||||
import("../lib/tiny-debug.lua")
|
||||
import("../lib/tiny.lua")
|
||||
|
||||
local tiny <const> = tiny
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
local gfx <const> = playdate.graphics
|
||||
|
||||
local focusPriority = {}
|
||||
|
||||
Camera = {
|
||||
pan = {
|
||||
x = 0,
|
||||
|
@ -11,6 +9,8 @@ Camera = {
|
|||
|
||||
expireBelowScreenSystem = filteredSystem("expireBelowScreen", { position = T.XyPair, expireBelowScreenBy = T.number })
|
||||
|
||||
local focusPriority = {}
|
||||
|
||||
cameraPanSystem = filteredSystem("cameraPan", { focusPriority = T.number, position = T.XyPair }, function(e, dt)
|
||||
if e.focusPriority >= focusPriority.priority then
|
||||
focusPriority.position = e.position
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
---@param process fun(entity: T, dt: number, system: System)
|
||||
---@return System | { entities: T[] }
|
||||
function filteredSystem(name, shape, process)
|
||||
assert(type(name) == "string")
|
||||
assert(type(shape) == "table")
|
||||
assert(process == nil or type(process) == "function")
|
||||
|
||||
local system = tiny.processingSystem()
|
||||
system.name = name
|
||||
local keys = {}
|
||||
|
|
Loading…
Reference in New Issue