six ecological seasons for terrain tiles

This commit is contained in:
minjaesong
2023-09-07 13:19:32 +09:00
parent b0e4bd31eb
commit 37492dc8a0
7 changed files with 82 additions and 61 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -14,7 +14,7 @@ data class WeatherSchedule(val weather: BaseModularWeather = WeatherMixer.DEFAUL
class Weatherbox { class Weatherbox {
companion object { companion object {
private val WIND_DIR_TIME_UNIT = 3600f * 6 // every 6hr private val WIND_DIR_TIME_UNIT = 3600f * 15 // every 15hr
private val WIND_SPEED_TIME_UNIT = 360f * 5 // every 0.5hr private val WIND_SPEED_TIME_UNIT = 360f * 5 // every 0.5hr
private val HALF_PIF = 1.5707964f private val HALF_PIF = 1.5707964f

View File

@@ -45,7 +45,8 @@ internal object BlocksDrawer {
/** Index zero: spring */ /** Index zero: spring */
val weatherTerrains: Array<TextureRegionPack> val weatherTerrains: Array<TextureRegionPack>
lateinit var tilesTerrain: TextureRegionPack; private set lateinit var tilesTerrain: TextureRegionPack; private set
lateinit var tilesTerrainBlend: TextureRegionPack; private set lateinit var tilesTerrainNext: TextureRegionPack; private set
private var tilesTerrainBlendDegree = 0f
//val tilesWire: TextureRegionPack //val tilesWire: TextureRegionPack
val tileItemTerrain: TextureRegionPack val tileItemTerrain: TextureRegionPack
val tileItemTerrainGlow: TextureRegionPack val tileItemTerrainGlow: TextureRegionPack
@@ -103,10 +104,12 @@ internal object BlocksDrawer {
// create terrain texture from pixmaps // create terrain texture from pixmaps
weatherTerrains = arrayOf( weatherTerrains = arrayOf(
TextureRegionPack(Texture(App.tileMaker.atlasSpring), TILE_SIZE, TILE_SIZE), TextureRegionPack(Texture(App.tileMaker.atlas), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlas), TILE_SIZE, TILE_SIZE), TextureRegionPack(Texture(App.tileMaker.atlasVernal), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlasAutumn), TILE_SIZE, TILE_SIZE), TextureRegionPack(Texture(App.tileMaker.atlasAestival), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlasWinter), TILE_SIZE, TILE_SIZE) TextureRegionPack(Texture(App.tileMaker.atlasSerotinal), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlasAutumnal), TILE_SIZE, TILE_SIZE),
TextureRegionPack(Texture(App.tileMaker.atlasHibernal), TILE_SIZE, TILE_SIZE),
) )
//tilesWire = TextureRegionPack(ModMgr.getGdxFile("basegame", "wires/wire.tga"), TILE_SIZE, TILE_SIZE) //tilesWire = TextureRegionPack(ModMgr.getGdxFile("basegame", "wires/wire.tga"), TILE_SIZE, TILE_SIZE)
@@ -193,11 +196,12 @@ internal object BlocksDrawer {
internal fun renderData() { internal fun renderData() {
try { try {
drawTIME_T = world.worldTime.TIME_T - (WorldTime.DAY_LENGTH * 15) // offset by -15 days drawTIME_T = world.worldTime.TIME_T - (WorldTime.DAY_LENGTH * 10) // offset by -10 days
val seasonalMonth = (drawTIME_T.div(WorldTime.DAY_LENGTH) fmod WorldTime.YEAR_DAYS.toLong()).toInt() / WorldTime.MONTH_LENGTH + 1 val seasonalMonth = (drawTIME_T fmod (WorldTime.DAY_LENGTH * WorldTime.YEAR_DAYS).toLong()).toFloat() / (WorldTime.DAY_LENGTH * WorldTime.YEAR_DAYS / weatherTerrains.size)
tilesTerrain = weatherTerrains[seasonalMonth - 1] tilesTerrain = weatherTerrains[seasonalMonth.floorToInt()]
tilesTerrainBlend = weatherTerrains[seasonalMonth fmod 4] tilesTerrainNext = weatherTerrains[(seasonalMonth + 1).floorToInt() fmod weatherTerrains.size]
tilesTerrainBlendDegree = seasonalMonth % 1f
} }
catch (e: ClassCastException) { } catch (e: ClassCastException) { }
@@ -616,7 +620,7 @@ internal object BlocksDrawer {
tilesGlow.texture.bind(0) // for some fuck reason, it must be bound as last tilesGlow.texture.bind(0) // for some fuck reason, it must be bound as last
} }
else { else {
tilesTerrainBlend.texture.bind(2) tilesTerrainNext.texture.bind(2)
_tilesBufferAsTex.bind(1) // trying 1 and 0... _tilesBufferAsTex.bind(1) // trying 1 and 0...
tileAtlas.texture.bind(0) // for some fuck reason, it must be bound as last tileAtlas.texture.bind(0) // for some fuck reason, it must be bound as last
} }
@@ -639,7 +643,7 @@ internal object BlocksDrawer {
shader.setUniformf("atlasTexSize", tileAtlas.texture.width.toFloat(), tileAtlas.texture.height.toFloat()) //depends on the tile atlas shader.setUniformf("atlasTexSize", tileAtlas.texture.width.toFloat(), tileAtlas.texture.height.toFloat()) //depends on the tile atlas
// set the blend value as world's time progresses, in linear fashion // set the blend value as world's time progresses, in linear fashion
shader.setUniformf("tilesBlend", if (mode == TERRAIN || mode == WALL) shader.setUniformf("tilesBlend", if (mode == TERRAIN || mode == WALL)
drawTIME_T.fmod(SECONDS_IN_MONTH) / SECONDS_IN_MONTH.toFloat() tilesTerrainBlendDegree
else else
0f 0f
) )

View File

@@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.utils.GdxRuntimeException import com.badlogic.gdx.utils.GdxRuntimeException
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec import net.torvald.gdx.graphics.Cvec
import net.torvald.gdx.graphics.PixmapIO2
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
@@ -40,10 +39,12 @@ class CreateTileAtlas {
val wallOverlayColour = Color(.65f, .65f, .65f, 1f) val wallOverlayColour = Color(.65f, .65f, .65f, 1f)
lateinit var atlas: Pixmap lateinit var atlas: Pixmap // prevernal
lateinit var atlasAutumn: Pixmap lateinit var atlasVernal: Pixmap
lateinit var atlasWinter: Pixmap lateinit var atlasAestival: Pixmap
lateinit var atlasSpring: Pixmap lateinit var atlasSerotinal: Pixmap
lateinit var atlasAutumnal: Pixmap
lateinit var atlasHibernal: Pixmap
lateinit var atlasFluid: Pixmap lateinit var atlasFluid: Pixmap
lateinit var atlasGlow: Pixmap // glowing won't be affected by the season... for now lateinit var atlasGlow: Pixmap // glowing won't be affected by the season... for now
lateinit var itemTerrainTexture: Texture lateinit var itemTerrainTexture: Texture
@@ -84,9 +85,11 @@ class CreateTileAtlas {
if (MAX_TEX_SIZE >= initPixmap.width) { if (MAX_TEX_SIZE >= initPixmap.width) {
atlas.drawPixmap(initPixmap, 0, 0) atlas.drawPixmap(initPixmap, 0, 0)
atlasAutumn.drawPixmap(initPixmap, 0, 0) atlasVernal.drawPixmap(initPixmap, 0, 0)
atlasWinter.drawPixmap(initPixmap, 0, 0) atlasAestival.drawPixmap(initPixmap, 0, 0)
atlasSpring.drawPixmap(initPixmap, 0, 0) atlasSerotinal.drawPixmap(initPixmap, 0, 0)
atlasAutumnal.drawPixmap(initPixmap, 0, 0)
atlasHibernal.drawPixmap(initPixmap, 0, 0)
} }
else { else {
/* /*
@@ -107,9 +110,11 @@ class CreateTileAtlas {
val destY = scantile * TILE_SIZE val destY = scantile * TILE_SIZE
atlas.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH) atlas.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH)
atlasAutumn.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH) atlasVernal.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH)
atlasWinter.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH) atlasAestival.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH)
atlasSpring.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH) atlasSerotinal.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH)
atlasAutumnal.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH)
atlasHibernal.drawPixmap(initPixmap, srcX, srcY, scanW, scanH, destX, destY, scanW, scanH)
} }
} }
@@ -125,9 +130,11 @@ class CreateTileAtlas {
itemSheetNumbers = HashMap<ItemID, Int>() itemSheetNumbers = HashMap<ItemID, Int>()
atlas = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None } atlas = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
atlasAutumn = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None } atlasVernal = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
atlasWinter = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None } atlasAestival = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
atlasSpring = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None } atlasSerotinal = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
atlasAutumnal = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
atlasHibernal = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
atlasFluid = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None } atlasFluid = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
atlasGlow = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None } atlasGlow = Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.None }
@@ -352,25 +359,29 @@ class CreateTileAtlas {
expandAtlantes() expandAtlantes()
} }
val seasonal = matte.width == matte.height && matte.width == 14 * TILE_SIZE val sixSeasonal = matte.width == 21 * TILE_SIZE && matte.height == 14 * TILE_SIZE
val txOfPixmap = matte.width / TILE_SIZE val txOfPixmap = matte.width / TILE_SIZE
val txOfPixmapGlow = glow.width / TILE_SIZE val txOfPixmapGlow = glow.width / TILE_SIZE
for (i in 0 until tilesCount) { for (i in 0 until tilesCount) {
//printdbg(this, "Rendering to atlas, tile# $atlasCursor, tilesCount = $tilesCount, seasonal = $seasonal") //printdbg(this, "Rendering to atlas, tile# $atlasCursor, tilesCount = $tilesCount, seasonal = $seasonal")
// different texture for different seasons (224x224) // different texture for different seasons (224x224)
if (seasonal) { if (sixSeasonal) {
val i = if (i < 41) i else i + 1 // to compensate the discontinuity between 40th and 41st tile val i = if (i < 41) i else i + 1 // to compensate the discontinuity between 40th and 41st tile
_drawToAtlantes(matte, atlasCursor, i % 7, i / 7, SUMMER) _drawToAtlantes(matte, atlasCursor, i % 7 , i / 7, PREVERNAL)
_drawToAtlantes(matte, atlasCursor, i % 7 + 7, i / 7, AUTUMN) _drawToAtlantes(matte, atlasCursor, i % 7 + 7 , i / 7, VERNAL)
_drawToAtlantes(matte, atlasCursor, i % 7 + 7, i / 7 + 7, WINTER) _drawToAtlantes(matte, atlasCursor, i % 7 + 14, i / 7, AESTIVAL)
_drawToAtlantes(matte, atlasCursor, i % 7, i / 7 + 7, SPRING)
_drawToAtlantes(matte, atlasCursor, i % 7 + 14, i / 7 + 7, SEROTINAL)
_drawToAtlantes(matte, atlasCursor, i % 7 + 7 , i / 7 + 7, AUTUMNAL)
_drawToAtlantes(matte, atlasCursor, i % 7 , i / 7 + 7, HIBERNAL)
_drawToAtlantes(glow, atlasCursor, i % 7, i / 7, GLOW) _drawToAtlantes(glow, atlasCursor, i % 7, i / 7, GLOW)
atlasCursor += 1 atlasCursor += 1
} }
else { else {
val i = if (i < 41) i else i + 1 // to compensate the discontinuity between 40th and 41st tile val i = if (i < 41) i else i + 1 // to compensate the discontinuity between 40th and 41st tile
_drawToAtlantes(matte, atlasCursor, i % txOfPixmap, i / txOfPixmap, FOUR_SEASONS) _drawToAtlantes(matte, atlasCursor, i % txOfPixmap, i / txOfPixmap, SIX_SEASONS)
_drawToAtlantes(glow, atlasCursor, i % txOfPixmapGlow, i / txOfPixmapGlow, GLOW) _drawToAtlantes(glow, atlasCursor, i % txOfPixmapGlow, i / txOfPixmapGlow, GLOW)
atlasCursor += 1 atlasCursor += 1
} }
@@ -381,11 +392,13 @@ class CreateTileAtlas {
* mode: 0 for all the atlantes, 1-4 for summer/autumn/winter/spring atlas * mode: 0 for all the atlantes, 1-4 for summer/autumn/winter/spring atlas
*/ */
private fun _drawToAtlantes(pixmap: Pixmap, destTileNum: Int, srcTileX: Int, srcTileY: Int, source: AtlasSource) { private fun _drawToAtlantes(pixmap: Pixmap, destTileNum: Int, srcTileX: Int, srcTileY: Int, source: AtlasSource) {
if (source == FOUR_SEASONS) { if (source == SIX_SEASONS) {
_drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, SUMMER) _drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, PREVERNAL)
_drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, AUTUMN) _drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, VERNAL)
_drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, WINTER) _drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, AESTIVAL)
_drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, SPRING) _drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, SEROTINAL)
_drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, AUTUMNAL)
_drawToAtlantes(pixmap, destTileNum, srcTileX, srcTileY, HIBERNAL)
} }
else { else {
val atlasX = (destTileNum % TILES_IN_X) * TILE_SIZE val atlasX = (destTileNum % TILES_IN_X) * TILE_SIZE
@@ -396,10 +409,12 @@ class CreateTileAtlas {
//if (mode == 1) printdbg(this, "atlaspos: ($atlasX, $atlasY), srcpos: ($sourceX, $sourceY), srcpixmap = $pixmap") //if (mode == 1) printdbg(this, "atlaspos: ($atlasX, $atlasY), srcpos: ($sourceX, $sourceY), srcpixmap = $pixmap")
when (source) { when (source) {
SUMMER -> atlas.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE) PREVERNAL -> atlas.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
AUTUMN -> atlasAutumn.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE) VERNAL -> atlasVernal.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
WINTER -> atlasWinter.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE) AESTIVAL -> atlasAestival.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
SPRING -> atlasSpring.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE) SEROTINAL -> atlasSerotinal.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
AUTUMNAL -> atlasAutumnal.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
HIBERNAL -> atlasHibernal.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
FLUID -> atlasFluid.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE) FLUID -> atlasFluid.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
GLOW -> atlasGlow.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE) GLOW -> atlasGlow.drawPixmap(pixmap, sourceX, sourceY, TILE_SIZE, TILE_SIZE, atlasX, atlasY, TILE_SIZE, TILE_SIZE)
else -> throw IllegalArgumentException("Unknown draw source $source") else -> throw IllegalArgumentException("Unknown draw source $source")
@@ -436,9 +451,11 @@ class CreateTileAtlas {
fun dispose() { fun dispose() {
atlas.dispose() atlas.dispose()
atlasAutumn.dispose() atlasVernal.dispose()
atlasWinter.dispose() atlasAestival.dispose()
atlasSpring.dispose() atlasSerotinal.dispose()
atlasAutumnal.dispose()
atlasHibernal.dispose()
atlasFluid.dispose() atlasFluid.dispose()
atlasGlow.dispose() atlasGlow.dispose()
//itemTerrainTexture.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemTerrain (TextureRegionPack)' //itemTerrainTexture.dispose() //BlocksDrawer will dispose of it as it disposes of 'tileItemTerrain (TextureRegionPack)'
@@ -452,7 +469,8 @@ class CreateTileAtlas {
} }
private enum class AtlasSource { private enum class AtlasSource {
FOUR_SEASONS, SUMMER, AUTUMN, WINTER, SPRING, FLUID, GLOW /*FOUR_SEASONS, SUMMER, AUTUMN, WINTER, SPRING,*/ FLUID, GLOW,
SIX_SEASONS, PREVERNAL, VERNAL, AESTIVAL, SEROTINAL, AUTUMNAL, HIBERNAL,
} }
private fun expandAtlantes() { private fun expandAtlantes() {
@@ -470,13 +488,13 @@ class CreateTileAtlas {
TOTAL_TILES = TILES_IN_X * TILES_IN_X TOTAL_TILES = TILES_IN_X * TILES_IN_X
val newAtlantes = Array<Pixmap>(5) { val newAtlantes = Array(7) {
Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also { Pixmap(TILES_IN_X * TILE_SIZE, TILES_IN_X * TILE_SIZE, Pixmap.Format.RGBA8888).also {
it.blending = Pixmap.Blending.None it.blending = Pixmap.Blending.None
it.filter = Pixmap.Filter.NearestNeighbour it.filter = Pixmap.Filter.NearestNeighbour
} }
} }
listOf(atlas, atlasAutumn, atlasWinter, atlasSpring, atlasGlow).forEachIndexed { index, pixmap -> listOf(atlas, atlasVernal, atlasAestival, atlasSerotinal, atlasAutumnal, atlasHibernal, atlasGlow).forEachIndexed { index, pixmap ->
/* /*
How it works: How it works:
@@ -502,10 +520,12 @@ class CreateTileAtlas {
} }
atlas = newAtlantes[0] atlas = newAtlantes[0]
atlasAutumn = newAtlantes[1] atlasVernal = newAtlantes[1]
atlasWinter = newAtlantes[2] atlasAestival = newAtlantes[2]
atlasSpring = newAtlantes[3] atlasSerotinal = newAtlantes[3]
atlasGlow = newAtlantes[4] atlasAutumnal = newAtlantes[4]
atlasHibernal = newAtlantes[5]
atlasGlow = newAtlantes[6]
App.setConfig("atlastexsize", newTexSize) App.setConfig("atlastexsize", newTexSize)