Class: Hemi::Event::LoopMachine

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/hemi/event/loop_machine.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.currentObject (readonly)

Returns the value of attribute current.



24
25
26
# File 'lib/hemi/event/loop_machine.rb', line 24

def current
  @current
end

.loopsObject (readonly)

Returns the value of attribute loops.



24
25
26
# File 'lib/hemi/event/loop_machine.rb', line 24

def loops
  @loops
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



8
9
10
# File 'lib/hemi/event/loop_machine.rb', line 8

def event
  @event
end

Class Method Details

.[](name) ⇒ Object



34
35
36
# File 'lib/hemi/event/loop_machine.rb', line 34

def [](name)
  @loops[name]
end

.register(name, logic, events) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/hemi/event/loop_machine.rb', line 26

def register(name, logic, events)
  event_loop   = EventLoop.new(logic, events)
  @current     = event_loop if loops.empty?
  @loops[name] = event_loop

  event_loop
end

.switch(name) ⇒ Object



38
39
40
# File 'lib/hemi/event/loop_machine.rb', line 38

def switch(name)
  @current = LoopMachine[name]
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hemi/event/loop_machine.rb', line 10

def call
  loop do
    Hemi::Render::Window.wipe_screen

    handle_events while poll_event
    process_logic

    Hemi::Render::Window.renderer.present
    debug!
    sleep 0.1
  end
end