Example #1
0
// AddComponent adds a given component to this Entity
// +component+ *must* be a pointer or the system won't work.
func (self *Entity) AddComponent(component components.Component) {
	self.components[component.Type()] = component

	if self.entityDB != nil {
		self.entityDB.ComponentAdded(self)
	}
}
Example #2
0
func (self *EntityDB) notifyListenersOfRemovedComponent(entity *Entity, component components.Component) {
	for _, listenerEntry := range self.listeners {
		// Find listeners who know about this Entity but no longer want this
		// entity (because the entity's component map no longer matches the Listener's map)
		if listenerEntry.entitySet.Contains(entity) &&
			(listenerEntry.componentMap&component.Type()) > 0 {

			listenerEntry.entitySet.Delete(entity)
			listenerEntry.listener.TearDownEntity(entity)
		}
	}
}