Skip to content

Commit

Permalink
Refactored to use CyberarmEngine::Window#delta_time instead of our re…
Browse files Browse the repository at this point in the history
…implementing it, add WIP frame timing to Overlay using CyberarmEngine::Stats.frames data
  • Loading branch information
cyberarm committed Apr 20, 2023
1 parent 8f2d7ff commit 2da9edb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -54,4 +54,4 @@ DEPENDENCIES
rubyzip

BUNDLED WITH
2.4.1
2.4.8
2 changes: 1 addition & 1 deletion lib/common_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/networking/director.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion lib/overlay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/tools/map_editor/lib/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions lib/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def setup
end

push_state(CyberarmEngine::IntroState, forward: Boot)

@delta_time = Gosu.milliseconds
end

def input_hijack=(hijacker)
Expand Down Expand Up @@ -75,8 +73,6 @@ def update
@console.update if @show_console
@overlay.update
SoundManager.update

@delta_time = Gosu.milliseconds
end

def close
Expand Down

0 comments on commit 2da9edb

Please sign in to comment.