Module: GTK::Runtime::Framerate

Defined in:
dragon/framerate.rb

Instance Method Summary collapse

Instance Method Details

#check_framerateObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'dragon/framerate.rb', line 22

def check_framerate
  if @framerate_diagnostics_requested
    log "================================"
    log framerate_get_diagnostics
    @framerate_diagnostics_requested = false
  end

  if !@paused
    if @tick_time
      @tick_speed_count += 1
      @tick_speed_sum += Time.now.to_i - @tick_time
      if @tick_speed_count > 60 * 2
        if framerate_below_threshold?
          @last_framerate = current_framerate
          if !@console.visible?
            if !@framerate_important_notification_happened
              log_important framerate_warning_message
            else
              log framerate_warning_message
            end
            @framerate_important_notification_happened = true
          end
        end

        @previous_framerate = current_framerate.floor
      end
    end

    @tick_time = Time.new.to_i
  else
    reset_framerate_calculation
  end
rescue
  reset_framerate_calculation
end

#current_framerateObject


71
72
73
74
75
76
77
78
79
80
# File 'dragon/framerate.rb', line 71

def current_framerate
  return 60 if !@tick_speed_sum || !@tick_speed_sum
  r = 100.fdiv(@tick_speed_sum.fdiv(@tick_speed_count) * 100)
  if (r.nan? || r.infinite? || r > 58)
    r = 60
  end
  r || 60
rescue
  60
end

#delta_framerateObject


12
13
14
# File 'dragon/framerate.rb', line 12

def delta_framerate
  (current_framerate || 0) - (@previous_framerate || 0)
end

#framerate_below_threshold?Boolean

Returns:

  • (Boolean)

63
64
65
66
67
68
69
# File 'dragon/framerate.rb', line 63

def framerate_below_threshold?
  @last_framerate ||= 60
  current_framerate < @last_framerate &&
    current_framerate < 50 &&
    @previous_framerate > current_framerate &&
    Kernel.tick_count > 600
end

#framerate_diagnosticsObject


58
59
60
61
# File 'dragon/framerate.rb', line 58

def framerate_diagnostics
  # request framerate diagnostics to be printed at the end of tick
  @framerate_diagnostics_requested = true
end

#framerate_initObject


8
9
10
# File 'dragon/framerate.rb', line 8

def framerate_init
  @tick_time = Time.new.to_i
end

#reset_framerate_calculationObject


16
17
18
19
20
# File 'dragon/framerate.rb', line 16

def reset_framerate_calculation
  @tick_speed_sum = 0
  @tick_speed_count = 0
  @previous_framerate = 0
end