From c4b64140be5164ea357d6634d81bf424312eae24 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Sun, 24 Apr 2016 16:37:08 +0900 Subject: [PATCH] actors are now active/dormant depending on the distance to the player, only the active actors are to be updated. Actors outside of the camera (actually a distance to the player) are not rendered Former-commit-id: 5f80c2ef3592aab5567723087c264e05458e98b3 Former-commit-id: 7714c6f5a6d7a48d4f5adfe8f6990b249bdb80b0 --- src/net/torvald/imagefont/GameFontBase.kt | 55 +++++--- src/net/torvald/terrarum/Game.kt | 50 ++++---- src/net/torvald/terrarum/Terrarum.kt | 12 ++ .../torvald/terrarum/console/CodexEdictis.kt | 2 +- .../torvald/terrarum/console/CommandDict.kt | 1 + .../terrarum/console/CommandInterpreter.kt | 26 +++- src/net/torvald/terrarum/console/GetAV.kt | 83 ++++++++---- .../torvald/terrarum/console/GetFactioning.kt | 118 ++++++++++++++---- src/net/torvald/terrarum/console/SetAV.kt | 41 +++--- src/net/torvald/terrarum/console/Version.kt | 16 +++ src/net/torvald/terrarum/gameactors/Actor.kt | 2 +- .../terrarum/gameactors/CollisionSolver.kt | 2 +- .../terrarum/itemproperties/ItemPropCodex.kt | 6 +- .../terrarum/mapdrawer/LightmapRenderer.kt | 33 ++--- .../terrarum/ui/BasicDebugInfoWindow.kt | 28 ++--- src/net/torvald/terrarum/ui/ConsoleWindow.kt | 3 +- 16 files changed, 332 insertions(+), 146 deletions(-) create mode 100644 src/net/torvald/terrarum/console/Version.kt diff --git a/src/net/torvald/imagefont/GameFontBase.kt b/src/net/torvald/imagefont/GameFontBase.kt index 1b6b0a627..765c39aeb 100644 --- a/src/net/torvald/imagefont/GameFontBase.kt +++ b/src/net/torvald/imagefont/GameFontBase.kt @@ -586,28 +586,47 @@ constructor() : Font { internal var interchar = 0 val colourKey = hashMapOf( - Pair(0x11.toChar(), Color(0xFFFFFF)), //w - Pair(0x12.toChar(), Color(0xFF8080)), //r - Pair(0x13.toChar(), Color(0x80FF80)), //g - Pair(0x14.toChar(), Color(0x8080FF)), //b - Pair(0x15.toChar(), Color(0xFFE080)), //y - Pair(0x16.toChar(), Color(0x808080)) //k + Pair(0x10.toChar(), Color(0xFFFFFF)), //*w hite + Pair(0x11.toChar(), Color(0xFFE080)), //*y ellow + Pair(0x12.toChar(), Color(0xFFB020)), //o range + Pair(0x13.toChar(), Color(0xFF8080)), //*r ed + Pair(0x14.toChar(), Color(0xFFA0E0)), //f uchsia + Pair(0x15.toChar(), Color(0xE0A0FF)), //*m agenta (purple) + Pair(0x16.toChar(), Color(0x8080FF)), //*b lue + Pair(0x17.toChar(), Color(0xFF80FF)), //c yan + Pair(0x18.toChar(), Color(0x80FF80)), //*g reen + Pair(0x19.toChar(), Color(0x008000)), //v iridian + Pair(0x1A.toChar(), Color(0x805030)), //x (khaki) + Pair(0x1B.toChar(), Color(0x808080)) //*k + //* marked: commonly used ) val colToCode = hashMapOf( - Pair("w", 0x11.toChar()), - Pair("r", 0x12.toChar()), - Pair("g", 0x13.toChar()), - Pair("b", 0x14.toChar()), - Pair("y", 0x15.toChar()), - Pair("k", 0x16.toChar()) + Pair("w", 0x10.toChar()), + Pair("y", 0x11.toChar()), + Pair("o", 0x12.toChar()), + Pair("r", 0x13.toChar()), + Pair("f", 0x14.toChar()), + Pair("m", 0x15.toChar()), + Pair("b", 0x16.toChar()), + Pair("c", 0x17.toChar()), + Pair("g", 0x18.toChar()), + Pair("v", 0x19.toChar()), + Pair("x", 0x1A.toChar()), + Pair("k", 0x1B.toChar()) ) val codeToCol = hashMapOf( - Pair("w", colourKey[0x11.toChar()]), - Pair("r", colourKey[0x12.toChar()]), - Pair("g", colourKey[0x13.toChar()]), - Pair("b", colourKey[0x14.toChar()]), - Pair("y", colourKey[0x15.toChar()]), - Pair("k", colourKey[0x16.toChar()]) + Pair("w", colourKey[0x10.toChar()]), + Pair("y", colourKey[0x11.toChar()]), + Pair("o", colourKey[0x12.toChar()]), + Pair("r", colourKey[0x13.toChar()]), + Pair("f", colourKey[0x14.toChar()]), + Pair("m", colourKey[0x15.toChar()]), + Pair("b", colourKey[0x16.toChar()]), + Pair("c", colourKey[0x17.toChar()]), + Pair("g", colourKey[0x18.toChar()]), + Pair("v", colourKey[0x19.toChar()]), + Pair("x", colourKey[0x1A.toChar()]), + Pair("k", colourKey[0x1B.toChar()]) ) } } diff --git a/src/net/torvald/terrarum/Game.kt b/src/net/torvald/terrarum/Game.kt index 884c7a911..048bf1617 100644 --- a/src/net/torvald/terrarum/Game.kt +++ b/src/net/torvald/terrarum/Game.kt @@ -43,8 +43,9 @@ constructor() : BasicGameState() { /** * Linked list of Actors that is sorted by Actors' referenceID */ - val actorContainer = ArrayList(128) - val actorcontainerInactive = ArrayList(128) + val ACTORCONTAINER_INITIAL_SIZE = 128 + val actorContainer = ArrayList(ACTORCONTAINER_INITIAL_SIZE) + val actorContainerInactive = ArrayList(ACTORCONTAINER_INITIAL_SIZE) val uiContainer = LinkedList() lateinit var consoleHandler: UIHandler @@ -144,22 +145,32 @@ constructor() : BasicGameState() { MapDrawer.update(gc, delta) MapCamera.update(gc, delta) - actorContainer.forEach { actor -> // update actors - if (actor !is Visible - || actor is Visible && distToActorSqr(actor, player) < ACTOR_UPDATE_RANGE.sqr()) - // update if the does not have specific position. (visible) - // if the actor has position (visible), update only if it is within the range - actor.update(gc, delta) - } - actorContainer.forEach { actor -> // update sprite(s) - if (actor is Visible && - distToActorSqr(actor, player) <= (Terrarum.WIDTH.plus(actor.hitbox.width.div(2)).sqr() + - Terrarum.HEIGHT.plus(actor.hitbox.height.div(2)).sqr()) - ) { // if visible and within screen - actor.updateBodySprite(gc, delta) - actor.updateGlowSprite(gc, delta) + // determine whether the inactive actor should be re-active + actorContainerInactive.forEach { actor -> + if (actor is Visible && distToActorSqr(actor, player) <= ACTOR_UPDATE_RANGE.sqr()) { + addActor(actor) } } + actorContainer.forEach { if (actorContainerInactive.contains(it)) + actorContainerInactive.remove(it) + } + + actorContainer.forEach { actor -> // update actors + // determine whether the actor should be active by their distance from the player + // will put inactive actors to list specifically for them + if (actor is Visible && distToActorSqr(actor, player) > ACTOR_UPDATE_RANGE.sqr()) { + actorContainerInactive.add(actor) + } + else { + // update our remaining active actors + actor.update(gc, delta) + if (actor is Visible) { + actor.updateBodySprite(gc, delta) + actor.updateGlowSprite(gc, delta) + } + } + } + actorContainerInactive.forEach { removeActor(it.referenceID) } uiContainer.forEach { ui -> ui.update(gc, delta) } consoleHandler.update(gc, delta) @@ -244,13 +255,6 @@ constructor() : BasicGameState() { actor.hitbox.posX, actor.hitbox.pointedY + 4 ) - g.color = Color(0x80FF80) - g.drawString( - i.toString(), - actor.hitbox.posX, - actor.hitbox.pointedY + 12 - ) - g.font = Terrarum.gameFont } } } diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index be53c4e9e..5cf599252 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -355,6 +355,18 @@ constructor(gamename: String) : StateBasedGame(gamename) { } } +/** + * 0xAA_BB_XXXX + * AA: Major version + * BB: Minor version + * XXXX: Revision + * + * e.g. 0x02010034 can be translated as 2.1.52 + */ +const val VERSION_RAW = 0x00024000 +const val VERSION_STRING: String = + "${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}" + fun main(args: Array) = Terrarum.main(args) fun setBlendMul() { diff --git a/src/net/torvald/terrarum/console/CodexEdictis.kt b/src/net/torvald/terrarum/console/CodexEdictis.kt index e3d3a4b41..cc8227429 100644 --- a/src/net/torvald/terrarum/console/CodexEdictis.kt +++ b/src/net/torvald/terrarum/console/CodexEdictis.kt @@ -39,7 +39,7 @@ class CodexEdictis : ConsoleCommand { private fun printList() { val echo = Echo() echo.execute(Lang.get("DEV_MESSAGE_CONSOLE_AVAILABLE_COMMANDS")) - CommandDict.dict.keys.forEach { s -> echo.execute("] " + s) } + CommandDict.dict.keys.forEach { s -> echo.execute("• " + s) } } } diff --git a/src/net/torvald/terrarum/console/CommandDict.kt b/src/net/torvald/terrarum/console/CommandDict.kt index 9a8f4bc5f..f59005452 100644 --- a/src/net/torvald/terrarum/console/CommandDict.kt +++ b/src/net/torvald/terrarum/console/CommandDict.kt @@ -35,6 +35,7 @@ object CommandDict { Pair("gettime", GetTime()), Pair("settimedelta", SetTimeDelta()), Pair("help", Help()), + Pair("version", Version()), // Test codes Pair("bulletintest", SetBulletin()), diff --git a/src/net/torvald/terrarum/console/CommandInterpreter.kt b/src/net/torvald/terrarum/console/CommandInterpreter.kt index e0c777301..8fc0143ba 100644 --- a/src/net/torvald/terrarum/console/CommandInterpreter.kt +++ b/src/net/torvald/terrarum/console/CommandInterpreter.kt @@ -1,7 +1,10 @@ package net.torvald.terrarum.console +import net.torvald.imagefont.GameFontBase import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.Terrarum +import java.time.LocalDateTime +import java.time.ZonedDateTime import java.util.ArrayList import java.util.Formatter @@ -14,8 +17,14 @@ object CommandInterpreter { private val commandsNoAuth = arrayOf("auth", "qqq", "zoom", "setlocale", "getlocale", "help") + private val ccW = GameFontBase.colToCode["w"] + private val ccG = GameFontBase.colToCode["g"] + private val ccY = GameFontBase.colToCode["y"] + private val ccR = GameFontBase.colToCode["r"] + fun execute(command: String) { - val cmd = parse(command) + val cmd: Array = parse(command) + val echo = Echo() for (single_command in cmd) { var commandObj: ConsoleCommand? = null @@ -38,6 +47,8 @@ object CommandInterpreter { } finally { + echo.execute("$ccW> $single_command") // prints out the input + println("${ZonedDateTime.now()} [CommandInterpreter] issuing command '$single_command'") try { if (commandObj != null) { commandObj.execute(single_command!!.toStringArray()) @@ -50,7 +61,7 @@ object CommandInterpreter { catch (e: Exception) { System.err.print("[CommandInterpreter] ") e.printStackTrace() - Echo().error(Lang["ERROR_GENERIC_TEXT"]) + echo.error(Lang["ERROR_GENERIC_TEXT"]) } } @@ -112,5 +123,16 @@ object CommandInterpreter { val argsCount: Int get() = tokens.size + + override fun toString(): String { + val sb = StringBuilder() + tokens.forEachIndexed { i, s -> + if (i == 0) + sb.append("${ccY}$s${ccG}") + else + sb.append(" $s") + } + return sb.toString() + } } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/console/GetAV.kt b/src/net/torvald/terrarum/console/GetAV.kt index 88e207bd4..feff930b4 100644 --- a/src/net/torvald/terrarum/console/GetAV.kt +++ b/src/net/torvald/terrarum/console/GetAV.kt @@ -1,13 +1,21 @@ package net.torvald.terrarum.console -import net.torvald.terrarum.gameactors.ActorValue -import net.torvald.terrarum.Game +import com.sun.javaws.exceptions.InvalidArgumentException +import net.torvald.imagefont.GameFontBase import net.torvald.terrarum.Terrarum /** * Created by minjaesong on 16-01-19. */ class GetAV : ConsoleCommand { + + val ccW = GameFontBase.colToCode["w"] + val ccG = GameFontBase.colToCode["g"] + val ccY = GameFontBase.colToCode["y"] + val ccM = GameFontBase.colToCode["m"] + val ccK = GameFontBase.colToCode["k"] + val ccO = GameFontBase.colToCode["o"] + override fun execute(args: Array) { val echo = Echo() @@ -17,8 +25,12 @@ class GetAV : ConsoleCommand { val av = Terrarum.game.player.actorValue val keyset = av.keySet - echo.execute("== ActorValue list for player ==") - keyset.forEach { elem -> echo.execute("$elem = ${av[elem as String]}") } + echo.execute("$ccW== ActorValue list for ${ccY}player $ccW==") + println("[GetAV] == ActorValue list for 'player' ==") + keyset.forEach { elem -> + echo.execute("$ccM$elem $ccW= $ccG${av[elem as String]}") + println("[GetAV] $elem = ${av[elem]}") + } } else if (args.size != 3 && args.size != 2) { printUsage() @@ -26,50 +38,69 @@ class GetAV : ConsoleCommand { else if (args.size == 2) { // check if args[1] is number or not if (!args[1].isNum()) { // args[1] is ActorValue name - echo.execute("player.${args[1]} = " - + Terrarum.game.player.actorValue[args[1]] - + " (" - + Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName - + ")" + echo.execute("${ccW}player.$ccM${args[1]} $ccW= " + + ccG + + Terrarum.game.player.actorValue[args[1]] + + " $ccO" + + Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName + ) + println("[GetAV] player.${args[1]} = " + + Terrarum.game.player.actorValue[args[1]] + + " " + + Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName ) } - else { // args[1] is actor ID - val av = Terrarum.game.getActor(args[1].toInt()).actorValue + else { + // args[1] is actor ID + val actor = Terrarum.game.getActor(args[1].toInt()) + val av = actor.actorValue val keyset = av.keySet - echo.execute("== ActorValue list for ${args[1].toInt()} ==") - if (keyset.size == 0) - echo.execute("(nothing)") - else - keyset.forEach { elem -> echo.execute("$elem = ${av[elem as String]}") } + echo.execute("$ccW== ActorValue list for $ccY$actor $ccW==") + println("[GetAV] == ActorValue list for '$actor' ==") + if (keyset.size == 0) { + echo.execute("$ccK(nothing)") + println("[GetAV] (nothing)") + } + else { + keyset.forEach { elem -> + echo.execute("$ccM$elem $ccW= $ccG${av[elem as String]}") + println("[GetAV] $elem = ${av[elem]}") + } + } } } else if (args.size == 3) { val id = args[1].toInt() val av = args[2] - echo.execute("$id.$av = " + + echo.execute("$ccW$id.$ccM$av $ccW= $ccG" + Terrarum.game.getActor(id).actorValue[av] + - " (" + - Terrarum.game.getActor(id).actorValue[av]!!.javaClass.simpleName + - ")" + " $ccO" + + Terrarum.game.getActor(id).actorValue[av]!!.javaClass.simpleName + ) + println("id.av = " + + Terrarum.game.getActor(id).actorValue[av] + + " " + + Terrarum.game.getActor(id).actorValue[av]!!.javaClass.simpleName ) } } catch (e: NullPointerException) { if (args.size == 2) { echo.error(args[1] + ": actor value does not exist.") + System.err.println("[GetAV] ${args[1]}: actor value does not exist.") } else if (args.size == 3) { echo.error(args[2] + ": actor value does not exist.") + System.err.println("[GetAV] ${args[2]}: actor value does not exist.") } else { throw NullPointerException() } } catch (e1: IllegalArgumentException) { - if (args.size == 3) { - echo.error(args[1] + ": no actor with this ID.") - } + echo.error("${args[1]}: no actor with this ID.") + System.err.println("[GetAV] ${args[1]}: no actor with this ID.") } } @@ -86,8 +117,8 @@ class GetAV : ConsoleCommand { override fun printUsage() { val echo = Echo() - echo.execute("Get desired actor value of specific target.") - echo.execute("Usage: getav (id) ") - echo.execute("blank ID for player") + echo.execute("${ccW}Get desired ActorValue of specific target.") + echo.execute("${ccW}Usage: ${ccY}getav ${ccG}(id) ") + echo.execute("${ccW}blank ID for player") } } diff --git a/src/net/torvald/terrarum/console/GetFactioning.kt b/src/net/torvald/terrarum/console/GetFactioning.kt index 64d0f5367..a37965a58 100644 --- a/src/net/torvald/terrarum/console/GetFactioning.kt +++ b/src/net/torvald/terrarum/console/GetFactioning.kt @@ -1,47 +1,113 @@ package net.torvald.terrarum.console -import net.torvald.terrarum.gameactors.faction.Faction +import net.torvald.imagefont.GameFontBase import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.Terrarum - -import java.util.HashSet +import net.torvald.terrarum.gameactors.Actor +import net.torvald.terrarum.gameactors.Factionable +import net.torvald.terrarum.gameactors.Player /** * Created by minjaesong on 16-02-17. */ class GetFactioning : ConsoleCommand { + val ccW = GameFontBase.colToCode["w"] + val ccG = GameFontBase.colToCode["g"] + val ccY = GameFontBase.colToCode["y"] + val ccM = GameFontBase.colToCode["m"] + val ccK = GameFontBase.colToCode["k"] + val ccB = GameFontBase.colToCode["b"] - private val PRINT_INDENTATION = " --> " + private val PRINT_INDENTATION = "$ccK --> $ccW" override fun execute(args: Array) { val echo = Echo() - if (args.size == 1) { - // get all factioning data of player - val factionSet = Terrarum.game.player.faction + fun printOutFactioning(id: Int) { + val a = Terrarum.game.getActor(id) + if (a is Factionable) { + echo.execute("$ccW== Faction assignment for $ccY${if (id == Player.PLAYER_REF_ID) "player" else id.toString()} $ccW==") + println("[GetFactioning] == Faction assignment for '${if (id == Player.PLAYER_REF_ID) "player" else id.toString()}' ==") - if (factionSet.isEmpty()) { - echo.execute("The actor has empty faction set.") + // get all factioning data of player + val factionSet = a.faction + + if (factionSet.isEmpty()) { + echo.execute("The actor has empty faction set.") + println("[GetFactioning] The actor has empty faction set.") + return + } + + val count = factionSet.size + echo.execute("$ccG${count.toString()} $ccW${Lang.pluralise(" faction", count)} assigned.") + println("[GetFactioning] ${count.toString()} ${Lang.pluralise(" faction", count)} assigned.") + + for (faction in factionSet) { + echo.execute("${ccW}faction $ccM${faction.factionName}") + println("[GetFactioning] faction '${faction.factionName}'") + echo.execute("$ccY Amicable") + println("[GetFactioning] Amicable") + faction.factionAmicable.forEach { s -> + echo.execute(PRINT_INDENTATION + s) + println("[GetFactioning] --> $s") + } + + echo.execute("$ccY Explicit neutral") + println("[GetFactioning] Explicit neutral") + faction.factionNeutral.forEach { s -> + echo.execute(PRINT_INDENTATION + s) + println("[GetFactioning] --> $s") + } + + echo.execute("$ccY Hostile") + println("[GetFactioning] Hostile") + faction.factionHostile.forEach { s -> + echo.execute(PRINT_INDENTATION + s) + println("[GetFactioning] --> $s") + } + + echo.execute("$ccY Fearful") + println("[GetFactioning] Fearful") + faction.factionFearful.forEach { s -> + echo.execute(PRINT_INDENTATION + s) + println("[GetFactioning] --> $s") + } + } + } + else { + echo.error("The actor is not factionable.") + System.err.println("[GetFactioning] The actor is not factionable.") + } + } + + if (args.size == 1) { + printOutFactioning(Player.PLAYER_REF_ID) + } + else { + if (!args[1].isNum()) { + echo.error("Invalid actor ID input.") + System.err.println("[GetFactioning] Invalid actor ID input.") return } - - val count = factionSet.size - echo.execute(count.toString() + Lang.pluralise(" faction", count) + " assigned.") - - for (faction in factionSet) { - echo.execute("faction “${faction.factionName}”") - echo.execute(" Amicable") - faction.factionAmicable.forEach { s -> echo.execute(PRINT_INDENTATION + s) } - - echo.execute(" Explicit neutral") - faction.factionNeutral.forEach { s -> echo.execute(PRINT_INDENTATION + s) } - - echo.execute(" Hostile") - faction.factionHostile.forEach { s -> echo.execute(PRINT_INDENTATION + s) } - - echo.execute(" Fearful") - faction.factionFearful.forEach { s -> echo.execute(PRINT_INDENTATION + s) } + try { + val actorID = args[1].toInt() + printOutFactioning(actorID) } + catch (e: IllegalArgumentException) { + echo.error("${args[1]}: no actor with this ID.") + System.err.println("[GetFactioning] ${args[1]}: no actor with this ID.") + } + } + + } + + fun String.isNum(): Boolean { + try { + this.toInt() + return true + } + catch (e: NumberFormatException) { + return false } } diff --git a/src/net/torvald/terrarum/console/SetAV.kt b/src/net/torvald/terrarum/console/SetAV.kt index 4464a169d..4ecc7d1a8 100644 --- a/src/net/torvald/terrarum/console/SetAV.kt +++ b/src/net/torvald/terrarum/console/SetAV.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.console +import net.torvald.imagefont.GameFontBase import net.torvald.terrarum.Game import net.torvald.terrarum.Terrarum @@ -8,18 +9,23 @@ import net.torvald.terrarum.Terrarum */ internal class SetAV : ConsoleCommand { + val ccW = GameFontBase.colToCode["w"] + val ccG = GameFontBase.colToCode["g"] + val ccY = GameFontBase.colToCode["y"] + val ccR = GameFontBase.colToCode["r"] + val ccM = GameFontBase.colToCode["m"] + override fun printUsage() { val echo = Echo() - echo.execute("Set actor value of specific target to desired value.") - echo.execute("Usage: setav (id) ") - echo.execute("blank ID for player") - echo.execute("Contaminated (float -> string) actor value will crash the game,") - echo.execute(" so make it sure before you issue the command.") - echo.execute("Use '__true' and '__false' for boolean value.") + echo.execute("${ccW}Set actor value of specific target to desired value.") + echo.execute("${ccW}Usage: ${ccY}setav ${ccG}(id) ") + echo.execute("${ccW}blank ID for player") + echo.execute("${ccR}Contaminated (float -> string) ActorValue will crash the game,") + echo.execute("${ccR}so make sure it will not happen before you issue the command!") + echo.execute("${ccW}Use ${ccG}__true ${ccW}and ${ccG}__false ${ccW}for boolean value.") } override fun execute(args: Array) { - fun parseAVInput(arg: String): Any { val `val`: Any @@ -58,30 +64,37 @@ internal class SetAV : ConsoleCommand { // check if av is number if (args[1].isNum()) { - echo.error("Illegal ActorValue “${args[1]}”: ActorValue cannot be a number.") + echo.error("Illegal ActorValue ${args[1]}: ActorValue cannot be a number.") + System.err.println("[SetAV] Illegal ActorValue ${args[1]}: ActorValue cannot be a number.") return } Terrarum.game.player.actorValue[args[1]] = `val` - echo.execute("Set ${args[1]} to $`val`") + echo.execute("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$`val`") + println("[SetAV] set ActorValue '${args[1]}' for player to '$`val`'.") } else if (args.size == 4) { try { val id = args[1].toInt() val `val` = parseAVInput(args[3]) + val actor = Terrarum.game.getActor(id) // check if av is number if (args[2].isNum()) { - echo.error("Illegal ActorValue “${args[2]}”: ActorValue cannot be a number.") + echo.error("Illegal ActorValue ${args[2]}: ActorValue cannot be a number.") + System.err.println("[SetAV] Illegal ActorValue ${args[2]}: ActorValue cannot be a number.") return } - Terrarum.game.getActor(id).actorValue[args[2]] = `val` - echo.execute("Set ${args[2]} of $id to $`val`") + actor.actorValue[args[2]] = `val` + echo.execute("${ccW}Set $ccM${args[2]} ${ccW}for $ccY$id ${ccW}to $ccG$`val`") + println("[SetAV] set ActorValue '${args[2]}' for $actor to '$`val`'.") } catch (e: IllegalArgumentException) { - if (args.size == 4) - echo.error(args[1] + ": no actor with this ID.") + if (args.size == 4) { + echo.error("${args[1]}: no actor with this ID.") + System.err.println("[SetAV] ${args[1]}: no actor with this ID.") + } } } diff --git a/src/net/torvald/terrarum/console/Version.kt b/src/net/torvald/terrarum/console/Version.kt new file mode 100644 index 000000000..cbdc15bf9 --- /dev/null +++ b/src/net/torvald/terrarum/console/Version.kt @@ -0,0 +1,16 @@ +package net.torvald.terrarum.console + +import net.torvald.terrarum.VERSION_STRING + +/** + * Created by minjaesong on 16-04-23. + */ +class Version : ConsoleCommand { + override fun execute(args: Array) { + Echo().execute(VERSION_STRING) + } + + override fun printUsage() { + Echo().execute("Prints out current version of the application") + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/Actor.kt b/src/net/torvald/terrarum/gameactors/Actor.kt index 53cc60cf6..cc5d4136b 100644 --- a/src/net/torvald/terrarum/gameactors/Actor.kt +++ b/src/net/torvald/terrarum/gameactors/Actor.kt @@ -19,6 +19,6 @@ abstract class Actor : Comparable { override fun equals(other: Any?) = referenceID == (other as Actor).referenceID override fun hashCode() = referenceID - override fun toString() = "ActorID: ${hashCode()}" + override fun toString() = "ID: ${hashCode()}" override fun compareTo(other: Actor): Int = this.referenceID - other.referenceID } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/CollisionSolver.kt b/src/net/torvald/terrarum/gameactors/CollisionSolver.kt index e21cf218e..5a87a44c1 100644 --- a/src/net/torvald/terrarum/gameactors/CollisionSolver.kt +++ b/src/net/torvald/terrarum/gameactors/CollisionSolver.kt @@ -35,7 +35,7 @@ object CollisionSolver { } } - // sort list x (will use Timsort with Java SE >= 8, Mergesort otherwise) + // sort list x collListX.sortBy { it.pos } // set candidateX diff --git a/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt index 029ab825b..06700c816 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt @@ -33,10 +33,8 @@ object ItemPropCodex { if (code < ITEM_UNIQUE_MAX) return itemCodex[code] else { - for (actor in Terrarum.game.actorContainer) { - if (actor is CanBeAnItem && actor.referenceID == code) - return actor.itemData - } + val a = Terrarum.game.getActor(code) + if (a is CanBeAnItem) return a.itemData throw NullPointerException() } diff --git a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt index 7cae31f68..b45718159 100644 --- a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt @@ -2,10 +2,10 @@ package net.torvald.terrarum.mapdrawer import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameactors.Luminous -import net.torvald.terrarum.gamemap.WorldTime import net.torvald.terrarum.Terrarum import net.torvald.terrarum.tileproperties.TilePropCodex import com.jme3.math.FastMath +import net.torvald.terrarum.gameactors.Visible import net.torvald.terrarum.tileproperties.TileNameCode import org.newdawn.slick.Color import org.newdawn.slick.Graphics @@ -27,8 +27,8 @@ object LightmapRenderer { /** * 8-Bit RGB values */ - //private val lightmap: Array = Array(Terrarum.game.map.height) { IntArray(Terrarum.game.map.width) } private val lightmap: Array = Array(LIGHTMAP_HEIGHT) { IntArray(LIGHTMAP_WIDTH) } + private val lanternMap = ArrayList(Terrarum.game.ACTORCONTAINER_INITIAL_SIZE) private val AIR = TileNameCode.AIR @@ -165,9 +165,19 @@ object LightmapRenderer { * for all staticLightMap[y][x] */ - //purgePartOfLightmap(for_x_start - overscan_open, for_y_start - overscan_open, for_x_end + overscan_open, for_y_end + overscan_open) purgeLightmap() + // scan for luminous actors and store their lighting info to the lanterns + lanternMap.clear() + Terrarum.game.actorContainer.forEach { it -> + if (it is Luminous && it is Visible) + lanternMap.add(Lantern( + it.hitbox.centeredX.div(TSIZE).round(), + it.hitbox.centeredY.div(TSIZE).round(), + it.luminosity + )) + } + try { // Round 1 for (y in for_y_start - overscan_open..for_y_end) { @@ -229,23 +239,16 @@ object LightmapRenderer { // END MIX TILE // mix luminous actor - for (actor in Terrarum.game.actorContainer) { - if (actor is Luminous && actor is ActorWithBody) { - val tileX = Math.round(actor.hitbox.pointedX / TSIZE) - val tileY = Math.round(actor.hitbox.pointedY / TSIZE) - 1 - val actorLuminosity = actor.luminosity - if (x == tileX && y == tileY) { - lightLevelThis = maximiseRGB(lightLevelThis, actorLuminosity) // maximise to not exceed 1.0 with normal (<= 1.0) light - break - } - } + for ((posX, posY, luminosity) in lanternMap) { + if (posX == x && posY == y) + lightLevelThis = maximiseRGB(lightLevelThis, luminosity) // maximise to not exceed 1.0 with normal (<= 1.0) light } if (!doNotCalculateAmbient) { // calculate ambient var ambient: Int = 0 - var nearby: Int = 0 + var nearby: Int for (yoff in -1..1) { for (xoff in -1..1) { /** @@ -595,6 +598,8 @@ object LightmapRenderer { fun Int.even(): Boolean = this and 1 == 0 fun Int.odd(): Boolean = this and 1 == 1 + data class Lantern(val posX: Int, val posY: Int, val luminosity: Int) + val histogram: Histogram get() { var reds = IntArray(MUL) // reds[intensity] ← counts diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 54ad49e12..01d2ebfef 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -32,6 +32,12 @@ class BasicDebugInfoWindow:UICanvas { private var xdelta = 0f private var ydelta = 0f + val ccW = GameFontBase.colToCode["w"] + val ccG = GameFontBase.colToCode["g"] + val ccY = GameFontBase.colToCode["y"] + val ccR = GameFontBase.colToCode["r"] + val ccM = GameFontBase.colToCode["m"] + override fun processInput(input: Input) { } @@ -66,8 +72,6 @@ class BasicDebugInfoWindow:UICanvas { val hitbox = player.hitbox val nextHitbox = player.nextHitbox - val ccG = "${GameFontBase.colToCode["g"]}" - printLine(g, 1, "posX " + ccG + "${hitbox.pointedX.toString()}" @@ -167,24 +171,20 @@ class BasicDebugInfoWindow:UICanvas { ) g.color = GameFontBase.codeToCol["y"] - g.drawString("MEM ", (Terrarum.WIDTH - 15 * 8 - 2).toFloat(), 2f) - //g.drawString("FPS ", (Terrarum.WIDTH - 6 * 8 - 2).toFloat(), 10f) - g.drawString("Actors total ", 2f, Terrarum.HEIGHT - 10f) - g.drawString("Active ", (2 + 17*8).toFloat(), Terrarum.HEIGHT - 10f) + g.drawString("${ccY}MEM ", (Terrarum.WIDTH - 15 * 8 - 2).toFloat(), 2f) + //g.drawString("${ccY}FPS $ccG${Terrarum.appgc.fps}", (Terrarum.WIDTH - 6 * 8 - 2).toFloat(), 10f) + g.drawString("${ccY}Actors total $ccG${Terrarum.game.actorContainer.size + Terrarum.game.actorContainerInactive.size}", + 2f, Terrarum.HEIGHT - 10f) + g.drawString("${ccY}Active $ccG${Terrarum.game.actorContainer.size}", + (2 + 17*8).toFloat(), Terrarum.HEIGHT - 10f) + g.drawString("${ccY}Dormant $ccG${Terrarum.game.actorContainerInactive.size}", + (2 + 28*8).toFloat(), Terrarum.HEIGHT - 10f) g.color = GameFontBase.codeToCol["g"] g.drawString("${Terrarum.game.memInUse}M", (Terrarum.WIDTH - 11 * 8 - 2).toFloat(), 2f) g.drawString("/${Terrarum.game.totalVMMem}M", (Terrarum.WIDTH - 6 * 8 - 2).toFloat(), 2f) - //g.drawString("${Terrarum.appgc.fps}", - // (Terrarum.WIDTH - 2 * 8 - 2).toFloat(), 10f) - g.drawString("${Terrarum.game.actorContainer.size + Terrarum.game.actorcontainerInactive.size}", - (2 + 13*8).toFloat(), Terrarum.HEIGHT - 10f - ) - g.drawString(Terrarum.game.actorContainer.size.toString(), - (2 + 24*8).toFloat(), Terrarum.HEIGHT - 10f - ) } private fun printLine(g: Graphics, l: Int, s: String) { diff --git a/src/net/torvald/terrarum/ui/ConsoleWindow.kt b/src/net/torvald/terrarum/ui/ConsoleWindow.kt index 01212ca6e..e1ae571af 100644 --- a/src/net/torvald/terrarum/ui/ConsoleWindow.kt +++ b/src/net/torvald/terrarum/ui/ConsoleWindow.kt @@ -112,7 +112,6 @@ class ConsoleWindow : UICanvas, UITypable { } private fun executeCommand() { - sendMessage("> " + commandInputPool!!.toString()) CommandInterpreter.execute(commandInputPool!!.toString()) } @@ -152,7 +151,7 @@ class ConsoleWindow : UICanvas, UITypable { prevCommand = "" commandInputPool = StringBuilder() - if (Terrarum.game.auth.b()) sendMessage(Lang.get("DEV_MESSAGE_CONSOLE_CODEX")) + if (Terrarum.game.auth.b()) sendMessage(Lang["DEV_MESSAGE_CONSOLE_CODEX"]) } override fun doOpening(gc: GameContainer, delta: Int) {