Class: World

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

Instance Method Summary collapse

Methods included from Query

#query, #query_ids, #query_with_ids

Constructor Details

#initializeWorld

Returns a new instance of World.



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

def initialize
  @entityStore = EntityStore.new
  @archStore = ArchStore.new
end

Instance Method Details

#entity_countObject



37
38
39
# File 'lib/world.rb', line 37

def entity_count
  return @entityStore.entity_count
end

#get_component(entityId, componentType) ⇒ Object



24
25
26
27
28
# File 'lib/world.rb', line 24

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



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

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



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

def has_flag(entityId, flagId)
  return @entityStore.has_flag entityId, flagId
end

#has_flags(entityId, *flagIds) ⇒ Object



51
52
53
# File 'lib/world.rb', line 51

def has_flags(entityId, *flagIds)
  return flagIds.filter { |flagId| !@entityStore.has_flag entityId, flagId }.count == 0
end

#kill(entityId) ⇒ Object



30
31
32
33
34
35
# File 'lib/world.rb', line 30

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



59
60
61
# File 'lib/world.rb', line 59

def remove_flag(entityId, flagId)
  @entityStore.remove_flag(entityId, flagId)
end

#set_flag(entityId, flagId) ⇒ Object



55
56
57
# File 'lib/world.rb', line 55

def set_flag(entityId, flagId)
  @entityStore.set_flag(entityId, flagId)
end

#spawn(*components) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/world.rb', line 11

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