mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
new RNG for everything; Joise update
This commit is contained in:
@@ -8,7 +8,7 @@ internal interface RNGConsumer {
|
||||
val RNG: HQRNG
|
||||
|
||||
fun loadFromSave(s0: Long, s1: Long) {
|
||||
RNG.reseed(s0, s1)
|
||||
RNG.setSeed(s0, s1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ open class ActorHumanoid(
|
||||
private var oldJUMPPOWERBUFF = -1.0 // init
|
||||
private var oldScale = -1.0
|
||||
private var oldDragCoefficient = -1.0
|
||||
val jumpAirTime: Double = -1.0
|
||||
var jumpAirTime: Double = -1.0
|
||||
get() {
|
||||
// compare all the affecting variables
|
||||
if (oldMAX_JUMP_LENGTH == MAX_JUMP_LENGTH &&
|
||||
|
||||
@@ -13,9 +13,10 @@ typealias time_t = Long
|
||||
* https://en.wikipedia.org/wiki/World_Calendar
|
||||
* http://dwarffortresswiki.org/index.php/DF2014:Calendar
|
||||
*
|
||||
* And there is no AM/PM concept, 22-hour clock is forced; no leap years.
|
||||
* (AM 12 is still 00h in this system, again, to reduce confusion)
|
||||
* And there is no AM/PM concept, 24-hour clock is forced; no leap years.
|
||||
* An ingame day should last 22 real-life minutes.
|
||||
*
|
||||
* // TODO 4-month year? like Stardew Valley
|
||||
*
|
||||
* Calendar
|
||||
*
|
||||
@@ -110,13 +111,13 @@ class WorldTime(initTime: Long = 0L) {
|
||||
"Mala", "Gale", "Lime", "Sand", "Timb", "Moon")
|
||||
|
||||
companion object {
|
||||
/** Each day is 22-hour long */
|
||||
val DAY_LENGTH = 79200 //must be the multiple of 3600
|
||||
/** Each day is displayed as 24 hours, but in real-life clock it's 22 mins long */
|
||||
val DAY_LENGTH = 86400 //must be the multiple of 3600
|
||||
|
||||
val HOUR_SEC: Int = 3600
|
||||
val MINUTE_SEC: Int = 60
|
||||
val HOUR_MIN: Int = 60
|
||||
val GAME_MIN_TO_REAL_SEC: Float = 60f
|
||||
val GAME_MIN_TO_REAL_SEC: Float = 720f/11f
|
||||
val HOURS_PER_DAY = DAY_LENGTH / HOUR_SEC
|
||||
|
||||
val YEAR_DAYS: Int = 365
|
||||
@@ -164,8 +165,8 @@ class WorldTime(initTime: Long = 0L) {
|
||||
val dayName: String
|
||||
get() = DAY_NAMES[dayOfWeek]
|
||||
|
||||
inline fun Long.toPositiveInt() = this.and(0x7FFFFFFF).toInt()
|
||||
inline fun Long.abs() = Math.abs(this)
|
||||
fun Long.toPositiveInt() = this.and(0x7FFFFFFF).toInt()
|
||||
fun Long.abs() = Math.abs(this)
|
||||
|
||||
/** Format: "%A, %d %B %Y %X" */
|
||||
fun getFormattedTime() = "${getDayNameShort()}, " +
|
||||
|
||||
@@ -22,6 +22,11 @@ object ReadWorldInfo {
|
||||
throw IllegalArgumentException("File not a Save Meta")
|
||||
}
|
||||
|
||||
|
||||
val descVersion = fis.read(1) // 0-127
|
||||
val numberOfHashes = fis.read() // 0-127
|
||||
|
||||
|
||||
var byteRead = fis.read()
|
||||
while (byteRead != 0) {
|
||||
if (byteRead == -1)
|
||||
@@ -38,14 +43,14 @@ object ReadWorldInfo {
|
||||
fis.read(8).toLittleLong(), // rng s1
|
||||
fis.read(8).toLittleLong(), // weather s0
|
||||
fis.read(8).toLittleLong(), // weather s1
|
||||
fis.read(32),
|
||||
fis.read(32),
|
||||
fis.read(32),
|
||||
fis.read(4).toLittleInt(), // player id
|
||||
fis.read(8).toLittleLong(), // world TIME_T
|
||||
fis.read(6).toLittleLong(), // creation time
|
||||
fis.read(6).toLittleLong(), // last play time
|
||||
fis.read(4).toLittleInt() // total time wasted
|
||||
fis.read(4).toLittleInt(), // total time wasted
|
||||
fis.read(32), // sha256sum worldinfo1
|
||||
fis.read(32), // sha256sum worldinfo2
|
||||
fis.read(32) // sha256sum worldinfo3
|
||||
)
|
||||
}
|
||||
|
||||
@@ -57,13 +62,13 @@ object ReadWorldInfo {
|
||||
val rngS1: Long,
|
||||
val weatherS0: Long,
|
||||
val weatherS1: Long,
|
||||
val worldinfo1Hash: ByteArray,
|
||||
val worldInfo2Hash: ByteArray,
|
||||
val worldInfo3Hash: ByteArray,
|
||||
val playerID: Int,
|
||||
val timeNow: Long,
|
||||
val creationTime: Long,
|
||||
val lastPlayTime: Long,
|
||||
val totalPlayTime: Int
|
||||
val totalPlayTime: Int,
|
||||
val worldinfo1Hash: ByteArray,
|
||||
val worldInfo2Hash: ByteArray,
|
||||
val worldInfo3Hash: ByteArray
|
||||
)
|
||||
}
|
||||
@@ -18,6 +18,9 @@ object WriteWorldInfo {
|
||||
val META_MAGIC = "TESV".toByteArray(Charsets.UTF_8)
|
||||
val NULL = 0.toByte()
|
||||
|
||||
val VERSION = 1
|
||||
val HASHED_FILES_COUNT = 3
|
||||
|
||||
/**
|
||||
* TODO currently it'll dump the temporary file (tmp_worldinfo1) onto the disk and will return the temp file.
|
||||
*
|
||||
@@ -38,10 +41,11 @@ object WriteWorldInfo {
|
||||
|
||||
val outFiles = ArrayList<File>()
|
||||
outFiles.add(metaFile)
|
||||
|
||||
val worldInfoHash = ArrayList<ByteArray>() // hash of worldinfo1-3
|
||||
// try to write worldinfo1-3
|
||||
|
||||
for (filenum in 1..3) {
|
||||
for (filenum in 1..HASHED_FILES_COUNT) {
|
||||
val outFile = File(path + filenum.toString())
|
||||
if (outFile.exists()) outFile.delete()
|
||||
outFile.createNewFile()
|
||||
@@ -65,11 +69,13 @@ object WriteWorldInfo {
|
||||
}
|
||||
|
||||
|
||||
// compose save meta
|
||||
// compose save meta (actual writing part)
|
||||
val metaOut = BufferedOutputStream(FileOutputStream(metaFile), 256)
|
||||
|
||||
|
||||
metaOut.write(META_MAGIC)
|
||||
metaOut.write(VERSION)
|
||||
metaOut.write(HASHED_FILES_COUNT)
|
||||
|
||||
// world name
|
||||
val worldNameBytes = world.worldName.toByteArray(Charsets.UTF_8)
|
||||
@@ -80,28 +86,23 @@ object WriteWorldInfo {
|
||||
metaOut.write(world.generatorSeed.toLittle())
|
||||
|
||||
// randomiser seed
|
||||
metaOut.write(RoguelikeRandomiser.RNG.s0.toLittle())
|
||||
metaOut.write(RoguelikeRandomiser.RNG.s1.toLittle())
|
||||
metaOut.write(RoguelikeRandomiser.RNG.state0.toLittle())
|
||||
metaOut.write(RoguelikeRandomiser.RNG.state1.toLittle())
|
||||
|
||||
// weather seed
|
||||
metaOut.write(WeatherMixer.RNG.s0.toLittle())
|
||||
metaOut.write(WeatherMixer.RNG.s1.toLittle())
|
||||
|
||||
// SHA256SUM of worldinfo1-3
|
||||
worldInfoHash.forEach {
|
||||
metaOut.write(it)
|
||||
}
|
||||
metaOut.write(WeatherMixer.RNG.state0.toLittle())
|
||||
metaOut.write(WeatherMixer.RNG.state1.toLittle())
|
||||
|
||||
// reference ID of the player
|
||||
metaOut.write(Terrarum.PLAYER_REF_ID.toLittle())
|
||||
|
||||
// time_t
|
||||
// ingame time_t
|
||||
metaOut.write((world as GameWorldExtension).time.TIME_T.toLittle())
|
||||
|
||||
// creation time (real world time)
|
||||
metaOut.write(world.creationTime.toLittle48())
|
||||
|
||||
// time at save
|
||||
// time at save (real world time)
|
||||
val timeNow = System.currentTimeMillis() / 1000L
|
||||
metaOut.write(timeNow.toLittle48())
|
||||
|
||||
@@ -111,8 +112,14 @@ object WriteWorldInfo {
|
||||
world.lastPlayTime = timeNow
|
||||
world.totalPlayTime += timeToAdd
|
||||
|
||||
// SHA256SUM of worldinfo1-3
|
||||
worldInfoHash.forEach {
|
||||
metaOut.write(it)
|
||||
}
|
||||
|
||||
|
||||
// more data goes here //
|
||||
|
||||
|
||||
metaOut.flush()
|
||||
metaOut.close()
|
||||
|
||||
Reference in New Issue
Block a user