Class: RenderDoc::FrameTrigger

Inherits:
Object
  • Object
show all
Defined in:
lib/renderdoc/frame_trigger.rb

Constant Summary collapse

ENVIRONMENT_VARIABLE =
"STAGECRAFT_RENDERDOC"
FRAME_PATTERN =
/\Aframe:(\d+)\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame:, renderdoc: RenderDoc) ⇒ FrameTrigger

Returns a new instance of FrameTrigger.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
# File 'lib/renderdoc/frame_trigger.rb', line 22

def initialize(frame:, renderdoc: RenderDoc)
  raise ArgumentError, "frame must be a non-negative Integer" unless frame.is_a?(Integer) && frame >= 0

  @frame = frame
  @renderdoc = renderdoc
  @triggered = false
end

Instance Attribute Details

#frameObject (readonly)

Returns the value of attribute frame.



8
9
10
# File 'lib/renderdoc/frame_trigger.rb', line 8

def frame
  @frame
end

Class Method Details

.from_environment(environment: ENV, renderdoc: RenderDoc) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/renderdoc/frame_trigger.rb', line 10

def self.from_environment(environment: ENV, renderdoc: RenderDoc)
  specification = environment[ENVIRONMENT_VARIABLE]
  return unless specification

  match = FRAME_PATTERN.match(specification)
  unless match
    raise ArgumentError, "#{ENVIRONMENT_VARIABLE} must use the form frame:N"
  end

  new(frame: Integer(match[1], 10), renderdoc: renderdoc)
end

Instance Method Details

#call(current_frame) ⇒ Object Also known as: tick



30
31
32
33
34
35
36
# File 'lib/renderdoc/frame_trigger.rb', line 30

def call(current_frame)
  return false if @triggered || current_frame != frame

  @renderdoc.trigger_capture
  @triggered = true
  true
end