mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
why ghost item latch is always false when read?? fixed using atomic vars
This commit is contained in:
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
@@ -12,16 +13,18 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
||||
import net.torvald.terrarum.utils.RandomWordsName
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-12-13.
|
||||
*/
|
||||
open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : GameItem(originalID) {
|
||||
|
||||
private val hash = RandomWordsName(4)
|
||||
// @Transient private val hash = RandomWordsName(4)
|
||||
|
||||
|
||||
protected open val makeFixture: () -> FixtureBase = {
|
||||
@Transient protected open val makeFixture: () -> FixtureBase = {
|
||||
Class.forName(fixtureClassName).getDeclaredConstructor().newInstance() as FixtureBase
|
||||
}
|
||||
|
||||
@@ -29,11 +32,11 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
||||
ItemCodex.fixtureToSpawnerItemID[fixtureClassName] = originalID
|
||||
|
||||
|
||||
println("FixtureItemBase init: $hash")
|
||||
// println("FixtureItemBase init: $hash")
|
||||
}
|
||||
|
||||
// private var _ghostItem: FixtureBase? = null
|
||||
private var ghostItem: FixtureBase? = null
|
||||
@Transient private var ghostItem = AtomicReference<FixtureBase>()
|
||||
|
||||
override var dynamicID: ItemID = originalID
|
||||
override val originalName = "FIXTUREBASE"
|
||||
@@ -54,17 +57,18 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
||||
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
private var ghostInit = false
|
||||
|
||||
@Transient private var ghostInit = AtomicBoolean(false)
|
||||
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
println("ghost: ${ghostItem}; ghostInit = $ghostInit; instance: $hash")
|
||||
if (!ghostInit) {
|
||||
ghostInit = true
|
||||
ghostItem = makeFixture()
|
||||
// println("ghost: ${ghostItem}; ghostInit = $ghostInit; instance: $hash")
|
||||
if (!ghostInit.get()) {
|
||||
ghostItem.getAndSet(makeFixture())
|
||||
ghostInit.getAndSet(true)
|
||||
// printdbg(this, "ghost item initialised: $ghostItem")
|
||||
}
|
||||
|
||||
(INGAME as TerrarumIngame).blockMarkingActor.let {
|
||||
it.setGhost(ghostItem!!)
|
||||
it.setGhost(ghostItem.get())
|
||||
it.isVisible = true
|
||||
it.update(delta)
|
||||
it.setGhostColourBlock()
|
||||
@@ -83,7 +87,7 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
|
||||
val item = ghostItem!!//makeFixture()
|
||||
val item = ghostItem.get()//makeFixture()
|
||||
|
||||
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
|
||||
// return true when placed, false when cannot be placed
|
||||
|
||||
@@ -345,7 +345,6 @@ class UIItemTextLineInput(
|
||||
textbuf.addAll(cursorX, codepoints)
|
||||
cursorX += codepoints.size
|
||||
currentTextLenPx = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||
println("cursorX now: $cursorX; w: $currentTextLenPx; wOld: $oldTextLenPx")
|
||||
moveCursorForward(currentTextLenPx - oldTextLenPx)
|
||||
oldTextLenPx = currentTextLenPx
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user