Cleanup nexus event delegate handling

This commit is contained in:
Christian Treffs 2019-08-20 17:01:36 +02:00
parent b692d5de92
commit 00026ad85a
5 changed files with 10 additions and 22 deletions

View File

@ -27,7 +27,7 @@ public extension Nexus {
/// test if component is already assigned
guard !has(componentId: componentId, entityId: entityId) else {
report("ComponentAdd collision: \(entityId) already has a component \(component)")
delegate?.nexusRecoverableErrorOccurred("ComponentAdd collision: \(entityId) already has a component \(component)")
assertionFailure("ComponentAdd collision: \(entityId) already has a component \(component)")
return
}
@ -46,7 +46,7 @@ public extension Nexus {
update(familyMembership: entityId)
notify(ComponentAdded(component: componentId, toEntity: entity.identifier))
delegate?.nexusEventOccurred(ComponentAdded(component: componentId, toEntity: entity.identifier))
}
final func assign<C>(component: C, to entity: Entity) where C: Component {
@ -89,14 +89,14 @@ public extension Nexus {
update(familyMembership: entityId)
notify(ComponentRemoved(component: componentId, from: entityId))
delegate?.nexusEventOccurred(ComponentRemoved(component: componentId, from: entityId))
return true
}
@discardableResult
final func removeAll(componentes entityId: EntityIdentifier) -> Bool {
guard let allComponents = get(components: entityId) else {
report("clearing components form entity \(entityId) with no components")
delegate?.nexusRecoverableErrorOccurred("clearing components form entity \(entityId) with no components")
return false
}
var iter = allComponents.makeIterator()

View File

@ -18,7 +18,7 @@ extension Nexus {
let newEntityIdentifier: EntityIdentifier = nextEntityId()
let newEntity = Entity(nexus: self, id: newEntityIdentifier)
entityStorage.insert(newEntity, at: newEntityIdentifier.index)
notify(EntityCreated(entityId: newEntityIdentifier))
delegate?.nexusEventOccurred(EntityCreated(entityId: newEntityIdentifier))
return newEntity
}
@ -51,7 +51,7 @@ extension Nexus {
let entityId: EntityIdentifier = entity.identifier
guard entityStorage.remove(at: entityId.index) != nil else {
report("EntityRemove failure: no entity \(entityId) to remove")
delegate?.nexusRecoverableErrorOccurred("EntityRemove failure: no entity \(entityId) to remove")
return false
}
@ -61,7 +61,7 @@ extension Nexus {
freeEntities.append(entityId)
notify(EntityDestroyed(entityId: entityId))
delegate?.nexusEventOccurred(EntityDestroyed(entityId: entityId))
return true
}
}

View File

@ -11,8 +11,7 @@ public extension Nexus {
}
func canBecomeMember(_ entity: Entity, in traits: FamilyTraitSet) -> Bool {
let entityId = entity.identifier
guard let componentIds = componentIdsByEntity[entityId] else {
guard let componentIds = componentIdsByEntity[entity.identifier] else {
assertionFailure("no component set defined for entity: \(entity)")
return false
}

View File

@ -48,12 +48,12 @@ extension Nexus {
switch (isMatch, isMember) {
case (true, false):
add(entityWithId: entityId, toFamilyWithTraits: traits)
notify(FamilyMemberAdded(member: entityId, toFamily: traits))
delegate?.nexusEventOccurred(FamilyMemberAdded(member: entityId, toFamily: traits))
return
case (false, true):
remove(entityWithId: entityId, fromFamilyWithTraits: traits)
notify(FamilyMemberRemoved(member: entityId, from: traits))
delegate?.nexusEventOccurred(FamilyMemberRemoved(member: entityId, from: traits))
return
default:

View File

@ -74,17 +74,6 @@ extension Nexus: Equatable {
}
}
// MARK: - nexus delegate
extension Nexus {
internal func notify(_ event: ECSEvent) {
delegate?.nexusEventOccurred(event)
}
internal func report(_ message: String) {
delegate?.nexusRecoverableErrorOccurred(message)
}
}
// MARK: - CustomDebugStringConvertible
extension Nexus: CustomDebugStringConvertible {
public var debugDescription: String {