mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
separated Camera from TileDrawer (was MapCamera)
Former-commit-id: b2fe7716722634b03f3750fade420d26022500f9 Former-commit-id: 521826d176c6902007646e6b9b9c7b5d4f3468cf
This commit is contained in:
@@ -17,9 +17,10 @@ import net.torvald.terrarum.gameworld.WorldSimulator
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer.constructRGBFromInt
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.mapgenerator.WorldGenerator
|
||||
import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
@@ -199,8 +200,9 @@ constructor() : BasicGameState() {
|
||||
////////////////////////////
|
||||
// camera-related updates //
|
||||
////////////////////////////
|
||||
MapDrawer.update(gc, delta)
|
||||
MapCamera.update(gc, delta)
|
||||
FeaturesDrawer.update(gc, delta)
|
||||
MapCamera.update()
|
||||
TilesDrawer.update()
|
||||
|
||||
|
||||
///////////////////////////
|
||||
@@ -288,14 +290,14 @@ constructor() : BasicGameState() {
|
||||
|
||||
// make camara work //
|
||||
// compensate for zoom. UIs must be treated specially! (see UIHandler)
|
||||
//g.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
|
||||
worldDrawFrameBuffer.graphics.translate(-MapCamera.cameraX.toFloat(), -MapCamera.cameraY.toFloat())
|
||||
//g.translate(-MapCamera.x * screenZoom, -MapCamera.y * screenZoom)
|
||||
worldDrawFrameBuffer.graphics.translate(-MapCamera.x.toFloat(), -MapCamera.y.toFloat())
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// draw map related stuffs //
|
||||
/////////////////////////////
|
||||
MapCamera.renderBehind(gc, worldDrawFrameBuffer.graphics)
|
||||
TilesDrawer.renderBehind(gc, worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
/////////////////
|
||||
@@ -316,14 +318,14 @@ constructor() : BasicGameState() {
|
||||
/////////////////////////////
|
||||
LightmapRenderer.renderLightMap()
|
||||
|
||||
// --> blendMul() <-- by MapCamera.renderFront
|
||||
MapCamera.renderFront(gc, worldDrawFrameBuffer.graphics)
|
||||
// --> blendNormal() <-- by MapCamera.renderFront
|
||||
MapDrawer.render(gc, worldDrawFrameBuffer.graphics)
|
||||
// --> blendMul() <-- by TilesDrawer.renderFront
|
||||
TilesDrawer.renderFront(gc, worldDrawFrameBuffer.graphics)
|
||||
// --> blendNormal() <-- by TilesDrawer.renderFront
|
||||
FeaturesDrawer.render(gc, worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
// --> blendMul() <-- by MapCamera.drawEnvOverlay
|
||||
MapDrawer.drawEnvOverlay(worldDrawFrameBuffer.graphics)
|
||||
// --> blendMul() <-- by TilesDrawer.drawEnvOverlay
|
||||
FeaturesDrawer.drawEnvOverlay(worldDrawFrameBuffer.graphics)
|
||||
|
||||
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul()
|
||||
else blendNormal()
|
||||
@@ -558,12 +560,12 @@ constructor() : BasicGameState() {
|
||||
)
|
||||
private fun distToCameraSqr(a: ActorWithBody) =
|
||||
min(
|
||||
(a.hitbox.posX - MapCamera.cameraX).sqr() +
|
||||
(a.hitbox.posY - MapCamera.cameraY).sqr(),
|
||||
(a.hitbox.posX - MapCamera.cameraX + world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.posY - MapCamera.cameraY).sqr(),
|
||||
(a.hitbox.posX - MapCamera.cameraX - world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.posY - MapCamera.cameraY).sqr()
|
||||
(a.hitbox.posX - MapCamera.x).sqr() +
|
||||
(a.hitbox.posY - MapCamera.y).sqr(),
|
||||
(a.hitbox.posX - MapCamera.x + world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.posY - MapCamera.y).sqr(),
|
||||
(a.hitbox.posX - MapCamera.x - world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.posY - MapCamera.y).sqr()
|
||||
)
|
||||
|
||||
/** whether the actor is within screen */
|
||||
|
||||
@@ -3,8 +3,9 @@ package net.torvald.terrarum.console
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.PhysTestBall
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-05.
|
||||
@@ -20,8 +21,8 @@ internal object SpawnPhysTestBall : ConsoleCommand {
|
||||
|
||||
val ball = PhysTestBall()
|
||||
ball.setPosition(
|
||||
(mouseX + MapCamera.cameraX).toDouble(),
|
||||
(mouseY + MapCamera.cameraY).toDouble()
|
||||
(mouseX + MapCamera.x).toDouble(),
|
||||
(mouseY + MapCamera.y).toDouble()
|
||||
)
|
||||
ball.elasticity = elasticity
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.terrarum.StateInGame
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
|
||||
@@ -16,8 +16,8 @@ internal object Teleport : ConsoleCommand {
|
||||
val x: Int
|
||||
val y: Int
|
||||
try {
|
||||
x = args[1].toInt() * MapDrawer.TILE_SIZE + MapDrawer.TILE_SIZE / 2
|
||||
y = args[2].toInt() * MapDrawer.TILE_SIZE + MapDrawer.TILE_SIZE / 2
|
||||
x = args[1].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
|
||||
y = args[2].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
EchoError("Teleport: wrong number input.")
|
||||
@@ -76,8 +76,8 @@ internal object Teleport : ConsoleCommand {
|
||||
val x: Int
|
||||
val y: Int
|
||||
try {
|
||||
x = args[3].toInt() * MapDrawer.TILE_SIZE + MapDrawer.TILE_SIZE / 2
|
||||
y = args[4].toInt() * MapDrawer.TILE_SIZE + MapDrawer.TILE_SIZE / 2
|
||||
x = args[3].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
|
||||
y = args[4].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
|
||||
val actorID = args[1].toInt()
|
||||
|
||||
if (Terrarum.ingame.getActorByID(actorID) !is ActorWithBody) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.ActorValue
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Color
|
||||
import java.awt.Dimension
|
||||
@@ -177,8 +177,8 @@ class ActorValueTracker constructor() : JFrame() {
|
||||
|
||||
if (actor != null) {
|
||||
sb.append("toString: ${actor!!}\n")
|
||||
sb.append("X: ${actor!!.hitbox.pointedX} (${(actor!!.hitbox.pointedX / MapDrawer.TILE_SIZE).toInt()})\n")
|
||||
sb.append("Y: ${actor!!.hitbox.pointedY} (${(actor!!.hitbox.pointedY / MapDrawer.TILE_SIZE).toInt()})")
|
||||
sb.append("X: ${actor!!.hitbox.pointedX} (${(actor!!.hitbox.pointedX / FeaturesDrawer.TILE_SIZE).toInt()})\n")
|
||||
sb.append("Y: ${actor!!.hitbox.pointedY} (${(actor!!.hitbox.pointedY / FeaturesDrawer.TILE_SIZE).toInt()})")
|
||||
|
||||
avPosArea.text = "$sb"
|
||||
sb.setLength(0) // clear stringbuffer
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
import net.torvald.spriteanimation.SpriteAnimation
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.tileproperties.TileProp
|
||||
import org.dyn4j.Epsilon
|
||||
@@ -1117,7 +1117,7 @@ open class ActorWithBody : Actor() {
|
||||
@Transient const val BLEND_SCREEN = 5
|
||||
@Transient const val BLEND_MULTIPLY = 6
|
||||
|
||||
@Transient private val TILE_SIZE = MapDrawer.TILE_SIZE
|
||||
@Transient private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
|
||||
private fun div16TruncateToMapWidth(x: Int): Int {
|
||||
if (x < 0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.gameactors.faction.Faction
|
||||
import net.torvald.terrarum.gamecontroller.EnumKeyFunc
|
||||
import net.torvald.terrarum.gamecontroller.KeyMap
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.ui.UIQuickBar
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.torvald.terrarum.gameactors
|
||||
import net.torvald.spriteanimation.SpriteAnimation
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.ai.scripts.PokemonNPCAI
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-25.
|
||||
@@ -26,7 +26,7 @@ object PlayerBuilderCynthia {
|
||||
|
||||
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT) ?: ActorHumanoid.BASE_HEIGHT, 9, 0)
|
||||
|
||||
p.setPosition(4096.0 * MapDrawer.TILE_SIZE, 300.0 * MapDrawer.TILE_SIZE)
|
||||
p.setPosition(4096.0 * FeaturesDrawer.TILE_SIZE, 300.0 * FeaturesDrawer.TILE_SIZE)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.faction.FactionFactory
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.to10bit
|
||||
import net.torvald.terrarum.toInt
|
||||
import org.newdawn.slick.Color
|
||||
@@ -70,7 +70,7 @@ object PlayerBuilderSigrid {
|
||||
|
||||
p.inventory = ActorInventory(0x7FFFFFFF, true)
|
||||
|
||||
p.setPosition((4096 * MapDrawer.TILE_SIZE).toDouble(), (300 * 16).toDouble())
|
||||
p.setPosition((4096 * FeaturesDrawer.TILE_SIZE).toDouble(), (300 * 16).toDouble())
|
||||
|
||||
p.faction.add(FactionFactory.create("FactionSigrid.json"))
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ package net.torvald.terrarum.gamecontroller
|
||||
|
||||
import net.torvald.terrarum.gameactors.Controllable
|
||||
import net.torvald.terrarum.gameactors.Player
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ProjectileSimple
|
||||
import net.torvald.terrarum.gameactors.floorInt
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
import net.torvald.terrarum.ui.UIHandler
|
||||
@@ -24,16 +25,16 @@ object GameController {
|
||||
|
||||
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
|
||||
internal val mouseX: Float
|
||||
get() = (MapCamera.cameraX + Terrarum.appgc.input.mouseX / Terrarum.ingame.screenZoom)
|
||||
get() = (MapCamera.x + Terrarum.appgc.input.mouseX / Terrarum.ingame.screenZoom)
|
||||
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise)*/
|
||||
internal val mouseY: Float
|
||||
get() = (MapCamera.cameraY + Terrarum.appgc.input.mouseY / Terrarum.ingame.screenZoom)
|
||||
get() = (MapCamera.y + Terrarum.appgc.input.mouseY / Terrarum.ingame.screenZoom)
|
||||
/** currently pointing tile coordinate */
|
||||
internal val mouseTileX: Int
|
||||
get() = (mouseX / MapDrawer.TILE_SIZE).floorInt()
|
||||
get() = (mouseX / FeaturesDrawer.TILE_SIZE).floorInt()
|
||||
/** currently pointing tile coordinate */
|
||||
internal val mouseTileY: Int
|
||||
get() = (mouseY / MapDrawer.TILE_SIZE).floorInt()
|
||||
get() = (mouseY / FeaturesDrawer.TILE_SIZE).floorInt()
|
||||
|
||||
fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import net.torvald.terrarum.gameactors.HistoricalFigure
|
||||
import net.torvald.terrarum.gameactors.Player
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gameworld.WorldSimulator.isSolid
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
import org.newdawn.slick.Color
|
||||
@@ -40,8 +40,8 @@ object WorldSimulator {
|
||||
|
||||
// TODO future Kotlin feature -- typealias AnyPlayer: HistoricalFigure
|
||||
operator fun invoke(world: GameWorld, p: HistoricalFigure, delta: Int) {
|
||||
updateXFrom = p.hitbox.centeredX.div(MapDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt()
|
||||
updateYFrom = p.hitbox.centeredY.div(MapDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt()
|
||||
updateXFrom = p.hitbox.centeredX.div(FeaturesDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt()
|
||||
updateYFrom = p.hitbox.centeredY.div(FeaturesDrawer.TILE_SIZE).minus(FLUID_UPDATING_SQUARE_RADIUS).roundInt()
|
||||
updateXTo = updateXFrom + DOUBLE_RADIUS
|
||||
updateYTo = updateYFrom + DOUBLE_RADIUS
|
||||
|
||||
@@ -155,16 +155,16 @@ object WorldSimulator {
|
||||
for (y in 0..fluidMap.size - 1) {
|
||||
for (x in 0..fluidMap[0].size - 1) {
|
||||
val data = fluidMap[y][x]
|
||||
if (MapCamera.tileInCamera(x + updateXFrom, y + updateYFrom)) {
|
||||
if (TilesDrawer.tileInCamera(x + updateXFrom, y + updateYFrom)) {
|
||||
if (data == 0)
|
||||
g.color = colourNone
|
||||
else
|
||||
g.color = colourWater
|
||||
|
||||
g.drawString(data.toString(),
|
||||
updateXFrom.plus(x).times(MapDrawer.TILE_SIZE).toFloat()
|
||||
updateXFrom.plus(x).times(FeaturesDrawer.TILE_SIZE).toFloat()
|
||||
+ if (data < 10) 4f else 0f,
|
||||
updateYFrom.plus(y).times(MapDrawer.TILE_SIZE) + 4f
|
||||
updateYFrom.plus(y).times(FeaturesDrawer.TILE_SIZE) + 4f
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.newdawn.slick.*
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
object MapDrawer {
|
||||
object FeaturesDrawer {
|
||||
const val TILE_SIZE = 16
|
||||
|
||||
private val ENV_COLTEMP_LOWEST = 5500
|
||||
@@ -55,8 +55,8 @@ object MapDrawer {
|
||||
g.color = ColourTemp(colTemp)
|
||||
//g.color = getColourFromMap(3022)
|
||||
g.fillRect(
|
||||
MapCamera.cameraX * zoom,
|
||||
MapCamera.cameraY * zoom,
|
||||
MapCamera.x * zoom,
|
||||
MapCamera.y * zoom,
|
||||
Terrarum.WIDTH * if (zoom < 1) 1f / zoom else zoom,
|
||||
Terrarum.HEIGHT * if (zoom < 1) 1f / zoom else zoom
|
||||
)
|
||||
@@ -7,7 +7,7 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.RGB
|
||||
import net.torvald.colourutil.CIELuvUtil.additiveLuv
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera.world
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.tileproperties.TilePropUtil
|
||||
import org.newdawn.slick.Color
|
||||
@@ -19,13 +19,15 @@ import java.util.*
|
||||
*/
|
||||
|
||||
object LightmapRenderer {
|
||||
val overscan_open: Int = Math.min(32, 256f.div(TileCodex[Tile.AIR].opacity and 0xFF).toFloat().ceil())
|
||||
val overscan_opaque: Int = Math.min(8, 256f.div(TileCodex[Tile.STONE].opacity and 0xFF).toFloat().ceil())
|
||||
private val world: GameWorld = Terrarum.ingame.world
|
||||
|
||||
val overscan_open: Int = Math.min(32, 256f.div(TileCodex[Tile.AIR].opacity and 0xFF).ceil())
|
||||
val overscan_opaque: Int = Math.min(8, 256f.div(TileCodex[Tile.STONE].opacity and 0xFF).ceil())
|
||||
|
||||
private val LIGHTMAP_WIDTH = Terrarum.ingame.ZOOM_MIN.inv().times(Terrarum.WIDTH)
|
||||
.div(MapDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
private val LIGHTMAP_HEIGHT = Terrarum.ingame.ZOOM_MIN.inv().times(Terrarum.HEIGHT)
|
||||
.div(MapDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||
|
||||
/**
|
||||
* 8-Bit RGB values
|
||||
@@ -39,7 +41,7 @@ object LightmapRenderer {
|
||||
private val OFFSET_G = 1
|
||||
private val OFFSET_B = 0
|
||||
|
||||
private const val TILE_SIZE = MapDrawer.TILE_SIZE
|
||||
private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
|
||||
// color model related constants
|
||||
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB
|
||||
@@ -80,11 +82,11 @@ object LightmapRenderer {
|
||||
}
|
||||
|
||||
fun renderLightMap() {
|
||||
for_x_start = MapCamera.cameraX / TILE_SIZE - 1 // fix for premature lightmap rendering
|
||||
for_y_start = MapCamera.cameraY / TILE_SIZE - 1 // on topmost/leftmost side
|
||||
for_x_start = MapCamera.x / TILE_SIZE - 1 // fix for premature lightmap rendering
|
||||
for_y_start = MapCamera.y / TILE_SIZE - 1 // on topmost/leftmost side
|
||||
|
||||
for_x_end = for_x_start + MapCamera.renderWidth / TILE_SIZE + 3
|
||||
for_y_end = for_y_start + MapCamera.renderHeight / TILE_SIZE + 2 // same fix as above
|
||||
for_x_end = for_x_start + MapCamera.width / TILE_SIZE + 3
|
||||
for_y_end = for_y_start + MapCamera.height / TILE_SIZE + 2 // same fix as above
|
||||
|
||||
/**
|
||||
* * true: overscanning is limited to 8 tiles in width (overscan_opaque)
|
||||
|
||||
@@ -1,534 +1,39 @@
|
||||
package net.torvald.terrarum.mapdrawer
|
||||
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.concurrent.ThreadPool
|
||||
import net.torvald.terrarum.blendMul
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer.TILE_SIZE
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.newdawn.slick.*
|
||||
import java.util.*
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-19.
|
||||
* Created by SKYHi14 on 2016-12-30.
|
||||
*/
|
||||
object MapCamera {
|
||||
val world: GameWorld = Terrarum.ingame.world
|
||||
private val world: GameWorld = Terrarum.ingame.world
|
||||
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
|
||||
var cameraX = 0
|
||||
var x = 0
|
||||
private set
|
||||
var cameraY = 0
|
||||
var y = 0
|
||||
private set
|
||||
var width: Int = 0
|
||||
private set
|
||||
var height: Int = 0
|
||||
private set
|
||||
|
||||
private val TILE_SIZE = MapDrawer.TILE_SIZE
|
||||
|
||||
var tilesWall: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wall.png", TILE_SIZE, TILE_SIZE)
|
||||
private set
|
||||
var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.tga", TILE_SIZE, TILE_SIZE)
|
||||
private set // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here.
|
||||
var tilesWire: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wire.png", TILE_SIZE, TILE_SIZE)
|
||||
private set
|
||||
var tilesetBook: Array<SpriteSheet> = arrayOf(tilesWall, tilesTerrain, tilesWire)
|
||||
private set
|
||||
|
||||
val WALL = GameWorld.WALL
|
||||
val TERRAIN = GameWorld.TERRAIN
|
||||
val WIRE = GameWorld.WIRE
|
||||
|
||||
var renderWidth: Int = 0
|
||||
private set
|
||||
var renderHeight: Int = 0
|
||||
private set
|
||||
|
||||
private val NEARBY_TILE_KEY_UP = 0
|
||||
private val NEARBY_TILE_KEY_RIGHT = 1
|
||||
private val NEARBY_TILE_KEY_DOWN = 2
|
||||
private val NEARBY_TILE_KEY_LEFT = 3
|
||||
|
||||
private val NEARBY_TILE_CODE_UP = 1
|
||||
private val NEARBY_TILE_CODE_RIGHT = 2
|
||||
private val NEARBY_TILE_CODE_DOWN = 4
|
||||
private val NEARBY_TILE_CODE_LEFT = 8
|
||||
|
||||
/**
|
||||
* Connectivity group 01 : artificial tiles
|
||||
* It holds different shading rule to discriminate with group 02, index 0 is single tile.
|
||||
* These are the tiles that only connects to itself, will not connect to colour variants
|
||||
*/
|
||||
val TILES_CONNECT_SELF = arrayOf(
|
||||
Tile.ICE_MAGICAL,
|
||||
Tile.GLASS_CRUDE,
|
||||
Tile.GLASS_CLEAN,
|
||||
Tile.ILLUMINATOR_BLACK,
|
||||
Tile.ILLUMINATOR_BLUE,
|
||||
Tile.ILLUMINATOR_BROWN,
|
||||
Tile.ILLUMINATOR_CYAN,
|
||||
Tile.ILLUMINATOR_FUCHSIA,
|
||||
Tile.ILLUMINATOR_GREEN,
|
||||
Tile.ILLUMINATOR_GREEN_DARK,
|
||||
Tile.ILLUMINATOR_GREY_DARK,
|
||||
Tile.ILLUMINATOR_GREY_LIGHT,
|
||||
Tile.ILLUMINATOR_GREY_MED,
|
||||
Tile.ILLUMINATOR_ORANGE,
|
||||
Tile.ILLUMINATOR_PURPLE,
|
||||
Tile.ILLUMINATOR_RED,
|
||||
Tile.ILLUMINATOR_TAN,
|
||||
Tile.ILLUMINATOR_WHITE,
|
||||
Tile.ILLUMINATOR_YELLOW,
|
||||
Tile.ILLUMINATOR_BLACK_OFF,
|
||||
Tile.ILLUMINATOR_BLUE_OFF,
|
||||
Tile.ILLUMINATOR_BROWN_OFF,
|
||||
Tile.ILLUMINATOR_CYAN_OFF,
|
||||
Tile.ILLUMINATOR_FUCHSIA_OFF,
|
||||
Tile.ILLUMINATOR_GREEN_OFF,
|
||||
Tile.ILLUMINATOR_GREEN_DARK_OFF,
|
||||
Tile.ILLUMINATOR_GREY_DARK_OFF,
|
||||
Tile.ILLUMINATOR_GREY_LIGHT_OFF,
|
||||
Tile.ILLUMINATOR_GREY_MED_OFF,
|
||||
Tile.ILLUMINATOR_ORANGE_OFF,
|
||||
Tile.ILLUMINATOR_PURPLE_OFF,
|
||||
Tile.ILLUMINATOR_RED_OFF,
|
||||
Tile.ILLUMINATOR_TAN_OFF,
|
||||
Tile.ILLUMINATOR_WHITE_OFF,
|
||||
Tile.ILLUMINATOR_YELLOW,
|
||||
Tile.SANDSTONE,
|
||||
Tile.SANDSTONE_BLACK,
|
||||
Tile.SANDSTONE_DESERT,
|
||||
Tile.SANDSTONE_RED,
|
||||
Tile.SANDSTONE_WHITE,
|
||||
Tile.SANDSTONE_GREEN,
|
||||
Tile.DAYLIGHT_CAPACITOR
|
||||
)
|
||||
|
||||
/**
|
||||
* Connectivity group 02 : natural tiles
|
||||
* It holds different shading rule to discriminate with group 01, index 0 is middle tile.
|
||||
*/
|
||||
val TILES_CONNECT_MUTUAL = arrayOf(
|
||||
Tile.STONE,
|
||||
Tile.STONE_QUARRIED,
|
||||
Tile.STONE_TILE_WHITE,
|
||||
Tile.STONE_BRICKS,
|
||||
Tile.DIRT,
|
||||
Tile.GRASS,
|
||||
Tile.PLANK_BIRCH,
|
||||
Tile.PLANK_BLOODROSE,
|
||||
Tile.PLANK_EBONY,
|
||||
Tile.PLANK_NORMAL,
|
||||
Tile.SAND,
|
||||
Tile.SAND_WHITE,
|
||||
Tile.SAND_RED,
|
||||
Tile.SAND_DESERT,
|
||||
Tile.SAND_BLACK,
|
||||
Tile.SAND_GREEN,
|
||||
Tile.GRAVEL,
|
||||
Tile.GRAVEL_GREY,
|
||||
Tile.SNOW,
|
||||
Tile.ICE_NATURAL,
|
||||
Tile.ORE_COPPER,
|
||||
Tile.ORE_IRON,
|
||||
Tile.ORE_GOLD,
|
||||
Tile.ORE_SILVER,
|
||||
Tile.ORE_ILMENITE,
|
||||
Tile.ORE_AURICHALCUM,
|
||||
|
||||
Tile.WATER,
|
||||
Tile.WATER_1,
|
||||
Tile.WATER_2,
|
||||
Tile.WATER_3,
|
||||
Tile.WATER_4,
|
||||
Tile.WATER_5,
|
||||
Tile.WATER_6,
|
||||
Tile.WATER_7,
|
||||
Tile.WATER_8,
|
||||
Tile.WATER_9,
|
||||
Tile.WATER_10,
|
||||
Tile.WATER_11,
|
||||
Tile.WATER_12,
|
||||
Tile.WATER_13,
|
||||
Tile.WATER_14,
|
||||
Tile.WATER_15,
|
||||
Tile.LAVA,
|
||||
Tile.LAVA_1,
|
||||
Tile.LAVA_2,
|
||||
Tile.LAVA_3,
|
||||
Tile.LAVA_4,
|
||||
Tile.LAVA_5,
|
||||
Tile.LAVA_6,
|
||||
Tile.LAVA_7,
|
||||
Tile.LAVA_8,
|
||||
Tile.LAVA_9,
|
||||
Tile.LAVA_10,
|
||||
Tile.LAVA_11,
|
||||
Tile.LAVA_12,
|
||||
Tile.LAVA_13,
|
||||
Tile.LAVA_14,
|
||||
Tile.LAVA_15
|
||||
)
|
||||
|
||||
/**
|
||||
* Torches, levers, switches, ...
|
||||
*/
|
||||
val TILES_WALL_STICKER = arrayOf(
|
||||
Tile.TORCH,
|
||||
Tile.TORCH_FROST,
|
||||
Tile.TORCH_OFF,
|
||||
Tile.TORCH_FROST_OFF
|
||||
)
|
||||
|
||||
/**
|
||||
* platforms, ...
|
||||
*/
|
||||
val TILES_WALL_STICKER_CONNECT_SELF = arrayOf(
|
||||
Tile.PLATFORM_BIRCH,
|
||||
Tile.PLATFORM_BLOODROSE,
|
||||
Tile.PLATFORM_EBONY,
|
||||
Tile.PLATFORM_STONE,
|
||||
Tile.PLATFORM_WOODEN
|
||||
)
|
||||
|
||||
/**
|
||||
* Tiles that half-transparent and has hue
|
||||
* will blend colour using colour multiplication
|
||||
* i.e. red hues get lost if you dive into the water
|
||||
*/
|
||||
val TILES_BLEND_MUL = arrayOf(
|
||||
Tile.WATER,
|
||||
Tile.WATER_1,
|
||||
Tile.WATER_2,
|
||||
Tile.WATER_3,
|
||||
Tile.WATER_4,
|
||||
Tile.WATER_5,
|
||||
Tile.WATER_6,
|
||||
Tile.WATER_7,
|
||||
Tile.WATER_8,
|
||||
Tile.WATER_9,
|
||||
Tile.WATER_10,
|
||||
Tile.WATER_11,
|
||||
Tile.WATER_12,
|
||||
Tile.WATER_13,
|
||||
Tile.WATER_14,
|
||||
Tile.WATER_15,
|
||||
Tile.LAVA,
|
||||
Tile.LAVA_1,
|
||||
Tile.LAVA_2,
|
||||
Tile.LAVA_3,
|
||||
Tile.LAVA_4,
|
||||
Tile.LAVA_5,
|
||||
Tile.LAVA_6,
|
||||
Tile.LAVA_7,
|
||||
Tile.LAVA_8,
|
||||
Tile.LAVA_9,
|
||||
Tile.LAVA_10,
|
||||
Tile.LAVA_11,
|
||||
Tile.LAVA_12,
|
||||
Tile.LAVA_13,
|
||||
Tile.LAVA_14,
|
||||
Tile.LAVA_15
|
||||
)
|
||||
|
||||
fun update(gc: GameContainer, delta_t: Int) {
|
||||
fun update() {
|
||||
val player = Terrarum.ingame.player
|
||||
|
||||
renderWidth = FastMath.ceil(Terrarum.WIDTH / Terrarum.ingame.screenZoom) // div, not mul
|
||||
renderHeight = FastMath.ceil(Terrarum.HEIGHT / Terrarum.ingame.screenZoom)
|
||||
width = FastMath.ceil(Terrarum.WIDTH / Terrarum.ingame.screenZoom) // div, not mul
|
||||
height = FastMath.ceil(Terrarum.HEIGHT / Terrarum.ingame.screenZoom)
|
||||
|
||||
// position - (WH / 2)
|
||||
cameraX = Math.round( // X only: ROUNDWORLD implementation
|
||||
player.hitbox.centeredX.toFloat() - renderWidth / 2)
|
||||
cameraY = Math.round(FastMath.clamp(
|
||||
player.hitbox.centeredY.toFloat() - renderHeight / 2,
|
||||
TILE_SIZE.toFloat(), world.height * TILE_SIZE - renderHeight - TILE_SIZE.toFloat()))
|
||||
x = Math.round(// X only: ROUNDWORLD implementation
|
||||
player.hitbox.centeredX.toFloat() - width / 2)
|
||||
y = Math.round(FastMath.clamp(
|
||||
player.hitbox.centeredY.toFloat() - height / 2,
|
||||
TILE_SIZE.toFloat(),
|
||||
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
))
|
||||
|
||||
}
|
||||
|
||||
fun renderBehind(gc: GameContainer, g: Graphics) {
|
||||
/**
|
||||
* render to camera
|
||||
*/
|
||||
blendNormal()
|
||||
drawTiles(g, WALL, false)
|
||||
drawTiles(g, TERRAIN, false)
|
||||
}
|
||||
|
||||
fun renderFront(gc: GameContainer, g: Graphics) {
|
||||
blendMul()
|
||||
drawTiles(g, TERRAIN, true)
|
||||
blendNormal()
|
||||
}
|
||||
|
||||
private fun drawTiles(g: Graphics, mode: Int, drawModeTilesBlendMul: Boolean) {
|
||||
val for_y_start = MapCamera.cameraY / TILE_SIZE
|
||||
val for_y_end = MapCamera.clampHTile(for_y_start + (MapCamera.renderHeight / TILE_SIZE) + 2)
|
||||
|
||||
val for_x_start = MapCamera.cameraX / TILE_SIZE - 1
|
||||
val for_x_end = for_x_start + (MapCamera.renderWidth / TILE_SIZE) + 3
|
||||
|
||||
// initialise
|
||||
MapCamera.tilesetBook[mode].startUse()
|
||||
|
||||
var zeroTileCounter = 0
|
||||
|
||||
// loop
|
||||
for (y in for_y_start..for_y_end) {
|
||||
for (x in for_x_start..for_x_end - 1) {
|
||||
|
||||
val thisTile: Int?
|
||||
if (mode % 3 == WALL)
|
||||
thisTile = world.getTileFromWall(x, y)
|
||||
else if (mode % 3 == TERRAIN)
|
||||
thisTile = world.getTileFromTerrain(x, y)
|
||||
else if (mode % 3 == WIRE)
|
||||
thisTile = world.getTileFromWire(x, y)
|
||||
else
|
||||
throw IllegalArgumentException()
|
||||
|
||||
val noDamageLayer = mode % 3 == WIRE
|
||||
|
||||
// draw
|
||||
try {
|
||||
if (
|
||||
(mode == WALL || mode == TERRAIN) && // not an air tile
|
||||
(thisTile ?: 0) > 0) //&& // commented out: meh
|
||||
// check if light level of nearby or this tile is illuminated
|
||||
/*( LightmapRenderer.getValueFromMap(x, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x, y + 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y + 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y + 1) ?: 0 > 0)
|
||||
)*/ {
|
||||
val nearbyTilesInfo: Int
|
||||
if (isPlatform(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y)
|
||||
}
|
||||
else if (isWallSticker(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y)
|
||||
}
|
||||
else if (isConnectMutual(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode)
|
||||
}
|
||||
else if (isConnectSelf(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile)
|
||||
}
|
||||
else {
|
||||
nearbyTilesInfo = 0
|
||||
}
|
||||
|
||||
|
||||
val thisTileX: Int
|
||||
if (!noDamageLayer)
|
||||
thisTileX = PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
|
||||
else
|
||||
thisTileX = nearbyTilesInfo
|
||||
|
||||
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
|
||||
|
||||
if (drawModeTilesBlendMul) {
|
||||
if (MapCamera.isBlendMul(thisTile)) {
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
} else {
|
||||
// do NOT add "if (!isBlendMul(thisTile))"!
|
||||
// or else they will not look like they should be when backed with wall
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
} // end if (not an air and is illuminated)
|
||||
else {
|
||||
zeroTileCounter++
|
||||
}
|
||||
} catch (e: NullPointerException) {
|
||||
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
MapCamera.tilesetBook[mode].endUse()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @param x
|
||||
* *
|
||||
* @param y
|
||||
* *
|
||||
* @return binary [0-15] 1: up, 2: right, 4: down, 8: left
|
||||
*/
|
||||
fun getNearbyTilesInfo(x: Int, y: Int, mode: Int, mark: Int?): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFrom(mode, x , y - 1) ?: 4906
|
||||
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(mode, x , y + 1) ?: 4096
|
||||
|
||||
// try for
|
||||
var ret = 0
|
||||
for (i in 0..3) {
|
||||
if (nearbyTiles[i] == mark) {
|
||||
ret += 1 shl i // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getNearbyTilesInfoNonSolid(x: Int, y: Int, mode: Int): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFrom(mode, x , y - 1) ?: 4906
|
||||
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(mode, x , y + 1) ?: 4096
|
||||
|
||||
// try for
|
||||
var ret = 0
|
||||
for (i in 0..3) {
|
||||
try {
|
||||
if (!TileCodex[nearbyTiles[i]].isSolid &&
|
||||
!TileCodex[nearbyTiles[i]].isFluid) {
|
||||
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
||||
}
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getNearbyTilesInfoWallSticker(x: Int, y: Int): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
val NEARBY_TILE_KEY_BACK = NEARBY_TILE_KEY_UP
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(TERRAIN, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(TERRAIN, x + 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(TERRAIN, x , y + 1) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_BACK] = world.getTileFrom(WALL, x , y) ?: 4096
|
||||
|
||||
try {
|
||||
if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_DOWN]].isSolid)
|
||||
// has tile on the bottom
|
||||
return 3
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid
|
||||
&& TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid)
|
||||
// has tile on both sides
|
||||
return 0
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid)
|
||||
// has tile on the right
|
||||
return 2
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid)
|
||||
// has tile on the left
|
||||
return 1
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_BACK]].isSolid)
|
||||
// has tile on the back
|
||||
return 0
|
||||
else
|
||||
return 3
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
return if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_DOWN]].isSolid)
|
||||
// has tile on the bottom
|
||||
3 else 0
|
||||
}
|
||||
}
|
||||
|
||||
fun getNearbyTilesInfoPlatform(x: Int, y: Int): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(TERRAIN, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(TERRAIN, x + 1, y) ?: 4096
|
||||
|
||||
if ((TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid) ||
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT]) &&
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // LR solid || LR platform
|
||||
return 0
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT]) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // L solid and not platform && R not solid and not platform
|
||||
return 4
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT]) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) // R solid and not platform && L not solid and nto platform
|
||||
return 6
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) // L solid && L not platform
|
||||
return 3
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // R solid && R not platform
|
||||
return 5
|
||||
else if ((TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid ||
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // L solid or platform && R not solid and not platform
|
||||
return 1
|
||||
else if ((TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid ||
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) // R solid or platform && L not solid and not platform
|
||||
return 2
|
||||
else
|
||||
return 7
|
||||
}
|
||||
|
||||
private fun drawTile(mode: Int, tilewisePosX: Int, tilewisePosY: Int, sheetX: Int, sheetY: Int) {
|
||||
tilesetBook[mode].renderInUse(
|
||||
FastMath.floor((tilewisePosX * TILE_SIZE).toFloat()),
|
||||
FastMath.floor((tilewisePosY * TILE_SIZE).toFloat()),
|
||||
sheetX, sheetY
|
||||
)
|
||||
}
|
||||
|
||||
fun clampH(x: Int): Int {
|
||||
if (x < 0) {
|
||||
return 0
|
||||
} else if (x > world.height * TILE_SIZE) {
|
||||
return world.height * TILE_SIZE
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
fun clampWTile(x: Int): Int {
|
||||
if (x < 0) {
|
||||
return 0
|
||||
} else if (x > world.width) {
|
||||
return world.width
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
fun clampHTile(x: Int): Int {
|
||||
if (x < 0) {
|
||||
return 0
|
||||
} else if (x > world.height) {
|
||||
return world.height
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
fun getRenderStartX(): Int = cameraX / TILE_SIZE
|
||||
fun getRenderStartY(): Int = cameraY / TILE_SIZE
|
||||
|
||||
fun getRenderEndX(): Int = clampWTile(getRenderStartX() + (renderWidth / TILE_SIZE) + 2)
|
||||
fun getRenderEndY(): Int = clampHTile(getRenderStartY() + (renderHeight / TILE_SIZE) + 2)
|
||||
|
||||
fun isConnectSelf(b: Int?): Boolean = TILES_CONNECT_SELF.contains(b)
|
||||
fun isConnectMutual(b: Int?): Boolean = TILES_CONNECT_MUTUAL.contains(b)
|
||||
fun isWallSticker(b: Int?): Boolean = TILES_WALL_STICKER.contains(b)
|
||||
fun isPlatform(b: Int?): Boolean = TILES_WALL_STICKER_CONNECT_SELF.contains(b)
|
||||
fun isBlendMul(b: Int?): Boolean = TILES_BLEND_MUL.contains(b)
|
||||
|
||||
fun tileInCamera(x: Int, y: Int) =
|
||||
x >= cameraX.div(TILE_SIZE) && y >= cameraY.div(TILE_SIZE) &&
|
||||
x <= cameraX.plus(renderWidth).div(TILE_SIZE) && y <= cameraY.plus(renderWidth).div(TILE_SIZE)
|
||||
}
|
||||
}
|
||||
516
src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt
Normal file
516
src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt
Normal file
@@ -0,0 +1,516 @@
|
||||
package net.torvald.terrarum.mapdrawer
|
||||
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.concurrent.ThreadPool
|
||||
import net.torvald.terrarum.blendMul
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera.x
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera.y
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera.height
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera.width
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.newdawn.slick.*
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-19.
|
||||
*/
|
||||
object TilesDrawer {
|
||||
private val world: GameWorld = Terrarum.ingame.world
|
||||
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||
|
||||
var tilesWall: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wall.png", TILE_SIZE, TILE_SIZE)
|
||||
private set
|
||||
var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.tga", TILE_SIZE, TILE_SIZE)
|
||||
private set // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here.
|
||||
var tilesWire: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wire.png", TILE_SIZE, TILE_SIZE)
|
||||
private set
|
||||
var tilesetBook: Array<SpriteSheet> = arrayOf(tilesWall, tilesTerrain, tilesWire)
|
||||
private set
|
||||
|
||||
val WALL = GameWorld.WALL
|
||||
val TERRAIN = GameWorld.TERRAIN
|
||||
val WIRE = GameWorld.WIRE
|
||||
|
||||
private val NEARBY_TILE_KEY_UP = 0
|
||||
private val NEARBY_TILE_KEY_RIGHT = 1
|
||||
private val NEARBY_TILE_KEY_DOWN = 2
|
||||
private val NEARBY_TILE_KEY_LEFT = 3
|
||||
|
||||
private val NEARBY_TILE_CODE_UP = 1
|
||||
private val NEARBY_TILE_CODE_RIGHT = 2
|
||||
private val NEARBY_TILE_CODE_DOWN = 4
|
||||
private val NEARBY_TILE_CODE_LEFT = 8
|
||||
|
||||
/**
|
||||
* Connectivity group 01 : artificial tiles
|
||||
* It holds different shading rule to discriminate with group 02, index 0 is single tile.
|
||||
* These are the tiles that only connects to itself, will not connect to colour variants
|
||||
*/
|
||||
val TILES_CONNECT_SELF = arrayOf(
|
||||
Tile.ICE_MAGICAL,
|
||||
Tile.GLASS_CRUDE,
|
||||
Tile.GLASS_CLEAN,
|
||||
Tile.ILLUMINATOR_BLACK,
|
||||
Tile.ILLUMINATOR_BLUE,
|
||||
Tile.ILLUMINATOR_BROWN,
|
||||
Tile.ILLUMINATOR_CYAN,
|
||||
Tile.ILLUMINATOR_FUCHSIA,
|
||||
Tile.ILLUMINATOR_GREEN,
|
||||
Tile.ILLUMINATOR_GREEN_DARK,
|
||||
Tile.ILLUMINATOR_GREY_DARK,
|
||||
Tile.ILLUMINATOR_GREY_LIGHT,
|
||||
Tile.ILLUMINATOR_GREY_MED,
|
||||
Tile.ILLUMINATOR_ORANGE,
|
||||
Tile.ILLUMINATOR_PURPLE,
|
||||
Tile.ILLUMINATOR_RED,
|
||||
Tile.ILLUMINATOR_TAN,
|
||||
Tile.ILLUMINATOR_WHITE,
|
||||
Tile.ILLUMINATOR_YELLOW,
|
||||
Tile.ILLUMINATOR_BLACK_OFF,
|
||||
Tile.ILLUMINATOR_BLUE_OFF,
|
||||
Tile.ILLUMINATOR_BROWN_OFF,
|
||||
Tile.ILLUMINATOR_CYAN_OFF,
|
||||
Tile.ILLUMINATOR_FUCHSIA_OFF,
|
||||
Tile.ILLUMINATOR_GREEN_OFF,
|
||||
Tile.ILLUMINATOR_GREEN_DARK_OFF,
|
||||
Tile.ILLUMINATOR_GREY_DARK_OFF,
|
||||
Tile.ILLUMINATOR_GREY_LIGHT_OFF,
|
||||
Tile.ILLUMINATOR_GREY_MED_OFF,
|
||||
Tile.ILLUMINATOR_ORANGE_OFF,
|
||||
Tile.ILLUMINATOR_PURPLE_OFF,
|
||||
Tile.ILLUMINATOR_RED_OFF,
|
||||
Tile.ILLUMINATOR_TAN_OFF,
|
||||
Tile.ILLUMINATOR_WHITE_OFF,
|
||||
Tile.ILLUMINATOR_YELLOW,
|
||||
Tile.SANDSTONE,
|
||||
Tile.SANDSTONE_BLACK,
|
||||
Tile.SANDSTONE_DESERT,
|
||||
Tile.SANDSTONE_RED,
|
||||
Tile.SANDSTONE_WHITE,
|
||||
Tile.SANDSTONE_GREEN,
|
||||
Tile.DAYLIGHT_CAPACITOR
|
||||
)
|
||||
|
||||
/**
|
||||
* Connectivity group 02 : natural tiles
|
||||
* It holds different shading rule to discriminate with group 01, index 0 is middle tile.
|
||||
*/
|
||||
val TILES_CONNECT_MUTUAL = arrayOf(
|
||||
Tile.STONE,
|
||||
Tile.STONE_QUARRIED,
|
||||
Tile.STONE_TILE_WHITE,
|
||||
Tile.STONE_BRICKS,
|
||||
Tile.DIRT,
|
||||
Tile.GRASS,
|
||||
Tile.PLANK_BIRCH,
|
||||
Tile.PLANK_BLOODROSE,
|
||||
Tile.PLANK_EBONY,
|
||||
Tile.PLANK_NORMAL,
|
||||
Tile.SAND,
|
||||
Tile.SAND_WHITE,
|
||||
Tile.SAND_RED,
|
||||
Tile.SAND_DESERT,
|
||||
Tile.SAND_BLACK,
|
||||
Tile.SAND_GREEN,
|
||||
Tile.GRAVEL,
|
||||
Tile.GRAVEL_GREY,
|
||||
Tile.SNOW,
|
||||
Tile.ICE_NATURAL,
|
||||
Tile.ORE_COPPER,
|
||||
Tile.ORE_IRON,
|
||||
Tile.ORE_GOLD,
|
||||
Tile.ORE_SILVER,
|
||||
Tile.ORE_ILMENITE,
|
||||
Tile.ORE_AURICHALCUM,
|
||||
|
||||
Tile.WATER,
|
||||
Tile.WATER_1,
|
||||
Tile.WATER_2,
|
||||
Tile.WATER_3,
|
||||
Tile.WATER_4,
|
||||
Tile.WATER_5,
|
||||
Tile.WATER_6,
|
||||
Tile.WATER_7,
|
||||
Tile.WATER_8,
|
||||
Tile.WATER_9,
|
||||
Tile.WATER_10,
|
||||
Tile.WATER_11,
|
||||
Tile.WATER_12,
|
||||
Tile.WATER_13,
|
||||
Tile.WATER_14,
|
||||
Tile.WATER_15,
|
||||
Tile.LAVA,
|
||||
Tile.LAVA_1,
|
||||
Tile.LAVA_2,
|
||||
Tile.LAVA_3,
|
||||
Tile.LAVA_4,
|
||||
Tile.LAVA_5,
|
||||
Tile.LAVA_6,
|
||||
Tile.LAVA_7,
|
||||
Tile.LAVA_8,
|
||||
Tile.LAVA_9,
|
||||
Tile.LAVA_10,
|
||||
Tile.LAVA_11,
|
||||
Tile.LAVA_12,
|
||||
Tile.LAVA_13,
|
||||
Tile.LAVA_14,
|
||||
Tile.LAVA_15
|
||||
)
|
||||
|
||||
/**
|
||||
* Torches, levers, switches, ...
|
||||
*/
|
||||
val TILES_WALL_STICKER = arrayOf(
|
||||
Tile.TORCH,
|
||||
Tile.TORCH_FROST,
|
||||
Tile.TORCH_OFF,
|
||||
Tile.TORCH_FROST_OFF
|
||||
)
|
||||
|
||||
/**
|
||||
* platforms, ...
|
||||
*/
|
||||
val TILES_WALL_STICKER_CONNECT_SELF = arrayOf(
|
||||
Tile.PLATFORM_BIRCH,
|
||||
Tile.PLATFORM_BLOODROSE,
|
||||
Tile.PLATFORM_EBONY,
|
||||
Tile.PLATFORM_STONE,
|
||||
Tile.PLATFORM_WOODEN
|
||||
)
|
||||
|
||||
/**
|
||||
* Tiles that half-transparent and has hue
|
||||
* will blend colour using colour multiplication
|
||||
* i.e. red hues get lost if you dive into the water
|
||||
*/
|
||||
val TILES_BLEND_MUL = arrayOf(
|
||||
Tile.WATER,
|
||||
Tile.WATER_1,
|
||||
Tile.WATER_2,
|
||||
Tile.WATER_3,
|
||||
Tile.WATER_4,
|
||||
Tile.WATER_5,
|
||||
Tile.WATER_6,
|
||||
Tile.WATER_7,
|
||||
Tile.WATER_8,
|
||||
Tile.WATER_9,
|
||||
Tile.WATER_10,
|
||||
Tile.WATER_11,
|
||||
Tile.WATER_12,
|
||||
Tile.WATER_13,
|
||||
Tile.WATER_14,
|
||||
Tile.WATER_15,
|
||||
Tile.LAVA,
|
||||
Tile.LAVA_1,
|
||||
Tile.LAVA_2,
|
||||
Tile.LAVA_3,
|
||||
Tile.LAVA_4,
|
||||
Tile.LAVA_5,
|
||||
Tile.LAVA_6,
|
||||
Tile.LAVA_7,
|
||||
Tile.LAVA_8,
|
||||
Tile.LAVA_9,
|
||||
Tile.LAVA_10,
|
||||
Tile.LAVA_11,
|
||||
Tile.LAVA_12,
|
||||
Tile.LAVA_13,
|
||||
Tile.LAVA_14,
|
||||
Tile.LAVA_15
|
||||
)
|
||||
|
||||
fun update() {
|
||||
val player = Terrarum.ingame.player
|
||||
}
|
||||
|
||||
fun renderBehind(gc: GameContainer, g: Graphics) {
|
||||
/**
|
||||
* render to camera
|
||||
*/
|
||||
blendNormal()
|
||||
drawTiles(g, WALL, false)
|
||||
drawTiles(g, TERRAIN, false)
|
||||
}
|
||||
|
||||
fun renderFront(gc: GameContainer, g: Graphics) {
|
||||
blendMul()
|
||||
drawTiles(g, TERRAIN, true)
|
||||
blendNormal()
|
||||
}
|
||||
|
||||
private fun drawTiles(g: Graphics, mode: Int, drawModeTilesBlendMul: Boolean) {
|
||||
val for_y_start = y / TILE_SIZE
|
||||
val for_y_end = TilesDrawer.clampHTile(for_y_start + (height / TILE_SIZE) + 2)
|
||||
|
||||
val for_x_start = x / TILE_SIZE - 1
|
||||
val for_x_end = for_x_start + (width / TILE_SIZE) + 3
|
||||
|
||||
// initialise
|
||||
TilesDrawer.tilesetBook[mode].startUse()
|
||||
|
||||
var zeroTileCounter = 0
|
||||
|
||||
// loop
|
||||
for (y in for_y_start..for_y_end) {
|
||||
for (x in for_x_start..for_x_end - 1) {
|
||||
|
||||
val thisTile: Int?
|
||||
if (mode % 3 == WALL)
|
||||
thisTile = world.getTileFromWall(x, y)
|
||||
else if (mode % 3 == TERRAIN)
|
||||
thisTile = world.getTileFromTerrain(x, y)
|
||||
else if (mode % 3 == WIRE)
|
||||
thisTile = world.getTileFromWire(x, y)
|
||||
else
|
||||
throw IllegalArgumentException()
|
||||
|
||||
val noDamageLayer = mode % 3 == WIRE
|
||||
|
||||
// draw
|
||||
try {
|
||||
if (
|
||||
(mode == WALL || mode == TERRAIN) && // not an air tile
|
||||
(thisTile ?: 0) > 0) //&& // commented out: meh
|
||||
// check if light level of nearby or this tile is illuminated
|
||||
/*( LightmapRenderer.getValueFromMap(x, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x, y + 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y + 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x + 1, y - 1) ?: 0 > 0 ||
|
||||
LightmapRenderer.getValueFromMap(x - 1, y + 1) ?: 0 > 0)
|
||||
)*/ {
|
||||
val nearbyTilesInfo: Int
|
||||
if (isPlatform(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y)
|
||||
}
|
||||
else if (isWallSticker(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y)
|
||||
}
|
||||
else if (isConnectMutual(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode)
|
||||
}
|
||||
else if (isConnectSelf(thisTile)) {
|
||||
nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile)
|
||||
}
|
||||
else {
|
||||
nearbyTilesInfo = 0
|
||||
}
|
||||
|
||||
|
||||
val thisTileX: Int
|
||||
if (!noDamageLayer)
|
||||
thisTileX = PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
|
||||
else
|
||||
thisTileX = nearbyTilesInfo
|
||||
|
||||
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
|
||||
|
||||
if (drawModeTilesBlendMul) {
|
||||
if (TilesDrawer.isBlendMul(thisTile)) {
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
} else {
|
||||
// do NOT add "if (!isBlendMul(thisTile))"!
|
||||
// or else they will not look like they should be when backed with wall
|
||||
drawTile(mode, x, y, thisTileX, thisTileY)
|
||||
}
|
||||
} // end if (not an air and is illuminated)
|
||||
else {
|
||||
zeroTileCounter++
|
||||
}
|
||||
} catch (e: NullPointerException) {
|
||||
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
TilesDrawer.tilesetBook[mode].endUse()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @param x
|
||||
* *
|
||||
* @param y
|
||||
* *
|
||||
* @return binary [0-15] 1: up, 2: right, 4: down, 8: left
|
||||
*/
|
||||
fun getNearbyTilesInfo(x: Int, y: Int, mode: Int, mark: Int?): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFrom(mode, x , y - 1) ?: 4906
|
||||
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(mode, x , y + 1) ?: 4096
|
||||
|
||||
// try for
|
||||
var ret = 0
|
||||
for (i in 0..3) {
|
||||
if (nearbyTiles[i] == mark) {
|
||||
ret += 1 shl i // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getNearbyTilesInfoNonSolid(x: Int, y: Int, mode: Int): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(mode, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(mode, x + 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_UP] = world.getTileFrom(mode, x , y - 1) ?: 4906
|
||||
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(mode, x , y + 1) ?: 4096
|
||||
|
||||
// try for
|
||||
var ret = 0
|
||||
for (i in 0..3) {
|
||||
try {
|
||||
if (!TileCodex[nearbyTiles[i]].isSolid &&
|
||||
!TileCodex[nearbyTiles[i]].isFluid) {
|
||||
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
|
||||
}
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getNearbyTilesInfoWallSticker(x: Int, y: Int): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
val NEARBY_TILE_KEY_BACK = NEARBY_TILE_KEY_UP
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(TERRAIN, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(TERRAIN, x + 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_DOWN] = world.getTileFrom(TERRAIN, x , y + 1) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_BACK] = world.getTileFrom(WALL, x , y) ?: 4096
|
||||
|
||||
try {
|
||||
if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_DOWN]].isSolid)
|
||||
// has tile on the bottom
|
||||
return 3
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid
|
||||
&& TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid)
|
||||
// has tile on both sides
|
||||
return 0
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid)
|
||||
// has tile on the right
|
||||
return 2
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid)
|
||||
// has tile on the left
|
||||
return 1
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_BACK]].isSolid)
|
||||
// has tile on the back
|
||||
return 0
|
||||
else
|
||||
return 3
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
return if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_DOWN]].isSolid)
|
||||
// has tile on the bottom
|
||||
3 else 0
|
||||
}
|
||||
}
|
||||
|
||||
fun getNearbyTilesInfoPlatform(x: Int, y: Int): Int {
|
||||
val nearbyTiles = IntArray(4)
|
||||
nearbyTiles[NEARBY_TILE_KEY_LEFT] = world.getTileFrom(TERRAIN, x - 1, y) ?: 4096
|
||||
nearbyTiles[NEARBY_TILE_KEY_RIGHT] = world.getTileFrom(TERRAIN, x + 1, y) ?: 4096
|
||||
|
||||
if ((TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid) ||
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT]) &&
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // LR solid || LR platform
|
||||
return 0
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT]) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // L solid and not platform && R not solid and not platform
|
||||
return 4
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT]) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) // R solid and not platform && L not solid and nto platform
|
||||
return 6
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) // L solid && L not platform
|
||||
return 3
|
||||
else if (TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // R solid && R not platform
|
||||
return 5
|
||||
else if ((TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid ||
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) // L solid or platform && R not solid and not platform
|
||||
return 1
|
||||
else if ((TileCodex[nearbyTiles[NEARBY_TILE_KEY_RIGHT]].isSolid ||
|
||||
isPlatform(nearbyTiles[NEARBY_TILE_KEY_RIGHT])) &&
|
||||
!TileCodex[nearbyTiles[NEARBY_TILE_KEY_LEFT]].isSolid &&
|
||||
!isPlatform(nearbyTiles[NEARBY_TILE_KEY_LEFT])) // R solid or platform && L not solid and not platform
|
||||
return 2
|
||||
else
|
||||
return 7
|
||||
}
|
||||
|
||||
private fun drawTile(mode: Int, tilewisePosX: Int, tilewisePosY: Int, sheetX: Int, sheetY: Int) {
|
||||
tilesetBook[mode].renderInUse(
|
||||
FastMath.floor((tilewisePosX * TILE_SIZE).toFloat()),
|
||||
FastMath.floor((tilewisePosY * TILE_SIZE).toFloat()),
|
||||
sheetX, sheetY
|
||||
)
|
||||
}
|
||||
|
||||
fun clampH(x: Int): Int {
|
||||
if (x < 0) {
|
||||
return 0
|
||||
} else if (x > world.height * TILE_SIZE) {
|
||||
return world.height * TILE_SIZE
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
fun clampWTile(x: Int): Int {
|
||||
if (x < 0) {
|
||||
return 0
|
||||
} else if (x > world.width) {
|
||||
return world.width
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
fun clampHTile(x: Int): Int {
|
||||
if (x < 0) {
|
||||
return 0
|
||||
} else if (x > world.height) {
|
||||
return world.height
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
fun getRenderStartX(): Int = x / TILE_SIZE
|
||||
fun getRenderStartY(): Int = y / TILE_SIZE
|
||||
|
||||
fun getRenderEndX(): Int = clampWTile(getRenderStartX() + (width / TILE_SIZE) + 2)
|
||||
fun getRenderEndY(): Int = clampHTile(getRenderStartY() + (height / TILE_SIZE) + 2)
|
||||
|
||||
fun isConnectSelf(b: Int?): Boolean = TILES_CONNECT_SELF.contains(b)
|
||||
fun isConnectMutual(b: Int?): Boolean = TILES_CONNECT_MUTUAL.contains(b)
|
||||
fun isWallSticker(b: Int?): Boolean = TILES_WALL_STICKER.contains(b)
|
||||
fun isPlatform(b: Int?): Boolean = TILES_WALL_STICKER_CONNECT_SELF.contains(b)
|
||||
fun isBlendMul(b: Int?): Boolean = TILES_BLEND_MUL.contains(b)
|
||||
|
||||
fun tileInCamera(x: Int, y: Int) =
|
||||
x >= MapCamera.x.div(TILE_SIZE) && y >= MapCamera.y.div(TILE_SIZE) &&
|
||||
x <= MapCamera.x.plus(width).div(TILE_SIZE) && y <= MapCamera.y.plus(width).div(TILE_SIZE)
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package net.torvald.terrarum.tilestats
|
||||
import net.torvald.terrarum.gameactors.Player
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.MapLayer
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import com.jme3.math.FastMath
|
||||
|
||||
@@ -17,7 +17,7 @@ object TileStats {
|
||||
|
||||
private val tilestat = ShortArray(GameWorld.TILES_SUPPORTED)
|
||||
|
||||
private val TSIZE = MapDrawer.TILE_SIZE
|
||||
private val TSIZE = FeaturesDrawer.TILE_SIZE
|
||||
|
||||
/**
|
||||
* Update tile stats from tiles on screen
|
||||
@@ -40,8 +40,8 @@ object TileStats {
|
||||
|
||||
val for_x_start = noZoomCameraX / TSIZE
|
||||
val for_y_start = noZoomCameraY / TSIZE
|
||||
val for_y_end = MapCamera.clampHTile(for_y_start + (renderHeight / TSIZE) + 2)
|
||||
val for_x_end = MapCamera.clampWTile(for_x_start + (renderWidth / TSIZE) + 2)
|
||||
val for_y_end = TilesDrawer.clampHTile(for_y_start + (renderHeight / TSIZE) + 2)
|
||||
val for_x_end = TilesDrawer.clampWTile(for_x_start + (renderWidth / TSIZE) + 2)
|
||||
|
||||
for (y in for_y_start..for_y_end - 1) {
|
||||
for (x in for_x_start..for_x_end - 1) {
|
||||
|
||||
@@ -4,11 +4,12 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.imagefont.GameFontBase
|
||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blendScreen
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
@@ -60,8 +61,8 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
val player = Terrarum.ingame.player
|
||||
|
||||
val mouseTileX = ((MapCamera.cameraX + gc.input.mouseX / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((MapCamera.cameraY + gc.input.mouseY / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileX = ((MapCamera.x + gc.input.mouseX / Terrarum.ingame.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((MapCamera.y + gc.input.mouseY / Terrarum.ingame.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt()
|
||||
|
||||
g.font = Terrarum.fontSmallNumbers
|
||||
g.color = GameFontBase.codeToCol["y"]
|
||||
@@ -77,13 +78,13 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
+ ccG
|
||||
+ "${hitbox.pointedX}"
|
||||
+ " ("
|
||||
+ "${(hitbox.pointedX / MapDrawer.TILE_SIZE).toInt()}"
|
||||
+ "${(hitbox.pointedX / FeaturesDrawer.TILE_SIZE).toInt()}"
|
||||
+ ")")
|
||||
printLine(g, 2, "posY "
|
||||
+ ccG
|
||||
+ hitbox.pointedY.toString()
|
||||
+ " ("
|
||||
+ (hitbox.pointedY / MapDrawer.TILE_SIZE).toInt().toString()
|
||||
+ (hitbox.pointedY / FeaturesDrawer.TILE_SIZE).toInt().toString()
|
||||
+ ")")
|
||||
|
||||
printLine(g, 3, "veloX reported $ccG${player.moveDelta.x}")
|
||||
@@ -125,7 +126,7 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
*/
|
||||
|
||||
printLineColumn(g, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
|
||||
printLineColumn(g, 2, 2, "Env colour temp $ccG" + MapDrawer.colTemp)
|
||||
printLineColumn(g, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
|
||||
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame.world.time.elapsedSeconds}" +
|
||||
" (${Terrarum.ingame.world.time.getFormattedTime()})")
|
||||
printLineColumn(g, 2, 6, "Mass $ccG${player.mass}")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.mapdrawer.TilesDrawer
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import com.jme3.math.FastMath
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
Reference in New Issue
Block a user