Class: Chingu::FPSCounter
- Inherits:
-
Object
- Object
- Chingu::FPSCounter
- Defined in:
- lib/chingu/fpscounter.rb
Overview
Calculates a fps and a tick-time for use in update-calls register_tick() must be called every game loop iteration
Instance Attribute Summary collapse
-
#fps ⇒ Object
readonly
Returns the value of attribute fps.
-
#milliseconds_since_last_tick ⇒ Object
readonly
Returns the value of attribute milliseconds_since_last_tick.
-
#ticks ⇒ Object
readonly
Returns the value of attribute ticks.
Instance Method Summary collapse
-
#initialize ⇒ FPSCounter
constructor
A new instance of FPSCounter.
-
#register_tick ⇒ Object
This should be called once every game-iteration, preferable in update().
Constructor Details
#initialize ⇒ FPSCounter
Returns a new instance of FPSCounter.
31 32 33 34 35 36 37 38 39 |
# File 'lib/chingu/fpscounter.rb', line 31 def initialize @current_second = Gosu::milliseconds / 1000 @accum_fps = 0 @fps = 0 @ticks = 0 @milliseconds_since_last_tick = 0 @last_value = Gosu::milliseconds end |
Instance Attribute Details
#fps ⇒ Object (readonly)
Returns the value of attribute fps.
29 30 31 |
# File 'lib/chingu/fpscounter.rb', line 29 def fps @fps end |
#milliseconds_since_last_tick ⇒ Object (readonly)
Returns the value of attribute milliseconds_since_last_tick.
29 30 31 |
# File 'lib/chingu/fpscounter.rb', line 29 def milliseconds_since_last_tick @milliseconds_since_last_tick end |
#ticks ⇒ Object (readonly)
Returns the value of attribute ticks.
29 30 31 |
# File 'lib/chingu/fpscounter.rb', line 29 def ticks @ticks end |
Instance Method Details
#register_tick ⇒ Object
This should be called once every game-iteration, preferable in update()
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chingu/fpscounter.rb', line 44 def register_tick @accum_fps += 1 @ticks += 1 current_second = Gosu::milliseconds / 1000 if current_second != @current_second @current_second = current_second @fps = @accum_fps @accum_fps = 0 end # # Calculate how many milliseconds passed since last game loop iteration. # @milliseconds_since_last_tick = Gosu::milliseconds - @last_value @last_value = Gosu::milliseconds return @milliseconds_since_last_tick end |