Class: Baku::World

Inherits:
Object
  • Object
show all
Defined in:
lib/baku/world.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorld

Returns a new instance of World.



5
6
7
8
9
10
11
12
13
14
# File 'lib/baku/world.rb', line 5

def initialize
  # TODO: there's currently no way to interleave update and draw systems.
  # Is this something we'll eventually need?
  @update_systems = []
  @draw_systems = []

  @entity_manager = EntityManager.new
  
  @blackboard = {}
end

Instance Attribute Details

#blackboardObject (readonly)

Returns the value of attribute blackboard.



3
4
5
# File 'lib/baku/world.rb', line 3

def blackboard
  @blackboard
end

#delta_msObject (readonly)

Returns the value of attribute delta_ms.



3
4
5
# File 'lib/baku/world.rb', line 3

def delta_ms
  @delta_ms
end

#entity_managerObject (readonly)

Returns the value of attribute entity_manager.



3
4
5
# File 'lib/baku/world.rb', line 3

def entity_manager
  @entity_manager
end

Instance Method Details

#add_system(system) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/baku/world.rb', line 23

def add_system(system)
  system_list = 
    if system.game_loop_step == :update
      @update_systems
    elsif system.game_loop_step == :draw
      @draw_systems
    end

  if system_list.map(&:class).include?(system.class)
    raise StandardError.new("Already added #{system.class} system to world.")
  end
  
  system_list << system

  @entity_manager.register_component_mask(system.component_mask)
  
  system.world = self
end

#create_entity(tags = []) ⇒ Object



42
43
44
45
46
# File 'lib/baku/world.rb', line 42

def create_entity(tags = [])
  entity = Entity.new(tags)
  @entity_manager.add_entity(entity)
  entity
end

#destroy_entity(entity) ⇒ Object



48
49
50
# File 'lib/baku/world.rb', line 48

def destroy_entity(entity)
  @entity_manager.remove_entity(entity)
end

#disposeObject



16
17
18
19
20
21
# File 'lib/baku/world.rb', line 16

def dispose
  @update_systems.clear
  @draw_systems.clear
  @entity_manager.dispose
  @blackboard.clear
end

#drawObject



57
58
59
# File 'lib/baku/world.rb', line 57

def draw
  @draw_systems.each(&:execute)
end

#update(delta_ms) ⇒ Object



52
53
54
55
# File 'lib/baku/world.rb', line 52

def update(delta_ms)
  @delta_ms = delta_ms
  @update_systems.each(&:execute)
end