mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
blocksdrawer use offsetted time_t
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user