-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEntity.go
42 lines (32 loc) · 1019 Bytes
/
Entity.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
package talosecs
type Entity uint32
var currentEntityId Entity
// Add is similar to the AddComponent(entity, component), just shorter way to do this
func (e Entity) Add(c any) { AddComponent(e, c) }
// OneFrame is similar to the AddOneFrame(entity, component), just shorter way to do this
func (e Entity) OneFrame(c any) { AddOneFrame(e, c) }
// NewEntity creates new Entity in the game world.
func NewEntity() Entity {
currentEntityId++
id := currentEntityId
entsComponents[id] = []any{}
return id
}
func GetEntity(comp any) Entity { return componentsEnts[comp] }
func SameEntity(compA, compB any) bool { return GetEntity(compA) == GetEntity(compB) }
func IsAlive(entity Entity) bool {
_, exist := entsComponents[entity]
return exist
}
func KillEntity(entity Entity) {
if IsAlive(entity) {
for _, component := range entsComponents[entity] {
DelSpecificComponent(component, entity)
}
}
}
func fullRemoveEntity(entity Entity) {
if IsAlive(entity) {
delete(entsComponents, entity)
}
}