From f367b35892dc0e2b070d5a604617d3820da54a95 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Fri, 30 Dec 2016 02:47:15 +0900 Subject: [PATCH] separated Camera from TileDrawer (was MapCamera) Former-commit-id: b2fe7716722634b03f3750fade420d26022500f9 Former-commit-id: 521826d176c6902007646e6b9b9c7b5d4f3468cf --- src/net/torvald/terrarum/StateInGame.kt | 40 +- .../terrarum/console/SpawnPhysTestBall.kt | 7 +- src/net/torvald/terrarum/console/Teleport.kt | 10 +- .../terrarum/debuggerapp/ActorValueTracker.kt | 6 +- .../terrarum/gameactors/ActorWithBody.kt | 6 +- .../terrarum/gameactors/PhysTestBall.kt | 2 +- src/net/torvald/terrarum/gameactors/Player.kt | 2 +- .../gameactors/PlayerBuilderCynthia.kt | 4 +- .../gameactors/PlayerBuilderSigrid.kt | 4 +- .../terrarum/gamecontroller/GameController.kt | 13 +- .../terrarum/gameworld/WorldSimulator.kt | 14 +- .../{MapDrawer.kt => FeaturesDrawer.kt} | 6 +- .../terrarum/mapdrawer/LightmapRenderer.kt | 22 +- .../torvald/terrarum/mapdrawer/MapCamera.kt | 539 +----------------- .../torvald/terrarum/mapdrawer/TilesDrawer.kt | 516 +++++++++++++++++ .../torvald/terrarum/tilestats/TileStats.kt | 10 +- .../terrarum/ui/BasicDebugInfoWindow.kt | 15 +- src/net/torvald/terrarum/ui/UIHandler.kt | 2 +- 18 files changed, 623 insertions(+), 595 deletions(-) rename src/net/torvald/terrarum/mapdrawer/{MapDrawer.kt => FeaturesDrawer.kt} (95%) create mode 100644 src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index 5d53563a0..347dcb505 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -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 */ diff --git a/src/net/torvald/terrarum/console/SpawnPhysTestBall.kt b/src/net/torvald/terrarum/console/SpawnPhysTestBall.kt index 706f13ad6..d5f4494d9 100644 --- a/src/net/torvald/terrarum/console/SpawnPhysTestBall.kt +++ b/src/net/torvald/terrarum/console/SpawnPhysTestBall.kt @@ -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 diff --git a/src/net/torvald/terrarum/console/Teleport.kt b/src/net/torvald/terrarum/console/Teleport.kt index cba5e5e60..3a3651368 100644 --- a/src/net/torvald/terrarum/console/Teleport.kt +++ b/src/net/torvald/terrarum/console/Teleport.kt @@ -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) { diff --git a/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt b/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt index 8dbb8df05..ce48cf57c 100644 --- a/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt +++ b/src/net/torvald/terrarum/debuggerapp/ActorValueTracker.kt @@ -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 diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index fc0827e27..c355f13e8 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -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) diff --git a/src/net/torvald/terrarum/gameactors/PhysTestBall.kt b/src/net/torvald/terrarum/gameactors/PhysTestBall.kt index b4e877836..32608ffa4 100644 --- a/src/net/torvald/terrarum/gameactors/PhysTestBall.kt +++ b/src/net/torvald/terrarum/gameactors/PhysTestBall.kt @@ -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 diff --git a/src/net/torvald/terrarum/gameactors/Player.kt b/src/net/torvald/terrarum/gameactors/Player.kt index fed14b80d..288b4db0f 100644 --- a/src/net/torvald/terrarum/gameactors/Player.kt +++ b/src/net/torvald/terrarum/gameactors/Player.kt @@ -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 diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt index 153ee68f8..cba020bea 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilderCynthia.kt @@ -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) diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt index 79327d703..28427dde3 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt @@ -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")) diff --git a/src/net/torvald/terrarum/gamecontroller/GameController.kt b/src/net/torvald/terrarum/gamecontroller/GameController.kt index 79e79e5d5..e80f2102a 100644 --- a/src/net/torvald/terrarum/gamecontroller/GameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/GameController.kt @@ -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) { diff --git a/src/net/torvald/terrarum/gameworld/WorldSimulator.kt b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt index fa6c89bc3..322aed4cb 100644 --- a/src/net/torvald/terrarum/gameworld/WorldSimulator.kt +++ b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt @@ -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 ) } diff --git a/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt b/src/net/torvald/terrarum/mapdrawer/FeaturesDrawer.kt similarity index 95% rename from src/net/torvald/terrarum/mapdrawer/MapDrawer.kt rename to src/net/torvald/terrarum/mapdrawer/FeaturesDrawer.kt index 7282999cc..52a5ea4dd 100644 --- a/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt +++ b/src/net/torvald/terrarum/mapdrawer/FeaturesDrawer.kt @@ -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 ) diff --git a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt index 6136a9059..21812af49 100644 --- a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt @@ -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) diff --git a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt index f7692e849..71261b651 100644 --- a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt +++ b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt @@ -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 = 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) -} +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt b/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt new file mode 100644 index 000000000..7012e66f4 --- /dev/null +++ b/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt @@ -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 = 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) +} diff --git a/src/net/torvald/terrarum/tilestats/TileStats.kt b/src/net/torvald/terrarum/tilestats/TileStats.kt index eb8d3599c..303226217 100644 --- a/src/net/torvald/terrarum/tilestats/TileStats.kt +++ b/src/net/torvald/terrarum/tilestats/TileStats.kt @@ -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) { diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 7dce7535f..94d049607 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -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}") diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index e6cf52976..1547aed92 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -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