Class: Lotu::FpsSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/lotu/systems/fps_system.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, opts = {}) ⇒ FpsSystem

Returns a new instance of FpsSystem.



4
5
6
7
8
9
10
11
12
13
# File 'lib/lotu/systems/fps_system.rb', line 4

def initialize(user, opts={})
  default_opts = {
    :ticks_per_update => 10
  }
  opts = default_opts.merge!(opts)
  @accum = 0.0
  @ticks = 0
  @fps = 0.0
  @ticks_per_update = opts[:ticks_per_update]
end

Instance Method Details

#drawObject



29
# File 'lib/lotu/systems/fps_system.rb', line 29

def draw;end

#to_sObject



25
26
27
# File 'lib/lotu/systems/fps_system.rb', line 25

def to_s
  "Ticks per update: #{@ticks_per_update} | FPS: #{format("%.2f",@fps)}"
end

#updateObject



15
16
17
18
19
20
21
22
23
# File 'lib/lotu/systems/fps_system.rb', line 15

def update
  @ticks += 1
  @accum += $lotu.dt
  if @ticks >= @ticks_per_update
    @fps = @ticks/@accum
    @ticks = 0
    @accum = 0.0
  end
end