-
Notifications
You must be signed in to change notification settings - Fork 9
/
entity_info.go
60 lines (51 loc) · 1.28 KB
/
entity_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package ecs
type EntityInfo struct {
entity Entity
compound Compound
}
func (e *EntityInfo) Destroy(world IWorld) {
for i := 0; i < len(e.compound); i++ {
world.deleteComponentByIntType(e.entity, e.compound[i])
}
// must be last
world.deleteEntity(e.entity)
}
func (e *EntityInfo) Entity() Entity {
return e.entity
}
func (e *EntityInfo) Add(world IWorld, components ...IComponent) {
for _, c := range components {
if !e.compound.Exist(world.getComponentMetaInfoByType(c.Type()).it) {
world.addComponent(e.entity, c)
}
}
}
func (e *EntityInfo) Has(its ...uint16) bool {
for i := 0; i < len(its); i++ {
if !e.compound.Exist(its[i]) {
return false
}
}
return true
}
func (e *EntityInfo) HasType(world *ecsWorld, components ...IComponent) bool {
for i := 0; i < len(components); i++ {
if !e.compound.Exist(world.getComponentMetaInfoByType(components[i].Type()).it) {
return false
}
}
return true
}
func (e *EntityInfo) addToCompound(it uint16) {
e.compound.Add(it)
}
func (e *EntityInfo) removeFromCompound(it uint16) {
e.compound.Remove(it)
}
func (e *EntityInfo) Remove(world IWorld, components ...IComponent) {
for _, c := range components {
if e.compound.Exist(world.getComponentMetaInfoByType(c.Type()).it) {
world.deleteComponent(e.entity, c)
}
}
}