Cleanups
This commit is contained in:
parent
d9f7f44564
commit
ea7be64755
|
|
@ -1,8 +1,7 @@
|
|||
included:
|
||||
- Sources
|
||||
- Tests
|
||||
excluded:
|
||||
- Tests/FirebladeECSTests
|
||||
- Tests
|
||||
opt_in_rules:
|
||||
#- file_header
|
||||
- array_init
|
||||
|
|
@ -65,20 +64,4 @@ identifier_name:
|
|||
- id
|
||||
line_length: 220
|
||||
number_separator:
|
||||
minimum_length: 5
|
||||
|
||||
custom_rules:
|
||||
rule_id:
|
||||
included: Source/SwiftLintFramework/Rules/\w+\.swift
|
||||
name: Rule ID
|
||||
message: Rule IDs must be all lowercase, snake case and not end with `rule`
|
||||
regex: identifier:\s*("\w+_rule"|"\S*[^a-z_]\S*")
|
||||
severity: error
|
||||
fatal_error:
|
||||
name: Fatal Error
|
||||
excluded: "Tests/*"
|
||||
message: Prefer using `queuedFatalError` over `fatalError` to avoid leaking compiler host machine paths.
|
||||
regex: \bfatalError\b
|
||||
match_kinds:
|
||||
- identifier
|
||||
severity: error
|
||||
minimum_length: 5
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Entity.swift
|
||||
// Entity.swift
|
||||
// FirebladeECS
|
||||
//
|
||||
// Created by Christian Treffs on 08.10.17.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Events.swift
|
||||
// Events.swift
|
||||
// FirebladeECS
|
||||
//
|
||||
// Created by Christian Treffs on 08.10.17.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
//
|
||||
// Family.swift
|
||||
// FirebladeECS
|
||||
//
|
||||
|
|
@ -41,7 +40,7 @@ public final class Family {
|
|||
public extension Family {
|
||||
|
||||
var count: Int {
|
||||
return nexus?.members(of: self).count ?? 0
|
||||
return nexus?.members(of: self)?.count ?? 0
|
||||
}
|
||||
|
||||
final func canBecomeMember(_ entity: Entity) -> Bool {
|
||||
|
|
|
|||
|
|
@ -54,10 +54,7 @@ extension Nexus {
|
|||
}
|
||||
componentIdsByEntity[entityIdx]?.add(componentId, at: componentId.hashValue)
|
||||
|
||||
// FIXME: iterating all families is costly for many families
|
||||
for (_, family) in familiesByTraitHash {
|
||||
update(membership: family, for: entityId)
|
||||
}
|
||||
update(familyMembership: entityId)
|
||||
|
||||
notify(ComponentAdded(component: componentId, toEntity: entity.identifier))
|
||||
}
|
||||
|
|
@ -99,10 +96,7 @@ extension Nexus {
|
|||
// unasign component from entity
|
||||
componentIdsByEntity[entityIdx]?.remove(at: componentId.hashValue)
|
||||
|
||||
// FIXME: iterating all families is costly for many families
|
||||
for (_, family) in familiesByTraitHash {
|
||||
update(membership: family, for: entityId)
|
||||
}
|
||||
update(familyMembership: entityId)
|
||||
|
||||
notify(ComponentRemoved(component: componentId, from: entityId))
|
||||
return true
|
||||
|
|
@ -117,5 +111,4 @@ extension Nexus {
|
|||
let removedAll: Bool = allComponents.reduce(true) { $0 && remove(component: $1, from: entityId) }
|
||||
return removedAll
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,10 +52,7 @@ extension Nexus {
|
|||
|
||||
freeEntities.append(entityId)
|
||||
|
||||
// FIXME: iterating all families is costly for many families
|
||||
for (_, family) in familiesByTraitHash {
|
||||
update(membership: family, for: entityId)
|
||||
}
|
||||
update(familyMembership: entityId)
|
||||
|
||||
notify(EntityDestroyed(entityId: entityId))
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -36,14 +36,13 @@ public extension Nexus {
|
|||
return family.traits.isMatch(components: componentSet)
|
||||
}
|
||||
|
||||
func members(of family: Family) -> UniformEntityIdentifiers {
|
||||
func members(of family: Family) -> UniformEntityIdentifiers? {
|
||||
let traitHash: FamilyTraitSetHash = family.traits.hashValue
|
||||
return members(of: traitHash)
|
||||
}
|
||||
|
||||
func members(of traitHash: FamilyTraitSetHash) -> UniformEntityIdentifiers {
|
||||
// FIXME: we may fail here if this is empty
|
||||
return familyMembersByTraitHash[traitHash] ?? UniformEntityIdentifiers()
|
||||
func members(of traitHash: FamilyTraitSetHash) -> UniformEntityIdentifiers? {
|
||||
return familyMembersByTraitHash[traitHash]
|
||||
}
|
||||
|
||||
func isMember(_ entity: Entity, in family: Family) -> Bool {
|
||||
|
|
@ -52,7 +51,7 @@ public extension Nexus {
|
|||
|
||||
func isMember(_ entityId: EntityIdentifier, in family: Family) -> Bool {
|
||||
let traitHash: FamilyTraitSetHash = family.traits.hashValue
|
||||
guard let members: UniformEntityIdentifiers = familyMembersByTraitHash[traitHash] else {
|
||||
guard let members: UniformEntityIdentifiers = members(of: traitHash) else {
|
||||
return false
|
||||
}
|
||||
return members.has(entityId.index)
|
||||
|
|
@ -72,11 +71,21 @@ extension Nexus {
|
|||
}
|
||||
|
||||
func onFamilyDeinit(traitHash: FamilyTraitSetHash) {
|
||||
for member in members(of: traitHash) {
|
||||
guard let members = members(of: traitHash) else {
|
||||
return
|
||||
}
|
||||
for member in members {
|
||||
remove(from: traitHash, entityId: member, entityIdx: member.index)
|
||||
}
|
||||
}
|
||||
|
||||
func update(familyMembership entityId: EntityIdentifier) {
|
||||
// FIXME: iterating all families is costly for many families
|
||||
for family in familiesByTraitHash.values {
|
||||
update(membership: family, for: entityId)
|
||||
}
|
||||
}
|
||||
|
||||
func update(membership family: Family, for entityId: EntityIdentifier) {
|
||||
let entityIdx: EntityIndex = entityId.index
|
||||
let traits: FamilyTraitSet = family.traits
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ class FamilyTests: XCTestCase {
|
|||
}
|
||||
|
||||
let familyA = nexus.family(requiresAll: [Position.self], excludesAll: [Velocity.self])
|
||||
let familyB = nexus.family(requiresAll: [Velocity.self], excludesAll: [Position.self])
|
||||
_ = nexus.family(requiresAll: [Velocity.self], excludesAll: [Position.self])
|
||||
|
||||
familyA.iterate { (_: EntityIdentifier, pos: Position!, vel: Velocity!) in
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue