mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-11-04 16:33:52 +00:00
Compare commits
2 Commits
2cc1382696
...
685c94bd1b
| Author | SHA1 | Date | |
|---|---|---|---|
| 685c94bd1b | |||
| d6d3c07bbc |
@@ -33,6 +33,9 @@ module CyberarmEngine
|
|||||||
@timers.delete_if(&:dead?)
|
@timers.delete_if(&:dead?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fixed_update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
def needs_redraw?
|
def needs_redraw?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def value=(bool)
|
def value=(bool)
|
||||||
old_value = this.value
|
old_value = self.value
|
||||||
|
|
||||||
@toggle_button.value = bool
|
@toggle_button.value = bool
|
||||||
publish(:changed, bool) if bool != old_value
|
publish(:changed, bool) if bool != old_value
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def value=(n)
|
def value=(n)
|
||||||
old_value = this.value
|
old_value = self.value
|
||||||
|
|
||||||
@value = n
|
@value = n
|
||||||
position_handle
|
position_handle
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ module CyberarmEngine
|
|||||||
SAMPLES = {}
|
SAMPLES = {}
|
||||||
SONGS = {}
|
SONGS = {}
|
||||||
|
|
||||||
|
FixedUpdateProperties = Data.define(:fixed_timestep, :fixed_timestep_int_ms, :max_timestep)
|
||||||
|
FixedUpdate = Struct.new(:milliseconds, :accumulator, :interpolation, :alpha)
|
||||||
|
|
||||||
attr_accessor :show_cursor, :show_stats_plotter
|
attr_accessor :show_cursor, :show_stats_plotter
|
||||||
attr_writer :exit_on_opengl_error
|
attr_writer :exit_on_opengl_error
|
||||||
attr_reader :last_frame_time, :delta_time, :states
|
attr_reader :last_frame_time, :delta_time, :states
|
||||||
@@ -28,7 +31,7 @@ module CyberarmEngine
|
|||||||
@@instance
|
@@instance
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
|
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false, fixed_update_timestep: 1.0 / 125, fixed_update_timestep_int_ms: 8, fixed_max_timestep: 1.0 / 60)
|
||||||
@show_cursor = false
|
@show_cursor = false
|
||||||
@has_focus = false
|
@has_focus = false
|
||||||
@show_stats_plotter = false
|
@show_stats_plotter = false
|
||||||
@@ -46,6 +49,9 @@ module CyberarmEngine
|
|||||||
preload_default_shaders if respond_to?(:preload_default_shaders)
|
preload_default_shaders if respond_to?(:preload_default_shaders)
|
||||||
@stats_plotter = Stats::StatsPlotter.new(2, 28) # FIXME: Make positioning easy
|
@stats_plotter = Stats::StatsPlotter.new(2, 28) # FIXME: Make positioning easy
|
||||||
|
|
||||||
|
@fixed_timestep_data = FixedUpdateProperties.new(1.0 / 125, 8, 1.0 / 60)
|
||||||
|
@fixed_update = FixedUpdate.new(0, 0.0, 0.0, 1.0)
|
||||||
|
|
||||||
setup
|
setup
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -79,11 +85,44 @@ module CyberarmEngine
|
|||||||
|
|
||||||
Stats.frame.start_timing(:update)
|
Stats.frame.start_timing(:update)
|
||||||
current_state&.update
|
current_state&.update
|
||||||
|
Stats.frame.start_timing(:fixed_update)
|
||||||
|
fixed_update
|
||||||
|
Stats.frame.end_timing(:fixed_update)
|
||||||
Stats.frame.end_timing(:update)
|
Stats.frame.end_timing(:update)
|
||||||
|
|
||||||
Stats.frame.start_timing(:interframe_sleep) unless needs_redraw?
|
Stats.frame.start_timing(:interframe_sleep) unless needs_redraw?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fixed_update
|
||||||
|
@delta_time = @fixed_timestep_data.max_timestep if @delta_time > @fixed_timestep_data.max_timestep
|
||||||
|
@fixed_update.accumulator += @delta_time
|
||||||
|
|
||||||
|
while @fixed_update.accumulator >= @fixed_timestep_data.fixed_timestep
|
||||||
|
@fixed_update.accumulator -= @fixed_timestep_data.fixed_timestep
|
||||||
|
|
||||||
|
@fixed_update.alpha = @fixed_update.accumulator / @fixed_timestep_data.fixed_timestep
|
||||||
|
|
||||||
|
@fixed_update.milliseconds += @fixed_timestep_data.fixed_timestep_int_ms
|
||||||
|
current_state&.fixed_update(@fixed_timestep_data.fixed_timestep)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fixed_update_milliseconds
|
||||||
|
@fixed_update.milliseconds
|
||||||
|
end
|
||||||
|
|
||||||
|
def fixed_update_accumulator
|
||||||
|
@fixed_update.accumulator
|
||||||
|
end
|
||||||
|
|
||||||
|
def fixed_update_interpolation
|
||||||
|
@fixed_update.interpolation
|
||||||
|
end
|
||||||
|
|
||||||
|
def fixed_update_alpha
|
||||||
|
@fixed_update.alpha
|
||||||
|
end
|
||||||
|
|
||||||
def needs_cursor?
|
def needs_cursor?
|
||||||
@show_cursor
|
@show_cursor
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user