Sha256: c038c75654dcc85440d90c9a50691d4629ccbacbc75b94c39f7ef97020e8a4ad

Contents?: true

Size: 652 Bytes

Versions: 4

Compression:

Stored size: 652 Bytes

Contents

class FpsCounter
  attr_reader :fps
  
  def initialize(samples = 10)
    @accum = 0.0
    @ticks = 0
    @fps = 0.0
    @samples = samples
    @objs = @actors = @input_controllers = 0
  end

  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

  def to_s
    "@samples(#{@samples}) @fps(#{format("%.2f",@fps)}) @objs(#{@objs}) @actors(#{@actors}) @inputs(#{@inputs})"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lotu-0.1.7 lib/lotu/misc/fps.rb
lotu-0.1.6 lib/lotu/misc/fps.rb
lotu-0.1.5 lib/lotu/misc/fps.rb
lotu-0.1.4 lib/lotu/misc/fps.rb