createtileatlas: fixing a mistake where non-47 blocks won't be rendered to atlas

This commit is contained in:
minjaesong
2019-03-03 21:53:56 +09:00
parent 01e5f75bf4
commit a05e2fc695
27 changed files with 107 additions and 92 deletions

View File

@@ -32,8 +32,8 @@ internal object BlocksDrawer {
var world: GameWorld = GameWorld.makeNullWorld()
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
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)

View File

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

View File

@@ -10,7 +10,6 @@ import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.toInt
import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE
import kotlin.math.roundToInt
/**
@@ -25,8 +24,12 @@ import kotlin.math.roundToInt
*/
object CreateTileAtlas {
const val TILES_IN_X = 256
const val MAX_TEX_SIZE = 4096
const val TILE_SIZE = 16
const val TILES_IN_X = MAX_TEX_SIZE / TILE_SIZE
private val TOTAL_TILES = TILES_IN_X * TILES_IN_X
lateinit var atlas: Pixmap
lateinit var atlasAutumn: Pixmap
lateinit var atlasWinter: Pixmap
@@ -246,11 +249,14 @@ object CreateTileAtlas {
}
private fun drawToAtlantes(pixmap: Pixmap, tilesCount: Int) {
if (atlasCursor >= TOTAL_TILES) {
throw Error("Too much tiles for $MAX_TEX_SIZE texture size: $atlasCursor")
}
val seasonal = pixmap.width == pixmap.height && pixmap.width == 14 * TILE_SIZE
val txOfPixmap = pixmap.width / TILE_SIZE
val tyOfPixmap = pixmap.height / TILE_SIZE
for (i in 0 until tilesCount) {
//printdbg(this, "Rendering to atlas, tile# $atlasCursor")
//printdbg(this, "Rendering to atlas, tile# $atlasCursor, tilesCount = $tilesCount, seasonal = $seasonal")
// different texture for different seasons (224x224)
if (seasonal) {
@@ -263,7 +269,7 @@ object CreateTileAtlas {
}
else {
val i = if (i < 41) i else i + 1 // to compensate the discontinuity between 40th and 41st tile
_drawToAtlantes(pixmap, atlasCursor, i % txOfPixmap, i / tyOfPixmap, 0)
_drawToAtlantes(pixmap, atlasCursor, i % txOfPixmap, i / txOfPixmap, 0)
atlasCursor += 1
}
}
@@ -285,6 +291,8 @@ object CreateTileAtlas {
val sourceX = srcTileX * TILE_SIZE
val sourceY = srcTileY * TILE_SIZE
//if (mode == 1) printdbg(this, "atlaspos: ($atlasX, $atlasY), srcpos: ($sourceX, $sourceY), srcpixmap = $pixmap")
when (mode) {
1 -> atlas.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
2 -> atlasAutumn.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockstats.BlockStats
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE
/**
* Created by minjaesong on 2015-12-31.
@@ -17,7 +18,7 @@ import net.torvald.terrarum.gameworld.GameWorld
object FeaturesDrawer {
lateinit var world: GameWorld
const val TILE_SIZE = 16
//const val TILE_SIZE = CreateTileAtlas.TILE_SIZE
private val ENV_COLTEMP_LOWEST = 5500
private val ENV_COLTEMP_HIGHEST = 7500

View File

@@ -40,9 +40,9 @@ object LightmapRendererOld {
// TODO resize(int, int) -aware
val LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.WIDTH)
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
.div(CreateTileAtlas.TILE_SIZE).ceil() + overscan_open * 2 + 3
val LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.HEIGHT)
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
.div(CreateTileAtlas.TILE_SIZE).ceil() + overscan_open * 2 + 3
/**
* Float value, 1.0 for 1023
@@ -53,8 +53,8 @@ object LightmapRendererOld {
private val AIR = Block.AIR
private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val DRAW_TILE_SIZE: Float = FeaturesDrawer.TILE_SIZE / IngameRenderer.lightmapDownsample
private const val TILE_SIZE = CreateTileAtlas.TILE_SIZE
private val DRAW_TILE_SIZE: Float = CreateTileAtlas.TILE_SIZE / IngameRenderer.lightmapDownsample
// color model related constants
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB

View File

@@ -33,7 +33,7 @@ import net.torvald.terrarum.realestate.LandUtil
* own ingame renderer
*/
object LightmapRenderer {
private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private const val TILE_SIZE = CreateTileAtlas.TILE_SIZE
private var world: GameWorld = GameWorld.makeNullWorld()
private lateinit var lightCalcShader: ShaderProgram
@@ -91,7 +91,7 @@ object LightmapRenderer {
private val AIR = Block.AIR
val DRAW_TILE_SIZE: Float = FeaturesDrawer.TILE_SIZE / IngameRenderer.lightmapDownsample
val DRAW_TILE_SIZE: Float = CreateTileAtlas.TILE_SIZE / IngameRenderer.lightmapDownsample
// color model related constants
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB

View File

@@ -11,7 +11,7 @@ import org.dyn4j.geometry.Vector2
* Created by minjaesong on 2016-12-30.
*/
object WorldCamera {
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val TILE_SIZE = CreateTileAtlas.TILE_SIZE
var x: Int = 0 // left position
private set