fixed a stupid bug where spawning a same kind of fixture twice would crash the game because the spawner would not renew the fixture instance after a first spawn

This commit is contained in:
minjaesong
2022-03-23 10:03:03 +09:00
parent de45ad1c25
commit 76435dbbdf
5 changed files with 24 additions and 19 deletions

View File

@@ -775,7 +775,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
repossessActor()
// process actor addition requests
actorAdditionQueue.forEach { forceAddActor(it) }
actorAdditionQueue.forEach { forceAddActor(it.first, it.second) }
actorAdditionQueue.clear()
// determine whether the inactive actor should be activated
wakeDormantActors()
@@ -784,7 +784,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
// determine whether the actor should keep being activated or be dormant
killOrKnockdownActors()
// process actor removal requests
actorRemovalQueue.forEach { forceRemoveActor(it) }
actorRemovalQueue.forEach { forceRemoveActor(it.first, it.second) }
actorRemovalQueue.clear()
// update particles
particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) }
@@ -1141,7 +1141,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
}
override fun forceRemoveActor(actor: Actor) {
override fun forceRemoveActor(actor: Actor, caller: Throwable) {
arrayOf(actorContainerActive, actorContainerInactive).forEach { actorContainer ->
val indexToDelete = actorContainer.searchForIndex(actor.referenceID) { it.referenceID }
if (indexToDelete != null) {
@@ -1185,11 +1185,11 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
/**
* Check for duplicates, append actor and sort the list
*/
override fun forceAddActor(actor: Actor?) {
override fun forceAddActor(actor: Actor?, caller: Throwable) {
if (actor == null) return
if (theGameHasActor(actor.referenceID)) {
throw ReferencedActorAlreadyExistsException(actor)
throw ReferencedActorAlreadyExistsException(actor, caller)
}
else {
actorContainerActive.add(actor)

View File

@@ -26,6 +26,8 @@ open class DroppedItem : ActorWithBody {
var itemID: ItemID = ""; private set
@Transient private var visualItemID = ""
@Transient private var textureRegion: TextureRegion? = null // deserialiser won't call setter of the fields
var itemCount = 1L
@@ -76,8 +78,11 @@ open class DroppedItem : ActorWithBody {
override fun drawBody(batch: SpriteBatch) {
// deserialiser won't call setter of the fields
if (visualItemID == "") {
visualItemID = BlockCodex.getOrNull(itemID)?.world ?: itemID
}
if (textureRegion == null) {
textureRegion = ItemCodex.getItemImage(itemID)!!
textureRegion = ItemCodex.getItemImage(visualItemID)!!
}
// copy-pasted from ActorWithBody.drawSpriteInGoodPosition()

View File

@@ -87,7 +87,7 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
val item = ghostItem.get()//makeFixture()
val item = ghostItem.getAndSet(makeFixture()) // renew the "ghost" otherwise you'll be spawning exactly the same fixture again; old ghost will be returned
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
// return true when placed, false when cannot be placed