New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.1 family doesn't get updated #76
Comments
Hm I wouldn't know which change was introduced in 2.1 that could cause that 😅 weird. Anyway, can you let me know please which assertion exactly is failing? Also, which family doesn't get updated? The one from the system or the one that you create inside the onTickEntity method? Also, with 2.1 there is a filter function that you can use to remove your findEntitiesInPosition function. But first let's find out what is not working and why 😉 edit: please also add your component code so that I can reproduce your scenario. |
It is the last assertions // Check it should have moved
Assertions.assertEquals(original, target) The family still returns the toDie entity as it still have the Solid component but if I inspect the entity doesn't have it class MoveSystem(
private val maxWidth:Int = inject("maxWidth"),
private val maxHeight:Int = inject("maxHeight")
) : IteratingSystem(family { all(Position, Moving).none(Dead)}) {
override fun onTickEntity(entity: Entity) {
val originalPosition = entity[Position]
val targetPosition = entity[Moving].target
// position is within the limit and position is not occupied
val entityInTarget = targetPosition.findEntitiesInPosition(world.family { all(Position, Solid) })
entityInTarget.forEach { println(world.snapshotOf(it)) }
if (targetPosition.positionWithin(maxWidth, maxHeight)
&& targetPosition.findEntitiesInPosition(world.family { all(Position, Solid) }).isEmpty()){
originalPosition.x = targetPosition.x
originalPosition.y = targetPosition.y
}
entity.configure { it -= Moving }
} And getting: |
Components: data class Position(
var x: Int,
var y: Int,
) : Component<Position> {
constructor(pos: Position) : this(pos.x, pos.y)
override fun type(): ComponentType<Position> = Position
companion object : ComponentType<Position>()
fun equals(other: Position): Boolean {
return x == other.x && y == other.y
}
}
class Solid: Component<Solid> {
override fun type(): ComponentType<Solid> = Solid
companion object : ComponentType<Solid>()
}
class Dead: Component<Dead> {
override fun type(): ComponentType<Dead> = Dead
companion object : ComponentType<Dead>()
}
data class Moving(val target: Position) : Component<Moving> {
override fun type(): ComponentType<Moving> = Moving
companion object : ComponentType<Moving>()
} |
I also need your "positionWithin" function please and maxWidth/maxHeight |
sure! fun Position.positionWithin(widthLimit:Int, heightLimit:Int):Boolean {
return x in 0 until widthLimit
&& y in 0 until heightLimit
}
class MoveSystemTest {
private val width = 100
private val height = 100
private val world = world {
systems {
add(MoveSystem(width,height))
}
} |
It is indeed a bug that got introduced with 2.1 but it only happens, when family iteration is happening in a nested case like you have it. Your system is iterating over its own family and then you are also iterating over the "special" family that you retrieve from your world. Unfortunately, I broke something in this scenario when trying to cleanup some code and avoid some code duplication. I will have a look at that within this week (I hope) and try to release a fixed version. Additional info for me (and of course you if you are interested!):
In some cases like in @PublishedApi
internal val mutableEntities = MutableEntityBag()
get() {
if (!entityService.delayRemoval || field.isEmpty()) {
// no iteration in process -> update entities if necessary
updateActiveEntities(field)
}
return field
} BUT, this is not correct because e.g. in a nested What I need to do:
|
* update Kotlin to 1.7.21 * update kotlinx.benchmark to 0.4.5 * update version to 2.1a * fix family update during nested iteration
version 2.2 should be soon available on maven |
Hi Simon,
I think I found a bug in the 2.1 version.
So I have a extension that check if a certain family is in a position:
I use this to see if I can move to a target position
So for the version 2.0 this was working fine but I recently upgraded to 2.1 and now it is failing the test below:
The text was updated successfully, but these errors were encountered: