no more context fuckups on apploader

This commit is contained in:
minjaesong
2019-07-02 04:57:43 +09:00
parent da1c752996
commit 1a00f73d52
81 changed files with 635 additions and 563 deletions

2
.idea/misc.xml generated
View File

@@ -38,7 +38,7 @@
<property name="caretWidth" class="java.lang.Integer" /> <property name="caretWidth" class="java.lang.Integer" />
</properties> </properties>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8.0_212" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

Binary file not shown.

View File

@@ -22,15 +22,36 @@ object UnsafeHelper {
val ptr = unsafe.allocateMemory(size) val ptr = unsafe.allocateMemory(size)
return UnsafePtr(ptr, size) return UnsafePtr(ptr, size)
} }
fun memcpy(src: UnsafePtr, fromIndex: Long, dest: UnsafePtr, toIndex: Long, copyLength: Long) {
// unsafe.copyMemory(srcAddress, destAddress, bytes); in case no src for the sun.misc.Unsafe is available :D
unsafe.copyMemory(src.ptr + fromIndex, dest.ptr + toIndex, copyLength)
}
fun memcpy(srcAddress: Long, destAddress: Long, copyLength: Long) = unsafe.copyMemory(srcAddress, destAddress, copyLength)
} }
/** /**
* To allocate a memory, use UnsafeHelper.allocate(long) * To allocate a memory, use UnsafeHelper.allocate(long)
*
* All the getFloat/Int/whatever methods will follow the endianness of your system,
* e.g. it'll be Little Endian on x86, Big Endian on PPC, User-defined on ARM; therefore these functions should not be
* used when the portability matters (e.g. Savefile). In such situations, do byte-wise operations will be needed.
*/ */
class UnsafePtr(val ptr: Long, val allocSize: Long) { class UnsafePtr(pointer: Long, allocSize: Long) {
var destroyed = false var destroyed = false
private set private set
var ptr: Long = pointer
private set
var size: Long = allocSize
private set
fun realloc(newSize: Long) {
ptr = UnsafeHelper.unsafe.reallocateMemory(ptr, newSize)
}
fun destroy() { fun destroy() {
if (!destroyed) { if (!destroyed) {
UnsafeHelper.unsafe.freeMemory(ptr) UnsafeHelper.unsafe.freeMemory(ptr)
@@ -42,7 +63,7 @@ class UnsafePtr(val ptr: Long, val allocSize: Long) {
} }
} }
private inline fun checkNullPtr(index: Long) { private inline fun checkNullPtr(index: Long) { // ignore what IDEA says and do inline this
if (destroyed) throw NullPointerException("The pointer is already destroyed ($this)") if (destroyed) throw NullPointerException("The pointer is already destroyed ($this)")
// OOB Check: debugging purposes only -- comment out for the production // OOB Check: debugging purposes only -- comment out for the production
@@ -59,6 +80,11 @@ class UnsafePtr(val ptr: Long, val allocSize: Long) {
return UnsafeHelper.unsafe.getFloat(ptr + index) return UnsafeHelper.unsafe.getFloat(ptr + index)
} }
fun getInt(index: Long): Int {
checkNullPtr(index)
return UnsafeHelper.unsafe.getInt(ptr + index)
}
operator fun set(index: Long, value: Byte) { operator fun set(index: Long, value: Byte) {
checkNullPtr(index) checkNullPtr(index)
UnsafeHelper.unsafe.putByte(ptr + index, value) UnsafeHelper.unsafe.putByte(ptr + index, value)
@@ -69,10 +95,15 @@ class UnsafePtr(val ptr: Long, val allocSize: Long) {
UnsafeHelper.unsafe.putFloat(ptr + index, value) UnsafeHelper.unsafe.putFloat(ptr + index, value)
} }
fun fillWith(byte: Byte) { fun setInt(index: Long, value: Int) {
UnsafeHelper.unsafe.setMemory(ptr, allocSize, byte) checkNullPtr(index)
UnsafeHelper.unsafe.putInt(ptr + index, value)
} }
override fun toString() = "0x${ptr.toString(16)} with size $allocSize" fun fillWith(byte: Byte) {
UnsafeHelper.unsafe.setMemory(ptr, size, byte)
}
override fun toString() = "0x${ptr.toString(16)} with size $size"
override fun equals(other: Any?) = this.ptr == (other as UnsafePtr).ptr override fun equals(other: Any?) = this.ptr == (other as UnsafePtr).ptr
} }

View File

@@ -1,9 +1,6 @@
package net.torvald.terrarum; package net.torvald.terrarum;
import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.*;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.AudioDevice; import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
@@ -13,7 +10,9 @@ 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.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.github.strikerx3.jxinput.XInputDevice; import com.github.strikerx3.jxinput.XInputDevice;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@@ -21,14 +20,15 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import net.torvald.gdx.graphics.PixmapIO2; import net.torvald.gdx.graphics.PixmapIO2;
import net.torvald.getcpuname.GetCpuName; import net.torvald.getcpuname.GetCpuName;
import net.torvald.terrarum.concurrent.ThreadParallel;
import net.torvald.terrarum.controller.GdxControllerAdapter; import net.torvald.terrarum.controller.GdxControllerAdapter;
import net.torvald.terrarum.controller.TerrarumController; import net.torvald.terrarum.controller.TerrarumController;
import net.torvald.terrarum.controller.XinputControllerAdapter; import net.torvald.terrarum.controller.XinputControllerAdapter;
import net.torvald.terrarum.gamecontroller.KeyToggler; import net.torvald.terrarum.gamecontroller.KeyToggler;
import net.torvald.terrarum.gameworld.GameWorld; import net.torvald.terrarum.gameworld.GameWorld;
import net.torvald.terrarum.imagefont.TinyAlphNum; import net.torvald.terrarum.imagefont.TinyAlphNum;
import net.torvald.terrarum.modulebasegame.Ingame;
import net.torvald.terrarum.modulebasegame.IngameRenderer; import net.torvald.terrarum.modulebasegame.IngameRenderer;
import net.torvald.terrarum.modulebasegame.TerrarumIngame;
import net.torvald.terrarum.utils.JsonFetcher; import net.torvald.terrarum.utils.JsonFetcher;
import net.torvald.terrarum.utils.JsonWriter; import net.torvald.terrarum.utils.JsonWriter;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase; import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
@@ -51,13 +51,23 @@ import static net.torvald.terrarum.TerrarumKt.gdxClearAndSetBlend;
*/ */
public class AppLoader implements ApplicationListener { public class AppLoader implements ApplicationListener {
public static final String GAME_NAME = "Terrarum";
public static final String COPYRIGHT_DATE_NAME = "Copyright 2013-2019 Torvald (minjaesong)";
/** /**
* 0xAA_BB_XXXX * <p>
* AA: Major version * Version numbering that follows Semantic Versioning 2.0.0 (https://semver.org/)
* BB: Minor version * </p>
* XXXX: Revision (Repository commits, or something arbitrary) *
* <p>
* 0xAA_BB_XXXX, where:
* </p>
* <li>AA: Major version</li>
* <li>BB: Minor version</li>
* <li>XXXX: Patch version</li>
* <p> * <p>
* e.g. 0x02010034 will be translated as 2.1.52 * e.g. 0x02010034 will be translated as 2.1.52
* </p>
*/ */
public static final int VERSION_RAW = 0x00_02_0590; public static final int VERSION_RAW = 0x00_02_0590;
@@ -110,6 +120,9 @@ public class AppLoader implements ApplicationListener {
/** /**
* Singleton pattern implementation in Java. * Singleton pattern implementation in Java.
* *
* This function exists because the limitation in the Java language and the design of the GDX itself, where
* not everything (more like not every method) can be static.
*
* @return * @return
*/ */
public static AppLoader getINSTANCE() { public static AppLoader getINSTANCE() {
@@ -119,8 +132,6 @@ public class AppLoader implements ApplicationListener {
return INSTANCE; return INSTANCE;
} }
public static final String GAME_NAME = "Terrarum";
public static final String COPYRIGHT_DATE_NAME = "Copyright 2013-2019 Torvald (minjaesong)";
public static String GAME_LOCALE = System.getProperty("user.language") + System.getProperty("user.country"); public static String GAME_LOCALE = System.getProperty("user.language") + System.getProperty("user.country");
public static final String systemArch = System.getProperty("os.arch"); public static final String systemArch = System.getProperty("os.arch");
@@ -129,8 +140,13 @@ public class AppLoader implements ApplicationListener {
public static String renderer = "(a super-fancy virtual photoradiator)"; public static String renderer = "(a super-fancy virtual photoradiator)";
public static String rendererVendor = "(radiosity)"; public static String rendererVendor = "(radiosity)";
public static int THREADS = ThreadParallel.INSTANCE.getThreadCount();
public static boolean MULTITHREAD;
public static final boolean is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64"); public static final boolean is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64");
public static int GL_VERSION;
public static final int MINIMAL_GL_VERSION = 320;
public static final float TV_SAFE_GRAPHICS = 0.05f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf) public static final float TV_SAFE_GRAPHICS = 0.05f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
public static final float TV_SAFE_ACTION = 0.035f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf) public static final float TV_SAFE_ACTION = 0.035f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
@@ -206,15 +222,18 @@ public class AppLoader implements ApplicationListener {
public static ShaderProgram shaderColLUT; public static ShaderProgram shaderColLUT;
public static Mesh fullscreenQuad; public static Mesh fullscreenQuad;
private OrthographicCamera camera; private static OrthographicCamera camera;
private SpriteBatch logoBatch; private static SpriteBatch logoBatch;
public static TextureRegion logo; public static TextureRegion logo;
public static AudioDevice audioDevice; public static AudioDevice audioDevice;
private com.badlogic.gdx.graphics.Color gradWhiteTop = new com.badlogic.gdx.graphics.Color(0xf8f8f8ff); public static SpriteBatch batch;
private com.badlogic.gdx.graphics.Color gradWhiteBottom = new com.badlogic.gdx.graphics.Color(0xd8d8d8ff); public static ShapeRenderer shapeRender;
public Screen screen; private static com.badlogic.gdx.graphics.Color gradWhiteTop = new com.badlogic.gdx.graphics.Color(0xf8f8f8ff);
private static com.badlogic.gdx.graphics.Color gradWhiteBottom = new com.badlogic.gdx.graphics.Color(0xd8d8d8ff);
private static Screen currenScreen;
public static int screenW = 0; public static int screenW = 0;
public static int screenH = 0; public static int screenH = 0;
@@ -234,10 +253,10 @@ public class AppLoader implements ApplicationListener {
public static final double UPDATE_RATE = 1.0 / 60.0; // TODO set it like 1/100, because apparent framerate is limited by update rate public static final double UPDATE_RATE = 1.0 / 60.0; // TODO set it like 1/100, because apparent framerate is limited by update rate
private float loadTimer = 0f; private static float loadTimer = 0f;
private final float showupTime = 100f / 1000f; private static final float showupTime = 100f / 1000f;
private FrameBuffer renderFBO; private static FrameBuffer renderFBO;
public static CommonResourcePool resourcePool; public static CommonResourcePool resourcePool;
public static HashSet<File> tempFilePool = new HashSet(); public static HashSet<File> tempFilePool = new HashSet();
@@ -294,6 +313,7 @@ public class AppLoader implements ApplicationListener {
appConfig.foregroundFPS = getConfigInt("displayfps"); appConfig.foregroundFPS = getConfigInt("displayfps");
appConfig.title = GAME_NAME; appConfig.title = GAME_NAME;
appConfig.forceExit = false; appConfig.forceExit = false;
appConfig.samples = 4; // force the AA on, if the graphics driver didn't do already
// load app icon // load app icon
int[] appIconSizes = new int[]{256,128,64,32,16}; int[] appIconSizes = new int[]{256,128,64,32,16};
@@ -310,11 +330,36 @@ public class AppLoader implements ApplicationListener {
//KeyToggler.INSTANCE.forceSet(Input.Keys.F11, true); //KeyToggler.INSTANCE.forceSet(Input.Keys.F11, true);
} }
// set some more configuration vars
MULTITHREAD = ThreadParallel.INSTANCE.getThreadCount() >= 3 && getConfigBoolean("multithread");
new LwjglApplication(new AppLoader(appConfig), appConfig); new LwjglApplication(new AppLoader(appConfig), appConfig);
} }
@Override @Override
public void create() { public void create() {
Gdx.graphics.setContinuousRendering(true);
GAME_LOCALE = getConfigString("language");
printdbg(this, "locale = " + GAME_LOCALE);
String glInfo = Gdx.graphics.getGLVersion().getDebugVersionString();
GL_VERSION = Gdx.graphics.getGLVersion().getMajorVersion() * 100 +
Gdx.graphics.getGLVersion().getMinorVersion() * 10 +
Gdx.graphics.getGLVersion().getReleaseVersion();
System.out.println("GL_VERSION = " + GL_VERSION);
System.out.println("GL info:\n" + glInfo); // debug info
if (GL_VERSION < MINIMAL_GL_VERSION) {
// TODO notify properly
throw new GdxRuntimeException("Graphics device not capable -- device's GL_VERSION: " + GL_VERSION +
", required: " + MINIMAL_GL_VERSION);
}
resourcePool = CommonResourcePool.INSTANCE; resourcePool = CommonResourcePool.INSTANCE;
resourcePool.addToLoadingList("blockmarkings_common", () -> new TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16, 0, 0, 0, 0, false)); resourcePool.addToLoadingList("blockmarkings_common", () -> new TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16, 0, 0, 0, 0, false));
@@ -325,6 +370,9 @@ 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));
batch = new SpriteBatch();
shapeRender = new ShapeRenderer();
initViewPort(appConfig.width, appConfig.height); initViewPort(appConfig.width, appConfig.height);
// logo here :p // logo here :p
@@ -416,6 +464,10 @@ public class AppLoader implements ApplicationListener {
postInit(); postInit();
} }
AppLoader.setDebugTime("GDX.rawDelta", (long) (Gdx.graphics.getRawDeltaTime() * 1000_000_000f));
AppLoader.setDebugTime("GDX.smtDelta", (long) (Gdx.graphics.getDeltaTime() * 1000_000_000f));
FrameBufferManager.begin(renderFBO); FrameBufferManager.begin(renderFBO);
gdxClearAndSetBlend(.094f, .094f, .094f, 0f); gdxClearAndSetBlend(.094f, .094f, .094f, 0f);
setCameraPosition(0, 0); setCameraPosition(0, 0);
@@ -423,7 +475,7 @@ public class AppLoader implements ApplicationListener {
// draw splash screen when predefined screen is null // draw splash screen when predefined screen is null
// because in normal operation, the only time screen == null is when the app is cold-launched // 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 // you can't have a text drawn here :v
if (screen == null) { if (currenScreen == null) {
shaderBayerSkyboxFill.begin(); shaderBayerSkyboxFill.begin();
shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined); shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined);
shaderBayerSkyboxFill.setUniformf("parallax_size", 0f); shaderBayerSkyboxFill.setUniformf("parallax_size", 0f);
@@ -450,15 +502,20 @@ public class AppLoader implements ApplicationListener {
if (loadTimer >= showupTime) { if (loadTimer >= showupTime) {
// hand over the scene control to this single class; Terrarum must call // hand over the scene control to this single class; Terrarum must call
// 'AppLoader.getINSTANCE().screen.render(delta)', this is not redundant at all! // 'AppLoader.getINSTANCE().screen.render(delta)', this is not redundant at all!
setScreen(Terrarum.INSTANCE);
printdbg(this, "!! Force set current screen and ingame instance to TitleScreen !!");
IngameInstance title = new TitleScreen(batch);
Terrarum.INSTANCE.setCurrentIngameInstance(title);
setScreen(title);
} }
} }
// draw the screen // draw the screen
else { else {
screen.render((float) UPDATE_RATE); currenScreen.render((float) UPDATE_RATE);
} }
KeyToggler.INSTANCE.update(screen instanceof Ingame); KeyToggler.INSTANCE.update(currenScreen instanceof TerrarumIngame);
// nested FBOs are just not a thing in GL! // nested FBOs are just not a thing in GL!
net.torvald.terrarum.FrameBufferManager.end(); net.torvald.terrarum.FrameBufferManager.end();
@@ -489,6 +546,7 @@ public class AppLoader implements ApplicationListener {
splashDisplayed = true; splashDisplayed = true;
GLOBAL_RENDER_TIMER += 1; GLOBAL_RENDER_TIMER += 1;
} }
@Override @Override
@@ -506,7 +564,7 @@ public class AppLoader implements ApplicationListener {
if (screenW % 2 == 1) screenW -= 1; if (screenW % 2 == 1) screenW -= 1;
if (screenH % 2 == 1) screenH -= 1; if (screenH % 2 == 1) screenH -= 1;
if (screen != null) screen.resize(screenW, screenH); if (currenScreen != null) currenScreen.resize(screenW, screenH);
if (renderFBO == null || if (renderFBO == null ||
@@ -539,9 +597,9 @@ public class AppLoader implements ApplicationListener {
System.out.println("Goodbye !"); System.out.println("Goodbye !");
if (screen != null) { if (currenScreen != null) {
screen.hide(); currenScreen.hide();
screen.dispose(); currenScreen.dispose();
} }
//IngameRenderer.INSTANCE.dispose(); //IngameRenderer.INSTANCE.dispose();
@@ -549,7 +607,6 @@ public class AppLoader implements ApplicationListener {
//MinimapComposer.INSTANCE.dispose(); //MinimapComposer.INSTANCE.dispose();
//FloatDrawer.INSTANCE.dispose(); //FloatDrawer.INSTANCE.dispose();
//Terrarum.INSTANCE.dispose();
shaderBayerSkyboxFill.dispose(); shaderBayerSkyboxFill.dispose();
shaderHicolour.dispose(); shaderHicolour.dispose();
@@ -573,43 +630,55 @@ public class AppLoader implements ApplicationListener {
GameWorld.Companion.makeNullWorld().dispose(); GameWorld.Companion.makeNullWorld().dispose();
Terrarum.INSTANCE.dispose();
deleteTempfiles(); deleteTempfiles();
} }
@Override @Override
public void pause() { public void pause() {
if (screen != null) screen.pause(); if (currenScreen != null) currenScreen.pause();
} }
@Override @Override
public void resume() { public void resume() {
if (screen != null) screen.resume(); if (currenScreen != null) currenScreen.resume();
} }
public void setScreen(Screen screen) { public static void setScreen(Screen screen) {
printdbg(this, "Changing screen to " + screen.getClass().getCanonicalName()); printdbg("[AppLoader-Static]", "Changing screen to " + screen.getClass().getCanonicalName());
// this whole thing is directtly copied from com.badlogic.gdx.Game // this whole thing is directtly copied from com.badlogic.gdx.Game
if (this.screen != null) { if (currenScreen != null) {
this.screen.hide(); printdbg("[AppLoader-Static]", "Screen before change: " + currenScreen.getClass().getCanonicalName());
this.screen.dispose();
currenScreen.hide();
currenScreen.dispose();
} }
this.screen = screen; else {
if (this.screen != null) { printdbg("[AppLoader-Static]", "Screen before change: null");
this.screen.show();
this.screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
} }
currenScreen = screen;
currenScreen.show();
currenScreen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
System.gc(); System.gc();
printdbg(this, "Screen transisiton complete: " + this.screen.getClass().getCanonicalName()); printdbg("[AppLoader-Static]", "Screen transition complete: " + currenScreen.getClass().getCanonicalName());
} }
/** /**
* Init stuffs which needs GL context * Init stuffs which needs GL context
*/ */
private void postInit() { private void postInit() {
Terrarum.initialise();
textureWhiteSquare = new Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga")); textureWhiteSquare = new Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"));
textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest); textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);

View File

@@ -925,7 +925,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
actorContainer.forEachIndexed { i, actor -> actorContainer.forEachIndexed { i, actor ->
if (actor is ActorWithBody) { if (actor is ActorWithBody) {
batch.color = Color.WHITE batch.color = Color.WHITE
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
actor.referenceID.toString(), actor.referenceID.toString(),
actor.hitbox.startX.toFloat(), actor.hitbox.startX.toFloat(),
actor.hitbox.canonicalY.toFloat() + 4 actor.hitbox.canonicalY.toFloat() + 4
@@ -950,12 +950,12 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// velocity // velocity
batch.color = Color.CHARTREUSE//GameFontBase.codeToCol["g"] batch.color = Color.CHARTREUSE//GameFontBase.codeToCol["g"]
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
"${0x7F.toChar()}X ${actor.externalForce.x}", "${0x7F.toChar()}X ${actor.externalForce.x}",
actor.hitbox.startX.toFloat(), actor.hitbox.startX.toFloat(),
actor.hitbox.canonicalY.toFloat() + 4 + 8 actor.hitbox.canonicalY.toFloat() + 4 + 8
) )
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
"${0x7F.toChar()}Y ${actor.externalForce.y}", "${0x7F.toChar()}Y ${actor.externalForce.y}",
actor.hitbox.startX.toFloat(), actor.hitbox.startX.toFloat(),
actor.hitbox.canonicalY.toFloat() + 4 + 8 * 2 actor.hitbox.canonicalY.toFloat() + 4 + 8 * 2

View File

@@ -60,7 +60,7 @@ object GlslTilingTest : ApplicationAdapter() {
//ErrorDisp.title = "Error in shader ${shader.vertexShaderSource}" //ErrorDisp.title = "Error in shader ${shader.vertexShaderSource}"
//ErrorDisp.text = shader.log.split('\n') //ErrorDisp.text = shader.log.split('\n')
//AppLoader.getINSTANCE().setScreen(ErrorDisp) //AppLoader.setScreen(ErrorDisp)
System.exit(1) System.exit(1)
} }

View File

@@ -8,8 +8,8 @@ import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.util.HistoryArray
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.util.HistoryArray
/** /**
* Created by minjaesong on 2017-07-13. * Created by minjaesong on 2017-07-13.
@@ -97,10 +97,10 @@ object LoadScreen : ScreenAdapter() {
textFbo = FrameBuffer( textFbo = FrameBuffer(
Pixmap.Format.RGBA4444, Pixmap.Format.RGBA4444,
maxOf( maxOf(
Terrarum.fontGame.getWidth(Lang["MENU_IO_LOADING"]), AppLoader.fontGame.getWidth(Lang["MENU_IO_LOADING"]),
Terrarum.fontGame.getWidth(Lang["ERROR_GENERIC_TEXT"]) AppLoader.fontGame.getWidth(Lang["ERROR_GENERIC_TEXT"])
), ),
Terrarum.fontGame.lineHeight.toInt(), AppLoader.fontGame.lineHeight.toInt(),
true true
) )
@@ -122,7 +122,7 @@ object LoadScreen : ScreenAdapter() {
override fun render(delta: Float) { override fun render(delta: Float) {
val delta = Gdx.graphics.rawDeltaTime val delta = Gdx.graphics.rawDeltaTime
glideDispY = Terrarum.HEIGHT - 100f - Terrarum.fontGame.lineHeight glideDispY = Terrarum.HEIGHT - 100f - AppLoader.fontGame.lineHeight
arrowObjGlideSize = arrowObjTex.width + 2f * Terrarum.WIDTH arrowObjGlideSize = arrowObjTex.width + 2f * Terrarum.WIDTH
@@ -155,7 +155,7 @@ object LoadScreen : ScreenAdapter() {
val textToPrint = if (errorTrapped) Lang["ERROR_GENERIC_TEXT"] else Lang["MENU_IO_LOADING"] val textToPrint = if (errorTrapped) Lang["ERROR_GENERIC_TEXT"] else Lang["MENU_IO_LOADING"]
val textWidth = Terrarum.fontGame.getWidth(textToPrint).toFloat() val textWidth = AppLoader.fontGame.getWidth(textToPrint).toFloat()
if (!doContextChange) { if (!doContextChange) {
// draw text to FBO // draw text to FBO
@@ -164,20 +164,20 @@ object LoadScreen : ScreenAdapter() {
blendNormal(Terrarum.batch) blendNormal(Terrarum.batch)
Terrarum.fontGame AppLoader.fontGame
it.color = Color.WHITE it.color = Color.WHITE
Terrarum.fontGame.draw(it, textToPrint, ((textFbo.width - textWidth) / 2).toInt().toFloat(), 0f) AppLoader.fontGame.draw(it, textToPrint, ((textFbo.width - textWidth) / 2).toInt().toFloat(), 0f)
blendMul(Terrarum.batch) blendMul(Terrarum.batch)
// draw colour overlay, flipped // draw colour overlay, flipped
it.draw(textOverlayTex, it.draw(textOverlayTex,
(textFbo.width - textWidth) / 2f, (textFbo.width - textWidth) / 2f,
Terrarum.fontGame.lineHeight, AppLoader.fontGame.lineHeight,
textWidth, textWidth,
-Terrarum.fontGame.lineHeight -AppLoader.fontGame.lineHeight
) )
} }
} }
@@ -234,15 +234,15 @@ object LoadScreen : ScreenAdapter() {
// message backgrounds // message backgrounds
it.color = messageBackgroundColour it.color = messageBackgroundColour
it.fillRect(0f, 60f, Terrarum.WIDTH.toFloat(), 40f + (messages.size) * Terrarum.fontGame.lineHeight) it.fillRect(0f, 60f, Terrarum.WIDTH.toFloat(), 40f + (messages.size) * AppLoader.fontGame.lineHeight)
// log messages // log messages
it.color = messageForegroundColour it.color = messageForegroundColour
for (i in 0 until messages.elemCount) { for (i in 0 until messages.elemCount) {
Terrarum.fontGame.draw(it, AppLoader.fontGame.draw(it,
messages[i] ?: "", messages[i] ?: "",
AppLoader.getTvSafeGraphicsWidth() + 16f, AppLoader.getTvSafeGraphicsWidth() + 16f,
80f + (messages.size - i - 1) * Terrarum.fontGame.lineHeight 80f + (messages.size - i - 1) * AppLoader.fontGame.lineHeight
) )
} }
} }
@@ -259,15 +259,15 @@ object LoadScreen : ScreenAdapter() {
// message backgrounds // message backgrounds
it.color = messageBackgroundColour it.color = messageBackgroundColour
it.fillRect(0f, 60f, Terrarum.WIDTH.toFloat(), 40f + (messages.size) * Terrarum.fontGame.lineHeight) it.fillRect(0f, 60f, Terrarum.WIDTH.toFloat(), 40f + (messages.size) * AppLoader.fontGame.lineHeight)
// log messages // log messages
it.color = messageForegroundColour it.color = messageForegroundColour
for (i in 0 until messages.elemCount) { for (i in 0 until messages.elemCount) {
Terrarum.fontGame.draw(it, AppLoader.fontGame.draw(it,
messages[i] ?: "", messages[i] ?: "",
AppLoader.getTvSafeGraphicsWidth() + 16f, AppLoader.getTvSafeGraphicsWidth() + 16f,
80f + (messages.size - i - 1) * Terrarum.fontGame.lineHeight 80f + (messages.size - i - 1) * AppLoader.fontGame.lineHeight
) )
} }
} }
@@ -276,7 +276,7 @@ object LoadScreen : ScreenAdapter() {
Thread.sleep(80) Thread.sleep(80)
Terrarum.setScreen(screenToLoad!!) AppLoader.setScreen(screenToLoad!!)
} }
} }

View File

@@ -0,0 +1,61 @@
package net.torvald.terrarum;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.Texture;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
import java.io.File;
/**
* Created by minjaesong on 2019-06-27.
*/
public class MusicComposerApp extends ApplicationAdapter {
public static LwjglApplicationConfiguration appConfig;
public static GameFontBase fontGame;
public MusicComposerApp(LwjglApplicationConfiguration appConfig) {
this.appConfig = appConfig;
}
public void main(String[] args) {
LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
appConfig.useGL30 = true; // utilising some GL trickeries, need this to be TRUE
appConfig.resizable = false;//true;
//appConfig.width = 1110; // photographic ratio (1.5:1)
//appConfig.height = 740; // photographic ratio (1.5:1)
appConfig.width = 1000;;;
appConfig.height = 666;
appConfig.backgroundFPS = 9999;
appConfig.foregroundFPS = 9999;
appConfig.title = "Speelklok";
appConfig.forceExit = false;
// load app icon
int[] appIconSizes = new int[]{256,128,64,32,16};
for (int size : appIconSizes) {
String name = "assets/appicon" + size + ".png";
if (new File("./" + name).exists()) {
appConfig.addIcon(name, Files.FileType.Internal);
}
}
new LwjglApplication(new MusicComposerApp(appConfig), appConfig);
}
@Override
public void create() {
fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true,
Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 256, false
);
}
@Override
public void dispose() {
super.dispose();
}
}

View File

@@ -0,0 +1,7 @@
package net.torvald.terrarum
/**
* Created by minjaesong on 2019-06-27.
*/
class MusicComposerStandalone {
}

View File

@@ -10,21 +10,17 @@ 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.ShapeRenderer import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.Disposable
import com.badlogic.gdx.utils.GdxRuntimeException
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.AppLoader.* import net.torvald.terrarum.AppLoader.*
import net.torvald.terrarum.concurrent.ThreadParallel
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.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
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 net.torvald.util.CircularArray import net.torvald.util.CircularArray
import org.lwjgl.BufferUtils
import java.io.File import java.io.File
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
@@ -38,15 +34,15 @@ typealias RGBA8888 = Int
* *
* LibGDX Version Created by minjaesong on 2017-06-15. * LibGDX Version Created by minjaesong on 2017-06-15.
*/ */
object Terrarum : Screen, Disposable { object Terrarum : Disposable {
/** /**
* All singleplayer "Player" must have this exact reference ID. * All singleplayer "Player" must have this exact reference ID.
*/ */
const val PLAYER_REF_ID: Int = 0x91A7E2 const val PLAYER_REF_ID: Int = 0x91A7E2
lateinit var batch: SpriteBatch var batch: SpriteBatch = AppLoader.batch
lateinit var shapeRender: ShapeRenderer // DO NOT USE!! for very limited applications e.g. WeatherMixer var shapeRender: ShapeRenderer = AppLoader.shapeRender // 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) {
shapeRender.begin(shapeRendererType) shapeRender.begin(shapeRendererType)
action(shapeRender) action(shapeRender)
@@ -85,6 +81,7 @@ object Terrarum : Screen, Disposable {
/** Current ingame instance the game is holding */ /** Current ingame instance the game is holding */
var ingame: IngameInstance? = null var ingame: IngameInstance? = null
private set
private val javaHeapCircularArray = CircularArray<Int>(64) private val javaHeapCircularArray = CircularArray<Int>(64)
private val nativeHeapCircularArray = CircularArray<Int>(64) private val nativeHeapCircularArray = CircularArray<Int>(64)
@@ -118,11 +115,6 @@ object Terrarum : Screen, Disposable {
} }
val fontGame: GameFontBase = AppLoader.fontGame
val fontSmallNumbers: TinyAlphNum = AppLoader.fontSmallNumbers
// 0x0 - 0xF: Game-related // 0x0 - 0xF: Game-related
// 0x10 - 0x1F: Config // 0x10 - 0x1F: Config
// 0x100 and onward: unit tests for dev // 0x100 and onward: unit tests for dev
@@ -144,20 +136,6 @@ object Terrarum : Screen, Disposable {
val STATE_ID_TOOL_NOISEGEN = 0x200 val STATE_ID_TOOL_NOISEGEN = 0x200
val STATE_ID_TOOL_RUMBLE_DIAGNOSIS = 0x201 val STATE_ID_TOOL_RUMBLE_DIAGNOSIS = 0x201
/** Available CPU threads */
val THREADS = ThreadParallel.threadCount //Runtime.getRuntime().availableProcessors() + 1
/**
* If the game is multithreading.
* True if:
*
* THREADS >= 2 and config "multithread" is true
*/
val MULTITHREAD: Boolean
get() = THREADS >= 3 && getConfigBoolean("multithread")
const val NAME = AppLoader.GAME_NAME
lateinit var testTexture: Texture lateinit var testTexture: Texture
@@ -170,7 +148,7 @@ object Terrarum : Screen, Disposable {
println("[Terrarum] init called by:") println("[Terrarum] init called by:")
Thread.currentThread().stackTrace.forEach { println("... $it") } Thread.currentThread().stackTrace.forEach { println("... $it") }
println("[Terrarum] $NAME version ${AppLoader.getVERSION_STRING()}") println("[Terrarum] ${AppLoader.GAME_NAME} version ${AppLoader.getVERSION_STRING()}")
println("[Terrarum] LibGDX version ${com.badlogic.gdx.Version.VERSION}") println("[Terrarum] LibGDX version ${com.badlogic.gdx.Version.VERSION}")
@@ -193,6 +171,11 @@ object Terrarum : Screen, Disposable {
} }
@JvmStatic fun initialise() {
// dummy init method
}
val RENDER_FPS = getConfigInt("displayfps") val RENDER_FPS = getConfigInt("displayfps")
val USE_VSYNC = getConfigBoolean("usevsync") val USE_VSYNC = getConfigBoolean("usevsync")
var VSYNC = USE_VSYNC var VSYNC = USE_VSYNC
@@ -202,7 +185,7 @@ object Terrarum : Screen, Disposable {
Gdx.graphics.glVersion.minorVersion * 10 + Gdx.graphics.glVersion.minorVersion * 10 +
Gdx.graphics.glVersion.releaseVersion Gdx.graphics.glVersion.releaseVersion
val MINIMAL_GL_VERSION = 210 val MINIMAL_GL_VERSION = 210
val GL_MAX_TEXTURE_SIZE: Int /*val GL_MAX_TEXTURE_SIZE: Int
get() { get() {
val intBuffer = BufferUtils.createIntBuffer(16) // size must be at least 16, or else LWJGL complains val intBuffer = BufferUtils.createIntBuffer(16) // size must be at least 16, or else LWJGL complains
Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_SIZE, intBuffer) Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_SIZE, intBuffer)
@@ -211,33 +194,28 @@ object Terrarum : Screen, Disposable {
return intBuffer.get() return intBuffer.get()
} }
val MINIMAL_GL_MAX_TEXTURE_SIZE = 4096 val MINIMAL_GL_MAX_TEXTURE_SIZE = 4096*/
override fun show() { fun setCurrentIngameInstance(ingame: IngameInstance) {
this.ingame = ingame
printdbg(this, "Accepting new ingame instance '${ingame.javaClass.canonicalName}', called by:")
Thread.currentThread().stackTrace.forEach { printdbg(this, it) }
}
private fun showxxx() {
testTexture = Texture(Gdx.files.internal("./assets/test_texture.tga")) testTexture = Texture(Gdx.files.internal("./assets/test_texture.tga"))
val glInfo = Gdx.graphics.glVersion.debugVersionString
println("GL_VERSION = $GL_VERSION")
println("GL_MAX_TEXTURE_SIZE = $GL_MAX_TEXTURE_SIZE")
println("GL info:\n$glInfo") // debug info
if (GL_VERSION < MINIMAL_GL_VERSION || GL_MAX_TEXTURE_SIZE < MINIMAL_GL_MAX_TEXTURE_SIZE) {
// TODO notify properly
throw GdxRuntimeException("Graphics device not capable -- device's GL_VERSION: $GL_VERSION, required: $MINIMAL_GL_VERSION; GL_MAX_TEXTURE_SIZE: $GL_MAX_TEXTURE_SIZE, required: $MINIMAL_GL_MAX_TEXTURE_SIZE")
}
// resize fullscreen quad? // resize fullscreen quad?
TextureRegionPack.globalFlipY = true // !! TO MAKE LEGACY CODE RENDER ON ITS POSITION !! TextureRegionPack.globalFlipY = true // !! TO MAKE LEGACY CODE RENDER ON ITS POSITION !!
Gdx.graphics.isContinuousRendering = true Gdx.graphics.isContinuousRendering = true
batch = SpriteBatch() //batch = SpriteBatch()
shapeRender = ShapeRenderer() //shapeRender = ShapeRenderer()
AppLoader.GAME_LOCALE = getConfigString("language") AppLoader.GAME_LOCALE = getConfigString("language")
@@ -257,25 +235,7 @@ object Terrarum : Screen, Disposable {
// title screen // title screen
AppLoader.getINSTANCE().setScreen(TitleScreen(batch)) AppLoader.setScreen(TitleScreen(batch))
}
fun setScreen(screen: Screen) {
AppLoader.getINSTANCE().setScreen(screen)
}
override fun render(delta: Float) {
AppLoader.setDebugTime("GDX.rawDelta", Gdx.graphics.rawDeltaTime.times(1000_000_000f).toLong())
AppLoader.setDebugTime("GDX.smtDelta", Gdx.graphics.deltaTime.times(1000_000_000f).toLong())
AppLoader.getINSTANCE().screen.render(delta)
}
override fun pause() {
AppLoader.getINSTANCE().screen.pause()
}
override fun resume() {
AppLoader.getINSTANCE().screen.resume()
} }
/** Don't call this! Call AppLoader.dispose() */ /** Don't call this! Call AppLoader.dispose() */
@@ -284,16 +244,13 @@ object Terrarum : Screen, Disposable {
ingame?.dispose() ingame?.dispose()
} }
override fun hide() {
AppLoader.getINSTANCE().screen.hide()
}
/** For the actual resize, call AppLoader.resize() */ /** For the actual resize, call AppLoader.resize() */
override fun resize(width: Int, height: Int) { /*fun resize(width: Int, height: Int) {
ingame?.resize(width, height) ingame?.resize(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")
} }*/

View File

@@ -2,7 +2,6 @@ package net.torvald.terrarum
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputAdapter import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Pixmap
@@ -20,8 +19,8 @@ import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.HumanoidNPC import net.torvald.terrarum.modulebasegame.gameactors.HumanoidNPC
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
@@ -35,7 +34,9 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
/** /**
* Created by minjaesong on 2017-09-02. * Created by minjaesong on 2017-09-02.
*/ */
class TitleScreen(val batch: SpriteBatch) : Screen { class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
// todo register titlescreen as the ingame, similar in a way that the buildingmaker did
var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
@@ -229,7 +230,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
} }
fun renderScreen() { fun renderScreen() {
Gdx.graphics.setTitle(Ingame.getCanonicalTitle()) Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
//camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) //camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
@@ -267,16 +268,16 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
) )
COPYTING.forEachIndexed { index, s -> COPYTING.forEachIndexed { index, s ->
val textWidth = Terrarum.fontGame.getWidth(s) val textWidth = AppLoader.fontGame.getWidth(s)
Terrarum.fontGame.draw(batch, s, AppLoader.fontGame.draw(batch, s,
(Terrarum.WIDTH - textWidth - 1f).toInt().toFloat(), (Terrarum.WIDTH - textWidth - 1f).toInt().toFloat(),
(Terrarum.HEIGHT - Terrarum.fontGame.lineHeight * (COPYTING.size - index) - 1f).toInt().toFloat() (Terrarum.HEIGHT - AppLoader.fontGame.lineHeight * (COPYTING.size - index) - 1f).toInt().toFloat()
) )
} }
Terrarum.fontGame.draw(batch, "${AppLoader.GAME_NAME} ${AppLoader.getVERSION_STRING()}", AppLoader.fontGame.draw(batch, "${AppLoader.GAME_NAME} ${AppLoader.getVERSION_STRING()}",
1f.toInt().toFloat(), 1f.toInt().toFloat(),
(Terrarum.HEIGHT - Terrarum.fontGame.lineHeight - 1f).toInt().toFloat() (Terrarum.HEIGHT - AppLoader.fontGame.lineHeight - 1f).toInt().toFloat()
) )
} }
@@ -317,7 +318,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
fun setCameraPosition(newX: Float, newY: Float) { fun setCameraPosition(newX: Float, newY: Float) {
Ingame.setCameraPosition(batch, camera, newX, newY) TerrarumIngame.setCameraPosition(batch, camera, newX, newY)
} }
@@ -415,4 +416,5 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
TODO("not implemented") TODO("not implemented")
} }
} }
} }

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
@@ -104,7 +104,7 @@ class UIItemInventoryElem(
batch.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol batch.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol
// draw name of the item // draw name of the item
if (AppLoader.IS_DEVELOPMENT_BUILD) { if (AppLoader.IS_DEVELOPMENT_BUILD) {
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
// print static id, dynamic id, and count // print static id, dynamic id, and count
"${item!!.originalID}/${item!!.dynamicID}" + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1) "$fwsp!!$amountString!!" else ""), "${item!!.originalID}/${item!!.dynamicID}" + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1) "$fwsp!!$amountString!!" else ""),
posX + textOffsetX, posX + textOffsetX,
@@ -112,7 +112,7 @@ class UIItemInventoryElem(
) )
} }
else { else {
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
// print name and amount in parens // print name and amount in parens
item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1) "$fwsp!!$amountString!!" else "") + item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1) "$fwsp!!$amountString!!" else "") +
// TEMPORARY print eqipped slot info as well // TEMPORARY print eqipped slot info as well
@@ -143,8 +143,8 @@ class UIItemInventoryElem(
if (quickslot != null) { if (quickslot != null) {
val label = quickslot!!.plus(0xE010).toChar() val label = quickslot!!.plus(0xE010).toChar()
val labelW = Terrarum.fontGame.getWidth("$label") val labelW = AppLoader.fontGame.getWidth("$label")
Terrarum.fontGame.draw(batch, "$label", barOffset + barFullLen - labelW, posY + textOffsetY) AppLoader.fontGame.draw(batch, "$label", barOffset + barFullLen - labelW, posY + textOffsetY)
} }
} }
@@ -156,7 +156,7 @@ class UIItemInventoryElem(
override fun keyDown(keycode: Int): Boolean { override fun keyDown(keycode: Int): Boolean {
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) { if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return false if (player == null) return false
@@ -194,7 +194,7 @@ class UIItemInventoryElem(
TODO("Equip position is NULL, does this mean it's single-consume items like a potion? (from item: \"$item\" with itemID: ${item?.originalID}/${item?.dynamicID})") TODO("Equip position is NULL, does this mean it's single-consume items like a potion? (from item: \"$item\" with itemID: ${item?.originalID}/${item?.dynamicID})")
} }
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return false if (player == null) return false

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
@@ -116,10 +116,10 @@ class UIItemInventoryElemSimple(
} }
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
amountString, amountString,
posX + (width - Terrarum.fontSmallNumbers.getWidth(amountString)).toFloat(), posX + (width - AppLoader.fontSmallNumbers.getWidth(amountString)).toFloat(),
posY + (height - Terrarum.fontSmallNumbers.H).toFloat() posY + (height - AppLoader.fontSmallNumbers.H).toFloat()
) )
} }
@@ -133,7 +133,7 @@ class UIItemInventoryElemSimple(
override fun keyDown(keycode: Int): Boolean { override fun keyDown(keycode: Int): Boolean {
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) { if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return false if (player == null) return false
val inventory = player.inventory val inventory = player.inventory
@@ -168,7 +168,7 @@ class UIItemInventoryElemSimple(
// equip da shit // equip da shit
val itemEquipSlot = item!!.equipPosition val itemEquipSlot = item!!.equipPosition
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return false if (player == null) return false
if (item != ItemCodex[player.inventory.itemEquipped.get(itemEquipSlot)]) { // if this item is unequipped, equip it if (item != ItemCodex[player.inventory.itemEquipped.get(itemEquipSlot)]) { // if this item is unequipped, equip it

View File

@@ -15,7 +15,7 @@ import net.torvald.terrarum.worlddrawer.LightmapRenderer
*/ */
object BlockPropUtil { object BlockPropUtil {
var flickerFuncX: Second = 0f // saves current status (time) of func var flickerFuncX: Second = 0f // saves current status (time) of func
val flickerFuncDomain: Second = 0.1f // time between two noise sample val flickerFuncDomain: Second = 0.08f // time between two noise sample
val flickerFuncRange = 0.012f // intensity [0, 1] val flickerFuncRange = 0.012f // intensity [0, 1]
var breathFuncX = 0f var breathFuncX = 0f
@@ -30,31 +30,27 @@ object BlockPropUtil {
var flickerP0 = getNewRandom() var flickerP0 = getNewRandom()
var flickerP1 = getNewRandom() var flickerP1 = getNewRandom()
var flickerP2 = getNewRandom()
var flickerP3 = getNewRandom()
init { init {
} }
private fun getTorchFlicker(baseLum: Cvec): Cvec { private fun getTorchFlicker(baseLum: Cvec): Cvec {
val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX / flickerFuncDomain, val funcY = FastMath.interpolateLinear(flickerFuncX / flickerFuncDomain, flickerP0, flickerP1)
flickerP0, flickerP1, flickerP2, flickerP3
)
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY) return alterBrightnessUniform(baseLum, funcY)
} }
private fun getSlowBreath(baseLum: Cvec): Cvec { private fun getSlowBreath(baseLum: Cvec): Cvec {
val funcY = FastMath.sin(FastMath.PI * breathFuncX / breathCycleDuration) * breathRange val funcY = FastMath.sin(FastMath.PI * breathFuncX / breathCycleDuration) * breathRange
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY) return alterBrightnessUniform(baseLum, funcY)
} }
private fun getPulsate(baseLum: Cvec): Cvec { private fun getPulsate(baseLum: Cvec): Cvec {
val funcY = FastMath.sin(FastMath.PI * pulsateFuncX / pulsateCycleDuration) * pulsateRange val funcY = FastMath.sin(FastMath.PI * pulsateFuncX / pulsateCycleDuration) * pulsateRange
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY) return alterBrightnessUniform(baseLum, funcY)
} }
/** /**
@@ -63,21 +59,17 @@ object BlockPropUtil {
internal fun dynamicLumFuncTickClock() { internal fun dynamicLumFuncTickClock() {
// FPS-time compensation // FPS-time compensation
if (Gdx.graphics.framesPerSecond > 0) { if (Gdx.graphics.framesPerSecond > 0) {
flickerFuncX += Gdx.graphics.rawDeltaTime * 1000f flickerFuncX += Gdx.graphics.rawDeltaTime
breathFuncX += Gdx.graphics.rawDeltaTime * 1000f breathFuncX += Gdx.graphics.rawDeltaTime
pulsateFuncX += Gdx.graphics.rawDeltaTime * 1000f pulsateFuncX += Gdx.graphics.rawDeltaTime
} }
// flicker-related vars // flicker-related vars
if (flickerFuncX > flickerFuncDomain) { if (flickerFuncX > flickerFuncDomain) {
flickerFuncX -= flickerFuncDomain flickerFuncX -= flickerFuncDomain
//flickerPatternThis = flickerPatternNext
//flickerPatternNext = getNewRandom()
flickerP0 = flickerP1 flickerP0 = flickerP1
flickerP1 = flickerP2 flickerP1 = getNewRandom()
flickerP2 = flickerP3
flickerP3 = getNewRandom()
} }
// breath-related vars // breath-related vars
@@ -101,4 +93,20 @@ object BlockPropUtil {
else -> baseLum else -> baseLum
} }
} }
/**
* Darken or brighten colour by 'brighten' argument
*
* @param data Raw channel value (0-255) per channel
* @param brighten (-1.0 - 1.0) negative means darkening
* @return processed colour
*/
private fun alterBrightnessUniform(data: Cvec, brighten: Float): Cvec {
return Cvec(
data.r + brighten,
data.g + brighten,
data.b + brighten,
data.a + brighten
)
}
} }

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.blockstats
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import java.util.* import java.util.*
@@ -26,7 +26,7 @@ object BlockStats {
// Get stats on no-zoomed screen area. In other words, will behave as if screen zoom were 1.0 // Get stats on no-zoomed screen area. In other words, will behave as if screen zoom were 1.0
// no matter how the screen is zoomed. // no matter how the screen is zoomed.
val map = (Terrarum.ingame!!.world) val map = (Terrarum.ingame!!.world)
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return if (player == null) return
val renderWidth = FastMath.ceil(Terrarum.WIDTH.toFloat()) val renderWidth = FastMath.ceil(Terrarum.WIDTH.toFloat())

View File

@@ -7,7 +7,6 @@ import com.badlogic.gdx.utils.GdxRuntimeException
import com.badlogic.gdx.utils.Queue import com.badlogic.gdx.utils.Queue
import net.torvald.terrarum.AppLoader 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.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.BlocksDrawer
@@ -60,7 +59,7 @@ object MinimapComposer : Disposable {
private val liveTilesMeta = Array(TILES_IN_X * TILES_IN_Y) { LiveTileMeta(revalidate = true) } private val liveTilesMeta = Array(TILES_IN_X * TILES_IN_Y) { LiveTileMeta(revalidate = true) }
private val updaterQueue = Queue<Runnable>(TILES_IN_X * TILES_IN_Y * 2) private val updaterQueue = Queue<Runnable>(TILES_IN_X * TILES_IN_Y * 2)
private var currentThreads = Array(maxOf(1, Terrarum.THREADS.times(2).div(3))) { private var currentThreads = Array(maxOf(1, AppLoader.THREADS.times(2).div(3))) {
Thread() Thread()
} }

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.langpack.Lang
internal object Version : ConsoleCommand { internal object Version : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
Echo("${Terrarum.NAME} ${AppLoader.getVERSION_STRING()}") Echo("${AppLoader.GAME_NAME} ${AppLoader.getVERSION_STRING()}")
Echo("Polyglot language pack version ${Lang.POLYGLOT_VERSION}") Echo("Polyglot language pack version ${Lang.POLYGLOT_VERSION}")
Echo("GL_VERSION: ${Terrarum.GL_VERSION}") Echo("GL_VERSION: ${Terrarum.GL_VERSION}")
Echo("Renderer: ${Gdx.graphics.glVersion.rendererString}, ${Gdx.graphics.glVersion.vendorString}") Echo("Renderer: ${Gdx.graphics.glVersion.rendererString}, ${Gdx.graphics.glVersion.vendorString}")

View File

@@ -10,14 +10,14 @@ import net.torvald.terrarum.controller.TerrarumController
import net.torvald.terrarum.floorInt import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
/** /**
* Created by minjaesong on 2015-12-31. * Created by minjaesong on 2015-12-31.
*/ */
class IngameController(val ingame: Ingame) : InputAdapter() { class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
val hasGamepad: Boolean val hasGamepad: Boolean
@@ -29,10 +29,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */ /** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val mouseX: Float val mouseX: Float
get() = WorldCamera.x + Gdx.input.x / (ingame.screenZoom) get() = WorldCamera.x + Gdx.input.x / (terrarumIngame.screenZoom)
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise)*/ /** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise)*/
val mouseY: Float val mouseY: Float
get() = WorldCamera.y + Gdx.input.y / (ingame.screenZoom) get() = WorldCamera.y + Gdx.input.y / (terrarumIngame.screenZoom)
/** currently pointing tile coordinate */ /** currently pointing tile coordinate */
val mouseTileX: Int val mouseTileX: Int
get() = (mouseX / CreateTileAtlas.TILE_SIZE).floorInt() get() = (mouseX / CreateTileAtlas.TILE_SIZE).floorInt()
@@ -54,14 +54,14 @@ 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)
// don't separate Player from this! Physics will break, esp. airborne manoeuvre // don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.canPlayerControl) { if (terrarumIngame.canPlayerControl) {
// 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 (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
if ( if (
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) || Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) ||
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) { Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
ingame.worldPrimaryClickStart(AppLoader.UPDATE_RATE.toFloat()) terrarumIngame.worldPrimaryClickStart(AppLoader.UPDATE_RATE.toFloat())
} }
/*if Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary")) { /*if Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary")) {
ingame.worldSecondaryClickStart(AppLoader.UPDATE_RATE.toFloat()) ingame.worldSecondaryClickStart(AppLoader.UPDATE_RATE.toFloat())
@@ -79,35 +79,35 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
override fun keyDown(keycode: Int): Boolean { override fun keyDown(keycode: Int): Boolean {
if (ingame.canPlayerControl) { if (terrarumIngame.canPlayerControl) {
ingame.actorNowPlaying?.keyDown(keycode) terrarumIngame.actorNowPlaying?.keyDown(keycode)
// quickslot by number keys // quickslot by number keys
val quickslotKeys = AppLoader.getConfigIntArray("keyquickslots") val quickslotKeys = AppLoader.getConfigIntArray("keyquickslots")
if (keycode in quickslotKeys) { if (keycode in quickslotKeys) {
ingame.actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, quickslotKeys.indexOf(keycode)) terrarumIngame.actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, quickslotKeys.indexOf(keycode))
} }
// pie menu // pie menu
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode) if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|| keycode == AppLoader.getConfigInt("keyquicksel")) { || keycode == AppLoader.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsOpen() terrarumIngame.uiPieMenu.setAsOpen()
ingame.uiQuickBar.setAsClose() terrarumIngame.uiQuickBar.setAsClose()
} }
} }
ingame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases terrarumIngame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases
// Debug UIs // Debug UIs
if (keycode == Input.Keys.GRAVE) { if (keycode == Input.Keys.GRAVE) {
ingame.consoleHandler.toggleOpening() terrarumIngame.consoleHandler.toggleOpening()
} }
// screenshot key // screenshot key
if (keycode == Input.Keys.F12 && !f12Down) { if (keycode == Input.Keys.F12 && !f12Down) {
AppLoader.requestScreenshot() AppLoader.requestScreenshot()
ingame.sendNotification("Screenshot taken") terrarumIngame.sendNotification("Screenshot taken")
f12Down = true f12Down = true
println("Screenshot taken.") println("Screenshot taken.")
} }
@@ -118,11 +118,11 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
override fun keyUp(keycode: Int): Boolean { override fun keyUp(keycode: Int): Boolean {
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode) if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|| keycode == AppLoader.getConfigInt("keyquicksel")) { || keycode == AppLoader.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsClose() terrarumIngame.uiPieMenu.setAsClose()
ingame.uiQuickBar.setAsOpen() terrarumIngame.uiQuickBar.setAsOpen()
} }
ingame.uiContainer.forEach { it.keyUp(keycode) } // for KeyboardControlled UIcanvases terrarumIngame.uiContainer.forEach { it.keyUp(keycode) } // for KeyboardControlled UIcanvases
// screenshot key // screenshot key
@@ -133,25 +133,25 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
} }
override fun keyTyped(character: Char): Boolean { override fun keyTyped(character: Char): Boolean {
ingame.uiContainer.forEach { if (it.isVisible) it.keyTyped(character) } terrarumIngame.uiContainer.forEach { if (it.isVisible) it.keyTyped(character) }
return true return true
} }
override fun mouseMoved(screenX: Int, screenY: Int): Boolean { override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
ingame.uiContainer.forEach { it.mouseMoved(screenX, screenY) } terrarumIngame.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
return true return true
} }
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre // don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.canPlayerControl) { if (terrarumIngame.canPlayerControl) {
// 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 (terrarumIngame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
if ( if (
button == AppLoader.getConfigInt("mouseprimary") || button == AppLoader.getConfigInt("mouseprimary") ||
button == AppLoader.getConfigInt("mousesecondary")) { button == AppLoader.getConfigInt("mousesecondary")) {
ingame.worldPrimaryClickEnd(AppLoader.UPDATE_RATE.toFloat()) terrarumIngame.worldPrimaryClickEnd(AppLoader.UPDATE_RATE.toFloat())
} }
/*if (button == AppLoader.getConfigInt("mousesecondary")) { /*if (button == AppLoader.getConfigInt("mousesecondary")) {
ingame.worldSecondaryClickEnd(AppLoader.UPDATE_RATE.toFloat()) ingame.worldSecondaryClickEnd(AppLoader.UPDATE_RATE.toFloat())
@@ -160,33 +160,33 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
} }
ingame.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases terrarumIngame.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } // for MouseControlled UIcanvases
return true return true
} }
override fun scrolled(amount: Int): Boolean { override fun scrolled(amount: Int): Boolean {
if (ingame.canPlayerControl) { if (terrarumIngame.canPlayerControl) {
// quickslot by wheel // quickslot by wheel
if (ingame.actorNowPlaying != null) { if (terrarumIngame.actorNowPlaying != null) {
ingame.actorNowPlaying!!.actorValue.set( terrarumIngame.actorNowPlaying!!.actorValue.set(
AVKey.__PLAYER_QUICKSLOTSEL, AVKey.__PLAYER_QUICKSLOTSEL,
(ingame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amount) fmod ingame.actorNowPlaying!!.inventory.quickSlot.size (terrarumIngame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amount) fmod terrarumIngame.actorNowPlaying!!.inventory.quickSlot.size
) )
} }
} }
ingame.uiContainer.forEach { it.scrolled(amount) } terrarumIngame.uiContainer.forEach { it.scrolled(amount) }
return true return true
} }
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
ingame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) } terrarumIngame.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
return true return true
} }
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
ingame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) } terrarumIngame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
return true return true
} }

View File

@@ -140,7 +140,7 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
override fun dispose() { override fun dispose() {
ptr.destroy() ptr.destroy()
//directByteBuffer.clear() //directByteBuffer.clear()
printdbg(this, "BlockLayer successfully freed") printdbg(this, "BlockLayer with ptr ($ptr) successfully freed")
} }
companion object { companion object {

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.CanBeAnItem import net.torvald.terrarum.modulebasegame.gameactors.CanBeAnItem
import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.BlocksDrawer
import java.util.* import java.util.*
@@ -195,7 +195,7 @@ object ItemCodex {
} }
override fun startPrimaryUse(delta: Float): Boolean { override fun startPrimaryUse(delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame // must be in here val ingame = Terrarum.ingame!! as TerrarumIngame // must be in here
ingame.world.setFluid(Terrarum.mouseTileX, Terrarum.mouseTileY, Fluid.WATER, 4f) ingame.world.setFluid(Terrarum.mouseTileX, Terrarum.mouseTileY, Fluid.WATER, 4f)
return true return true
} }
@@ -222,7 +222,7 @@ object ItemCodex {
} }
override fun startPrimaryUse(delta: Float): Boolean { override fun startPrimaryUse(delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame // must be in here val ingame = Terrarum.ingame!! as TerrarumIngame // must be in here
ingame.world.setFluid(Terrarum.mouseTileX, Terrarum.mouseTileY, Fluid.LAVA, 4f) ingame.world.setFluid(Terrarum.mouseTileX, Terrarum.mouseTileY, Fluid.LAVA, 4f)
return true return true
} }
@@ -257,7 +257,7 @@ object ItemCodex {
return dynamicItemDescription[code]!! return dynamicItemDescription[code]!!
} }
else { else {
val a = (Terrarum.ingame!! as Ingame).getActorByID(code) // actor item val a = (Terrarum.ingame!! as TerrarumIngame).getActorByID(code) // actor item
if (a is CanBeAnItem) return a.itemData if (a is CanBeAnItem) return a.itemData
return null return null

View File

@@ -2,7 +2,6 @@ package net.torvald.terrarum.itemproperties
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ai.toLua import net.torvald.terrarum.gameactors.ai.toLua
import net.torvald.terrarum.modulebasegame.Ingame
import org.luaj.vm2.Globals import org.luaj.vm2.Globals
import org.luaj.vm2.LuaTable import org.luaj.vm2.LuaTable
import org.luaj.vm2.LuaValue import org.luaj.vm2.LuaValue

View File

@@ -318,7 +318,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private var updateAkku = 0.0 private var updateAkku = 0.0
override fun render(delta: Float) { override fun render(delta: Float) {
Gdx.graphics.setTitle(Ingame.getCanonicalTitle()) Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
// ASYNCHRONOUS UPDATE AND RENDER // // ASYNCHRONOUS UPDATE AND RENDER //
@@ -590,7 +590,7 @@ class MovableWorldCamera(val parent: BuildingMaker) : ActorHumanoid(0, usePhysic
class YamlCommandExit : YamlInvokable { class YamlCommandExit : YamlInvokable {
override fun invoke(args: Array<Any>) { override fun invoke(args: Array<Any>) {
Terrarum.setScreen(TitleScreen(Terrarum.batch)) AppLoader.setScreen(TitleScreen(Terrarum.batch))
} }
} }

View File

@@ -39,10 +39,12 @@ import java.util.concurrent.locks.ReentrantLock
/** /**
* Ingame instance for the game Terrarum.
*
* Created by minjaesong on 2017-06-16. * Created by minjaesong on 2017-06-16.
*/ */
open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
private val ACTOR_UPDATE_RANGE = 4096 private val ACTOR_UPDATE_RANGE = 4096
@@ -240,7 +242,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
printdbg(this, "loaded successfully.") printdbg(this, "loaded successfully.")
} }
else { else {
LoadScreen.addMessage("${Terrarum.NAME} version ${AppLoader.getVERSION_STRING()}") LoadScreen.addMessage("${AppLoader.GAME_NAME} version ${AppLoader.getVERSION_STRING()}")
LoadScreen.addMessage("Creating new world") LoadScreen.addMessage("Creating new world")
@@ -416,7 +418,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
/////////////// ///////////////
// prod code // // prod code //
/////////////// ///////////////
private class ThreadIngameUpdate(val ingame: Ingame): Runnable { private class ThreadIngameUpdate(val terrarumIngame: TerrarumIngame): Runnable {
override fun run() { override fun run() {
TODO() TODO()
} }
@@ -425,6 +427,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private var updateAkku = 0.0 private var updateAkku = 0.0
override fun render(delta: Float) { override fun render(delta: Float) {
println("Vitun Perkeleen TerrarumIngame")
// Q&D solution for LoadScreen and Ingame, where while LoadScreen is working, Ingame now no longer has GL Context // Q&D solution for LoadScreen and Ingame, where while LoadScreen is working, Ingame now no longer has GL Context
// there's still things to load which needs GL context to be present // there's still things to load which needs GL context to be present
if (!gameFullyLoaded) { if (!gameFullyLoaded) {
@@ -660,12 +664,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainerActive.size > Terrarum.THREADS) { if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainerActive.size > Terrarum.THREADS) {
val actors = actorContainerActive.size.toFloat() val actors = actorContainerActive.size.toFloat()
// set up indices // set up indices
for (i in 0..Terrarum.THREADS - 1) { for (i in 0..AppLoader.THREADS - 1) {
ThreadParallel.map( ThreadParallel.map(
i, "ActorUpdate", i, "ActorUpdate",
ThreadActorUpdate( ThreadActorUpdate(
actors.div(Terrarum.THREADS).times(i).roundInt(), actors.div(AppLoader.THREADS).times(i).roundInt(),
actors.div(Terrarum.THREADS).times(i + 1).roundInt() - 1 actors.div(AppLoader.THREADS).times(i + 1).roundInt() - 1
) )
) )
} }

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.Terrarum
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.console.EchoError import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.debuggerapp.ActorValueTracker import net.torvald.terrarum.modulebasegame.debuggerapp.ActorValueTracker
import java.util.* import java.util.*
@@ -16,7 +16,7 @@ internal object AVTracker : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size < 2) { if (args.size < 2) {
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).actorNowPlaying)) jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as TerrarumIngame).actorNowPlaying))
} }
else { else {
try { try {

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.Terrarum
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.debuggerapp.ActorsLister import net.torvald.terrarum.debuggerapp.ActorsLister
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import java.util.* import java.util.*
/** /**
@@ -15,8 +15,8 @@ internal object ActorsList : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
jPanelInstances.add(ActorsLister( jPanelInstances.add(ActorsLister(
(Terrarum.ingame!! as Ingame).actorContainerActive, (Terrarum.ingame!! as TerrarumIngame).actorContainerActive,
(Terrarum.ingame!! as Ingame).actorContainerInactive) (Terrarum.ingame!! as TerrarumIngame).actorContainerInactive)
) )
} }

View File

@@ -2,12 +2,12 @@ package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
object CheatWarnTest : ConsoleCommand { object CheatWarnTest : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
(Terrarum.ingame as? Ingame)?.uiCheatMotherfuckerNootNoot?.setAsOpen() (Terrarum.ingame as? TerrarumIngame)?.uiCheatMotherfuckerNootNoot?.setAsOpen()
} }
override fun printUsage() { override fun printUsage() {

View File

@@ -5,7 +5,7 @@ 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
import net.torvald.terrarum.console.Echo import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import java.io.IOException import java.io.IOException
@@ -16,7 +16,7 @@ internal object ExportAV : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size == 2) { if (args.size == 2) {
try { try {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return if (player == null) return
JsonWriter.writeToFile( JsonWriter.writeToFile(

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.Terrarum
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.console.EchoError import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
/** /**
* Created by minjaesong on 2016-01-19. * Created by minjaesong on 2016-01-19.
@@ -14,8 +14,8 @@ internal object GetAV : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
try { try {
val ingame = Terrarum.ingame!! as Ingame val ingame = Terrarum.ingame!! as TerrarumIngame
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return if (player == null) return

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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.TerrarumIngame
import net.torvald.terrarum.utils.JsonWriter import net.torvald.terrarum.utils.JsonWriter
import java.io.BufferedWriter import java.io.BufferedWriter
import java.io.FileWriter import java.io.FileWriter
@@ -20,7 +20,7 @@ internal object GsonTest : ConsoleCommand {
val jsonBuilder = JsonWriter.getJsonBuilder() val jsonBuilder = JsonWriter.getJsonBuilder()
val jsonString = jsonBuilder.toJson((Terrarum.ingame!! as Ingame).actorNowPlaying) val jsonString = jsonBuilder.toJson((Terrarum.ingame!! as TerrarumIngame).actorNowPlaying)
//val avelem = Gson().toJson((Terrarum.ingame!! as Ingame).actorNowPlaying) //val avelem = Gson().toJson((Terrarum.ingame!! as Ingame).actorNowPlaying)
//val jsonString = avelem.toString() //val jsonString = avelem.toString()

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
/** /**
@@ -13,7 +13,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
*/ */
internal object Inventory : ConsoleCommand { internal object Inventory : ConsoleCommand {
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).actorNowPlaying private var target: Pocketed? = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size == 1) { if (args.size == 1) {

View File

@@ -4,7 +4,6 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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
/** /**
* Created by minjaesong on 2016-06-16. * Created by minjaesong on 2016-06-16.

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.Terrarum
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.console.EchoError import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
/** /**
* Created by minjaesong on 2016-01-15. * Created by minjaesong on 2016-01-15.
@@ -63,7 +63,7 @@ internal object SetAV : ConsoleCommand {
return return
} }
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) { if (player == null) {
EchoError("Player does not exist") EchoError("Player does not exist")
println("[SetAV] Player does not exist") println("[SetAV] Player does not exist")

View File

@@ -2,7 +2,7 @@ package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
/** /**
* Created by minjaesong on 2016-01-23. * Created by minjaesong on 2016-01-23.
@@ -11,7 +11,7 @@ internal object SetBulletin : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
//send(Lang["ERROR_SAVE_CORRUPTED"], Lang["MENU_LABEL_CONTINUE_QUESTION"]) //send(Lang["ERROR_SAVE_CORRUPTED"], Lang["MENU_LABEL_CONTINUE_QUESTION"])
(Terrarum.ingame!! as Ingame).sendNotification(args.sliceArray(1..args.lastIndex)) (Terrarum.ingame!! as TerrarumIngame).sendNotification(args.sliceArray(1..args.lastIndex))
println("sent notifinator") println("sent notifinator")
} }

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.Terrarum
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.console.EchoError import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
/** /**
@@ -14,7 +14,7 @@ internal object SetScale : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size == 2 || args.size == 3) { if (args.size == 2 || args.size == 3) {
try { try {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return if (player == null) return

View File

@@ -4,14 +4,14 @@ import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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.TerrarumIngame
/** /**
* Created by minjaesong on 2016-03-20. * Created by minjaesong on 2016-03-20.
*/ */
internal object SetTime : ConsoleCommand { internal object SetTime : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).gameworld val world = (Terrarum.ingame!! as TerrarumIngame).gameworld
if (args.size == 2) { if (args.size == 2) {

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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.TerrarumIngame
/** /**
* Created by minjaesong on 2016-03-20. * Created by minjaesong on 2016-03-20.
@@ -13,7 +13,7 @@ internal object SetTimeDelta : ConsoleCommand {
val HARD_LIMIT = 60 val HARD_LIMIT = 60
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).gameworld val world = (Terrarum.ingame!! as TerrarumIngame).gameworld
if (args.size == 2) { if (args.size == 2) {

View File

@@ -4,7 +4,6 @@ import net.torvald.terrarum.modulebasegame.gameactors.PhysTestBall
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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 org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
/** /**

View File

@@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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.gameactors.PhysTestLuarLander import net.torvald.terrarum.modulebasegame.gameactors.PhysTestLuarLander
/** /**

View File

@@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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.gameactors.FixtureTikiTorch import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
/** /**

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
/** /**
@@ -27,7 +27,7 @@ internal object Teleport : ConsoleCommand {
return return
} }
(Terrarum.ingame!! as Ingame).actorNowPlaying?.setPosition(x.toDouble(), y.toDouble()) (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.setPosition(x.toDouble(), y.toDouble())
} }
else if (args.size == 4) { else if (args.size == 4) {
if (args[2].toLowerCase() != "to") { if (args[2].toLowerCase() != "to") {
@@ -39,7 +39,7 @@ internal object Teleport : ConsoleCommand {
try { try {
val fromActorID = args[1].toInt() val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player") { val targetActorID = if (args[3].toLowerCase() == "player") {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) { if (player == null) {
EchoError("Player does not exist") EchoError("Player does not exist")
return return

View File

@@ -3,14 +3,14 @@ package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
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.TerrarumIngame
/** /**
* Created by minjaesong on 2016-01-19. * Created by minjaesong on 2016-01-19.
*/ */
internal object ToggleNoClip : ConsoleCommand { internal object ToggleNoClip : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return if (player == null) return

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorValue import net.torvald.terrarum.gameactors.ActorValue
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.console.SetAV import net.torvald.terrarum.modulebasegame.console.SetAV
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import java.awt.BorderLayout import java.awt.BorderLayout
@@ -86,7 +86,7 @@ class ActorValueTracker constructor() : JFrame() {
buttonChangeActor.addMouseListener(object : MouseAdapter() { buttonChangeActor.addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent?) { override fun mousePressed(e: MouseEvent?) {
if (actorIDField.text.toLowerCase() == "player") { if (actorIDField.text.toLowerCase() == "player") {
actor = (Terrarum.ingame!! as Ingame).actorNowPlaying actor = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
actorValue = actor!!.actorValue actorValue = actor!!.actorValue
} }
else if (actorIDField.text.isNotBlank()) { else if (actorIDField.text.isNotBlank()) {

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.LightmapRenderer
@@ -588,8 +588,8 @@ open class ActorHumanoid(
// force update inventory UI, but when the pie menu is not open (pie menu constantly writes to the actorvalue, which will rebuildList() // force update inventory UI, but when the pie menu is not open (pie menu constantly writes to the actorvalue, which will rebuildList()
try { try {
if (!(Terrarum.ingame!! as Ingame).uiPieMenu.isVisible) { if (!(Terrarum.ingame!! as TerrarumIngame).uiPieMenu.isVisible) {
((Terrarum.ingame!! as Ingame).uiInventoryPlayer as UIInventoryFull).rebuildList() ((Terrarum.ingame!! as TerrarumIngame).uiInventoryPlayer as UIInventoryFull).rebuildList()
} }
} }
catch (LateInitMyArse: kotlin.UninitializedPropertyAccessException) { catch (LateInitMyArse: kotlin.UninitializedPropertyAccessException) {

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS
import net.torvald.terrarum.gameitem.ItemID import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.lock import net.torvald.terrarum.lock
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar
import java.util.* import java.util.*
import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.locks.ReentrantLock
@@ -67,8 +67,8 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.") "These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
if (item.originalID == Terrarum.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic if (item.originalID == Terrarum.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic
throw IllegalArgumentException("Attempted to put human player into the inventory.") throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (((Terrarum.ingame as? Ingame)?.gameFullyLoaded ?: false) && if (((Terrarum.ingame as? TerrarumIngame)?.gameFullyLoaded ?: false) &&
(item.originalID == (Terrarum.ingame as? Ingame)?.actorNowPlaying?.referenceID)) (item.originalID == (Terrarum.ingame as? TerrarumIngame)?.actorNowPlaying?.referenceID))
throw IllegalArgumentException("Attempted to put active player into the inventory.") throw IllegalArgumentException("Attempted to put active player into the inventory.")
if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1) if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1)
throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count") throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count")

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
/** /**
* Created by minjaesong on 2016-02-03. * Created by minjaesong on 2016-02-03.
@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
object PlayerBuilder { object PlayerBuilder {
operator fun invoke(): Actor { operator fun invoke(): Actor {
val world = (Terrarum.ingame!! as Ingame).gameworld val world = (Terrarum.ingame!! as TerrarumIngame).gameworld
val p: Actor = IngamePlayer("lol", "lol_glow", world.worldTime.TIME_T) val p: Actor = IngamePlayer("lol", "lol_glow", world.worldTime.TIME_T)
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json") InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.HumanoidNPC
import net.torvald.terrarum.Second import net.torvald.terrarum.Second
import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ai.ActorAI import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
/** /**
* Slime's stupid AI but can adjust his jump power to smack you as fast as possible * Slime's stupid AI but can adjust his jump power to smack you as fast as possible
@@ -35,7 +35,7 @@ class SmarterSlimes : ActorAI {
// TEST: just target player // TEST: just target player
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return if (player == null) return
val playerXPos = player.centrePosPoint.x val playerXPos = player.centrePosPoint.x

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameactors.physicssolver package net.torvald.terrarum.modulebasegame.gameactors.physicssolver
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import java.util.* import java.util.*
@@ -39,7 +39,7 @@ object CollisionSolver {
collCandidateY.clear() collCandidateY.clear()
// mark list x // mark list x
(Terrarum.ingame!! as Ingame).actorContainerActive.forEach { it -> (Terrarum.ingame!! as TerrarumIngame).actorContainerActive.forEach { it ->
if (it is ActorWBMovable) { if (it is ActorWBMovable) {
collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it)) collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it))
collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it)) collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it))
@@ -72,7 +72,7 @@ object CollisionSolver {
collCandidateStack.clear() collCandidateStack.clear()
// mark list y // mark list y
(Terrarum.ingame!! as Ingame).actorContainerActive.forEach { it -> (Terrarum.ingame!! as TerrarumIngame).actorContainerActive.forEach { it ->
if (it is ActorWBMovable) { if (it is ActorWBMovable) {
collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it)) collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it))
collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it)) collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it))

View File

@@ -7,7 +7,7 @@ import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil
@@ -21,7 +21,7 @@ object BlockBase {
* for wire items, otherwise you want it to be true. * for wire items, otherwise you want it to be true.
*/ */
fun blockStartPrimaryUse(gameItem: GameItem, itemID: Int, delta: Float): Boolean { fun blockStartPrimaryUse(gameItem: GameItem, itemID: Int, delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame val ingame = Terrarum.ingame!! as TerrarumIngame
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble()) val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY) val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
@@ -74,7 +74,7 @@ object BlockBase {
} }
fun wireStartPrimaryUse(gameItem: GameItem, wireTypeBit: Int, delta: Float): Boolean { fun wireStartPrimaryUse(gameItem: GameItem, wireTypeBit: Int, delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame val ingame = Terrarum.ingame!! as TerrarumIngame
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY) val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
// return false if the tile is already there // return false if the tile is already there

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Calculate import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.itemproperties.MaterialCodex import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -22,7 +22,7 @@ import kotlin.math.roundToInt
*/ */
object PickaxeCore { object PickaxeCore {
fun startPrimaryUse(delta: Float, item: GameItem): Boolean { fun startPrimaryUse(delta: Float, item: GameItem): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return false if (player == null) return false
val mouseTileX = Terrarum.mouseTileX val mouseTileX = Terrarum.mouseTileX
@@ -58,7 +58,7 @@ object PickaxeCore {
} }
fun endPrimaryUse(delta: Float, item: GameItem): Boolean { fun endPrimaryUse(delta: Float, item: GameItem): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return false if (player == null) return false
item.using = false item.using = false

View File

@@ -12,7 +12,7 @@ package net.torvald.terrarum.modulebasegame.ui
override var height: Int = 0 override var height: Int = 0
private var fontCol: Color = if (!isBlackVariant) Color.BLACK else Color.WHITE private var fontCol: Color = if (!isBlackVariant) Color.BLACK else Color.WHITE
private val GLYPH_HEIGHT = Terrarum.fontGame.lineHeight private val GLYPH_HEIGHT = AppLoader.fontGame.lineHeight
override var openCloseTime: Second = OPEN_CLOSE_TIME override var openCloseTime: Second = OPEN_CLOSE_TIME
@@ -29,7 +29,7 @@ package net.torvald.terrarum.modulebasegame.ui
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
blendNormal(batch) blendNormal(batch)
val textWidth = messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1] val textWidth = messagesList.map { AppLoader.fontGame.getWidth(it) }.sorted()[1]
batch.color = Color.WHITE batch.color = Color.WHITE
@@ -38,7 +38,7 @@ package net.torvald.terrarum.modulebasegame.ui
batch.draw(segment.get(2, 0), 2 * LRmargin + textWidth, 0f) batch.draw(segment.get(2, 0), 2 * LRmargin + textWidth, 0f)
messagesList.forEachIndexed { index, s -> messagesList.forEachIndexed { index, s ->
Terrarum.fontGame.draw(batch, s, segment.tileW + LRmargin, (segment.tileH - Terrarum.fontGame.lineHeight) / 2f) AppLoader.fontGame.draw(batch, s, segment.tileW + LRmargin, (segment.tileH - AppLoader.fontGame.lineHeight) / 2f)
} }
AppLoader.printdbg(this, "render") AppLoader.printdbg(this, "render")

View File

@@ -56,15 +56,15 @@ class Notification : UICanvas() {
fontCol.a = handler.opacity fontCol.a = handler.opacity
val realTextWidth = 12 + if (message.size == 1) val realTextWidth = 12 + if (message.size == 1)
Terrarum.fontGame.getWidth(message[0]) AppLoader.fontGame.getWidth(message[0])
else else
message.map { Terrarum.fontGame.getWidth(it) }.sorted().last() message.map { AppLoader.fontGame.getWidth(it) }.sorted().last()
val displayedTextWidth = maxOf(240, realTextWidth) val displayedTextWidth = maxOf(240, realTextWidth)
// force the UI to the centre of the screen // force the UI to the centre of the screen
this.posX = (Terrarum.WIDTH - displayedTextWidth) / 2 this.posX = (Terrarum.WIDTH - displayedTextWidth) / 2
val textHeight = message.size * Terrarum.fontGame.lineHeight val textHeight = message.size * AppLoader.fontGame.lineHeight
batch.color = drawColor batch.color = drawColor
@@ -73,8 +73,8 @@ class Notification : UICanvas() {
batch.color = fontCol batch.color = fontCol
message.forEachIndexed { index, s -> message.forEachIndexed { index, s ->
val xoff = 6 + (displayedTextWidth - realTextWidth) / 2 val xoff = 6 + (displayedTextWidth - realTextWidth) / 2
val y = -textHeight + Terrarum.fontGame.lineHeight * index val y = -textHeight + AppLoader.fontGame.lineHeight * index
Terrarum.fontGame.draw(batch, s, LRmargin + xoff, y) AppLoader.fontGame.draw(batch, s, LRmargin + xoff, y)
} }

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
@@ -52,7 +52,7 @@ class UIBasicInfo(private val player: ActorHumanoid?) : UICanvas() {
get() { get() {
if (player != null) { if (player != null) {
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? TerrarumIngame)?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f)
return if (tempCelsius < -10) return if (tempCelsius < -10)
0 0

View File

@@ -3,9 +3,10 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.fillRect import net.torvald.terrarum.fillRect
import net.torvald.terrarum.Second
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
@@ -37,10 +38,10 @@ class UICheatDetected : UICanvas() {
batch.color = Color.WHITE batch.color = Color.WHITE
val txt = Lang["ERROR_GENERIC_CHEATING"] val txt = Lang["ERROR_GENERIC_CHEATING"]
val txtW = Terrarum.fontGame.getWidth(txt) val txtW = AppLoader.fontGame.getWidth(txt)
val txtH = Terrarum.fontGame.lineHeight.toInt() val txtH = AppLoader.fontGame.lineHeight.toInt()
Terrarum.fontGame.draw(batch, txt, width.minus(txtW).ushr(1).toFloat(), height.minus(txtH).ushr(1).toFloat()) AppLoader.fontGame.draw(batch, txt, width.minus(txtW).ushr(1).toFloat(), height.minus(txtH).ushr(1).toFloat())
} }
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {

View File

@@ -47,7 +47,7 @@ package net.torvald.terrarum.modulebasegame.ui
val itemStripGutterH = 8 val itemStripGutterH = 8
val itemInterColGutter = 8 val itemInterColGutter = 8
val controlHelpHeight = Terrarum.fontGame.lineHeight.toInt() val controlHelpHeight = AppLoader.fontGame.lineHeight.toInt()
val pageButtonExtraGap = 32 val pageButtonExtraGap = 32
@@ -239,16 +239,16 @@ package net.torvald.terrarum.modulebasegame.ui
blendNormal() blendNormal()
batch.color = defaultTextColour batch.color = defaultTextColour
// W - close // W - close
Terrarum.fontGame.draw(batch, listControlClose, 4f, height - controlHelpHeight.toFloat()) AppLoader.fontGame.draw(batch, listControlClose, 4f, height - controlHelpHeight.toFloat())
// MouseL - Use ; 1.9 - Register ; T - Drop // MouseL - Use ; 1.9 - Register ; T - Drop
Terrarum.fontGame.draw(batch, listControlHelp, catButtons.width + 4f, height - controlHelpHeight.toFloat()) AppLoader.fontGame.draw(batch, listControlHelp, catButtons.width + 4f, height - controlHelpHeight.toFloat())
// encumbrance // encumbrance
if (inventory != null) { if (inventory != null) {
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"] val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
encumbranceText, encumbranceText,
width - 9 - Terrarum.fontGame.getWidth(encumbranceText) - weightBarWidth, width - 9 - AppLoader.fontGame.getWidth(encumbranceText) - weightBarWidth,
height - controlHelpHeight.toFloat() height - controlHelpHeight.toFloat()
) )

View File

@@ -6,22 +6,12 @@ import com.badlogic.gdx.graphics.*
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.ShapeRenderer import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.IS_DEVELOPMENT_BUILD import net.torvald.terrarum.AppLoader.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.AppLoader.gamepadLabelEast
import net.torvald.terrarum.AppLoader.gamepadLabelLStick
import net.torvald.terrarum.AppLoader.gamepadLabelLT
import net.torvald.terrarum.AppLoader.gamepadLabelNorth
import net.torvald.terrarum.AppLoader.gamepadLabelRStick
import net.torvald.terrarum.AppLoader.gamepadLabelRT
import net.torvald.terrarum.AppLoader.gamepadLabelStart
import net.torvald.terrarum.AppLoader.gamepadLabelWest
import net.torvald.terrarum.blockstats.MinimapComposer import net.torvald.terrarum.blockstats.MinimapComposer
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
@@ -87,7 +77,7 @@ class UIInventoryFull(
else else
"$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]}$SP" + "$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]}$SP" +
"$gamepadLabelLT ${Lang["GAME_INVENTORY"]}" "$gamepadLabelLT ${Lang["GAME_INVENTORY"]}"
val controlHelpHeight = Terrarum.fontGame.lineHeight val controlHelpHeight = AppLoader.fontGame.lineHeight
private var encumbrancePerc = 0f private var encumbrancePerc = 0f
private var isEncumbered = false private var isEncumbered = false
@@ -194,7 +184,7 @@ class UIInventoryFull(
// make gameMenuButtons work // make gameMenuButtons work
gameMenuButtons.selectionChangeListener = { old, new -> gameMenuButtons.selectionChangeListener = { old, new ->
if (new == 0) { if (new == 0) {
Terrarum.setScreen(TitleScreen(Terrarum.batch)) AppLoader.setScreen(TitleScreen(Terrarum.batch))
} }
else if (new == 1) { else if (new == 1) {
Gdx.app.exit() Gdx.app.exit()
@@ -441,7 +431,7 @@ class UIInventoryFull(
batch.begin() batch.begin()
Terrarum.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapScrOffX + (Terrarum.WIDTH - MINIMAP_WIDTH) / 2, -10f + itemList.posY) AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapScrOffX + (Terrarum.WIDTH - MINIMAP_WIDTH) / 2, -10f + itemList.posY)
batch.projectionMatrix = camera.combined batch.projectionMatrix = camera.combined
@@ -451,7 +441,7 @@ class UIInventoryFull(
// control hints // control hints
batch.color = Color.WHITE batch.color = Color.WHITE
Terrarum.fontGame.draw(batch, minimapControlHelp, offsetX + minimapScrOffX, yEnd - 20) AppLoader.fontGame.draw(batch, minimapControlHelp, offsetX + minimapScrOffX, yEnd - 20)
// the minimap // the minimap
batch.draw(minimapFBO.colorBufferTexture, minimapScrOffX + (Terrarum.WIDTH - MINIMAP_WIDTH) / 2, itemList.posY.toFloat()) batch.draw(minimapFBO.colorBufferTexture, minimapScrOffX + (Terrarum.WIDTH - MINIMAP_WIDTH) / 2, itemList.posY.toFloat())
@@ -461,7 +451,7 @@ class UIInventoryFull(
// control hints // control hints
blendNormal(batch) blendNormal(batch)
batch.color = Color.WHITE batch.color = Color.WHITE
Terrarum.fontGame.draw(batch, gameMenuControlHelp, offsetX + menuScrOffX, yEnd - 20) AppLoader.fontGame.draw(batch, gameMenuControlHelp, offsetX + menuScrOffX, yEnd - 20)
// text buttons // text buttons
gameMenuButtons.render(batch, camera) gameMenuButtons.render(batch, camera)
@@ -475,15 +465,15 @@ class UIInventoryFull(
// control hints // control hints
blendNormal(batch) blendNormal(batch)
batch.color = Color.WHITE batch.color = Color.WHITE
Terrarum.fontGame.draw(batch, listControlHelp, offsetX + inventoryScrOffX, yEnd - 20) AppLoader.fontGame.draw(batch, listControlHelp, offsetX + inventoryScrOffX, yEnd - 20)
// encumbrance meter // encumbrance meter
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"] val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
encumbranceText, encumbranceText,
xEnd - 6 - Terrarum.fontGame.getWidth(encumbranceText) - weightBarWidth + inventoryScrOffX, xEnd - 6 - AppLoader.fontGame.getWidth(encumbranceText) - weightBarWidth + inventoryScrOffX,
yEnd-20 yEnd-20
) )
@@ -514,7 +504,7 @@ class UIInventoryFull(
if (IS_DEVELOPMENT_BUILD) { if (IS_DEVELOPMENT_BUILD) {
AppLoader.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
"${actor.inventory.capacity}/${actor.inventory.maxCapacity}", "${actor.inventory.capacity}/${actor.inventory.maxCapacity}",
xEnd - 6 - Terrarum.fontGame.getWidth(encumbranceText) - weightBarWidth + inventoryScrOffX, xEnd - 6 - AppLoader.fontGame.getWidth(encumbranceText) - weightBarWidth + inventoryScrOffX,
yEnd-20 + 3f + controlHelpHeight - 4f yEnd-20 + 3f + controlHelpHeight - 4f
) )
} }
@@ -554,18 +544,18 @@ class UIInventoryFull(
override fun doOpening(delta: Float) { override fun doOpening(delta: Float) {
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null) (Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
} }
override fun doClosing(delta: Float) { override fun doClosing(delta: Float) {
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null) (Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
} }
override fun endOpening(delta: Float) { override fun endOpening(delta: Float) {
} }
override fun endClosing(delta: Float) { override fun endClosing(delta: Float) {
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null) // required! (Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null) // required!
MinimapComposer.revalidateAll() MinimapComposer.revalidateAll()
} }

View File

@@ -7,7 +7,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
@@ -287,7 +287,7 @@ class UIItemInventoryDynamicList(
// set tooltip accordingly // set tooltip accordingly
if (isCompactMode && it.mouseUp && !tooltipSet) { if (isCompactMode && it.mouseUp && !tooltipSet) {
(Terrarum.ingame as? Ingame)?.setTooltipMessage( (Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(
if (AppLoader.IS_DEVELOPMENT_BUILD) { if (AppLoader.IS_DEVELOPMENT_BUILD) {
it.item?.name + "/Mat: ${it.item?.material?.identifier}" it.item?.name + "/Mat: ${it.item?.material?.identifier}"
} }
@@ -300,7 +300,7 @@ class UIItemInventoryDynamicList(
} }
if (!tooltipSet) { if (!tooltipSet) {
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null) (Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
} }

View File

@@ -2,10 +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.*
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendScreen
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.serialise.ReadWorldInfo import net.torvald.terrarum.serialise.ReadWorldInfo
@@ -45,7 +42,7 @@ class UIItemPlayerInfoCell(
private val backColInactive = ItemSlotImageFactory.CELLCOLOUR_BLACK private val backColInactive = ItemSlotImageFactory.CELLCOLOUR_BLACK
private val backColActive = ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE private val backColActive = ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
private val textRow1 = (((height / 2) - Terrarum.fontGame.lineHeight) / 2).toFloat() private val textRow1 = (((height / 2) - AppLoader.fontGame.lineHeight) / 2).toFloat()
private val textRow2 = textRow1 + (height / 2) private val textRow2 = textRow1 + (height / 2)
private val creationTimeStr: String private val creationTimeStr: String
@@ -69,7 +66,7 @@ class UIItemPlayerInfoCell(
worldCountStr = Lang["CONTEXT_WORLD_COUNT"] + saveInfo.worldCount worldCountStr = Lang["CONTEXT_WORLD_COUNT"] + saveInfo.worldCount
worldCountStrWidth = Terrarum.fontGame.getWidth(worldCountStr) worldCountStrWidth = AppLoader.fontGame.getWidth(worldCountStr)
} }
override fun render(batch: SpriteBatch, camera: Camera) { override fun render(batch: SpriteBatch, camera: Camera) {
@@ -109,15 +106,15 @@ class UIItemPlayerInfoCell(
// name // name
batch.color = Color.WHITE batch.color = Color.WHITE
Terrarum.fontGame.draw(batch, saveInfo.playerName, spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow1) AppLoader.fontGame.draw(batch, saveInfo.playerName, spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow1)
// creation and modification time // creation and modification time
Terrarum.fontGame.draw(batch, "$creationTimeStr/$modificationTimeStr", spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow2) AppLoader.fontGame.draw(batch, "$creationTimeStr/$modificationTimeStr", spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow2)
// world count // world count
Terrarum.fontGame.draw(batch, worldCountStr, width - (edgeGap + worldCountStrWidth).toFloat(), textRow1) AppLoader.fontGame.draw(batch, worldCountStr, width - (edgeGap + worldCountStrWidth).toFloat(), textRow1)
// wallet // wallet
val walletStr = "¤ " + (ingamePlayer?.inventory?.wallet ?: saveInfo.playerWallet) val walletStr = "¤ " + (ingamePlayer?.inventory?.wallet ?: saveInfo.playerWallet)
val walletStrWidth = Terrarum.fontGame.getWidth(walletStr) val walletStrWidth = AppLoader.fontGame.getWidth(walletStr)
Terrarum.fontGame.draw(batch, walletStr, width - (edgeGap + walletStrWidth).toFloat(), textRow2) AppLoader.fontGame.draw(batch, walletStr, width - (edgeGap + walletStrWidth).toFloat(), textRow2)
*/ */
} }

View File

@@ -2,6 +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.AppLoader
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
@@ -24,7 +25,7 @@ class UIItemSavegameInfoCell(
override var oldPosX = posX override var oldPosX = posX
override var oldPosY = posY override var oldPosY = posY
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2 override val height: Int = AppLoader.fontGame.lineHeight.toInt() * 2
override fun render(batch: SpriteBatch, camera: Camera) { override fun render(batch: SpriteBatch, camera: Camera) {

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
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.blendNormal import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.fillRect import net.torvald.terrarum.fillRect
@@ -26,7 +26,7 @@ class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
val LINE_HEIGHT = 24 val LINE_HEIGHT = 24
val TEXT_OFFSETX = 3f val TEXT_OFFSETX = 3f
val TEXT_OFFSETY = (LINE_HEIGHT - Terrarum.fontGame.lineHeight) / 2f val TEXT_OFFSETY = (LINE_HEIGHT - AppLoader.fontGame.lineHeight) / 2f
fun mouseOnTitleBar() = fun mouseOnTitleBar() =
relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT
@@ -78,7 +78,7 @@ class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
// draw "Pal." // draw "Pal."
batch.color = UINSMenu.DEFAULT_TITLETEXTCOL batch.color = UINSMenu.DEFAULT_TITLETEXTCOL
Terrarum.fontGame.draw(batch, titleText, TEXT_OFFSETX, TEXT_OFFSETY) AppLoader.fontGame.draw(batch, titleText, TEXT_OFFSETX, TEXT_OFFSETY)
// draw background // draw background
batch.color = CELLCOLOUR_BLACK batch.color = CELLCOLOUR_BLACK
@@ -89,7 +89,7 @@ class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
// TODO carve the overlap // TODO carve the overlap
batch.draw(ItemCodex.getItemImage(back), 14f, 41f) batch.draw(ItemCodex.getItemImage(back), 14f, 41f)
batch.draw(ItemCodex.getItemImage(fore), 6f, 33f) batch.draw(ItemCodex.getItemImage(fore), 6f, 33f)
Terrarum.fontSmallNumbers.draw(batch, fore.toString(), 3f, 61f) AppLoader.fontSmallNumbers.draw(batch, fore.toString(), 3f, 61f)
// draw swap icon // draw swap icon
batch.color = Color.WHITE batch.color = Color.WHITE

View File

@@ -2,12 +2,11 @@ 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.random.HQRNG import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.LoadScreen import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.Second import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.BuildingMaker import net.torvald.terrarum.modulebasegame.BuildingMaker
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
/** /**
@@ -35,9 +34,9 @@ class UIProxyNewBuildingMaker : UICanvas() {
override fun endOpening(delta: Float) { override fun endOpening(delta: Float) {
val ingame = BuildingMaker(Terrarum.batch) val ingame = BuildingMaker(Terrarum.batch)
Terrarum.ingame = ingame Terrarum.setCurrentIngameInstance(ingame)
LoadScreen.screenToLoad = ingame LoadScreen.screenToLoad = ingame
Terrarum.setScreen(LoadScreen) AppLoader.setScreen(LoadScreen)
} }
override fun endClosing(delta: Float) { override fun endClosing(delta: Float) {

View File

@@ -3,10 +3,12 @@ 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.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.LoadScreen import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.Second import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
/** /**
@@ -32,14 +34,17 @@ class UIProxyNewRandomGame : UICanvas() {
} }
override fun endOpening(delta: Float) { override fun endOpening(delta: Float) {
val ingame = Ingame(Terrarum.batch) printdbg(this, "endOpening")
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
//ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(8192, 2048, 0x51621DL)
ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
Terrarum.ingame = ingame
val ingame = TerrarumIngame(AppLoader.batch)
ingame.gameLoadInfoPayload = TerrarumIngame.NewWorldParameters(2400, 800, HQRNG().nextLong())
//ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(8192, 2048, 0x51621DL)
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
Terrarum.setCurrentIngameInstance(ingame)
LoadScreen.screenToLoad = ingame LoadScreen.screenToLoad = ingame
Terrarum.setScreen(LoadScreen) AppLoader.setScreen(LoadScreen)
} }
override fun endClosing(delta: Float) { override fun endClosing(delta: Float) {

View File

@@ -3,12 +3,13 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Second import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
/** /**
@@ -21,15 +22,15 @@ class UIQuickslotBar : UICanvas() {
private val gutter = 10 - 6 // do -6 to get a gutter size of not-enlarged cells private val gutter = 10 - 6 // do -6 to get a gutter size of not-enlarged cells
override var width: Int = cellSize * SLOT_COUNT + gutter * (SLOT_COUNT - 1) // 452 override var width: Int = cellSize * SLOT_COUNT + gutter * (SLOT_COUNT - 1) // 452
override var height: Int = ItemSlotImageFactory.slotImage.tileH + 4 + Terrarum.fontGame.lineHeight.toInt() override var height: Int = ItemSlotImageFactory.slotImage.tileH + 4 + AppLoader.fontGame.lineHeight.toInt()
/** /**
* In milliseconds * In milliseconds
*/ */
override var openCloseTime: Second = COMMON_OPEN_CLOSE override var openCloseTime: Second = COMMON_OPEN_CLOSE
private var selection: Int private var selection: Int
get() = (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0 get() = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) } set(value) { (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
companion object { companion object {
@@ -47,7 +48,7 @@ class UIQuickslotBar : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
for (i in 0..SLOT_COUNT - 1) { for (i in 0..SLOT_COUNT - 1) {
val item = ItemCodex[(Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item] val item = ItemCodex[(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.inventory?.getQuickslot(i)?.item]
val image = if (i == selection) val image = if (i == selection)
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item) ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbgerr import net.torvald.terrarum.AppLoader.printdbgerr
import net.torvald.terrarum.QNDTreeNode import net.torvald.terrarum.QNDTreeNode
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
@@ -299,6 +300,6 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
val remoConWidth = 304 val remoConWidth = 304
fun getRemoConHeight(menu: ArrayList<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1) fun getRemoConHeight(menu: ArrayList<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
fun getRemoConHeight(menu: Array<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1) fun getRemoConHeight(menu: Array<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt() val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (AppLoader.fontGame.lineHeight * 1.5).toInt()
} }
} }

View File

@@ -6,7 +6,7 @@ package net.torvald.terrarum.modulebasegame.ui
val remoConWidth = 240 val remoConWidth = 240
fun getRemoConHeight(menu: ArrayList<String>) = 36 * menu.size.plus(1) fun getRemoConHeight(menu: ArrayList<String>) = 36 * menu.size.plus(1)
fun getRemoConHeight(menu: Array<String>) = 36 * menu.size.plus(1) fun getRemoConHeight(menu: Array<String>) = 36 * menu.size.plus(1)
val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt() val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (AppLoader.fontGame.lineHeight * 1.5).toInt()
} }
@@ -83,7 +83,7 @@ package net.torvald.terrarum.modulebasegame.ui
(Terrarum.ingame!! as Ingame).gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong()) (Terrarum.ingame!! as Ingame).gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
(Terrarum.ingame!! as Ingame).gameLoadMode = Ingame.GameLoadMode.CREATE_NEW (Terrarum.ingame!! as Ingame).gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
LoadScreen.screenToLoad = (Terrarum.ingame!! as Ingame) LoadScreen.screenToLoad = (Terrarum.ingame!! as Ingame)
Terrarum.setScreen(LoadScreen) AppLoader.setScreen(LoadScreen)
} }
@@ -114,7 +114,7 @@ package net.torvald.terrarum.modulebasegame.ui
val maker = BuildingMaker(Terrarum.batch) val maker = BuildingMaker(Terrarum.batch)
Terrarum.ingame = maker Terrarum.ingame = maker
Terrarum.setScreen(maker) AppLoader.setScreen(maker)
} }
} }
} }

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Second import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
@@ -20,7 +21,7 @@ class UITooltip : UICanvas() {
msgWidth = font.getWidth(value) msgWidth = font.getWidth(value)
} }
private val font = Terrarum.fontGame private val font = AppLoader.fontGame
private var msgWidth = 0 private var msgWidth = 0
val textMarginX = 4 val textMarginX = 4

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
@@ -40,8 +40,8 @@ class uiQuickslotPie : UICanvas() {
var selection: Int = -1 var selection: Int = -1
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
if (selection >= 0 && (Terrarum.ingame!! as Ingame).actorNowPlaying != null) if (selection >= 0 && (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying != null)
(Terrarum.ingame!! as Ingame).actorNowPlaying!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount selection % slotCount
@@ -63,7 +63,7 @@ class uiQuickslotPie : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
// draw radial thingies // draw radial thingies
for (i in 0..slotCount - 1) { for (i in 0..slotCount - 1) {
val item = ItemCodex[(Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item] val item = ItemCodex[(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.inventory?.getQuickslot(i)?.item]
// set position // set position
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise

View File

@@ -12,7 +12,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.RNGConsumer import net.torvald.terrarum.modulebasegame.RNGConsumer
import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain
@@ -96,7 +96,7 @@ internal object WeatherMixer : RNGConsumer {
// test rain toggled by F2 // test rain toggled by F2
if (KeyToggler.isOn(Input.Keys.F2) && Terrarum.ingame is Ingame) { if (KeyToggler.isOn(Input.Keys.F2) && Terrarum.ingame is TerrarumIngame) {
val playerPosX = player.hitbox.centeredX val playerPosX = player.hitbox.centeredX
val playerPosY = player.hitbox.centeredY val playerPosY = player.hitbox.centeredY
kotlin.repeat(7) { kotlin.repeat(7) {
@@ -104,7 +104,7 @@ internal object WeatherMixer : RNGConsumer {
playerPosX + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW, playerPosX + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW,
playerPosY - Terrarum.HEIGHT playerPosY - Terrarum.HEIGHT
) )
(Terrarum.ingame!! as Ingame).addParticle(rainParticle) (Terrarum.ingame!! as TerrarumIngame).addParticle(rainParticle)
} }
//globalLightNow.set(getGlobalLightOfTime((Terrarum.ingame!!.world).time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 0.58f)) //globalLightNow.set(getGlobalLightOfTime((Terrarum.ingame!!.world).time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 0.58f))
} }

View File

@@ -4,9 +4,9 @@ import com.jme3.math.FastMath
import com.sudoplay.joise.Joise import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.* import com.sudoplay.joise.module.*
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.LoadScreen import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.concurrent.ThreadParallel import net.torvald.terrarum.concurrent.ThreadParallel
@@ -774,14 +774,14 @@ object WorldGenerator {
} }
private fun processNoiseLayers(noiseRecords: Array<TaggedJoise>) { private fun processNoiseLayers(noiseRecords: Array<TaggedJoise>) {
if (Terrarum.MULTITHREAD) { if (AppLoader.MULTITHREAD) {
// set up indices // set up indices
for (i in 0 until Terrarum.THREADS) { for (i in 0 until AppLoader.THREADS) {
ThreadParallel.map( ThreadParallel.map(
i, "SampleJoiseMap", i, "SampleJoiseMap",
ThreadProcessNoiseLayers( ThreadProcessNoiseLayers(
HEIGHT.toFloat().div(Terrarum.THREADS).times(i).roundInt(), HEIGHT.toFloat().div(AppLoader.THREADS).times(i).roundInt(),
HEIGHT.toFloat().div(Terrarum.THREADS).times(i.plus(1)).roundInt() - 1, HEIGHT.toFloat().div(AppLoader.THREADS).times(i.plus(1)).roundInt() - 1,
noiseRecords noiseRecords
) )
) )

View File

@@ -1,10 +1,13 @@
package net.torvald.terrarum.swingapp package net.torvald.terrarum.swingapp
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import java.awt.BorderLayout import java.awt.BorderLayout
import java.awt.FlowLayout import java.awt.FlowLayout
import java.awt.event.* import java.awt.event.KeyEvent
import java.awt.event.KeyListener
import java.awt.event.MouseEvent
import java.awt.event.MouseListener
import javax.swing.* import javax.swing.*
@@ -42,7 +45,7 @@ class IMStringReader(feedInput: (String) -> Unit, message: String? = null) : JFr
this.title = labelTitle this.title = labelTitle
defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE
Terrarum.pause() AppLoader.getINSTANCE().pause()
buttonOkay.addMouseListener(object : MouseListener { buttonOkay.addMouseListener(object : MouseListener {
override fun mouseEntered(e: MouseEvent?) { } override fun mouseEntered(e: MouseEvent?) { }
@@ -52,7 +55,7 @@ class IMStringReader(feedInput: (String) -> Unit, message: String? = null) : JFr
override fun mousePressed(e: MouseEvent?) { override fun mousePressed(e: MouseEvent?) {
userInput = inputArea.text userInput = inputArea.text
isVisible = false isVisible = false
Terrarum.resume() AppLoader.getINSTANCE().resume()
feedInput(userInput) feedInput(userInput)
@@ -68,7 +71,7 @@ class IMStringReader(feedInput: (String) -> Unit, message: String? = null) : JFr
override fun mousePressed(e: MouseEvent?) { override fun mousePressed(e: MouseEvent?) {
userInput = ""//null userInput = ""//null
isVisible = false isVisible = false
Terrarum.resume() AppLoader.getINSTANCE().resume()
dispose() dispose()
} }
@@ -80,7 +83,7 @@ class IMStringReader(feedInput: (String) -> Unit, message: String? = null) : JFr
override fun keyPressed(e: KeyEvent?) { override fun keyPressed(e: KeyEvent?) {
userInput = inputArea.text userInput = inputArea.text
isVisible = false isVisible = false
Terrarum.resume() AppLoader.getINSTANCE().resume()
feedInput(userInput) feedInput(userInput)

View File

@@ -22,7 +22,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.concurrent.BlockingThreadPool import net.torvald.terrarum.concurrent.BlockingThreadPool
import net.torvald.terrarum.concurrent.sliceEvenly import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.inUse import net.torvald.terrarum.inUse
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.roundInt import net.torvald.terrarum.roundInt
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
@@ -100,7 +100,7 @@ class NoiseGenerator : ScreenAdapter() {
private var timerFired = false private var timerFired = false
override fun render(delta: Float) { override fun render(delta: Float) {
Gdx.graphics.setTitle(Ingame.getCanonicalTitle()) Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
updateTestGovernor(delta) updateTestGovernor(delta)
@@ -138,7 +138,7 @@ class NoiseGenerator : ScreenAdapter() {
batch.draw(texture, 0f, 0f) batch.draw(texture, 0f, 0f)
batch.color = Color.CYAN batch.color = Color.CYAN
Terrarum.fontGame.draw(batch, "Tests: $totalTestsDone / ${testSets.size * samplingCount}", 10f, 10f) AppLoader.fontGame.draw(batch, "Tests: $totalTestsDone / ${testSets.size * samplingCount}", 10f, 10f)
} }
} }

View File

@@ -10,7 +10,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.graphics.glutils.ShaderProgram
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.ui.UINSMenu import net.torvald.terrarum.ui.UINSMenu
/** /**
@@ -85,7 +85,7 @@ class UITestPad1 : ScreenAdapter() {
var _dct = 0f var _dct = 0f
override fun render(delta: Float) { override fun render(delta: Float) {
Gdx.graphics.setTitle(Ingame.getCanonicalTitle()) Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
// UPDATE // UPDATE

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.tests package net.torvald.terrarum.tests
import net.torvald.UnsafeHelper
import net.torvald.terrarum.gameworld.toUint import net.torvald.terrarum.gameworld.toUint
import sun.misc.Unsafe import sun.misc.Unsafe
@@ -15,20 +16,32 @@ class UnsafeTest {
unsafe = unsafeConstructor.newInstance() unsafe = unsafeConstructor.newInstance()
} }
private val memsize = 2048L // must be big enough value so that your OS won't always return zero-filled pieces private val memsize = 512L // must be big enough value so that your OS won't always return zero-filled pieces
fun main() { fun main() {
val ptr = unsafe.allocateMemory(memsize) var ptr = unsafe.allocateMemory(memsize)
printDump(ptr) printDump(ptr)
unsafe.setMemory(ptr, memsize, 0x00.toByte()) unsafe.setMemory(ptr, memsize, 0x00.toByte())
printDump(ptr) printDump(ptr)
for (k in 0 until memsize step 4) { for (k in 0 until 13) {
unsafe.putInt(ptr + k, 0xcafebabe.toInt()) unsafe.putByte(ptr + k, (-1 - k).toByte())
} }
printDump(ptr) printDump(ptr)
// test shingled memory copy -- how would it work out?
UnsafeHelper.memcpy(ptr, ptr + 3L, 13L)
printDump(ptr)
println(ptr)
ptr = unsafe.reallocateMemory(ptr, 256L)
println(ptr)
// that's all for today!
unsafe.freeMemory(ptr) unsafe.freeMemory(ptr)
} }

View File

@@ -10,8 +10,8 @@ import net.torvald.terrarum.Terrarum.mouseTileY
import net.torvald.terrarum.controller.TerrarumController import net.torvald.terrarum.controller.TerrarumController
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.imagefont.TinyAlphNum import net.torvald.terrarum.imagefont.TinyAlphNum
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
@@ -40,7 +40,7 @@ class BasicDebugInfoWindow : UICanvas() {
private val world: GameWorld? private val world: GameWorld?
get() = Terrarum.ingame?.world get() = Terrarum.ingame?.world
private val world2: GameWorldExtension? private val world2: GameWorldExtension?
get() = Terrarum.ingame?.world as GameWorldExtension? get() = Terrarum.ingame?.world as? GameWorldExtension?
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
@@ -179,8 +179,8 @@ class BasicDebugInfoWindow : UICanvas() {
//printLineColumn(batch, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp) //printLineColumn(batch, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
if (world != null) { if (world != null) {
printLineColumn(batch, 2, 5, "Time $ccG${world2!!.worldTime.todaySeconds.toString().padStart(5, '0')}" + printLineColumn(batch, 2, 5, "Time $ccG${world2?.worldTime?.todaySeconds.toString().padStart(5, '0')}" +
" (${world2!!.worldTime.getFormattedTime()})") " (${world2?.worldTime?.getFormattedTime()})")
} }
if (player != null) { if (player != null) {
@@ -189,14 +189,14 @@ class BasicDebugInfoWindow : UICanvas() {
printLineColumn(batch, 2, 7, "noClip $ccG${player.isNoClip}") printLineColumn(batch, 2, 7, "noClip $ccG${player.isNoClip}")
} }
drawHistogram(batch, LightmapRenderer.histogram, /*drawHistogram(batch, LightmapRenderer.histogram,
Terrarum.WIDTH - histogramW - TinyAlphNum.W * 2, Terrarum.WIDTH - histogramW - TinyAlphNum.W * 2,
Terrarum.HEIGHT - histogramH - TinyAlphNum.H * 4 Terrarum.HEIGHT - histogramH - TinyAlphNum.H * 4
) )*/ // histogram building is currently bugged
batch.color = Color.WHITE batch.color = Color.WHITE
val gamepad = (Terrarum.ingame as? Ingame)?.ingameController?.gamepad val gamepad = (Terrarum.ingame as? TerrarumIngame)?.ingameController?.gamepad
if (gamepad != null) { if (gamepad != null) {
drawGamepadAxis(gamepad, batch, drawGamepadAxis(gamepad, batch,
gamepad.getAxis(AppLoader.getConfigInt("gamepadaxislx")), gamepad.getAxis(AppLoader.getConfigInt("gamepadaxislx")),
@@ -211,20 +211,20 @@ class BasicDebugInfoWindow : UICanvas() {
*/ */
// memory pressure // memory pressure
Terrarum.fontSmallNumbers.draw(batch, "${ccY}MEM ", (Terrarum.WIDTH - 23 * TinyAlphNum.W - 2).toFloat(), line(1)) AppLoader.fontSmallNumbers.draw(batch, "${ccY}MEM ", (Terrarum.WIDTH - 23 * TinyAlphNum.W - 2).toFloat(), line(1))
// thread count // thread count
Terrarum.fontSmallNumbers.draw(batch, "${ccY}CPUs${if (Terrarum.MULTITHREAD) ccG else ccR}${Terrarum.THREADS.toString().padStart(2, ' ')}", AppLoader.fontSmallNumbers.draw(batch, "${ccY}CPUs${if (AppLoader.MULTITHREAD) ccG else ccR}${AppLoader.THREADS.toString().padStart(2, ' ')}",
(Terrarum.WIDTH - 2 - 8 * TinyAlphNum.W).toFloat(), line(2)) (Terrarum.WIDTH - 2 - 8 * TinyAlphNum.W).toFloat(), line(2))
// memory texts // memory texts
Terrarum.fontSmallNumbers.draw(batch, "${Terrarum.memJavaHeap}M", AppLoader.fontSmallNumbers.draw(batch, "${Terrarum.memJavaHeap}M",
(Terrarum.WIDTH - 19 * TinyAlphNum.W - 2).toFloat(), line(1)) (Terrarum.WIDTH - 19 * TinyAlphNum.W - 2).toFloat(), line(1))
Terrarum.fontSmallNumbers.draw(batch, "/${Terrarum.memNativeHeap}M/", AppLoader.fontSmallNumbers.draw(batch, "/${Terrarum.memNativeHeap}M/",
(Terrarum.WIDTH - 14 * TinyAlphNum.W - 2).toFloat(), line(1)) (Terrarum.WIDTH - 14 * TinyAlphNum.W - 2).toFloat(), line(1))
Terrarum.fontSmallNumbers.draw(batch, "${Terrarum.memXmx}M", AppLoader.fontSmallNumbers.draw(batch, "${Terrarum.memXmx}M",
(Terrarum.WIDTH - 7 * TinyAlphNum.W - 2).toFloat(), line(1)) (Terrarum.WIDTH - 7 * TinyAlphNum.W - 2).toFloat(), line(1))
// FPS count // FPS count
Terrarum.fontSmallNumbers.draw(batch, "${ccY}FPS${ccG}${Gdx.graphics.framesPerSecond.toString().padStart(3, ' ')}", AppLoader.fontSmallNumbers.draw(batch, "${ccY}FPS${ccG}${Gdx.graphics.framesPerSecond.toString().padStart(3, ' ')}",
(Terrarum.WIDTH - 3 - 15 * TinyAlphNum.W).toFloat(), line(2)) (Terrarum.WIDTH - 3 - 15 * TinyAlphNum.W).toFloat(), line(2))
/** /**
@@ -232,21 +232,21 @@ class BasicDebugInfoWindow : UICanvas() {
*/ */
if (ingame != null) { if (ingame != null) {
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${ingame!!.actorContainerActive.size + ingame!!.actorContainerInactive.size}", AppLoader.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${ingame!!.actorContainerActive.size + ingame!!.actorContainerInactive.size}",
TinyAlphNum.W * 2f, Terrarum.HEIGHT - TinyAlphNum.H * 2f) TinyAlphNum.W * 2f, Terrarum.HEIGHT - TinyAlphNum.H * 2f)
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${ingame!!.actorContainerActive.size}", AppLoader.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${ingame!!.actorContainerActive.size}",
(TinyAlphNum.W * 2 + 17 * 8).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f) (TinyAlphNum.W * 2 + 17 * 8).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f)
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${ingame!!.actorContainerInactive.size}", AppLoader.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${ingame!!.actorContainerInactive.size}",
(TinyAlphNum.W * 2 + 28 * 8).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f) (TinyAlphNum.W * 2 + 28 * 8).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f)
if (ingame is Ingame) { if (ingame is TerrarumIngame) {
Terrarum.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${(ingame as Ingame).particlesActive}", AppLoader.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${(ingame as TerrarumIngame).particlesActive}",
(TinyAlphNum.W * 2 + 41 * 8).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f) (TinyAlphNum.W * 2 + 41 * 8).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f)
} }
} }
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Actors rendering $ccG${IngameRenderer.renderingActorsCount}", AppLoader.fontSmallNumbers.draw(batch, "${ccY}Actors rendering $ccG${IngameRenderer.renderingActorsCount}",
TinyAlphNum.W * 2f, Terrarum.HEIGHT - TinyAlphNum.H * 3f) TinyAlphNum.W * 2f, Terrarum.HEIGHT - TinyAlphNum.H * 3f)
Terrarum.fontSmallNumbers.draw(batch, "${ccY}UIs rendering $ccG${IngameRenderer.renderingUIsCount}", AppLoader.fontSmallNumbers.draw(batch, "${ccY}UIs rendering $ccG${IngameRenderer.renderingUIsCount}",
TinyAlphNum.W * 2f + (21 * 8), Terrarum.HEIGHT - TinyAlphNum.H * 3f) TinyAlphNum.W * 2f + (21 * 8), Terrarum.HEIGHT - TinyAlphNum.H * 3f)
/** /**
@@ -254,7 +254,7 @@ class BasicDebugInfoWindow : UICanvas() {
*/ */
// processor and renderer // processor and renderer
Terrarum.fontSmallNumbers.draw(batch, "$ccY$totalHardwareName", AppLoader.fontSmallNumbers.draw(batch, "$ccY$totalHardwareName",
(Terrarum.WIDTH - (totalHardwareName.length + 2) * TinyAlphNum.W).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f) (Terrarum.WIDTH - (totalHardwareName.length + 2) * TinyAlphNum.W).toFloat(), Terrarum.HEIGHT - TinyAlphNum.H * 2f)
} }
@@ -263,13 +263,13 @@ class BasicDebugInfoWindow : UICanvas() {
private val totalHardwareName = "$processorName $rendererName" private val totalHardwareName = "$processorName $rendererName"
private fun printLine(batch: SpriteBatch, l: Int, s: String) { private fun printLine(batch: SpriteBatch, l: Int, s: String) {
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
s, TinyAlphNum.W * 2f, line(l) s, TinyAlphNum.W * 2f, line(l)
) )
} }
private fun printLineColumn(batch: SpriteBatch, col: Int, row: Int, s: String) { private fun printLineColumn(batch: SpriteBatch, col: Int, row: Int, s: String) {
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
s, (TinyAlphNum.W * 2f + column(col)), line(row) s, (TinyAlphNum.W * 2f + column(col)), line(row)
) )
} }
@@ -293,9 +293,9 @@ class BasicDebugInfoWindow : UICanvas() {
batch.color = uiColour batch.color = uiColour
batch.fillRect(x.toFloat(), y.toFloat(), w.plus(1), h) batch.fillRect(x.toFloat(), y.toFloat(), w.plus(1), h)
batch.color = Color.GRAY batch.color = Color.GRAY
Terrarum.fontSmallNumbers.draw(batch, "0", x.toFloat(), y.toFloat() + h + 2) AppLoader.fontSmallNumbers.draw(batch, "0", x.toFloat(), y.toFloat() + h + 2)
Terrarum.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8 * 3, y.toFloat() + h + 2) AppLoader.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8 * 3, y.toFloat() + h + 2)
Terrarum.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2) AppLoader.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
blendScreen(batch) blendScreen(batch)
for (c in 0..3) { for (c in 0..3) {
@@ -342,7 +342,7 @@ class BasicDebugInfoWindow : UICanvas() {
} }
batch.begin() batch.begin()
Terrarum.fontSmallNumbers.draw(batch, gamepad.getName(), Terrarum.WIDTH - (gamepad.getName().length + 2f) * TinyAlphNum.W, uiY.toFloat() + h + 2) AppLoader.fontSmallNumbers.draw(batch, gamepad.getName(), Terrarum.WIDTH - (gamepad.getName().length + 2f) * TinyAlphNum.W, uiY.toFloat() + h + 2)
} }

View File

@@ -4,13 +4,13 @@ import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.util.HistoryArray
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.AppLoader import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.Authenticator import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.CommandInterpreter import net.torvald.terrarum.console.CommandInterpreter
import net.torvald.terrarum.fillRect import net.torvald.terrarum.fillRect
import net.torvald.terrarum.langpack.Lang
import net.torvald.util.HistoryArray
/** /**
@@ -58,12 +58,12 @@ class ConsoleWindow : UICanvas() {
batch.fillRect(drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat()) batch.fillRect(drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
val input = commandInputPool!!.toString() val input = commandInputPool!!.toString()
val inputDrawWidth = Terrarum.fontGame.getWidth(input) val inputDrawWidth = AppLoader.fontGame.getWidth(input)
val inputDrawHeight = Terrarum.fontGame.lineHeight val inputDrawHeight = AppLoader.fontGame.lineHeight
// text and cursor // text and cursor
batch.color = Color.WHITE batch.color = Color.WHITE
Terrarum.fontGame.draw(batch, input, 1f + drawOffX, drawOffY) AppLoader.fontGame.draw(batch, input, 1f + drawOffX, drawOffY)
batch.color = Color(0x7f7f7f_ff) batch.color = Color(0x7f7f7f_ff)
batch.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight) batch.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight)
@@ -74,7 +74,7 @@ class ConsoleWindow : UICanvas() {
// messages // messages
for (i in 0..MESSAGES_DISPLAY_COUNT - 1) { for (i in 0..MESSAGES_DISPLAY_COUNT - 1) {
val message = messages[messageDisplayPos + i] val message = messages[messageDisplayPos + i]
Terrarum.fontGame.draw(batch, message, 1f + drawOffX, (LINE_HEIGHT * (i + 1)).toFloat() + drawOffY) AppLoader.fontGame.draw(batch, message, 1f + drawOffX, (LINE_HEIGHT * (i + 1)).toFloat() + drawOffY)
} }
} }
@@ -181,7 +181,7 @@ class ConsoleWindow : UICanvas() {
commandInputPool = StringBuilder() commandInputPool = StringBuilder()
if (Authenticator.b()) { if (Authenticator.b()) {
sendMessage("${Terrarum.NAME} ${AppLoader.getVERSION_STRING()}") sendMessage("${AppLoader.GAME_NAME} ${AppLoader.getVERSION_STRING()}")
sendMessage(Lang["DEV_MESSAGE_CONSOLE_CODEX"]) sendMessage(Lang["DEV_MESSAGE_CONSOLE_CODEX"])
} }
} }

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.TerrarumIngame
/** /**
* UIHandler is a handler for UICanvas. It opens/closes the attached UI, moves the "window" (or "canvas") * UIHandler is a handler for UICanvas. It opens/closes the attached UI, moves the "window" (or "canvas")
@@ -279,7 +279,7 @@ class UIHandler(//var UI: UICanvas,
} }
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) { fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
Ingame.setCameraPosition(batch, camera, newX, newY) TerrarumIngame.setCameraPosition(batch, camera, newX, newY)
} }
fun mouseMoved(uiItems: List<UIItem>, screenX: Int, screenY: Int): Boolean { fun mouseMoved(uiItems: List<UIItem>, screenX: Int, screenY: Int): Boolean {

View File

@@ -3,8 +3,8 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.ModMgr import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.floor import net.torvald.terrarum.floor
@@ -20,9 +20,9 @@ class UIItemModuleInfoCell(
override var oldPosX = posX override var oldPosX = posX
override var oldPosY = posY override var oldPosY = posY
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2 override val height: Int = AppLoader.fontGame.lineHeight.toInt() * 2
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4 private val numberAreaWidth = AppLoader.fontSmallNumbers.W * 3 + 4
override fun render(batch: SpriteBatch, camera: Camera) { override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch) blendNormal(batch)
@@ -32,53 +32,53 @@ class UIItemModuleInfoCell(
// print load order index // print load order index
batch.color = Color(0xccccccff.toInt()) batch.color = Color(0xccccccff.toInt())
var strlen = Terrarum.fontSmallNumbers.getWidth(modInfo.order.toString()) var strlen = AppLoader.fontSmallNumbers.getWidth(modInfo.order.toString())
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
modInfo.order.toString(), modInfo.order.toString(),
posX + (numberAreaWidth - strlen).div(2f).floor(), posX + (numberAreaWidth - strlen).div(2f).floor(),
posY + (height - Terrarum.fontSmallNumbers.H).div(2f).floor() posY + (height - AppLoader.fontSmallNumbers.H).div(2f).floor()
) )
// print module name // print module name
batch.color = Color.WHITE batch.color = Color.WHITE
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
"${modInfo.properName} (${modInfo.version})", "${modInfo.properName} (${modInfo.version})",
posX + numberAreaWidth.toFloat(), posX + numberAreaWidth.toFloat(),
posY.toFloat() posY.toFloat()
) )
// print author name // print author name
strlen = Terrarum.fontGame.getWidth(modInfo.author) strlen = AppLoader.fontGame.getWidth(modInfo.author)
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
modInfo.author, modInfo.author,
posX + width - strlen.toFloat(), posX + width - strlen.toFloat(),
posY.toFloat() posY.toFloat()
) )
// print description // print description
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
modInfo.description, modInfo.description,
posX + numberAreaWidth.toFloat(), posX + numberAreaWidth.toFloat(),
posY + Terrarum.fontGame.lineHeight posY + AppLoader.fontGame.lineHeight
) )
// print releasedate // print releasedate
strlen = Terrarum.fontGame.getWidth(modInfo.releaseDate) strlen = AppLoader.fontGame.getWidth(modInfo.releaseDate)
Terrarum.fontGame.draw(batch, AppLoader.fontGame.draw(batch,
modInfo.releaseDate, modInfo.releaseDate,
posX + width - strlen.toFloat(), posX + width - strlen.toFloat(),
posY + Terrarum.fontGame.lineHeight posY + AppLoader.fontGame.lineHeight
) )
} }
else { else {
batch.color = Color(0xff8080_ff.toInt()) batch.color = Color(0xff8080_ff.toInt())
val str = "InternalError: no such module: '$moduleName'" val str = "InternalError: no such module: '$moduleName'"
val strlen = Terrarum.fontSmallNumbers.getWidth(str) val strlen = AppLoader.fontSmallNumbers.getWidth(str)
Terrarum.fontSmallNumbers.draw(batch, AppLoader.fontSmallNumbers.draw(batch,
str, str,
posX + (width - numberAreaWidth - strlen).div(2f).floor() + numberAreaWidth, posX + (width - numberAreaWidth - strlen).div(2f).floor() + numberAreaWidth,
posY + (height - Terrarum.fontSmallNumbers.H).div(2f).floor() posY + (height - AppLoader.fontSmallNumbers.H).div(2f).floor()
) )
} }
} }

View File

@@ -2,7 +2,7 @@ package net.torvald.terrarum.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.floor import net.torvald.terrarum.floor
import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
@@ -13,7 +13,7 @@ class UIItemTextArea(
override val width: Int, override val width: Int,
override val height: Int, override val height: Int,
val lineGap: Int = 0, val lineGap: Int = 0,
val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt(), val lineCount: Int = ((height + lineGap) / AppLoader.fontGame.lineHeight).toInt(),
val align: Alignment = Alignment.LEFT val align: Alignment = Alignment.LEFT
) : UIItem(parentUI) { ) : UIItem(parentUI) {
@@ -40,12 +40,12 @@ class UIItemTextArea(
for (i in scrollPos until minOf(lineCount + scrollPos, entireText.size)) { for (i in scrollPos until minOf(lineCount + scrollPos, entireText.size)) {
val yPtr = i - scrollPos val yPtr = i - scrollPos
val textWidth = Terrarum.fontGame.getWidth(entireText[i]) val textWidth = AppLoader.fontGame.getWidth(entireText[i])
when (align) { when (align) {
Alignment.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) Alignment.LEFT -> AppLoader.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (AppLoader.fontGame.lineHeight + lineGap))
Alignment.CENTRE -> Terrarum.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) Alignment.CENTRE -> AppLoader.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (AppLoader.fontGame.lineHeight + lineGap))
Alignment.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) Alignment.RIGHT -> AppLoader.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (AppLoader.fontGame.lineHeight + lineGap))
} }
} }
} }

View File

@@ -3,8 +3,8 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.BlendMode import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.fillRect import net.torvald.terrarum.fillRect
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
@@ -53,7 +53,7 @@ open class UIItemTextButton(
override var oldPosY = posY override var oldPosY = posY
companion object { companion object {
val font = Terrarum.fontGame val font = AppLoader.fontGame
val height = font.lineHeight.toInt() val height = font.lineHeight.toInt()
val defaultInactiveCol = Color.WHITE val defaultInactiveCol = Color.WHITE
val defaultHighlightCol = Color(0x00f8ff_ff) val defaultHighlightCol = Color(0x00f8ff_ff)

View File

@@ -31,14 +31,14 @@ class UINSMenu(
override var openCloseTime: Second = 0f override var openCloseTime: Second = 0f
val LINE_HEIGHT = 24 val LINE_HEIGHT = 24
val TEXT_OFFSETX = 3f val TEXT_OFFSETX = 3f
val TEXT_OFFSETY = (LINE_HEIGHT - Terrarum.fontGame.lineHeight) / 2f val TEXT_OFFSETY = (LINE_HEIGHT - AppLoader.fontGame.lineHeight) / 2f
val CHILD_ARROW = "${0x2023.toChar()}" val CHILD_ARROW = "${0x2023.toChar()}"
val tree = treeRepresentation.parseAsYamlInvokable() val tree = treeRepresentation.parseAsYamlInvokable()
override var width = 0 override var width = 0
override var height = 0 override var height = 0
//override var width = maxOf(minimumWidth, tree.getLevelData(1).map { Terrarum.fontGame.getWidth(it ?: "") }.max() ?: 0) //override var width = maxOf(minimumWidth, tree.getLevelData(1).map { AppLoader.fontGame.getWidth(it ?: "") }.max() ?: 0)
//override var height = LINE_HEIGHT * (tree.children.size + 1) //override var height = LINE_HEIGHT * (tree.children.size + 1)
@@ -91,8 +91,8 @@ class UINSMenu(
} }
val listWidth = maxOf( val listWidth = maxOf(
Terrarum.fontGame.getWidth(menuTitle), minimumWidth, AppLoader.fontGame.getWidth(menuTitle), minimumWidth,
stringsFromTree.map { Terrarum.fontGame.getWidth(it) }.max() ?: 0 stringsFromTree.map { AppLoader.fontGame.getWidth(it) }.max() ?: 0
) )
val uiWidth = listWidth + (2 * TEXT_OFFSETX.toInt()) val uiWidth = listWidth + (2 * TEXT_OFFSETX.toInt())
val listHeight = stringsFromTree.size * LINE_HEIGHT val listHeight = stringsFromTree.size * LINE_HEIGHT
@@ -176,7 +176,7 @@ class UINSMenu(
batch.color = titleTextCol batch.color = titleTextCol
blendNormal(batch) blendNormal(batch)
Terrarum.fontGame.draw(batch, it.title, TEXT_OFFSETX + it.ui.posX, TEXT_OFFSETY + it.ui.posY - LINE_HEIGHT) AppLoader.fontGame.draw(batch, it.title, TEXT_OFFSETX + it.ui.posX, TEXT_OFFSETY + it.ui.posY - LINE_HEIGHT)
// draw the list // draw the list
batch.color = Color.WHITE batch.color = Color.WHITE

View File

@@ -74,8 +74,8 @@ object LightmapRenderer {
} }
} }
val overscan_open: Int = 40 private const val overscan_open: Int = 40
val overscan_opaque: Int = 10 private const val overscan_opaque: Int = 10
// TODO resize(int, int) -aware // TODO resize(int, int) -aware
@@ -83,7 +83,7 @@ object LightmapRenderer {
var LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.WIDTH).div(TILE_SIZE).ceil() + overscan_open * 2 + 3 var LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.WIDTH).div(TILE_SIZE).ceil() + overscan_open * 2 + 3
var LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.HEIGHT).div(TILE_SIZE).ceil() + overscan_open * 2 + 3 var LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.HEIGHT).div(TILE_SIZE).ceil() + overscan_open * 2 + 3
val noopMask = HashSet<Point2i>((LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT) * 2) private val noopMask = HashSet<Point2i>((LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT) * 2)
/** /**
* Float value, 1.0 for 1023 * Float value, 1.0 for 1023
@@ -99,9 +99,9 @@ object LightmapRenderer {
printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque") printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque")
} }
private val AIR = Block.AIR private const val AIR = Block.AIR
val DRAW_TILE_SIZE: Float = CreateTileAtlas.TILE_SIZE / IngameRenderer.lightmapDownsample const val DRAW_TILE_SIZE: Float = CreateTileAtlas.TILE_SIZE / IngameRenderer.lightmapDownsample
// color model related constants // color model related constants
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB
@@ -120,9 +120,17 @@ object LightmapRenderer {
internal var for_x = 0 internal var for_x = 0
internal var for_y = 0 internal var for_y = 0
/**
//inline fun getLightRawPos(x: Int, y: Int) = lightmap[y][x] * @param x world coord
* @param y world coord
*/
private fun inBounds(x: Int, y: Int) =
(y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH)
/** World coord to array coord */
private inline fun Int.convX() = this - for_x_start + overscan_open
/** World coord to array coord */
private inline fun Int.convY() = this - for_y_start + overscan_open
/** /**
* Conventional level (multiplied by four) * Conventional level (multiplied by four)
@@ -147,66 +155,6 @@ object LightmapRenderer {
} }
} }
/**
* @param x world coord
* @param y world coord
*/
private fun inBounds(x: Int, y: Int) =
(y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH)
/** World coord to array coord */
private inline fun Int.convX() = this - for_x_start + overscan_open
/** World coord to array coord */
private inline fun Int.convY() = this - for_y_start + overscan_open
/**
* Internal level (0..1)
*
* @param x world tile coord
* @param y world tile coord
*/
// TODO in regard of "colour math against integers", return Int?
/*private fun getLightInternal(x: Int, y: Int): Cvec? {
if (y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
val ypos = y - for_y_start + overscan_open
val xpos = x - for_x_start + overscan_open
// TODO as you can see above, we're already doing a boundary check; try using unsafe here?
return lightmap[ypos][xpos]
//return lightmap[ypos * LIGHTMAP_WIDTH + xpos]
}
return null
}*/
/**
* Converts world coord (x,y) into the lightmap index, and stores the input colour into the given list
* with given applyFun applied.
*
* Default 'applyFun' is simply storing given colour into the array.
*
* @param list The lightmap
* @param x World X coordinate
* @param y World Y coordinate
* @param colour Cvec to write
* @param applyFun A function ```foo(old_colour, given_colour)```
*/
/*private fun setLightOf(list: Array<Array<Cvec>>, x: Int, y: Int, colour: Cvec, applyFun: (Cvec, Cvec) -> Cvec = { _, c -> c }) {
if (y - for_y_start + overscan_open in 0 until LIGHTMAP_HEIGHT &&
x - for_x_start + overscan_open in 0 until LIGHTMAP_WIDTH) {
val ypos = y - for_y_start + overscan_open
val xpos = x - for_x_start + overscan_open
// TODO as you can see above, we're already doing a boundary check; try using unsafe here?
lightmap[ypos][xpos] = applyFun.invoke(list[ypos][xpos], colour)
//list[ypos * LIGHTMAP_WIDTH + xpos] = applyFun.invoke(list[ypos * LIGHTMAP_WIDTH + xpos], colour)
}
}*/
internal fun fireRecalculateEvent(vararg actorContainers: List<ActorWithBody>?) { internal fun fireRecalculateEvent(vararg actorContainers: List<ActorWithBody>?) {
try { try {
world.getTileFromTerrain(0, 0) // test inquiry world.getTileFromTerrain(0, 0) // test inquiry
@@ -395,7 +343,7 @@ object LightmapRenderer {
} }
} }
updateMessages = lightTaskArr.toTypedArray().sliceEvenly(Terrarum.THREADS) updateMessages = lightTaskArr.toTypedArray().sliceEvenly(AppLoader.THREADS)
} }
internal data class ThreadedLightmapUpdateMessage(val x: Int, val y: Int) internal data class ThreadedLightmapUpdateMessage(val x: Int, val y: Int)
@@ -650,7 +598,7 @@ object LightmapRenderer {
private val colourNull = Cvec(0) private val colourNull = Cvec(0)
private val gdxColorNull = Color(0) private val gdxColorNull = Color(0)
private val epsilon = 1f/1024f private const val epsilon = 1f/1024f
private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888) private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
@@ -719,10 +667,12 @@ object LightmapRenderer {
} }
fun dispose() { fun dispose() {
_lightBufferAsTex.dispose()
lightBuffer.dispose()
lightmap.destroy()
} }
val lightScalingMagic = 8f private const val lightScalingMagic = 8f
/** /**
* Subtract each channel's RGB value. * Subtract each channel's RGB value.
@@ -732,7 +682,7 @@ object LightmapRenderer {
* @param darken (0-255) per channel * @param darken (0-255) per channel
* @return darkened data (0-255) per channel * @return darkened data (0-255) per channel
*/ */
fun darkenColoured(x: Int, y: Int, darken: Cvec): Cvec { private fun darkenColoured(x: Int, y: Int, darken: Cvec): Cvec {
// use equation with magic number 8.0 // use equation with magic number 8.0
// this function, when done recursively (A_x = darken(A_x-1, C)), draws exponential curve. (R^2 = 1) // this function, when done recursively (A_x = darken(A_x-1, C)), draws exponential curve. (R^2 = 1)
@@ -753,24 +703,8 @@ object LightmapRenderer {
} }
/**
* Darken or brighten colour by 'brighten' argument
*
* @param data Raw channel value (0-255) per channel
* @param brighten (-1.0 - 1.0) negative means darkening
* @return processed colour
*/
fun alterBrightnessUniform(data: Cvec, brighten: Float): Cvec {
return Cvec(
data.r + brighten,
data.g + brighten,
data.b + brighten,
data.a + brighten
)
}
/** infix is removed to clarify the association direction */ /** infix is removed to clarify the association direction */
fun Cvec.maxAndAssign(other: Cvec): Cvec { private fun Cvec.maxAndAssign(other: Cvec): Cvec {
// TODO investigate: if I use assignment instead of set(), it blackens like the vector branch. --Torvald, 2019-06-07 // TODO investigate: if I use assignment instead of set(), it blackens like the vector branch. --Torvald, 2019-06-07
// that was because you forgot 'this.r/g/b/a = ' part, bitch. --Torvald, 2019-06-07 // that was because you forgot 'this.r/g/b/a = ' part, bitch. --Torvald, 2019-06-07
this.r = if (this.r > other.r) this.r else other.r this.r = if (this.r > other.r) this.r else other.r
@@ -793,7 +727,7 @@ object LightmapRenderer {
// TODO: float LUT lookup using linear interpolation // TODO: float LUT lookup using linear interpolation
// input: 0..1 for int 0..1023 // input: 0..1 for int 0..1023
fun hdr(intensity: Float): Float { private fun hdr(intensity: Float): Float {
val intervalStart = (intensity * CHANNEL_MAX).floorInt() val intervalStart = (intensity * CHANNEL_MAX).floorInt()
val intervalEnd = minOf(rgbHDRLookupTable.lastIndex, (intensity * CHANNEL_MAX).floorInt() + 1) val intervalEnd = minOf(rgbHDRLookupTable.lastIndex, (intensity * CHANNEL_MAX).floorInt() + 1)
@@ -839,7 +773,7 @@ object LightmapRenderer {
} }
val rgbHDRLookupTable = floatArrayOf( // polynomial of 6.0 please refer to work_files/HDRcurveBezierLinIntp.kts private val rgbHDRLookupTable = floatArrayOf( // polynomial of 6.0 please refer to work_files/HDRcurveBezierLinIntp.kts
0.0000f,0.0004f,0.0020f,0.0060f,0.0100f,0.0139f,0.0179f,0.0219f,0.0259f,0.0299f,0.0338f,0.0378f,0.0418f,0.0458f,0.0497f,0.0537f, 0.0000f,0.0004f,0.0020f,0.0060f,0.0100f,0.0139f,0.0179f,0.0219f,0.0259f,0.0299f,0.0338f,0.0378f,0.0418f,0.0458f,0.0497f,0.0537f,
0.0577f,0.0617f,0.0656f,0.0696f,0.0736f,0.0776f,0.0816f,0.0855f,0.0895f,0.0935f,0.0975f,0.1014f,0.1054f,0.1094f,0.1134f,0.1173f, 0.0577f,0.0617f,0.0656f,0.0696f,0.0736f,0.0776f,0.0816f,0.0855f,0.0895f,0.0935f,0.0975f,0.1014f,0.1054f,0.1094f,0.1134f,0.1173f,
0.1213f,0.1253f,0.1293f,0.1332f,0.1372f,0.1412f,0.1451f,0.1491f,0.1531f,0.1571f,0.1610f,0.1650f,0.1690f,0.1730f,0.1769f,0.1809f, 0.1213f,0.1253f,0.1293f,0.1332f,0.1372f,0.1412f,0.1451f,0.1491f,0.1531f,0.1571f,0.1610f,0.1650f,0.1690f,0.1730f,0.1769f,0.1809f,
@@ -906,7 +840,7 @@ object LightmapRenderer {
1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f // isn't it beautiful? 1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f,1.0000f // isn't it beautiful?
) )
/** To eliminated visible edge on the gradient when 255/1023 is exceeded */ /** To eliminated visible edge on the gradient when 255/1023 is exceeded */
internal fun Color.normaliseToHDR() = Color( fun Color.normaliseToHDR() = Color(
hdr(this.r.coerceIn(0f, 1f)), hdr(this.r.coerceIn(0f, 1f)),
hdr(this.g.coerceIn(0f, 1f)), hdr(this.g.coerceIn(0f, 1f)),
hdr(this.b.coerceIn(0f, 1f)), hdr(this.b.coerceIn(0f, 1f)),
@@ -927,14 +861,7 @@ object LightmapRenderer {
for (y in overscan_open..render_height + overscan_open + 1) { for (y in overscan_open..render_height + overscan_open + 1) {
for (x in overscan_open..render_width + overscan_open + 1) { for (x in overscan_open..render_width + overscan_open + 1) {
try { try {
//val colour = lightmap[y][x] // TODO
//val colour = lightmap[y * LIGHTMAP_WIDTH + x]
val x = x.convX()
val y = y.convY()
//reds[minOf(CHANNEL_MAX, lightmap.getR(x, y).times(MUL).floorInt())] += 1
//greens[minOf(CHANNEL_MAX, lightmap.getG(x, y).times(MUL).floorInt())] += 1
//blues[minOf(CHANNEL_MAX, lightmap.getB(x, y).floorInt())] += 1
//uvs[minOf(CHANNEL_MAX, lightmap.getA(x, y).floorInt())] += 1
} }
catch (e: ArrayIndexOutOfBoundsException) { } catch (e: ArrayIndexOutOfBoundsException) { }
} }