Skip to content

Commit

Permalink
#153 add isMarkedForRemoval function
Browse files Browse the repository at this point in the history
  • Loading branch information
Quillraven committed Aug 30, 2024
1 parent 2a4046e commit 3c0ece2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/commonMain/kotlin/com/github/quillraven/fleks/entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ abstract class EntityComponentContext(
* future calls to [World.entity].
*/
fun Entity.remove() = componentService.world.minusAssign(this)

/**
* Returns true, if and only if an [entity][Entity] will be removed at the end of the current [IteratingSystem].
* This is the case, if it gets [removed][remove] during the system's iteration.
*/
fun Entity.isMarkedForRemoval() = this in componentService.world.entityService.delayedEntities
}

/**
Expand Down Expand Up @@ -423,7 +429,7 @@ class EntityService(
/**
* The entities that get removed at the end of an [IteratingSystem] iteration.
*/
private val delayedEntities = MutableEntityBag()
internal val delayedEntities = MutableEntityBag()

/**
* An optional [EntityHook] that gets called whenever an [entity][Entity] gets created and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ internal class EntityTest {
val entity = testEntityService.create { }
testEntityService.delayRemoval = true

with(testEntityService.world) { assertFalse(entity.isMarkedForRemoval()) }
testEntityService -= entity

assertEquals(1, testEntityService.numEntities)
with(testEntityService.world) { assertTrue(entity.isMarkedForRemoval()) }
}

@Test
Expand Down

0 comments on commit 3c0ece2

Please sign in to comment.