initial screen size is read from the config

This commit is contained in:
minjaesong
2019-01-22 20:56:16 +09:00
parent 53c45d6829
commit 450874540c
4 changed files with 44 additions and 27 deletions

View File

@@ -129,7 +129,7 @@ public class LwjglGraphics implements Graphics {
// only for a > 0 && b > 0
private float getMagnitudeDifference(float a, float b) {
if (a < getMagnitudeDifferenceEpsilon || b < getMagnitudeDifferenceEpsilon) {
return a + b;
return (a + b) / getMagnitudeDifferenceEpsilon;
}
if (a > b) {

View File

@@ -154,18 +154,28 @@ public class AppLoader implements ApplicationListener {
public static ArrayListMap debugTimers = new ArrayListMap<String, Long>();
static final int defaultW = 1110;
static final int defaultH = 740;
public static void main(String[] args) {
// load configs
getDefaultDirectory();
createDirs();
readConfigJson();
ShaderProgram.pedantic = false;
LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
//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.width = 1110; // photographic ratio (1.5:1)
appConfig.height = 740; // photographic ratio (1.5:1)
appConfig.backgroundFPS = 0;
appConfig.foregroundFPS = 0;
//appConfig.width = 1110; // photographic ratio (1.5:1)
//appConfig.height = 740; // photographic ratio (1.5:1)
appConfig.width = getConfigInt("screenwidth");
appConfig.height = getConfigInt("screenheight");
appConfig.backgroundFPS = getConfigInt("displayfps");
appConfig.foregroundFPS = getConfigInt("displayfps");
appConfig.title = GAME_NAME;
appConfig.forceExit = false;
@@ -396,16 +406,6 @@ public class AppLoader implements ApplicationListener {
}
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.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
@@ -459,7 +459,7 @@ public class AppLoader implements ApplicationListener {
public static String configDir;
public static RunningEnvironment environment;
private void getDefaultDirectory() {
private static void getDefaultDirectory() {
String OS = OSName.toUpperCase();
if (OS.contains("WIN")) {
operationSystem = "WINDOWS";
@@ -495,7 +495,7 @@ public class AppLoader implements ApplicationListener {
System.out.println(String.format("default directory: %s", defaultDir));
}
private void createDirs() {
private static void createDirs() {
File[] dirs = {new File(defaultSaveDir)};
for (File it : dirs) {
@@ -641,7 +641,7 @@ public class AppLoader implements ApplicationListener {
if (config == null) {
if (defaults == null) {
throw new NullPointerException("key not found: '$key'");
throw new NullPointerException("key not found: '" + key + "'");
}
else {
return defaults;
@@ -661,13 +661,13 @@ public class AppLoader implements ApplicationListener {
// //
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());
}
}
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());
}
}

View File

@@ -15,7 +15,8 @@ object DefaultConfig {
jsonObject.addProperty("displayfps", 0) // 0: no limit, non-zero: limit
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

View File

@@ -1,12 +1,13 @@
package net.torvald.terrarum
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Matrix4
import kotlin.system.measureNanoTime
@@ -16,21 +17,26 @@ import kotlin.system.measureNanoTime
object PostProcessor {
private lateinit var batch: SpriteBatch // not nulling to save some lines of code
private lateinit var shapeRenderer: ShapeRenderer
//private lateinit var camera: OrthographicCamera
private var textureRegion: TextureRegion? = null
//private var textureRegion: TextureRegion? = null
private lateinit var lutTex: Texture
private var init = false
fun reloadLUT(filename: String) {
lutTex = Texture(Gdx.files.internal("assets/clut/$filename"))
}
fun draw(projMat: Matrix4, fbo: FrameBuffer) {
if (textureRegion == null) {
textureRegion = TextureRegion(fbo.colorBufferTexture)
// init
if (!init) {
//textureRegion = TextureRegion(fbo.colorBufferTexture)
batch = SpriteBatch()
shapeRenderer = ShapeRenderer()
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
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()
)
}
}
}
}