Skip to content

Commit

Permalink
add plusAssign(family) to MutableEntityBag
Browse files Browse the repository at this point in the history
  • Loading branch information
Quillraven committed Dec 19, 2024
1 parent 3aecc15 commit ce471b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.github.quillraven.fleks.collection

import com.github.quillraven.fleks.Entity
import com.github.quillraven.fleks.Family
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random
Expand Down Expand Up @@ -470,6 +471,13 @@ class MutableEntityBag(
entities.forEach { plusAssign(it) }
}

/**
* Adds all entities of the [family] to the bag. If the [capacity] is not sufficient then a resize is happening.
*/
operator fun plusAssign(family: Family) {
family.entities.forEach { plusAssign(it) }
}

/**
* Removes all [entities] of the bag.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.quillraven.fleks.collection

import com.github.quillraven.fleks.Entity
import com.github.quillraven.fleks.Family
import com.github.quillraven.fleks.configureWorld
import kotlin.test.*

Expand Down Expand Up @@ -661,6 +662,22 @@ class EntityBagTest {
assertTrue { testEntity2 in bag }
}

@Test
fun `test plusAssign of a family`() {
val bag = mutableEntityBagOf()
val testWorld = configureWorld { }
val toAdd = Family(world = testWorld).apply {
onEntityAdded(testEntity1, BitArray())
onEntityAdded(testEntity2, BitArray())
}

bag += toAdd

assertEquals(2, bag.size)
assertTrue { testEntity1 in bag }
assertTrue { testEntity2 in bag }
}

@Test
fun `test minusAssign of an EntityBag`() {
val bag = mutableEntityBagOf()
Expand Down

0 comments on commit ce471b0

Please sign in to comment.