new gem on worldgen

This commit is contained in:
minjaesong
2024-02-13 23:42:43 +09:00
parent 6e1af36a63
commit e5ac560966
27 changed files with 263 additions and 82 deletions

View File

@@ -3,12 +3,12 @@
"1";"N/A";"N/A";"BLOCK_UPDATE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"AIIR";"0";"1";"N/A";"0";"0";"4";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"INTERNAL,NORANDTILE" "1";"N/A";"N/A";"BLOCK_UPDATE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"AIIR";"0";"1";"N/A";"0";"0";"4";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"INTERNAL,NORANDTILE"
# rocks # rocks
"16";"17";"17";"BLOCK_STONE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURAL,OREBEARING" "16";"17";"17";"BLOCK_STONE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURAL,OREBEARING,SHALLOWROCK"
"17";"17";"17";"BLOCK_STONE_QUARRIED";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURAL,OREBEARING" "17";"17";"17";"BLOCK_STONE_QUARRIED";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURAL,OREBEARING,SHALLOWROCK"
"18";"18";"18";"BLOCK_STONE_TILE_WHITE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.18";"STONE,NORANDTILE" "18";"18";"18";"BLOCK_STONE_TILE_WHITE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.18";"STONE,NORANDTILE"
"19";"19";"19";"BLOCK_STONE_BRICKS";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"STONE,NORANDTILE" "19";"19";"19";"BLOCK_STONE_BRICKS";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"STONE,NORANDTILE"
"20";"20";"20";"BLOCK_STONE_DEEP";"0.1252";"0.1252";"0.1252";"0.1252";"80";"24600";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURA,OREBEARING" "20";"20";"20";"BLOCK_STONE_DEEP";"0.1252";"0.1252";"0.1252";"0.1252";"80";"24600";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURA,OREBEARING,DEEPROCK"
"21";"21";"21";"BLOCK_STONE_MARBLE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.1";"ROCK,NATURAL" "21";"21";"21";"BLOCK_STONE_MARBLE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.1";"ROCK,NATURAL,DEEPROCK"
# dirts # dirts
"32";"32";"32";"BLOCK_DIRT";"0.1252";"0.1252";"0.1252";"0.1252";"24";"1400";"DIRT";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"DIRT,NATURAL,CULTIVABLE" "32";"32";"32";"BLOCK_DIRT";"0.1252";"0.1252";"0.1252";"0.1252";"24";"1400";"DIRT";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"DIRT,NATURAL,CULTIVABLE"
1 id drop spawn name shdr shdg shdb shduv str dsty mate solid wall grav dlfn fv fr lumr lumg lumb lumuv colour vscs refl tags
3 1 N/A N/A BLOCK_UPDATE 0.0312 0.0312 0.0312 0.0312 1 1 AIIR 0 1 N/A 0 0 4 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 INTERNAL,NORANDTILE
4 # rocks
5 16 17 17 BLOCK_STONE 0.1252 0.1252 0.1252 0.1252 48 2400 ROCK 1 1 N/A 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 ROCK,NATURAL,OREBEARING ROCK,NATURAL,OREBEARING,SHALLOWROCK
6 17 17 17 BLOCK_STONE_QUARRIED 0.1252 0.1252 0.1252 0.1252 48 2400 ROCK 1 1 N/A 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 ROCK,NATURAL,OREBEARING ROCK,NATURAL,OREBEARING,SHALLOWROCK
7 18 18 18 BLOCK_STONE_TILE_WHITE 0.1252 0.1252 0.1252 0.1252 48 2400 ROCK 1 1 N/A 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.18 STONE,NORANDTILE
8 19 19 19 BLOCK_STONE_BRICKS 0.1252 0.1252 0.1252 0.1252 48 2400 ROCK 1 1 N/A 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 STONE,NORANDTILE
9 20 20 20 BLOCK_STONE_DEEP 0.1252 0.1252 0.1252 0.1252 80 24600 ROCK 1 1 N/A 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 ROCK,NATURA,OREBEARING ROCK,NATURA,OREBEARING,DEEPROCK
10 21 21 21 BLOCK_STONE_MARBLE 0.1252 0.1252 0.1252 0.1252 48 2400 ROCK 1 1 N/A 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.1 ROCK,NATURAL ROCK,NATURAL,DEEPROCK
11 # dirts
12 32 32 32 BLOCK_DIRT 0.1252 0.1252 0.1252 0.1252 24 1400 DIRT 1 1 N/A 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 DIRT,NATURAL,CULTIVABLE
13 33 32 32 BLOCK_GRASS 0.1252 0.1252 0.1252 0.1252 24 1400 GRSS 1 0 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 GRASS,NATURAL,CULTIVABLE
14 34 34 34 BLOCK_GRASSWALL 0.1252 0.1252 0.1252 0.1252 24 1400 GRSS 1 1 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A 0.0 GRASS,NATURAL

View File

@@ -19,7 +19,6 @@ MoneyDisp
MusicTest MusicTest
Possess Possess
PrintWorld PrintWorld
Save
Seed Seed
SetAV SetAV
SetBulletin SetBulletin
@@ -29,7 +28,6 @@ SetTurb
SetTime SetTime
SetTimeDelta SetTimeDelta
SpawnPhysTestBall SpawnPhysTestBall
StreamerMode
Teleport Teleport
ToggleNoClip ToggleNoClip
Zoom Zoom
1 CatStdout
19 MusicTest
20 Possess
21 PrintWorld
Save
22 Seed
23 SetAV
24 SetBulletin
28 SetTime
29 SetTimeDelta
30 SpawnPhysTestBall
StreamerMode
31 Teleport
32 ToggleNoClip
33 Zoom

View File

@@ -56,6 +56,7 @@ id;classname;tags
144;net.torvald.terrarum.modulebasegame.gameitems.GemQuartz;SMELTABLE,SIO2 144;net.torvald.terrarum.modulebasegame.gameitems.GemQuartz;SMELTABLE,SIO2
145;net.torvald.terrarum.modulebasegame.gameitems.GemAmethyst;SMELTABLE,SIO2 145;net.torvald.terrarum.modulebasegame.gameitems.GemAmethyst;SMELTABLE,SIO2
146;net.torvald.terrarum.modulebasegame.gameitems.ItemRockSalt; 146;net.torvald.terrarum.modulebasegame.gameitems.ItemRockSalt;
147;net.torvald.terrarum.modulebasegame.gameitems.ItemNitre;
# tree seeds by tree species # tree seeds by tree species
160;net.torvald.terrarum.modulebasegame.gameitems.ItemSeedOak;SEEDLING 160;net.torvald.terrarum.modulebasegame.gameitems.ItemSeedOak;SEEDLING
1 id classname tags
56 161 160 net.torvald.terrarum.modulebasegame.gameitems.ItemSeedEbony net.torvald.terrarum.modulebasegame.gameitems.ItemSeedOak SEEDLING
57 162 161 net.torvald.terrarum.modulebasegame.gameitems.ItemSeedBirch net.torvald.terrarum.modulebasegame.gameitems.ItemSeedEbony SEEDLING
58 163 162 net.torvald.terrarum.modulebasegame.gameitems.ItemSeedRosewood net.torvald.terrarum.modulebasegame.gameitems.ItemSeedBirch SEEDLING
59 163 net.torvald.terrarum.modulebasegame.gameitems.ItemSeedRosewood SEEDLING
60 # tree logs
61 168 net.torvald.terrarum.modulebasegame.gameitems.ItemLogsOak COMBUSTIBLE,SMELTABLE
62 169 net.torvald.terrarum.modulebasegame.gameitems.ItemLogsEbony COMBUSTIBLE,SMELTABLE

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/mods/basegame/ores/259.tga LFS Normal file

Binary file not shown.

View File

@@ -1,22 +1,24 @@
"id";"item";"tags" "id";"item";"tags"
"1";"item@basegame:128";"COPPER,MALACHITE" "1";"item@basegame:128";"COPPER,MALACHITE"
"2";"item@basegame:129";"IRON,HAEMATITE" "2";"item@basegame:129";"IRON,HAEMATITE"
"3";"item@basegame:130";"COAL,CARBON" "3";"item@basegame:130";"COAL,CARBON"
"4";"item@basegame:131";"ZINC,SPHALERITE" "4";"item@basegame:131";"ZINC,SPHALERITE"
"5";"item@basegame:132";"TIN,CASSITERITE" "5";"item@basegame:132";"TIN,CASSITERITE"
"6";"item@basegame:133";"GOLD,NATURAL_GOLD" "6";"item@basegame:133";"GOLD,NATURAL_GOLD"
"7";"item@basegame:134";"SILVER,NATURAL_SILVER" "7";"item@basegame:134";"SILVER,NATURAL_SILVER"
"8";"item@basegame:135";"LEAD,GALENA" "8";"item@basegame:135";"LEAD,GALENA"
#"9";"item@basegame:143";"TITANIUM,RUTILE" #"9";"item@basegame:143";"TITANIUM,RUTILE"
"256";"item@basegame:146";"SALT" "256";"item@basegame:146";"SALT"
"257";"item@basegame:145";"GEM,SIO2,AMETHYST" "257";"item@basegame:145";"GEM,SIO2,AMETHYST"
"258";"item@basegame:144";"GEM,SIO2,QUARTZ" "258";"item@basegame:144";"GEM,SIO2,QUARTZ"
#"259";"item@basegame:136";"GEM,RUBY" "259";"item@basegame:147";"GEM,NITRE"
#"260";"item@basegame:137";"GEM,EMERALD"
#"261";"item@basegame:138";"GEM,SAPPHIRE" #"260";"item@basegame:136";"GEM,RUBY"
#"262";"item@basegame:139";"GEM,TOPAZ" #"261";"item@basegame:137";"GEM,EMERALD"
#"263";"item@basegame:140";"GEM,DIAMOND" #"262";"item@basegame:138";"GEM,SAPPHIRE"
#"263";"item@basegame:139";"GEM,TOPAZ"
#"264";"item@basegame:140";"GEM,DIAMOND"
#"512";"macro@BASETILE";"GRASS" #"512";"macro@BASETILE";"GRASS"
#"513";"macro@BASETILE";"MOSS" #"513";"macro@BASETILE";"MOSS"
Can't render this file because it contains an unexpected character in line 10 and column 2.

View File

@@ -1,16 +1,17 @@
"id";"freq";"power";"scale";"ratio";"tiling";"comment" "id";"freq";"power";"scale";"ratio";"tiling";"comment";"blocktagnongrata"
"1";"0.026";"0.010";"0.517";"1.0";"a16x16";"copper (malachite)" "1";"0.026";"0.010";"0.517";"1.0";"a16x16";"copper (malachite)";""
"2";"0.045";"0.011";"0.517";"1.0";"a16x16";"iron (haematite)" "2";"0.045";"0.011";"0.517";"1.0";"a16x16";"iron (haematite)";""
"3";"0.017";"0.070";"0.511";"3.8";"a16x4";"coal" "3";"0.017";"0.070";"0.511";"3.8";"a16x4";"coal";""
"4";"0.019";"0.011";"0.511";"1.0";"a16x16";"zinc (sphalerite)" "4";"0.019";"0.011";"0.511";"1.0";"a16x16";"zinc (sphalerite)";""
"5";"0.017";"0.017";"0.511";"1.0";"a16x16";"tin (cassiterite)" "5";"0.017";"0.017";"0.511";"1.0";"a16x16";"tin (cassiterite)";""
"6";"0.009";"0.300";"0.474";"1.0";"a16x16";"natural gold" "6";"0.009";"0.300";"0.474";"1.0";"a16x16";"natural gold";""
"7";"0.013";"0.300";"0.476";"1.0";"a16x16";"natural silver" "7";"0.013";"0.300";"0.476";"1.0";"a16x16";"natural silver";""
"8";"0.017";"0.020";"0.511";"1.0";"a16x16";"lead (galena)" "8";"0.017";"0.020";"0.511";"1.0";"a16x16";"lead (galena)";""
"256";"0.010";"-0.366";"0.528";"2.4";"a16x8";"rocksalt" "256";"0.010";"-0.366";"0.528";"2.4";"a16x8";"rocksalt";"DEEPROCK"
"257";"0.007";"0.100";"0.494";"1.0";"a16x8";"amethyst" "257";"0.007";"0.100";"0.494";"1.0";"a16x8";"amethyst";""
"258";"0.019";"0.015";"0.509";"1.0";"a16x8";"quartz" "258";"0.019";"0.015";"0.509";"1.0";"a16x8";"quartz";""
"259";"0.010";"-0.166";"0.517";"1.4";"a16x8";"nitre";"DEEPROCK"
################################################################################ ################################################################################
@@ -31,4 +32,5 @@
# - r16: use the hash of the tile position as a variant selection, module 16 # - r16: use the hash of the tile position as a variant selection, module 16
# - r8: use the hash of the tile position as a variant selection, module 8 # - r8: use the hash of the tile position as a variant selection, module 8
# #
# comment: human-readable comments, not actually parsed # comment: human-readable comments, not actually used
# blocktagnongrata: blocks with matching tag will not bear the ore. leave empty "" to allow all
Can't render this file because it contains an unexpected character in line 36 and column 81.

View File

@@ -623,8 +623,9 @@ object ModMgr {
val scale = rec.get("scale").toDouble() val scale = rec.get("scale").toDouble()
val ratio = rec.get("ratio").toDouble() val ratio = rec.get("ratio").toDouble()
val tiling = rec.get("tiling") val tiling = rec.get("tiling")
val blockTagNonGrata = rec.get("blocktagnongrata").split(',').map { it.trim().toUpperCase() }.toHashSet()
Worldgen.registerOre(OregenParams(tile, freq, power, scale, ratio, tiling)) Worldgen.registerOre(OregenParams(tile, freq, power, scale, ratio, tiling, blockTagNonGrata))
} }
} }
catch (e: IOException) { catch (e: IOException) {

View File

@@ -15,19 +15,20 @@ import java.util.regex.Pattern
internal object CommandInterpreter { internal object CommandInterpreter {
private val commandsNoAuth = arrayOf( private val commandsNoAuth = arrayOf(
"auth", "auth",
"qqq", "qqq",
"setlocale", "setlocale",
"getlocale", "getlocale",
"help", "help",
"version", "version",
"tips", "tips",
"screenshot", "screenshot",
"resize", "resize",
"echo", "echo",
"error", "error",
"seed", "seed",
"quicksave" "quicksave",
"uuid"
) )
internal fun execute(command: String) { internal fun execute(command: String) {

View File

@@ -293,6 +293,31 @@ class SavegameCracker(
if (worldIndex.isNotBlank()) println("${ccNoun}World UUID: $ccNoun2$worldIndex") if (worldIndex.isNotBlank()) println("${ccNoun}World UUID: $ccNoun2$worldIndex")
} }
} }
@Command("Removes the specified chunk(s) completely", "IDs")
fun discardchunk(args: List<String>) {
letdisk { disk ->
val ids = args[1]
val range = if (ids.matches(Regex("""[0-9]+-[0-9]+""")))
ids.substringBefore('-').toLong()..ids.substringAfter('-').toLong()
else
ids.toLong()..ids.toLong()
var rms = 0
range.forEach {
// TODO update according to the savegame format
val fileIDs = (0..15).map { layer -> 4294967296L + layer.shl(24) or it }
fileIDs.forEach {
if (disk.entries.containsKey(it)) rms += 1
disk.entries.remove(it)
VDUtil.getAsDirectory(disk, 0).remove(it)
}
}
println("${cc0}$rms entries removed")
}
}
} }
internal annotation class Command(val help: String = "", val synopsis: String = "") internal annotation class Command(val help: String = "", val synopsis: String = "")

View File

@@ -7,9 +7,15 @@ import com.badlogic.gdx.utils.Disposable
*/ */
interface BlockLayer : Disposable { interface BlockLayer : Disposable {
val width: Int
val height: Int
val bytesPerBlock: Long val bytesPerBlock: Long
fun unsafeToBytes(x: Int, y: Int): ByteArray fun unsafeToBytes(x: Int, y: Int): ByteArray
fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray) fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray)
fun unsafeGetTile(x: Int, y: Int): Int fun unsafeGetTile(x: Int, y: Int): Int
}
inline fun BlockLayer.getOffset(x: Int, y: Int): Long {
return this.bytesPerBlock * (y * this.width + x)
} }

View File

@@ -18,13 +18,13 @@ import net.torvald.unsafe.UnsafePtr
* *
* Note to self: refrain from using shorts--just do away with two bytes: different system have different endianness * Note to self: refrain from using shorts--just do away with two bytes: different system have different endianness
*/ */
open class BlockLayerI16(val width: Int, val height: Int) : BlockLayer { open class BlockLayerI16(override val width: Int, override val height: Int) : BlockLayer {
override val bytesPerBlock = BYTES_PER_BLOCK override val bytesPerBlock = BYTES_PER_BLOCK
// for some reason, all the efforts of saving the memory space were futile. // for some reason, all the efforts of saving the memory space were futile.
// using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90 // using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90
internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * BYTES_PER_BLOCK) internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * bytesPerBlock)
val ptrDestroyed: Boolean val ptrDestroyed: Boolean
get() = ptr.destroyed get() = ptr.destroyed
@@ -50,7 +50,7 @@ open class BlockLayerI16(val width: Int, val height: Int) : BlockLayer {
return object : Iterator<Byte> { return object : Iterator<Byte> {
private var iteratorCount = 0L private var iteratorCount = 0L
override fun hasNext(): Boolean { override fun hasNext(): Boolean {
return iteratorCount < width * height * BYTES_PER_BLOCK return iteratorCount < width * height * bytesPerBlock
} }
override fun next(): Byte { override fun next(): Byte {
iteratorCount += 1 iteratorCount += 1
@@ -60,7 +60,7 @@ open class BlockLayerI16(val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeGetTile(x: Int, y: Int): Int { override fun unsafeGetTile(x: Int, y: Int): Int {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = ptr[offset] val lsb = ptr[offset]
val msb = ptr[offset + 1] val msb = ptr[offset + 1]
@@ -68,12 +68,12 @@ open class BlockLayerI16(val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeToBytes(x: Int, y: Int): ByteArray { override fun unsafeToBytes(x: Int, y: Int): ByteArray {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
return byteArrayOf(ptr[offset + 1], ptr[offset + 0]) return byteArrayOf(ptr[offset + 1], ptr[offset + 0])
} }
internal fun unsafeSetTile(x: Int, y: Int, tile: Int) { internal fun unsafeSetTile(x: Int, y: Int, tile: Int) {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = tile.and(0xff).toByte() val lsb = tile.and(0xff).toByte()
val msb = tile.ushr(8).and(0xff).toByte() val msb = tile.ushr(8).and(0xff).toByte()
@@ -90,7 +90,7 @@ open class BlockLayerI16(val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray) { override fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray) {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
ptr[offset] = bytes[1] ptr[offset] = bytes[1]
ptr[offset + 1] = bytes[0] ptr[offset + 1] = bytes[0]
} }

View File

@@ -16,13 +16,13 @@ import net.torvald.util.Float16
* *
* Created by minjaesong on 2023-10-10. * Created by minjaesong on 2023-10-10.
*/ */
class BlockLayerI16F16(val width: Int, val height: Int) : BlockLayer { class BlockLayerI16F16(override val width: Int, override val height: Int) : BlockLayer {
override val bytesPerBlock = BYTES_PER_BLOCK override val bytesPerBlock = BYTES_PER_BLOCK
// for some reason, all the efforts of saving the memory space were futile. // for some reason, all the efforts of saving the memory space were futile.
// using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90 // using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90
internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * BYTES_PER_BLOCK) internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * bytesPerBlock)
val ptrDestroyed: Boolean val ptrDestroyed: Boolean
get() = ptr.destroyed get() = ptr.destroyed
@@ -48,7 +48,7 @@ class BlockLayerI16F16(val width: Int, val height: Int) : BlockLayer {
return object : Iterator<Byte> { return object : Iterator<Byte> {
private var iteratorCount = 0L private var iteratorCount = 0L
override fun hasNext(): Boolean { override fun hasNext(): Boolean {
return iteratorCount < width * height * BYTES_PER_BLOCK return iteratorCount < width * height * bytesPerBlock
} }
override fun next(): Byte { override fun next(): Byte {
iteratorCount += 1 iteratorCount += 1
@@ -58,7 +58,7 @@ class BlockLayerI16F16(val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeGetTile(x: Int, y: Int): Int { override fun unsafeGetTile(x: Int, y: Int): Int {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = ptr[offset] val lsb = ptr[offset]
val msb = ptr[offset + 1] val msb = ptr[offset + 1]
val hbits = (ptr[offset + 2].toUint() or ptr[offset + 3].toUint().shl(8)).toShort() val hbits = (ptr[offset + 2].toUint() or ptr[offset + 3].toUint().shl(8)).toShort()
@@ -68,7 +68,7 @@ class BlockLayerI16F16(val width: Int, val height: Int) : BlockLayer {
} }
internal fun unsafeGetTile1(x: Int, y: Int): Pair<Int, Float> { internal fun unsafeGetTile1(x: Int, y: Int): Pair<Int, Float> {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = ptr[offset] val lsb = ptr[offset]
val msb = ptr[offset + 1] val msb = ptr[offset + 1]
val hbits = (ptr[offset + 2].toUint() or ptr[offset + 3].toUint().shl(8)).toShort() val hbits = (ptr[offset + 2].toUint() or ptr[offset + 3].toUint().shl(8)).toShort()
@@ -78,12 +78,12 @@ class BlockLayerI16F16(val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeToBytes(x: Int, y: Int): ByteArray { override fun unsafeToBytes(x: Int, y: Int): ByteArray {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
return byteArrayOf(ptr[offset + 1], ptr[offset + 0], ptr[offset + 3], ptr[offset + 2]) return byteArrayOf(ptr[offset + 1], ptr[offset + 0], ptr[offset + 3], ptr[offset + 2])
} }
internal fun unsafeSetTile(x: Int, y: Int, tile0: Int, fill: Float) { internal fun unsafeSetTile(x: Int, y: Int, tile0: Int, fill: Float) {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val hbits = Float16.fromFloat(fill).toInt().and(0xFFFF) val hbits = Float16.fromFloat(fill).toInt().and(0xFFFF)
val tile = if (fill < FLUID_MIN_MASS) 0 else tile0 val tile = if (fill < FLUID_MIN_MASS) 0 else tile0
@@ -102,7 +102,7 @@ class BlockLayerI16F16(val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray) { override fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray) {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
ptr[offset] = bytes[1] ptr[offset] = bytes[1]
ptr[offset + 1] = bytes[0] ptr[offset + 1] = bytes[0]
ptr[offset + 2] = bytes[3] ptr[offset + 2] = bytes[3]

View File

@@ -13,13 +13,13 @@ import net.torvald.unsafe.UnsafePtr
* where a_n is a tile number, p_n is a placement index * where a_n is a tile number, p_n is a placement index
* Created by minjaesong on 2023-10-10. * Created by minjaesong on 2023-10-10.
*/ */
class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer { class BlockLayerI16I8 (override val width: Int, override val height: Int) : BlockLayer {
override val bytesPerBlock = BYTES_PER_BLOCK override val bytesPerBlock = BYTES_PER_BLOCK
// for some reason, all the efforts of saving the memory space were futile. // for some reason, all the efforts of saving the memory space were futile.
// using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90 // using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90
internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * BYTES_PER_BLOCK) internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * bytesPerBlock)
val ptrDestroyed: Boolean val ptrDestroyed: Boolean
get() = ptr.destroyed get() = ptr.destroyed
@@ -45,7 +45,7 @@ class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer {
return object : Iterator<Byte> { return object : Iterator<Byte> {
private var iteratorCount = 0L private var iteratorCount = 0L
override fun hasNext(): Boolean { override fun hasNext(): Boolean {
return iteratorCount < width * height * BYTES_PER_BLOCK return iteratorCount < width * height * bytesPerBlock
} }
override fun next(): Byte { override fun next(): Byte {
iteratorCount += 1 iteratorCount += 1
@@ -55,7 +55,7 @@ class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeGetTile(x: Int, y: Int): Int { override fun unsafeGetTile(x: Int, y: Int): Int {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = ptr[offset] val lsb = ptr[offset]
val msb = ptr[offset + 1] val msb = ptr[offset + 1]
val placement = ptr[offset + 2] val placement = ptr[offset + 2]
@@ -64,7 +64,7 @@ class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer {
} }
internal fun unsafeGetTile1(x: Int, y: Int): Pair<Int, Int> { internal fun unsafeGetTile1(x: Int, y: Int): Pair<Int, Int> {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = ptr[offset] val lsb = ptr[offset]
val msb = ptr[offset + 1] val msb = ptr[offset + 1]
val placement = ptr[offset + 2] val placement = ptr[offset + 2]
@@ -73,12 +73,12 @@ class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeToBytes(x: Int, y: Int): ByteArray { override fun unsafeToBytes(x: Int, y: Int): ByteArray {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
return byteArrayOf(ptr[offset + 1], ptr[offset + 0], ptr[offset + 2]) return byteArrayOf(ptr[offset + 1], ptr[offset + 0], ptr[offset + 2])
} }
internal fun unsafeSetTile(x: Int, y: Int, tile: Int, placement: Int) { internal fun unsafeSetTile(x: Int, y: Int, tile: Int, placement: Int) {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = tile.and(0xff).toByte() val lsb = tile.and(0xff).toByte()
val msb = tile.ushr(8).and(0xff).toByte() val msb = tile.ushr(8).and(0xff).toByte()
@@ -96,14 +96,14 @@ class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer {
} }
override fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray) { override fun unsafeSetTile(x: Int, y: Int, bytes: ByteArray) {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
ptr[offset] = bytes[1] ptr[offset] = bytes[1]
ptr[offset + 1] = bytes[0] ptr[offset + 1] = bytes[0]
ptr[offset + 2] = bytes[2] ptr[offset + 2] = bytes[2]
} }
internal fun unsafeSetTileKeepPlacement(x: Int, y: Int, tile: Int) { internal fun unsafeSetTileKeepPlacement(x: Int, y: Int, tile: Int) {
val offset = BYTES_PER_BLOCK * (y * width + x) val offset = getOffset(x, y)
val lsb = tile.and(0xff).toByte() val lsb = tile.and(0xff).toByte()
val msb = tile.ushr(8).and(0xff).toByte() val msb = tile.ushr(8).and(0xff).toByte()

View File

@@ -0,0 +1,80 @@
package net.torvald.terrarum.modulebasegame
import net.torvald.terrarum.gameworld.BlockLayerI16
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.getOffset
import net.torvald.terrarum.tryDispose
import net.torvald.unsafe.UnsafeHelper
/**
* Created by minjaesong on 2024-02-13.
*/
object ExplosionManager {
private const val CALC_RADIUS = 127
private const val CALC_WIDTH = CALC_RADIUS * 2 + 1
fun goBoom(world: GameWorld, tx: Int, ty: Int, power: Float) {
// create a copy of the tilemap
val tilemap = BlockLayerI16(CALC_WIDTH, CALC_WIDTH)
// fill in the tilemap copy
for (line in 0 until CALC_WIDTH) {
memcpyFromWorld(world, tx - CALC_RADIUS, ty - CALC_RADIUS, line, tilemap)
}
createExplosionWorker(tilemap, tx, ty, power, world).start()
}
private fun memcpyFromWorld(world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: BlockLayerI16) {
// if the bounding box must wrap around
if (xStart > world.width - CALC_RADIUS) {
val lenLeft = world.width - xStart
val lenRight = CALC_WIDTH - lenLeft
UnsafeHelper.memcpy(
world.layerTerrain.ptr,
world.layerTerrain.getOffset(xStart, yStart + yOff),
out.ptr,
out.getOffset(0, yOff),
world.layerTerrain.bytesPerBlock * lenLeft
)
UnsafeHelper.memcpy(
world.layerTerrain.ptr,
world.layerTerrain.getOffset(0, yStart + yOff),
out.ptr,
out.getOffset(lenLeft, yOff),
world.layerTerrain.bytesPerBlock * lenRight
)
}
else {
UnsafeHelper.memcpy(
world.layerTerrain.ptr,
world.layerTerrain.getOffset(xStart, yStart + yOff),
out.ptr,
out.getOffset(0, yOff),
world.layerTerrain.bytesPerBlock * CALC_WIDTH
)
}
}
/**
* @param tilemap a portion copy of the tilemap from the world, centred to the explosive
* @param tx tilewise centre-x of the explosive
* @param ty tilewise centre-y of the explosive
* @param outWorld world object to write the result to
*/
private fun createExplosionWorker(tilemap: BlockLayerI16, tx: Int, ty: Int, power: Float, outWorld: GameWorld): Thread {
return Thread {
// simulate explosion like lightmaprenderer
// write to the world
// dispose of the tilemap copy
tilemap.tryDispose()
}
}
}

View File

@@ -1116,7 +1116,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
Point2iMod(pcx - 2, pcy + 1), Point2iMod(pcx - 1, pcy + 1), Point2iMod(pcx, pcy + 1), Point2iMod(pcx + 1, pcy + 1), Point2iMod(pcx + 2, pcy + 1), Point2iMod(pcx - 2, pcy + 1), Point2iMod(pcx - 1, pcy + 1), Point2iMod(pcx, pcy + 1), Point2iMod(pcx + 1, pcy + 1), Point2iMod(pcx + 2, pcy + 1),
Point2iMod(pcx - 1, pcy + 2), Point2iMod(pcx, pcy + 2), Point2iMod(pcx + 1, pcy + 2), Point2iMod(pcx - 1, pcy + 2), Point2iMod(pcx, pcy + 2), Point2iMod(pcx + 1, pcy + 2),
).filter { it.y in 0 until world.height }.filter { (cx, cy) -> ).filter { it.y in 0 until world.height }.filter { (cx, cy) ->
world.chunkFlags[cy][cx].and(0x7F) == 0.toByte() if (cy !in 0 until world.height / CHUNK_H) false
else (world.chunkFlags[cy][cx].and(0x7F) == 0.toByte())
}.forEach { (cx, cy) -> }.forEach { (cx, cy) ->
Worldgen.generateChunkIngame(cx, cy) { cx, cy -> Worldgen.generateChunkIngame(cx, cy) { cx, cy ->
listOf(0,1,2).forEach { layer -> listOf(0,1,2).forEach { layer ->

View File

@@ -37,6 +37,7 @@ internal object ExportMap : ConsoleCommand {
"ores@basegame:256" to Cvec(0xff00ffff.toInt()), "ores@basegame:256" to Cvec(0xff00ffff.toInt()),
"ores@basegame:257" to Cvec(0xee77ffff.toInt()), "ores@basegame:257" to Cvec(0xee77ffff.toInt()),
"ores@basegame:258" to Cvec(0xffffffff.toInt()), "ores@basegame:258" to Cvec(0xffffffff.toInt()),
"ores@basegame:259" to Cvec(0xdbd6a1ff.toInt()),
) )
private val WALL_OVERLAY = Cvec(0.35f, 0.35f, 0.35f, 1f) private val WALL_OVERLAY = Cvec(0.35f, 0.35f, 0.35f, 1f)

View File

@@ -0,0 +1,44 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.Second
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.modulebasegame.ExplosionManager
import org.dyn4j.geometry.Vector2
/**
* Created by minjaesong on 2024-02-13.
*/
open class ActorPrimedBomb : ActorWithBody {
protected constructor() {
renderOrder = RenderOrder.MIDTOP
}
private var explosionPower: Float = 1f
private var fuse: Second = 1f
constructor(
initialPos: Vector2,
initialVelo: Vector2,
power: Float,
fuse: Second
) {
renderOrder = RenderOrder.MIDTOP
this.explosionPower = power
this.fuse = fuse
}
override fun updateImpl(delta: Float) {
super.updateImpl(delta)
fuse -= delta
if (fuse <= 0f) {
physProp.usePhysics = false
ExplosionManager.goBoom(INGAME.world, intTilewiseHitbox.centeredX.toInt(), intTilewiseHitbox.centeredY.toInt(), explosionPower)
flagDespawn()
}
}
}

View File

@@ -169,6 +169,11 @@ class ItemRockSalt(originalID: ItemID) : OreItemBase(originalID, true) {
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(10,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(10,6)
} }
class ItemNitre(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_NITRE"
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(15,6)
}
class ItemCoalCoke(originalID: ItemID) : OreItemBase(originalID) { class ItemCoalCoke(originalID: ItemID) : OreItemBase(originalID) {

View File

@@ -70,7 +70,12 @@ internal class UIInventoryCells(
// tooltip // tooltip
if (Terrarum.mouseScreenX.toFloat() in encumbBarXPos..encumbBarXPos+UIInventoryCells.weightBarWidth && Terrarum.mouseScreenY.toFloat() in encumbBarYPos..encumbBarYPos+UIInventoryFull.controlHelpHeight - 6f) { if (Terrarum.mouseScreenX.toFloat() in encumbBarXPos..encumbBarXPos+UIInventoryCells.weightBarWidth && Terrarum.mouseScreenY.toFloat() in encumbBarYPos..encumbBarYPos+UIInventoryFull.controlHelpHeight - 6f) {
INGAME.setTooltipMessage("${actorInventory.capacity}/${actorInventory.maxCapacity}") val capaStr = if (actorInventory.capacity >= 1125899906842624.0) /* 2^50 */
"${actorInventory.capacity}"
else
"${(actorInventory.capacity * 100L).toLong() / 100.0}"
INGAME.setTooltipMessage("$capaStr/${actorInventory.maxCapacity}.0")
tooltipShowing[10001] = true tooltipShowing[10001] = true
} }
else { else {

View File

@@ -58,7 +58,10 @@ class Oregen(world: GameWorld, isFinal: Boolean, private val caveAttenuateBiasSc
noiseValues.zip(oreTiles).firstNotNullOfOrNull { (n, tile) -> if (n > 0.5) tile else null } noiseValues.zip(oreTiles).firstNotNullOfOrNull { (n, tile) -> if (n > 0.5) tile else null }
val backingTile = world.getTileFromTerrain(x, y) val backingTile = world.getTileFromTerrain(x, y)
if (tileToPut != null && BlockCodex[backingTile].hasAllTagOf("ROCK", "OREBEARING")) { val blockTagNonGrata = ores.firstOrNull { it.tile == tileToPut }?.blockTagNonGrata ?: hashSetOf()
val backingTileProp = BlockCodex[backingTile]
if (tileToPut != null && backingTileProp.hasAllTagOf("ROCK", "OREBEARING") && backingTileProp.hasNoTag(blockTagNonGrata)) {
// actually put the ore block // actually put the ore block
world.setTileOre(x, y, tileToPut, 0) // autotiling will be handled by the other worldgen process world.setTileOre(x, y, tileToPut, 0) // autotiling will be handled by the other worldgen process
} }
@@ -153,4 +156,5 @@ data class OregenParams(
val scale: Double, // also adjust this if you've touched the bias value. Number can be greater than 1.0 val scale: Double, // also adjust this if you've touched the bias value. Number can be greater than 1.0
val ratio: Double, // how stretched the ore veins are. >1.0 = stretched horizontally, <1.0 = stretched vertically val ratio: Double, // how stretched the ore veins are. >1.0 = stretched horizontally, <1.0 = stretched vertically
val tiling: String, // a16, a47, r16, r8 val tiling: String, // a16, a47, r16, r8
val blockTagNonGrata: HashSet<String>,
) )

View File

@@ -343,9 +343,10 @@ internal object TerragenTest : NoiseMaker {
private val QUARTZ = 0//x55ff33ff.toInt() private val QUARTZ = 0//x55ff33ff.toInt()
private val AMETHYST = 0//xee77ffff.toInt() private val AMETHYST = 0//xee77ffff.toInt()
private val ROCKSALT = 0xff00ffff.toInt() private val ROCKSALT = 0xff00ffff.toInt()
private val NITRE = 0xdbd6a1ff.toInt()
private val oreCols = listOf( private val oreCols = listOf(
COPPER_ORE, IRON_ORE, COAL_ORE, ZINC_ORE, TIN_ORE, GOLD_ORE, SILVER_ORE, LEAD_ORE, ROCKSALT, QUARTZ, AMETHYST COPPER_ORE, IRON_ORE, COAL_ORE, ZINC_ORE, TIN_ORE, GOLD_ORE, SILVER_ORE, LEAD_ORE, ROCKSALT, QUARTZ, AMETHYST, NITRE
) )
private val terragenYscaling = (NOISEBOX_HEIGHT / 2400.0).pow(0.75) private val terragenYscaling = (NOISEBOX_HEIGHT / 2400.0).pow(0.75)
@@ -693,6 +694,7 @@ internal object TerragenTest : NoiseMaker {
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:256", 0.010, -0.366, 0.528, 2.4)), Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:256", 0.010, -0.366, 0.528, 2.4)),
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:257", 0.007, 0.100, 0.494, 1.0)), Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:257", 0.007, 0.100, 0.494, 1.0)),
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:258", 0.019, 0.015, 0.509, 1.0)), Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:258", 0.019, 0.015, 0.509, 1.0)),
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:259", 0.010, -0.166, 0.517, 1.4)),
Joise(generateRockLayer(groundScalingCached, seed, params, (0..7).map { Joise(generateRockLayer(groundScalingCached, seed, params, (0..7).map {
thicknesses[it] + marblerng.nextTriangularBal() * 0.006 to (2.6 * terragenYscaling) + it * 0.18 + marblerng.nextTriangularBal() * 0.09 thicknesses[it] + marblerng.nextTriangularBal() * 0.006 to (2.6 * terragenYscaling) + it * 0.18 + marblerng.nextTriangularBal() * 0.09

Binary file not shown.