Class: Ruck::GLApp::GLAppShreduler

Inherits:
Shreduler
  • Object
show all
Defined in:
lib/ruck/glapp/glapp.rb

Instance Method Summary collapse

Constructor Details

#initializeGLAppShreduler

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_nowObject



20
21
22
# File 'lib/ruck/glapp/glapp.rb', line 20

def actual_now
  Time.now - @start_time
end

#catch_upObject



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

#startingObject



16
17
18
# File 'lib/ruck/glapp/glapp.rb', line 16

def starting
  @start_time = Time.now
end