IS_DEVELOPMENT_BUILD key can now be toggled with vm option '-ea'

This commit is contained in:
minjaesong
2022-01-13 09:55:51 +09:00
parent 53645925ba
commit 1060d96364
14 changed files with 78 additions and 59 deletions

View File

@@ -90,7 +90,7 @@ internal class UnsafePtr(pointer: Long, allocSize: Long) {
fun destroy() {
if (!destroyed) {
println("[UnsafePtr] Destroying pointer $this; called from:")
printdbg(this, "Destroying pointer $this; called from:")
printStackTrace(this)
UnsafeHelper.unsafe.freeMemory(ptr)
@@ -100,7 +100,7 @@ internal class UnsafePtr(pointer: Long, allocSize: Long) {
UnsafeHelper.unsafeAllocatedSize -= size
}
else {
println("[UnsafePtr] Destroy() is called but the pointer $this is already been destroyed; called from:")
printdbg(this, "Destroy() is called but the pointer $this is already been destroyed; called from:")
printStackTrace(this)
}
}

View File

@@ -72,8 +72,13 @@ public class App implements ApplicationListener {
/**
* when FALSE, some assertion and print code will not execute
*/
public static boolean IS_DEVELOPMENT_BUILD = true;
public static boolean IS_DEVELOPMENT_BUILD = false;
{
// if -ea flag is set, turn on all the debug prints
try { assert (false); }
catch (AssertionError e) { IS_DEVELOPMENT_BUILD = true; }
}
/**
* Singleton instance
@@ -378,8 +383,6 @@ public class App implements ApplicationListener {
Object[] iconPathsTemp = appIconPaths.toArray();
appConfig.setWindowIcon(Arrays.copyOf(iconPathsTemp, iconPathsTemp.length, String[].class));
IS_DEVELOPMENT_BUILD = true;
// set some more configuration vars
MULTITHREAD = THREAD_COUNT >= 3 && getConfigBoolean("multithread");
@@ -920,10 +923,12 @@ public class App implements ApplicationListener {
// test print
System.out.println("[App] Test printing every registered item");
Terrarum.INSTANCE.getItemCodex().getItemCodex().values().stream().map(GameItem::getOriginalID).forEach(
(String s) -> System.out.print(s + " "));
System.out.println();
if (IS_DEVELOPMENT_BUILD) {
System.out.println("[App] Test printing every registered item");
Terrarum.INSTANCE.getItemCodex().getItemCodex().values().stream().map(GameItem::getOriginalID).forEach(
(String s) -> System.out.print(s + " "));
System.out.println();
}
try {
@@ -1348,6 +1353,14 @@ public class App implements ApplicationListener {
System.out.println("[" + out + "] " + message);
}
public static void printmsgerr(Object obj, Object message) {
String out = (obj instanceof String) ? (String) obj : obj.getClass().getSimpleName();
if (message == null)
System.out.println(csiR + "[" + out + "] null" + csi0);
else
System.out.println(csiR + "[" + out + "] " + message + csi0);
}
public static ShaderProgram loadShaderFromFile(String vert, String frag) {
ShaderProgram s = new ShaderProgram(Gdx.files.internal(vert), Gdx.files.internal(frag));
@@ -1369,29 +1382,23 @@ public class App implements ApplicationListener {
}
public static void measureDebugTime(String name, kotlin.jvm.functions.Function0<kotlin.Unit> block) {
if (IS_DEVELOPMENT_BUILD) {
//debugTimers.put(name, kotlin.system.TimingKt.measureNanoTime(block));
long start = System.nanoTime();
block.invoke();
debugTimers.put(name, System.nanoTime() - start);
}
long start = System.nanoTime();
block.invoke();
debugTimers.put(name, System.nanoTime() - start);
}
public static void setDebugTime(String name, long value) {
if (IS_DEVELOPMENT_BUILD) {
debugTimers.put(name, value);
}
debugTimers.put(name, value);
}
public static void addDebugTime(String target, String... targets) {
if (IS_DEVELOPMENT_BUILD) {
long l = 0L;
for (String s : targets) {
l += ((long) debugTimers.get(s));
}
debugTimers.put(target, l);
long l = 0L;
for (String s : targets) {
l += ((long) debugTimers.get(s));
}
debugTimers.put(target, l);
}
public static long getTIME_T() {

View File

@@ -219,10 +219,10 @@ object ModMgr {
}
printdbg(this, "Module $moduleName processed")
printmsg(this, "Module $moduleName processed")
}
catch (noSuchModule: FileNotFoundException) {
printdbgerr(this, "No such module: $moduleName, skipping...")
printmsgerr(this, "No such module: $moduleName, skipping...")
logError(LoadErrorType.NOT_EVEN_THERE, moduleName)
@@ -232,8 +232,8 @@ object ModMgr {
// TODO: Instead of skipping module with error, just display the error message onto the face?
printdbgerr(this, "There was an error while loading module $moduleName")
printdbgerr(this, "\t$e")
printmsgerr(this, "There was an error while loading module $moduleName")
printmsgerr(this, "\t$e")
print(App.csiR); e.printStackTrace(System.out); print(App.csi0)
logError(LoadErrorType.YOUR_FAULT, moduleName, e)

View File

@@ -3,7 +3,6 @@ package net.torvald.terrarum.blockproperties
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.App
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.App.printmsg
import net.torvald.terrarum.ReferencingRanges.PREFIX_VIRTUALTILE
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.FluidType
@@ -59,7 +58,7 @@ class BlockCodex {
* Later entry (possible from other modules) will replace older ones
*/
fun fromModule(module: String, path: String) {
App.printmsg(this, "Building block properties table")
printdbg(this, "Building block properties table")
try {
register(module, CSVFetcher.readFromModule(module, path))
}
@@ -67,7 +66,7 @@ class BlockCodex {
}
fun fromCSV(module: String, csvString: String) {
App.printmsg(this, "Building wire properties table for module $module")
printdbg(this, "Building wire properties table for module $module")
val csvParser = org.apache.commons.csv.CSVParser.parse(
csvString,
@@ -211,7 +210,7 @@ class BlockCodex {
blockProps[prop.id] = prop
printmsg(this, "Setting prop ${prop.id} ->>\t${prop.nameKey}\tsolid:${prop.isSolid}")
printdbg(this, "Setting prop ${prop.id} ->>\t${prop.nameKey}\tsolid:${prop.isSolid}")
}
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.blockproperties
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
@@ -39,7 +40,7 @@ class WireCodex {
* @param path to the "wires" directory, not path to the CSV; must end with a slash!
*/
fun fromModule(module: String, path: String) {
App.printmsg(this, "Building wire properties table for module $module")
printdbg(this, "Building wire properties table for module $module")
try {
register(module, path, CSVFetcher.readFromModule(module, path + "wires.csv"))
}
@@ -47,7 +48,7 @@ class WireCodex {
}
fun fromCSV(module: String, path: String, csvString: String) {
App.printmsg(this, "Building wire properties table for module $module")
printdbg(this, "Building wire properties table for module $module")
val csvParser = org.apache.commons.csv.CSVParser.parse(
csvString,
@@ -64,7 +65,7 @@ class WireCodex {
setProp(module, it.intVal("id"), it)
}
App.printmsg(this, "Registering wire textures into the resource pool")
printdbg(this, "Registering wire textures into the resource pool")
wireProps.keys.forEach { id ->
val wireid = id.split(':').last().toInt()
@@ -148,6 +149,6 @@ class WireCodex {
val loadedClassInstance = loadedClassConstructor.newInstance(prop.id, invImgSheet, invImgX, invImgY)
ItemCodex[prop.id] = loadedClassInstance as GameItem
App.printmsg(this, "Setting prop ${prop.id} ->>\t${prop.nameKey}")
printdbg(this, "Setting prop ${prop.id} ->>\t${prop.nameKey}")
}
}

View File

@@ -371,6 +371,20 @@ fun mouseInInteractableRange(actor: ActorWithBody, action: () -> Boolean): Boole
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale // perform some error checking here
if (dist <= distMax.sqr()) return action() else return false
}
fun mouseInInteractableRangeTools(actor: ActorWithBody, item: GameItem?, reachMultiplierInTiles: (Int) -> Double = { it.toDouble() }, action: () -> Boolean): Boolean {
if (item == null) return false
val mousePos1 = Vector2(Terrarum.mouseX, Terrarum.mouseY)
val mousePos2 = Vector2(Terrarum.mouseX + INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
val mousePos3 = Vector2(Terrarum.mouseX - INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
val actorPos = actor.centrePosVector
val dist = minOf(actorPos.distanceSquared(mousePos1), actorPos.distanceSquared(mousePos2), actorPos.distanceSquared(mousePos3))
val reachBonus = (actor.actorValue.getAsDouble(AVKey.REACHBUFF) ?: 1.0) * actor.scale
val distMax = actor.actorValue.getAsDouble(AVKey.REACH)!! * reachBonus // perform some error checking here
val toolDistMax = (TILE_SIZED * reachMultiplierInTiles(item.material.toolReach)) * reachBonus
if (dist <= minOf(toolDistMax, distMax).sqr()) return action() else return false
}
fun IntRange.pickRandom() = HQRNG().nextInt(this.endInclusive - this.start + 1) + this.start // count() on 200 million entries? Se on vitun hyvää idea
fun IntArray.pickRandom(): Int = this[HQRNG().nextInt(this.size)]
fun DoubleArray.pickRandom(): Double = this[HQRNG().nextInt(this.size)]

View File

@@ -58,9 +58,7 @@ class ItemCodex {
* @param: dynamicID string of "dyn:<random id>"
*/
fun registerNewDynamicItem(dynamicID: ItemID, item: GameItem) {
if (App.IS_DEVELOPMENT_BUILD) {
printdbg(this, "Registering new dynamic item $dynamicID (from ${item.originalID})")
}
printdbg(this, "Registering new dynamic item $dynamicID (from ${item.originalID})")
dynamicItemDescription[dynamicID] = item
dynamicToStaticTable[dynamicID] = item.originalID
}

View File

@@ -1,7 +1,6 @@
package net.torvald.terrarum.itemproperties
import net.torvald.terrarum.App
import net.torvald.terrarum.App.printmsg
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.Codex
import net.torvald.terrarum.blockproperties.floatVal
import net.torvald.terrarum.blockproperties.intVal
@@ -44,7 +43,7 @@ class MaterialCodex {
internal constructor()
fun fromModule(module: String, path: String) {
App.printmsg(this, "Building material properties table")
printdbg(this, "Building material properties table")
try {
register(CSVFetcher.readFromModule(module, path))
}
@@ -74,7 +73,7 @@ class MaterialCodex {
materialProps[prop.identifier] = prop
printmsg(this, "${prop.identifier}\t${prop.strength}\t${prop.density}\t${prop.forceMod}\t${prop.enduranceMod}")
printdbg(this, "${prop.identifier}\t${prop.strength}\t${prop.density}\t${prop.forceMod}\t${prop.enduranceMod}")
}
}

View File

@@ -1137,8 +1137,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
arrayOf(actorContainerActive, actorContainerInactive).forEach { actorContainer ->
val indexToDelete = actorContainer.searchForIndex(actor.referenceID) { it.referenceID }
if (indexToDelete != null) {
printdbg(this, "Removing actor $actor")
printStackTrace(this)
// printdbg(this, "Removing actor $actor")
// printStackTrace(this)
actor.dispose()
actorContainer.removeAt(indexToDelete)
@@ -1180,13 +1180,13 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
override fun addNewActor(actor: Actor?) {
if (actor == null) return
if (App.IS_DEVELOPMENT_BUILD && theGameHasActor(actor.referenceID)) {
if (theGameHasActor(actor.referenceID)) {
throw ReferencedActorAlreadyExistsException(actor)
}
else {
if (actor.referenceID !in ReferencingRanges.ACTORS_WIRES && actor.referenceID !in ReferencingRanges.ACTORS_WIRES_HELPER) {
printdbg(this, "Adding actor $actor")
printStackTrace(this)
// printdbg(this, "Adding actor $actor")
// printStackTrace(this)
}
actorContainerActive.add(actor)
@@ -1199,7 +1199,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
fun activateDormantActor(actor: Actor) {
if (App.IS_DEVELOPMENT_BUILD && !isInactive(actor.referenceID)) {
if (!isInactive(actor.referenceID)) {
/*if (isActive(actor.referenceID))
throw Error("The actor $actor is already activated")
else
@@ -1306,7 +1306,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
println("[Ingame] Resize event")
printdbg(this, "Resize event")
}
override fun dispose() {

View File

@@ -231,7 +231,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
worldFBO = FloatFrameBuffer(App.scr.width, App.scr.height, false)
// load list of savegames
println("[TitleScreen] update list of savegames")
printdbg(this, "update list of savegames")
// to show "Continue" and "Load" on the titlescreen, uncomment this line
App.updateListOfSavegames()

View File

@@ -46,7 +46,6 @@ internal class FixtureStorageChest : FixtureBase {
actorValue[AVKey.BASEMASS] = MASS
println("FixtureStorageChest constructor call")
printStackTrace(this)
}

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRangeTools
import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
@@ -29,7 +30,7 @@ object PickaxeCore {
fun startPrimaryUse(
actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int,
dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1, attackActorBlocks: Boolean = true
) = mouseInInteractableRange(actor) {
) = mouseInInteractableRangeTools(actor, item) {
// un-round the mx
val ww = INGAME.world.width
val apos = actor.centrePosPoint

View File

@@ -157,7 +157,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
scrollAnimCounter = 0f
loadFired = 0
println("savelist mode: $mode")
printdbg(this, "savelist mode: $mode")
}
override fun show() {

View File

@@ -5,8 +5,7 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.App.printdbgerr
import net.torvald.terrarum.App.*
import net.torvald.terrarum.QNDTreeNode
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.Yaml
@@ -109,7 +108,7 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
val tag = it.tags
if (tag.contains("WRITETOCONFIG")) WriteConfig()
print("[UIRemoCon] Returning from ${currentRemoConContents.data}")
if (IS_DEVELOPMENT_BUILD) print("[UIRemoCon] Returning from ${currentRemoConContents.data}")
if (currentRemoConContents.parent != null) {
remoConTray.consume()
@@ -120,7 +119,7 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
parent.uiFakeBlurOverlay.setAsClose()
println(" to ${currentlySelectedRemoConItem}")
if (IS_DEVELOPMENT_BUILD) println(" to ${currentlySelectedRemoConItem}")
}
else {
throw NullPointerException("No parent node to return")
@@ -128,8 +127,10 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
}
else {
// check if target exists
//println("current node: ${currentRemoConContents.data}")
//currentRemoConContents.children.forEach { println("- ${it.data}") }
if (IS_DEVELOPMENT_BUILD) {
//println("current node: ${currentRemoConContents.data}")
//currentRemoConContents.children.forEach { println("- ${it.data}") }
}
if (currentRemoConContents.children.size > selectedIndex ?: 0x7FFFFFFF) {
setNewRemoConContents(currentRemoConContents.children[selectedIndex!!])