new world via teleporter wip

This commit is contained in:
minjaesong
2023-07-02 18:54:04 +09:00
parent afb7dff5d2
commit 9c396e7b8d
7 changed files with 136 additions and 15 deletions

View File

@@ -640,7 +640,6 @@ public class App implements ApplicationListener {
// process screenshot request
if (screenshotRequested) {
FrameBufferManager.begin(postProcessorOutFBO);
screenshotRequested = false;
try {
Pixmap p = Pixmap.createFromFrameBuffer(0, 0, scr.getWidth(), scr.getHeight());
PixmapIO.writePNG(Gdx.files.absolute(defaultDir+"/Screenshot-"+String.valueOf(System.currentTimeMillis())+".png"), p, 9, true);
@@ -652,6 +651,7 @@ public class App implements ApplicationListener {
Terrarum.INSTANCE.getIngame().sendNotification("Failed to take screenshot: "+e.getMessage());
}
FrameBufferManager.end();
screenshotRequested = false;
}

View File

@@ -409,6 +409,14 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
return uiTooltip.message
}
open fun requestForceSave(callback: () -> Unit) {
}
open fun saveTheGame(onSuccessful: () -> Unit, onError: (Throwable) -> Unit) {
}
/**
* Copies most recent `save` to `save.1`, leaving `save` for overwriting, previous `save.1` will be copied to `save.2`
*/

View File

@@ -53,6 +53,10 @@ class SavegameCollection(files0: List<DiskSkimmer>) {
}
}
}
fun getBaseFile(): DiskSkimmer {
return files.first { it.diskFile.extension.isBlank() }
}
}
class SavegameCollectionPair(player: SavegameCollection?, world: SavegameCollection?) {

View File

@@ -879,6 +879,11 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
//println("paused = $paused")
if ((!paused && !App.isScreenshotRequested()) && newWorldLoadedLatch) newWorldLoadedLatch = false
if (saveRequested != null) {
doForceSave(saveRequested!!)
saveRequested = null
}
}
@@ -915,6 +920,53 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
)
}
private var saveRequested: (() -> Unit)? = null
override fun requestForceSave(callback: () -> Unit) {
saveRequested = callback
}
internal fun doForceSave(callback: () -> Unit) {
// TODO show appropriate UI
saveTheGame({ // onSuccessful
System.gc()
autosaveTimer = 0f
// TODO hide appropriate UI
callback()
}, { // onError
// TODO show failure message
// TODO hide appropriate UI
})
}
override fun saveTheGame(onSuccessful: () -> Unit, onError: (Throwable) -> Unit) {
val saveTime_t = App.getTIME_T()
val playerSavefile = getPlayerSaveFiledesc(INGAME.playerSavefileName)
val worldSavefile = getWorldSaveFiledesc(INGAME.worldSavefileName)
INGAME.makeSavegameBackupCopy(playerSavefile)
WriteSavegame(saveTime_t, WriteSavegame.SaveMode.PLAYER, INGAME.playerDisk, playerSavefile, INGAME as TerrarumIngame, false, onError) {
INGAME.makeSavegameBackupCopy(worldSavefile)
WriteSavegame(saveTime_t, WriteSavegame.SaveMode.WORLD, INGAME.worldDisk, worldSavefile, INGAME as TerrarumIngame, false, onError) {
// callback:
// rebuild the disk skimmers
INGAME.actorContainerActive.filterIsInstance<IngamePlayer>().forEach {
printdbg(this, "Game Save callback -- rebuilding the disk skimmer for IngamePlayer ${it.actorValue.getAsString(AVKey.NAME)}")
// it.rebuildingDiskSkimmer?.rebuild()
}
// return to normal state
onSuccessful()
}
}
}
private val maxRenderableWires = ReferencingRanges.ACTORS_WIRES.last - ReferencingRanges.ACTORS_WIRES.first + 1
private val wireActorsContainer = Array(maxRenderableWires) { WireActor(ReferencingRanges.ACTORS_WIRES.first + it).let {
forceAddActor(it)

View File

@@ -1,14 +1,25 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.random.XXHash64
import net.torvald.terrarum.App
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.WireCodex
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.WorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory.Companion.CAPACITY_MODE_WEIGHT
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame
import net.torvald.terrarum.modulebasegame.serialise.ReadActor
import net.torvald.terrarum.modulebasegame.ui.UILoadGovernor
import net.torvald.terrarum.modulebasegame.ui.UIWorldPortal
import net.torvald.terrarum.savegame.ByteArray64Reader
import net.torvald.terrarum.savegame.DiskSkimmer
import net.torvald.terrarum.savegame.VDFileID
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.dyn4j.geometry.Vector2
import java.util.HashMap
@@ -55,7 +66,48 @@ class FixtureWorldPortal : Electric {
}
override fun onRisingEdge(readFrom: BlockBoxIndex) {
println("[FixtureWorldPortal] teleport! $teleportRequest")
printdbg(this, "teleport! $teleportRequest")
teleportRequest?.let {
if (it.worldDiskToLoad != null && it.worldLoadParam != null) {
throw InternalError("Contradiction -- worldDiskToLoad and worldLoadParam are both not null: $teleportRequest")
}
val player = INGAME.actorGamer
// load existing
val jobAfterSave: () -> Unit
if (it.worldDiskToLoad != null) {
UILoadGovernor.worldDisk = it.worldDiskToLoad
UILoadGovernor.playerDisk = App.savegamePlayers[player.uuid]!!.getBaseFile()
jobAfterSave = {
LoadSavegame(UILoadGovernor.worldDisk!!, UILoadGovernor.playerDisk)
}
}
// create new
else {
jobAfterSave = {
val wx = it.worldLoadParam!!.width
val wy = it.worldLoadParam!!.height
val seed = it.worldLoadParam!!.worldGenSeed
val name = it.worldLoadParam!!.savegameName
printdbg(this, "generate for teleportation! Size=${wx}x${wy}, Name=$name, Seed=$seed")
val ingame = TerrarumIngame(App.batch)
val worldParam = TerrarumIngame.NewGameParams(player, it.worldLoadParam)
ingame.gameLoadInfoPayload = worldParam
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
Terrarum.setCurrentIngameInstance(ingame)
val loadScreen = WorldgenLoadScreen(ingame, wx, wy)
App.setLoadScreen(loadScreen)
}
}
INGAME.requestForceSave(jobAfterSave)
teleportRequest = null
}
}
override fun reload() {

View File

@@ -105,11 +105,19 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
full.unlockTransition()
}
val saveTime_t = App.getTIME_T()
val onSuccessful = {
// return to normal state
System.gc()
screen = 0
full.handler.unlockToggle()
full.unlockTransition()
(INGAME as TerrarumIngame).autosaveTimer = 0f
}
/*val saveTime_t = App.getTIME_T()
val playerSavefile = getPlayerSaveFiledesc(INGAME.playerSavefileName)
val worldSavefile = getWorldSaveFiledesc(INGAME.worldSavefileName)
INGAME.makeSavegameBackupCopy(playerSavefile)
WriteSavegame(saveTime_t, WriteSavegame.SaveMode.PLAYER, INGAME.playerDisk, playerSavefile, INGAME as TerrarumIngame, false, onError) {
@@ -123,13 +131,12 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
}
// return to normal state
System.gc()
screen = 0
full.handler.unlockToggle()
full.unlockTransition()
(INGAME as TerrarumIngame).autosaveTimer = 0f
onSuccessful()
}
}
}*/
INGAME.saveTheGame(onSuccessful, onError)
}
1 -> {

View File

@@ -7,11 +7,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.random.HQRNG
import net.torvald.random.XXHash64
import net.torvald.terrarum.App
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.TerrarumIngame.Companion.NEW_WORLD_SIZE
@@ -91,6 +88,7 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
private val backButton = UIItemTextButton(this, "MENU_LABEL_BACK", drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
private val goButton = UIItemTextButton(this, "MENU_LABEL_CONFIRM_BUTTON", drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
init {
goButton.clickOnceListener = { _, _ ->