mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
issue #26 resolved (someone is hoolding stale ingame context)
This commit is contained in:
@@ -317,7 +317,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private var updateAkku = 0.0
|
||||
|
||||
override fun render(delta: Float) {
|
||||
override fun render(updateRate: Float) {
|
||||
Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
|
||||
|
||||
|
||||
@@ -327,9 +327,9 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
updateAkku += dt
|
||||
|
||||
var i = 0L
|
||||
while (updateAkku >= delta) {
|
||||
AppLoader.measureDebugTime("Ingame.update") { updateGame(delta) }
|
||||
updateAkku -= delta
|
||||
while (updateAkku >= updateRate) {
|
||||
AppLoader.measureDebugTime("Ingame.update") { updateGame(updateRate) }
|
||||
updateAkku -= updateRate
|
||||
i += 1
|
||||
}
|
||||
AppLoader.setDebugTime("Ingame.updateCounter", i)
|
||||
|
||||
@@ -27,7 +27,6 @@ import net.torvald.terrarum.modulebasegame.ui.*
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
|
||||
import net.torvald.terrarum.ui.ConsoleWindow
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE
|
||||
@@ -236,7 +235,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
*/
|
||||
private fun enter(worldParams: NewWorldParameters) {
|
||||
printdbg(this, "Ingame called")
|
||||
printStackTrace()
|
||||
printStackTrace(this)
|
||||
|
||||
if (gameInitialised) {
|
||||
printdbg(this, "loaded successfully.")
|
||||
@@ -285,8 +284,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
// init console window
|
||||
consoleHandler = ConsoleWindow()
|
||||
consoleHandler.setPosition(0, 0)
|
||||
// TODO test put it on the IngameInstance.(init)
|
||||
//consoleHandler = ConsoleWindow()
|
||||
//consoleHandler.setPosition(0, 0)
|
||||
|
||||
|
||||
// init notifier
|
||||
@@ -426,9 +426,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private var updateAkku = 0.0
|
||||
|
||||
override fun render(delta: Float) {
|
||||
println("Vitun Perkeleen TerrarumIngame")
|
||||
|
||||
override fun render(`_`: Float) {
|
||||
// Q&D solution for LoadScreen and Ingame, where while LoadScreen is working, Ingame now no longer has GL Context
|
||||
// there's still things to load which needs GL context to be present
|
||||
if (!gameFullyLoaded) {
|
||||
@@ -447,6 +445,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
gameFullyLoaded = true
|
||||
}
|
||||
|
||||
// define custom update rate
|
||||
val updateRate = if (KeyToggler.isOn(Input.Keys.APOSTROPHE)) 1f / 8f else AppLoader.UPDATE_RATE
|
||||
|
||||
// ASYNCHRONOUS UPDATE AND RENDER //
|
||||
|
||||
/** UPDATE CODE GOES HERE */
|
||||
@@ -454,9 +455,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
updateAkku += dt
|
||||
|
||||
var i = 0L
|
||||
while (updateAkku >= delta) {
|
||||
AppLoader.measureDebugTime("Ingame.update") { updateGame(delta) }
|
||||
updateAkku -= delta
|
||||
while (updateAkku >= updateRate) {
|
||||
AppLoader.measureDebugTime("Ingame.update") { updateGame(updateRate) }
|
||||
updateAkku -= updateRate
|
||||
i += 1
|
||||
}
|
||||
AppLoader.setDebugTime("Ingame.updateCounter", i)
|
||||
@@ -473,7 +474,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private var worldWidth: Double = 0.0
|
||||
|
||||
|
||||
/**
|
||||
* Ingame (world) related updates; UI update must go to renderGame()
|
||||
*/
|
||||
protected fun updateGame(delta: Float) {
|
||||
val world = this.world as GameWorldExtension
|
||||
worldWidth = world.width.toDouble() * TILE_SIZE
|
||||
@@ -532,7 +535,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
////////////////////////
|
||||
// ui-related updates //
|
||||
////////////////////////
|
||||
uiContainer.forEach { it.update(delta) }
|
||||
//uiContainer.forEach { it.update(delta) }
|
||||
//debugWindow.update(delta)
|
||||
//notifier.update(delta)
|
||||
|
||||
@@ -548,6 +551,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
Gdx.graphics.setTitle(getCanonicalTitle())
|
||||
|
||||
filterVisibleActors()
|
||||
uiContainer.forEach { it.update(Gdx.graphics.rawDeltaTime) }
|
||||
|
||||
IngameRenderer.invoke(
|
||||
paused,
|
||||
@@ -769,7 +773,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
val indexToDelete = actorContainerActive.searchForIndex(actor.referenceID!!) { it.referenceID!! }
|
||||
if (indexToDelete != null) {
|
||||
printdbg(this, "Removing actor $actor")
|
||||
printStackTrace()
|
||||
printStackTrace(this)
|
||||
|
||||
actorContainerActive.removeAt(indexToDelete)
|
||||
|
||||
@@ -835,7 +839,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
else {
|
||||
printdbg(this, "Adding actor $actor")
|
||||
printStackTrace()
|
||||
printStackTrace(this)
|
||||
|
||||
actorContainerActive.add(actor)
|
||||
|
||||
@@ -1008,11 +1012,4 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
super.dispose()
|
||||
}
|
||||
|
||||
|
||||
private fun printStackTrace() {
|
||||
Thread.currentThread().getStackTrace().forEach {
|
||||
printdbg(this, "--> $it")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ open class ActorHumanoid(
|
||||
|
||||
val timedJumpCharge = jumpFunc(MAX_JUMP_LENGTH, jmpCtr)
|
||||
forceVec.y -= getJumpAcc(jumpPower, timedJumpCharge)
|
||||
forceVec.y += getDrag(AppLoader.UPDATE_RATE.toFloat(), forceVec).y
|
||||
forceVec.y += getDrag(AppLoader.UPDATE_RATE, forceVec).y
|
||||
|
||||
simYPos += forceVec.y // ignoring all the fluid drag OTHER THAN THE AIR
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
|
||||
actor.avStrength / 1000.0
|
||||
else
|
||||
1.0 // TODO variable: scale, strength
|
||||
val swingDmgToFrameDmg = AppLoader.UPDATE_RATE.toFloat().toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = AppLoader.UPDATE_RATE.toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
|
||||
// damage the item
|
||||
newItem.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat()
|
||||
|
||||
@@ -23,7 +23,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
|
||||
/** Will NOT actually delete from the CircularArray */
|
||||
@Volatile var flagDespawn = false
|
||||
|
||||
override fun run() = update(AppLoader.UPDATE_RATE.toFloat())
|
||||
override fun run() = update(AppLoader.UPDATE_RATE)
|
||||
|
||||
var isNoSubjectToGrav = false
|
||||
var dragCoefficient = 3.0
|
||||
|
||||
@@ -28,7 +28,7 @@ interface Pocketed {
|
||||
}
|
||||
|
||||
inventory.itemEquipped[item.equipPosition] = null
|
||||
item.effectOnUnequip(AppLoader.UPDATE_RATE.toFloat())
|
||||
item.effectOnUnequip(AppLoader.UPDATE_RATE)
|
||||
}
|
||||
|
||||
fun unequipItem(itemID: ItemID?) {
|
||||
@@ -56,7 +56,7 @@ interface Pocketed {
|
||||
|
||||
if (item.equipPosition >= 0) {
|
||||
inventory.itemEquipped[item.equipPosition] = item.dynamicID
|
||||
item.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
||||
item.effectWhenEquipped(AppLoader.UPDATE_RATE)
|
||||
}
|
||||
// else do nothing
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
|
||||
override fun run() {
|
||||
for (i in startIndex..endIndex) {
|
||||
val it = Terrarum.ingame!!.actorContainerActive[i]
|
||||
it.update(AppLoader.UPDATE_RATE.toFloat())
|
||||
it.update(AppLoader.UPDATE_RATE)
|
||||
|
||||
if (it is Pocketed) {
|
||||
it.inventory.forEach { inventoryEntry ->
|
||||
ItemCodex[inventoryEntry.item]?.effectWhileInPocket(AppLoader.UPDATE_RATE.toFloat())
|
||||
ItemCodex[inventoryEntry.item]?.effectWhileInPocket(AppLoader.UPDATE_RATE)
|
||||
if (it.equipped(inventoryEntry.item)) {
|
||||
ItemCodex[inventoryEntry.item]?.effectWhenEquipped(AppLoader.UPDATE_RATE.toFloat())
|
||||
ItemCodex[inventoryEntry.item]?.effectWhenEquipped(AppLoader.UPDATE_RATE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.aa.KDTree
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
@@ -11,6 +12,7 @@ import net.torvald.terrarum.blockproperties.Fluid
|
||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.FluidType
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.roundInt
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||
@@ -58,8 +60,10 @@ object WorldSimulator {
|
||||
val colourNone = Color(0x808080FF.toInt())
|
||||
val colourWater = Color(0x66BBFFFF.toInt())
|
||||
|
||||
private val ingame = Terrarum.ingame!!
|
||||
private val world = ingame.world
|
||||
private val ingame: IngameInstance
|
||||
get() = Terrarum.ingame!!
|
||||
private val world: GameWorld
|
||||
get() = ingame.world
|
||||
|
||||
// TODO use R-Tree instead? https://stackoverflow.com/questions/10269179/find-rectangles-that-contain-point-efficient-algorithm#10269695
|
||||
private var actorsKDTree: KDTree? = null
|
||||
@@ -81,7 +85,6 @@ object WorldSimulator {
|
||||
updateXTo = updateXFrom + DOUBLE_RADIUS
|
||||
updateYTo = updateYFrom + DOUBLE_RADIUS
|
||||
}
|
||||
|
||||
moveFluids(delta)
|
||||
displaceFallables(delta)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.torvald.terrarum.ui.UICanvas
|
||||
/**
|
||||
* Created by minjaesong on 2017-03-13.
|
||||
*/
|
||||
class NullUI : UICanvas() {
|
||||
object NullUI : UICanvas() {
|
||||
override var width: Int = 0
|
||||
override var height: Int = 0
|
||||
override var openCloseTime = 0f
|
||||
|
||||
Reference in New Issue
Block a user