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