MCPcopy Create free account
hub / github.com/EngoEngine/ecs / AddEntity

Method AddEntity

world.go:62–96  ·  view source on GitHub ↗

AddEntity adds the entity to all systems that have been added via AddSystemInterface. If the system was added via AddSystem the entity will not be added to it.

(e Identifier)

Source from the content-addressed store, hash-verified

60// AddSystemInterface. If the system was added via AddSystem the entity will not be
61// added to it.
62func (w *World) AddEntity(e Identifier) {
63 if w.sysIn == nil {
64 w.sysIn = make(map[reflect.Type][]reflect.Type)
65 }
66 if w.sysEx == nil {
67 w.sysEx = make(map[reflect.Type][]reflect.Type)
68 }
69
70 search := func(i Identifier, types []reflect.Type) bool {
71 for _, t := range types {
72 if reflect.TypeOf(i).Implements(t) {
73 return true
74 }
75 }
76 return false
77 }
78 for _, system := range w.systems {
79 sys, ok := system.(SystemAddByInterfacer)
80 if !ok {
81 continue
82 }
83
84 if ex, not := w.sysEx[reflect.TypeOf(sys)]; not {
85 if search(e, ex) {
86 continue
87 }
88 }
89 if in, ok := w.sysIn[reflect.TypeOf(sys)]; ok {
90 if search(e, in) {
91 sys.AddByInterface(e)
92 continue
93 }
94 }
95 }
96}
97
98// Systems returns the list of Systems managed by the World.
99func (w *World) Systems() []System {

Callers 3

TestAddRemoveFunction · 0.95
TestWorld_AddEntityFunction · 0.80

Calls 1

AddByInterfaceMethod · 0.65

Tested by 3

TestAddRemoveFunction · 0.76
TestWorld_AddEntityFunction · 0.64