mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
serialised RNG; font update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.torvald.random
|
||||
|
||||
import net.torvald.terrarum.serialise.toLittle
|
||||
import net.torvald.terrarum.serialise.toLittleLong
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import java.util.Random
|
||||
@@ -12,6 +13,11 @@ class HQRNG @JvmOverloads constructor(seed: Long = System.nanoTime()) : Random()
|
||||
private var s0: Long
|
||||
private var s1: Long
|
||||
|
||||
constructor(s0: Long, s1: Long) : this() {
|
||||
this.s0 = s0
|
||||
this.s1 = s1
|
||||
}
|
||||
|
||||
init {
|
||||
if (seed == 0L)
|
||||
throw IllegalArgumentException("Invalid seed: cannot be zero")
|
||||
@@ -30,4 +36,11 @@ class HQRNG @JvmOverloads constructor(seed: Long = System.nanoTime()) : Random()
|
||||
s1 = x xor y xor (x ushr 17) xor (y ushr 26)
|
||||
return s1 + y
|
||||
}
|
||||
|
||||
fun serialize() = s0.toLittle() + s1.toLittle()
|
||||
|
||||
fun reseed(s0: Long, s1: Long) {
|
||||
this.s0 = s0
|
||||
this.s1 = s1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user