mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
moved things a lot just so that splash screen shows up WHILE things load
This commit is contained in:
@@ -10,10 +10,17 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
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.GameFontBase;
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack;
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -30,10 +37,11 @@ public class AppLoader implements ApplicationListener {
|
|||||||
* AA: Major version
|
* AA: Major version
|
||||||
* BB: Minor version
|
* BB: Minor version
|
||||||
* XXXX: Revision (Repository commits, or something arbitrary)
|
* XXXX: Revision (Repository commits, or something arbitrary)
|
||||||
*
|
* <p>
|
||||||
* e.g. 0x02010034 will be translated as 2.1.52
|
* e.g. 0x02010034 will be translated as 2.1.52
|
||||||
*/
|
*/
|
||||||
public static final int VERSION_RAW = 0x00_02_04B1;
|
public static final int VERSION_RAW = 0x00_02_04B1;
|
||||||
|
|
||||||
public static final String getVERSION_STRING() {
|
public static final String getVERSION_STRING() {
|
||||||
return String.format("%d.%d.%d", VERSION_RAW >>> 24, (VERSION_RAW & 0xff0000) >>> 16, VERSION_RAW & 0xFFFF);
|
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
|
* 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
|
* @param injectScreen GDX Screen you want to run
|
||||||
*/
|
*/
|
||||||
public AppLoader(LwjglApplicationConfiguration appConfig, Screen injectScreen) {
|
public AppLoader(LwjglApplicationConfiguration appConfig, Screen injectScreen) {
|
||||||
@@ -66,6 +75,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the application with default game screen
|
* Initialise the application with default game screen
|
||||||
|
*
|
||||||
* @param appConfig LWJGL(2) Application Configuration
|
* @param appConfig LWJGL(2) Application Configuration
|
||||||
*/
|
*/
|
||||||
public AppLoader(LwjglApplicationConfiguration appConfig) {
|
public AppLoader(LwjglApplicationConfiguration appConfig) {
|
||||||
@@ -80,6 +90,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton pattern implementation in Java.
|
* Singleton pattern implementation in Java.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static AppLoader getINSTANCE() {
|
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;
|
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 int GLOBAL_RENDER_TIMER = new Random().nextInt(1020) + 1;
|
||||||
|
|
||||||
|
|
||||||
|
public static ArrayListMap debugTimers = new ArrayListMap<String, Long>();
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ShaderProgram.pedantic = false;
|
ShaderProgram.pedantic = false;
|
||||||
|
|
||||||
@@ -165,6 +181,8 @@ public class AppLoader implements ApplicationListener {
|
|||||||
private Color gradWhiteBottom = new Color(0xd8d8d8ff);
|
private Color gradWhiteBottom = new Color(0xd8d8d8ff);
|
||||||
|
|
||||||
public Screen screen;
|
public Screen screen;
|
||||||
|
public static int screenW = 0;
|
||||||
|
public static int screenH = 0;
|
||||||
|
|
||||||
public static Texture textureWhiteSquare;
|
public static Texture textureWhiteSquare;
|
||||||
|
|
||||||
@@ -189,20 +207,20 @@ public class AppLoader implements ApplicationListener {
|
|||||||
logoBatch = new SpriteBatch();
|
logoBatch = new SpriteBatch();
|
||||||
camera = new OrthographicCamera(((float) appConfig.width), ((float) appConfig.height));
|
camera = new OrthographicCamera(((float) appConfig.width), ((float) appConfig.height));
|
||||||
|
|
||||||
|
|
||||||
initViewPort(appConfig.width, 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"));
|
shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"),
|
||||||
textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
|
Gdx.files.internal("assets/4096_bayer_skyboxfill.frag")
|
||||||
|
);
|
||||||
|
shaderHicolour = new ShaderProgram(Gdx.files.internal("assets/4096.vert"),
|
||||||
shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"));
|
Gdx.files.internal("assets/hicolour.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"));
|
shaderColLUT = new ShaderProgram(Gdx.files.internal("assets/4096.vert"),
|
||||||
|
Gdx.files.internal("assets/passthru.frag")
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
fullscreenQuad = new Mesh(
|
fullscreenQuad = new Mesh(
|
||||||
true, 4, 6,
|
true, 4, 6,
|
||||||
@@ -212,31 +230,29 @@ public class AppLoader implements ApplicationListener {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fullscreenQuad.setVertices(new float[]{
|
fullscreenQuad.setVertices(new float[]{
|
||||||
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
|
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
|
||||||
((float) appConfig.width), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 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,
|
((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, ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 0f, 0f
|
||||||
});
|
});
|
||||||
fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0});
|
fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0});
|
||||||
|
|
||||||
|
|
||||||
logo = new TextureRegion(new Texture(Gdx.files.internal("assets/graphics/logo_placeholder.tga")));
|
// load configs
|
||||||
logo.flip(false, true);
|
getDefaultDirectory();
|
||||||
|
createDirs();
|
||||||
|
readConfigJson();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
|
||||||
|
if (splashDisplayed && !postInitFired) {
|
||||||
|
postInit();
|
||||||
|
postInitFired = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FrameBufferManager.begin(renderFBO);
|
FrameBufferManager.begin(renderFBO);
|
||||||
Gdx.gl.glClearColor(.094f, .094f, .094f, 0f);
|
Gdx.gl.glClearColor(.094f, .094f, .094f, 0f);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
@@ -250,7 +266,9 @@ public class AppLoader implements ApplicationListener {
|
|||||||
FrameBufferManager.begin(renderFBO);
|
FrameBufferManager.begin(renderFBO);
|
||||||
setCameraPosition(0, 0);
|
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) {
|
if (screen == null) {
|
||||||
shaderBayerSkyboxFill.begin();
|
shaderBayerSkyboxFill.begin();
|
||||||
shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined);
|
shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined);
|
||||||
@@ -276,11 +294,10 @@ public class AppLoader implements ApplicationListener {
|
|||||||
loadTimer += Gdx.graphics.getRawDeltaTime();
|
loadTimer += Gdx.graphics.getRawDeltaTime();
|
||||||
|
|
||||||
if (loadTimer >= showupTime) {
|
if (loadTimer >= showupTime) {
|
||||||
Terrarum.INSTANCE.setScreenW(appConfig.width);
|
|
||||||
Terrarum.INSTANCE.setScreenH(appConfig.height);
|
|
||||||
setScreen(Terrarum.INSTANCE);
|
setScreen(Terrarum.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// draw the screen
|
||||||
else {
|
else {
|
||||||
screen.render(Gdx.graphics.getDeltaTime());
|
screen.render(Gdx.graphics.getDeltaTime());
|
||||||
}
|
}
|
||||||
@@ -291,7 +308,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
PostProcessor.INSTANCE.draw(camera.combined, renderFBO);
|
PostProcessor.INSTANCE.draw(camera.combined, renderFBO);
|
||||||
|
|
||||||
|
|
||||||
|
splashDisplayed = true;
|
||||||
GLOBAL_RENDER_TIMER += 1;
|
GLOBAL_RENDER_TIMER += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,30 +316,35 @@ public class AppLoader implements ApplicationListener {
|
|||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
//initViewPort(width, height);
|
//initViewPort(width, height);
|
||||||
|
|
||||||
Terrarum.INSTANCE.resize(width, height);
|
screenW = width;
|
||||||
if (screen != null) screen.resize(Terrarum.INSTANCE.getWIDTH(), Terrarum.INSTANCE.getHEIGHT());
|
screenH = height;
|
||||||
|
|
||||||
|
if (screenW % 2 == 1) screenW -= 1;
|
||||||
|
if (screenH % 2 == 1) screenH -= 1;
|
||||||
|
|
||||||
|
if (screen != null) screen.resize(screenW, screenH);
|
||||||
|
|
||||||
|
|
||||||
if (renderFBO == null ||
|
if (renderFBO == null ||
|
||||||
(renderFBO.getWidth() != Terrarum.INSTANCE.getWIDTH() ||
|
(renderFBO.getWidth() != screenW ||
|
||||||
renderFBO.getHeight() != Terrarum.INSTANCE.getHEIGHT())
|
renderFBO.getHeight() != screenH)
|
||||||
) {
|
) {
|
||||||
renderFBO = new FrameBuffer(
|
renderFBO = new FrameBuffer(
|
||||||
Pixmap.Format.RGBA8888,
|
Pixmap.Format.RGBA8888,
|
||||||
Terrarum.INSTANCE.getWIDTH(),
|
screenW,
|
||||||
Terrarum.INSTANCE.getHEIGHT(),
|
screenH,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
appConfig.width = Terrarum.INSTANCE.getWIDTH();
|
appConfig.width = screenW;
|
||||||
appConfig.height = Terrarum.INSTANCE.getHEIGHT();
|
appConfig.height = screenH;
|
||||||
|
|
||||||
printdbg(this, "Resize event");
|
printdbg(this, "Resize event");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose () {
|
public void dispose() {
|
||||||
if (screen != null) screen.hide();
|
if (screen != null) screen.hide();
|
||||||
|
|
||||||
System.out.println("Goodbye !");
|
System.out.println("Goodbye !");
|
||||||
@@ -332,12 +354,12 @@ public class AppLoader implements ApplicationListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pause () {
|
public void pause() {
|
||||||
if (screen != null) screen.pause();
|
if (screen != null) screen.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resume () {
|
public void resume() {
|
||||||
if (screen != null) screen.resume();
|
if (screen != null) screen.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,6 +376,23 @@ public class AppLoader implements ApplicationListener {
|
|||||||
printdbg(this, "Screen transisiton complete: " + this.screen.getClass().getCanonicalName());
|
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) {
|
private void setCameraPosition(float newX, float newY) {
|
||||||
camera.position.set((-newX + appConfig.width / 2), (-newY + appConfig.height / 2), 0f);
|
camera.position.set((-newX + appConfig.width / 2), (-newY + appConfig.height / 2), 0f);
|
||||||
camera.update();
|
camera.update();
|
||||||
@@ -370,15 +409,226 @@ public class AppLoader implements ApplicationListener {
|
|||||||
fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0});
|
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) {
|
public static final void printdbg(Object obj, Object message) {
|
||||||
if (IS_DEVELOPMENT_BUILD) {
|
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) {
|
public static final void printdbgerr(Object obj, Object message) {
|
||||||
if (IS_DEVELOPMENT_BUILD) {
|
if (IS_DEVELOPMENT_BUILD) {
|
||||||
System.err.println("["+obj.getClass().getSimpleName()+"] "+message.toString());
|
System.err.println("[" + obj.getClass().getSimpleName() + "] " + message.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
* list of Actors that is sorted by Actors' referenceID
|
* list of Actors that is sorted by Actors' referenceID
|
||||||
*/
|
*/
|
||||||
//val ACTORCONTAINER_INITIAL_SIZE = 64
|
//val ACTORCONTAINER_INITIAL_SIZE = 64
|
||||||
val PARTICLES_MAX = Terrarum.getConfigInt("maxparticles")
|
val PARTICLES_MAX = AppLoader.getConfigInt("maxparticles")
|
||||||
//val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
//val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||||
//val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
//val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||||
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
|
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
|
||||||
@@ -362,14 +362,14 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
width = 900,
|
width = 900,
|
||||||
height = Terrarum.HEIGHT - 160,
|
height = Terrarum.HEIGHT - 160,
|
||||||
categoryWidth = 210,
|
categoryWidth = 210,
|
||||||
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
|
toggleKeyLiteral = AppLoader.getConfigInt("keyinventory")
|
||||||
)*/
|
)*/
|
||||||
/*uiInventoryPlayer.setPosition(
|
/*uiInventoryPlayer.setPosition(
|
||||||
-uiInventoryPlayer.width,
|
-uiInventoryPlayer.width,
|
||||||
70
|
70
|
||||||
)*/
|
)*/
|
||||||
uiInventoryPlayer = UIInventoryFull(player,
|
uiInventoryPlayer = UIInventoryFull(player,
|
||||||
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
|
toggleKeyLiteral = AppLoader.getConfigInt("keyinventory")
|
||||||
)
|
)
|
||||||
uiInventoryPlayer.setPosition(0, 0)
|
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) {
|
if (firstTimeRun || updateThreadWrapper.state == Thread.State.TERMINATED) {
|
||||||
updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread")
|
updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread")
|
||||||
updateThreadWrapper.start()
|
updateThreadWrapper.start()
|
||||||
@@ -529,7 +529,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
while (updateDeltaCounter >= updateRate) {
|
while (updateDeltaCounter >= updateRate) {
|
||||||
|
|
||||||
//updateGame(delta)
|
//updateGame(delta)
|
||||||
Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
||||||
|
|
||||||
updateDeltaCounter -= updateRate
|
updateDeltaCounter -= updateRate
|
||||||
updateTries++
|
updateTries++
|
||||||
@@ -544,7 +544,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
/** RENDER CODE GOES HERE */
|
/** RENDER CODE GOES HERE */
|
||||||
//renderGame(batch)
|
//renderGame(batch)
|
||||||
Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame(batch) }
|
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame(batch) }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun updateGame(delta: Float) {
|
protected fun updateGame(delta: Float) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.google.gson.JsonPrimitive
|
|||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
typealias ItemValue = KVHashMap
|
typealias ItemValue = KVHashMap
|
||||||
typealias GameConfig = KVHashMap
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2015-12-30.
|
* Created by minjaesong on 2015-12-30.
|
||||||
|
|||||||
@@ -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.glClearColor(.094f, .094f, .094f, 0f)
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
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)
|
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||||
|
|
||||||
val shader: ShaderProgram? =
|
val shader: ShaderProgram? =
|
||||||
if (Terrarum.getConfigBoolean("fxdither"))
|
if (AppLoader.getConfigBoolean("fxdither"))
|
||||||
AppLoader.shaderHicolour
|
AppLoader.shaderHicolour
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -3,26 +3,24 @@ package net.torvald.terrarum
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Screen
|
import com.badlogic.gdx.Screen
|
||||||
import com.badlogic.gdx.assets.AssetManager
|
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.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import com.google.gson.JsonArray
|
|
||||||
import com.google.gson.JsonPrimitive
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.dataclass.ArrayListMap
|
|
||||||
import net.torvald.dataclass.CircularArray
|
import net.torvald.dataclass.CircularArray
|
||||||
|
import net.torvald.getcpuname.GetCpuName
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.*
|
||||||
import net.torvald.terrarum.AppLoader.printdbgerr
|
|
||||||
import net.torvald.terrarum.gameactors.Actor
|
import net.torvald.terrarum.gameactors.Actor
|
||||||
import net.torvald.terrarum.gameactors.ActorID
|
import net.torvald.terrarum.gameactors.ActorID
|
||||||
import net.torvald.terrarum.imagefont.TinyAlphNum
|
import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
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.FeaturesDrawer
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
||||||
@@ -30,9 +28,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|||||||
import org.lwjgl.BufferUtils
|
import org.lwjgl.BufferUtils
|
||||||
import org.lwjgl.input.Controllers
|
import org.lwjgl.input.Controllers
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
|
||||||
import net.torvald.getcpuname.GetCpuName
|
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
|
|
||||||
@@ -52,11 +47,6 @@ object Terrarum : Screen {
|
|||||||
*/
|
*/
|
||||||
const val PLAYER_REF_ID: Int = 0x91A7E2
|
const val PLAYER_REF_ID: Int = 0x91A7E2
|
||||||
|
|
||||||
val debugTimers = ArrayListMap<String, Long>()
|
|
||||||
|
|
||||||
var screenW = 0
|
|
||||||
var screenH = 0
|
|
||||||
|
|
||||||
lateinit var batch: SpriteBatch
|
lateinit var batch: SpriteBatch
|
||||||
lateinit var shapeRender: ShapeRenderer // DO NOT USE!! for very limited applications e.g. WeatherMixer
|
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) {
|
inline fun inShapeRenderer(shapeRendererType: ShapeRenderer.ShapeType = ShapeRenderer.ShapeType.Filled, action: (ShapeRenderer) -> Unit) {
|
||||||
@@ -71,9 +61,9 @@ object Terrarum : Screen {
|
|||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
|
|
||||||
val WIDTH: Int
|
val WIDTH: Int
|
||||||
get() = if (screenW % 2 == 0) screenW else screenW - 1
|
get() = AppLoader.screenW
|
||||||
val HEIGHT: Int
|
val HEIGHT: Int
|
||||||
get() = if (screenH % 2 == 0) screenH else screenH - 1
|
get() = AppLoader.screenH
|
||||||
|
|
||||||
//val WIDTH_MIN = 800
|
//val WIDTH_MIN = 800
|
||||||
//val HEIGHT_MIN = 600
|
//val HEIGHT_MIN = 600
|
||||||
@@ -107,18 +97,6 @@ object Terrarum : Screen {
|
|||||||
|
|
||||||
|
|
||||||
var ingame: IngameInstance? = null
|
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<Int>(128)
|
private val javaHeapCircularArray = CircularArray<Int>(128)
|
||||||
private val nativeHeapCircularArray = CircularArray<Int>(128)
|
private val nativeHeapCircularArray = CircularArray<Int>(128)
|
||||||
@@ -142,9 +120,6 @@ object Terrarum : Screen {
|
|||||||
val memXmx: Int
|
val memXmx: Int
|
||||||
get() = (Runtime.getRuntime().maxMemory() shr 20).toInt()
|
get() = (Runtime.getRuntime().maxMemory() shr 20).toInt()
|
||||||
|
|
||||||
var environment: RunningEnvironment
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -203,8 +178,6 @@ object Terrarum : Screen {
|
|||||||
val MULTITHREAD: Boolean
|
val MULTITHREAD: Boolean
|
||||||
get() = THREADS >= 3 && getConfigBoolean("multithread")
|
get() = THREADS >= 3 && getConfigBoolean("multithread")
|
||||||
|
|
||||||
private lateinit var configDir: String
|
|
||||||
|
|
||||||
const val NAME = AppLoader.GAME_NAME
|
const val NAME = AppLoader.GAME_NAME
|
||||||
|
|
||||||
|
|
||||||
@@ -243,16 +216,6 @@ object Terrarum : Screen {
|
|||||||
println("LibGDX version ${com.badlogic.gdx.Version.VERSION}")
|
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
|
println("os.arch = $systemArch") // debug info
|
||||||
|
|
||||||
if (is32BitJVM) {
|
if (is32BitJVM) {
|
||||||
@@ -278,18 +241,19 @@ object Terrarum : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// setting environment as MOBILE precedes this code
|
||||||
environment = try {
|
if (environment != RunningEnvironment.MOBILE) {
|
||||||
Controllers.getController(0) // test if controller exists
|
environment = try {
|
||||||
if (getConfigString("pcgamepadenv") == "console")
|
Controllers.getController(0) // test if controller exists
|
||||||
RunningEnvironment.CONSOLE
|
if (getConfigString("pcgamepadenv") == "console")
|
||||||
else
|
RunningEnvironment.CONSOLE
|
||||||
|
else
|
||||||
|
RunningEnvironment.PC
|
||||||
|
}
|
||||||
|
catch (e: IndexOutOfBoundsException) {
|
||||||
RunningEnvironment.PC
|
RunningEnvironment.PC
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (e: IndexOutOfBoundsException) {
|
|
||||||
RunningEnvironment.PC
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -440,7 +404,7 @@ object Terrarum : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun render(delta: Float) {
|
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)
|
AppLoader.getINSTANCE().screen.render(deltaTime)
|
||||||
//GLOBAL_RENDER_TIMER += 1
|
//GLOBAL_RENDER_TIMER += 1
|
||||||
// moved to AppLoader; global event must be place at the apploader to prevent ACCIDENTAL forgot-to-update type of bug.
|
// 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) {
|
override fun resize(width: Int, height: Int) {
|
||||||
//var width = maxOf(width, WIDTH_MIN)
|
/*try {
|
||||||
//var height = maxOf(height, HEIGHT_MIN)
|
AppLoader.getINSTANCE().screen.resize(width, height)
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
catch (e: NullPointerException) { }
|
catch (e: NullPointerException) { }*/ // I sense circular recursion...
|
||||||
|
|
||||||
// re-calculate fullscreen quad
|
|
||||||
//updateFullscreenQuad(screenW, screenH)
|
|
||||||
|
|
||||||
//appLoader.resize(width, height)
|
|
||||||
//Gdx.graphics.setWindowedMode(width, height)
|
|
||||||
|
|
||||||
printdbg(this, "newsize: ${Gdx.graphics.width}x${Gdx.graphics.height} | internal: ${width}x$height")
|
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
|
val currentSaveDir: File
|
||||||
get() {
|
get() {
|
||||||
val file = File(defaultSaveDir + "/test")
|
val file = File(defaultSaveDir + "/test")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.gamecontroller
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Input
|
import com.badlogic.gdx.Input
|
||||||
import com.badlogic.gdx.InputAdapter
|
import com.badlogic.gdx.InputAdapter
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||||
import net.torvald.terrarum.Terrarum
|
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)
|
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
|
||||||
if (ingame.canPlayerControl) {
|
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
|
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
||||||
if (player == null) return
|
if (player == null) return
|
||||||
|
|
||||||
val itemOnGrip = player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
|
val itemOnGrip = player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
|
||||||
|
|
||||||
itemOnGrip?.let {
|
itemOnGrip?.let {
|
||||||
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary"))) {
|
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))) {
|
||||||
player.consumePrimary(it)
|
player.consumePrimary(it)
|
||||||
}
|
}
|
||||||
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) {
|
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
|
||||||
player.consumeSecondary(it)
|
player.consumeSecondary(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,8 +72,8 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
|||||||
ingame.actorNowPlaying?.keyDown(keycode)
|
ingame.actorNowPlaying?.keyDown(keycode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Terrarum.getConfigIntArray("keyquickselalt").contains(keycode)
|
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|
||||||
|| keycode == Terrarum.getConfigInt("keyquicksel")) {
|
|| keycode == AppLoader.getConfigInt("keyquicksel")) {
|
||||||
ingame.uiPieMenu.setAsOpen()
|
ingame.uiPieMenu.setAsOpen()
|
||||||
ingame.uiQuickBar.setAsClose()
|
ingame.uiQuickBar.setAsClose()
|
||||||
}
|
}
|
||||||
@@ -90,8 +93,8 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun keyUp(keycode: Int): Boolean {
|
override fun keyUp(keycode: Int): Boolean {
|
||||||
if (Terrarum.getConfigIntArray("keyquickselalt").contains(keycode)
|
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|
||||||
|| keycode == Terrarum.getConfigInt("keyquicksel")) {
|
|| keycode == AppLoader.getConfigInt("keyquicksel")) {
|
||||||
ingame.uiPieMenu.setAsClose()
|
ingame.uiPieMenu.setAsClose()
|
||||||
ingame.uiQuickBar.setAsOpen()
|
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
|
// 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 (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)
|
ingame.worldPrimaryClickEnd(Terrarum.deltaTime)
|
||||||
}
|
}
|
||||||
if (button == Terrarum.getConfigInt("mousesecondary")) {
|
if (button == AppLoader.getConfigInt("mousesecondary")) {
|
||||||
ingame.worldSecondaryClickEnd(Terrarum.deltaTime)
|
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
|
// 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 (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)
|
ingame.worldPrimaryClickStart(Terrarum.deltaTime)
|
||||||
}
|
}
|
||||||
if (button == Terrarum.getConfigInt("mousesecondary")) {
|
if (button == AppLoader.getConfigInt("mousesecondary")) {
|
||||||
ingame.worldSecondaryClickStart(Terrarum.deltaTime)
|
ingame.worldSecondaryClickStart(Terrarum.deltaTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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, NOP;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -138,7 +138,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
while (updateDeltaCounter >= updateRate) {
|
while (updateDeltaCounter >= updateRate) {
|
||||||
|
|
||||||
//updateGame(delta)
|
//updateGame(delta)
|
||||||
Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
||||||
|
|
||||||
updateDeltaCounter -= updateRate
|
updateDeltaCounter -= updateRate
|
||||||
updateTries++
|
updateTries++
|
||||||
@@ -153,7 +153,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
/** RENDER CODE GOES HERE */
|
/** RENDER CODE GOES HERE */
|
||||||
//renderGame(batch)
|
//renderGame(batch)
|
||||||
Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateGame(delta: Float) {
|
private fun updateGame(delta: Float) {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
* list of Actors that is sorted by Actors' referenceID
|
* list of Actors that is sorted by Actors' referenceID
|
||||||
*/
|
*/
|
||||||
//val ACTORCONTAINER_INITIAL_SIZE = 64
|
//val ACTORCONTAINER_INITIAL_SIZE = 64
|
||||||
val PARTICLES_MAX = Terrarum.getConfigInt("maxparticles")
|
val PARTICLES_MAX = AppLoader.getConfigInt("maxparticles")
|
||||||
//val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
//val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||||
//val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
//val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||||
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
|
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
|
||||||
@@ -305,14 +305,14 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
width = 900,
|
width = 900,
|
||||||
height = Terrarum.HEIGHT - 160,
|
height = Terrarum.HEIGHT - 160,
|
||||||
categoryWidth = 210,
|
categoryWidth = 210,
|
||||||
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
|
toggleKeyLiteral = AppLoader.getConfigInt("keyinventory")
|
||||||
)*/
|
)*/
|
||||||
/*uiInventoryPlayer.setPosition(
|
/*uiInventoryPlayer.setPosition(
|
||||||
-uiInventoryPlayer.width,
|
-uiInventoryPlayer.width,
|
||||||
70
|
70
|
||||||
)*/
|
)*/
|
||||||
uiInventoryPlayer = UIInventoryFull(actorNowPlaying,
|
uiInventoryPlayer = UIInventoryFull(actorNowPlaying,
|
||||||
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
|
toggleKeyLiteral = AppLoader.getConfigInt("keyinventory")
|
||||||
)
|
)
|
||||||
uiInventoryPlayer.setPosition(0, 0)
|
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) {
|
if (firstTimeRun || updateThreadWrapper.state == Thread.State.TERMINATED) {
|
||||||
updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread")
|
updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread")
|
||||||
updateThreadWrapper.start()
|
updateThreadWrapper.start()
|
||||||
@@ -485,7 +485,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
while (updateDeltaCounter >= renderRate) {
|
while (updateDeltaCounter >= renderRate) {
|
||||||
|
|
||||||
//updateGame(delta)
|
//updateGame(delta)
|
||||||
Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
AppLoader.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
|
||||||
|
|
||||||
updateDeltaCounter -= renderRate
|
updateDeltaCounter -= renderRate
|
||||||
updateTries++
|
updateTries++
|
||||||
@@ -501,7 +501,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
/** RENDER CODE GOES HERE */
|
/** RENDER CODE GOES HERE */
|
||||||
//renderGame(batch)
|
//renderGame(batch)
|
||||||
Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
AppLoader.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun updateGame(delta: Float) {
|
protected fun updateGame(delta: Float) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.console
|
package net.torvald.terrarum.modulebasegame.console
|
||||||
|
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.utils.JsonWriter
|
import net.torvald.terrarum.utils.JsonWriter
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.console.ConsoleCommand
|
import net.torvald.terrarum.console.ConsoleCommand
|
||||||
@@ -20,7 +21,7 @@ internal object ExportAV : ConsoleCommand {
|
|||||||
|
|
||||||
JsonWriter.writeToFile(
|
JsonWriter.writeToFile(
|
||||||
player.actorValue,
|
player.actorValue,
|
||||||
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
|
AppLoader.defaultDir + "/Exports/" + args[1] + ".json")
|
||||||
|
|
||||||
Echo("ExportAV: exported to " + args[1] + ".json")
|
Echo("ExportAV: exported to " + args[1] + ".json")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.console
|
package net.torvald.terrarum.modulebasegame.console
|
||||||
|
|
||||||
import net.torvald.colourutil.Col4096
|
import net.torvald.colourutil.Col4096
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.utils.RasterWriter
|
import net.torvald.terrarum.utils.RasterWriter
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
@@ -78,7 +79,7 @@ internal object ExportMap : ConsoleCommand {
|
|||||||
mapDataPointer += 3
|
mapDataPointer += 3
|
||||||
}
|
}
|
||||||
|
|
||||||
val dir = Terrarum.defaultDir + "/Exports/"
|
val dir = AppLoader.defaultDir + "/Exports/"
|
||||||
val dirAsFile = File(dir)
|
val dirAsFile = File(dir)
|
||||||
if (!dirAsFile.exists()) {
|
if (!dirAsFile.exists()) {
|
||||||
dirAsFile.mkdir()
|
dirAsFile.mkdir()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.console
|
|||||||
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.console.ConsoleCommand
|
import net.torvald.terrarum.console.ConsoleCommand
|
||||||
import net.torvald.terrarum.console.Echo
|
import net.torvald.terrarum.console.Echo
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
@@ -23,7 +24,7 @@ internal object GsonTest : ConsoleCommand {
|
|||||||
val bufferedWriter: BufferedWriter
|
val bufferedWriter: BufferedWriter
|
||||||
val writer: FileWriter
|
val writer: FileWriter
|
||||||
try {
|
try {
|
||||||
writer = FileWriter(Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
|
writer = FileWriter(AppLoader.defaultDir + "/Exports/" + args[1] + ".json")
|
||||||
bufferedWriter = BufferedWriter(writer)
|
bufferedWriter = BufferedWriter(writer)
|
||||||
|
|
||||||
bufferedWriter.write(jsonString)
|
bufferedWriter.write(jsonString)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.bipolarClamp
|
import net.torvald.terrarum.bipolarClamp
|
||||||
import net.torvald.terrarum.gameactors.*
|
import net.torvald.terrarum.gameactors.*
|
||||||
@@ -214,17 +215,17 @@ open class ActorHumanoid(
|
|||||||
|
|
||||||
private fun updateGamerControlBox() {
|
private fun updateGamerControlBox() {
|
||||||
if (isGamer) {
|
if (isGamer) {
|
||||||
isUpDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyup"))
|
isUpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyup"))
|
||||||
isLeftDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyleft"))
|
isLeftDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyleft"))
|
||||||
isDownDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keydown"))
|
isDownDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keydown"))
|
||||||
isRightDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyright"))
|
isRightDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyright"))
|
||||||
isJumpDown = Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyjump"))
|
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump"))
|
||||||
|
|
||||||
if (Terrarum.controller != null) {
|
if (Terrarum.controller != null) {
|
||||||
axisX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlstickx"))
|
axisX = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadlstickx"))
|
||||||
axisY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadlsticky"))
|
axisY = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadlsticky"))
|
||||||
axisRX = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrstickx"))
|
axisRX = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadrstickx"))
|
||||||
axisRY = Terrarum.controller!!.getAxisValue(Terrarum.getConfigInt("joypadrsticky"))
|
axisRY = Terrarum.controller!!.getAxisValue(AppLoader.getConfigInt("joypadrsticky"))
|
||||||
|
|
||||||
// deadzonning
|
// deadzonning
|
||||||
if (Math.abs(axisX) < Terrarum.CONTROLLER_DEADZONE) axisX = 0f
|
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(axisRX) < Terrarum.CONTROLLER_DEADZONE) axisRX = 0f
|
||||||
if (Math.abs(axisRY) < Terrarum.CONTROLLER_DEADZONE) axisRY = 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)
|
Terrarum.controller!!.isButtonPressed(GAMEPAD_JUMP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,11 +291,11 @@ open class ActorHumanoid(
|
|||||||
// ↑F, ↓S
|
// ↑F, ↓S
|
||||||
if (isRightDown && !isLeftDown) {
|
if (isRightDown && !isLeftDown) {
|
||||||
walkHorizontal(false, AXIS_KEYBOARD)
|
walkHorizontal(false, AXIS_KEYBOARD)
|
||||||
prevHMoveKey = Terrarum.getConfigInt("keyright")
|
prevHMoveKey = AppLoader.getConfigInt("keyright")
|
||||||
} // ↓F, ↑S
|
} // ↓F, ↑S
|
||||||
else if (isLeftDown && !isRightDown) {
|
else if (isLeftDown && !isRightDown) {
|
||||||
walkHorizontal(true, AXIS_KEYBOARD)
|
walkHorizontal(true, AXIS_KEYBOARD)
|
||||||
prevHMoveKey = Terrarum.getConfigInt("keyleft")
|
prevHMoveKey = AppLoader.getConfigInt("keyleft")
|
||||||
} // ↓F, ↓S
|
} // ↓F, ↓S
|
||||||
/*else if (isLeftDown && isRightDown) {
|
/*else if (isLeftDown && isRightDown) {
|
||||||
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
|
if (prevHMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_LEFT)) {
|
||||||
@@ -318,11 +319,11 @@ open class ActorHumanoid(
|
|||||||
// ↑E, ↓D
|
// ↑E, ↓D
|
||||||
if (isDownDown && !isUpDown) {
|
if (isDownDown && !isUpDown) {
|
||||||
walkVertical(false, AXIS_KEYBOARD)
|
walkVertical(false, AXIS_KEYBOARD)
|
||||||
prevVMoveKey = Terrarum.getConfigInt("keydown")
|
prevVMoveKey = AppLoader.getConfigInt("keydown")
|
||||||
} // ↓E, ↑D
|
} // ↓E, ↑D
|
||||||
else if (isUpDown && !isDownDown) {
|
else if (isUpDown && !isDownDown) {
|
||||||
walkVertical(true, AXIS_KEYBOARD)
|
walkVertical(true, AXIS_KEYBOARD)
|
||||||
prevVMoveKey = Terrarum.getConfigInt("keyup")
|
prevVMoveKey = AppLoader.getConfigInt("keyup")
|
||||||
} // ↓E, ↓D
|
} // ↓E, ↓D
|
||||||
/*else if (isUpDown && isDownDown) {
|
/*else if (isUpDown && isDownDown) {
|
||||||
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
|
if (prevVMoveKey == KeyMap.getKeyCode(EnumKeyFunc.MOVE_UP)) {
|
||||||
@@ -360,7 +361,7 @@ open class ActorHumanoid(
|
|||||||
|
|
||||||
override fun keyDown(keycode: Int): Boolean {
|
override fun keyDown(keycode: Int): Boolean {
|
||||||
// quickslot (quickbar)
|
// quickslot (quickbar)
|
||||||
val quickbarKeys = Terrarum.getConfigIntArray("keyquickbars")
|
val quickbarKeys = AppLoader.getConfigIntArray("keyquickbars")
|
||||||
if (keycode in quickbarKeys) {
|
if (keycode in quickbarKeys) {
|
||||||
actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = quickbarKeys.indexOf(keycode)
|
actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = quickbarKeys.indexOf(keycode)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package net.torvald.terrarum.modulebasegame.ui
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
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.Second
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ class Notification : UICanvas() {
|
|||||||
|
|
||||||
override var height: Int = msgUI.height
|
override var height: Int = msgUI.height
|
||||||
private val visibleTime = Math.min(
|
private val visibleTime = Math.min(
|
||||||
Terrarum.getConfigInt("notificationshowuptime"),
|
AppLoader.getConfigInt("notificationshowuptime"),
|
||||||
SHOWUP_MAX
|
SHOWUP_MAX
|
||||||
)
|
)
|
||||||
private var displayTimer = 0f
|
private var displayTimer = 0f
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
|
|||||||
ELuptimer += delta
|
ELuptimer += delta
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouseUp || Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyinteract"))) {
|
if (mouseUp || Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyinteract"))) {
|
||||||
ELuptimer = 0f
|
ELuptimer = 0f
|
||||||
ELon = true
|
ELon = true
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
|
|||||||
val playerTilePos = player.hIntTilewiseHitbox
|
val playerTilePos = player.hIntTilewiseHitbox
|
||||||
val tempCelsius = -273f + ((Terrarum.ingame as? Ingame)?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f)
|
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_KELVIN -> tempCelsius.times(1.8f).plus(32f).roundInt()
|
||||||
TEMP_CELCIUS -> tempCelsius.roundInt()
|
TEMP_CELCIUS -> tempCelsius.roundInt()
|
||||||
else -> tempCelsius.plus(273.15f).roundInt()
|
else -> tempCelsius.plus(273.15f).roundInt()
|
||||||
@@ -86,10 +86,10 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
|
|||||||
|
|
||||||
sb.append(temperature.abs())
|
sb.append(temperature.abs())
|
||||||
|
|
||||||
if (Terrarum.getConfigInt("temperatureunit") == 1) {
|
if (AppLoader.getConfigInt("temperatureunit") == 1) {
|
||||||
sb.append('"') // celsius superscript
|
sb.append('"') // celsius superscript
|
||||||
}
|
}
|
||||||
else if (Terrarum.getConfigInt("temperatureunit") == -1) {
|
else if (AppLoader.getConfigInt("temperatureunit") == -1) {
|
||||||
sb.append('#') // fahrenheit subscript
|
sb.append('#') // fahrenheit subscript
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -157,10 +157,10 @@ package net.torvald.terrarum.modulebasegame.ui
|
|||||||
private var isEncumbered = false
|
private var isEncumbered = false
|
||||||
|
|
||||||
|
|
||||||
private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // 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() = Terrarum.getConfigInt("keyright") // 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() = Terrarum.getConfigInt("keyup") // 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() = Terrarum.getConfigInt("keydown") // 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 {
|
init {
|
||||||
|
|||||||
@@ -8,11 +8,10 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
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.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
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.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
@@ -43,7 +42,7 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
||||||
val listControlHelp: String
|
val listControlHelp: String
|
||||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
get() = if (AppLoader.environment == RunningEnvironment.PC)
|
||||||
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||||
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" +
|
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" +
|
||||||
"${0xe011.toChar()}..${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
|
"${0xe011.toChar()}..${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
|
|||||||
ELuptimer += delta
|
ELuptimer += delta
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouseUp || Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyinteract"))) {
|
if (mouseUp || Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyinteract"))) {
|
||||||
ELuptimer = 0f
|
ELuptimer = 0f
|
||||||
ELon = true
|
ELon = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import net.torvald.terrarum.ui.UIItemTextButtonList
|
|||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (Terrarum.getConfigBoolean("__debug")) {
|
if (AppLoader.getConfigBoolean("__debug")) {
|
||||||
menuLabels.addAll(arrayOf(
|
menuLabels.addAll(arrayOf(
|
||||||
" Development Tools $",
|
" Development Tools $",
|
||||||
"Building Maker"
|
"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) }
|
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 = { _, _, _ ->
|
menubar.buttons[menuLabels.indexOf("Building Maker")].clickOnceListener = { _, _, _ ->
|
||||||
this.setAsClose()
|
this.setAsClose()
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package net.torvald.terrarum.serialise
|
package net.torvald.terrarum.serialise
|
||||||
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.AppLoader
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileFilter
|
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
object SavegameLedger {
|
object SavegameLedger {
|
||||||
|
|
||||||
private val SAVE_DIRECTORY = File(Terrarum.defaultSaveDir)
|
private val SAVE_DIRECTORY = File(AppLoader.defaultSaveDir)
|
||||||
|
|
||||||
fun hasSavegameDirectory() = SAVE_DIRECTORY.exists() && SAVE_DIRECTORY.isDirectory
|
fun hasSavegameDirectory() = SAVE_DIRECTORY.exists() && SAVE_DIRECTORY.isDirectory
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.serialise
|
package net.torvald.terrarum.serialise
|
||||||
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.AppLoader
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
@@ -20,11 +20,11 @@ internal object WriteCSV {
|
|||||||
//val itemCSV = CSVFetcher.readCSVasString(ItemCodex.CSV_PATH)
|
//val itemCSV = CSVFetcher.readCSVasString(ItemCodex.CSV_PATH)
|
||||||
//val matCSV = CSVFetcher.readCSVasString(MaterialCodex.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}")
|
"/$saveDirectoryName/${META_FILENAME_TILE}")
|
||||||
val pathItem = Paths.get("${Terrarum.defaultSaveDir}" +
|
val pathItem = Paths.get("${AppLoader.defaultSaveDir}" +
|
||||||
"/$saveDirectoryName/${META_FILENAME_ITEM}")
|
"/$saveDirectoryName/${META_FILENAME_ITEM}")
|
||||||
val pathMat = Paths.get("${Terrarum.defaultSaveDir}" +
|
val pathMat = Paths.get("${AppLoader.defaultSaveDir}" +
|
||||||
"/$saveDirectoryName/${META_FILENAME_MAT}")
|
"/$saveDirectoryName/${META_FILENAME_MAT}")
|
||||||
val tempPathTile = Files.createTempFile(pathTile.toString(), "_temp")
|
val tempPathTile = Files.createTempFile(pathTile.toString(), "_temp")
|
||||||
val tempPathItem = Files.createTempFile(pathItem.toString(), "_temp")
|
val tempPathItem = Files.createTempFile(pathItem.toString(), "_temp")
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package net.torvald.terrarum.serialise
|
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.Terrarum
|
||||||
import net.torvald.terrarum.console.EchoError
|
import net.torvald.terrarum.console.EchoError
|
||||||
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -26,11 +27,11 @@ internal object WriteLayerData {
|
|||||||
|
|
||||||
|
|
||||||
internal operator fun invoke(saveDirectoryName: String): Boolean {
|
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 tempPath = "${path}_bak"
|
||||||
val map = (Terrarum.ingame!!.world)
|
val map = (Terrarum.ingame!!.world)
|
||||||
|
|
||||||
val parentDir = File("${Terrarum.defaultSaveDir}/$saveDirectoryName")
|
val parentDir = File("${AppLoader.defaultSaveDir}/$saveDirectoryName")
|
||||||
if (!parentDir.exists()) {
|
if (!parentDir.exists()) {
|
||||||
parentDir.mkdir()
|
parentDir.mkdir()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.terrarum.serialise
|
package net.torvald.terrarum.serialise
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.compression.Lzma
|
import com.badlogic.gdx.utils.compression.Lzma
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.console.EchoError
|
import net.torvald.terrarum.console.EchoError
|
||||||
@@ -51,11 +52,11 @@ internal object WriteLayerDataLzma {
|
|||||||
internal operator fun invoke(): File? {
|
internal operator fun invoke(): File? {
|
||||||
val world = (Terrarum.ingame!!.world)
|
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...
|
// 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()) {
|
if (!parentDir.exists()) {
|
||||||
parentDir.mkdir()
|
parentDir.mkdir()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.torvald.terrarum.serialise
|
package net.torvald.terrarum.serialise
|
||||||
|
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.console.EchoError
|
import net.torvald.terrarum.console.EchoError
|
||||||
@@ -57,11 +58,11 @@ internal object WriteLayerDataZip {
|
|||||||
internal operator fun invoke(): File? {
|
internal operator fun invoke(): File? {
|
||||||
val world = (Terrarum.ingame!!.world)
|
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...
|
// 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()) {
|
if (!parentDir.exists()) {
|
||||||
parentDir.mkdir()
|
parentDir.mkdir()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ internal object WriteMeta {
|
|||||||
props.map { hashArray.add(DigestUtils.sha256(it)) }
|
props.map { hashArray.add(DigestUtils.sha256(it)) }
|
||||||
|
|
||||||
// open file and delete it
|
// open file and delete it
|
||||||
val metaPath = Paths.get("$Terrarum.defaultSaveDir" +
|
val metaPath = Paths.get("$AppLoader.defaultSaveDir" +
|
||||||
"/$saveDirectoryName/$META_FILENAME")
|
"/$saveDirectoryName/$META_FILENAME")
|
||||||
val metaTempPath = Files.createTempFile(metaPath.toString(), "_temp")
|
val metaTempPath = Files.createTempFile(metaPath.toString(), "_temp")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.terrarum.serialise
|
package net.torvald.terrarum.serialise
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilder
|
import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilder
|
||||||
@@ -29,7 +30,7 @@ object WriteWorldInfo {
|
|||||||
internal operator fun invoke(): List<File>? {
|
internal operator fun invoke(): List<File>? {
|
||||||
val world = (Terrarum.ingame!!.world)
|
val world = (Terrarum.ingame!!.world)
|
||||||
|
|
||||||
val path = "${Terrarum.defaultSaveDir}/tmp_worldinfo"
|
val path = "${AppLoader.defaultSaveDir}/tmp_worldinfo"
|
||||||
|
|
||||||
val infileList = arrayOf(
|
val infileList = arrayOf(
|
||||||
ModMgr.getGdxFilesFromEveryMod("blocks/blocks.csv"),
|
ModMgr.getGdxFilesFromEveryMod("blocks/blocks.csv"),
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
|
|
||||||
|
|
||||||
var dbgCnt = 12
|
var dbgCnt = 12
|
||||||
Terrarum.debugTimers.forEach { t, u ->
|
AppLoader.debugTimers.forEach { t, u ->
|
||||||
printLine(batch, dbgCnt, "$ccM$t $ccG$u$ccY ns")
|
printLine(batch, dbgCnt, "$ccM$t $ccG$u$ccY ns")
|
||||||
dbgCnt++
|
dbgCnt++
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ abstract class UICanvas(
|
|||||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||||
/** If mouse is hovering over it and mouse is down */
|
/** If mouse is hovering over it and mouse is down */
|
||||||
val mousePushed: Boolean
|
val mousePushed: Boolean
|
||||||
get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary"))
|
get() = mouseUp && Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))
|
||||||
|
|
||||||
|
|
||||||
/** Called by the screen */
|
/** Called by the screen */
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.Terrarum
|
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
|
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||||
/** If mouse is hovering over it and mouse is down */
|
/** If mouse is hovering over it and mouse is down */
|
||||||
open val mousePushed: Boolean
|
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 */
|
/** UI to call (show up) while mouse is up */
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.Texture
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
@@ -199,7 +200,7 @@ object LightmapRenderer {
|
|||||||
* for all lightmap[y][x]
|
* for all lightmap[y][x]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Terrarum.debugTimers["Renderer.Lanterns"] = measureNanoTime {
|
AppLoader.debugTimers["Renderer.Lanterns"] = measureNanoTime {
|
||||||
buildLanternmap()
|
buildLanternmap()
|
||||||
} // usually takes 3000 ns
|
} // usually takes 3000 ns
|
||||||
|
|
||||||
@@ -209,9 +210,9 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
// each usually takes 8 000 000..12 000 000 miliseconds total when not threaded
|
// each usually takes 8 000 000..12 000 000 miliseconds total when not threaded
|
||||||
|
|
||||||
if (!Terrarum.getConfigBoolean("multithreadedlight")) {
|
if (!AppLoader.getConfigBoolean("multithreadedlight")) {
|
||||||
// Round 1
|
// Round 1
|
||||||
Terrarum.debugTimers["Renderer.Light1"] = measureNanoTime {
|
AppLoader.debugTimers["Renderer.Light1"] = measureNanoTime {
|
||||||
for (y in for_y_start - overscan_open..for_y_end) {
|
for (y in for_y_start - overscan_open..for_y_end) {
|
||||||
for (x in for_x_start - overscan_open..for_x_end) {
|
for (x in for_x_start - overscan_open..for_x_end) {
|
||||||
setLight(x, y, calculate(x, y, 1))
|
setLight(x, y, calculate(x, y, 1))
|
||||||
@@ -220,7 +221,7 @@ object LightmapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Round 2
|
// 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 (y in for_y_end + overscan_open downTo for_y_start) {
|
||||||
for (x in for_x_start - overscan_open..for_x_end) {
|
for (x in for_x_start - overscan_open..for_x_end) {
|
||||||
setLight(x, y, calculate(x, y, 2))
|
setLight(x, y, calculate(x, y, 2))
|
||||||
@@ -229,7 +230,7 @@ object LightmapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Round 3
|
// 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 (y in for_y_end + overscan_open downTo for_y_start) {
|
||||||
for (x in for_x_end + overscan_open downTo for_x_start) {
|
for (x in for_x_end + overscan_open downTo for_x_start) {
|
||||||
setLight(x, y, calculate(x, y, 3))
|
setLight(x, y, calculate(x, y, 3))
|
||||||
@@ -238,7 +239,7 @@ object LightmapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Round 4
|
// Round 4
|
||||||
Terrarum.debugTimers["Renderer.Light4"] = measureNanoTime {
|
AppLoader.debugTimers["Renderer.Light4"] = measureNanoTime {
|
||||||
for (y in for_y_start - overscan_open..for_y_end) {
|
for (y in for_y_start - overscan_open..for_y_end) {
|
||||||
for (x in for_x_end + overscan_open downTo for_x_start) {
|
for (x in for_x_end + overscan_open downTo for_x_start) {
|
||||||
setLight(x, y, calculate(x, y, 4))
|
setLight(x, y, calculate(x, y, 4))
|
||||||
@@ -246,14 +247,14 @@ object LightmapRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Terrarum.debugTimers["Renderer.LightSequential"] =
|
AppLoader.debugTimers["Renderer.LightSequential"] =
|
||||||
Terrarum.debugTimers["Renderer.Light1"]!! +
|
(AppLoader.debugTimers["Renderer.Light1"]!! as Long) +
|
||||||
Terrarum.debugTimers["Renderer.Light2"]!! +
|
(AppLoader.debugTimers["Renderer.Light2"]!! as Long) +
|
||||||
Terrarum.debugTimers["Renderer.Light3"]!! +
|
(AppLoader.debugTimers["Renderer.Light3"]!! as Long) +
|
||||||
Terrarum.debugTimers["Renderer.Light4"]!!
|
(AppLoader.debugTimers["Renderer.Light4"]!! as Long)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Terrarum.debugTimers["Renderer.LightPre"] = measureNanoTime {
|
AppLoader.debugTimers["Renderer.LightPre"] = measureNanoTime {
|
||||||
|
|
||||||
val bufferForPasses = arrayOf(
|
val bufferForPasses = arrayOf(
|
||||||
lightmap.copyOf(), lightmap.copyOf(), lightmap.copyOf(), lightmap.copyOf()
|
lightmap.copyOf(), lightmap.copyOf(), lightmap.copyOf(), lightmap.copyOf()
|
||||||
@@ -297,7 +298,7 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
// couldn't help but do this nested timer
|
// 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 ->
|
calcTasks.forEachIndexed { index, list ->
|
||||||
ThreadParallel.map(index, "LightCalculate") { index -> // this index is that index
|
ThreadParallel.map(index, "LightCalculate") { index -> // this index is that index
|
||||||
list.forEach {
|
list.forEach {
|
||||||
@@ -312,7 +313,7 @@ object LightmapRenderer {
|
|||||||
ThreadParallel.startAllWaitForDie()
|
ThreadParallel.startAllWaitForDie()
|
||||||
}
|
}
|
||||||
|
|
||||||
Terrarum.debugTimers["Runderer.LightPost"] = measureNanoTime {
|
AppLoader.debugTimers["Runderer.LightPost"] = measureNanoTime {
|
||||||
combineTasks.forEachIndexed { index, intRange ->
|
combineTasks.forEachIndexed { index, intRange ->
|
||||||
ThreadParallel.map(index, "LightCombine") { index -> // this index is that index
|
ThreadParallel.map(index, "LightCombine") { index -> // this index is that index
|
||||||
for (i in intRange) {
|
for (i in intRange) {
|
||||||
@@ -331,11 +332,11 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
|
|
||||||
// get correct Renderer.LightPre by subtracting some shits
|
// get correct Renderer.LightPre by subtracting some shits
|
||||||
Terrarum.debugTimers["Renderer.LightParaTotal"] = Terrarum.debugTimers["Renderer.LightPre"]!!
|
AppLoader.debugTimers["Renderer.LightParaTotal"] = AppLoader.debugTimers["Renderer.LightPre"]!!
|
||||||
Terrarum.debugTimers["Renderer.LightPre"] =
|
AppLoader.debugTimers["Renderer.LightPre"] =
|
||||||
Terrarum.debugTimers["Renderer.LightPre"]!! -
|
(AppLoader.debugTimers["Renderer.LightPre"]!! as Long) -
|
||||||
Terrarum.debugTimers["Renderer.LightParallel${Terrarum.THREADS}x"]!! -
|
(AppLoader.debugTimers["Renderer.LightParallel${Terrarum.THREADS}x"]!! as Long) -
|
||||||
Terrarum.debugTimers["Runderer.LightPost"]!!
|
(AppLoader.debugTimers["Runderer.LightPost"]!! as Long)
|
||||||
|
|
||||||
// accuracy may suffer (overheads maybe?) but it doesn't matter (i think...)
|
// accuracy may suffer (overheads maybe?) but it doesn't matter (i think...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user