Refactored to use CyberarmEngine::Window#delta_time instead of our reimplementing it, add WIP frame timing to Overlay using CyberarmEngine::Stats.frames data

This commit is contained in:
2023-04-20 16:14:29 -05:00
parent 8f2d7ff905
commit 2da9edb6d0
6 changed files with 35 additions and 14 deletions

View File

@@ -1,8 +1,8 @@
GIT
remote: https://github.com/cyberarm/cyberarm_engine
revision: d1d87db070578fefe97f275b63157b4212a44a89
revision: 72037efc735089cf1ff4b56ec57eb793699b27c6
specs:
cyberarm_engine (0.22.0)
cyberarm_engine (0.23.0)
excon (~> 0.88)
gosu (~> 1.1)
gosu_more_drawables (~> 0.3)
@@ -20,15 +20,15 @@ GIT
GEM
remote: https://rubygems.org/
specs:
concurrent-ruby (1.1.10)
concurrent-ruby (1.2.2)
cri (2.1.0)
excon (0.96.0)
excon (0.99.0)
gosu (1.4.5)
gosu_more_drawables (0.3.1)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
mini_portile2 (2.8.1)
nokogiri (1.14.0.rc1)
nokogiri (1.14.2)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
ocra (1.3.11)
@@ -54,4 +54,4 @@ DEPENDENCIES
rubyzip
BUNDLED WITH
2.4.1
2.4.8

View File

@@ -11,7 +11,7 @@ class IMICFPS
end
def delta_time
(Gosu.milliseconds - window.delta_time) / 1000.0
window.delta_time
end
def button_down?(id)

View File

@@ -46,7 +46,7 @@ class IMICFPS
def tick(delta_time)
return unless @map
Publisher.instance.publish(:tick, delta_time * 1000.0)
Publisher.instance.publish(:tick, delta_time)
@map.update
@server&.update

View File

@@ -21,6 +21,31 @@ class IMICFPS
Gosu.draw_rect(2, 2, width - 4, (@text.height + 4) - 4, Gosu::Color.rgba(100, 100, 100, 100))
@text.draw
sample_points = 256
frame_stats = CyberarmEngine::Stats.frames.select(&:complete?)
return if frame_stats.empty?
right_origin = CyberarmEngine::Vector.new(10, 128)
nodes = Array.new(sample_points) { [] }
slice = 0
frame_stats.each_slice((CyberarmEngine::Stats.max_frame_history / sample_points.to_f).ceil) do |bucket|
bucket.each do |frame|
nodes[slice] << frame.frame_timing.duration
end
slice += 1
end
points = []
nodes.each_with_index do |cluster, i|
break if cluster.empty?
points << CyberarmEngine::Vector.new(right_origin.x + 1 * i, right_origin.y - cluster.max)
end
Gosu.draw_path(points, Gosu::Color::WHITE, Float::INFINITY) if points.size > 1
end
def update
@@ -33,7 +58,7 @@ class IMICFPS
if window.config.get(:options, :fps)
create_slot "FPS: #{Gosu.fps}"
if window.config.get(:debug_options, :stats)
create_slot "Frame time: #{(Gosu.milliseconds - window.delta_time).to_s.rjust(3, '0')}ms"
create_slot "Frame time: #{(window.delta_time * 1000).round.to_s}ms"
end
end

View File

@@ -29,7 +29,7 @@ class IMICFPS
def update
super
Publisher.instance.publish(:tick, Gosu.milliseconds - window.delta_time)
Publisher.instance.publish(:tick, window.delta_time)
control_editor

View File

@@ -37,8 +37,6 @@ class IMICFPS
end
push_state(CyberarmEngine::IntroState, forward: Boot)
@delta_time = Gosu.milliseconds
end
def input_hijack=(hijacker)
@@ -75,8 +73,6 @@ class IMICFPS
@console.update if @show_console
@overlay.update
SoundManager.update
@delta_time = Gosu.milliseconds
end
def close