bringing back old animating titlescreen

This commit is contained in:
minjaesong
2021-09-08 16:22:25 +09:00
parent 7c38e9a7fd
commit b8e181915e
16 changed files with 157 additions and 108 deletions

File diff suppressed because one or more lines are too long

View File

@@ -72,7 +72,7 @@ public class AppLoader implements ApplicationListener {
/**
* when FALSE, some assertion and print code will not execute
*/
public static boolean IS_DEVELOPMENT_BUILD = false;
public static boolean IS_DEVELOPMENT_BUILD = true;
/**
@@ -277,6 +277,11 @@ public class AppLoader implements ApplicationListener {
};
public static void main(String[] args) {
// print copyright message
System.out.println(csiB+GAME_NAME+" "+csiG+getVERSION_STRING()+" "+csiK+"\u2014"+" "+csi0+TerrarumAppConfiguration.COPYRIGHT_DATE_NAME);
System.out.println(csiG+TerrarumAppConfiguration.COPYRIGHT_LICENSE_TERMS_SHORT+csi0);
// load configs
getDefaultDirectory();
createDirs();
@@ -925,7 +930,8 @@ public class AppLoader implements ApplicationListener {
defaultDir = System.getProperty("user.home") + "/.Terrarum";
}
defaultSaveDir = defaultDir + "/Saves";
// defaultSaveDir = defaultDir + "/Players"; // as per the save format in the game's planning
defaultSaveDir = defaultDir + "/Saves"; // for the demo release
configDir = defaultDir + "/config.json";
System.out.println(String.format("os.name = %s (with identifier %s)", OSName, operationSystem));
@@ -1140,6 +1146,9 @@ public class AppLoader implements ApplicationListener {
// //
public static String csiR = "\u001B[31m";
public static String csiG = "\u001B[32m";
public static String csiB = "\u001B[34m";
public static String csiK = "\u001B[37m";
public static String csi0 = "\u001B[m";
public static void printdbg(Object obj, Object message) {
@@ -1148,7 +1157,7 @@ public class AppLoader implements ApplicationListener {
if (message == null)
System.out.println("[" + out + "] null");
else
System.out.println("[" + out + "] " + message.toString());
System.out.println("[" + out + "] " + message);
}
}
@@ -1158,7 +1167,7 @@ public class AppLoader implements ApplicationListener {
if (message == null)
System.out.println(csiR + "[" + out + "] null" + csi0);
else
System.out.println(csiR + "[" + out + "] " + message.toString() + csi0);
System.out.println(csiR + "[" + out + "] " + message + csi0);
}
}
@@ -1167,7 +1176,7 @@ public class AppLoader implements ApplicationListener {
if (message == null)
System.out.println("[" + out + "] null");
else
System.out.println("[" + out + "] " + message.toString());
System.out.println("[" + out + "] " + message);
}
public static ShaderProgram loadShaderFromFile(String vert, String frag) {

View File

@@ -15,6 +15,20 @@ object TerrarumAppConfiguration {
const val COPYRIGHT_DATE_NAME = "Copyright 2013-2021 CuriousTorvald (minjaesong)"
val COPYRIGHT_LICENSE: String; get() = Lang["COPYRIGHT_GNU_GPL_3"]
const val COPYRIGHT_LICENSE_ENGLISH = "Distributed under GNU GPL 3"
const val COPYRIGHT_LICENSE_TERMS_SHORT = """
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
/**
*

View File

@@ -15,6 +15,7 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.console.CommandDict
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.gameworld.GameWorld
@@ -26,9 +27,15 @@ import net.torvald.terrarum.modulebasegame.gameactors.HumanoidNPC
import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.ui.UIRemoCon
import net.torvald.terrarum.modulebasegame.ui.UITitleRemoConYaml
import net.torvald.terrarum.serialise.ReadWorld
import net.torvald.terrarum.weather.WeatherMixer
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.WorldCamera
import java.io.IOException
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.roundToInt
import kotlin.math.sin
/**
* Created by minjaesong on 2017-09-02.
@@ -58,53 +65,31 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
private lateinit var demoWorld: GameWorld
private lateinit var cameraNodes: FloatArray // camera Y-pos
private val cameraAI = object : ActorAI {
private val axisMax = 1f
private var firstTime = true
override fun update(actor: Actor, delta: Float) {
val actor = actor as HumanoidNPC
val actor = actor as ActorWithBody
val ww = TILE_SIZEF * demoWorld.width
// fuck
val avSpeed = 1.0 // FIXME camera goes faster when FPS is high
actor.actorValue[AVKey.SPEED] = avSpeed
actor.actorValue[AVKey.ACCEL] = avSpeed / 6.0
// end fuck
val indexThis = ((actor.hitbox.canonicalX / ww * cameraNodes.size).floorInt()) % cameraNodes.size
val indexNext = (indexThis + 1) % cameraNodes.size
val xwstart: Float = indexThis.toFloat() / cameraNodes.size * ww
val xwend: Float = ((indexThis + 1).toFloat() / cameraNodes.size) * ww
val xw: Float = xwend - xwstart
val px: Double = (actor.hitbox.canonicalX + actor.actorValue.getAsDouble(AVKey.SPEED)!!) % ww.toDouble()
val xperc: Double = (px - xwstart) / xw
val y = FastMath.interpolateLinear(xperc.toFloat(), cameraNodes[indexThis], cameraNodes[indexNext])
val tileSize = TILE_SIZEF
val catmullRomTension = 0f
// pan camera
actor.moveRight(axisMax)
val domainSize = demoWorld.width * tileSize
val codomainSize = cameraNodes.size
val x = actor.hitbox.canonicalX.toFloat()
val p1 = (x / (domainSize / codomainSize)).floorInt() fmod cameraNodes.size
val p0 = ((p1 - 1) fmod codomainSize) fmod cameraNodes.size
val p2 = ((p1 + 1) fmod codomainSize) fmod cameraNodes.size
val p3 = ((p1 + 2) fmod codomainSize) fmod cameraNodes.size
val u: Float = 1f - (p2 - (x / (domainSize / codomainSize))) / (p2 - p1)
//val targetYPos = FastMath.interpolateCatmullRom(u, catmullRomTension, cameraNodes[p0], cameraNodes[p1], cameraNodes[p2], cameraNodes[p3])
val targetYPos = FastMath.interpolateLinear(u, cameraNodes[p1], cameraNodes[p2])
val yDiff = targetYPos - actor.hitbox.canonicalY
/*if (!firstTime) {
actor.moveDown(yDiff.bipolarClamp(axisMax.toDouble()).toFloat())
if (firstTime) {
firstTime = false
actor.hitbox.setPositionY(y - 8.0)
}
else {
actor.hitbox.setPosition(actor.hitbox.canonicalX, targetYPos.toDouble())
firstTime = false
}*/
actor.hitbox.setPosition(actor.hitbox.canonicalX, targetYPos.toDouble()) // just move the cameraY to interpolated path
//println("${actor.hitbox.canonicalX}, ${actor.hitbox.canonicalY}")
(actor as CameraPlayer).moveTo(px, y - 8.0)
}
}
}
private lateinit var cameraPlayer: ActorWithBody
@@ -122,28 +107,51 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
printdbg(this, "Intro pre-load")
demoWorld = GameWorld(1, 64, 64, 0L, 0L, 0)
try {
val reader = java.io.FileReader(ModMgr.getFile("basegame", "demoworld"))
//ReadWorld.readWorldAndSetNewWorld(Terrarum.ingame!! as TerrarumIngame, reader)
val world = ReadWorld.invoke(reader)
demoWorld = world
printdbg(this, "Demo world loaded")
}
catch (e: IOException) {
demoWorld = GameWorld(1, 64, 64, 0L, 0L, 0)
printdbg(this, "Demo world not found, using empty world")
}
printdbg(this, "Demo world gen complete")
// set time to summer
demoWorld.worldTime.addTime(WorldTime.DAY_LENGTH * 32)
// construct camera nodes
val nodeCount = 100
cameraNodes = kotlin.FloatArray(nodeCount) { it ->
val nodeCount = 400
cameraNodes = kotlin.FloatArray(nodeCount) {
val tileXPos = (demoWorld.width.toFloat() * it / nodeCount).floorInt()
var travelDownCounter = 0
while (travelDownCounter < demoWorld.height && !BlockCodex[demoWorld.getTileFromTerrain(tileXPos, travelDownCounter)].isSolid) {
travelDownCounter += 4
travelDownCounter += 1
}
// println("Camera node #${it+1} = $travelDownCounter")
travelDownCounter * TILE_SIZEF
}
// apply gaussian blur to the camera nodes
for (i in cameraNodes.indices) {
val offM3 = cameraNodes[(i-3) fmod cameraNodes.size] * 0.025f
val offM2 = cameraNodes[(i-2) fmod cameraNodes.size] * 0.11f
val offM1 = cameraNodes[(i-1) fmod cameraNodes.size] * 0.29f
val off0 = cameraNodes[i] * 0.15f
val off1 = cameraNodes[(i+1) fmod cameraNodes.size] * 0.29f
val off2 = cameraNodes[(i+2) fmod cameraNodes.size] * 0.11f
val off3 = cameraNodes[(i+3) fmod cameraNodes.size] * 0.025f
cameraNodes[i] = offM3 + offM2 + offM1 + off0 + off1 + off2 + off3
}
cameraPlayer = CameraPlayer(demoWorld, cameraAI)
demoWorld.worldTime.timeDelta = 150
demoWorld.worldTime.timeDelta = 0//150
IngameRenderer.setRenderedWorld(demoWorld)
@@ -239,7 +247,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
if (!demoWorld.layerTerrain.ptr.destroyed) { // FIXME q&d hack to circumvent the dangling pointer issue #26
IngameRenderer.invoke(gamePaused = true, uiContainer = uiContainer)
IngameRenderer.invoke(gamePaused = false, uiContainer = uiContainer)
}
else {
printdbgerr(this, "Demoworld is already been destroyed")
@@ -365,6 +373,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
override val hitbox = Hitbox(0.0, 0.0, 2.0, 2.0)
init {
actorValue[AVKey.SPEED] = 3.0
hitbox.setPosition(
HQRNG().nextInt(demoWorld.width) * TILE_SIZED,
0.0 // Y pos: placeholder; camera AI will take it over
@@ -375,7 +384,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
override fun drawGlow(batch: SpriteBatch) { }
override fun update(delta: Float) {
ai.update(this, delta)
}
override fun onActorValueChange(key: String, value: Any?) { }
@@ -404,11 +413,21 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
}
override fun moveTo(bearing: Double) {
TODO("not implemented")
println(bearing)
val v = actorValue.getAsDouble(AVKey.SPEED)!!
hitbox.translate(v * cos(bearing), v * sin(bearing))
}
override fun moveTo(toX: Double, toY: Double) {
TODO("not implemented")
val ww = TILE_SIZED * demoWorld.width
// select appropriate toX because ROUNDWORLD
val xdiff1 = toX - hitbox.canonicalX
val xdiff2 = (toX + ww) - hitbox.canonicalX
val xdiff = if (xdiff1 < 0) xdiff2 else xdiff1
val ydiff = toY - hitbox.canonicalY
moveTo(atan2(ydiff, xdiff))
hitbox.setPositionX(hitbox.canonicalX % ww)
}
}

View File

@@ -1,14 +0,0 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.modulebasegame.IngameRenderer
object ExportRendererFboRGB: ConsoleCommand {
override fun execute(args: Array<String>) {
IngameRenderer.fboRGBexportRequested = true
}
override fun printUsage() {
}
}

View File

@@ -0,0 +1,20 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.ccG
import net.torvald.terrarum.modulebasegame.IngameRenderer
object ScreencapNogui: ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
IngameRenderer.fboRGBexportPath = AppLoader.defaultDir + "/Exports/${args[1]}.tga"
IngameRenderer.fboRGBexportRequested = true
Echo("FBO exported to$ccG Exports/${args[1]}.tga")
}
}
override fun printUsage() {
}
}

View File

@@ -330,6 +330,21 @@ object IngameRenderer : Disposable {
blendNormal(batch)
///////////////////////////////////////////////////////////////////////
if (fboRGBexportRequested) {
fboRGBexportRequested = false
try {
val w = 960
val h = 640
val p = Pixmap.createFromFrameBuffer((fboRGB.width - w).ushr(1), (fboRGB.height - h).ushr(1), w, h)
PixmapIO2.writeTGA(Gdx.files.absolute(fboRGBexportPath), p, true)
p.dispose()
}
catch (e: Throwable) {
e.printStackTrace()
}
}
///////////////////////////////////////////////////////////////////////
@@ -368,6 +383,7 @@ object IngameRenderer : Disposable {
}
internal var fboRGBexportRequested = false
internal var fboRGBexportPath = ""
private fun drawToRGB(
actorsRenderBehind: List<ActorWithBody>?,
@@ -418,25 +434,6 @@ object IngameRenderer : Disposable {
}
}
if (fboRGBexportRequested) {
fboRGBexportRequested = false
val fileChooser = JFileChooser()
fileChooser.showSaveDialog(null)
try {
if (fileChooser.selectedFile != null) {
fboRGB.inAction(null, null) {
val p = ScreenUtils.getFrameBufferPixmap(0, 0, fboRGB.width, fboRGB.height)
PixmapIO2.writeTGA(Gdx.files.absolute(fileChooser.selectedFile.absolutePath), p, false)
p.dispose()
}
}
}
catch (e: Throwable) {
e.printStackTrace()
}
}
fboRGB_lightMixed.inAction(camera, batch) {
setCameraPosition(0f, 0f)

View File

@@ -10,8 +10,6 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
*/
internal object SetTimeDelta : ConsoleCommand {
val HARD_LIMIT = 60
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as TerrarumIngame).world

View File

@@ -45,12 +45,12 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
// TODO scrolling of the palette, as the old method flat out won't work with The Flattening
private val tabs = UIItemTextButtonList(
this, arrayOf("Terrain", "Wall", "Wire"),
this, 36, arrayOf("Terrain", "Wall", "Wire"),
0, 0, textAreaWidth = MENUBAR_SIZE, width = MENUBAR_SIZE,
defaultSelection = 0
)
private val closeButton = UIItemTextButtonList(
this, arrayOf("Close"),
this, 36, arrayOf("Close"),
0, this.height - UIItemTextButtonList.DEFAULT_LINE_HEIGHT,
width = MENUBAR_SIZE, textAreaWidth = MENUBAR_SIZE
)

View File

@@ -23,7 +23,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
private val gameMenuListHeight = DEFAULT_LINE_HEIGHT * gameMenu.size
private val gameMenuListWidth = 400
private val gameMenuButtons = UIItemTextButtonList(
this, gameMenu,
this, DEFAULT_LINE_HEIGHT, gameMenu,
(AppLoader.screenSize.screenW - gameMenuListWidth) / 2,
INVENTORY_CELLS_OFFSET_Y + (INVENTORY_CELLS_UI_HEIGHT - gameMenuListHeight) / 2,
gameMenuListWidth, gameMenuListHeight,

View File

@@ -38,12 +38,12 @@ class UIProxyNewRandomGame : UICanvas() {
val ingame = TerrarumIngame(AppLoader.batch)
val worldParam = TerrarumIngame.NewWorldParameters(2400, 1280, 0x51621DL)
//val worldParam = TerrarumIngame.NewWorldParameters(2400, 1280, HQRNG().nextLong())
// val worldParam = TerrarumIngame.NewWorldParameters(2400, 1280, 0x51621DL)
val worldParam = TerrarumIngame.NewWorldParameters(2400, 1280, HQRNG().nextLong())
//val worldParam = TerrarumIngame.NewWorldParameters(6000, 1800, 0x51621DL) // small
// val worldParam = TerrarumIngame.NewWorldParameters(9000, 2250, 0x51621DL) // normal
//val worldParam = TerrarumIngame.NewWorldParameters(13500, 3000, 0x51621DL) // large
//val worldParam = TerrarumIngame.NewWorldParDoubleameters(13500, 3000, 0x51621DL) // large
//val worldParam = TerrarumIngame.NewWorldParameters(22500, 4500, 0x51621DL) // huge
ingame.gameLoadInfoPayload = worldParam
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW

View File

@@ -248,11 +248,14 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
class UIRemoConElement(uiRemoCon: UIRemoCon, val labels: Array<String>) {
private val lineHeight = 36
private val menubar = UIItemTextButtonList(
uiRemoCon,
lineHeight,
labels,
0, menubarOffY,
menubarOffX,
menubarOffY - lineHeight * labels.size + 16,
uiRemoCon.width, getRemoConHeight(labels),
textAreaWidth = uiRemoCon.width,
readFromLang = true,
@@ -261,7 +264,8 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null,
itemHitboxSize = 34
itemHitboxSize = lineHeight - 2,
alignment = UIItemTextButton.Companion.Alignment.LEFT
)
fun update(delta: Float) {
@@ -288,9 +292,10 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
}
companion object {
val remoConWidth = 304
val remoConWidth = 300
fun getRemoConHeight(menu: ArrayList<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
fun getRemoConHeight(menu: Array<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
val menubarOffY: Int; get() = AppLoader.screenSize.screenH / 2 - (AppLoader.fontGame.lineHeight * 1.5).toInt()
val menubarOffX: Int; get() = (0.11 * AppLoader.screenSize.screenW).toInt()
val menubarOffY: Int; get() = (0.82 * AppLoader.screenSize.screenH).toInt()
}
}

View File

@@ -25,6 +25,7 @@ class UITitleLanguage : UICanvas() {
private val localeList = Lang.languageList.toList().sorted()
private val textArea = UIItemTextButtonList(this,
24,
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
AppLoader.screenSize.screenW - width, textAreaHMargin,
width, height,

View File

@@ -13,12 +13,9 @@ object UITitleRemoConYaml {
* The class must be the UICanvas
*/
val menus = """
- MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UITitleCharactersList
- CONTEXT_CHARACTER_NEW
- CONTEXT_CHARACTER_DELETE
- MENU_LABEL_RETURN
- MENU_MODE_MULTIPLAYER
- MENU_LABEL_RETURN
- MENU_LABEL_CONTINUE
- MENU_LABEL_NEW_GAME : net.torvald.terrarum.modulebasegame.ui.UIProxyNewRandomGame
- MENU_IO_LOAD
- MENU_OPTIONS
- MENU_OPTIONS_GRAPHICS
- MENU_OPTIONS_CONTROLS
@@ -38,12 +35,12 @@ object UITitleRemoConYaml {
- MENU_LABEL_QUIT
""".trimIndent()
val debugTools = """
val debugTools = "" /*"""
- Development Tools $
- Building Maker : net.torvald.terrarum.modulebasegame.ui.UIProxyNewBuildingMaker
- Start New Random Game : net.torvald.terrarum.modulebasegame.ui.UIProxyNewRandomGame
- MENU_LABEL_RETURN
""".trimIndent()
""".trimIndent()*/
operator fun invoke() = if (AppLoader.IS_DEVELOPMENT_BUILD)
Yaml(menus + "\n" + debugTools).parse()

View File

@@ -12,11 +12,12 @@ import kotlin.math.roundToInt
*/
class UIItemTextButtonList(
parentUI: UICanvas,
val lineHeight: Int,
labelsList: Array<String>,
initialX: Int,
initialY: Int,
override var width: Int,
override var height: Int = DEFAULT_LINE_HEIGHT * labelsList.size,
override var height: Int = lineHeight * labelsList.size,
val readFromLang: Boolean = false,
val defaultSelection: Int? = null, // negative: INVALID, positive: valid, null: no select
@@ -48,7 +49,7 @@ class UIItemTextButtonList(
val kinematic: Boolean = false,
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE,
val itemHitboxSize: Int = DEFAULT_LINE_HEIGHT
val itemHitboxSize: Int = lineHeight
) : UIItem(parentUI, initialX, initialY) {
companion object {
@@ -75,7 +76,7 @@ class UIItemTextButtonList(
val h = height.toFloat()
val ss = labelsList.size.toFloat()
val lh = itemHitboxSize
val vertOff = (h/ss * i + (h/ss - lh) / 2f).roundToInt()
val vertOff = lineHeight * i
if (!kinematic) {
UIItemTextButton(

View File

@@ -99,6 +99,7 @@ class UINSMenu(
val list = UIItemTextButtonList(
this,
UIItemTextButtonList.DEFAULT_LINE_HEIGHT,
stringsFromTree,
width, LINE_HEIGHT,
uiWidth, listHeight,