Class: Baku::System

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(components, game_loop_step) ⇒ System

Returns a new instance of System.



6
7
8
9
# File 'lib/baku/system.rb', line 6

def initialize(components, game_loop_step)
  @components = components
  @game_loop_step = game_loop_step
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



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

def components
  @components
end

#game_loop_stepObject (readonly)

Returns the value of attribute game_loop_step.



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

def game_loop_step
  @game_loop_step
end

#world=(value) ⇒ Object (writeonly)

Sets the attribute world

Parameters:

  • value

    the value to set the attribute world to.



4
5
6
# File 'lib/baku/system.rb', line 4

def world=(value)
  @world = value
end

Instance Method Details

#component_maskObject



32
33
34
# File 'lib/baku/system.rb', line 32

def component_mask
  @component_mask ||= ComponentMask.from_components(@components)
end

#executeObject



11
12
13
14
15
16
17
18
19
# File 'lib/baku/system.rb', line 11

def execute
  if @world.nil?
    raise StandardError.new("Must set :world property of System.")
  end
  
  entities = @world.entity_manager.get_entities(component_mask)

  process_entities(entities)
end

#process_entities(entities) ⇒ Object



21
22
23
24
25
26
# File 'lib/baku/system.rb', line 21

def process_entities(entities)
  entities.each do |entity|
    entity_components = @components.map { |c| entity.get_component(c) }
    process_entity(entity, *entity_components)
  end
end

#process_entity(entity) ⇒ Object

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/baku/system.rb', line 28

def process_entity(entity)
  raise NotImplementedError
end