Skip to content

Commit

Permalink
Added some information logging on screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Orlando committed Dec 31, 2020
1 parent c16bc93 commit a08b859
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Assuming the runtime is installed and in PATH, you can run it with `love <dir>`,
* `f` toggles fluctuating framerate; `Ctrl+↑/↓` changes the maximum framerate, `Ctrl+←/→` changes the fluctuation speed.
* `r` toggles random stutter; `Alt+↑/↓` changes the amount of stuttering. Hold Shift as well to change faster.
* `Alt+←/→` changes the monitor the tool will be displayed on.
* `l` increases the amount of information shown on the screen, from nothing, to GPU-related information, to a list of frametimes. Wraps around.
* Number keys will select a scene to be displayed. Each scene has additional controls, shown on the right.

## Scenes
Expand Down
8 changes: 8 additions & 0 deletions colorFade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ color.update = function(dt)
love.graphics.setBackgroundColor(current.bg)
end

color.bg = function()
return current.bg
end

color.fg = function()
return current.fg
end

return color
31 changes: 31 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ local fullscreen

local vsync

local logLevel, logLevels
local deltaTimes, logLines, logWidth

local WIDTH, HEIGHT

local scenes = {}
Expand Down Expand Up @@ -61,6 +64,7 @@ vsync: %s (toggle with s)
fluctuating: %s (toggle with f, change max with ctrl + up/down arrow, change speed with ctrl + left/right arrow)
random stutter: %s [%dms] (toggle with r, change max amount with alt + up/down arrow, shift to change faster)
display: %d/%d (switch with alt + left/right arrow)
log level: %d/%d (increase with l, wraps around)
selected scene: %d (%s)
Freesync will only work when the application is fullscreen on Linux.
Expand Down Expand Up @@ -97,6 +101,12 @@ love.load = function()
frameTime = 1 / fps
lastUpdate = 0

logLevel = 0
logLevels = 3 -- 0-2
deltaTimes = {}
logLines = math.floor((HEIGHT - scenes.y) / love.graphics.getFont():getHeight())
logWidth = love.graphics.getFont():getWidth("00000 µs") + 16

fullscreen = flags.fullscreen
vsync = flags.vsync > 0
love.keyboard.setKeyRepeat(true)
Expand Down Expand Up @@ -130,6 +140,10 @@ love.update = function(dt)

scenes[scene].update(dt, fps)
color.update(dt)
if logLevel > 1 then
table.insert(deltaTimes, 1, string.format("%d µs", dt * 1000000))
deltaTimes[logLines + 1] = nil
end
end


Expand All @@ -145,13 +159,28 @@ love.draw = function()
fstr,
tostring(random), randomAmount,
display, displays,
logLevel, logLevels - 1,
scene,
scenes[scene].name)

love.graphics.print(str, 8, 8)
love.graphics.print(scenes[scene].str, WIDTH - scenes[scene].strWidth - 8, 8)
if logLevel > 0 then
love.graphics.printf(table.concat({love.graphics.getRendererInfo()}, "\n"), 0, scenes.y - love.graphics.getFont():getHeight() * 5, WIDTH - 8, "right")
end

scenes[scene].draw(scenes.x, scenes.y)

if logLevel > 1 then
--love.graphics.setColor(.75, 0, 0)
love.graphics.setColor(color.bg())
love.graphics.rectangle("fill", WIDTH - logWidth, scenes.y, logWidth + 1, HEIGHT)
love.graphics.setColor(color.fg())
for i, ms in ipairs(deltaTimes) do
love.graphics.printf(ms, 0, scenes.y + (i - 1) * love.graphics.getFont():getHeight(), WIDTH - 8, "right")
end
end

end


Expand Down Expand Up @@ -222,6 +251,8 @@ love.keypressed = function(key, keycode)
randomTime = 0
elseif key == "escape" or key == "q" then
love.event.quit()
elseif key == "l" then
logLevel = (logLevel + 1) % logLevels
end
end
if tonumber(key) and scenes[tonumber(key)] then
Expand Down

0 comments on commit a08b859

Please sign in to comment.