diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 259a430bc..604c26706 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -443,6 +443,7 @@ open class GameWorld { } infix fun Int.fmod(other: Int) = Math.floorMod(this, other) +infix fun Long.fmod(other: Long) = Math.floorMod(this, other) infix fun Float.fmod(other: Float) = if (this >= 0f) this % other else (this % other) + other inline class FluidType(val value: Int) { diff --git a/src/net/torvald/terrarum/modulebasegame/gameworld/WorldTime.kt b/src/net/torvald/terrarum/modulebasegame/gameworld/WorldTime.kt index 5a897b6a1..5466b647c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameworld/WorldTime.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameworld/WorldTime.kt @@ -1,5 +1,7 @@ package net.torvald.terrarum.modulebasegame.gameworld +import net.torvald.terrarum.gameworld.fmod + typealias time_t = Long @@ -96,11 +98,11 @@ class WorldTime(initTime: Long = 0L) { // these functions won't need inlining for performance val yearlyDays: Int // 0 - 119 - get() = (TIME_T.toPositiveInt().div(DAY_LENGTH) % YEAR_DAYS) + get() = (TIME_T.div(DAY_LENGTH) fmod YEAR_DAYS.toLong()).toInt() val days: Int // 1 - 30 fixed - get() = (yearlyDays % 30) + 1 + get() = (yearlyDays % MONTH_LENGTH) + 1 val months: Int // 1 - 4 - get() = (yearlyDays / 30) + 1 + get() = (yearlyDays / MONTH_LENGTH) + 1 val years: Int get() = TIME_T.div(YEAR_DAYS * DAY_LENGTH).abs().toInt() + EPOCH_YEAR diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt index 5fe3b85c0..ea94bd15c 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt @@ -360,15 +360,21 @@ internal object BlocksDrawer { return TILES_BLEND_MUL.add(blockID) } + private var drawTIME_T = 0L + private val SECONDS_IN_MONTH = WorldTime.MONTH_LENGTH * WorldTime.DAY_LENGTH.toLong() /////////////////////////////////////////// // NO draw lightmap using colour filter, actors must also be hidden behind the darkness /////////////////////////////////////////// internal fun renderData() { + try { - tilesTerrain = weatherTerrains[(world as GameWorldExtension).time.months - 1] - tilesTerrainBlend = weatherTerrains[(world as GameWorldExtension).time.months fmod 4] + drawTIME_T = (world as GameWorldExtension).time.TIME_T - (WorldTime.DAY_LENGTH * 15) // offset by -15 days + val seasonalMonth = (drawTIME_T.div(WorldTime.DAY_LENGTH) fmod WorldTime.YEAR_DAYS.toLong()).toInt() / WorldTime.MONTH_LENGTH + 1 + + tilesTerrain = weatherTerrains[seasonalMonth - 1] + tilesTerrainBlend = weatherTerrains[seasonalMonth fmod 4] } catch (e: ClassCastException) { } @@ -768,7 +774,7 @@ internal object BlocksDrawer { /*shader hard-code*/shader.setUniformi("atlasTexSize", tileAtlas.texture.width, tileAtlas.texture.height) //depends on the tile atlas // set the blend value as world's time progresses, in linear fashion shader.setUniformf("tilesBlend", if (world is GameWorldExtension && (mode == TERRAIN || mode == WALL)) - (world as GameWorldExtension).time.days.minus(1f) / WorldTime.MONTH_LENGTH + drawTIME_T.fmod(SECONDS_IN_MONTH) / SECONDS_IN_MONTH.toFloat() else 0f )