Class: Kiwi::World
Instance Method Summary
collapse
#query, #query_ids, #query_with_ids
Constructor Details
#initialize ⇒ World
Returns a new instance of World.
Instance Method Details
#entity_count ⇒ Object
38
39
40
|
# File 'lib/world.rb', line 38
def entity_count
return @entityStore.entity_count
end
|
#get_component(entityId, componentType) ⇒ Object
25
26
27
28
29
|
# File 'lib/world.rb', line 25
def get_component(entityId, componentType)
entity = @entityStore.get(entityId)
archetype = @archStore.get(entity.archId)
archetype.get_component(entity.archRow, componentType.object_id)
end
|
#has_component(entityId, componentType) ⇒ Object
42
43
44
45
46
|
# File 'lib/world.rb', line 42
def has_component(entityId, componentType)
entity = @entityStore.get(entityId)
archetype = @archStore.get(entity.archId)
return archetype.has_component(componentType.object_id)
end
|
#has_flag(entityId, flagId) ⇒ Object
48
49
50
|
# File 'lib/world.rb', line 48
def has_flag(entityId, flagId)
return @entityStore.has_flag entityId, flagId
end
|
#has_flags(entityId, *flagIds) ⇒ Object
52
53
54
|
# File 'lib/world.rb', line 52
def has_flags(entityId, *flagIds)
return flagIds.filter { |flagId| !@entityStore.has_flag entityId, flagId }.count == 0
end
|
#kill(entityId) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/world.rb', line 31
def kill(entityId)
entity = @entityStore.get entityId
@entityStore.kill(entityId)
archetype = @archStore.get(entity.archId)
archetype.remove_entity(entity.archRow)
end
|
#remove_flag(entityId, flagId) ⇒ Object
60
61
62
|
# File 'lib/world.rb', line 60
def remove_flag(entityId, flagId)
@entityStore.remove_flag(entityId, flagId)
end
|
#set_flag(entityId, flagId) ⇒ Object
56
57
58
|
# File 'lib/world.rb', line 56
def set_flag(entityId, flagId)
@entityStore.set_flag(entityId, flagId)
end
|
#spawn(*components) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/world.rb', line 12
def spawn(*components)
compIds = components.map { |c| c.class.object_id }.sort
archId = @archStore.get_archetype_id(compIds)
entId = @entityStore.new_id
archetype = @archStore.get(archId)
archRowId = archetype.new_arch_row_id(entId)
@entityStore.spawn(entId, archId, archRowId)
for component in components
archetype.set_component(archRowId, component)
end
return entId
end
|