still cleaning up

Making wall item textures takes SO long
This commit is contained in:
Minjae Song
2018-12-25 15:39:01 +09:00
parent 09d8702089
commit 98755fab61
6 changed files with 90 additions and 68 deletions

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.*;
@@ -14,6 +15,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.torvald.dataclass.ArrayListMap;
import net.torvald.terrarum.modulebasegame.IngameRenderer;
import net.torvald.terrarum.utils.JsonFetcher;
import net.torvald.terrarum.utils.JsonWriter;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
@@ -85,6 +87,7 @@ public class AppLoader implements ApplicationListener {
/**
* Default null constructor. Don't use it.
*/
@Deprecated
public AppLoader() {
}
@@ -153,6 +156,7 @@ public class AppLoader implements ApplicationListener {
ShaderProgram.pedantic = false;
LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
appConfig.useGL30 = true;
appConfig.vSyncEnabled = false;
appConfig.resizable = false;//true;
//appConfig.width = 1072; // IMAX ratio
@@ -176,6 +180,7 @@ public class AppLoader implements ApplicationListener {
private OrthographicCamera camera;
private SpriteBatch logoBatch;
public static TextureRegion logo;
public static AudioDevice audioDevice;
private Color gradWhiteTop = new Color(0xf8f8f8ff);
private Color gradWhiteBottom = new Color(0xd8d8d8ff);
@@ -228,28 +233,15 @@ public class AppLoader implements ApplicationListener {
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
);
fullscreenQuad.setVertices(new float[]{
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
((float) appConfig.width), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
((float) appConfig.width), ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 0f, 0f
});
fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0});
// load configs
getDefaultDirectory();
createDirs();
readConfigJson();
updateFullscreenQuad(appConfig.width, appConfig.height);
}
@Override
public void render() {
if (splashDisplayed && !postInitFired) {
postInit();
postInitFired = true;
postInit();
}
@@ -347,12 +339,19 @@ public class AppLoader implements ApplicationListener {
@Override
public void dispose() {
if (screen != null) screen.hide();
System.out.println("Goodbye !");
if (screen != null) {
screen.hide();
screen.dispose();
}
IngameRenderer.INSTANCE.dispose();
// delete temp files
new File("./tmp_wenquanyi.tga").delete();
new File("./tmp_wenquanyi.tga").delete(); // FIXME this is pretty much ad-hoc
}
@Override
@@ -368,7 +367,11 @@ public class AppLoader implements ApplicationListener {
public void setScreen(Screen screen) {
printdbg(this, "Changing screen to " + screen.getClass().getCanonicalName());
if (this.screen != null) this.screen.hide();
// this whole thing is directtly copied from com.badlogic.gdx.Game
if (this.screen != null) {
this.screen.hide();
}
this.screen = screen;
if (this.screen != null) {
this.screen.show();
@@ -379,6 +382,11 @@ public class AppLoader implements ApplicationListener {
}
private void postInit() {
// load configs
getDefaultDirectory();
createDirs();
readConfigJson();
textureWhiteSquare = new Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"));
textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
@@ -387,11 +395,15 @@ public class AppLoader implements ApplicationListener {
Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 128, false
);
audioDevice = Gdx.audio.newAudioDevice(48000, false);
// if there is a predefined screen, open that screen after my init process
if (injectScreen != null) {
setScreen(injectScreen);
}
printdbg(this, "PostInit done");
}
@@ -623,13 +635,13 @@ public class AppLoader implements ApplicationListener {
// //
public static final void printdbg(Object obj, Object message) {
if (IS_DEVELOPMENT_BUILD) {
if (IS_DEVELOPMENT_BUILD || getConfigBoolean("forcedevbuild")) {
System.out.println("[" + obj.getClass().getSimpleName() + "] " + message.toString());
}
}
public static final void printdbgerr(Object obj, Object message) {
if (IS_DEVELOPMENT_BUILD) {
if (IS_DEVELOPMENT_BUILD || getConfigBoolean("forcedevbuild")) {
System.err.println("[" + obj.getClass().getSimpleName() + "] " + message.toString());
}
}

View File

@@ -15,6 +15,7 @@ object DefaultConfig {
jsonObject.addProperty("displayfps", 0) // 0: no limit, non-zero: limit
jsonObject.addProperty("usevsync", true)
jsonObject.addProperty("forcedevbuild", false)
jsonObject.addProperty("imtooyoungtodie", false) // no perma-death
@@ -75,23 +76,20 @@ object DefaultConfig {
jsonObject.addProperty("pcgamepadenv", "console")
jsonObject.addProperty("safetywarning", true)
//jsonObject.addProperty("safetywarning", true)
jsonObject.addProperty("maxparticles", 768)
jsonObject.addProperty("fullframelightupdate", false)
//jsonObject.addProperty("fullframelightupdate", false)
jsonObject.addProperty("temperatureunit", 1) // -1: american, 0: kelvin, 1: celcius
// "fancy" graphics settings
jsonObject.addProperty("fxdither", true)
jsonObject.addProperty("fx3dlut", false)
jsonObject.addProperty("__debug", false)
//jsonObject.addProperty("fx3dlut", false)
return jsonObject

View File

@@ -18,14 +18,16 @@ import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.gameactors.*
import net.torvald.terrarum.modulebasegame.gameactors.HumanoidNPC
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.ui.UIRemoCon
import net.torvald.terrarum.serialise.ReadLayerData
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.modulebasegame.ui.UITitleRemoConYaml
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.*
import net.torvald.terrarum.serialise.ReadLayerData
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera
import java.io.FileInputStream
/**
@@ -49,7 +51,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
private var loadDone = false
//private var loadDone = false // not required; draw-while-loading is implemented in the AppLoader
private lateinit var demoWorld: GameWorldExtension
private lateinit var cameraNodes: FloatArray // camera Y-pos
@@ -128,14 +130,14 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
// construct camera nodes
val nodeCount = 100
cameraNodes = kotlin.FloatArray(nodeCount, { it ->
cameraNodes = kotlin.FloatArray(nodeCount) { it ->
val tileXPos = (demoWorld.width.toFloat() * it / nodeCount).floorInt()
var travelDownCounter = 0
while (!BlockCodex[demoWorld.getTileFromTerrain(tileXPos, travelDownCounter)].isSolid) {
travelDownCounter += 4
}
travelDownCounter * FeaturesDrawer.TILE_SIZE.toFloat()
})
}
cameraPlayer = object : HumanoidNPC(cameraAI, born = 0, usePhysics = false, forceAssignRefID = Terrarum.PLAYER_REF_ID) {
@@ -164,7 +166,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
uiContainer.add(uiMenu)
loadDone = true
//loadDone = true
}
@@ -172,7 +174,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
override fun show() {
printdbg(this, "atrniartsientsarinoetsar")
printdbg(this, "show() called")
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT)
@@ -184,6 +186,10 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
worldFBO = FrameBuffer(Pixmap.Format.RGBA8888, Terrarum.WIDTH, Terrarum.HEIGHT, false)
loadThingsWhileIntroIsVisible()
printdbg(this, "show() exit")
}
@@ -193,26 +199,21 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
protected val renderRate = Terrarum.renderRate
override fun render(delta: Float) {
if (!loadDone) {
loadThingsWhileIntroIsVisible()
}
else {
// async update
updateDeltaCounter += delta
var updateTries = 0
while (updateDeltaCounter >= renderRate) {
updateScreen(delta)
updateDeltaCounter -= renderRate
updateTries++
// async update
updateDeltaCounter += delta
var updateTries = 0
while (updateDeltaCounter >= renderRate) {
updateScreen(delta)
updateDeltaCounter -= renderRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
// render? just do it anyway
renderScreen()
}
// render? just do it anyway
renderScreen()
}
fun updateScreen(delta: Float) {
@@ -289,22 +290,24 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
override fun resize(width: Int, height: Int) {
printdbg(this, "resize() called")
// Set up viewport when window is resized
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT)
BlocksDrawer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
LightmapRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
if (loadDone) {
// resize UI by re-creating it (!!)
uiMenu.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
//uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY)
uiMenu.setPosition(0, 0) // shitty hack. Could be:
// 1: Init code and resize code are different
// 2: The UI is coded shit
}
// resize UI by re-creating it (!!)
uiMenu.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
// TODO I forgot what the fuck kind of hack I was talking about
//uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY)
uiMenu.setPosition(0, 0) // shitty hack. Could be:
// 1: Init code and resize code are different
// 2: The UI is coded shit
IngameRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
printdbg(this, "resize() exit")
}
override fun dispose() {

View File

@@ -970,6 +970,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderMiddle.forEach { it.dispose() }
actorsRenderMidTop.forEach { it.dispose() }
actorsRenderFront.forEach { it.dispose() }
actorsRenderOverlay.forEach { it.dispose() }
uiAliases.forEach { it.dispose() }
uiAlasesPausing.forEach { it.dispose() }

View File

@@ -24,7 +24,7 @@ class Notification : UICanvas() {
)
private var displayTimer = 0f
internal var message: Array<String> = Array(MessageWindow.MESSAGES_DISPLAY, { "" })
internal var message: Array<String> = Array(MessageWindow.MESSAGES_DISPLAY) { "" }
override var openCloseTime: Second = MessageWindow.OPEN_CLOSE_TIME

View File

@@ -4,18 +4,20 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.math.Matrix4
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.PairedMapLayer
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.ceilInt
import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.PairedMapLayer
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_TILES
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.roundInt
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.io.BufferedOutputStream
import java.io.File
@@ -91,6 +93,8 @@ internal object BlocksDrawer {
private val shader = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/tiling.frag"))
init {
printdbg(this, "Unpacking textures...")
// PNG still doesn't work right.
// The thing is, pixel with alpha 0 must have RGB of also 0, which PNG does not guarantee it.
// (pixels of RGB = 255, A = 0 -- white transparent -- causes 'glow')
@@ -137,6 +141,7 @@ internal object BlocksDrawer {
printdbg(this, "Making wall item textures...")
// create item_wall images
// --> make pixmap
@@ -166,6 +171,9 @@ internal object BlocksDrawer {
_tileItemImgPixMap.dispose()
_terrainPixMap.dispose() // finally
printdbg(this, "init() exit")
}
/**