From 2da9edb6d03dc0cd27224ec4a3aa4b79e5df8c89 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Thu, 20 Apr 2023 16:14:29 -0500 Subject: [PATCH] Refactored to use CyberarmEngine::Window#delta_time instead of our reimplementing it, add WIP frame timing to Overlay using CyberarmEngine::Stats.frames data --- Gemfile.lock | 12 ++++++------ lib/common_methods.rb | 2 +- lib/networking/director.rb | 2 +- lib/overlay.rb | 27 ++++++++++++++++++++++++++- lib/tools/map_editor/lib/editor.rb | 2 +- lib/window.rb | 4 ---- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bb9a3c1..64dac8a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/lib/common_methods.rb b/lib/common_methods.rb index a667eea..f432fdf 100644 --- a/lib/common_methods.rb +++ b/lib/common_methods.rb @@ -11,7 +11,7 @@ def window end def delta_time - (Gosu.milliseconds - window.delta_time) / 1000.0 + window.delta_time end def button_down?(id) diff --git a/lib/networking/director.rb b/lib/networking/director.rb index 58923d0..249e977 100644 --- a/lib/networking/director.rb +++ b/lib/networking/director.rb @@ -46,7 +46,7 @@ def run 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 diff --git a/lib/overlay.rb b/lib/overlay.rb index df3908c..5693250 100644 --- a/lib/overlay.rb +++ b/lib/overlay.rb @@ -21,6 +21,31 @@ def draw 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 @@ def rebuild_slots 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 diff --git a/lib/tools/map_editor/lib/editor.rb b/lib/tools/map_editor/lib/editor.rb index f9b3e3a..a99230d 100644 --- a/lib/tools/map_editor/lib/editor.rb +++ b/lib/tools/map_editor/lib/editor.rb @@ -29,7 +29,7 @@ def draw def update super - Publisher.instance.publish(:tick, Gosu.milliseconds - window.delta_time) + Publisher.instance.publish(:tick, window.delta_time) control_editor diff --git a/lib/window.rb b/lib/window.rb index 073f17a..f52ee62 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -37,8 +37,6 @@ def setup end push_state(CyberarmEngine::IntroState, forward: Boot) - - @delta_time = Gosu.milliseconds end def input_hijack=(hijacker) @@ -75,8 +73,6 @@ def update @console.update if @show_console @overlay.update SoundManager.update - - @delta_time = Gosu.milliseconds end def close