mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
fix: edge detection of electric fixture not working
This commit is contained in:
@@ -33,7 +33,7 @@ object CheckUpdate {
|
|||||||
private val checkUpdateURL = setOf(
|
private val checkUpdateURL = setOf(
|
||||||
"https://github.com/curioustorvald/Terrarum/releases/tag/v$versionNumOnly",
|
"https://github.com/curioustorvald/Terrarum/releases/tag/v$versionNumOnly",
|
||||||
"https://github.com/curioustorvald/Terrarum/releases/tag/v$versionNumFull",
|
"https://github.com/curioustorvald/Terrarum/releases/tag/v$versionNumFull",
|
||||||
).toList()
|
).map { it.replace(' ', '_') }
|
||||||
|
|
||||||
private fun wget(url: String): String? {
|
private fun wget(url: String): String? {
|
||||||
printdbg(this, "wget $url")
|
printdbg(this, "wget $url")
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ open class Electric : FixtureBase {
|
|||||||
|
|
||||||
protected constructor() : super() {
|
protected constructor() : super() {
|
||||||
oldSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
oldSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
||||||
newSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
// newSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +46,7 @@ open class Electric : FixtureBase {
|
|||||||
App.disposables.add(mainUI)
|
App.disposables.add(mainUI)
|
||||||
|
|
||||||
oldSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
oldSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
||||||
newSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
// newSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -138,7 +138,7 @@ open class Electric : FixtureBase {
|
|||||||
getWireEmissionAt(offsetX, offsetY).x <= ELECTRIC_THRESHOLD_LOW
|
getWireEmissionAt(offsetX, offsetY).x <= ELECTRIC_THRESHOLD_LOW
|
||||||
|
|
||||||
protected var oldSinkStatus: Array<Vector2>
|
protected var oldSinkStatus: Array<Vector2>
|
||||||
protected var newSinkStatus: Array<Vector2>
|
// protected var newSinkStatus: Array<Vector2>
|
||||||
|
|
||||||
open fun updateOnWireGraphTraversal(offsetX: Int, offsetY: Int, sinkType: WireEmissionType) {
|
open fun updateOnWireGraphTraversal(offsetX: Int, offsetY: Int, sinkType: WireEmissionType) {
|
||||||
val index = pointToBlockBoxIndex(offsetX, offsetY)
|
val index = pointToBlockBoxIndex(offsetX, offsetY)
|
||||||
@@ -150,9 +150,6 @@ open class Electric : FixtureBase {
|
|||||||
Vector2(acc.x + (it?.x ?: 0.0), acc.y + (it?.y ?: 0.0))
|
Vector2(acc.x + (it?.x ?: 0.0), acc.y + (it?.y ?: 0.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
oldSinkStatus[index].set(new2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,27 +167,33 @@ open class Electric : FixtureBase {
|
|||||||
// get indices of "falling edges"
|
// get indices of "falling edges"
|
||||||
val index = pointToBlockBoxIndex(x, y)
|
val index = pointToBlockBoxIndex(x, y)
|
||||||
val type = getWireSinkAt(index) ?: ""
|
val type = getWireSinkAt(index) ?: ""
|
||||||
val new = getWireStateAt(x, y, type)
|
|
||||||
|
|
||||||
if (new.x - oldSinkStatus[index].x >= ELECTRIC_THRESHOLD_EDGE_DELTA && new.x >= ELECTRIC_THRESHOLD_HIGH)
|
if (type.isNotBlank()) {
|
||||||
risingEdgeIndices.add(index)
|
val old = oldSinkStatus[index]
|
||||||
else if (oldSinkStatus[index].x - new.x >= ELECTRIC_THRESHOLD_EDGE_DELTA && new.x <= ELECTRIC_THRESHOLD_LOW)
|
val new = getWireStateAt(x, y, type)
|
||||||
fallingEdgeIndices.add(index)
|
|
||||||
|
val wx = x + worldBlockPos!!.x
|
||||||
|
val wy = y + worldBlockPos!!.y
|
||||||
|
|
||||||
|
println("Wxy($wx,$wy) getWireState($type)=$new, oldState($type)=$old")
|
||||||
|
|
||||||
|
if (new.x - old.x >= ELECTRIC_THRESHOLD_EDGE_DELTA && new.x >= ELECTRIC_THRESHOLD_HIGH)
|
||||||
|
risingEdgeIndices.add(index)
|
||||||
|
else if (old.x - new.x >= ELECTRIC_THRESHOLD_EDGE_DELTA && new.x <= ELECTRIC_THRESHOLD_LOW)
|
||||||
|
fallingEdgeIndices.add(index)
|
||||||
|
|
||||||
|
|
||||||
oldSinkStatus[index].set(new)
|
oldSinkStatus[index].set(new)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (risingEdgeIndices.isNotEmpty()) {
|
||||||
|
println("risingEdgeIndices=$risingEdgeIndices")
|
||||||
|
}
|
||||||
|
|
||||||
risingEdgeIndices.forEach { onRisingEdge(it) }
|
risingEdgeIndices.forEach { onRisingEdge(it) }
|
||||||
fallingEdgeIndices.forEach { onFallingEdge(it) }
|
fallingEdgeIndices.forEach { onFallingEdge(it) }
|
||||||
updateSignal()
|
updateSignal()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*oldSinkStatus.indices.forEach { index ->
|
|
||||||
oldSinkStatus[index].set(new)
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ class FixtureTextSignCopper : Electric {
|
|||||||
blockBox = BlockBox(BlockBox.NO_COLLISION, panelCount, 2)
|
blockBox = BlockBox(BlockBox.NO_COLLISION, panelCount, 2)
|
||||||
setHitboxDimension(TILE_SIZE * blockBox.width, TILE_SIZE * blockBox.height, 0, 2)
|
setHitboxDimension(TILE_SIZE * blockBox.width, TILE_SIZE * blockBox.height, 0, 2)
|
||||||
oldSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
oldSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
||||||
newSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
// newSinkStatus = Array(blockBox.width * blockBox.height) { Vector2() }
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be re-spawned on reload to make it visible after load
|
// must be re-spawned on reload to make it visible after load
|
||||||
|
|||||||
@@ -62,12 +62,12 @@ class FixtureWorldPortal : Electric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onRisingEdge(readFrom: BlockBoxIndex) {
|
override fun onRisingEdge(readFrom: BlockBoxIndex) {
|
||||||
printdbg(this, "readFrom=$readFrom; getWireSinkAt(readFrom)=${getWireSinkAt(readFrom)}")
|
// printdbg(this, "readFrom=$readFrom; getWireSinkAt(readFrom)=${getWireSinkAt(readFrom)}")
|
||||||
|
|
||||||
if (getWireSinkAt(readFrom) != "digital_bit") return
|
if (getWireSinkAt(readFrom) != "digital_bit") return
|
||||||
|
|
||||||
|
|
||||||
printdbg(this, "teleport! $teleportRequest")
|
// printdbg(this, "teleport! $teleportRequest")
|
||||||
teleportRequest?.let {
|
teleportRequest?.let {
|
||||||
if (it.worldDiskToLoad != null && it.worldLoadParam != null) {
|
if (it.worldDiskToLoad != null && it.worldLoadParam != null) {
|
||||||
throw InternalError("Contradiction -- worldDiskToLoad and worldLoadParam are both not null: $teleportRequest")
|
throw InternalError("Contradiction -- worldDiskToLoad and worldLoadParam are both not null: $teleportRequest")
|
||||||
|
|||||||
Reference in New Issue
Block a user