Class: Chingu::FPSCounter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFPSCounter

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

#fpsObject (readonly)

Returns the value of attribute fps.



29
30
31
# File 'lib/chingu/fpscounter.rb', line 29

def fps
  @fps
end

#milliseconds_since_last_tickObject (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

#ticksObject (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_tickObject

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