Skip to content

Commit

Permalink
Add exists check, fix contains function in TypeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Feb 7, 2024
1 parent 2c47c77 commit eb905c2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class AutoScannerDSL(
scanned.forEach { scannedComponent ->
runCatching { component(scannedComponent) }
.onFailure {
this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}\n${it.stackTraceToString()}")
if (it is ClassNotFoundException)
this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}, class not found")
else
this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}\n${it.stackTraceToString()}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ value class Entity(val id: EntityId) {
entityProvider.remove(this)
}

/** Checks whether this entity has not been removed. */
fun exists(): Boolean = read.exists(this)

/**
* Sets a component that holds data for this entity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class ArrayTypeMap : TypeMap {

override operator fun contains(entity: Entity): Boolean {
val id = entity.id.toInt()
return map.size < id && map[id] != null
return map.size > id && map[id] != null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ interface EntityReadOperations {
/** Gets a list of all the components [entity] has, as well as relations in the form of [RelationComponent]. */
fun getComponentsFor(entity: Entity): Array<Component>

/** Checks whether an [entity] is still active in the engine. */
fun exists(entity: Entity): Boolean

/**
* Gets relations in the same format as [Archetype.getRelations], but when kind/target [HOLDS_DATA], the appropriate
* data is written to a [RelationWithData] object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class ArchetypeReadOperations : EntityReadOperations {
}
}

override fun exists(entity: Entity): Boolean {
return records.contains(entity)
}

override fun getRelationsWithDataFor(
entity: Entity,
kind: ComponentId,
Expand Down

0 comments on commit eb905c2

Please sign in to comment.