Class: Stagecraft::Renderer::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/stagecraft/renderer/stats.rb

Constant Summary collapse

COUNTERS =
%i[draw_calls triangles buffers textures pipelines visible_objects culled_objects].freeze

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



10
11
12
# File 'lib/stagecraft/renderer/stats.rb', line 10

def initialize
  COUNTERS.each { |counter| instance_variable_set(:"@#{counter}", 0) }
end

Instance Method Details

#decrement(counter, amount = 1) ⇒ Object



28
29
30
# File 'lib/stagecraft/renderer/stats.rb', line 28

def decrement(counter, amount = 1)
  increment(counter, -amount)
end

#increment(counter, amount = 1) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
# File 'lib/stagecraft/renderer/stats.rb', line 22

def increment(counter, amount = 1)
  raise ArgumentError, "unknown stats counter #{counter.inspect}" unless COUNTERS.include?(counter)

  instance_variable_set(:"@#{counter}", public_send(counter) + amount)
end

#reset_frame!Object



14
15
16
17
18
19
20
# File 'lib/stagecraft/renderer/stats.rb', line 14

def reset_frame!
  @draw_calls = 0
  @triangles = 0
  @visible_objects = 0
  @culled_objects = 0
  self
end

#to_hObject



32
33
34
# File 'lib/stagecraft/renderer/stats.rb', line 32

def to_h
  COUNTERS.to_h { |counter| [counter, public_send(counter)] }
end

#to_sObject



36
37
38
# File 'lib/stagecraft/renderer/stats.rb', line 36

def to_s
  to_h.map { |name, value| "#{name}=#{value}" }.join(" ")
end