Class: Kiwi::Internal::Archetype
- Inherits:
-
Object
- Object
- Kiwi::Internal::Archetype
- Defined in:
- lib/archetype.rb
Instance Method Summary collapse
- #active_components(componentIds) ⇒ [Component, EntityId]
- #components_and_ids(componentIds) ⇒ Object
- #get_component(archRowId, componentId) ⇒ Object
- #has_component(componentId) ⇒ Object
-
#initialize(componentIds) ⇒ Archetype
constructor
A new instance of Archetype.
- #new_arch_row_id(entityId) ⇒ int
- #remove_entity(archRowId) ⇒ Object
- #set_component(archRowId, component) ⇒ Object
Constructor Details
#initialize(componentIds) ⇒ Archetype
Returns a new instance of Archetype.
7 8 9 10 11 12 13 14 |
# File 'lib/archetype.rb', line 7 def initialize(componentIds) # [Integer(componentId): ComponentColumn] @components = componentIds.map do |compId| [compId, ComponentColumn.new([])] end.to_h @availableEntityRows = [] @entities = [] end |
Instance Method Details
#active_components(componentIds) ⇒ [Component, EntityId]
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/archetype.rb', line 52 def active_components(componentIds) # [comp1a, comp1b] # [comp2a, comp2b] # ... components = componentIds .map do |compId| @components[compId].components end compCount = componentIds.size @entities .each_with_index .filter do |entId, _| entId != nil end .map do |_, rowIdx| (0...compCount).map do |compRowId| components[compRowId][rowIdx] end end end |
#components_and_ids(componentIds) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/archetype.rb', line 74 def components_and_ids(componentIds) # [comp1a, comp1b] # [comp2a, comp2b] # ... components = componentIds .map do |compId| @components[compId].components end compCount = componentIds.size @entities .each_with_index .filter do |entId, _| entId != nil end .map do |entId, rowIdx| [entId, *(0...compCount).map do |compRowId| components[compRowId][rowIdx] end] end end |
#get_component(archRowId, componentId) ⇒ Object
38 39 40 |
# File 'lib/archetype.rb', line 38 def get_component(archRowId, componentId) return @components[componentId].components[archRowId] end |
#has_component(componentId) ⇒ Object
42 43 44 |
# File 'lib/archetype.rb', line 42 def has_component(componentId) return @components[componentId] != nil end |
#new_arch_row_id(entityId) ⇒ int
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/archetype.rb', line 17 def new_arch_row_id(entityId) id = @availableEntityRows.pop if id != nil @entities[id] = entityId return id else id = @entities.size @entities.push entityId return id end end |
#remove_entity(archRowId) ⇒ Object
46 47 48 49 |
# File 'lib/archetype.rb', line 46 def remove_entity(archRowId) @availableEntityRows.push(archRowId) @entities[archRowId] = nil end |
#set_component(archRowId, component) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/archetype.rb', line 29 def set_component(archRowId, component) compCol = @components[component.class.object_id] if compCol.components.size <= archRowId compCol.components.push component else compCol.components[archRowId] = component end end |