mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
weather in weathercodex
This commit is contained in:
@@ -12,6 +12,7 @@ import net.torvald.reflection.extortField
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.audio.*
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.PlaysMusic
|
||||
|
||||
26
assets/mods/basegame/weathers/WeatherClear.json
Normal file
26
assets/mods/basegame/weathers/WeatherClear.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"identifier": "clear01",
|
||||
"skyboxGradColourMap": "generic_skybox.tga",
|
||||
"daylightClut": "clut_daylight.tga",
|
||||
"tags": "generic,clear",
|
||||
"cloudChance": 12,
|
||||
"cloudGamma": [1.2, 2.4],
|
||||
"cloudGammaVariance": [0.111, 0.0],
|
||||
"windSpeed": 0.35,
|
||||
"windSpeedVariance": 0.4,
|
||||
"windSpeedDamping": 0.5,
|
||||
"clouds": {
|
||||
"cumulus": {
|
||||
"filename": "cloud_normal.png", "tw": 1024, "th": 512, "probability": 0.05,
|
||||
"baseScale": 2.0, "scaleVariance": 0.6,
|
||||
"altLow": 1080, "altHigh": 2400
|
||||
},
|
||||
"altocumulus": {
|
||||
"filename": "cloud_normal.png", "tw": 1024, "th": 512, "probability": 1.0,
|
||||
"baseScale": 1.0, "scaleVariance": 0.1,
|
||||
"altLow": 2600, "altHigh": 4800
|
||||
}
|
||||
},
|
||||
"atmoTurbidity": 3.2,
|
||||
"shaderVibrancy": [1.0, 1.0]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"identifier": "generic01",
|
||||
"skyboxGradColourMap": "generic_skybox.tga",
|
||||
"daylightClut": "clut_daylight.tga",
|
||||
"classification": "generic",
|
||||
"tags": "generic",
|
||||
"cloudChance": 60,
|
||||
"cloudGamma": [0.9, 2.4],
|
||||
"cloudGammaVariance": [0.111, 0.0],
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"identifier": "generic02",
|
||||
"skyboxGradColourMap": "generic_skybox.tga",
|
||||
"daylightClut": "clut_daylight.tga",
|
||||
"classification": "generic2",
|
||||
"tags": "generic2",
|
||||
"cloudChance": 150,
|
||||
"cloudGamma": [0.9, 2.4],
|
||||
"cloudGammaVariance": [0.111, 0.0],
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"identifier": "overcast01",
|
||||
"skyboxGradColourMap": "generic_skybox.tga",
|
||||
"daylightClut": "clut_daylight.tga",
|
||||
"classification": "overcast",
|
||||
"cloudChance": 300,
|
||||
"tags": "overcast",
|
||||
"cloudChance": 200,
|
||||
"cloudGamma": [1.45, 1.0],
|
||||
"cloudGammaVariance": [0.0, 0.0],
|
||||
"windSpeed": 10.45,
|
||||
|
||||
@@ -19,7 +19,7 @@ import kotlin.text.Charsets;
|
||||
import net.torvald.getcpuname.GetCpuName;
|
||||
import net.torvald.terrarum.audio.AudioBank;
|
||||
import net.torvald.terrarum.audio.AudioMixer;
|
||||
import net.torvald.terrarum.audio.MusicContainer;
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer;
|
||||
import net.torvald.terrarum.audio.dsp.BinoPan;
|
||||
import net.torvald.terrarum.controller.GdxControllerAdapter;
|
||||
import net.torvald.terrarum.controller.TerrarumController;
|
||||
@@ -239,7 +239,7 @@ public class App implements ApplicationListener {
|
||||
/**
|
||||
* For the events depends on rendering frame (e.g. flicker on post-hit invincibility)
|
||||
*/
|
||||
public static int GLOBAL_RENDER_TIMER = new Random().nextInt(1020) + 1;
|
||||
public static long GLOBAL_RENDER_TIMER = new Random().nextInt(1020) + 1L;
|
||||
|
||||
|
||||
public static DebugTimers debugTimers = new DebugTimers();
|
||||
@@ -745,7 +745,7 @@ public class App implements ApplicationListener {
|
||||
}
|
||||
|
||||
public static Texture getCurrentDitherTex() {
|
||||
int hash = 31 + GLOBAL_RENDER_TIMER + 0x165667B1 + GLOBAL_RENDER_TIMER * 0xC2B2AE3D;
|
||||
int hash = (int) (31 + GLOBAL_RENDER_TIMER + 0x165667B1 + GLOBAL_RENDER_TIMER * 0xC2B2AE3D);
|
||||
hash = Integer.rotateLeft(hash, 17) * 0x27D4EB2F;
|
||||
hash ^= hash >>> 15;
|
||||
hash *= 0x85EBCA77;
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.dsp.BinoPan
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.ActorID
|
||||
@@ -46,7 +46,7 @@ import kotlin.math.min
|
||||
*/
|
||||
open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boolean = false) : TerrarumGamescreen {
|
||||
|
||||
var WORLD_UPDATE_TIMER = Random().nextInt(1020) + 1; protected set
|
||||
var WORLD_UPDATE_TIMER = Random().nextInt(1020) + 1L; protected set
|
||||
|
||||
open protected val actorMBRConverter = object : MBRConverter<ActorWithBody> {
|
||||
override fun getDimensions(): Int = 2
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.weather.WeatherCodex
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import org.apache.commons.csv.CSVFormat
|
||||
@@ -794,6 +795,20 @@ object ModMgr {
|
||||
}
|
||||
}
|
||||
|
||||
object GameWeatherLoader {
|
||||
val weatherPath = "weathers/"
|
||||
|
||||
init {
|
||||
Terrarum.weatherCodex = WeatherCodex()
|
||||
}
|
||||
|
||||
@JvmStatic operator fun invoke(module: String) {
|
||||
getFiles(module, weatherPath).filter { it.isFile && it.name.lowercase().endsWith(".json") }.forEach {
|
||||
Terrarum.weatherCodex.readFromJson(module, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A sugar-library for easy texture pack creation
|
||||
*/
|
||||
|
||||
20
src/net/torvald/terrarum/TaggedProp.kt
Normal file
20
src/net/torvald/terrarum/TaggedProp.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-04-13.
|
||||
*/
|
||||
interface TaggedProp {
|
||||
|
||||
fun hasTag(s: String): Boolean
|
||||
fun hasAnyTagsOf(vararg s: String) = s.any { hasTag(it) }
|
||||
fun hasAnyTags(s: Collection<String>) = s.any { hasTag(it) }
|
||||
fun hasAnyTags(s: Array<String>) = s.any { hasTag(it) }
|
||||
fun hasAllTagsOf(vararg s: String) = s.all { hasTag(it) }
|
||||
fun hasAllTags(s: Collection<String>) = s.all { hasTag(it) }
|
||||
fun hasAllTags(s: Array<String>) = s.all { hasTag(it) }
|
||||
fun hasNoTagsOf(vararg s: String) = s.none { hasTag(it) }
|
||||
fun hasNoTags(s: Collection<String>) = s.none { hasTag(it) }
|
||||
fun hasNoTags(s: Array<String>) = s.none { hasTag(it) }
|
||||
|
||||
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import net.torvald.terrarum.savegame.DiskSkimmer
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
import net.torvald.terrarum.weather.WeatherCodex
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
|
||||
import net.torvald.unsafe.UnsafeHelper
|
||||
@@ -83,6 +84,7 @@ object Terrarum : Disposable {
|
||||
var fluidCodex = FluidCodex(); internal set
|
||||
var oreCodex = OreCodex(); internal set
|
||||
var audioCodex = AudioCodex(); internal set
|
||||
var weatherCodex = WeatherCodex(); internal set
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
@@ -829,6 +831,8 @@ val FluidCodex: FluidCodex
|
||||
get() = Terrarum.fluidCodex
|
||||
val OreCodex: OreCodex
|
||||
get() = Terrarum.oreCodex
|
||||
val WeatherCodex: WeatherCodex
|
||||
get() = Terrarum.weatherCodex
|
||||
|
||||
class Codex : KVHashMap() {
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ object TerrarumPostProcessor : Disposable {
|
||||
}
|
||||
|
||||
if (KeyToggler.isOn(Input.Keys.F2)) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 64 == 42) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 64 == 42L) {
|
||||
// we're going to assume the data are normally distributed
|
||||
deltatBenchStr = if (INGAME.deltaTeeBenchmarks.elemCount < INGAME.deltaTeeBenchmarks.size) {
|
||||
"ΔF: Gathering data (${INGAME.deltaTeeBenchmarks.elemCount}/${INGAME.deltaTeeBenchmarks.size})"
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
package net.torvald.terrarum.audio
|
||||
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-04-05.
|
||||
*/
|
||||
abstract class AudioBank : Disposable {
|
||||
|
||||
companion object {
|
||||
fun fromMusic(name: String, file: File, looping: Boolean = false, toRAM: Boolean = false, songFinishedHook: (AudioBank) -> Unit = {}): AudioBank {
|
||||
return MusicContainer(name, file, looping, toRAM, songFinishedHook)
|
||||
}
|
||||
}
|
||||
|
||||
protected val hash = System.nanoTime()
|
||||
|
||||
abstract fun makeCopy(): AudioBank
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.audio
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.tryDispose
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Disposable
|
||||
import com.badlogic.gdx.utils.Queue
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.dsp.NullFilter
|
||||
import net.torvald.terrarum.audio.dsp.TerrarumAudioFilter
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.torvald.terrarum.audio.audiobank
|
||||
|
||||
import com.badlogic.gdx.utils.Queue
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.audio.AudioBank
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-04-12.
|
||||
*/
|
||||
class AudioBankMusicBox(override var songFinishedHook: (AudioBank) -> Unit = {}) : AudioBank() {
|
||||
|
||||
override val name = "spieluhr"
|
||||
override val samplingRate = 48000
|
||||
override val channels = 1
|
||||
|
||||
override val totalSizeInSamples = Long.MAX_VALUE // TODO length of lowest-pitch note
|
||||
|
||||
private val messageQueue = Queue<Pair<Long, Long>>() // pair of: absolute tick count, notes (61 notes polyphony)
|
||||
|
||||
override fun currentPositionInSamples(): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun readSamples(bufferL: FloatArray, bufferR: FloatArray): Int {
|
||||
val tickCount = INGAME.WORLD_UPDATE_TIMER
|
||||
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun makeCopy(): AudioBank {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.torvald.terrarum.audio
|
||||
package net.torvald.terrarum.audio.audiobank
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.audio.Music
|
||||
@@ -12,6 +12,8 @@ import javazoom.jl.decoder.Bitstream
|
||||
import net.torvald.reflection.extortField
|
||||
import net.torvald.reflection.forceInvoke
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.audio.AudioBank
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack
|
||||
import net.torvald.terrarum.serialise.toUint
|
||||
import net.torvald.unsafe.UnsafeHelper
|
||||
import net.torvald.unsafe.UnsafePtr
|
||||
@@ -195,7 +197,6 @@ class MusicContainer(
|
||||
val bytesToRead = minOf(buffer.size.toLong(), 2 * channels * (totalSizeInSamples - samplesReadCount))
|
||||
|
||||
if (!looping && bytesToRead <= 0) return bytesToRead.toInt()
|
||||
// if (looping) printdbg(this, "toRAM music loop (bytes cursor: $samplesReadCount/$totalSizeInSamples, bytesToRead=$bytesToRead, buffer.size=${buffer.size})")
|
||||
|
||||
UnsafeHelper.memcpyRaw(
|
||||
null,
|
||||
@@ -9,7 +9,7 @@ import net.torvald.terrarum.gameworld.fmod
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-16.
|
||||
*/
|
||||
class BlockProp {
|
||||
class BlockProp : TaggedProp {
|
||||
|
||||
var id: ItemID = ""
|
||||
var numericID: Int = -1
|
||||
@@ -75,16 +75,7 @@ class BlockProp {
|
||||
BlockCodex[BlockCodex.tileToVirtual[id]!![offset]]._lumCol.lane(channel)
|
||||
}
|
||||
|
||||
fun hasTag(s: String) = tags.contains(s)
|
||||
fun hasAnyTagOf(vararg s: String) = s.any { hasTag(it) }
|
||||
fun hasAnyTag(s: Collection<String>) = s.any { hasTag(it) }
|
||||
fun hasAnyTag(s: Array<String>) = s.any { hasTag(it) }
|
||||
fun hasAllTagOf(vararg s: String) = s.all { hasTag(it) }
|
||||
fun hasAllTag(s: Collection<String>) = s.all { hasTag(it) }
|
||||
fun hasAllTag(s: Array<String>) = s.all { hasTag(it) }
|
||||
fun hasNoTagOf(vararg s: String) = s.none { hasTag(it) }
|
||||
fun hasNoTag(s: Collection<String>) = s.none { hasTag(it) }
|
||||
fun hasNoTag(s: Array<String>) = s.none { hasTag(it) }
|
||||
override fun hasTag(s: String) = tags.contains(s)
|
||||
|
||||
/**
|
||||
* @param luminosity
|
||||
|
||||
@@ -108,7 +108,7 @@ object BlockPropUtil {
|
||||
return when (prop.dynamicLuminosityFunction) {
|
||||
1 -> getTorchFlicker(prop)
|
||||
2 -> (INGAME.world).globalLight.cpy() // current global light
|
||||
3 -> WeatherMixer.getGlobalLightOfTimeOfNoon(WeatherMixer.weatherDict["generic01"]!!).cpy() // daylight at noon
|
||||
3 -> WeatherMixer.getGlobalLightOfTimeOfNoon(WeatherCodex.getById("generic01")!!).cpy() // daylight at noon
|
||||
4 -> getSlowBreath(prop)
|
||||
5 -> getPulsate(prop)
|
||||
else -> prop.baseLumCol
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.TaggedProp
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
@@ -78,11 +79,11 @@ class OreCodex {
|
||||
}
|
||||
|
||||
|
||||
class OreProp {
|
||||
class OreProp : TaggedProp {
|
||||
var id: String = ""
|
||||
var item: ItemID = ""
|
||||
var tags = HashSet<String>()
|
||||
|
||||
fun hasTag(s: String) = tags.contains(s)
|
||||
override fun hasTag(s: String) = tags.contains(s)
|
||||
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import net.torvald.terrarum.Codex
|
||||
import net.torvald.terrarum.TaggedProp
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-07-28.
|
||||
*/
|
||||
class WireProp {
|
||||
class WireProp : TaggedProp {
|
||||
|
||||
var id: ItemID = ""
|
||||
var numericID: Int = -1
|
||||
@@ -27,15 +28,5 @@ class WireProp {
|
||||
|
||||
@Transient var tags = HashSet<String>()
|
||||
|
||||
fun hasTag(s: String) = tags.contains(s)
|
||||
fun hasAnyTagOf(vararg s: String) = s.any { hasTag(it) }
|
||||
fun hasAnyTag(s: Collection<String>) = s.any { hasTag(it) }
|
||||
fun hasAnyTag(s: Array<String>) = s.any { hasTag(it) }
|
||||
fun hasAllTagOf(vararg s: String) = s.all { hasTag(it) }
|
||||
fun hasAllTag(s: Collection<String>) = s.all { hasTag(it) }
|
||||
fun hasAllTag(s: Array<String>) = s.all { hasTag(it) }
|
||||
fun hasNoTagOf(vararg s: String) = s.none { hasTag(it) }
|
||||
fun hasNoTag(s: Collection<String>) = s.none { hasTag(it) }
|
||||
fun hasNoTag(s: Array<String>) = s.none { hasTag(it) }
|
||||
|
||||
override fun hasTag(s: String) = tags.contains(s)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ object TileSurvey {
|
||||
|
||||
proposals.forEach { (_, proposal) ->
|
||||
|
||||
if (INGAME.WORLD_UPDATE_TIMER % proposal.temporalGranularity == 0) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % proposal.temporalGranularity == 0L) {
|
||||
val for_x_start = floor(player.intTilewiseHitbox.centeredX - proposal.width / 2.0).toInt()
|
||||
val for_y_start = floor(player.intTilewiseHitbox.centeredY - proposal.height / 2.0).toInt()
|
||||
val for_x_end = ceil(player.intTilewiseHitbox.centeredX + proposal.width / 2.0).toInt()
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.torvald.terrarum.App.printdbgerr
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.audio.AudioBank
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack
|
||||
import net.torvald.terrarum.audio.TrackVolume
|
||||
import net.torvald.terrarum.audio.dsp.NullFilter
|
||||
|
||||
@@ -25,7 +25,7 @@ typealias ItemID = String
|
||||
*
|
||||
* Created by minjaesong on 2016-01-16.
|
||||
*/
|
||||
abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneable {
|
||||
abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneable, TaggedProp {
|
||||
|
||||
constructor() : this("-uninitialised-")
|
||||
|
||||
@@ -392,10 +392,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
return this
|
||||
}
|
||||
|
||||
fun hasTag(s: String) = tags.contains(s)
|
||||
fun hasAllTags(s: List<String>) = tags.containsAll(s)
|
||||
fun hasAllTagOf(vararg s: String) = s.all { hasTag(it) }
|
||||
|
||||
override fun hasTag(s: String) = tags.contains(s)
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ open class GameWorld(
|
||||
var weatherbox = Weatherbox()
|
||||
|
||||
init {
|
||||
weatherbox.initWith(WeatherMixer.weatherDict["generic01"] ?: WeatherMixer.DEFAULT_WEATHER, 3600L)
|
||||
weatherbox.initWith(WeatherCodex.getById("generic01") ?: WeatherMixer.DEFAULT_WEATHER, 3600L)
|
||||
val currentWeather = weatherbox.currentWeather
|
||||
// TEST FILL WITH RANDOM VALUES
|
||||
(0..6).map { WeatherMixer.takeUniformRand(0f..1f) }.let {
|
||||
|
||||
@@ -391,7 +391,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
BlockPropUtil.dynamicLumFuncTickClock()
|
||||
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
|
||||
if (WORLD_UPDATE_TIMER % 2 == 1) {
|
||||
if (WORLD_UPDATE_TIMER % 2 == 1L) {
|
||||
fillUpWiresBuffer()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
|
||||
/**
|
||||
* The entry point for the module "Basegame"
|
||||
@@ -36,6 +37,11 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
ModMgr.GameLanguageLoader.invoke(moduleName)
|
||||
ModMgr.GameCraftingRecipeLoader.invoke(moduleName)
|
||||
ModMgr.GameAudioLoader.invoke(moduleName)
|
||||
ModMgr.GameWeatherLoader.invoke(moduleName)
|
||||
|
||||
WeatherCodex.weatherById["titlescreen"] =
|
||||
WeatherCodex.getById("generic01")?.copy(identifier = "titlescreen", windSpeed = 1f) ?: WeatherMixer.DEFAULT_WEATHER
|
||||
|
||||
|
||||
if (App.IS_DEVELOPMENT_BUILD) {
|
||||
println("[EntryPoint] Crafting Recipes: ")
|
||||
|
||||
@@ -261,7 +261,7 @@ object IngameRenderer : Disposable {
|
||||
if ((!gamePaused && !App.isScreenshotRequested()) || newWorldLoadedLatch) {
|
||||
measureDebugTime("Renderer.LightRun*") {
|
||||
// recalculate for even frames, or if the sign of the cam-x changed
|
||||
if (App.GLOBAL_RENDER_TIMER % 3 == 0 || Math.abs(WorldCamera.x - oldCamX) >= world.width * 0.85f * TILE_SIZEF || newWorldLoadedLatch) {
|
||||
if (App.GLOBAL_RENDER_TIMER % 3 == 0L || Math.abs(WorldCamera.x - oldCamX) >= world.width * 0.85f * TILE_SIZEF || newWorldLoadedLatch) {
|
||||
LightmapRenderer.recalculate(actorsRenderFarBehind + actorsRenderBehind + actorsRenderFront + actorsRenderMidTop + actorsRenderMiddle + actorsRenderOverlay)
|
||||
}
|
||||
oldCamX = WorldCamera.x
|
||||
|
||||
@@ -948,12 +948,12 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
// fill up visibleActorsRenderFront for wires but not on every update
|
||||
measureDebugTime("Ingame.FillUpWiresBuffer*") {
|
||||
if (WORLD_UPDATE_TIMER % 2 == 1) {
|
||||
if (WORLD_UPDATE_TIMER % 2 == 1L) {
|
||||
fillUpWiresBuffer()
|
||||
}
|
||||
}
|
||||
measureDebugTime("Ingame.FillUpWirePortsView*") {
|
||||
if (WORLD_UPDATE_TIMER % 2 == 0) {
|
||||
if (WORLD_UPDATE_TIMER % 2 == 0L) {
|
||||
val fixtures = INGAME.actorContainerActive.filterIsInstance<Electric>()
|
||||
fillUpWirePortsView(fixtures)
|
||||
}
|
||||
@@ -978,7 +978,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
|
||||
|
||||
actorNowPlaying?.let { if (WORLD_UPDATE_TIMER % 4 == 1) updateWorldGenerator(actorNowPlaying!!) }
|
||||
actorNowPlaying?.let { if (WORLD_UPDATE_TIMER % 4 == 1L) updateWorldGenerator(actorNowPlaying!!) }
|
||||
|
||||
|
||||
|
||||
@@ -1646,7 +1646,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
val punchSize = getPunchSize(actor)
|
||||
val punchBlockSize = punchSize.div(TILE_SIZED).floorToInt()
|
||||
|
||||
val mouseUnderPunchableTree = BlockCodex[world.getTileFromTerrain(mtx, mty)].hasAnyTagOf("LEAVES", "TREESMALL")
|
||||
val mouseUnderPunchableTree = BlockCodex[world.getTileFromTerrain(mtx, mty)].hasAnyTagsOf("LEAVES", "TREESMALL")
|
||||
|
||||
|
||||
// punch a small tree/shrub
|
||||
|
||||
@@ -6,7 +6,8 @@ import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.audio.AudioBank
|
||||
import net.torvald.terrarum.audio.AudioMixer
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
|
||||
import net.torvald.terrarum.gameworld.WorldTime.Companion.DAY_LENGTH
|
||||
import java.io.File
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame
|
||||
import com.badlogic.gdx.utils.Queue
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
@@ -16,7 +15,6 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame.Companion.inUpdateRang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.*
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.AxeCore
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import java.lang.Math.pow
|
||||
import kotlin.math.cosh
|
||||
import kotlin.math.min
|
||||
import kotlin.math.pow
|
||||
@@ -154,7 +152,7 @@ object WorldSimulator {
|
||||
val ry = rng.nextInt(updateYFrom, updateYTo + 1)
|
||||
val tile = world.getTileFromTerrain(rx, ry)
|
||||
// if the dirt tile has a grass and an air tile nearby, put grass to it
|
||||
if (BlockCodex[tile].hasAllTagOf("TREE", "LEAVES")) {
|
||||
if (BlockCodex[tile].hasAllTagsOf("TREE", "LEAVES")) {
|
||||
val nearby8 = getNearbyTiles8(rx, ry)
|
||||
val nearbyCount = nearby8.count { BlockCodex[it].hasTag("TREE") }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.badlogic.gdx.Gdx
|
||||
import net.torvald.spriteanimation.SingleImageSprite
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.decibelsToFullscale
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.PhysProperties
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.Treegen
|
||||
@@ -76,7 +72,7 @@ open class SaplingBase(val species: Int) : Cultivable(72000) {
|
||||
|
||||
// check for soil
|
||||
val groundTile = INGAME.world.getTileFromTerrain(intTilewiseHitbox.startX.toInt(), intTilewiseHitbox.endY.toInt() + 1)
|
||||
if (BlockCodex[groundTile].hasNoTagOf("CULTIVABLE")) {
|
||||
if (BlockCodex[groundTile].hasNoTagsOf("CULTIVABLE")) {
|
||||
despawnHook = {
|
||||
printdbg(this, "Sapling despawn!")
|
||||
PickaxeCore.dropItem("item@basegame:${160 + species}", intTilewiseHitbox.canonicalX.toInt(), intTilewiseHitbox.canonicalY.toInt())
|
||||
@@ -96,7 +92,7 @@ open class SaplingBase(val species: Int) : Cultivable(72000) {
|
||||
}
|
||||
private var treeHasBeenGrown = false
|
||||
override fun tryToSpawnMaturePlant() {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 3 == 2) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 3 == 2L) {
|
||||
val size = if (Math.random() < 0.1) 2 else 1
|
||||
val result = Treegen.plantTree(INGAME.world, intTilewiseHitbox.startX.toInt(), intTilewiseHitbox.endY.toInt() + 1, species, size)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.torvald.random.HQRNG
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.dsp.Gain
|
||||
import net.torvald.terrarum.audio.dsp.NullFilter
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.dsp.Gain
|
||||
import net.torvald.terrarum.audio.dsp.NullFilter
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.AudioMixer.Companion.DEFAULT_FADEOUT_LEN
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack
|
||||
import net.torvald.terrarum.audio.dsp.NullFilter
|
||||
import net.torvald.terrarum.audio.dsp.Phono
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.audio.AudioMixer
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
@@ -16,7 +15,6 @@ import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.MusicDiscHelper
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore
|
||||
import net.torvald.terrarum.ui.MouseLatch
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
@@ -75,7 +73,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
|
||||
INGAME.actorNowPlaying!!.inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)
|
||||
val itemProp = ItemCodex[itemOnGrip]
|
||||
|
||||
if (itemProp?.hasAllTagOf("MUSIC", "PHONO") == true) {
|
||||
if (itemProp?.hasAllTagsOf("MUSIC", "PHONO") == true) {
|
||||
disc = itemOnGrip
|
||||
INGAME.actorNowPlaying!!.removeItem(itemOnGrip!!)
|
||||
playDisc()
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.torvald.random.HQRNG
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.audio.dsp.Gain
|
||||
import net.torvald.terrarum.audio.dsp.NullFilter
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
|
||||
@@ -69,7 +69,7 @@ object AxeCore {
|
||||
val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actionInterval
|
||||
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toInt()) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) {
|
||||
PickaxeCore.makeNoiseTileTouching(actor, tile)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ object AxeCore {
|
||||
val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actionInterval
|
||||
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toInt()) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) {
|
||||
PickaxeCore.makeNoiseTileTouching(actor, tile)
|
||||
}
|
||||
|
||||
@@ -121,13 +121,13 @@ object AxeCore {
|
||||
usageStatus = usageStatus or true
|
||||
}
|
||||
// check if tile under mouse is a tree
|
||||
else if (tileprop.hasAllTag(listOf("TREE", "TREETRUNK") + additionalCheckTags)) {
|
||||
else if (tileprop.hasAllTags(listOf("TREE", "TREETRUNK") + additionalCheckTags)) {
|
||||
val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actionInterval
|
||||
val isLargeTree = tileprop.hasTag("TREELARGE")
|
||||
val axePowerMult = if (isLargeTree) 0.5f else 1f
|
||||
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toInt()) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) {
|
||||
PickaxeCore.makeNoiseTileTouching(actor, tile)
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ object AxeCore {
|
||||
val tileThereR = INGAME.world.getTileFromTerrain(x+1, y - upCtr)
|
||||
val propThereL = BlockCodex[tileThereL]
|
||||
val propThereR = BlockCodex[tileThereR]
|
||||
val treeTrunkXoff = if (propThereL.hasAllTagOf("TREELARGE", "TREETRUNK")) -1
|
||||
else if (propThereR.hasAllTagOf("TREELARGE", "TREETRUNK")) 1
|
||||
val treeTrunkXoff = if (propThereL.hasAllTagsOf("TREELARGE", "TREETRUNK")) -1
|
||||
else if (propThereR.hasAllTagsOf("TREELARGE", "TREETRUNK")) 1
|
||||
else 0
|
||||
|
||||
if (treeTrunkXoff != 0) {
|
||||
@@ -162,7 +162,7 @@ object AxeCore {
|
||||
val tileHere = INGAME.world.getTileFromTerrain(x, y - upCtr)
|
||||
val propHere = BlockCodex[tileHere]
|
||||
|
||||
if (propHere.hasAllTagOf("TREELARGE", "TREETRUNK")) {
|
||||
if (propHere.hasAllTagsOf("TREELARGE", "TREETRUNK")) {
|
||||
INGAME.world.setTileTerrain(x, y - upCtr, Block.AIR, false)
|
||||
PickaxeCore.dropItem(propHere.drop, x, y - upCtr)
|
||||
PickaxeCore.makeDust(tile, x, y - upCtr, 2 + Math.random().roundToInt())
|
||||
|
||||
@@ -68,7 +68,7 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
|
||||
|
||||
|
||||
// update the ghost sparingly
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 2 == 0) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 2 == 0L) {
|
||||
(INGAME as TerrarumIngame).blockMarkingActor.let {
|
||||
val item = ghostItem.get()
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.jme3.math.FastMath.pow
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.MixerTrackProcessor
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.audiobank.MusicContainer
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
@@ -84,7 +83,7 @@ object PickaxeCore {
|
||||
}
|
||||
// return false for punchable trees
|
||||
// non-punchable trees (= "log" tile placed by log item) must be mineable in order to make them useful as decor tiles
|
||||
if (BlockCodex[tile].hasAllTagOf("TREE", "TREETRUNK", "TREESMALL")) {
|
||||
if (BlockCodex[tile].hasAllTagsOf("TREE", "TREETRUNK", "TREESMALL")) {
|
||||
usageStatus = usageStatus or false
|
||||
continue
|
||||
}
|
||||
@@ -93,7 +92,7 @@ object PickaxeCore {
|
||||
val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actionInterval
|
||||
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toInt()) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) {
|
||||
makeNoiseTileTouching(actor, tile)
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ object SledgehammerCore {
|
||||
val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actionInterval
|
||||
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toInt()) {
|
||||
if (INGAME.WORLD_UPDATE_TIMER % 11 == (Math.random() * 3).toLong()) {
|
||||
PickaxeCore.makeNoiseTileTouching(actor, wall)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class Oregen(world: GameWorld, isFinal: Boolean, private val caveAttenuateBiasSc
|
||||
val blockTagNonGrata = ores.firstOrNull { it.tile == tileToPut }?.blockTagNonGrata ?: hashSetOf()
|
||||
val backingTileProp = BlockCodex[backingTile]
|
||||
|
||||
if (tileToPut != null && backingTileProp.hasAllTagOf("ROCK", "OREBEARING") && backingTileProp.hasNoTag(blockTagNonGrata)) {
|
||||
if (tileToPut != null && backingTileProp.hasAllTagsOf("ROCK", "OREBEARING") && backingTileProp.hasNoTags(blockTagNonGrata)) {
|
||||
// actually put the ore block
|
||||
world.setTileOre(x, y, tileToPut, 0) // autotiling will be handled by the other worldgen process
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ import io.airlift.compress.snappy.SnappyFramedOutputStream
|
||||
import io.airlift.compress.zstd.ZstdInputStream
|
||||
import io.airlift.compress.zstd.ZstdOutputStream
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.gameworld.BlockLayerI16
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
@@ -18,12 +17,9 @@ import net.torvald.terrarum.savegame.ByteArray64
|
||||
import net.torvald.terrarum.savegame.ByteArray64GrowableOutputStream
|
||||
import net.torvald.terrarum.savegame.ByteArray64InputStream
|
||||
import net.torvald.terrarum.savegame.ByteArray64Reader
|
||||
import net.torvald.terrarum.toHex
|
||||
import net.torvald.terrarum.utils.*
|
||||
import net.torvald.terrarum.weather.BaseModularWeather
|
||||
import net.torvald.terrarum.weather.WeatherDirBox
|
||||
import net.torvald.terrarum.weather.*
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import net.torvald.terrarum.weather.WeatherStateBox
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
@@ -269,7 +265,7 @@ object Common {
|
||||
}
|
||||
|
||||
override fun read(json: Json, jsonData: JsonValue, type: Class<*>?): BaseModularWeather {
|
||||
return WeatherMixer.weatherDict[jsonData.asString()]!!
|
||||
return WeatherCodex.getById(jsonData.asString())!!
|
||||
}
|
||||
})
|
||||
// Fill
|
||||
|
||||
@@ -2,10 +2,10 @@ package net.torvald.terrarum.weather
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.math.Vector3
|
||||
import com.badlogic.gdx.utils.JsonValue
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.GdxColorMap
|
||||
import net.torvald.terrarum.TaggedProp
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
@@ -21,7 +21,7 @@ data class BaseModularWeather(
|
||||
val json: JsonValue,
|
||||
var skyboxGradColourMap: GdxColorMap, // row 0: skybox grad top, row 1: skybox grad bottom, row 2: sunlight (RGBA)
|
||||
val daylightClut: GdxColorMap,
|
||||
val classification: String,
|
||||
val tags: List<String>,
|
||||
val cloudChance: Float,
|
||||
val windSpeed: Float,
|
||||
val windSpeedVariance: Float,
|
||||
@@ -33,7 +33,7 @@ data class BaseModularWeather(
|
||||
|
||||
val mixFrom: String? = null,
|
||||
val mixPercentage: Double? = null,
|
||||
) {
|
||||
) : TaggedProp {
|
||||
|
||||
|
||||
/**
|
||||
@@ -60,6 +60,10 @@ data class BaseModularWeather(
|
||||
|
||||
return Vector2(gx, gy)
|
||||
}
|
||||
|
||||
|
||||
override fun hasTag(s: String) = tags.contains(s)
|
||||
|
||||
}
|
||||
|
||||
data class CloudProps(
|
||||
|
||||
121
src/net/torvald/terrarum/weather/WeatherCodex.kt
Normal file
121
src/net/torvald/terrarum/weather/WeatherCodex.kt
Normal file
@@ -0,0 +1,121 @@
|
||||
package net.torvald.terrarum.weather
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.GdxColorMap
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.tryDispose
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.utils.forEachSiblings
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-04-13.
|
||||
*/
|
||||
class WeatherCodex : Disposable {
|
||||
|
||||
internal val weatherById = HashMap<String, BaseModularWeather>()
|
||||
internal val weatherByTags = HashMap<String, MutableSet<BaseModularWeather>>()
|
||||
|
||||
fun getById(id: String) = weatherById[id]
|
||||
|
||||
fun getByAllTags(tags: Array<String>) = weatherById.values.filter { it.hasAllTags(tags) }.ifEmpty { null }
|
||||
fun getByAllTags(tags: Collection<String>) = weatherById.values.filter { it.hasAllTags(tags) }.ifEmpty { null }
|
||||
fun getByAllTagsOf(tag: String, vararg tags: String) = weatherById.values.filter { it.hasAllTags(tags.toList() + tag) }.ifEmpty { null }
|
||||
|
||||
fun getByAnyTag(tags: Array<String>) = weatherById.values.filter { it.hasAnyTags(tags) }.ifEmpty { null }
|
||||
fun getByAnyTag(tags: Collection<String>) = weatherById.values.filter { it.hasAnyTags(tags) }.ifEmpty { null }
|
||||
fun getByAnyTag(tag: String, vararg tags: String) = weatherById.values.filter { it.hasAnyTags(tags.toList() + tag) }.ifEmpty { null }
|
||||
|
||||
fun getByTag(tag: String) = weatherByTags[tag]
|
||||
|
||||
|
||||
init {
|
||||
App.disposables.add(this)
|
||||
}
|
||||
|
||||
|
||||
fun readFromJson(modname: String, file: File) = readFromJson(modname, file.path)
|
||||
|
||||
fun readFromJson(modname: String, path: String) {
|
||||
/* JSON structure:
|
||||
{
|
||||
"skyboxGradColourMap": "colourmap/sky_colour.tga", // string (path to image) for dynamic. Image must be RGBA8888 or RGB888
|
||||
"extraImages": [
|
||||
// if any, it will be like:
|
||||
sun01.tga,
|
||||
clouds01.tga,
|
||||
clouds02.tga,
|
||||
auroraBlueViolet.tga
|
||||
]
|
||||
}
|
||||
*/
|
||||
val pathToImage = "weathers"
|
||||
|
||||
val JSON = JsonFetcher(path)
|
||||
|
||||
val skyboxInJson = JSON.getString("skyboxGradColourMap")
|
||||
val lightbox = JSON.getString("daylightClut")
|
||||
|
||||
val cloudsMap = ArrayList<CloudProps>()
|
||||
val clouds = JSON["clouds"]
|
||||
clouds.forEachSiblings { name, json ->
|
||||
cloudsMap.add(CloudProps(
|
||||
name,
|
||||
TextureRegionPack(ModMgr.getGdxFile(modname, "$pathToImage/${json.getString("filename")}"), json.getInt("tw"), json.getInt("th")),
|
||||
json.getFloat("probability"),
|
||||
json.getFloat("baseScale"),
|
||||
json.getFloat("scaleVariance"),
|
||||
json.getFloat("altLow"),
|
||||
json.getFloat("altHigh"),
|
||||
))
|
||||
}
|
||||
cloudsMap.sortBy { it.probability }
|
||||
|
||||
|
||||
val ident = JSON.getString("identifier")
|
||||
val tags = JSON.getString("tags").split(',')
|
||||
|
||||
val obj = BaseModularWeather(
|
||||
identifier = ident,
|
||||
json = JSON,
|
||||
skyboxGradColourMap = GdxColorMap(ModMgr.getGdxFile(modname, "$pathToImage/${skyboxInJson}")),
|
||||
daylightClut = GdxColorMap(ModMgr.getGdxFile(modname, "$pathToImage/${lightbox}")),
|
||||
tags = tags,
|
||||
cloudChance = JSON.getFloat("cloudChance"),
|
||||
windSpeed = JSON.getFloat("windSpeed"),
|
||||
windSpeedVariance = JSON.getFloat("windSpeedVariance"),
|
||||
windSpeedDamping = JSON.getFloat("windSpeedDamping"),
|
||||
cloudGamma = JSON["cloudGamma"].asFloatArray().let { Vector2(it[0], it[1]) },
|
||||
cloudGammaVariance = JSON["cloudGammaVariance"].asFloatArray().let { Vector2(it[0], it[1]) },
|
||||
clouds = cloudsMap,
|
||||
shaderVibrancy = JSON["shaderVibrancy"].asFloatArray()
|
||||
)
|
||||
|
||||
weatherById[ident] = obj
|
||||
tags.forEach {
|
||||
if (weatherByTags[it] == null) {
|
||||
weatherByTags[it] = mutableSetOf()
|
||||
}
|
||||
|
||||
weatherByTags[it]!!.add(obj)
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
weatherById.values.forEach {
|
||||
it.clouds.forEach { it.spriteSheet.tryDispose() }
|
||||
}
|
||||
}
|
||||
|
||||
fun getRandom(tag: String? = null): BaseModularWeather {
|
||||
return if (tag == null) {
|
||||
var k = weatherById.values.random()
|
||||
if (k.identifier == "titlescreen") k = weatherById.values.random()
|
||||
k
|
||||
}
|
||||
else getByTag(tag)!!.random()
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
JsonValue(JsonValue.ValueType.`object`),
|
||||
GdxColorMap(1, 3, Color(0x55aaffff), Color(0xaaffffff.toInt()), Color.WHITE),
|
||||
GdxColorMap(2, 2, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE),
|
||||
"default",
|
||||
listOf("default"),
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
@@ -74,9 +74,6 @@ internal object WeatherMixer : RNGConsumer {
|
||||
|
||||
var globalLightOverridden = false
|
||||
|
||||
val weatherDB: HashMap<String, ArrayList<BaseModularWeather>> // search by classification
|
||||
val weatherDict: HashMap<String, BaseModularWeather> // search by identifier
|
||||
|
||||
private var forceWindVec: Vector3? = null
|
||||
|
||||
val globalLightNow = Cvec(0)
|
||||
@@ -153,37 +150,6 @@ internal object WeatherMixer : RNGConsumer {
|
||||
oldCamPos.set(WorldCamera.camVector)
|
||||
}
|
||||
|
||||
init {
|
||||
weatherDB = HashMap<String, ArrayList<BaseModularWeather>>()
|
||||
weatherDict = HashMap<String, BaseModularWeather>()
|
||||
|
||||
|
||||
// read weather descriptions from assets/weather (modular weather)
|
||||
val weatherRawValidList = ArrayList<Pair<String, File>>()
|
||||
val weatherRawsDir = ModMgr.getFilesFromEveryMod("weathers")
|
||||
weatherRawsDir.forEach { (modname, parentdir) ->
|
||||
printdbg(this, "Scanning dir $parentdir")
|
||||
parentdir.listFiles(FileFilter { !it.isDirectory && it.name.endsWith(".json") })?.forEach {
|
||||
weatherRawValidList.add(modname to it)
|
||||
printdbg(this, "Registering weather '$it' from module $modname")
|
||||
}
|
||||
}
|
||||
// --> read from directory and store file that looks like RAW
|
||||
for ((modname, raw) in weatherRawValidList) {
|
||||
val weather = readFromJson(modname, raw)
|
||||
|
||||
weatherDict[weather.identifier] = weather
|
||||
|
||||
// if List for the classification does not exist, make one
|
||||
if (!weatherDB.containsKey(weather.classification))
|
||||
weatherDB.put(weather.classification, ArrayList())
|
||||
|
||||
weatherDB[weather.classification]!!.add(weather)
|
||||
}
|
||||
|
||||
weatherDict["titlescreen"] = weatherDB[WEATHER_GENERIC]?.get(0)?.copy(identifier = "titlescreen", windSpeed = 1f) ?: DEFAULT_WEATHER
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of Ingame update
|
||||
*/
|
||||
@@ -527,7 +493,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
}
|
||||
|
||||
internal fun titleScreenInitWeather(weatherbox: Weatherbox) {
|
||||
weatherbox.initWith(weatherDict["titlescreen"]!!, Long.MAX_VALUE)
|
||||
weatherbox.initWith(WeatherCodex.getById("titlescreen")!!, Long.MAX_VALUE)
|
||||
forceWindVec = Vector3(
|
||||
-0.98f,
|
||||
0f,
|
||||
@@ -923,72 +889,7 @@ internal object WeatherMixer : RNGConsumer {
|
||||
return lerp(x, c1.linearise(), c2.linearise()).unlinearise()
|
||||
}
|
||||
|
||||
fun getWeatherList(classification: String) = weatherDB[classification]!!
|
||||
fun getRandomWeather(classification: String) =
|
||||
getWeatherList(classification)[RNG.nextInt(getWeatherList(classification).size)]
|
||||
|
||||
fun readFromJson(modname: String, file: File): BaseModularWeather = readFromJson(modname, file.path)
|
||||
|
||||
fun readFromJson(modname: String, path: String): BaseModularWeather {
|
||||
/* JSON structure:
|
||||
{
|
||||
"skyboxGradColourMap": "colourmap/sky_colour.tga", // string (path to image) for dynamic. Image must be RGBA8888 or RGB888
|
||||
"extraImages": [
|
||||
// if any, it will be like:
|
||||
sun01.tga,
|
||||
clouds01.tga,
|
||||
clouds02.tga,
|
||||
auroraBlueViolet.tga
|
||||
]
|
||||
}
|
||||
*/
|
||||
val pathToImage = "weathers"
|
||||
|
||||
val JSON = JsonFetcher(path)
|
||||
|
||||
val skyboxInJson = JSON.getString("skyboxGradColourMap")
|
||||
val lightbox = JSON.getString("daylightClut")
|
||||
|
||||
val cloudsMap = ArrayList<CloudProps>()
|
||||
val clouds = JSON["clouds"]
|
||||
clouds.forEachSiblings { name, json ->
|
||||
cloudsMap.add(CloudProps(
|
||||
name,
|
||||
TextureRegionPack(ModMgr.getGdxFile(modname, "$pathToImage/${json.getString("filename")}"), json.getInt("tw"), json.getInt("th")),
|
||||
json.getFloat("probability"),
|
||||
json.getFloat("baseScale"),
|
||||
json.getFloat("scaleVariance"),
|
||||
json.getFloat("altLow"),
|
||||
json.getFloat("altHigh"),
|
||||
))
|
||||
}
|
||||
cloudsMap.sortBy { it.probability }
|
||||
|
||||
|
||||
|
||||
return BaseModularWeather(
|
||||
identifier = JSON.getString("identifier"),
|
||||
json = JSON,
|
||||
skyboxGradColourMap = GdxColorMap(ModMgr.getGdxFile(modname, "$pathToImage/${skyboxInJson}")),
|
||||
daylightClut = GdxColorMap(ModMgr.getGdxFile(modname, "$pathToImage/${lightbox}")),
|
||||
classification = JSON.getString("classification"),
|
||||
cloudChance = JSON.getFloat("cloudChance"),
|
||||
windSpeed = JSON.getFloat("windSpeed"),
|
||||
windSpeedVariance = JSON.getFloat("windSpeedVariance"),
|
||||
windSpeedDamping = JSON.getFloat("windSpeedDamping"),
|
||||
cloudGamma = JSON["cloudGamma"].asFloatArray().let { Vector2(it[0], it[1]) },
|
||||
cloudGammaVariance = JSON["cloudGammaVariance"].asFloatArray().let { Vector2(it[0], it[1]) },
|
||||
clouds = cloudsMap,
|
||||
shaderVibrancy = JSON["shaderVibrancy"].asFloatArray()
|
||||
)
|
||||
}
|
||||
|
||||
fun dispose() {
|
||||
weatherDB.values.forEach { list ->
|
||||
list.forEach { weather ->
|
||||
weather.clouds.forEach { it.spriteSheet.dispose() }
|
||||
}
|
||||
}
|
||||
starmapTex.texture.dispose()
|
||||
shaderAstrum.dispose()
|
||||
shaderClouds.dispose()
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.weather
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.WeatherCodex
|
||||
import net.torvald.terrarum.floorToInt
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
@@ -64,9 +65,9 @@ class Weatherbox {
|
||||
|
||||
private fun pickNextWeather(): WeatherSchedule {
|
||||
// temporary setup for the release
|
||||
val newName = if (takeUniformRand(0f..1f) < 0.5f) "generic01" else "generic02"
|
||||
val newWeather = WeatherCodex.getRandom()
|
||||
val newDuration = takeTriangularRand(3600f..10800f).roundToLong()
|
||||
return WeatherSchedule(WeatherMixer.weatherDict[newName]!!, newDuration)
|
||||
return WeatherSchedule(newWeather, newDuration)
|
||||
}
|
||||
|
||||
fun update(world: GameWorld) {
|
||||
|
||||
@@ -919,8 +919,8 @@ internal object BlocksDrawer {
|
||||
fun isWallSticker(b: ItemID) = App.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER
|
||||
fun isPlatform(b: ItemID) = App.tileMaker.getRenderTag(b).connectionType == CreateTileAtlas.RenderTag.CONNECT_WALL_STICKER_CONNECT_SELF
|
||||
//fun isBlendMul(b: Int) = TILES_BLEND_MUL.contains(b)
|
||||
fun isTreeFoliage(b: ItemID) = BlockCodex[b].hasAllTagOf("TREE", "LEAVES")
|
||||
fun isTreeTrunk(b: ItemID) = BlockCodex[b].hasAllTagOf("TREE", "TREETRUNK")
|
||||
fun isTreeFoliage(b: ItemID) = BlockCodex[b].hasAllTagsOf("TREE", "LEAVES")
|
||||
fun isTreeTrunk(b: ItemID) = BlockCodex[b].hasAllTagsOf("TREE", "TREETRUNK")
|
||||
|
||||
fun tileInCamera(x: Int, y: Int) =
|
||||
x >= WorldCamera.x.div(TILE_SIZE) && y >= WorldCamera.y.div(TILE_SIZE) &&
|
||||
|
||||
Reference in New Issue
Block a user