tilesize declaration refactoring

This commit is contained in:
minjaesong
2021-07-27 16:17:54 +09:00
parent cb11267202
commit 67a5e2e1e6
38 changed files with 217 additions and 193 deletions

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.math.Matrix4
import com.jme3.math.FastMath
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.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
@@ -14,7 +15,6 @@ import net.torvald.terrarum.gameworld.fmod
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.worlddrawer.CreateTileAtlas.TILES_IN_X
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.roundToInt
@@ -35,8 +35,6 @@ internal object BlocksDrawer {
/** World change is managed by IngameRenderer.setWorld() */
internal var world: GameWorld = GameWorld.makeNullWorld()
private val TILE_SIZE = CreateTileAtlas.TILE_SIZE
private val TILE_SIZEF = CreateTileAtlas.TILE_SIZE.toFloat()
/**
* Widths of the tile atlases must have exactly the same width (height doesn't matter)
@@ -98,16 +96,16 @@ internal object BlocksDrawer {
// create terrain texture from pixmaps
weatherTerrains = arrayOf(
TextureRegionPack(Texture(CreateTileAtlas.atlasSpring), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(CreateTileAtlas.atlas), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(CreateTileAtlas.atlasAutumn), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(CreateTileAtlas.atlasWinter), TILE_SIZE, TILE_SIZE)
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)
)
//TODO make wire work with the TileAtlas system
tilesWire = TextureRegionPack(ModMgr.getGdxFile("basegame", "blocks/wire.tga"), TILE_SIZE, TILE_SIZE)
tilesFluid = TextureRegionPack(Texture(CreateTileAtlas.atlasFluid), TILE_SIZE, TILE_SIZE)
tilesGlow = TextureRegionPack(Texture(CreateTileAtlas.atlasGlow), TILE_SIZE, TILE_SIZE)
tilesFluid = TextureRegionPack(Texture(AppLoader.tileMaker.atlasFluid), TILE_SIZE, TILE_SIZE)
tilesGlow = TextureRegionPack(Texture(AppLoader.tileMaker.atlasGlow), TILE_SIZE, TILE_SIZE)
printdbg(this, "Making terrain and wall item textures...")
@@ -117,8 +115,8 @@ internal object BlocksDrawer {
// test print
//PixmapIO2.writeTGA(Gdx.files.absolute("${AppLoader.defaultDir}/terrainitem.tga"), itemTerrainPixmap, false)
tileItemTerrain = TextureRegionPack(CreateTileAtlas.itemTerrainTexture, TILE_SIZE, TILE_SIZE)
tileItemWall = TextureRegionPack(CreateTileAtlas.itemWallTexture, TILE_SIZE, TILE_SIZE)
tileItemTerrain = TextureRegionPack(AppLoader.tileMaker.itemTerrainTexture, TILE_SIZE, TILE_SIZE)
tileItemWall = TextureRegionPack(AppLoader.tileMaker.itemWallTexture, TILE_SIZE, TILE_SIZE)
@@ -321,10 +319,10 @@ internal object BlocksDrawer {
0
}
val renderTag = CreateTileAtlas.getRenderTag(thisTile)
val renderTag = AppLoader.tileMaker.getRenderTag(thisTile)
val tileNumberBase =
if (mode == FLUID)
CreateTileAtlas.fluidToTileNumber(world.getFluid(x, y))
AppLoader.tileMaker.fluidToTileNumber(world.getFluid(x, y))
else if (mode == WIRE)
0 // TODO need new wire storing format
else
@@ -343,8 +341,8 @@ internal object BlocksDrawer {
else -> throw IllegalArgumentException("Unknown mask type: ${renderTag.maskType}")
}
var thisTileX = tileNumber % TILES_IN_X
var thisTileY = tileNumber / TILES_IN_X
var thisTileX = tileNumber % AppLoader.tileMaker.TILES_IN_X
var thisTileY = tileNumber / AppLoader.tileMaker.TILES_IN_X
if (mode == FLUID && thisTileX == 22 && thisTileY == 3) {
//println("tileNumberBase = $tileNumberBase, tileNumber = $tileNumber, fluid = ${world.getFluid(x, y)}")
@@ -442,7 +440,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 < CreateTileAtlas.fluidFillToTileLevel(fluid.amount))) {
if (BlockCodex[nearbyTiles[i]].isSolid || (fluid.isFluid() && 0 < AppLoader.tileMaker.fluidFillToTileLevel(fluid.amount))) {
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
}
}
@@ -579,7 +577,7 @@ internal object BlocksDrawer {
}
val vertexColour = when (mode) {
TERRAIN, WIRE, FLUID -> Color.WHITE
WALL -> CreateTileAtlas.wallOverlayColour
WALL -> AppLoader.tileMaker.wallOverlayColour
else -> throw IllegalArgumentException()
}
@@ -729,7 +727,7 @@ internal object BlocksDrawer {
tilesQuad.dispose()
shader.dispose()
CreateTileAtlas.dispose()
AppLoader.tileMaker.dispose()
}
fun getRenderStartX(): Int = WorldCamera.x / TILE_SIZE
@@ -738,10 +736,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 = CreateTileAtlas.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_SELF
fun isConnectMutual(b: ItemID): Boolean = CreateTileAtlas.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_MUTUAL
fun isWallSticker(b: ItemID): Boolean = CreateTileAtlas.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER
fun isPlatform(b: ItemID): Boolean = CreateTileAtlas.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER_CONNECT_SELF
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 isBlendMul(b: Int): Boolean = TILES_BLEND_MUL.contains(b)
fun tileInCamera(x: Int, y: Int) =

View File

@@ -25,8 +25,8 @@ object BlocksDrawerOLD {
lateinit var world: GameWorld
private val TILE_SIZE = CreateTileAtlas.TILE_SIZE
private val TILE_SIZEF = CreateTileAtlas.TILE_SIZE.toFloat()
private val TILE_SIZE = TILE_SIZE
private val TILE_SIZEF = TILE_SIZEF
// TODO modular
//val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "blocks/terrain.tga.gz"), TILE_SIZE, TILE_SIZE) // 64 MB

View File

@@ -9,6 +9,7 @@ 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.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.Fluid
@@ -26,13 +27,12 @@ import kotlin.math.roundToInt
*
* Created by minjaesong on 2019-02-28.
*/
object CreateTileAtlas {
class CreateTileAtlas {
const val MAX_TEX_SIZE = TerrarumAppConfiguration.MAX_TEX_SIZE
const val TILE_SIZE = TerrarumAppConfiguration.TILE_SIZE
const val TILES_IN_X = MAX_TEX_SIZE / TILE_SIZE
val MAX_TEX_SIZE = AppLoader.getConfigInt("atlastexsize").coerceIn(1024, AppLoader.glInfo.GL_MAX_TEXTURE_SIZE)
val TILES_IN_X = MAX_TEX_SIZE / TILE_SIZE
const val ITEM_ATLAS_TILES_X = 16
val ITEM_ATLAS_TILES_X = 16
private val TOTAL_TILES = TILES_IN_X * TILES_IN_X
@@ -150,15 +150,15 @@ object CreateTileAtlas {
val itemTerrainPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
val itemWallPixmap = Pixmap(16 * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888)
CreateTileAtlas.tags.toMap().forEach { id, tag ->
tags.toMap().forEach { id, tag ->
val tilePosFromAtlas = tag.tileNumber + maskTypetoTileIDForItemImage(tag.maskType)
val srcX = (tilePosFromAtlas % TILES_IN_X) * TILE_SIZE
val srcY = (tilePosFromAtlas / TILES_IN_X) * TILE_SIZE
val t = tileIDtoItemSheetNumber(id)
val destX = (t % ITEM_ATLAS_TILES_X) * TILE_SIZE
val destY = (t / ITEM_ATLAS_TILES_X) * TILE_SIZE
itemTerrainPixmap.drawPixmap(CreateTileAtlas.atlas, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
itemWallPixmap.drawPixmap(CreateTileAtlas.atlas, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
itemTerrainPixmap.drawPixmap(atlas, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
itemWallPixmap.drawPixmap(atlas, srcX, srcY, TILE_SIZE, TILE_SIZE, destX, destY, TILE_SIZE, TILE_SIZE)
}
// darken things for the wall
for (y in 0 until itemWallPixmap.height) {

View File

@@ -4,10 +4,10 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
import net.torvald.colourutil.ColourTemp
import net.torvald.terrarum.*
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockstats.BlockStats
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE
/**
* Created by minjaesong on 2015-12-31.
@@ -17,7 +17,7 @@ object FeaturesDrawer {
/** World change is managed by IngameRenderer.setWorld() */
internal var world: GameWorld = GameWorld.makeNullWorld()
//const val TILE_SIZE = CreateTileAtlas.TILE_SIZE
//const val TILE_SIZE = TILE_SIZE
private val ENV_COLTEMP_LOWEST = 5500
private val ENV_COLTEMP_HIGHEST = 7500
@@ -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_SIZE.toFloat())) * 2
val onscreen_tiles_max = FastMath.ceil(AppLoader.screenSize.screenH * AppLoader.screenSize.screenW / 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()

View File

@@ -7,6 +7,7 @@ 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.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.Fluid
@@ -34,7 +35,6 @@ import kotlin.system.exitProcess
* own ingame renderer
*/
object LightmapRenderer {
private const val TILE_SIZE = CreateTileAtlas.TILE_SIZE
/** World change is managed by IngameRenderer.setWorld() */
private var world: GameWorld = GameWorld.makeNullWorld()
@@ -91,7 +91,7 @@ object LightmapRenderer {
private const val AIR = Block.AIR
const val DRAW_TILE_SIZE: Float = CreateTileAtlas.TILE_SIZE / IngameRenderer.lightmapDownsample
const val DRAW_TILE_SIZE: Float = TILE_SIZE / IngameRenderer.lightmapDownsample
internal var for_x_start = 0
internal var for_y_start = 0

View File

@@ -3,6 +3,8 @@ package net.torvald.terrarum.worlddrawer
import com.jme3.math.FastMath
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
import net.torvald.terrarum.ceilInt
import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.ActorWithBody
@@ -13,7 +15,6 @@ import org.dyn4j.geometry.Vector2
* Created by minjaesong on 2016-12-30.
*/
object WorldCamera {
private val TILE_SIZE = CreateTileAtlas.TILE_SIZE
//val zoom: Float
// get() = Terrarum.ingame?.screenZoom ?: 1f
@@ -82,8 +83,8 @@ object WorldCamera {
y = (FastMath.clamp(
(player.hitbox.centeredY - pVecSum.y).toFloat() - height / 2,
TILE_SIZE.toFloat(),
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
TILE_SIZEF,
world.height * TILE_SIZE - height - TILE_SIZEF
)).floorInt().clampCameraY(world)
xEnd = x + width