mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
initial screen size is read from the config
This commit is contained in:
@@ -129,7 +129,7 @@ public class LwjglGraphics implements Graphics {
|
|||||||
// only for a > 0 && b > 0
|
// only for a > 0 && b > 0
|
||||||
private float getMagnitudeDifference(float a, float b) {
|
private float getMagnitudeDifference(float a, float b) {
|
||||||
if (a < getMagnitudeDifferenceEpsilon || b < getMagnitudeDifferenceEpsilon) {
|
if (a < getMagnitudeDifferenceEpsilon || b < getMagnitudeDifferenceEpsilon) {
|
||||||
return a + b;
|
return (a + b) / getMagnitudeDifferenceEpsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a > b) {
|
if (a > b) {
|
||||||
|
|||||||
@@ -154,18 +154,28 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
public static ArrayListMap debugTimers = new ArrayListMap<String, Long>();
|
public static ArrayListMap debugTimers = new ArrayListMap<String, Long>();
|
||||||
|
|
||||||
|
static final int defaultW = 1110;
|
||||||
|
static final int defaultH = 740;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
// load configs
|
||||||
|
getDefaultDirectory();
|
||||||
|
createDirs();
|
||||||
|
readConfigJson();
|
||||||
|
|
||||||
|
|
||||||
ShaderProgram.pedantic = false;
|
ShaderProgram.pedantic = false;
|
||||||
|
|
||||||
LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
|
||||||
//appConfig.useGL30 = true; // used: loads GL 3.2, unused: loads GL 4.6; what the fuck?
|
//appConfig.useGL30 = true; // used: loads GL 3.2, unused: loads GL 4.6; what the fuck?
|
||||||
appConfig.vSyncEnabled = true;
|
appConfig.vSyncEnabled = getConfigBoolean("usevsync");
|
||||||
appConfig.resizable = false;//true;
|
appConfig.resizable = false;//true;
|
||||||
appConfig.width = 1110; // photographic ratio (1.5:1)
|
//appConfig.width = 1110; // photographic ratio (1.5:1)
|
||||||
appConfig.height = 740; // photographic ratio (1.5:1)
|
//appConfig.height = 740; // photographic ratio (1.5:1)
|
||||||
appConfig.backgroundFPS = 0;
|
appConfig.width = getConfigInt("screenwidth");
|
||||||
appConfig.foregroundFPS = 0;
|
appConfig.height = getConfigInt("screenheight");
|
||||||
|
appConfig.backgroundFPS = getConfigInt("displayfps");
|
||||||
|
appConfig.foregroundFPS = getConfigInt("displayfps");
|
||||||
appConfig.title = GAME_NAME;
|
appConfig.title = GAME_NAME;
|
||||||
appConfig.forceExit = false;
|
appConfig.forceExit = false;
|
||||||
|
|
||||||
@@ -396,16 +406,6 @@ public class AppLoader implements ApplicationListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void postInit() {
|
private void postInit() {
|
||||||
// load configs
|
|
||||||
getDefaultDirectory();
|
|
||||||
createDirs();
|
|
||||||
readConfigJson();
|
|
||||||
|
|
||||||
// set render configs according to local config
|
|
||||||
appConfig.vSyncEnabled = getConfigBoolean("usevsync");
|
|
||||||
appConfig.foregroundFPS = getConfigInt("displayfps");
|
|
||||||
appConfig.backgroundFPS = getConfigInt("displayfps");
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
public static String configDir;
|
public static String configDir;
|
||||||
public static RunningEnvironment environment;
|
public static RunningEnvironment environment;
|
||||||
|
|
||||||
private void getDefaultDirectory() {
|
private static void getDefaultDirectory() {
|
||||||
String OS = OSName.toUpperCase();
|
String OS = OSName.toUpperCase();
|
||||||
if (OS.contains("WIN")) {
|
if (OS.contains("WIN")) {
|
||||||
operationSystem = "WINDOWS";
|
operationSystem = "WINDOWS";
|
||||||
@@ -495,7 +495,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
System.out.println(String.format("default directory: %s", defaultDir));
|
System.out.println(String.format("default directory: %s", defaultDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDirs() {
|
private static void createDirs() {
|
||||||
File[] dirs = {new File(defaultSaveDir)};
|
File[] dirs = {new File(defaultSaveDir)};
|
||||||
|
|
||||||
for (File it : dirs) {
|
for (File it : dirs) {
|
||||||
@@ -641,7 +641,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
if (defaults == null) {
|
if (defaults == null) {
|
||||||
throw new NullPointerException("key not found: '$key'");
|
throw new NullPointerException("key not found: '" + key + "'");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return defaults;
|
return defaults;
|
||||||
@@ -661,13 +661,13 @@ public class AppLoader implements ApplicationListener {
|
|||||||
// //
|
// //
|
||||||
|
|
||||||
public static void printdbg(Object obj, Object message) {
|
public static void printdbg(Object obj, Object message) {
|
||||||
if (IS_DEVELOPMENT_BUILD || getConfigBoolean("forcedevbuild")) {
|
if (IS_DEVELOPMENT_BUILD) {
|
||||||
System.out.println("[" + obj.getClass().getSimpleName() + "] " + message.toString());
|
System.out.println("[" + obj.getClass().getSimpleName() + "] " + message.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printdbgerr(Object obj, Object message) {
|
public static void printdbgerr(Object obj, Object message) {
|
||||||
if (IS_DEVELOPMENT_BUILD || getConfigBoolean("forcedevbuild")) {
|
if (IS_DEVELOPMENT_BUILD) {
|
||||||
System.err.println("[" + obj.getClass().getSimpleName() + "] " + message.toString());
|
System.err.println("[" + obj.getClass().getSimpleName() + "] " + message.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ object DefaultConfig {
|
|||||||
|
|
||||||
jsonObject.addProperty("displayfps", 0) // 0: no limit, non-zero: limit
|
jsonObject.addProperty("displayfps", 0) // 0: no limit, non-zero: limit
|
||||||
jsonObject.addProperty("usevsync", false)
|
jsonObject.addProperty("usevsync", false)
|
||||||
jsonObject.addProperty("forcedevbuild", false)
|
jsonObject.addProperty("screenwidth", AppLoader.defaultW)
|
||||||
|
jsonObject.addProperty("screenheight", AppLoader.defaultH)
|
||||||
|
|
||||||
|
|
||||||
jsonObject.addProperty("imtooyoungtodie", false) // no perma-death
|
jsonObject.addProperty("imtooyoungtodie", false) // no perma-death
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package net.torvald.terrarum
|
package net.torvald.terrarum
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.GL20
|
import com.badlogic.gdx.graphics.GL20
|
||||||
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 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.math.Matrix4
|
import com.badlogic.gdx.math.Matrix4
|
||||||
import kotlin.system.measureNanoTime
|
import kotlin.system.measureNanoTime
|
||||||
|
|
||||||
@@ -16,21 +17,26 @@ import kotlin.system.measureNanoTime
|
|||||||
object PostProcessor {
|
object PostProcessor {
|
||||||
|
|
||||||
private lateinit var batch: SpriteBatch // not nulling to save some lines of code
|
private lateinit var batch: SpriteBatch // not nulling to save some lines of code
|
||||||
|
private lateinit var shapeRenderer: ShapeRenderer
|
||||||
//private lateinit var camera: OrthographicCamera
|
//private lateinit var camera: OrthographicCamera
|
||||||
private var textureRegion: TextureRegion? = null
|
//private var textureRegion: TextureRegion? = null
|
||||||
|
|
||||||
|
|
||||||
private lateinit var lutTex: Texture
|
private lateinit var lutTex: Texture
|
||||||
|
|
||||||
|
private var init = false
|
||||||
|
|
||||||
fun reloadLUT(filename: String) {
|
fun reloadLUT(filename: String) {
|
||||||
lutTex = Texture(Gdx.files.internal("assets/clut/$filename"))
|
lutTex = Texture(Gdx.files.internal("assets/clut/$filename"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun draw(projMat: Matrix4, fbo: FrameBuffer) {
|
fun draw(projMat: Matrix4, fbo: FrameBuffer) {
|
||||||
|
|
||||||
if (textureRegion == null) {
|
// init
|
||||||
textureRegion = TextureRegion(fbo.colorBufferTexture)
|
if (!init) {
|
||||||
|
//textureRegion = TextureRegion(fbo.colorBufferTexture)
|
||||||
batch = SpriteBatch()
|
batch = SpriteBatch()
|
||||||
|
shapeRenderer = ShapeRenderer()
|
||||||
Gdx.gl20.glViewport(0, 0, AppLoader.appConfig.width, AppLoader.appConfig.height)
|
Gdx.gl20.glViewport(0, 0, AppLoader.appConfig.width, AppLoader.appConfig.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +64,17 @@ object PostProcessor {
|
|||||||
|
|
||||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
||||||
|
|
||||||
|
if (AppLoader.IS_DEVELOPMENT_BUILD) {
|
||||||
|
shapeRenderer.color = Color.CYAN
|
||||||
|
shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) {
|
||||||
|
shapeRenderer.rect(
|
||||||
|
(AppLoader.screenW - AppLoader.defaultW).div(2).toFloat(),
|
||||||
|
(AppLoader.screenH - AppLoader.defaultH).div(2).toFloat(),
|
||||||
|
AppLoader.defaultW.toFloat(),
|
||||||
|
AppLoader.defaultH.toFloat()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user