Add FPS in window title

This commit is contained in:
Benoit Daloze 2017-03-05 15:06:47 +01:00
parent 2e58037c48
commit 85d2afe7da
2 changed files with 9 additions and 0 deletions

View file

@ -14,6 +14,7 @@ module Waterfoul
SDL.SetHint "SDL_HINT_RENDER_SCALE_QUALITY", "2"
SDL.RenderSetLogicalSize(@renderer, WINDOW_WIDTH, WINDOW_HEIGHT)
@texture = SDL.CreateTexture @renderer, SDL::PIXELFORMAT_ARGB8888, 1, SCREEN_WIDTH, SCREEN_HEIGHT
@last = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
def render(framebuffer)
@ -22,6 +23,13 @@ module Waterfoul
SDL.RenderClear @renderer
SDL.RenderCopy @renderer, @texture, nil, nil
SDL.RenderPresent @renderer
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
fps = 1.0 / (t - @last)
fps = fps.floor.to_s
@last = t
SDL.SetWindowTitle(@window, "waterfoul (#{fps} fps)")
end
end
end

View file

@ -36,5 +36,6 @@ module Waterfoul
attach_function :GetKeyboardState, 'SDL_GetKeyboardState', [:pointer], :pointer
attach_function :SetHint, 'SDL_SetHint', [:string, :string], :int
attach_function :RenderSetLogicalSize, 'SDL_RenderSetLogicalSize', [:pointer, :int, :int], :int
attach_function :SetWindowTitle, 'SDL_SetWindowTitle', [:pointer, :string], :void
end
end