diff --git a/lib/TerrarumSansBitmap.jar b/lib/TerrarumSansBitmap.jar index b85aa2b8a..68e2cc56c 100644 Binary files a/lib/TerrarumSansBitmap.jar and b/lib/TerrarumSansBitmap.jar differ diff --git a/src/net/torvald/terrarum/StateInGameGDX.kt b/src/net/torvald/terrarum/StateInGameGDX.kt index aa10a67f2..073a6925f 100644 --- a/src/net/torvald/terrarum/StateInGameGDX.kt +++ b/src/net/torvald/terrarum/StateInGameGDX.kt @@ -73,7 +73,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { val ZOOM_MIN = 0.5f var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false) - var backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false) + //var backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false) //private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader //private lateinit var shaderBlur: Shader @@ -127,55 +127,21 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { var camera = OrthographicCamera(Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) // invert Y - fun initViewPort(width: Int, height: Int, aspect: Float) { - val width = width.toFloat() - val height = height.toFloat() - - // Get the window size in pixels - val w = Gdx.graphics.width.toFloat() - val h = Gdx.graphics.height.toFloat() - - val vw: Float - val vh: Float // Viewport size in screen coordinates - val ox: Float - val oy: Float // Viewport offset in screen coordinates - - // Check aspect ratio - if (w > h * aspect) { - // Black bars on the sides - vh = h - vw = Math.round(vh * aspect).toFloat() - oy = 0f - ox = (w - vw) / 2 - } - else { - // Black bars on top and bottom - vw = w - vh = Math.round(vw * (1 / aspect)).toFloat() - ox = 0f - oy = (h - vh) / 2 - } - - // Create camera with the desired resolution - //camera = OrthographicCamera(width, height) - - // Move camera center to push 0,0 into the corner - //camera.translate(width / 2, height / 2) - + fun initViewPort(width: Int, height: Int) { // Set Y to point downwards - camera.setToOrtho(true, width, height) + camera.setToOrtho(true, width.toFloat(), height.toFloat()) // Update camera matrix camera.update() // Set viewport to restrict drawing - Gdx.gl20.glViewport(ox.toInt(), oy.toInt(), vw.toInt(), vh.toInt()) + Gdx.gl20.glViewport(0, 0, width, height) } override fun show() { // Set up viewport on first load - initViewPort(Gdx.graphics.width, Gdx.graphics.height, Gdx.graphics.width.toFloat() / Gdx.graphics.height.toFloat()) + initViewPort(Gdx.graphics.width, Gdx.graphics.height) } @@ -183,7 +149,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { Gdx.input.inputProcessor = GameController - initViewPort(Gdx.graphics.width, Gdx.graphics.height, Gdx.graphics.width.toFloat() / Gdx.graphics.height.toFloat()) + initViewPort(Gdx.graphics.width, Gdx.graphics.height) // load things when the game entered this "state" @@ -410,14 +376,15 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { Gdx.gl.glClearColor(0f,0f,0f,0f) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) } - backDrawFrameBuffer.inAction { - Gdx.gl.glClearColor(0f,0f,0f,0f) - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) - } + // Post-update; ones that needs everything is completed // + LightmapRenderer.renderLightMap() // + FeaturesDrawer.render(batch) // + // end of post-update // + // now the actual drawing part // worldDrawFrameBuffer.inAction { batch.inUse { camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work @@ -426,6 +393,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { + blendNormal() @@ -450,42 +418,33 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { ///////////////////////////// // draw map related stuffs // ///////////////////////////// - LightmapRenderer.renderLightMap() - //BlocksDrawer.renderFront(batch, false) + BlocksDrawer.renderFront(batch, false) // --> blendNormal() <-- by BlocksDrawer.renderFront - //FeaturesDrawer.render(batch) + FeaturesDrawer.drawEnvOverlay(batch) - //FeaturesDrawer.drawEnvOverlay(batch) - - //if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() - //else blendNormal() - //blendMul() - //LightmapRenderer.draw(batch) - + LightmapRenderer.draw(batch) ////////////////////// // draw actor glows // ////////////////////// - // needs some new blending/shader for glow... + // FIXME needs some new blending/shader for glow... //actorsRenderMiddle.forEach { it.drawGlow(batch) } //actorsRenderMidTop.forEach { it.drawGlow(batch) } - player?.drawGlow(batch) + //player?.drawGlow(batch) //actorsRenderFront.forEach { it.drawGlow(batch) } // --> blendLightenOnly() <-- introduced by childs of ActorWithBody // - - } } - ///////////////////////////////// - // draw framebuffers to screen // - ///////////////////////////////// + ///////////////////////// + // draw to main screen // + ///////////////////////// blendNormal() batch.inUse { camera.position.set(TerrarumGDX.HALFW.toFloat(), TerrarumGDX.HALFH.toFloat(), 0f) // make camara work @@ -493,14 +452,99 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { batch.projectionMatrix = camera.combined + ///////////////////////////////// + // draw framebuffers to screen // + ///////////////////////////////// + WeatherMixer.render(batch) val tex = worldDrawFrameBuffer.colorBufferTexture // TODO zoom! batch.draw(tex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) + + + + + //////////////////////// + // debug informations // + //////////////////////// + + blendNormal() + // draw reference ID if debugWindow is open + if (debugWindow.isVisible) { + + actorContainer.forEachIndexed { i, actor -> + if (actor is ActorWithBody) { + batch.color = Color.WHITE + TerrarumGDX.fontSmallNumbers.draw(batch, + actor.referenceID.toString(), + actor.hitbox.startX.toFloat(), + actor.hitbox.canonicalY.toFloat() + 4 + ) + } + } + } + // debug physics + if (KeyToggler.isOn(Input.Keys.F11)) { + actorContainer.forEachIndexed { i, actor -> + if (actor is ActorWithPhysics) { + /*shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) { + shapeRenderer.color = Color(1f, 0f, 1f, 1f) + //shapeRenderer.lineWidth = 1f + shapeRenderer.rect( + actor.hitbox.startX.toFloat(), + actor.hitbox.startY.toFloat(), + actor.hitbox.width.toFloat(), + actor.hitbox.height.toFloat() + ) + }*/ + + // velocity + batch.color = Color.CHARTREUSE//GameFontBase.codeToCol["g"] + TerrarumGDX.fontSmallNumbers.draw(batch, + "${0x7F.toChar()}X ${actor.externalForce.x}", + actor.hitbox.startX.toFloat(), + actor.hitbox.canonicalY.toFloat() + 4 + 8 + ) + TerrarumGDX.fontSmallNumbers.draw(batch, + "${0x7F.toChar()}Y ${actor.externalForce.y}", + actor.hitbox.startX.toFloat(), + actor.hitbox.canonicalY.toFloat() + 4 + 8 * 2 + ) + } + } + } + // fluidmap debug + if (KeyToggler.isOn(Input.Keys.F4)) { + WorldSimulator.drawFluidMapDebug(batch) + } + + + + + ///////////////////////////// + // draw some overlays (UI) // + ///////////////////////////// + + //uiContainer.forEach { if (it != consoleHandler) it.render(batch) } // FIXME draws black of grey coloured box on top right + debugWindow.render(batch) + // make sure console draws on top of other UIs + consoleHandler.render(batch) + notifier.render(batch) } + + + + + // ////// //// // //// // // + // // // // // // // // + // //// // // // // // //// + // // // // ////// // // + ////// ////// //// // // //// //// + + ///////////////////////////// // draw map related stuffs // ///////////////////////////// @@ -1037,15 +1081,12 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { override fun resize(width: Int, height: Int) { worldDrawFrameBuffer.dispose() worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false) - backDrawFrameBuffer.dispose() - backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false) - + // Set up viewport when window is resized - initViewPort(width, height, width.toFloat() / height.toFloat()) + initViewPort(width, height) } override fun dispose() { worldDrawFrameBuffer.dispose() - backDrawFrameBuffer.dispose() } } diff --git a/src/net/torvald/terrarum/console/GetFactioning.kt b/src/net/torvald/terrarum/console/GetFactioning.kt index 2da4f4321..1928cf305 100644 --- a/src/net/torvald/terrarum/console/GetFactioning.kt +++ b/src/net/torvald/terrarum/console/GetFactioning.kt @@ -4,17 +4,17 @@ import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.TerrarumGDX import net.torvald.terrarum.gameactors.Factionable import net.torvald.terrarum.gameactors.Player +import net.torvald.terrarumsansbitmap.gdx.GameFontBase /** * Created by minjaesong on 16-02-17. */ internal object GetFactioning : ConsoleCommand { - val ccW = 0.toChar()//GameFontBase.colToCode["w"] - val ccG = 0.toChar()//GameFontBase.colToCode["g"] - val ccY = 0.toChar()//GameFontBase.colToCode["y"] - val ccM = 0.toChar()//GameFontBase.colToCode["m"] - val ccK = 0.toChar()//GameFontBase.colToCode["k"] - val ccB = 0.toChar()//GameFontBase.colToCode["b"] + val ccW = GameFontBase.toColorCode(0xFFFF) + val ccY = GameFontBase.toColorCode(0xFE8F) + val ccM = GameFontBase.toColorCode(0xEAFF) + val ccG = GameFontBase.toColorCode(0x8F8F) + val ccK = GameFontBase.toColorCode(0x888F) private val PRINT_INDENTATION = "$ccK --> $ccW" diff --git a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt index e6f98729a..e297bde17 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt @@ -46,9 +46,9 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean @Transient private val world: GameWorld = TerrarumGDX.ingame!!.world - var hitboxTranslateX: Double = 0.0// relative to spritePosX + var hitboxTranslateX: Int = 0// relative to spritePosX protected set - var hitboxTranslateY: Double = 0.0// relative to spritePosY + var hitboxTranslateY: Int = 0// relative to spritePosY protected set var baseHitboxW: Int = 0 protected set @@ -269,8 +269,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean fun setHitboxDimension(w: Int, h: Int, tx: Int, ty: Int) { baseHitboxH = h baseHitboxW = w - hitboxTranslateX = tx.toDouble() - hitboxTranslateY = ty.toDouble() + hitboxTranslateX = tx + hitboxTranslateY = ty } fun setPosition(pos: Point2d) = setPosition(pos.x, pos.y) diff --git a/src/net/torvald/terrarum/gamecontroller/GameController.kt b/src/net/torvald/terrarum/gamecontroller/GameController.kt index 1c96a903e..2f76be70f 100644 --- a/src/net/torvald/terrarum/gamecontroller/GameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/GameController.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.gamecontroller import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Input import com.badlogic.gdx.InputAdapter import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.InputListener @@ -24,10 +25,10 @@ object GameController : InputAdapter() { /** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */ val mouseX: Float - get() = (WorldCamera.x + TerrarumGDX.mouseX.toFloat() / (ingame.screenZoom ?: 1f)) + get() = WorldCamera.x + Gdx.input.x / (ingame.screenZoom) /** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise)*/ val mouseY: Float - get() = (WorldCamera.y + TerrarumGDX.mouseY.toFloat() / (ingame.screenZoom ?: 1f)) + get() = WorldCamera.y + Gdx.input.y / (ingame.screenZoom) /** currently pointing tile coordinate */ val mouseTileX: Int get() = (mouseX / FeaturesDrawer.TILE_SIZE).floorInt() @@ -102,6 +103,10 @@ object GameController : InputAdapter() { ingame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases + if (keycode == Input.Keys.F3) { + ingame.debugWindow.toggleOpening() + } + return true } diff --git a/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt b/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt index 769ed980f..0a69c573d 100644 --- a/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt +++ b/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.imagefont +import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.graphics.g2d.GlyphLayout @@ -25,15 +26,67 @@ object TinyAlphNum : BitmapFont() { return W * str.length } + lateinit var colourHolder: Color + override fun draw(batch: Batch, text: CharSequence, x: Float, y: Float): GlyphLayout? { + val originalColour = batch.color + colourHolder = batch.color + + var charsPrinted = 0 text.forEachIndexed { index, c -> - batch.draw(fontSheet.get(index % 16, index / 16), x + index * W, y) + if (isColourCodeHigh(c)) { + val cchigh = c + val cclow = text[index + 1] + val colour = getColour(cchigh, cclow) + + colourHolder = colour + } + else if (c in 0.toChar()..255.toChar()) { + batch.color = colourHolder.cpy().mul(0.5f, 0.5f, 0.5f, 1f) + batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W + 1, y) + batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W , y + 1) + batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W + 1, y + 1) + + + batch.color = colourHolder.cpy() + batch.draw(fontSheet.get(c.toInt() % 16, c.toInt() / 16), x + charsPrinted * W, y) + + charsPrinted += 1 + } } + + batch.color = originalColour + return null } override fun getLineHeight() = H.toFloat() override fun getCapHeight() = getLineHeight() override fun getXHeight() = getLineHeight() + + + + private fun isColourCodeHigh(c: Char) = c.toInt() in 0b110110_1111000000..0b110110_1111111111 + private fun isColourCodeLow(c: Char) = c.toInt() in 0b110111_0000000000..0b110111_1111111111 + + private fun getColour(charHigh: Char, charLow: Char): Color { // input: 0x10ARGB, out: RGBA8888 + val codePoint = Character.toCodePoint(charHigh, charLow) + + if (colourBuffer.containsKey(codePoint)) + return colourBuffer[codePoint]!! + + val r = codePoint.and(0xF000).ushr(12) + val g = codePoint.and(0x0F00).ushr(8) + val b = codePoint.and(0x00F0).ushr(4) + val a = codePoint.and(0x000F) + + val col = Color(r.shl(28) or r.shl(24) or g.shl(20) or g.shl(16) or b.shl(12) or b.shl(8) or a.shl(4) or a) + + + colourBuffer[codePoint] = col + return col + } + + private val colourBuffer = HashMap() } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index c8da21e71..a003f886c 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -11,6 +11,7 @@ import net.torvald.terrarum.blendNormal import net.torvald.terrarum.blendScreen import net.torvald.terrarum.fillRect import net.torvald.terrarum.worlddrawer.WorldCamera +import net.torvald.terrarumsansbitmap.gdx.GameFontBase /** * Created by minjaesong on 16-03-14. @@ -30,11 +31,18 @@ class BasicDebugInfoWindow : UICanvas { private var xdelta = 0.0 private var ydelta = 0.0 - val ccW = 0.toChar()//GameFontBase.colToCode["w"] - val ccG = 0.toChar()//GameFontBase.colToCode["g"] - val ccY = 0.toChar()//GameFontBase.colToCode["y"] - val ccR = 0.toChar()//GameFontBase.colToCode["r"] - val ccM = 0.toChar()//GameFontBase.colToCode["m"] + val ccW = GameFontBase.toColorCode(0xFFFF) + val ccY = GameFontBase.toColorCode(0xFE8F) + val ccO = GameFontBase.toColorCode(0xFB2F) + val ccR = GameFontBase.toColorCode(0xF88F) + val ccF = GameFontBase.toColorCode(0xFAEF) + val ccM = GameFontBase.toColorCode(0xEAFF) + val ccB = GameFontBase.toColorCode(0x88FF) + val ccC = GameFontBase.toColorCode(0x8FFF) + val ccG = GameFontBase.toColorCode(0x8F8F) + val ccV = GameFontBase.toColorCode(0x080F) + val ccX = GameFontBase.toColorCode(0x853F) + val ccK = GameFontBase.toColorCode(0x888F) @@ -59,9 +67,7 @@ class BasicDebugInfoWindow : UICanvas { val mouseTileX = ((WorldCamera.x + TerrarumGDX.mouseX / TerrarumGDX.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt() val mouseTileY = ((WorldCamera.y + TerrarumGDX.mouseY / TerrarumGDX.ingame!!.screenZoom) / FeaturesDrawer.TILE_SIZE).toInt() - //g.color = GameFontBase.codeToCol["y"] - - batch.color = Color.WHITE + batch.color = Color(0xFFEE88FF.toInt()) val hitbox = player?.hitbox @@ -155,6 +161,9 @@ class BasicDebugInfoWindow : UICanvas { Gdx.graphics.width - histogramW - 30, Gdx.graphics.height - histogramH - 30 ) + + batch.color = Color.WHITE + if (TerrarumGDX.controller != null) { drawGamepadAxis(batch, TerrarumGDX.controller!!.getAxisValue(3), diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index c768d736e..32406357c 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -127,11 +127,13 @@ class UIHandler(val UI: UICanvas, fun render(batch: SpriteBatch) { if (isVisible || alwaysVisible) { + // camera SHOULD BE CENTERED to HALFX and HALFY (see StateInGame) // - batch.projectionMatrix = Matrix4() - if (!customPositioning) - TerrarumGDX.ingame?.camera?.position?.set(posX.toFloat(), posY.toFloat(), 0f) // does it work? + //batch.projectionMatrix = Matrix4() +// + //if (!customPositioning) + // TerrarumGDX.ingame?.camera?.position?.set(posX.toFloat(), posY.toFloat(), 0f) // does it work? UI.render(batch) //ingameGraphics.flush() diff --git a/src/net/torvald/terrarum/ui/UIInventory.kt b/src/net/torvald/terrarum/ui/UIInventory.kt index 66e250cf3..c7ecb60ee 100644 --- a/src/net/torvald/terrarum/ui/UIInventory.kt +++ b/src/net/torvald/terrarum/ui/UIInventory.kt @@ -316,7 +316,7 @@ class UIInventory( } override fun mouseMoved(screenX: Int, screenY: Int): Boolean { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + return false } override fun keyDown(keycode: Int): Boolean { diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt index f60fbd392..df3be9d0b 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt @@ -342,7 +342,9 @@ object BlocksDrawer { } - + /////////////////////////////////////////// + // NO draw lightmap using colour filter, actors must also be hidden behind the darkness + /////////////////////////////////////////// fun renderWall(batch: SpriteBatch) { /**