diff --git a/lib/waterfoul/screen.rb b/lib/waterfoul/screen.rb index 0dbd934..77762c5 100644 --- a/lib/waterfoul/screen.rb +++ b/lib/waterfoul/screen.rb @@ -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 diff --git a/lib/waterfoul/sdl.rb b/lib/waterfoul/sdl.rb index a07239e..e638152 100644 --- a/lib/waterfoul/sdl.rb +++ b/lib/waterfoul/sdl.rb @@ -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