support for screen-overlay actors; buildingmaker has light now

This commit is contained in:
Minjae Song
2018-12-12 02:49:09 +09:00
parent 258273fd25
commit 7a60ae0629
7 changed files with 69 additions and 30 deletions

View File

@@ -5,8 +5,8 @@
|8192..8447|Wires (256 possible)| |8192..8447|Wires (256 possible)|
|8448..32767|Items (static) (24320 possible)| |8448..32767|Items (static) (24320 possible)|
|32768..0x0FFF_FFFF|Items (dynamic\*) (268M possible)| |32768..0x0FFF_FFFF|Items (dynamic\*) (268M possible)|
|0x1000_0000..0x7FFF_FFFF|Actors| |0x1000_0000..0x7FFF_FFFF|Actors (1879M possible)|
|-2147483648..-1 (all negative numbers)|Faction| |-2147483648..-1 (all negative numbers)|Faction (2147M possible)|
* dynamic items have own properties that will persist through savegame. * dynamic items have own properties that will persist through savegame.
@@ -14,7 +14,8 @@ Actors range in-depth
|Range|Description| |Range|Description|
|-----|-----------| |-----|-----------|
|0x1000_0000..0x1FFF_FFFF|Rendered behind (e.g. tapestries) |0x1000_0000..0x1FFF_FFFF|Rendered behind (e.g. tapestries)|
|0x2000_0000..0x5FFF_FFFF|Regular actors (e.g. almost all of them) |0x2000_0000..0x4FFF_FFFF|Regular actors (e.g. almost all of them)|
|0x6000_0000..0x6FFF_FFFF|Special (e.g. weapon swung, bullets, dropped item, particles) |0x5000_0000..0x5FFF_FFFF|Special (e.g. weapon swung, bullets, dropped item, particles)|
|0x7000_0000..0x7FFF_FFFF|Rendered front (e.g. fake tile) |0x6000_0000..0x6FFF_FFFF|Rendered front (e.g. fake tile)|
|0x7000_0000..0x7FFF_FFFF|Rendered as screen overlay, not affected by light nor environment overlays|

View File

@@ -421,17 +421,17 @@ object Terrarum : Screen {
// jump right into the ingame // jump right into the ingame
val ingame = Ingame(batch) /*val ingame = Ingame(batch)
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong()) ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
LoadScreen.screenToLoad = ingame LoadScreen.screenToLoad = ingame
this.ingame = ingame this.ingame = ingame
setScreen(LoadScreen) setScreen(LoadScreen)*/
// title screen // title screen
//AppLoader.getINSTANCE().setScreen(TitleScreen(batch)) AppLoader.getINSTANCE().setScreen(TitleScreen(batch))
} }
fun setScreen(screen: Screen) { fun setScreen(screen: Screen) {
@@ -728,6 +728,7 @@ object Terrarum : Screen {
Actor.RenderOrder.MIDDLE -> Actor.RANGE_MIDDLE Actor.RenderOrder.MIDDLE -> Actor.RANGE_MIDDLE
Actor.RenderOrder.MIDTOP -> Actor.RANGE_MIDTOP Actor.RenderOrder.MIDTOP -> Actor.RANGE_MIDTOP
Actor.RenderOrder.FRONT -> Actor.RANGE_FRONT Actor.RenderOrder.FRONT -> Actor.RANGE_FRONT
Actor.RenderOrder.OVERLAY-> Actor.RANDE_OVERLAY
} }
} }
catch (gameNotInitialisedException: KotlinNullPointerException) { catch (gameNotInitialisedException: KotlinNullPointerException) {

View File

@@ -19,14 +19,16 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
BEHIND, // tapestries, some particles (obstructed by terrain) BEHIND, // tapestries, some particles (obstructed by terrain)
MIDDLE, // actors MIDDLE, // actors
MIDTOP, // bullets, thrown items MIDTOP, // bullets, thrown items
FRONT // fake tiles FRONT, // fake tiles
OVERLAY // screen overlay, not affected by lightmap
} }
companion object { companion object {
val RANGE_BEHIND = ACTORID_MIN..0x1FFF_FFFF val RANGE_BEHIND = ACTORID_MIN..0x1FFF_FFFF // 1
val RANGE_MIDDLE = 0x2000_0000..0x5FFF_FFFF val RANGE_MIDDLE = 0x2000_0000..0x4FFF_FFFF // 3
val RANGE_MIDTOP = 0x6000_0000..0x6FFF_FFFF val RANGE_MIDTOP = 0x5000_0000..0x5FFF_FFFF // 1
val RANGE_FRONT = 0x7000_0000..0x7FFF_FFFF val RANGE_FRONT = 0x6000_0000..0x6FFF_FFFF // 1
val RANDE_OVERLAY= 0x7000_0000..0x7FFF_FFFF // 1
} }
abstract fun update(delta: Float) abstract fun update(delta: Float)

View File

@@ -3,15 +3,13 @@ package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader import net.torvald.terrarum.*
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.Yaml
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.ui.Notification import net.torvald.terrarum.modulebasegame.ui.Notification
import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerToolbox import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerToolbox
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
@@ -56,18 +54,24 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
val uiContainer = ArrayList<UICanvas>() val uiContainer = ArrayList<UICanvas>()
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.FRONT) { val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
override var referenceID: ActorID? = Terrarum.generateUniqueReferenceID(renderOrder) override var referenceID: ActorID? = Terrarum.generateUniqueReferenceID(renderOrder)
val body = TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16) val body = TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16)
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0) override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
init {
this.actorValue[AVKey.LUMR] = 1.0
this.actorValue[AVKey.LUMG] = 1.0
}
override fun drawBody(batch: SpriteBatch) { override fun drawBody(batch: SpriteBatch) {
batch.color = Color.YELLOW batch.color = Color.YELLOW
batch.draw(body.get(0, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat()) batch.draw(body.get(0, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
} }
override fun drawGlow(batch: SpriteBatch) { } override fun drawGlow(batch: SpriteBatch) { }
override fun dispose() { override fun dispose() {
body.dispose() body.dispose()
} }
@@ -89,10 +93,13 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
protected var updateDeltaCounter = 0.0 protected var updateDeltaCounter = 0.0
protected val updateRate = 1.0 / Terrarum.TARGET_INTERNAL_FPS protected val updateRate = 1.0 / Terrarum.TARGET_INTERNAL_FPS
private val actorsRenderTop = ArrayList<ActorWithBody>() private val actorsRenderOverlay = ArrayList<ActorWithBody>()
init { init {
actorsRenderTop.add(blockPointingCursor) gameWorld.time.setTimeOfToday(WorldTime.HOUR_SEC * 10)
gameWorld.globalLight = Color(.8f,.8f,.8f,.8f)
actorsRenderOverlay.add(blockPointingCursor)
uiContainer.add(uiToolbox) uiContainer.add(uiToolbox)
uiContainer.add(notifier) uiContainer.add(notifier)
@@ -160,7 +167,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
} }
private fun renderGame() { private fun renderGame() {
IngameRenderer(world as GameWorldExtension, actorsRenderFront = actorsRenderTop, uisToDraw = uiContainer) IngameRenderer(world as GameWorldExtension, actorsRenderOverlay = actorsRenderOverlay, uisToDraw = uiContainer)
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {
@@ -171,7 +178,9 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
println("[BuildingMaker] Resize event") println("[BuildingMaker] Resize event")
} }
override fun dispose() {
IngameRenderer.dispose()
}
private val menuYaml = Yaml(""" private val menuYaml = Yaml("""
- File - File

View File

@@ -64,6 +64,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private val actorsRenderMiddle = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE) private val actorsRenderMiddle = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderMidTop = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE) private val actorsRenderMidTop = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderFront = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE) private val actorsRenderFront = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderOverlay= ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
//var screenZoom = 1.0f // definition moved to IngameInstance //var screenZoom = 1.0f // definition moved to IngameInstance
@@ -572,6 +573,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderMiddle, actorsRenderMiddle,
actorsRenderMidTop, actorsRenderMidTop,
actorsRenderFront, actorsRenderFront,
actorsRenderOverlay,
particlesContainer, particlesContainer,
actorNowPlaying, actorNowPlaying,
uiContainer uiContainer

View File

@@ -24,7 +24,8 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
*/ */
object IngameRenderer { object IngameRenderer {
private lateinit var batch: SpriteBatch /** for non-private use, use with care! */
lateinit var batch: SpriteBatch
private lateinit var camera: OrthographicCamera private lateinit var camera: OrthographicCamera
private lateinit var lightmapFboA: FrameBuffer private lateinit var lightmapFboA: FrameBuffer
@@ -59,11 +60,12 @@ object IngameRenderer {
operator fun invoke( operator fun invoke(
world: GameWorldExtension, world: GameWorldExtension,
actorsRenderBehind: List<ActorWithBody>? = null, actorsRenderBehind : List<ActorWithBody>? = null,
actorsRenderMiddle: List<ActorWithBody>? = null, actorsRenderMiddle : List<ActorWithBody>? = null,
actorsRenderMidTop: List<ActorWithBody>? = null, actorsRenderMidTop : List<ActorWithBody>? = null,
actorsRenderFront : List<ActorWithBody>? = null, actorsRenderFront : List<ActorWithBody>? = null,
particlesContainer: CircularArray<ParticleBase>? = null, actorsRenderOverlay: List<ActorWithBody>? = null,
particlesContainer : CircularArray<ParticleBase>? = null,
player: ActorWithBody? = null, player: ActorWithBody? = null,
uisToDraw: ArrayList<UICanvas>? = null uisToDraw: ArrayList<UICanvas>? = null
) { ) {
@@ -86,6 +88,7 @@ object IngameRenderer {
prepLightmapRGBA() prepLightmapRGBA()
drawToRGB(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) drawToRGB(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer)
drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer)
drawOverlayActors(actorsRenderOverlay)
// clear main or whatever super-FBO being used // clear main or whatever super-FBO being used
//clearBuffer() //clearBuffer()
@@ -391,6 +394,27 @@ object IngameRenderer {
blendNormal(batch) blendNormal(batch)
} }
private fun drawOverlayActors(actors: List<ActorWithBody>?) {
fboRGB_lightMixed.inAction(camera, batch) {
batch.inUse {
batch.shader = null
batch.color = Color.WHITE
}
setCameraPosition(0f, 0f)
// BlocksDrawer.renderWhateverGlow_WALL
batch.inUse {
moveCameraToWorldCoord()
actors?.forEach { it.drawBody(batch) }
}
setCameraPosition(0f, 0f)
// BlocksDrawer.renderWhateverGlow_TERRAIN
}
}
private fun init() { private fun init() {
if (!initDone) { if (!initDone) {

View File

@@ -45,7 +45,7 @@ object LightmapRenderer {
fun setWorld(world: GameWorld) { fun setWorld(world: GameWorld) {
try { try {
if (this.world != world) { if (this.world != world) {
println("World change detected -- old world: ${this.world.hashCode()}, new world: ${world.hashCode()}") printdbg(this, "World change detected -- old world: ${this.world.hashCode()}, new world: ${world.hashCode()}")
/*for (y in 0 until LIGHTMAP_HEIGHT) { /*for (y in 0 until LIGHTMAP_HEIGHT) {
for (x in 0 until LIGHTMAP_WIDTH) { for (x in 0 until LIGHTMAP_WIDTH) {