mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
more SANE way of drawing elements (actor zoom broken)
Former-commit-id: edca68d5d25c4e45be209da46449ad9e0b2c35cf Former-commit-id: 38858d235b553e41bea7d506b402fe0a92a1aab0
This commit is contained in:
@@ -120,9 +120,6 @@ constructor() {
|
|||||||
* @param scale
|
* @param scale
|
||||||
*/
|
*/
|
||||||
@JvmOverloads fun render(g: Graphics, posX: Float, posY: Float, scale: Float = 1f) {
|
@JvmOverloads fun render(g: Graphics, posX: Float, posY: Float, scale: Float = 1f) {
|
||||||
var scale = scale
|
|
||||||
scale *= Terrarum.ingame.screenZoom
|
|
||||||
|
|
||||||
// Null checking
|
// Null checking
|
||||||
if (currentImage == null) {
|
if (currentImage == null) {
|
||||||
currentImage = getScaledSprite(scale)
|
currentImage = getScaledSprite(scale)
|
||||||
@@ -139,8 +136,8 @@ constructor() {
|
|||||||
|
|
||||||
flippedImage.startUse()
|
flippedImage.startUse()
|
||||||
flippedImage.drawEmbedded(
|
flippedImage.drawEmbedded(
|
||||||
Math.round(posX * Terrarum.ingame.screenZoom).toFloat(),
|
Math.round(posX).toFloat(),
|
||||||
FastMath.floor(posY * Terrarum.ingame.screenZoom).toFloat(),
|
FastMath.floor(posY).toFloat(),
|
||||||
FastMath.floor(width * scale).toFloat(),
|
FastMath.floor(width * scale).toFloat(),
|
||||||
FastMath.floor(height * scale).toFloat()
|
FastMath.floor(height * scale).toFloat()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ constructor() : BasicGameState() {
|
|||||||
val ZOOM_MAX = 2.0f
|
val ZOOM_MAX = 2.0f
|
||||||
val ZOOM_MIN = 0.5f
|
val ZOOM_MIN = 0.5f
|
||||||
|
|
||||||
|
val tilesDrawFrameBuffer = Image(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||||
|
val actorsDrawFrameBuffer = Image(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||||
|
val uisDrawFrameBuffer = Image(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||||
|
|
||||||
private lateinit var shader12BitCol: Shader
|
private lateinit var shader12BitCol: Shader
|
||||||
private lateinit var shaderBlurH: Shader
|
private lateinit var shaderBlurH: Shader
|
||||||
private lateinit var shaderBlurV: Shader
|
private lateinit var shaderBlurV: Shader
|
||||||
@@ -263,24 +267,32 @@ constructor() : BasicGameState() {
|
|||||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.totalVMMem}M")
|
" — M: ${Terrarum.memInUse}M / ${Terrarum.totalVMMem}M")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
override fun render(gc: GameContainer, sbg: StateBasedGame, gwin: Graphics) {
|
||||||
g.isAntiAlias = true
|
// clean the shit beforehand
|
||||||
|
tilesDrawFrameBuffer.graphics.clear()
|
||||||
|
actorsDrawFrameBuffer.graphics.clear()
|
||||||
|
uisDrawFrameBuffer.graphics.clear()
|
||||||
|
|
||||||
|
|
||||||
|
gwin.isAntiAlias = true
|
||||||
blendNormal()
|
blendNormal()
|
||||||
|
|
||||||
|
|
||||||
drawSkybox(g)
|
drawSkybox(tilesDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
|
|
||||||
// make camara work //
|
// make camara work //
|
||||||
// compensate for zoom. UIs must be treated specially! (see UIHandler)
|
// compensate for zoom. UIs must be treated specially! (see UIHandler)
|
||||||
g.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
|
//g.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
|
||||||
|
tilesDrawFrameBuffer.graphics.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
|
||||||
|
actorsDrawFrameBuffer.graphics.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
|
||||||
// TODO add new framebuffer so that whole map is zoomed at once, yet not the UI
|
// TODO add new framebuffer so that whole map is zoomed at once, yet not the UI
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// draw map related stuffs //
|
// draw map related stuffs //
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
MapCamera.renderBehind(gc, g)
|
MapCamera.renderBehind(gc, tilesDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
@@ -288,10 +300,10 @@ constructor() : BasicGameState() {
|
|||||||
/////////////////
|
/////////////////
|
||||||
actorContainer.forEach { actor ->
|
actorContainer.forEach { actor ->
|
||||||
if (actor is Visible && actor.inScreen() && actor !is Player) { // if echo and within screen
|
if (actor is Visible && actor.inScreen() && actor !is Player) { // if echo and within screen
|
||||||
actor.drawBody(gc, g)
|
actor.drawBody(gc, actorsDrawFrameBuffer.graphics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.drawBody(gc, g)
|
player.drawBody(gc, actorsDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -299,15 +311,15 @@ constructor() : BasicGameState() {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
LightmapRenderer.renderLightMap()
|
LightmapRenderer.renderLightMap()
|
||||||
|
|
||||||
MapCamera.renderFront(gc, g)
|
MapCamera.renderFront(gc, tilesDrawFrameBuffer.graphics)
|
||||||
MapDrawer.render(gc, g)
|
MapDrawer.render(gc, tilesDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
|
|
||||||
blendMul()
|
blendMul()
|
||||||
MapDrawer.drawEnvOverlay(g)
|
MapDrawer.drawEnvOverlay(actorsDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() else blendNormal()
|
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() else blendNormal()
|
||||||
LightmapRenderer.draw(g)
|
LightmapRenderer.draw(actorsDrawFrameBuffer.graphics)
|
||||||
blendNormal()
|
blendNormal()
|
||||||
|
|
||||||
|
|
||||||
@@ -316,10 +328,10 @@ constructor() : BasicGameState() {
|
|||||||
//////////////////////
|
//////////////////////
|
||||||
actorContainer.forEach { actor ->
|
actorContainer.forEach { actor ->
|
||||||
if (actor is Visible && actor.inScreen() && actor !is Player) { // if echo and within screen
|
if (actor is Visible && actor.inScreen() && actor !is Player) { // if echo and within screen
|
||||||
actor.drawGlow(gc, g)
|
actor.drawGlow(gc, actorsDrawFrameBuffer.graphics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.drawGlow(gc, g)
|
player.drawGlow(gc, actorsDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
@@ -329,17 +341,17 @@ constructor() : BasicGameState() {
|
|||||||
if (debugWindow.isVisible) {
|
if (debugWindow.isVisible) {
|
||||||
actorContainer.forEachIndexed { i, actor ->
|
actorContainer.forEachIndexed { i, actor ->
|
||||||
if (actor is Visible) {
|
if (actor is Visible) {
|
||||||
g.color = Color.white
|
actorsDrawFrameBuffer.graphics.color = Color.white
|
||||||
g.font = Terrarum.fontSmallNumbers
|
actorsDrawFrameBuffer.graphics.font = Terrarum.fontSmallNumbers
|
||||||
g.drawString(
|
actorsDrawFrameBuffer.graphics.drawString(
|
||||||
actor.referenceID.toString(),
|
actor.referenceID.toString(),
|
||||||
actor.hitbox.posX.toFloat(),
|
actor.hitbox.posX.toFloat(),
|
||||||
actor.hitbox.pointedY.toFloat() + 4
|
actor.hitbox.pointedY.toFloat() + 4
|
||||||
)
|
)
|
||||||
|
|
||||||
if (DEBUG_ARRAY) {
|
if (DEBUG_ARRAY) {
|
||||||
g.color = GameFontBase.codeToCol["g"]
|
actorsDrawFrameBuffer.graphics.color = GameFontBase.codeToCol["g"]
|
||||||
g.drawString(
|
actorsDrawFrameBuffer.graphics.drawString(
|
||||||
i.toString(),
|
i.toString(),
|
||||||
actor.hitbox.posX.toFloat(),
|
actor.hitbox.posX.toFloat(),
|
||||||
actor.hitbox.pointedY.toFloat() + 4 + 10
|
actor.hitbox.pointedY.toFloat() + 4 + 10
|
||||||
@@ -350,16 +362,24 @@ constructor() : BasicGameState() {
|
|||||||
}
|
}
|
||||||
// fluidmap debug
|
// fluidmap debug
|
||||||
if (KeyToggler.isOn(Key.F4))
|
if (KeyToggler.isOn(Key.F4))
|
||||||
WorldSimulator.drawFluidMapDebug(g)
|
WorldSimulator.drawFluidMapDebug(actorsDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
// draw UIs //
|
// draw UIs //
|
||||||
//////////////
|
//////////////
|
||||||
uiContainer.forEach { ui -> ui.render(gc, sbg, g) }
|
uiContainer.forEach { ui -> ui.render(gc, sbg, uisDrawFrameBuffer.graphics) }
|
||||||
debugWindow.render(gc, sbg, g)
|
debugWindow.render(gc, sbg, uisDrawFrameBuffer.graphics)
|
||||||
consoleHandler.render(gc, sbg, g)
|
consoleHandler.render(gc, sbg, uisDrawFrameBuffer.graphics)
|
||||||
notifier.render(gc, sbg, g)
|
notifier.render(gc, sbg, uisDrawFrameBuffer.graphics)
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////
|
||||||
|
// draw layers //
|
||||||
|
/////////////////
|
||||||
|
gwin.drawImage(tilesDrawFrameBuffer, 0f, 0f)
|
||||||
|
gwin.drawImage(actorsDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f)
|
||||||
|
gwin.drawImage(uisDrawFrameBuffer, 0f, 0f)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun keyPressed(key: Int, c: Char) {
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
|
|||||||
@@ -120,22 +120,12 @@ constructor(val UI: UICanvas) {
|
|||||||
UIGraphicInstance.font = Terrarum.fontGame
|
UIGraphicInstance.font = Terrarum.fontGame
|
||||||
|
|
||||||
UI.render(gc, UIGraphicInstance)
|
UI.render(gc, UIGraphicInstance)
|
||||||
if (sbg.currentStateID == Terrarum.STATE_ID_GAME) {
|
|
||||||
ingameGraphics.drawImage(UIDrawnCanvas.getScaledCopy(scale),
|
|
||||||
posX + MapCamera.cameraX * Terrarum.ingame.screenZoom - (UI.width / 2f * scale.minus(1)),
|
|
||||||
posY + MapCamera.cameraY * Terrarum.ingame.screenZoom - (UI.height / 2f * scale.minus(1)),
|
|
||||||
Color(1f, 1f, 1f, opacity)
|
|
||||||
)// compensate for screenZoom AND camera translation
|
|
||||||
// (see Game.render -> g.translate())
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ingameGraphics.drawImage(UIDrawnCanvas.getScaledCopy(scale),
|
|
||||||
posX.toFloat() - (UI.width / 2f * scale.minus(1)),
|
|
||||||
posY.toFloat() - (UI.height / 2f * scale.minus(1)),
|
|
||||||
Color(1f, 1f, 1f, opacity)
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
ingameGraphics.drawImage(UIDrawnCanvas.getScaledCopy(scale),
|
||||||
|
posX.toFloat() - (UI.width / 2f * scale.minus(1)),
|
||||||
|
posY.toFloat() - (UI.height / 2f * scale.minus(1)),
|
||||||
|
Color(1f, 1f, 1f, opacity)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user