sortedarraylist update; physball breaks the actor render dunno why

This commit is contained in:
minjaesong
2019-04-30 02:52:09 +09:00
parent 5a95f1c21a
commit 7d216acd52
12 changed files with 130 additions and 52 deletions

View File

@@ -137,7 +137,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
internal var showSelection = true
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
override var referenceID: ActorID? = 1048575 // custom refID
override var referenceID: ActorID = 1048575 // custom refID
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
@@ -177,7 +177,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private var _testMarkerDrawCalls = 0L
private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
override var referenceID: ActorID? = blockPosToRefID(x, y) // custom refID
override var referenceID: ActorID = blockPosToRefID(x, y) // custom refID
override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0)
override fun drawBody(batch: SpriteBatch) {

View File

@@ -747,8 +747,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
throw RuntimeException("Attempted to remove player.")
val indexToDelete = actorContainerActive.binarySearch(actor.referenceID!!)
if (indexToDelete >= 0) {
val indexToDelete = actorContainerActive.searchForIndex(actor.referenceID!!) { it.referenceID!! }
if (indexToDelete != null) {
printdbg(this, "Removing actor $actor")
printStackTrace()
@@ -783,6 +783,28 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
}
private fun ArrayList<*>.binarySearch(actor: Actor) = this.binarySearch(actor.referenceID!!)
private fun ArrayList<*>.binarySearch(ID: Int): Int {
// code from collections/Collections.kt
var low = 0
var high = this.size - 1
while (low <= high) {
val mid = (low + high).ushr(1) // safe from overflows
val midVal = get(mid)!!
if (ID > midVal.hashCode())
low = mid + 1
else if (ID < midVal.hashCode())
high = mid - 1
else
return mid // key found
}
return -(low + 1) // key not found
}
/**
* Check for duplicates, append actor and sort the list
*/