limitedly successful attempt to create a title screen

This commit is contained in:
minjaesong
2017-07-20 00:36:41 +09:00
parent 3a1379e376
commit 15dbd16766
34 changed files with 1168 additions and 410 deletions

View File

@@ -2,7 +2,6 @@
package net.torvald.terrarum.gameworld
import com.badlogic.gdx.graphics.Color
import net.torvald.dataclass.Float16
import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.blockproperties.BlockCodex
import org.dyn4j.geometry.Vector2
@@ -23,8 +22,10 @@ class GameWorld(val width: Int, val height: Int) {
val layerThermal: MapLayerFloat // in Kelvins
val spawnX: Int
val spawnY: Int
/** Tilewise spawn point */
var spawnX: Int
/** Tilewise spawn point */
var spawnY: Int
val wallDamages = HashMap<BlockAddress, BlockDamage>()
val terrainDamages = HashMap<BlockAddress, BlockDamage>()
@@ -73,7 +74,7 @@ class GameWorld(val width: Int, val height: Int) {
* @return byte[][] terrain layer
*/
val terrainArray: Array<ByteArray>
val terrainArray: ByteArray
get() = layerTerrain.data
/**
@@ -81,7 +82,7 @@ class GameWorld(val width: Int, val height: Int) {
* @return byte[][] wall layer
*/
val wallArray: Array<ByteArray>
val wallArray: ByteArray
get() = layerWall.data
/**
@@ -89,7 +90,7 @@ class GameWorld(val width: Int, val height: Int) {
* @return byte[][] wire layer
*/
val wireArray: Array<ByteArray>
val wireArray: ByteArray
get() = layerWire.data
/**
@@ -97,8 +98,8 @@ class GameWorld(val width: Int, val height: Int) {
* Format: 0baaaabbbb, aaaa for x = 0, 2, 4, ..., bbbb for x = 1, 3, 5, ...
* @return byte[][] damage code pair
*/
val damageDataArray: Array<ByteArray>
get() = layerTerrainLowBits.dataPair
val damageDataArray: ByteArray
get() = layerTerrainLowBits.data
fun getTileFromWall(x: Int, y: Int): Int? {
val wall: Int? = layerWall.getTile(x fmod width, y)
@@ -167,7 +168,7 @@ class GameWorld(val width: Int, val height: Int) {
}
fun setTileWire(x: Int, y: Int, tile: Byte) {
layerWire.data[y][x fmod width] = tile
layerWire.setTile(x fmod width, y, tile)
}
fun getTileFrom(mode: Int, x: Int, y: Int): Int? {

View File

@@ -1,14 +1,16 @@
package net.torvald.terrarum.gameworld
import net.torvald.terrarum.virtualcomputer.tvd.ByteArray64
/**
* Created by minjaesong on 16-01-17.
*/
class MapLayer(val width: Int, val height: Int) : Iterable<Byte> {
internal @Volatile var data: Array<ByteArray> // in parallel programming: do not trust your register; always read freshly from RAM!
internal @Volatile var data: ByteArray // in parallel programming: do not trust your register; always read freshly from RAM!
init {
data = Array(height) { ByteArray(width) }
data = ByteArray(width * height)
}
/**
@@ -31,7 +33,7 @@ class MapLayer(val width: Int, val height: Int) : Iterable<Byte> {
// advance counter
iteratorCount += 1
return data[y][x]
return data[y * width + x]
}
}
}
@@ -40,11 +42,11 @@ class MapLayer(val width: Int, val height: Int) : Iterable<Byte> {
return if (x !in 0..width - 1 || y !in 0..height - 1)
null
else
data[y][x].toUint()
data[y * width + x].toUint()
}
internal fun setTile(x: Int, y: Int, tile: Byte) {
data[y][x] = tile
data[y * width + x] = tile
}
fun isInBound(x: Int, y: Int) = (x >= 0 && y >= 0 && x < width && y < height)

View File

@@ -1,9 +1,5 @@
package net.torvald.terrarum.gameworld
import java.io.Serializable
import java.util.Spliterator
import java.util.function.Consumer
/**
* Created by minjaesong on 16-02-15.
*/
@@ -17,14 +13,14 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
* 0110 1101 is interpreted as
* 6 for tile 0, 13 for tile 1.
*/
internal @Volatile var dataPair: Array<ByteArray>
internal @Volatile var data: ByteArray
val width: Int
init {
this.width = width / 2
dataPair = Array(height) { ByteArray(width / 2) }
data = ByteArray(width * height / 2)
}
/**
@@ -48,7 +44,7 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
// advance counter
iteratorCount += 1
return dataPair[y][x]
return data[y * width + x]
}
}
}
@@ -59,10 +55,10 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
else {
if (x and 0x1 == 0)
// higher four bits for i = 0, 2, 4, ...
(java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0xF0) ushr 4
(java.lang.Byte.toUnsignedInt(data[y * width + x / 2]) and 0xF0) ushr 4
else
// lower four bits for i = 1, 3, 5, ...
java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0x0F
java.lang.Byte.toUnsignedInt(data[y * width + x / 2]) and 0x0F
}
}
@@ -70,12 +66,12 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
if (data < 0 || data >= 16) throw IllegalArgumentException("[PairedMapLayer] $data: invalid data value.")
if (x and 0x1 == 0)
// higher four bits for i = 0, 2, 4, ...
dataPair[y][x / 2] =
(java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0x0F
this.data[y * width + x / 2] =
(java.lang.Byte.toUnsignedInt(this.data[y * width + x / 2]) and 0x0F
or (data and 0xF shl 4)).toByte()
else
// lower four bits for i = 1, 3, 5, ...
dataPair[y][x / 2] = (java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0xF0
this.data[y * width + x / 2] = (java.lang.Byte.toUnsignedInt(this.data[y * width + x / 2]) and 0xF0
or (data and 0xF)).toByte()
}