Class: Baku::System
- Inherits:
-
Object
- Object
- Baku::System
- Defined in:
- lib/baku/system.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#game_loop_step ⇒ Object
readonly
Returns the value of attribute game_loop_step.
-
#world ⇒ Object
writeonly
Sets the attribute world.
Instance Method Summary collapse
- #component_mask ⇒ Object
- #execute ⇒ Object
-
#initialize(components, game_loop_step) ⇒ System
constructor
A new instance of System.
- #process_entities(entities) ⇒ Object
- #process_entity(entity) ⇒ Object
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
#components ⇒ Object (readonly)
Returns the value of attribute components.
3 4 5 |
# File 'lib/baku/system.rb', line 3 def components @components end |
#game_loop_step ⇒ Object (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
4 5 6 |
# File 'lib/baku/system.rb', line 4 def world=(value) @world = value end |
Instance Method Details
#component_mask ⇒ Object
32 33 34 |
# File 'lib/baku/system.rb', line 32 def component_mask @component_mask ||= ComponentMask.from_components(@components) end |
#execute ⇒ Object
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
28 29 30 |
# File 'lib/baku/system.rb', line 28 def process_entity(entity) raise NotImplementedError end |