mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
new map data format and its read/writer
!! UNTESTED !! UNTESTED !! UNTESTED !!
This commit is contained in:
@@ -20,8 +20,8 @@ open class GameWorld(val width: Int, val height: Int) {
|
||||
val layerWallLowBits: PairedMapLayer
|
||||
val layerTerrainLowBits: PairedMapLayer
|
||||
|
||||
val layerThermal: MapLayerHalfFloat // in Kelvins
|
||||
val layerAirPressure: MapLayerHalfFloat // (milibar - 1000)
|
||||
//val layerThermal: MapLayerHalfFloat // in Kelvins
|
||||
//val layerAirPressure: MapLayerHalfFloat // (milibar - 1000)
|
||||
|
||||
/** Tilewise spawn point */
|
||||
var spawnX: Int
|
||||
@@ -57,10 +57,10 @@ open class GameWorld(val width: Int, val height: Int) {
|
||||
layerWallLowBits = PairedMapLayer(width, height)
|
||||
|
||||
// temperature layer: 2x2 is one cell
|
||||
layerThermal = MapLayerHalfFloat(width / 2, height / 2, averageTemperature)
|
||||
//layerThermal = MapLayerHalfFloat(width / 2, height / 2, averageTemperature)
|
||||
|
||||
// air pressure layer: 4 * 8 is one cell
|
||||
layerAirPressure = MapLayerHalfFloat(width / 4, height / 8, 13f) // 1013 mBar
|
||||
//layerAirPressure = MapLayerHalfFloat(width / 4, height / 8, 13f) // 1013 mBar
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,11 +282,13 @@ open class GameWorld(val width: Int, val height: Int) {
|
||||
|
||||
|
||||
fun getTemperature(worldTileX: Int, worldTileY: Int): Float? {
|
||||
return layerThermal.getValue((worldTileX fmod width) / 2, worldTileY / 2)
|
||||
return null
|
||||
//return layerThermal.getValue((worldTileX fmod width) / 2, worldTileY / 2)
|
||||
}
|
||||
|
||||
fun getAirPressure(worldTileX: Int, worldTileY: Int): Float? {
|
||||
return layerAirPressure.getValue((worldTileX fmod width) / 4, worldTileY / 8)
|
||||
return null
|
||||
//return layerAirPressure.getValue((worldTileX fmod width) / 4, worldTileY / 8)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,14 +3,23 @@ package net.torvald.terrarum.gameworld
|
||||
/**
|
||||
* Created by minjaesong on 2016-01-17.
|
||||
*/
|
||||
open class MapLayer(val width: Int, val height: Int) : Iterable<Byte> {
|
||||
open class MapLayer : Iterable<Byte> {
|
||||
|
||||
val width: Int; val height: Int
|
||||
internal @Volatile var data: ByteArray // in parallel programming: do not trust your register; always read freshly from RAM!
|
||||
|
||||
init {
|
||||
constructor(width: Int, height: Int) {
|
||||
this.width = width
|
||||
this.height = height
|
||||
data = ByteArray(width * height)
|
||||
}
|
||||
|
||||
constructor(width: Int, height: Int, data: ByteArray) {
|
||||
this.data = data
|
||||
this.width = width
|
||||
this.height = height
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over elements of type `T`.
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@ package net.torvald.terrarum.gameworld
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-15.
|
||||
*/
|
||||
open class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
|
||||
open class PairedMapLayer : Iterable<Byte> {
|
||||
|
||||
val width: Int; val height: Int
|
||||
|
||||
|
||||
/**
|
||||
* 0b_xxxx_yyyy, x for lower index, y for higher index
|
||||
@@ -15,14 +18,19 @@ open class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
|
||||
*/
|
||||
internal @Volatile var data: ByteArray
|
||||
|
||||
val width: Int
|
||||
|
||||
init {
|
||||
constructor(width: Int, height: Int) {
|
||||
this.width = width / 2
|
||||
|
||||
this.height = height
|
||||
data = ByteArray(width * height / 2)
|
||||
}
|
||||
|
||||
constructor(width: Int, height: Int, data: ByteArray) {
|
||||
this.data = data
|
||||
this.width = width / 2
|
||||
this.height = height
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an iterator over elements of type `T`.
|
||||
* Note: this iterator will return combined damage, that is 0bxxxx_yyyy as whole.
|
||||
|
||||
Reference in New Issue
Block a user