Compare commits
No commits in common. "e77c75aaf82c29bb900897abb1df636779b99fe6" and "eb7ce44fa1084c130ea6039a0b46f04c42652b07" have entirely different histories.
e77c75aaf8
...
eb7ce44fa1
2 changed files with 2 additions and 71 deletions
67
main.lua
67
main.lua
|
|
@ -53,7 +53,7 @@ function love.load()
|
||||||
up = {'key:up', 'key:w'},
|
up = {'key:up', 'key:w'},
|
||||||
down = {'key:down', 'key:s'},
|
down = {'key:down', 'key:s'},
|
||||||
action = {'key:z', 'key:space'},
|
action = {'key:z', 'key:space'},
|
||||||
f1 = {'key:f1'}, f2 = {'key:f2'}, f3 = {'key:f3'}, f12 = {'key:f12'}
|
f1 = {'key:f1'}, f2 = {'key:f2'}, f3 = {'key:f3'}
|
||||||
},
|
},
|
||||||
pairs = {
|
pairs = {
|
||||||
move = {'left', 'right', 'up', 'down'}
|
move = {'left', 'right', 'up', 'down'}
|
||||||
|
|
@ -69,16 +69,7 @@ function love.update(dt)
|
||||||
input:update(dt)
|
input:update(dt)
|
||||||
if input:pressed('f1') then gotoRoom('CircleRoom') end
|
if input:pressed('f1') then gotoRoom('CircleRoom') end
|
||||||
if input:pressed('f3') then camera:shake(4, 60, 1) end
|
if input:pressed('f3') then camera:shake(4, 60, 1) end
|
||||||
if input:pressed('f12') then
|
|
||||||
print("-------------------------------------")
|
|
||||||
print("Before collection: " .. collectgarbage("count")/1024)
|
|
||||||
collectgarbage()
|
|
||||||
print("After collection: " .. collectgarbage("count")/1024)
|
|
||||||
print("Object count: ")
|
|
||||||
local counts = type_count()
|
|
||||||
for k, v in pairs(counts) do print(k, v) end
|
|
||||||
print("-------------------------------------")
|
|
||||||
end
|
|
||||||
camera:update(dt)
|
camera:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -130,7 +121,6 @@ function gotoRoom(room_type, ...)
|
||||||
if type(Class) ~= "table" and type(Class) ~= "function" then
|
if type(Class) ~= "table" and type(Class) ~= "function" then
|
||||||
error("room '"..room_type.."' is not callable (got "..type(Class)..", does room return itself?)")
|
error("room '"..room_type.."' is not callable (got "..type(Class)..", does room return itself?)")
|
||||||
end
|
end
|
||||||
if current_room and current_room.destroy then current_room:destroy() end
|
|
||||||
current_room = _G[room_type](...)
|
current_room = _G[room_type](...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -160,56 +150,3 @@ function random(min, max)
|
||||||
local min, max = min or 0, max or 1
|
local min, max = min or 0, max or 1
|
||||||
return (min > max and (love.math.random()*(min - max) + max)) or (love.math.random()*(max - min) + min)
|
return (min > max and (love.math.random()*(min - max) + max)) or (love.math.random()*(max - min) + min)
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------
|
|
||||||
-- garbage collection --
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
---Counts all globals and applies function
|
|
||||||
---@param f function
|
|
||||||
function count_all(f)
|
|
||||||
local seen = {}
|
|
||||||
local count_table
|
|
||||||
count_table = function(t)
|
|
||||||
if seen[t] then return end
|
|
||||||
f(t)
|
|
||||||
seen[t] = true
|
|
||||||
for k,v in pairs(t) do
|
|
||||||
if type(v) == "table" then
|
|
||||||
count_table(v)
|
|
||||||
elseif type(v) == "userdata" then
|
|
||||||
f(v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
count_table(_G)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Count all types of globals
|
|
||||||
---@return table
|
|
||||||
function type_count()
|
|
||||||
local counts = {}
|
|
||||||
local enumerate = function (o)
|
|
||||||
local t = type_name(o)
|
|
||||||
counts[t] = (counts[t] or 0) + 1
|
|
||||||
end
|
|
||||||
count_all(enumerate)
|
|
||||||
return counts
|
|
||||||
end
|
|
||||||
|
|
||||||
global_type_table = nil
|
|
||||||
---Resolves an object's true class name via metatable lookup.
|
|
||||||
---Caches results in `global_type_table` for speed.
|
|
||||||
---Fallbacks: "table" (no metatable), "Unknown" (uncached).
|
|
||||||
---@param o any Any object (table, userdata, etc.)
|
|
||||||
---@return string Class name (e.g., "Player", "Camera", "ImageData")
|
|
||||||
function type_name(o)
|
|
||||||
if global_type_table == nil then
|
|
||||||
global_type_table = {}
|
|
||||||
for k,v in pairs(_G) do
|
|
||||||
global_type_table[v] = k
|
|
||||||
end
|
|
||||||
global_type_table[0] = "table"
|
|
||||||
end
|
|
||||||
return global_type_table[getmetatable(o) or 0] or "Unknown"
|
|
||||||
end
|
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,4 @@ function Room:canvasDraw()
|
||||||
self.area:draw()
|
self.area:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
---Destroys room
|
|
||||||
function Room:destroy()
|
|
||||||
self.area:destroy()
|
|
||||||
self.area = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
return Room
|
return Room
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue