diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java index 424c0dde4..9ba30d2a7 100644 --- a/src/net/torvald/terrarum/AppLoader.java +++ b/src/net/torvald/terrarum/AppLoader.java @@ -10,10 +10,17 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.ShaderProgram; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import net.torvald.dataclass.ArrayListMap; +import net.torvald.terrarum.utils.JsonFetcher; +import net.torvald.terrarum.utils.JsonWriter; import net.torvald.terrarumsansbitmap.gdx.GameFontBase; import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.Random; @@ -30,10 +37,11 @@ public class AppLoader implements ApplicationListener { * AA: Major version * BB: Minor version * XXXX: Revision (Repository commits, or something arbitrary) - * + *

* e.g. 0x02010034 will be translated as 2.1.52 */ public static final int VERSION_RAW = 0x00_02_04B1; + public static final String getVERSION_STRING() { return String.format("%d.%d.%d", VERSION_RAW >>> 24, (VERSION_RAW & 0xff0000) >>> 16, VERSION_RAW & 0xFFFF); } @@ -56,7 +64,8 @@ public class AppLoader implements ApplicationListener { /** * Initialise the application with the alternative Screen you choose - * @param appConfig LWJGL(2) Application Configuration + * + * @param appConfig LWJGL(2) Application Configuration * @param injectScreen GDX Screen you want to run */ public AppLoader(LwjglApplicationConfiguration appConfig, Screen injectScreen) { @@ -66,6 +75,7 @@ public class AppLoader implements ApplicationListener { /** * Initialise the application with default game screen + * * @param appConfig LWJGL(2) Application Configuration */ public AppLoader(LwjglApplicationConfiguration appConfig) { @@ -80,6 +90,7 @@ public class AppLoader implements ApplicationListener { /** * Singleton pattern implementation in Java. + * * @return */ public static AppLoader getINSTANCE() { @@ -123,8 +134,10 @@ public class AppLoader implements ApplicationListener { } } - public static LwjglApplicationConfiguration appConfig; + private static boolean splashDisplayed = false; + private static boolean postInitFired = false; + public static LwjglApplicationConfiguration appConfig; public static GameFontBase fontGame; /** @@ -133,6 +146,9 @@ public class AppLoader implements ApplicationListener { public static int GLOBAL_RENDER_TIMER = new Random().nextInt(1020) + 1; + public static ArrayListMap debugTimers = new ArrayListMap(); + + public static void main(String[] args) { ShaderProgram.pedantic = false; @@ -165,6 +181,8 @@ public class AppLoader implements ApplicationListener { private Color gradWhiteBottom = new Color(0xd8d8d8ff); public Screen screen; + public static int screenW = 0; + public static int screenH = 0; public static Texture textureWhiteSquare; @@ -189,20 +207,20 @@ public class AppLoader implements ApplicationListener { logoBatch = new SpriteBatch(); camera = new OrthographicCamera(((float) appConfig.width), ((float) appConfig.height)); - initViewPort(appConfig.width, appConfig.height); + logo = new TextureRegion(new Texture(Gdx.files.internal("assets/graphics/logo_placeholder.tga"))); + logo.flip(false, true); - textureWhiteSquare = new Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga")); - textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest); - - - shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag")); - shaderHicolour = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/hicolour.frag")); - shaderColLUT = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/passthru.frag")); - - - + shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), + Gdx.files.internal("assets/4096_bayer_skyboxfill.frag") + ); + shaderHicolour = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), + Gdx.files.internal("assets/hicolour.frag") + ); + shaderColLUT = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), + Gdx.files.internal("assets/passthru.frag") + ); fullscreenQuad = new Mesh( true, 4, 6, @@ -212,31 +230,29 @@ public class AppLoader implements ApplicationListener { ); fullscreenQuad.setVertices(new float[]{ - 0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f, - ((float) appConfig.width), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f, - ((float) appConfig.width), ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 1f, 0f, - 0f, ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 0f, 0f + 0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f, + ((float) appConfig.width), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f, + ((float) appConfig.width), ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 1f, 0f, + 0f, ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 0f, 0f }); fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0}); - logo = new TextureRegion(new Texture(Gdx.files.internal("assets/graphics/logo_placeholder.tga"))); - logo.flip(false, true); - - - TextureRegionPack.Companion.setGlobalFlipY(true); - fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 128, false); - - - // if there is a predefined screen, open that screen after my init process - if (injectScreen != null) { - setScreen(injectScreen); - } + // load configs + getDefaultDirectory(); + createDirs(); + readConfigJson(); } @Override public void render() { + if (splashDisplayed && !postInitFired) { + postInit(); + postInitFired = true; + } + + FrameBufferManager.begin(renderFBO); Gdx.gl.glClearColor(.094f, .094f, .094f, 0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); @@ -250,7 +266,9 @@ public class AppLoader implements ApplicationListener { FrameBufferManager.begin(renderFBO); setCameraPosition(0, 0); - // if there's no predefined screen, default to the actual game's screen, and set the screen as the one + // draw splash screen when predefined screen is null + // because in normal operation, the only time screen == null is when the app is cold-launched + // you can't have a text drawn here :v if (screen == null) { shaderBayerSkyboxFill.begin(); shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined); @@ -276,11 +294,10 @@ public class AppLoader implements ApplicationListener { loadTimer += Gdx.graphics.getRawDeltaTime(); if (loadTimer >= showupTime) { - Terrarum.INSTANCE.setScreenW(appConfig.width); - Terrarum.INSTANCE.setScreenH(appConfig.height); setScreen(Terrarum.INSTANCE); } } + // draw the screen else { screen.render(Gdx.graphics.getDeltaTime()); } @@ -291,7 +308,7 @@ public class AppLoader implements ApplicationListener { PostProcessor.INSTANCE.draw(camera.combined, renderFBO); - + splashDisplayed = true; GLOBAL_RENDER_TIMER += 1; } @@ -299,30 +316,35 @@ public class AppLoader implements ApplicationListener { public void resize(int width, int height) { //initViewPort(width, height); - Terrarum.INSTANCE.resize(width, height); - if (screen != null) screen.resize(Terrarum.INSTANCE.getWIDTH(), Terrarum.INSTANCE.getHEIGHT()); + screenW = width; + screenH = height; + + if (screenW % 2 == 1) screenW -= 1; + if (screenH % 2 == 1) screenH -= 1; + + if (screen != null) screen.resize(screenW, screenH); if (renderFBO == null || - (renderFBO.getWidth() != Terrarum.INSTANCE.getWIDTH() || - renderFBO.getHeight() != Terrarum.INSTANCE.getHEIGHT()) - ) { + (renderFBO.getWidth() != screenW || + renderFBO.getHeight() != screenH) + ) { renderFBO = new FrameBuffer( Pixmap.Format.RGBA8888, - Terrarum.INSTANCE.getWIDTH(), - Terrarum.INSTANCE.getHEIGHT(), + screenW, + screenH, false ); } - appConfig.width = Terrarum.INSTANCE.getWIDTH(); - appConfig.height = Terrarum.INSTANCE.getHEIGHT(); + appConfig.width = screenW; + appConfig.height = screenH; printdbg(this, "Resize event"); } @Override - public void dispose () { + public void dispose() { if (screen != null) screen.hide(); System.out.println("Goodbye !"); @@ -332,12 +354,12 @@ public class AppLoader implements ApplicationListener { } @Override - public void pause () { + public void pause() { if (screen != null) screen.pause(); } @Override - public void resume () { + public void resume() { if (screen != null) screen.resume(); } @@ -354,6 +376,23 @@ public class AppLoader implements ApplicationListener { printdbg(this, "Screen transisiton complete: " + this.screen.getClass().getCanonicalName()); } + private void postInit() { + textureWhiteSquare = new Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga")); + textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest); + + TextureRegionPack.Companion.setGlobalFlipY(true); + fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, + Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 128, false + ); + + + // if there is a predefined screen, open that screen after my init process + if (injectScreen != null) { + setScreen(injectScreen); + } + } + + private void setCameraPosition(float newX, float newY) { camera.position.set((-newX + appConfig.width / 2), (-newY + appConfig.height / 2), 0f); camera.update(); @@ -370,15 +409,226 @@ public class AppLoader implements ApplicationListener { fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0}); } + // DEFAULT DIRECTORIES // + + public static String OSName = System.getProperty("os.name"); + public static String OSVersion = System.getProperty("os.version"); + public static String operationSystem; + public static String defaultDir; + public static String defaultSaveDir; + public static String configDir; + public static RunningEnvironment environment; + + private void getDefaultDirectory() { + String OS = OSName.toUpperCase(); + if (OS.contains("WIN")) { + operationSystem = "WINDOWS"; + defaultDir = System.getenv("APPDATA") + "/Terrarum"; + } + else if (OS.contains("OS X")) { + operationSystem = "OSX"; + defaultDir = System.getProperty("user.home") + "/Library/Application Support/Terrarum"; + } + else if (OS.contains("NUX") || OS.contains("NIX") || OS.contains("BSD")) { + operationSystem = "LINUX"; + defaultDir = System.getProperty("user.home") + "/.Terrarum"; + } + else if (OS.contains("SUNOS")) { + operationSystem = "SOLARIS"; + defaultDir = System.getProperty("user.home") + "/.Terrarum"; + } + else if (System.getProperty("java.runtime.name").toUpperCase().contains("ANDROID")) { + operationSystem = "ANDROID"; + defaultDir = System.getProperty("user.home") + "/.Terrarum"; + environment = RunningEnvironment.MOBILE; + } + else { + operationSystem = "UNKNOWN"; + defaultDir = System.getProperty("user.home") + "/.Terrarum"; + } + + defaultSaveDir = defaultDir + "/Saves"; + configDir = defaultDir + "/config.json"; + + System.out.println("os.name = $OSName (with identifier $operationSystem)"); + System.out.println("os.version = $OSVersion"); + System.out.println("default directory: $defaultDir"); + } + + private void createDirs() { + File[] dirs = {new File(defaultSaveDir)}; + + for (File it : dirs) { + if (!it.exists()) + it.mkdirs(); + } + + //dirs.forEach { if (!it.exists()) it.mkdirs() } + } + + + // CONFIG // + + private static KVHashMap gameConfig = new KVHashMap(); + + private static void createConfigJson() throws IOException { + File configFile = new File(configDir); + + if (!configFile.exists() || configFile.length() == 0L) { + JsonWriter.INSTANCE.writeToFile(DefaultConfig.INSTANCE.fetch(), configDir); + } + } + + /** + * + * @return true on successful, false on failure. + */ + private static Boolean readConfigJson() { + try { + // read from disk and build config from it + JsonObject jsonObject = JsonFetcher.INSTANCE.invoke(configDir); + + // make config + jsonObject.entrySet().forEach((entry) -> + gameConfig.set(entry.getKey(), entry.getValue()) + ); + + return true; + } + catch (IOException e) { + // write default config to game dir. Call this method again to read config from it. + try { + createConfigJson(); + } + catch (IOException e1) { + System.out.println("[AppLoader] Unable to write config.json file"); + e.printStackTrace(); + } + + return false; + } + + } + + /** + * Return config from config set. If the config does not exist, default value will be returned. + * @param key + * * + * @return Config from config set or default config if it does not exist. + * * + * @throws NullPointerException if the specified config simply does not exist. + */ + public static int getConfigInt(String key) { + Object cfg = getConfigMaster(key); + if (cfg instanceof JsonPrimitive) + return ((JsonPrimitive) cfg).getAsInt(); + else + return Integer.parseInt(((String) cfg)); + } + + /** + * Return config from config set. If the config does not exist, default value will be returned. + * @param key + * * + * @return Config from config set or default config if it does not exist. + * * + * @throws NullPointerException if the specified config simply does not exist. + */ + public static String getConfigString(String key) { + Object cfg = getConfigMaster(key); + if (cfg instanceof JsonPrimitive) + return ((JsonPrimitive) cfg).getAsString(); + else + return ((String) cfg); + } + + /** + * Return config from config set. If the config does not exist, default value will be returned. + * @param key + * * + * @return Config from config set or default config if it does not exist. + * * + * @throws NullPointerException if the specified config simply does not exist. + */ + public static boolean getConfigBoolean(String key) { + Object cfg = getConfigMaster(key); + if (cfg instanceof JsonPrimitive) + return ((JsonPrimitive) cfg).getAsBoolean(); + else + return ((boolean) cfg); + } + + public static int[] getConfigIntArray(String key) { + Object cfg = getConfigMaster(key); + if (cfg instanceof JsonArray) { + JsonArray jsonArray = ((JsonArray) cfg).getAsJsonArray(); + //return IntArray(jsonArray.size(), { i -> jsonArray[i].asInt }) + int[] intArray = new int[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + intArray[i] = jsonArray.get(i).getAsInt(); + } + return intArray; + } + else + return ((int[]) cfg); + } + + /** + * Get config from config file. If the entry does not exist, get from defaults; if the entry is not in the default, NullPointerException will be thrown + */ + private static JsonObject getDefaultConfig() { + return DefaultConfig.INSTANCE.fetch(); + } + + private static Object getConfigMaster(String key1) { + String key = key1.toLowerCase(); + + Object config; + try { + config = gameConfig.get(key); + } + catch (NullPointerException e) { + config = null; + } + + Object defaults; + try { + defaults = getDefaultConfig().get(key); + } + catch (NullPointerException e) { + defaults = null; + } + + if (config == null) { + if (defaults == null) { + throw new NullPointerException("key not found: '$key'"); + } + else { + return defaults; + } + } + else { + return config; + } + } + + public static void setConfig(String key, Object value) { + gameConfig.set(key, value); + } + + + + // // public static final void printdbg(Object obj, Object message) { if (IS_DEVELOPMENT_BUILD) { - System.out.println("["+obj.getClass().getSimpleName()+"] "+message.toString()); + System.out.println("[" + obj.getClass().getSimpleName() + "] " + message.toString()); } } + public static final void printdbgerr(Object obj, Object message) { if (IS_DEVELOPMENT_BUILD) { - System.err.println("["+obj.getClass().getSimpleName()+"] "+message.toString()); + System.err.println("[" + obj.getClass().getSimpleName() + "] " + message.toString()); } } -} +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/FuckingWorldRenderer.kt.unused b/src/net/torvald/terrarum/FuckingWorldRenderer.kt.unused index e6ce8e9bf..87e3b85cf 100644 --- a/src/net/torvald/terrarum/FuckingWorldRenderer.kt.unused +++ b/src/net/torvald/terrarum/FuckingWorldRenderer.kt.unused @@ -65,7 +65,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { * list of Actors that is sorted by Actors' referenceID */ //val ACTORCONTAINER_INITIAL_SIZE = 64 - val PARTICLES_MAX = Terrarum.getConfigInt("maxparticles") + val PARTICLES_MAX = AppLoader.getConfigInt("maxparticles") //val actorContainer = ArrayList(ACTORCONTAINER_INITIAL_SIZE) //val actorContainerInactive = ArrayList(ACTORCONTAINER_INITIAL_SIZE) val particlesContainer = CircularArray(PARTICLES_MAX) @@ -362,14 +362,14 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { width = 900, height = Terrarum.HEIGHT - 160, categoryWidth = 210, - toggleKeyLiteral = Terrarum.getConfigInt("keyinventory") + toggleKeyLiteral = AppLoader.getConfigInt("keyinventory") )*/ /*uiInventoryPlayer.setPosition( -uiInventoryPlayer.width, 70 )*/ uiInventoryPlayer = UIInventoryFull(player, - toggleKeyLiteral = Terrarum.getConfigInt("keyinventory") + toggleKeyLiteral = AppLoader.getConfigInt("keyinventory") ) uiInventoryPlayer.setPosition(0, 0) @@ -515,7 +515,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { - if (false && Terrarum.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements) + if (false && AppLoader.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements) if (firstTimeRun || updateThreadWrapper.state == Thread.State.TERMINATED) { updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread") updateThreadWrapper.start() @@ -529,7 +529,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { while (updateDeltaCounter >= updateRate) { //updateGame(delta) - Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) } + AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) } updateDeltaCounter -= updateRate updateTries++ @@ -544,7 +544,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) { /** RENDER CODE GOES HERE */ //renderGame(batch) - Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame(batch) } + AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame(batch) } } protected fun updateGame(delta: Float) { diff --git a/src/net/torvald/terrarum/KVHashMap.kt b/src/net/torvald/terrarum/KVHashMap.kt index 62d4616f4..a1cb36307 100644 --- a/src/net/torvald/terrarum/KVHashMap.kt +++ b/src/net/torvald/terrarum/KVHashMap.kt @@ -9,7 +9,6 @@ import com.google.gson.JsonPrimitive import kotlin.collections.HashMap typealias ItemValue = KVHashMap -typealias GameConfig = KVHashMap /** * Created by minjaesong on 2015-12-30. diff --git a/src/net/torvald/terrarum/PostProcessor.kt b/src/net/torvald/terrarum/PostProcessor.kt index 1949f94c7..ad5744799 100644 --- a/src/net/torvald/terrarum/PostProcessor.kt +++ b/src/net/torvald/terrarum/PostProcessor.kt @@ -37,7 +37,7 @@ object PostProcessor { - Terrarum.debugTimers["Renderer.PostProcessor"] = measureNanoTime { + AppLoader.debugTimers["Renderer.PostProcessor"] = measureNanoTime { Gdx.gl.glClearColor(.094f, .094f, .094f, 0f) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) @@ -46,7 +46,7 @@ object PostProcessor { Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) val shader: ShaderProgram? = - if (Terrarum.getConfigBoolean("fxdither")) + if (AppLoader.getConfigBoolean("fxdither")) AppLoader.shaderHicolour else null diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 36c390ef4..af3e64ad0 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -3,26 +3,24 @@ package net.torvald.terrarum import com.badlogic.gdx.Gdx import com.badlogic.gdx.Screen import com.badlogic.gdx.assets.AssetManager -import com.badlogic.gdx.graphics.* +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.GL20 +import com.badlogic.gdx.graphics.OrthographicCamera +import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.utils.GdxRuntimeException -import com.google.gson.JsonArray -import com.google.gson.JsonPrimitive import com.jme3.math.FastMath -import net.torvald.dataclass.ArrayListMap import net.torvald.dataclass.CircularArray +import net.torvald.getcpuname.GetCpuName import net.torvald.random.HQRNG -import net.torvald.terrarum.AppLoader.printdbg -import net.torvald.terrarum.AppLoader.printdbgerr +import net.torvald.terrarum.AppLoader.* import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.ActorID import net.torvald.terrarum.imagefont.TinyAlphNum import net.torvald.terrarum.itemproperties.ItemCodex -import net.torvald.terrarum.utils.JsonFetcher -import net.torvald.terrarum.utils.JsonWriter import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarumsansbitmap.gdx.GameFontBase @@ -30,9 +28,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import org.lwjgl.BufferUtils import org.lwjgl.input.Controllers import java.io.File -import java.io.IOException -import net.torvald.getcpuname.GetCpuName -import net.torvald.terrarum.modulebasegame.Ingame import kotlin.math.absoluteValue @@ -52,11 +47,6 @@ object Terrarum : Screen { */ const val PLAYER_REF_ID: Int = 0x91A7E2 - val debugTimers = ArrayListMap() - - var screenW = 0 - var screenH = 0 - lateinit var batch: SpriteBatch lateinit var shapeRender: ShapeRenderer // DO NOT USE!! for very limited applications e.g. WeatherMixer inline fun inShapeRenderer(shapeRendererType: ShapeRenderer.ShapeType = ShapeRenderer.ShapeType.Filled, action: (ShapeRenderer) -> Unit) { @@ -71,9 +61,9 @@ object Terrarum : Screen { ////////////////////////////// val WIDTH: Int - get() = if (screenW % 2 == 0) screenW else screenW - 1 + get() = AppLoader.screenW val HEIGHT: Int - get() = if (screenH % 2 == 0) screenH else screenH - 1 + get() = AppLoader.screenH //val WIDTH_MIN = 800 //val HEIGHT_MIN = 600 @@ -107,18 +97,6 @@ object Terrarum : Screen { var ingame: IngameInstance? = null - private val gameConfig = GameConfig() - - val OSName = System.getProperty("os.name") - val OSVersion = System.getProperty("os.version") - lateinit var OperationSystem: String // all caps "WINDOWS, "OSX", "LINUX", "SOLARIS", "UNKNOWN" - private set - lateinit var defaultDir: String - private set - lateinit var defaultSaveDir: String - private set - - private val javaHeapCircularArray = CircularArray(128) private val nativeHeapCircularArray = CircularArray(128) @@ -142,9 +120,6 @@ object Terrarum : Screen { val memXmx: Int get() = (Runtime.getRuntime().maxMemory() shr 20).toInt() - var environment: RunningEnvironment - private set - @@ -203,8 +178,6 @@ object Terrarum : Screen { val MULTITHREAD: Boolean get() = THREADS >= 3 && getConfigBoolean("multithread") - private lateinit var configDir: String - const val NAME = AppLoader.GAME_NAME @@ -243,16 +216,6 @@ object Terrarum : Screen { println("LibGDX version ${com.badlogic.gdx.Version.VERSION}") - getDefaultDirectory() - createDirs() - - - // read config i guess...? - val readFromDisk = readConfigJson() - if (!readFromDisk) readConfigJson() // what's this for? - - - println("os.arch = $systemArch") // debug info if (is32BitJVM) { @@ -278,18 +241,19 @@ object Terrarum : Screen { } - - environment = try { - Controllers.getController(0) // test if controller exists - if (getConfigString("pcgamepadenv") == "console") - RunningEnvironment.CONSOLE - else + // setting environment as MOBILE precedes this code + if (environment != RunningEnvironment.MOBILE) { + environment = try { + Controllers.getController(0) // test if controller exists + if (getConfigString("pcgamepadenv") == "console") + RunningEnvironment.CONSOLE + else + RunningEnvironment.PC + } + catch (e: IndexOutOfBoundsException) { RunningEnvironment.PC + } } - catch (e: IndexOutOfBoundsException) { - RunningEnvironment.PC - } - } @@ -440,7 +404,7 @@ object Terrarum : Screen { } override fun render(delta: Float) { - Terrarum.debugTimers["GDX.delta"] = delta.times(1000_000_000f).toLong() + AppLoader.debugTimers["GDX.delta"] = delta.times(1000_000_000f).toLong() AppLoader.getINSTANCE().screen.render(deltaTime) //GLOBAL_RENDER_TIMER += 1 // moved to AppLoader; global event must be place at the apploader to prevent ACCIDENTAL forgot-to-update type of bug. @@ -479,206 +443,16 @@ object Terrarum : Screen { } override fun resize(width: Int, height: Int) { - //var width = maxOf(width, WIDTH_MIN) - //var height = maxOf(height, HEIGHT_MIN) - - var width = width - var height = height - - if (width % 2 == 1) width -= 1 - if (height % 2 == 1) height -= 1 - - screenW = width - screenH = height - - - try { - AppLoader.getINSTANCE().screen.resize(screenW, screenH) + /*try { + AppLoader.getINSTANCE().screen.resize(width, height) } - catch (e: NullPointerException) { } - - // re-calculate fullscreen quad - //updateFullscreenQuad(screenW, screenH) - - //appLoader.resize(width, height) - //Gdx.graphics.setWindowedMode(width, height) + catch (e: NullPointerException) { }*/ // I sense circular recursion... printdbg(this, "newsize: ${Gdx.graphics.width}x${Gdx.graphics.height} | internal: ${width}x$height") } - - private fun getDefaultDirectory() { - val OS = System.getProperty("os.name").toUpperCase() - if (OS.contains("WIN")) { - OperationSystem = "WINDOWS" - defaultDir = System.getenv("APPDATA") + "/Terrarum" - } - else if (OS.contains("OS X")) { - OperationSystem = "OSX" - defaultDir = System.getProperty("user.home") + "/Library/Application Support/Terrarum" - } - else if (OS.contains("NUX") || OS.contains("NIX") || OS.contains("BSD")) { - OperationSystem = "LINUX" - defaultDir = System.getProperty("user.home") + "/.Terrarum" - } - else if (OS.contains("SUNOS")) { - OperationSystem = "SOLARIS" - defaultDir = System.getProperty("user.home") + "/.Terrarum" - } - else if (System.getProperty("java.runtime.name").toUpperCase().contains("ANDROID")) { - OperationSystem = "ANDROID" - defaultDir = System.getProperty("user.home") + "/.Terrarum" - environment = RunningEnvironment.MOBILE - } - else { - OperationSystem = "UNKNOWN" - defaultDir = System.getProperty("user.home") + "/.Terrarum" - } - - defaultSaveDir = defaultDir + "/Saves" - configDir = defaultDir + "/config.json" - - println("os.name = $OSName (with identifier $OperationSystem)") - println("os.version = $OSVersion") - println("default directory: $defaultDir") - } - - private fun createDirs() { - val dirs = arrayOf(File(defaultSaveDir)) - dirs.forEach { if (!it.exists()) it.mkdirs() } - } - - private fun createConfigJson() { - val configFile = File(configDir) - - if (!configFile.exists() || configFile.length() == 0L) { - JsonWriter.writeToFile(DefaultConfig.fetch(), configDir) - } - } - - private fun readConfigJson(): Boolean { - try { - // read from disk and build config from it - val jsonObject = JsonFetcher(configDir) - - // make config - jsonObject.entrySet().forEach { entry -> gameConfig[entry.key] = entry.value } - - return true - } - catch (e: IOException) { - // write default config to game dir. Call this method again to read config from it. - try { - createConfigJson() - } - catch (e1: IOException) { - e.printStackTrace() - } - - return false - } - - } - - /** - * Return config from config set. If the config does not exist, default value will be returned. - * @param key - * * - * @return Config from config set or default config if it does not exist. - * * - * @throws NullPointerException if the specified config simply does not exist. - */ - fun getConfigInt(key: String): Int { - val cfg = getConfigMaster(key) - if (cfg is JsonPrimitive) - return cfg.asInt - else - return cfg as Int - } - - /** - * Return config from config set. If the config does not exist, default value will be returned. - * @param key - * * - * @return Config from config set or default config if it does not exist. - * * - * @throws NullPointerException if the specified config simply does not exist. - */ - fun getConfigString(key: String): String { - val cfg = getConfigMaster(key) - if (cfg is JsonPrimitive) - return cfg.asString - else - return cfg as String - } - - /** - * Return config from config set. If the config does not exist, default value will be returned. - * @param key - * * - * @return Config from config set or default config if it does not exist. - * * - * @throws NullPointerException if the specified config simply does not exist. - */ - fun getConfigBoolean(key: String): Boolean { - val cfg = getConfigMaster(key) - if (cfg is JsonPrimitive) - return cfg.asBoolean - else - return cfg as Boolean - } - - fun getConfigIntArray(key: String): IntArray { - val cfg = getConfigMaster(key) - if (cfg is JsonArray) { - val jsonArray = cfg.asJsonArray - return IntArray(jsonArray.size(), { i -> jsonArray[i].asInt }) - } - else - return cfg as IntArray - } - - /** - * Get config from config file. If the entry does not exist, get from defaults; if the entry is not in the default, NullPointerException will be thrown - */ - private val defaultConfig = DefaultConfig.fetch() - - private fun getConfigMaster(key: String): Any { - val key = key.toLowerCase() - - val config = try { - gameConfig[key] - } - catch (e: NullPointerException) { - null - } - - val defaults = try { - defaultConfig.get(key) - } - catch (e: NullPointerException) { - null - } - - if (config == null) { - if (defaults == null) { - throw NullPointerException("key not found: '$key'") - } - else { - return defaults - } - } - else { - return config - } - } - - fun setConfig(key: String, value: Any) { - gameConfig[key] = value - } - val currentSaveDir: File get() { val file = File(defaultSaveDir + "/test") diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index a236c7a48..82941bd0d 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.gamecontroller import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import com.badlogic.gdx.InputAdapter +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.Terrarum @@ -40,17 +41,19 @@ class IngameController(val ingame: Ingame) : InputAdapter() { // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) if (ingame.canPlayerControl) { - if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")) || Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) { + if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) || + Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) { + val player = (Terrarum.ingame!! as Ingame).actorNowPlaying if (player == null) return val itemOnGrip = player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] itemOnGrip?.let { - if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary"))) { + if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))) { player.consumePrimary(it) } - if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) { + if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) { player.consumeSecondary(it) } } @@ -69,8 +72,8 @@ class IngameController(val ingame: Ingame) : InputAdapter() { ingame.actorNowPlaying?.keyDown(keycode) } - if (Terrarum.getConfigIntArray("keyquickselalt").contains(keycode) - || keycode == Terrarum.getConfigInt("keyquicksel")) { + if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode) + || keycode == AppLoader.getConfigInt("keyquicksel")) { ingame.uiPieMenu.setAsOpen() ingame.uiQuickBar.setAsClose() } @@ -90,8 +93,8 @@ class IngameController(val ingame: Ingame) : InputAdapter() { } override fun keyUp(keycode: Int): Boolean { - if (Terrarum.getConfigIntArray("keyquickselalt").contains(keycode) - || keycode == Terrarum.getConfigInt("keyquicksel")) { + if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode) + || keycode == AppLoader.getConfigInt("keyquicksel")) { ingame.uiPieMenu.setAsClose() ingame.uiQuickBar.setAsOpen() } @@ -118,10 +121,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() { // fire world click events; the event is defined as Ingame's (or any others') WorldClick event if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? - if (button == Terrarum.getConfigInt("mouseprimary")) { + if (button == AppLoader.getConfigInt("mouseprimary")) { ingame.worldPrimaryClickEnd(Terrarum.deltaTime) } - if (button == Terrarum.getConfigInt("mousesecondary")) { + if (button == AppLoader.getConfigInt("mousesecondary")) { ingame.worldSecondaryClickEnd(Terrarum.deltaTime) } } @@ -149,10 +152,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() { // fire world click events; the event is defined as Ingame's (or any others') WorldClick event if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right? - if (button == Terrarum.getConfigInt("mouseprimary")) { + if (button == AppLoader.getConfigInt("mouseprimary")) { ingame.worldPrimaryClickStart(Terrarum.deltaTime) } - if (button == Terrarum.getConfigInt("mousesecondary")) { + if (button == AppLoader.getConfigInt("mousesecondary")) { ingame.worldSecondaryClickStart(Terrarum.deltaTime) } } diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index bd61a4b17..31cc45f6e 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -130,7 +130,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { - if (false && Terrarum.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements) + if (false && AppLoader.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements) // else, NOP; } else { @@ -138,7 +138,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { while (updateDeltaCounter >= updateRate) { //updateGame(delta) - Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) } + AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) } updateDeltaCounter -= updateRate updateTries++ @@ -153,7 +153,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { /** RENDER CODE GOES HERE */ //renderGame(batch) - Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame() } + AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() } } private fun updateGame(delta: Float) { diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index 07735a0f5..91e73ccd9 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -54,7 +54,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { * list of Actors that is sorted by Actors' referenceID */ //val ACTORCONTAINER_INITIAL_SIZE = 64 - val PARTICLES_MAX = Terrarum.getConfigInt("maxparticles") + val PARTICLES_MAX = AppLoader.getConfigInt("maxparticles") //val actorContainer = ArrayList(ACTORCONTAINER_INITIAL_SIZE) //val actorContainerInactive = ArrayList(ACTORCONTAINER_INITIAL_SIZE) val particlesContainer = CircularArray(PARTICLES_MAX) @@ -305,14 +305,14 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { width = 900, height = Terrarum.HEIGHT - 160, categoryWidth = 210, - toggleKeyLiteral = Terrarum.getConfigInt("keyinventory") + toggleKeyLiteral = AppLoader.getConfigInt("keyinventory") )*/ /*uiInventoryPlayer.setPosition( -uiInventoryPlayer.width, 70 )*/ uiInventoryPlayer = UIInventoryFull(actorNowPlaying, - toggleKeyLiteral = Terrarum.getConfigInt("keyinventory") + toggleKeyLiteral = AppLoader.getConfigInt("keyinventory") ) uiInventoryPlayer.setPosition(0, 0) @@ -470,7 +470,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { - if (false && Terrarum.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements) + if (false && AppLoader.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements) if (firstTimeRun || updateThreadWrapper.state == Thread.State.TERMINATED) { updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread") updateThreadWrapper.start() @@ -485,7 +485,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { while (updateDeltaCounter >= renderRate) { //updateGame(delta) - Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) } + AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) } updateDeltaCounter -= renderRate updateTries++ @@ -501,7 +501,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { /** RENDER CODE GOES HERE */ //renderGame(batch) - Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame() } + AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() } } protected fun updateGame(delta: Float) { diff --git a/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt b/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt index 1bda6ca9b..75ca928a7 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/ExportAV.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.modulebasegame.console +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.utils.JsonWriter import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.ConsoleCommand @@ -20,7 +21,7 @@ internal object ExportAV : ConsoleCommand { JsonWriter.writeToFile( player.actorValue, - Terrarum.defaultDir + "/Exports/" + args[1] + ".json") + AppLoader.defaultDir + "/Exports/" + args[1] + ".json") Echo("ExportAV: exported to " + args[1] + ".json") } diff --git a/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt b/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt index 03ff72150..572a73682 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.modulebasegame.console import net.torvald.colourutil.Col4096 +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.utils.RasterWriter import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blockproperties.Block @@ -78,7 +79,7 @@ internal object ExportMap : ConsoleCommand { mapDataPointer += 3 } - val dir = Terrarum.defaultDir + "/Exports/" + val dir = AppLoader.defaultDir + "/Exports/" val dirAsFile = File(dir) if (!dirAsFile.exists()) { dirAsFile.mkdir() diff --git a/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt b/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt index d27088bab..d2ac6ca5b 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/GsonTest.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.console import net.torvald.terrarum.Terrarum import com.google.gson.Gson +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.Echo import net.torvald.terrarum.modulebasegame.Ingame @@ -23,7 +24,7 @@ internal object GsonTest : ConsoleCommand { val bufferedWriter: BufferedWriter val writer: FileWriter try { - writer = FileWriter(Terrarum.defaultDir + "/Exports/" + args[1] + ".json") + writer = FileWriter(AppLoader.defaultDir + "/Exports/" + args[1] + ".json") bufferedWriter = BufferedWriter(writer) bufferedWriter.write(jsonString) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt index fbcb1135c..a76ba50b4 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color import com.jme3.math.FastMath +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.Terrarum import net.torvald.terrarum.bipolarClamp import net.torvald.terrarum.gameactors.* @@ -214,17 +215,17 @@ open class ActorHumanoid( private fun updateGamerControlBox() { if (isGamer) { - isUpDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyup")) - isLeftDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyleft")) - isDownDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keydown")) - isRightDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyright")) - isJumpDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyjump")) + isUpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyup")) + isLeftDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyleft")) + isDownDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keydown")) + isRightDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyright")) + isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump")) if (Terrarum.controller != null) { - axisX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlstickx")) - axisY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlsticky")) - axisRX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrstickx")) - axisRY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrsticky")) + axisX = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadlstickx")) + axisY = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadlsticky")) + axisRX = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadrstickx")) + axisRY = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadrsticky")) // deadzonning if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0f @@ -232,7 +233,7 @@ open class ActorHumanoid( if (Math.abs(axisRX) < Terrarum.CONTROLLER_DEADZONE) axisRX = 0f if (Math.abs(axisRY) < Terrarum.CONTROLLER_DEADZONE) axisRY = 0f - isJumpDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyjump")) || + isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump")) || Terrarum.controller!!.isButtonPressed(GAMEPAD_JUMP) } } @@ -290,11 +291,11 @@ open class ActorHumanoid( // ↑F, ↓S if (isRightDown && !isLeftDown) { walkHorizontal(false, AXIS_KEYBOARD) - prevHMoveKey = Terrarum.getConfigInt("keyright") + prevHMoveKey = AppLoader.getConfigInt("keyright") } // ↓F, ↑S else if (isLeftDown && !isRightDown) { walkHorizontal(true, AXIS_KEYBOARD) - prevHMoveKey = Terrarum.getConfigInt("keyleft") + prevHMoveKey = AppLoader.getConfigInt("keyleft") } // ↓F, ↓S /*else if (isLeftDown && isRightDown) { if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) { @@ -318,11 +319,11 @@ open class ActorHumanoid( // ↑E, ↓D if (isDownDown && !isUpDown) { walkVertical(false, AXIS_KEYBOARD) - prevVMoveKey = Terrarum.getConfigInt("keydown") + prevVMoveKey = AppLoader.getConfigInt("keydown") } // ↓E, ↑D else if (isUpDown && !isDownDown) { walkVertical(true, AXIS_KEYBOARD) - prevVMoveKey = Terrarum.getConfigInt("keyup") + prevVMoveKey = AppLoader.getConfigInt("keyup") } // ↓E, ↓D /*else if (isUpDown && isDownDown) { if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) { @@ -360,7 +361,7 @@ open class ActorHumanoid( override fun keyDown(keycode: Int): Boolean { // quickslot (quickbar) - val quickbarKeys = Terrarum.getConfigIntArray("keyquickbars") + val quickbarKeys = AppLoader.getConfigIntArray("keyquickbars") if (keycode in quickbarKeys) { actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = quickbarKeys.indexOf(keycode) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt index 032e303df..38469be86 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt @@ -2,7 +2,7 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.Second import net.torvald.terrarum.ui.UICanvas @@ -19,7 +19,7 @@ class Notification : UICanvas() { override var height: Int = msgUI.height private val visibleTime = Math.min( - Terrarum.getConfigInt("notificationshowuptime"), + AppLoader.getConfigInt("notificationshowuptime"), SHOWUP_MAX ) private var displayTimer = 0f diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt index 8e15d9a2d..63628837f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt @@ -40,7 +40,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() { ELuptimer += delta } - if (mouseUp || Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyinteract"))) { + if (mouseUp || Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyinteract"))) { ELuptimer = 0f ELon = true } @@ -56,7 +56,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() { val playerTilePos = player.hIntTilewiseHitbox val tempCelsius = -273f + ((Terrarum.ingame as? Ingame)?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f) - return when (Terrarum.getConfigInt("temperatureunit")) { + return when (AppLoader.getConfigInt("temperatureunit")) { TEMP_KELVIN -> tempCelsius.times(1.8f).plus(32f).roundInt() TEMP_CELCIUS -> tempCelsius.roundInt() else -> tempCelsius.plus(273.15f).roundInt() @@ -86,10 +86,10 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() { sb.append(temperature.abs()) - if (Terrarum.getConfigInt("temperatureunit") == 1) { + if (AppLoader.getConfigInt("temperatureunit") == 1) { sb.append('"') // celsius superscript } - else if (Terrarum.getConfigInt("temperatureunit") == -1) { + else if (AppLoader.getConfigInt("temperatureunit") == -1) { sb.append('#') // fahrenheit subscript } else { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventory.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventory.kt index 260efc7bb..5b8f4a3b8 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventory.kt @@ -157,10 +157,10 @@ package net.torvald.terrarum.modulebasegame.ui private var isEncumbered = false - private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // getter used to support in-game keybind changing - private val seekRight: Int; get() = Terrarum.getConfigInt("keyright") // getter used to support in-game keybind changing - private val seekUp: Int; get() = Terrarum.getConfigInt("keyup") // getter used to support in-game keybind changing - private val seekDown: Int; get() = Terrarum.getConfigInt("keydown") // getter used to support in-game keybind changing + private val seekLeft: Int; get() = AppLoader.getConfigInt("keyleft") // getter used to support in-game keybind changing + private val seekRight: Int; get() = AppLoader.getConfigInt("keyright") // getter used to support in-game keybind changing + private val seekUp: Int; get() = AppLoader.getConfigInt("keyup") // getter used to support in-game keybind changing + private val seekDown: Int; get() = AppLoader.getConfigInt("keydown") // getter used to support in-game keybind changing init { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index 589fe51f0..0232c8d9e 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -8,11 +8,10 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.ShapeRenderer import net.torvald.terrarum.* import net.torvald.terrarum.gameactors.ActorWBMovable -import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER -import net.torvald.terrarum.modulebasegame.gameactors.Pocketed -import net.torvald.terrarum.Second import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER +import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -43,7 +42,7 @@ class UIInventoryFull( private val SP = "${0x3000.toChar()}${0x3000.toChar()}" val listControlHelp: String - get() = if (Terrarum.environment == RunningEnvironment.PC) + get() = if (AppLoader.environment == RunningEnvironment.PC) "${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP" + "${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" + "${0xe011.toChar()}..${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" + diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt index 6eeeefa58..f021eaa59 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt @@ -49,7 +49,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() { ELuptimer += delta } - if (mouseUp || Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyinteract"))) { + if (mouseUp || Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyinteract"))) { ELuptimer = 0f ELon = true } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt index c3d77c956..e19b3f5f7 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt @@ -32,7 +32,7 @@ import net.torvald.terrarum.ui.UIItemTextButtonList ) init { - if (Terrarum.getConfigBoolean("__debug")) { + if (AppLoader.getConfigBoolean("__debug")) { menuLabels.addAll(arrayOf( " Development Tools $", "Building Maker" @@ -117,7 +117,7 @@ import net.torvald.terrarum.ui.UIItemTextButtonList menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> Thread.sleep(50); System.exit(0) } - if (Terrarum.getConfigBoolean("__debug")) { + if (AppLoader.getConfigBoolean("__debug")) { menubar.buttons[menuLabels.indexOf("Building Maker")].clickOnceListener = { _, _, _ -> this.setAsClose() diff --git a/src/net/torvald/terrarum/serialise/SavegameLedger.kt b/src/net/torvald/terrarum/serialise/SavegameLedger.kt index 5647cb344..738f9533d 100644 --- a/src/net/torvald/terrarum/serialise/SavegameLedger.kt +++ b/src/net/torvald/terrarum/serialise/SavegameLedger.kt @@ -1,15 +1,14 @@ package net.torvald.terrarum.serialise -import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.AppLoader import java.io.File -import java.io.FileFilter import java.io.FileInputStream object SavegameLedger { - private val SAVE_DIRECTORY = File(Terrarum.defaultSaveDir) + private val SAVE_DIRECTORY = File(AppLoader.defaultSaveDir) fun hasSavegameDirectory() = SAVE_DIRECTORY.exists() && SAVE_DIRECTORY.isDirectory diff --git a/src/net/torvald/terrarum/serialise/WriteCSV.kt b/src/net/torvald/terrarum/serialise/WriteCSV.kt index 3a744a943..f88c7d30e 100644 --- a/src/net/torvald/terrarum/serialise/WriteCSV.kt +++ b/src/net/torvald/terrarum/serialise/WriteCSV.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.serialise -import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.AppLoader import java.io.IOException import java.nio.file.Files import java.nio.file.Paths @@ -20,11 +20,11 @@ internal object WriteCSV { //val itemCSV = CSVFetcher.readCSVasString(ItemCodex.CSV_PATH) //val matCSV = CSVFetcher.readCSVasString(MaterialCodex.CSV_PATH) - val pathTile = Paths.get("${Terrarum.defaultSaveDir}" + + val pathTile = Paths.get("${AppLoader.defaultSaveDir}" + "/$saveDirectoryName/${META_FILENAME_TILE}") - val pathItem = Paths.get("${Terrarum.defaultSaveDir}" + + val pathItem = Paths.get("${AppLoader.defaultSaveDir}" + "/$saveDirectoryName/${META_FILENAME_ITEM}") - val pathMat = Paths.get("${Terrarum.defaultSaveDir}" + + val pathMat = Paths.get("${AppLoader.defaultSaveDir}" + "/$saveDirectoryName/${META_FILENAME_MAT}") val tempPathTile = Files.createTempFile(pathTile.toString(), "_temp") val tempPathItem = Files.createTempFile(pathItem.toString(), "_temp") diff --git a/src/net/torvald/terrarum/serialise/WriteLayerData.kt b/src/net/torvald/terrarum/serialise/WriteLayerData.kt index 21ad557e2..b978b27dc 100644 --- a/src/net/torvald/terrarum/serialise/WriteLayerData.kt +++ b/src/net/torvald/terrarum/serialise/WriteLayerData.kt @@ -1,8 +1,9 @@ package net.torvald.terrarum.serialise -import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.EchoError +import net.torvald.terrarum.gameworld.GameWorld import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -26,11 +27,11 @@ internal object WriteLayerData { internal operator fun invoke(saveDirectoryName: String): Boolean { - val path = "${Terrarum.defaultSaveDir}/$saveDirectoryName/${LAYERS_FILENAME}" + val path = "${AppLoader.defaultSaveDir}/$saveDirectoryName/${LAYERS_FILENAME}" val tempPath = "${path}_bak" val map = (Terrarum.ingame!!.world) - val parentDir = File("${Terrarum.defaultSaveDir}/$saveDirectoryName") + val parentDir = File("${AppLoader.defaultSaveDir}/$saveDirectoryName") if (!parentDir.exists()) { parentDir.mkdir() } diff --git a/src/net/torvald/terrarum/serialise/WriteLayerDataLzma.kt b/src/net/torvald/terrarum/serialise/WriteLayerDataLzma.kt index 68e36c990..4bc8329e9 100644 --- a/src/net/torvald/terrarum/serialise/WriteLayerDataLzma.kt +++ b/src/net/torvald/terrarum/serialise/WriteLayerDataLzma.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.serialise import com.badlogic.gdx.utils.compression.Lzma +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.EchoError @@ -51,11 +52,11 @@ internal object WriteLayerDataLzma { internal operator fun invoke(): File? { val world = (Terrarum.ingame!!.world) - val path = "${Terrarum.defaultSaveDir}/tmp_$LAYERS_FILENAME${world.worldIndex}" + val path = "${AppLoader.defaultSaveDir}/tmp_$LAYERS_FILENAME${world.worldIndex}" // TODO let's try dump-on-the-disk-then-pack method... - /*val parentDir = File("${Terrarum.defaultSaveDir}/$saveDirectoryName") + /*val parentDir = File("${AppLoader.defaultSaveDir}/$saveDirectoryName") if (!parentDir.exists()) { parentDir.mkdir() } diff --git a/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt b/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt index 6b2a9de6d..ee21b4115 100644 --- a/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt +++ b/src/net/torvald/terrarum/serialise/WriteLayerDataZip.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.serialise +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.EchoError @@ -57,11 +58,11 @@ internal object WriteLayerDataZip { internal operator fun invoke(): File? { val world = (Terrarum.ingame!!.world) - val path = "${Terrarum.defaultSaveDir}/tmp_$LAYERS_FILENAME${world.worldIndex}" + val path = "${AppLoader.defaultSaveDir}/tmp_$LAYERS_FILENAME${world.worldIndex}" // TODO let's try dump-on-the-disk-then-pack method... - /*val parentDir = File("${Terrarum.defaultSaveDir}/$saveDirectoryName") + /*val parentDir = File("${AppLoader.defaultSaveDir}/$saveDirectoryName") if (!parentDir.exists()) { parentDir.mkdir() } diff --git a/src/net/torvald/terrarum/serialise/WriteMeta.kt b/src/net/torvald/terrarum/serialise/WriteMeta.kt index 19aa758de..f8f8f8f67 100644 --- a/src/net/torvald/terrarum/serialise/WriteMeta.kt +++ b/src/net/torvald/terrarum/serialise/WriteMeta.kt @@ -41,7 +41,7 @@ internal object WriteMeta { props.map { hashArray.add(DigestUtils.sha256(it)) } // open file and delete it - val metaPath = Paths.get("$Terrarum.defaultSaveDir" + + val metaPath = Paths.get("$AppLoader.defaultSaveDir" + "/$saveDirectoryName/$META_FILENAME") val metaTempPath = Files.createTempFile(metaPath.toString(), "_temp") diff --git a/src/net/torvald/terrarum/serialise/WriteWorldInfo.kt b/src/net/torvald/terrarum/serialise/WriteWorldInfo.kt index 18ce61b76..847f762b8 100644 --- a/src/net/torvald/terrarum/serialise/WriteWorldInfo.kt +++ b/src/net/torvald/terrarum/serialise/WriteWorldInfo.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.serialise import com.badlogic.gdx.Gdx +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.ModMgr import net.torvald.terrarum.Terrarum import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilder @@ -29,7 +30,7 @@ object WriteWorldInfo { internal operator fun invoke(): List? { val world = (Terrarum.ingame!!.world) - val path = "${Terrarum.defaultSaveDir}/tmp_worldinfo" + val path = "${AppLoader.defaultSaveDir}/tmp_worldinfo" val infileList = arrayOf( ModMgr.getGdxFilesFromEveryMod("blocks/blocks.csv"), diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index dadec41bf..7d8ec491f 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -135,7 +135,7 @@ class BasicDebugInfoWindow : UICanvas() { var dbgCnt = 12 - Terrarum.debugTimers.forEach { t, u -> + AppLoader.debugTimers.forEach { t, u -> printLine(batch, dbgCnt, "$ccM$t $ccG$u$ccY ns") dbgCnt++ } diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index fe16f69bf..36f011e32 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -63,7 +63,7 @@ abstract class UICanvas( get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1 /** If mouse is hovering over it and mouse is down */ val mousePushed: Boolean - get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")) + get() = mouseUp && Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) /** Called by the screen */ diff --git a/src/net/torvald/terrarum/ui/UIItem.kt b/src/net/torvald/terrarum/ui/UIItem.kt index 02ce0413c..6e3a158bb 100644 --- a/src/net/torvald/terrarum/ui/UIItem.kt +++ b/src/net/torvald/terrarum/ui/UIItem.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.ui import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.Terrarum @@ -53,7 +54,7 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1 /** If mouse is hovering over it and mouse is down */ open val mousePushed: Boolean - get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")!!) + get() = mouseUp && Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")!!) /** UI to call (show up) while mouse is up */ diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt index d1be611f4..0ea194a21 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt @@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.blockproperties.BlockCodex import com.jme3.math.FastMath +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameworld.GameWorld @@ -199,7 +200,7 @@ object LightmapRenderer { * for all lightmap[y][x] */ - Terrarum.debugTimers["Renderer.Lanterns"] = measureNanoTime { + AppLoader.debugTimers["Renderer.Lanterns"] = measureNanoTime { buildLanternmap() } // usually takes 3000 ns @@ -209,9 +210,9 @@ object LightmapRenderer { // each usually takes 8 000 000..12 000 000 miliseconds total when not threaded - if (!Terrarum.getConfigBoolean("multithreadedlight")) { + if (!AppLoader.getConfigBoolean("multithreadedlight")) { // Round 1 - Terrarum.debugTimers["Renderer.Light1"] = measureNanoTime { + AppLoader.debugTimers["Renderer.Light1"] = measureNanoTime { for (y in for_y_start - overscan_open..for_y_end) { for (x in for_x_start - overscan_open..for_x_end) { setLight(x, y, calculate(x, y, 1)) @@ -220,7 +221,7 @@ object LightmapRenderer { } // Round 2 - Terrarum.debugTimers["Renderer.Light2"] = measureNanoTime { + AppLoader.debugTimers["Renderer.Light2"] = measureNanoTime { for (y in for_y_end + overscan_open downTo for_y_start) { for (x in for_x_start - overscan_open..for_x_end) { setLight(x, y, calculate(x, y, 2)) @@ -229,7 +230,7 @@ object LightmapRenderer { } // Round 3 - Terrarum.debugTimers["Renderer.Light3"] = measureNanoTime { + AppLoader.debugTimers["Renderer.Light3"] = measureNanoTime { for (y in for_y_end + overscan_open downTo for_y_start) { for (x in for_x_end + overscan_open downTo for_x_start) { setLight(x, y, calculate(x, y, 3)) @@ -238,7 +239,7 @@ object LightmapRenderer { } // Round 4 - Terrarum.debugTimers["Renderer.Light4"] = measureNanoTime { + AppLoader.debugTimers["Renderer.Light4"] = measureNanoTime { for (y in for_y_start - overscan_open..for_y_end) { for (x in for_x_end + overscan_open downTo for_x_start) { setLight(x, y, calculate(x, y, 4)) @@ -246,14 +247,14 @@ object LightmapRenderer { } } - Terrarum.debugTimers["Renderer.LightSequential"] = - Terrarum.debugTimers["Renderer.Light1"]!! + - Terrarum.debugTimers["Renderer.Light2"]!! + - Terrarum.debugTimers["Renderer.Light3"]!! + - Terrarum.debugTimers["Renderer.Light4"]!! + AppLoader.debugTimers["Renderer.LightSequential"] = + (AppLoader.debugTimers["Renderer.Light1"]!! as Long) + + (AppLoader.debugTimers["Renderer.Light2"]!! as Long) + + (AppLoader.debugTimers["Renderer.Light3"]!! as Long) + + (AppLoader.debugTimers["Renderer.Light4"]!! as Long) } else { - Terrarum.debugTimers["Renderer.LightPre"] = measureNanoTime { + AppLoader.debugTimers["Renderer.LightPre"] = measureNanoTime { val bufferForPasses = arrayOf( lightmap.copyOf(), lightmap.copyOf(), lightmap.copyOf(), lightmap.copyOf() @@ -297,7 +298,7 @@ object LightmapRenderer { // couldn't help but do this nested timer - Terrarum.debugTimers["Renderer.LightParallel${Terrarum.THREADS}x"] = measureNanoTime { + AppLoader.debugTimers["Renderer.LightParallel${Terrarum.THREADS}x"] = measureNanoTime { calcTasks.forEachIndexed { index, list -> ThreadParallel.map(index, "LightCalculate") { index -> // this index is that index list.forEach { @@ -312,7 +313,7 @@ object LightmapRenderer { ThreadParallel.startAllWaitForDie() } - Terrarum.debugTimers["Runderer.LightPost"] = measureNanoTime { + AppLoader.debugTimers["Runderer.LightPost"] = measureNanoTime { combineTasks.forEachIndexed { index, intRange -> ThreadParallel.map(index, "LightCombine") { index -> // this index is that index for (i in intRange) { @@ -331,11 +332,11 @@ object LightmapRenderer { // get correct Renderer.LightPre by subtracting some shits - Terrarum.debugTimers["Renderer.LightParaTotal"] = Terrarum.debugTimers["Renderer.LightPre"]!! - Terrarum.debugTimers["Renderer.LightPre"] = - Terrarum.debugTimers["Renderer.LightPre"]!! - - Terrarum.debugTimers["Renderer.LightParallel${Terrarum.THREADS}x"]!! - - Terrarum.debugTimers["Runderer.LightPost"]!! + AppLoader.debugTimers["Renderer.LightParaTotal"] = AppLoader.debugTimers["Renderer.LightPre"]!! + AppLoader.debugTimers["Renderer.LightPre"] = + (AppLoader.debugTimers["Renderer.LightPre"]!! as Long) - + (AppLoader.debugTimers["Renderer.LightParallel${Terrarum.THREADS}x"]!! as Long) - + (AppLoader.debugTimers["Runderer.LightPost"]!! as Long) // accuracy may suffer (overheads maybe?) but it doesn't matter (i think...) }