mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
A working autosave
This commit is contained in:
@@ -232,7 +232,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private val introUncoverTime: Second = 0.3f
|
||||
private var introUncoverDeltaCounter = 0f
|
||||
private var updateAkku = 0.0
|
||||
private var updateAkku = 0f
|
||||
|
||||
private var fucklatch = false
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
super.show()
|
||||
}
|
||||
|
||||
private var updateAkku = 0.0
|
||||
private var updateAkku = 0f
|
||||
|
||||
override fun render(updateRate: Float) {
|
||||
Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
|
||||
|
||||
@@ -16,7 +16,10 @@ import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||
import net.torvald.terrarum.console.AVTracker
|
||||
import net.torvald.terrarum.console.ActorsList
|
||||
import net.torvald.terrarum.console.Authenticator
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.ActorID
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.WireActor
|
||||
import net.torvald.terrarum.gamecontroller.IngameController
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
@@ -37,14 +40,12 @@ import net.torvald.terrarum.tvda.VDUtil
|
||||
import net.torvald.terrarum.tvda.VirtualDisk
|
||||
import net.torvald.terrarum.ui.UIAutosaveNotifier
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.utils.RandomWordsName
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.util.CircularArray
|
||||
import org.khelekore.prtree.PRTree
|
||||
import java.io.File
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -322,8 +323,10 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
)
|
||||
|
||||
// make initial savefile
|
||||
uiAutosaveNotifier.setAsOpen()
|
||||
WriteSavegame.immediate(savegameArchive, getSaveFileMain(), this, true) {
|
||||
makeSavegameBackupCopy() // don't put it on the postInit() or render(); must be called using callback
|
||||
uiAutosaveNotifier.setAsClose()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,8 +434,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
uiBasicInfo.setAsAlwaysVisible()
|
||||
uiBasicInfo.setPosition((uiQuickBar.posX - uiBasicInfo.width - App.scr.tvSafeActionWidth) / 2 + App.scr.tvSafeActionWidth, uiWatchTierOne.posY)
|
||||
|
||||
uiAutosaveNotifier = UIAutosaveNotifier()
|
||||
|
||||
|
||||
uiCheatMotherfuckerNootNoot = UICheatDetected()
|
||||
|
||||
@@ -549,13 +550,16 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
}
|
||||
|
||||
private var updateAkku = 0.0
|
||||
private var updateAkku = 0f
|
||||
private var autosaveTimer = 0f
|
||||
|
||||
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) {
|
||||
|
||||
uiAutosaveNotifier = UIAutosaveNotifier()
|
||||
|
||||
if (gameLoadMode == GameLoadMode.CREATE_NEW) {
|
||||
postInitForNewGame()
|
||||
}
|
||||
@@ -580,6 +584,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
/** UPDATE CODE GOES HERE */
|
||||
val dt = Gdx.graphics.deltaTime
|
||||
updateAkku += dt
|
||||
autosaveTimer += dt
|
||||
|
||||
var i = 0L
|
||||
while (updateAkku >= updateRate) {
|
||||
@@ -594,6 +599,12 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
/** RENDER CODE GOES HERE */
|
||||
measureDebugTime("Ingame.Render") { renderGame() }
|
||||
|
||||
val autosaveInterval = App.getConfigInt("autosaveinterval") / 1000f
|
||||
if (autosaveTimer >= autosaveInterval) {
|
||||
queueAutosave()
|
||||
autosaveTimer -= autosaveInterval
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var worldWidth: Double = 0.0
|
||||
@@ -608,14 +619,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
particlesActive = 0
|
||||
|
||||
if (KeyToggler.isOn(Input.Keys.SLASH) && !uiAutosaveNotifier.isVisible) {
|
||||
println("autosave open")
|
||||
uiAutosaveNotifier.setAsOpen()
|
||||
}
|
||||
else if (!KeyToggler.isOn(Input.Keys.SLASH) && uiAutosaveNotifier.isOpened) {
|
||||
println("autosave close")
|
||||
uiAutosaveNotifier.setAsClose()
|
||||
}
|
||||
|
||||
// synchronised Ingame Input Updater
|
||||
// will also queue up the block/wall/wire placed events
|
||||
@@ -949,6 +952,19 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
}
|
||||
|
||||
fun queueAutosave() {
|
||||
val start = System.nanoTime()
|
||||
|
||||
uiAutosaveNotifier.setAsOpen()
|
||||
makeSavegameBackupCopy()
|
||||
WriteSavegame.quick(savegameArchive, getSaveFileMain(), this, true) {
|
||||
uiAutosaveNotifier.setAsClose()
|
||||
|
||||
debugTimers.put("Last Autosave Duration", System.nanoTime() - start)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Double.sqr() = this * this
|
||||
fun Int.sqr() = this * this
|
||||
fun min(vararg d: Double): Double {
|
||||
|
||||
Reference in New Issue
Block a user