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 c7d7ae03c0
commit bfea5c9936
7 changed files with 69 additions and 30 deletions

View File

@@ -5,8 +5,8 @@
|8192..8447|Wires (256 possible)|
|8448..32767|Items (static) (24320 possible)|
|32768..0x0FFF_FFFF|Items (dynamic\*) (268M possible)|
|0x1000_0000..0x7FFF_FFFF|Actors|
|-2147483648..-1 (all negative numbers)|Faction|
|0x1000_0000..0x7FFF_FFFF|Actors (1879M possible)|
|-2147483648..-1 (all negative numbers)|Faction (2147M possible)|
* dynamic items have own properties that will persist through savegame.
@@ -14,7 +14,8 @@ Actors range in-depth
|Range|Description|
|-----|-----------|
|0x1000_0000..0x1FFF_FFFF|Rendered behind (e.g. tapestries)
|0x2000_0000..0x5FFF_FFFF|Regular actors (e.g. almost all of them)
|0x6000_0000..0x6FFF_FFFF|Special (e.g. weapon swung, bullets, dropped item, particles)
|0x7000_0000..0x7FFF_FFFF|Rendered front (e.g. fake tile)
|0x1000_0000..0x1FFF_FFFF|Rendered behind (e.g. tapestries)|
|0x2000_0000..0x4FFF_FFFF|Regular actors (e.g. almost all of them)|
|0x5000_0000..0x5FFF_FFFF|Special (e.g. weapon swung, bullets, dropped item, particles)|
|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
val ingame = Ingame(batch)
/*val ingame = Ingame(batch)
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
LoadScreen.screenToLoad = ingame
this.ingame = ingame
setScreen(LoadScreen)
setScreen(LoadScreen)*/
// title screen
//AppLoader.getINSTANCE().setScreen(TitleScreen(batch))
AppLoader.getINSTANCE().setScreen(TitleScreen(batch))
}
fun setScreen(screen: Screen) {
@@ -728,6 +728,7 @@ object Terrarum : Screen {
Actor.RenderOrder.MIDDLE -> Actor.RANGE_MIDDLE
Actor.RenderOrder.MIDTOP -> Actor.RANGE_MIDTOP
Actor.RenderOrder.FRONT -> Actor.RANGE_FRONT
Actor.RenderOrder.OVERLAY-> Actor.RANDE_OVERLAY
}
}
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)
MIDDLE, // actors
MIDTOP, // bullets, thrown items
FRONT // fake tiles
FRONT, // fake tiles
OVERLAY // screen overlay, not affected by lightmap
}
companion object {
val RANGE_BEHIND = ACTORID_MIN..0x1FFF_FFFF
val RANGE_MIDDLE = 0x2000_0000..0x5FFF_FFFF
val RANGE_MIDTOP = 0x6000_0000..0x6FFF_FFFF
val RANGE_FRONT = 0x7000_0000..0x7FFF_FFFF
val RANGE_BEHIND = ACTORID_MIN..0x1FFF_FFFF // 1
val RANGE_MIDDLE = 0x2000_0000..0x4FFF_FFFF // 3
val RANGE_MIDTOP = 0x5000_0000..0x5FFF_FFFF // 1
val RANGE_FRONT = 0x6000_0000..0x6FFF_FFFF // 1
val RANDE_OVERLAY= 0x7000_0000..0x7FFF_FFFF // 1
}
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.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.Yaml
import net.torvald.terrarum.*
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
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.UIBuildingMakerToolbox
import net.torvald.terrarum.ui.UICanvas
@@ -56,18 +54,24 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
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)
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)
init {
this.actorValue[AVKey.LUMR] = 1.0
this.actorValue[AVKey.LUMG] = 1.0
}
override fun drawBody(batch: SpriteBatch) {
batch.color = Color.YELLOW
batch.draw(body.get(0, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
}
override fun drawGlow(batch: SpriteBatch) { }
override fun dispose() {
body.dispose()
}
@@ -89,10 +93,13 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
protected var updateDeltaCounter = 0.0
protected val updateRate = 1.0 / Terrarum.TARGET_INTERNAL_FPS
private val actorsRenderTop = ArrayList<ActorWithBody>()
private val actorsRenderOverlay = ArrayList<ActorWithBody>()
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(notifier)
@@ -160,7 +167,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
}
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) {
@@ -171,7 +178,9 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
println("[BuildingMaker] Resize event")
}
override fun dispose() {
IngameRenderer.dispose()
}
private val menuYaml = Yaml("""
- File

View File

@@ -64,6 +64,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private val actorsRenderMiddle = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderMidTop = 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
@@ -572,6 +573,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderMiddle,
actorsRenderMidTop,
actorsRenderFront,
actorsRenderOverlay,
particlesContainer,
actorNowPlaying,
uiContainer

View File

@@ -24,7 +24,8 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
*/
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 lightmapFboA: FrameBuffer
@@ -59,11 +60,12 @@ object IngameRenderer {
operator fun invoke(
world: GameWorldExtension,
actorsRenderBehind: List<ActorWithBody>? = null,
actorsRenderMiddle: List<ActorWithBody>? = null,
actorsRenderMidTop: List<ActorWithBody>? = null,
actorsRenderFront : List<ActorWithBody>? = null,
particlesContainer: CircularArray<ParticleBase>? = null,
actorsRenderBehind : List<ActorWithBody>? = null,
actorsRenderMiddle : List<ActorWithBody>? = null,
actorsRenderMidTop : List<ActorWithBody>? = null,
actorsRenderFront : List<ActorWithBody>? = null,
actorsRenderOverlay: List<ActorWithBody>? = null,
particlesContainer : CircularArray<ParticleBase>? = null,
player: ActorWithBody? = null,
uisToDraw: ArrayList<UICanvas>? = null
) {
@@ -86,6 +88,7 @@ object IngameRenderer {
prepLightmapRGBA()
drawToRGB(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer)
drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer)
drawOverlayActors(actorsRenderOverlay)
// clear main or whatever super-FBO being used
//clearBuffer()
@@ -391,6 +394,27 @@ object IngameRenderer {
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() {
if (!initDone) {

View File

@@ -45,7 +45,7 @@ object LightmapRenderer {
fun setWorld(world: GameWorld) {
try {
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 (x in 0 until LIGHTMAP_WIDTH) {