Class: FpsCounter
- Inherits:
-
Object
- Object
- FpsCounter
- Defined in:
- lib/lotu/fps.rb
Instance Attribute Summary collapse
-
#fps ⇒ Object
readonly
Returns the value of attribute fps.
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(samples = 10) ⇒ FpsCounter
constructor
A new instance of FpsCounter.
- #to_s ⇒ Object
- #update(dt) ⇒ Object
Constructor Details
#initialize(samples = 10) ⇒ FpsCounter
Returns a new instance of FpsCounter.
4 5 6 7 8 9 10 |
# File 'lib/lotu/fps.rb', line 4 def initialize(samples = 10) @accum = 0.0 @ticks = 0 @fps = 0.0 @samples = samples @objs = @actors = @input_controllers = 0 end |
Instance Attribute Details
#fps ⇒ Object (readonly)
Returns the value of attribute fps.
2 3 4 |
# File 'lib/lotu/fps.rb', line 2 def fps @fps end |
Instance Method Details
#draw ⇒ Object
25 26 27 |
# File 'lib/lotu/fps.rb', line 25 def draw $window.font.draw("FPS: #{to_s}", 10, 10, 0, 1.0, 1.0, 0xffffff00) end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/lotu/fps.rb', line 29 def to_s "Samples: #{@samples} FPS: #{format("%.2f",@fps)} Objs: #{@objs} Acts: #{@actors} InputsCs: #{@inputs}" end |
#update(dt) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lotu/fps.rb', line 12 def update(dt) @ticks += 1 @accum += dt if @ticks >= @samples @fps = @ticks/@accum @ticks = 0 @accum = 0.0 @objs = ObjectSpace.each_object.count @actors = ObjectSpace.each_object(Lotu::Actor).count @inputs = ObjectSpace.each_object(Lotu::InputController).count end end |