Renamed AppLoader into App

This commit is contained in:
minjaesong
2021-09-09 09:48:33 +09:00
parent c3dd005fb2
commit 8f834fe869
116 changed files with 796 additions and 850 deletions

View File

@@ -5,11 +5,10 @@ import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.math.Matrix4
import com.jme3.math.FastMath
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.measureDebugTime
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.App.measureDebugTime
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod
@@ -86,7 +85,7 @@ internal object BlocksDrawer {
private lateinit var tilesQuad: Mesh
private val shader = AppLoader.loadShaderFromFile("assets/4096.vert", "assets/tiling.frag")
private val shader = App.loadShaderFromFile("assets/4096.vert", "assets/tiling.frag")
init {
@@ -100,15 +99,15 @@ internal object BlocksDrawer {
// create terrain texture from pixmaps
weatherTerrains = arrayOf(
TextureRegionPack(Texture(AppLoader.tileMaker.atlasSpring), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(AppLoader.tileMaker.atlas), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(AppLoader.tileMaker.atlasAutumn), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(AppLoader.tileMaker.atlasWinter), TILE_SIZE, TILE_SIZE)
TextureRegionPack(Texture(App.tileMaker.atlasSpring), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlas), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlasAutumn), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlasWinter), TILE_SIZE, TILE_SIZE)
)
//tilesWire = TextureRegionPack(ModMgr.getGdxFile("basegame", "wires/wire.tga"), TILE_SIZE, TILE_SIZE)
tilesFluid = TextureRegionPack(Texture(AppLoader.tileMaker.atlasFluid), TILE_SIZE, TILE_SIZE)
tilesGlow = TextureRegionPack(Texture(AppLoader.tileMaker.atlasGlow), TILE_SIZE, TILE_SIZE)
tilesFluid = TextureRegionPack(Texture(App.tileMaker.atlasFluid), TILE_SIZE, TILE_SIZE)
tilesGlow = TextureRegionPack(Texture(App.tileMaker.atlasGlow), TILE_SIZE, TILE_SIZE)
printdbg(this, "Making terrain and wall item textures...")
@@ -118,8 +117,8 @@ internal object BlocksDrawer {
// test print
//PixmapIO2.writeTGA(Gdx.files.absolute("${AppLoader.defaultDir}/terrainitem.tga"), itemTerrainPixmap, false)
tileItemTerrain = TextureRegionPack(AppLoader.tileMaker.itemTerrainTexture, TILE_SIZE, TILE_SIZE)
tileItemWall = TextureRegionPack(AppLoader.tileMaker.itemWallTexture, TILE_SIZE, TILE_SIZE)
tileItemTerrain = TextureRegionPack(App.tileMaker.itemTerrainTexture, TILE_SIZE, TILE_SIZE)
tileItemWall = TextureRegionPack(App.tileMaker.itemWallTexture, TILE_SIZE, TILE_SIZE)
@@ -326,12 +325,12 @@ internal object BlocksDrawer {
0
}
val renderTag = AppLoader.tileMaker.getRenderTag(thisTile)
val renderTag = App.tileMaker.getRenderTag(thisTile)
val tileNumberBase =
if (mode == OCCLUSION)
OCCLUSION_TILE_NUM_BASE
else if (mode == FLUID)
AppLoader.tileMaker.fluidToTileNumber(world.getFluid(x, y))
App.tileMaker.fluidToTileNumber(world.getFluid(x, y))
else
renderTag.tileNumber
val tileNumber = if (thisTile == Block.AIR) 0
@@ -349,8 +348,8 @@ internal object BlocksDrawer {
else -> throw IllegalArgumentException("Unknown mask type: ${renderTag.maskType}")
}
var thisTileX = tileNumber % AppLoader.tileMaker.TILES_IN_X
var thisTileY = tileNumber / AppLoader.tileMaker.TILES_IN_X
var thisTileX = tileNumber % App.tileMaker.TILES_IN_X
var thisTileY = tileNumber / App.tileMaker.TILES_IN_X
if (mode == FLUID && thisTileX == 22 && thisTileY == 3) {
//println("tileNumberBase = $tileNumberBase, tileNumber = $tileNumber, fluid = ${world.getFluid(x, y)}")
@@ -433,7 +432,7 @@ internal object BlocksDrawer {
var ret = 0
for (i in nearbyTiles.indices) {
val fluid = world.getFluid(nearbyPos[i].x, nearbyPos[i].y)
if (BlockCodex[nearbyTiles[i]].isSolid || (fluid.isFluid() && 0 < AppLoader.tileMaker.fluidFillToTileLevel(fluid.amount))) {
if (BlockCodex[nearbyTiles[i]].isSolid || (fluid.isFluid() && 0 < App.tileMaker.fluidFillToTileLevel(fluid.amount))) {
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
}
}
@@ -573,7 +572,7 @@ internal object BlocksDrawer {
}
val vertexColour = when (mode) {
TERRAIN, /*WIRE,*/ FLUID, OCCLUSION -> Color.WHITE
WALL -> AppLoader.tileMaker.wallOverlayColour
WALL -> App.tileMaker.wallOverlayColour
else -> throw IllegalArgumentException()
}
@@ -606,8 +605,8 @@ internal object BlocksDrawer {
shader.bind()
shader.setUniformMatrix("u_projTrans", projectionMatrix)//camera.combined)
shader.setUniform2fv("tilesInAtlas", AppLoader.tileMaker.SHADER_SIZE_KEYS, 2, 2)
shader.setUniform2fv("atlasTexSize", AppLoader.tileMaker.SHADER_SIZE_KEYS, 0, 2)
shader.setUniform2fv("tilesInAtlas", App.tileMaker.SHADER_SIZE_KEYS, 2, 2)
shader.setUniform2fv("atlasTexSize", App.tileMaker.SHADER_SIZE_KEYS, 0, 2)
shader.setUniformf("colourFilter", vertexColour)
shader.setUniformf("screenDimension", Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
shader.setUniformi("tilesAtlas", 0)
@@ -638,8 +637,8 @@ internal object BlocksDrawer {
var tilesInVertical = -1; private set
fun resize(screenW: Int, screenH: Int) {
tilesInHorizontal = (AppLoader.screenSize.screenWf / TILE_SIZE).ceilInt() + 1
tilesInVertical = (AppLoader.screenSize.screenHf / TILE_SIZE).ceilInt() + 1
tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilInt() + 1
tilesInVertical = (App.scr.hf / TILE_SIZE).ceilInt() + 1
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilInt() + 1
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilInt() + 1
@@ -665,9 +664,9 @@ internal object BlocksDrawer {
tilesQuad.setVertices(floatArrayOf( // WARNING! not ususal quads; TexCoords of Y is flipped
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 0f,
AppLoader.screenSize.screenWf, 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
0f, AppLoader.screenSize.screenHf, 0f, 1f, 1f, 1f, 1f, 0f, 1f
App.scr.wf, 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
App.scr.wf, App.scr.hf, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
0f, App.scr.hf, 0f, 1f, 1f, 1f, 1f, 0f, 1f
))
tilesQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
}
@@ -725,7 +724,7 @@ internal object BlocksDrawer {
tilesQuad.dispose()
shader.dispose()
AppLoader.tileMaker.dispose()
App.tileMaker.dispose()
}
fun getRenderStartX(): Int = WorldCamera.x / TILE_SIZE
@@ -734,10 +733,10 @@ internal object BlocksDrawer {
fun getRenderEndX(): Int = clampWTile(getRenderStartX() + (WorldCamera.width / TILE_SIZE) + 2)
fun getRenderEndY(): Int = clampHTile(getRenderStartY() + (WorldCamera.height / TILE_SIZE) + 2)
fun isConnectSelf(b: ItemID): Boolean = AppLoader.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_SELF
fun isConnectMutual(b: ItemID): Boolean = AppLoader.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_MUTUAL
fun isWallSticker(b: ItemID): Boolean = AppLoader.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER
fun isPlatform(b: ItemID): Boolean = AppLoader.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER_CONNECT_SELF
fun isConnectSelf(b: ItemID): Boolean = App.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_SELF
fun isConnectMutual(b: ItemID): Boolean = App.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_MUTUAL
fun isWallSticker(b: ItemID): Boolean = App.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER
fun isPlatform(b: ItemID): Boolean = App.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER_CONNECT_SELF
//fun isBlendMul(b: Int): Boolean = TILES_BLEND_MUL.contains(b)
fun tileInCamera(x: Int, y: Int) =

View File

@@ -8,11 +8,8 @@ import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.BlockProp
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.gameworld.GameWorld
@@ -31,7 +28,7 @@ import kotlin.math.roundToInt
class CreateTileAtlas {
// min size 1024 = tile_size 16 * atlasCursor 64
val MAX_TEX_SIZE = AppLoader.getConfigInt("atlastexsize").coerceIn(1024, AppLoader.glInfo.GL_MAX_TEXTURE_SIZE)
val MAX_TEX_SIZE = App.getConfigInt("atlastexsize").coerceIn(1024, App.glInfo.GL_MAX_TEXTURE_SIZE)
val TILES_IN_X = MAX_TEX_SIZE / TILE_SIZE
val SHADER_SIZE_KEYS = floatArrayOf(MAX_TEX_SIZE.toFloat(), MAX_TEX_SIZE.toFloat(), TILES_IN_X.toFloat(), TILES_IN_X.toFloat())

View File

@@ -45,7 +45,7 @@ object FeaturesDrawer {
* usually targeted for the environmental temperature (desert/winterland), hence the name.
*/
fun drawEnvOverlay(batch: SpriteBatch) {
val onscreen_tiles_max = FastMath.ceil(AppLoader.screenSize.screenH * AppLoader.screenSize.screenW / FastMath.sqr(TILE_SIZEF)) * 2
val onscreen_tiles_max = FastMath.ceil(App.scr.height * App.scr.width / FastMath.sqr(TILE_SIZEF)) * 2
val onscreen_tiles_cap = onscreen_tiles_max / 4f
val onscreen_cold_tiles = BlockStats.getCount(*TILES_COLD).toFloat()
val onscreen_warm_tiles = BlockStats.getCount(*TILES_WARM).toFloat()
@@ -59,8 +59,8 @@ object FeaturesDrawer {
batch.color = ColourTemp(colTemp)
batch.fillRect(0f, 0f,
AppLoader.screenSize.screenW * if (zoom < 1) 1f / zoom else zoom,
AppLoader.screenSize.screenH * if (zoom < 1) 1f / zoom else zoom
App.scr.width * if (zoom < 1) 1f / zoom else zoom,
App.scr.height * if (zoom < 1) 1f / zoom else zoom
)
blendNormal(batch)

View File

@@ -6,15 +6,13 @@ import com.badlogic.gdx.graphics.Texture
import net.torvald.gdx.graphics.Cvec
import net.torvald.gdx.graphics.UnsafeCvecArray
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.BlockProp
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.IngameRenderer
@@ -70,8 +68,8 @@ object LightmapRenderer {
const val overscan_opaque: Int = 10
const val LIGHTMAP_OVERRENDER = 8
private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenW).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenH).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
//private val noopMask = HashSet<Point2i>((LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT) * 2)
@@ -177,7 +175,7 @@ object LightmapRenderer {
//println("$for_x_start..$for_x_end, $for_x\t$for_y_start..$for_y_end, $for_y")
AppLoader.measureDebugTime("Renderer.Lanterns") {
App.measureDebugTime("Renderer.Lanterns") {
buildLanternmap(actorContainers)
} // usually takes 3000 ns
@@ -191,7 +189,7 @@ object LightmapRenderer {
}*/
// wipe out lightmap
AppLoader.measureDebugTime("Renderer.LightPrecalc") {
App.measureDebugTime("Renderer.LightPrecalc") {
// when disabled, light will "decay out" instead of "instantly out", which can have a cool effect
// but the performance boost is measly 0.1 ms on 6700K
@@ -305,7 +303,7 @@ object LightmapRenderer {
//
// multithreading - forget about it; overhead is way too big and for some reason i was not able to
// resolve the 'noisy shit' artefact
AppLoader.measureDebugTime("Renderer.LightRuns") {
App.measureDebugTime("Renderer.LightRuns") {
// To save you from pains:
// - Per-channel light updating is actually slower
@@ -589,7 +587,7 @@ object LightmapRenderer {
internal fun draw(): Texture {
// when shader is not used: 0.5 ms on 6700K
AppLoader.measureDebugTime("Renderer.LightToScreen") {
App.measureDebugTime("Renderer.LightToScreen") {
val this_x_start = for_draw_x_start
val this_y_start = for_draw_y_start
@@ -741,11 +739,11 @@ object LightmapRenderer {
// copied from BlocksDrawer, duh!
// FIXME 'lightBuffer' is not zoomable in this way
val tilesInHorizontal = (AppLoader.screenSize.screenWf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
val tilesInVertical = (AppLoader.screenSize.screenHf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
val tilesInHorizontal = (App.scr.wf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
val tilesInVertical = (App.scr.hf / TILE_SIZE).ceilInt() + 1 + LIGHTMAP_OVERRENDER * 2
LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenW).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenH).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.width).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(App.scr.height).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
if (_init) {
lightBuffer.dispose()

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.worlddrawer
import com.jme3.math.FastMath
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.App
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
@@ -64,8 +64,8 @@ object WorldCamera {
fun update(world: GameWorld, player: ActorWithBody?) {
if (player == null) return
width = AppLoader.screenSize.screenW//FastMath.ceil(AppLoader.terrarumAppConfig.screenW / zoom) // div, not mul
height = AppLoader.screenSize.screenH//FastMath.ceil(AppLoader.terrarumAppConfig.screenH / zoom)
width = App.scr.width//FastMath.ceil(AppLoader.terrarumAppConfig.screenW / zoom) // div, not mul
height = App.scr.height//FastMath.ceil(AppLoader.terrarumAppConfig.screenH / zoom)
zoom = Terrarum.ingame?.screenZoom ?: 1f
zoomSamplePoint = (1f - 1f / zoom) / 2f // will never quite exceed 0.5
@@ -94,8 +94,8 @@ object WorldCamera {
private fun Int.clampCameraY(world: GameWorld): Int {
return if (this < 0)
0
else if (this > world.height.times(TILE_SIZE) - AppLoader.screenSize.screenH)
world.height.times(TILE_SIZE) - AppLoader.screenSize.screenH
else if (this > world.height.times(TILE_SIZE) - App.scr.height)
world.height.times(TILE_SIZE) - App.scr.height
else
this
}