From b4311064f690d57380b63a522bf78ffc734e45f7 Mon Sep 17 00:00:00 2001 From: bizcochito Date: Mon, 31 Jan 2022 15:03:14 +0100 Subject: [PATCH] Added memmory usage to debug menu and logging --- data/scripts/debug.lua | 94 ++++++++++++++++++++++++++++++------------ main.lua | 17 ++++++++ 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/data/scripts/debug.lua b/data/scripts/debug.lua index 60a30e0..da05bc3 100644 --- a/data/scripts/debug.lua +++ b/data/scripts/debug.lua @@ -1,36 +1,35 @@ function DebugUI() + local mouse_x, mouse_y = love.mouse.getPosition() + for _, light in pairs(Lights) do + love.graphics.print(light.pos.x,light.pos.x,light.pos.y) + love.graphics.print(light.pos.y,light.pos.x,light.pos.y+20) + love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40) + end -local mouse_x, mouse_y = love.mouse.getPosition() + love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale) + love.graphics.print(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memoryUsage: "..memoryUsage.."kB", 10*textScale, 20*textScale, 0, textScale) -for _, light in pairs(Lights) do - love.graphics.print(light.pos.x,light.pos.x,light.pos.y) - love.graphics.print(light.pos.y,light.pos.x,light.pos.y+20) - love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40) -end + love.graphics.setColor(1,1,1) + -- lots of variables + love.graphics.print("[main_Player]",10*textScale,40*textScale, 0, textScale) + love.graphics.print("position: {"..main_Player.pos.x..", "..main_Player.pos.y.."}",10*textScale,60*textScale, 0, textScale) + love.graphics.print("velocity: {"..main_Player.vel.x..", "..main_Player.vel.y.."}",10*textScale,80*textScale, 0, textScale) + love.graphics.print("scale: {"..main_Player.sprite_scale.x..", "..main_Player.sprite_scale.y.."}",10*textScale,100*textScale, 0, textScale) + love.graphics.print("states: \"isOnGround\": "..tostring(main_Player.isOnGround),10*textScale,120*textScale, 0, textScale) + love.graphics.print("\"coyoteValue\": "..tostring(main_Player.coyoteValue),10*textScale,140*textScale, 0, textScale) - love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale) + love.graphics.print("[Camera]",10*textScale,160*textScale, 0, textScale) + love.graphics.print("position: {"..Camera.pos.x..", "..Camera.pos.y.."}",10*textScale,180*textScale, 0, textScale) + love.graphics.print("size: {"..Camera.width..", "..Camera.height.."}",10*textScale,200*textScale, 0, textScale) - love.graphics.setColor(1,1,1) - -- lots of variables - love.graphics.print("[main_Player]",10*textScale,40*textScale, 0, textScale) - love.graphics.print("position: {"..main_Player.pos.x..", "..main_Player.pos.y.."}",10*textScale,60*textScale, 0, textScale) - love.graphics.print("velocity: {"..main_Player.vel.x..", "..main_Player.vel.y.."}",10*textScale,80*textScale, 0, textScale) - love.graphics.print("scale: {"..main_Player.sprite_scale.x..", "..main_Player.sprite_scale.y.."}",10*textScale,100*textScale, 0, textScale) - love.graphics.print("states: \"isOnGround\": "..tostring(main_Player.isOnGround),10*textScale,120*textScale, 0, textScale) - love.graphics.print("\"coyoteValue\": "..tostring(main_Player.coyoteValue),10*textScale,140*textScale, 0, textScale) + love.graphics.print("[Cursor]",10*textScale,220*textScale, 0, textScale) + love.graphics.print("position: {"..mouse_x+Camera.pos.x..", "..mouse_y+Camera.pos.y.."}",10*textScale,240*textScale, 0, textScale) - love.graphics.print("[Camera]",10*textScale,160*textScale, 0, textScale) - love.graphics.print("position: {"..Camera.pos.x..", "..Camera.pos.y.."}",10*textScale,180*textScale, 0, textScale) - love.graphics.print("size: {"..Camera.width..", "..Camera.height.."}",10*textScale,200*textScale, 0, textScale) + love.graphics.print(textScale,10*textScale,240*textScale, 0, textScale) + love.graphics.print("Level: "..levelNum.." / "..#levelList.." \""..currLevel.."\"",10*textScale,260*textScale, 0, textScale) - love.graphics.print("[Cursor]",10*textScale,220*textScale, 0, textScale) - love.graphics.print("position: {"..mouse_x+Camera.pos.x..", "..mouse_y+Camera.pos.y.."}",10*textScale,240*textScale, 0, textScale) - - love.graphics.print(textScale,10*textScale,240*textScale, 0, textScale) - love.graphics.print("Level: "..levelNum.." / "..#levelList.." \""..currLevel.."\"",10*textScale,260*textScale, 0, textScale) - - -- player isOnGroundCheck - love.graphics.setColor(1,0,0) + -- player isOnGroundCheck + love.graphics.setColor(1,0,0) end function DebugColisions() @@ -45,3 +44,46 @@ function DebugEntities() enty:Debug() end end + +--[[CPUUsage = {} +function checkCPUTime(action, name) + if name then + if action == "start" then + if CPUUsage.name == nil then CPUUsage.name = {} end + CPUUsage.name.start = os.clock() + elseif action == "fin" then + CPUUsage.name.fin = os.clock() + CPUUsage.name.use = CPUUsage.name.fin - CPUUsage.name.start + if CPUUsage.name.total == nil then CPUUsage.name.total = 0 end + CPUUsage.name.total = CPUUsage.name.total + CPUUsage.name.use + print(CPUUsage.name.fin.." : "..CPUUsage.name.use.." : "..CPUUsage.name.total) + elseif action == "get" then + return CPUUsage.name.use + elseif action == "total" then + return CPUUsage.name.total + else + return CPUUsage.name.use + end + -- Totals + else + if action == "get" then + local currentTotalCPU = 0 + for _, timings in ipairs(CPUUsage) do + currentTotalCPU = currentTotalCPU + CPUUsage.timings.use + end + return currentTotalCPU + elseif action == "total" then + local currentTotalCPU = 0 + for _, timings in ipairs(CPUUsage) do + currentTotalCPU = currentTotalCPU + CPUUsage.timings.total + end + return currentTotalCPU + else + local currentTotalCPU = 0 + for _, timings in ipairs(CPUUsage) do + currentTotalCPU = currentTotalCPU + CPUUsage.timings.use + end + return currentTotalCPU + end + end +end]] diff --git a/main.lua b/main.lua index 844f3b0..6be1228 100644 --- a/main.lua +++ b/main.lua @@ -1,4 +1,6 @@ function love.load() + --logging = true + if logging then print("love: "..collectgarbage("count").." kB") end arrow = 0 do_pause = false @@ -54,6 +56,9 @@ function love.load() --CursedBook:New(180,68) gravity = 0.2 + -- Debug and log stuff + memoryUsage, dtcount = 0, 0 + if logging then print("mothback: "..collectgarbage("count").." kB, Loading time: "..os.clock().." seconds") end end function love.update(dt) @@ -68,6 +73,18 @@ function love.update(dt) fps_count = fps_count + 1 current_dt = dt + -- things per second + dtcount = dtcount + dt + if dtcount >= 1 then + if secs == nil then secs = 0 end + secs = secs + 1 + dtcount = dtcount - 1 + if debug or logging then + memoryUsage = math.floor(collectgarbage("count")) + end + if logging then print("Second "..secs..": "..memoryUsage.." kB") end + end + --keypressed if Keybind:HasPressed(Keybind.menu.pause) then if do_pause then