Class: Stagecraft::App
- Inherits:
-
Object
- Object
- Stagecraft::App
- Defined in:
- lib/stagecraft/app.rb
Instance Attribute Summary collapse
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #aspect ⇒ Object
-
#initialize(title: "Stagecraft", width: 800, height: 600, msaa: 4, window: :sdl3, renderer: nil, resizable: true) ⇒ App
constructor
A new instance of App.
- #run ⇒ Object
Constructor Details
#initialize(title: "Stagecraft", width: 800, height: 600, msaa: 4, window: :sdl3, renderer: nil, resizable: true) ⇒ App
Returns a new instance of App.
7 8 9 10 11 12 13 14 |
# File 'lib/stagecraft/app.rb', line 7 def initialize(title: "Stagecraft", width: 800, height: 600, msaa: 4, window: :sdl3, renderer: nil, resizable: true) @window = build_window(window, title:, width:, height:, resizable:) @renderer = renderer || Renderer.new(window: @window, width:, height:, msaa:) rescue StandardError @window&.close raise end |
Instance Attribute Details
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
5 6 7 |
# File 'lib/stagecraft/app.rb', line 5 def renderer @renderer end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
5 6 7 |
# File 'lib/stagecraft/app.rb', line 5 def window @window end |
Instance Method Details
#aspect ⇒ Object
16 17 18 19 |
# File 'lib/stagecraft/app.rb', line 16 def aspect width, height = window.drawable_size height.zero? ? 1.0 : width.to_f / height end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stagecraft/app.rb', line 21 def run raise ArgumentError, "App#run requires a block" unless block_given? previous = monotonic_time loop do window.poll_events break if window.should_close? now = monotonic_time dt = (now - previous).clamp(0.0, 0.1) previous = now yield(dt) break if ENV["STAGECRAFT_SMOKE"] == "1" end self ensure begin renderer.dispose ensure window.close end end |