mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
limitedly successful attempt to create a title screen
This commit is contained in:
@@ -27,7 +27,9 @@ import java.util.zip.GZIPInputStream
|
||||
* Created by minjaesong on 16-01-19.
|
||||
*/
|
||||
object BlocksDrawer {
|
||||
private inline val world: GameWorld; get() = Terrarum.ingame!!.world
|
||||
lateinit var world: GameWorld
|
||||
|
||||
|
||||
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
|
||||
|
||||
|
||||
@@ -8,11 +8,14 @@ import net.torvald.colourutil.ColourTemp
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blendMul
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
object FeaturesDrawer {
|
||||
lateinit var world: GameWorld
|
||||
|
||||
const val TILE_SIZE = 16
|
||||
|
||||
private val ENV_COLTEMP_LOWEST = 5500
|
||||
@@ -36,9 +39,6 @@ object FeaturesDrawer {
|
||||
fun update(delta: Float) {
|
||||
}
|
||||
|
||||
fun render(batch: SpriteBatch) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A colour filter used to provide effect that makes whole screen look warmer/cooler,
|
||||
* usually targeted for the environmental temperature (desert/winterland), hence the name.
|
||||
@@ -52,7 +52,7 @@ object FeaturesDrawer {
|
||||
val colTemp_cold = colTempLinearFunc(onscreen_cold_tiles / onscreen_tiles_cap)
|
||||
val colTemp_warm = colTempLinearFunc(-(onscreen_warm_tiles / onscreen_tiles_cap))
|
||||
colTemp = colTemp_warm + colTemp_cold - ENV_COLTEMP_NOON
|
||||
val zoom = Terrarum.ingame!!.screenZoom
|
||||
val zoom = Terrarum.ingame?.screenZoom ?: 1f
|
||||
|
||||
blendMul()
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.*
|
||||
// NOTE: no Float16 on this thing: 67 kB of memory footage is totally acceptable
|
||||
|
||||
object LightmapRenderer {
|
||||
private val world: GameWorld = Terrarum.ingame!!.world
|
||||
lateinit var world: GameWorld
|
||||
|
||||
|
||||
// TODO if (VBO works on BlocksDrawer) THEN overscan of 256, utilise same technique in here
|
||||
@@ -38,9 +38,9 @@ object LightmapRenderer {
|
||||
|
||||
// TODO resize(int, int) -aware
|
||||
|
||||
val LIGHTMAP_WIDTH = Terrarum.ingame!!.ZOOM_MINIMUM.inv().times(Terrarum.WIDTH)
|
||||
val LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.WIDTH)
|
||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
val LIGHTMAP_HEIGHT = Terrarum.ingame!!.ZOOM_MINIMUM.inv().times(Terrarum.HEIGHT)
|
||||
val LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(Terrarum.HEIGHT)
|
||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ object LightmapRenderer {
|
||||
*/
|
||||
// TODO utilise alpha channel to determine brightness of "glow" sprites (so that alpha channel works like UV light)
|
||||
private val lightmap: Array<Array<Color>> = Array(LIGHTMAP_HEIGHT) { Array(LIGHTMAP_WIDTH, { Color(0f,0f,0f,0f) }) } // TODO framebuffer?
|
||||
private val lanternMap = ArrayList<Lantern>(Terrarum.ingame!!.ACTORCONTAINER_INITIAL_SIZE * 4)
|
||||
private val lanternMap = ArrayList<Lantern>((Terrarum.ingame?.ACTORCONTAINER_INITIAL_SIZE ?: 2) * 4)
|
||||
|
||||
private val AIR = Block.AIR
|
||||
|
||||
@@ -178,7 +178,7 @@ object LightmapRenderer {
|
||||
// build noop map
|
||||
for (i in 0..rect_size) {
|
||||
val point = edgeToMaskNum(i)
|
||||
val tile = Terrarum.ingame!!.world.getTileFromTerrain(point.first, point.second) ?: Block.NULL
|
||||
val tile = world.getTileFromTerrain(point.first, point.second) ?: Block.NULL
|
||||
val isSolid = BlockCodex[tile].isSolid
|
||||
|
||||
noop_mask.set(i, isSolid)
|
||||
@@ -235,25 +235,27 @@ object LightmapRenderer {
|
||||
|
||||
private fun buildLanternmap() {
|
||||
lanternMap.clear()
|
||||
Terrarum.ingame!!.actorContainer.forEach { it ->
|
||||
if (it is Luminous && it is ActorWithPhysics) {
|
||||
// put lanterns to the area the luminantBox is occupying
|
||||
for (lightBox in it.lightBoxList) {
|
||||
val lightBoxX = it.hitbox.startX + lightBox.startX
|
||||
val lightBoxY = it.hitbox.startY + lightBox.startY
|
||||
val lightBoxW = lightBox.width
|
||||
val lightBoxH = lightBox.height
|
||||
for (y in lightBoxY.div(TILE_SIZE).floorInt()
|
||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
|
||||
for (x in lightBoxX.div(TILE_SIZE).floorInt()
|
||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
|
||||
Terrarum.ingame?.let {
|
||||
it.actorContainer.forEach { it ->
|
||||
if (it is Luminous && it is ActorWithPhysics) {
|
||||
// put lanterns to the area the luminantBox is occupying
|
||||
for (lightBox in it.lightBoxList) {
|
||||
val lightBoxX = it.hitbox.startX + lightBox.startX
|
||||
val lightBoxY = it.hitbox.startY + lightBox.startY
|
||||
val lightBoxW = lightBox.width
|
||||
val lightBoxH = lightBox.height
|
||||
for (y in lightBoxY.div(TILE_SIZE).floorInt()
|
||||
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
|
||||
for (x in lightBoxX.div(TILE_SIZE).floorInt()
|
||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
|
||||
|
||||
val normalisedColor = it.color.cpy().mul(DIV_FLOAT)
|
||||
val normalisedColor = it.color.cpy().mul(DIV_FLOAT)
|
||||
|
||||
lanternMap.add(Lantern(x, y, normalisedColor))
|
||||
// Q&D fix for Roundworld anomaly
|
||||
lanternMap.add(Lantern(x + world.width, y, normalisedColor))
|
||||
lanternMap.add(Lantern(x - world.width, y, normalisedColor))
|
||||
lanternMap.add(Lantern(x, y, normalisedColor))
|
||||
// Q&D fix for Roundworld anomaly
|
||||
lanternMap.add(Lantern(x + world.width, y, normalisedColor))
|
||||
lanternMap.add(Lantern(x - world.width, y, normalisedColor))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,11 +272,11 @@ object LightmapRenderer {
|
||||
var ambientAccumulator = Color(0f,0f,0f,0f)
|
||||
|
||||
var lightLevelThis: Color = Color(0f,0f,0f,0f)
|
||||
val thisTerrain = Terrarum.ingame!!.world.getTileFromTerrain(x, y)
|
||||
val thisWall = Terrarum.ingame!!.world.getTileFromWall(x, y)
|
||||
val thisTerrain = world.getTileFromTerrain(x, y)
|
||||
val thisWall = world.getTileFromWall(x, y)
|
||||
val thisTileLuminosity = BlockCodex[thisTerrain].luminosity // already been div by four
|
||||
val thisTileOpacity = BlockCodex[thisTerrain].opacity // already been div by four
|
||||
val sunLight = Terrarum.ingame!!.world.globalLight.cpy().mul(DIV_FLOAT)
|
||||
val sunLight = world.globalLight.cpy().mul(DIV_FLOAT)
|
||||
|
||||
// MIX TILE
|
||||
// open air
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.worlddrawer
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.floor
|
||||
import net.torvald.terrarum.gameactors.floorInt
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
@@ -12,7 +13,6 @@ import net.torvald.terrarum.round
|
||||
* Created by minjaesong on 2016-12-30.
|
||||
*/
|
||||
object WorldCamera {
|
||||
private val world: GameWorld? = Terrarum.ingame?.world
|
||||
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
|
||||
var x: Int = 0 // left position
|
||||
@@ -32,22 +32,20 @@ object WorldCamera {
|
||||
val yCentre: Int
|
||||
get() = y + height.ushr(1)
|
||||
|
||||
fun update() {
|
||||
fun update(world: GameWorld, player: ActorWithBody) {
|
||||
if (Terrarum.ingame != null) {
|
||||
|
||||
val player = Terrarum.ingame!!.player
|
||||
|
||||
width = FastMath.ceil(Terrarum.WIDTH / Terrarum.ingame!!.screenZoom) // div, not mul
|
||||
height = FastMath.ceil(Terrarum.HEIGHT / Terrarum.ingame!!.screenZoom)
|
||||
width = FastMath.ceil(Terrarum.WIDTH / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul
|
||||
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))
|
||||
|
||||
// position - (WH / 2)
|
||||
x = (// X only: ROUNDWORLD implementation
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2).floorInt()
|
||||
player.hitbox.centeredX.toFloat() - width / 2).floorInt()
|
||||
y = (FastMath.clamp(
|
||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
|
||||
player.hitbox.centeredY.toFloat() - height / 2,
|
||||
TILE_SIZE.toFloat(),
|
||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
)).floorInt().clampCameraY()
|
||||
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
)).floorInt().clampCameraY(world)
|
||||
|
||||
|
||||
gdxCamX = x + (width / 2f).floor()
|
||||
@@ -55,11 +53,11 @@ object WorldCamera {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.clampCameraY(): Int {
|
||||
private fun Int.clampCameraY(world: GameWorld): Int {
|
||||
return if (this < 0)
|
||||
0
|
||||
else if (this > (world?.height ?: Terrarum.HEIGHT).times(TILE_SIZE) - Terrarum.HEIGHT)
|
||||
(world?.height ?: Terrarum.HEIGHT).times(TILE_SIZE) - Terrarum.HEIGHT
|
||||
else if (this > world.height.times(TILE_SIZE) - Terrarum.HEIGHT)
|
||||
world.height.times(TILE_SIZE) - Terrarum.HEIGHT
|
||||
else
|
||||
this
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user