Class: Ruck::GLApp::GLAppShreduler
- Inherits:
-
Shreduler
- Object
- Shreduler
- Ruck::GLApp::GLAppShreduler
- Defined in:
- lib/ruck/glapp/glapp.rb
Instance Method Summary collapse
- #actual_now ⇒ Object
- #catch_up ⇒ Object
-
#initialize ⇒ GLAppShreduler
constructor
A new instance of GLAppShreduler.
- #raise_event(ev, queue) ⇒ Object
- #sleep_current_til(queue) ⇒ Object
- #starting ⇒ Object
Constructor Details
#initialize ⇒ GLAppShreduler
Returns a new instance of GLAppShreduler.
6 7 8 9 10 11 12 13 14 |
# File 'lib/ruck/glapp/glapp.rb', line 6 def initialize @shred_queues = {} [:frame, :key_down, :key_up, :mouse_down, :mouse_up, :mouse_move].each do |q| @shred_queues[q] = [] end super end |
Instance Method Details
#actual_now ⇒ Object
20 21 22 |
# File 'lib/ruck/glapp/glapp.rb', line 20 def actual_now Time.now - @start_time end |
#catch_up ⇒ Object
52 53 54 55 56 |
# File 'lib/ruck/glapp/glapp.rb', line 52 def catch_up while shreds.length > 0 && next_shred.now < actual_now run_one end end |
#raise_event(ev, queue) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruck/glapp/glapp.rb', line 33 def raise_event(ev, queue) # should use actual_now, # but we don't want to put it into the future new_now = actual_now new_now = [new_now, next_shred.now].min if next_shred @now = new_now @ev = ev # returned by sleep_current_til shreds = @shred_queues[queue] @shred_queues[queue] = [] shreds.each do |shred| shred.now = new_now @shreds << shred invoke_shred shred end end |
#sleep_current_til(queue) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/ruck/glapp/glapp.rb', line 24 def sleep_current_til(queue) shred = current_shred @shreds.delete(shred) @shred_queues[queue] << shred shred.yield(0) @ev end |
#starting ⇒ Object
16 17 18 |
# File 'lib/ruck/glapp/glapp.rb', line 16 def starting @start_time = Time.now end |