
com.almasb.fxgl.entity.EntityPool.kt Maven / Gradle / Ivy
/*
* FXGL - JavaFX Game Library. The MIT License (MIT).
* Copyright (c) AlmasB ([email protected]).
* See LICENSE for details.
*/
package com.almasb.fxgl.entity
import java.util.*
/**
*
* @author Almas Baimagambetov ([email protected])
*/
internal class EntityPool {
private val pool = hashMapOf>()
fun put(spawnName: String, entity: Entity) {
var queue: Deque? = pool[spawnName]
if (queue == null) {
queue = ArrayDeque()
pool[spawnName] = queue
}
queue.addLast(entity)
}
fun take(spawnName: String): Entity? {
val queue: Deque? = pool[spawnName]
if (queue != null && queue.isNotEmpty()) {
return queue.removeFirst()
}
return null
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy