wire actor renders; functionality still wip

This commit is contained in:
minjaesong
2021-07-31 14:18:46 +09:00
parent f64574db80
commit b10fb0a30b
8 changed files with 106 additions and 40 deletions

View File

@@ -53,7 +53,7 @@ object AssembleSheetPixmap {
val animRow = theAnim.row
val animFrame = properties.getFrameNumberFromName(frameName)
AppLoader.printdbg(this, "Frame to draw: $frameName (R$animRow C$animFrame)")
// AppLoader.printdbg(this, "Frame to draw: $frameName (R$animRow C$animFrame)")
drawFrame(animRow, animFrame, canvas, properties, bodyparts, transformList)

View File

@@ -225,7 +225,7 @@ object ModMgr {
object GameBlockLoader {
@JvmStatic operator fun invoke(module: String) {
BlockCodex(module, "blocks/blocks.csv")
WireCodex(module, "wires/wires.csv")
WireCodex(module, "wires/")
}
}

View File

@@ -32,9 +32,10 @@ object TerrarumAppConfiguration {
*/
const val VERSION_RAW = 0x000206D3
//////////////////////////////////
// CONFIGURATION FOR TILE MAKER //
//////////////////////////////////
//////////////////////////////////////////////////////////
// CONFIGURATION FOR TILE MAKER //
// MAKE SURE THESE VALUES ARE UNIQUE IN THE SOURCE CODE //
//////////////////////////////////////////////////////////
const val TILE_SIZE = 16
const val TILE_SIZEF = TILE_SIZE.toFloat()
const val TILE_SIZED = TILE_SIZE.toDouble()

View File

@@ -1,10 +1,14 @@
package net.torvald.terrarum.blockproperties
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.utils.CSVFetcher
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.apache.commons.csv.CSVRecord
import java.io.IOException
@@ -17,23 +21,34 @@ object WireCodex {
private val nullProp = WireProp()
/**
* `wire.csv` and texture for all wires are expected to be found in the given path.
*
* @param module name of the module
* @param path to the "wires" directory, not path to the CSV; must end with a slash!
*/
operator fun invoke(module: String, path: String) {
try {
val records = CSVFetcher.readFromModule(module, path)
AppLoader.printmsg(this, "Building wire properties table for module $module")
try {
val records = CSVFetcher.readFromModule(module, path + "wires.csv")
AppLoader.printmsg(this, "Building wire properties table")
records.forEach {
/*if (intVal(it, "id") == -1) {
setProp(nullProp, it)
}
else {
setProp(wireProps[intVal(it, "id")], it)
}*/
WireCodex.setProp(module, intVal(it, "id"), it)
//val tileId = "$module:${intVal(it, "id")}"
}
AppLoader.printmsg(this, "Registering wire textures into the resource pool")
wireProps.keys.forEach { id ->
val wireid = id.split(':').last().toInt()
CommonResourcePool.addToLoadingList(id) {
val t = TextureRegionPack(ModMgr.getPath(module, "$path$wireid.tga"), TILE_SIZE, TILE_SIZE)
/*return*/t
}
}
CommonResourcePool.loadAll()
}
catch (e: IOException) {
e.printStackTrace()

View File

@@ -214,9 +214,13 @@ open class ActorWithBody(renderOrder: RenderOrder, val physProp: PhysProperties)
(world!!.gravitation.y > 0 && isWalled(hitbox, COLLIDING_BOTTOM) ||
world!!.gravitation.y < 0 && isWalled(hitbox, COLLIDING_TOP))
}
/** Default to 'true' */
/**
* Toggles rendering
* Default to 'true' */
var isVisible = true
/** Default to 'true' */
/**
* Toggles the actual update
* Default to 'true' */
var isUpdate = true
var isNoSubjectToGrav = false
var isNoCollideWorld = false
@@ -230,6 +234,11 @@ open class ActorWithBody(renderOrder: RenderOrder, val physProp: PhysProperties)
*/
var isChronostasis = false
/**
* if set to TRUE, the ingame will not move the actor into the active list
*/
var forceDormant = false
/**
* Gravitational Constant G. Load from gameworld.
* [m / s^2]

View File

@@ -1,10 +1,44 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameitem.ItemID
/**
* Created by minjaesong on 2021-07-30.
*/
class WireActor(id: ActorID) : ActorWithBody(RenderOrder.WIRES, PhysProperties.IMMOBILE) {
init {
this.referenceID = id
referenceID = id
setHitboxDimension(2, 2, 0, 0)
}
private var oldWireId = ""
/**
* @param itemID must start with "wire@"
*/
fun setWire(itemID: ItemID, worldX: Int, worldY: Int) {
if (oldWireId != itemID) {
if (sprite == null) {
makeNewSprite(CommonResourcePool.getAsTextureRegionPack(itemID))
sprite!!.delays = floatArrayOf(1f,1f)
sprite!!.setRowsAndFrames(2, 16)
}
else sprite!!.setSpriteImage(CommonResourcePool.getAsTextureRegionPack(itemID))
oldWireId = itemID
}
setPosition(worldX * TILE_SIZE + 1.0, (worldY + 1.0) * TILE_SIZE - 1.0) // what the fuck?
sprite!!.currentRow = 1
sprite!!.currentFrame = 15
}
override fun update(delta: Float) {
// set autotiling here
// hint: manipulate `sprite!!.currentFrame`
}
}

View File

@@ -654,9 +654,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
private fun fillUpWiresBuffer() {
fun getOrMakeWireActor(num: Int): ActorWithBody {
fun getOrMakeWireActor(num: Int): WireActor {
return try {
getActorByID(ReferencingRanges.ACTORS_WIRES.first + num) as ActorWithBody
getActorByID(ReferencingRanges.ACTORS_WIRES.first + num) as WireActor
}
catch (_: IllegalArgumentException) {
val actor = WireActor(ReferencingRanges.ACTORS_WIRES.first + num)
@@ -665,29 +665,35 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
}
if (selectedWireRenderClass.isNotBlank()) {
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt()
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical - 1
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt()
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical - 1
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt()
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal - 1
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt()
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal - 1
var wiringCounter = 0
for (y in for_y_start..for_y_end) {
for (x in for_x_start..for_x_end) {
val wires = world.getAllWiresFrom(x, y)
var wiringCounter = 0
for (y in for_y_start..for_y_end) {
for (x in for_x_start..for_x_end) {
val wires = world.getAllWiresFrom(x, y)
wires?.forEach {
if (WireCodex[it].renderClass == selectedWireRenderClass) {
val wireActor = getOrMakeWireActor(wiringCounter)
wires?.forEach {
val wireActor = getOrMakeWireActor(wiringCounter)
// TODO setup the wire actor
wiringCounter += 1
}
if (WireCodex[it].renderClass == selectedWireRenderClass) {
wireActor.isUpdate = true
wireActor.isVisible = true
wireActor.forceDormant = false
wireActor.setWire(it, x, y)
}
else {
wireActor.isUpdate = false
wireActor.isVisible = false
wireActor.forceDormant = true
}
wiringCounter += 1
}
}
}
}
@@ -746,7 +752,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
var i = 0
while (i < actorContainerSize) { // loop through actorContainerInactive
val actor = actorContainerInactive[i]
if (actor is ActorWithBody && actor.inUpdateRange()) {
if (actor is ActorWithBody && actor.inUpdateRange() && !actor.forceDormant) {
activateDormantActor(actor) // duplicates are checked here
actorContainerSize -= 1
i-- // array removed 1 elem, so we also decrement counter by 1
@@ -773,7 +779,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
i-- // array removed 1 elem, so we also decrement counter by 1
}
// inactivate distant actors
else if (actor is ActorWithBody && !actor.inUpdateRange()) {
else if (actor is ActorWithBody && (!actor.inUpdateRange() || actor.forceDormant)) {
if (actor !is Projectile) { // if it's a projectile, don't inactivate it; just kill it.
actorContainerInactive.add(actor) // naïve add; duplicates are checked when the actor is re-activated
}

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import net.torvald.terrarum.*
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.langpack.Lang
@@ -40,7 +41,7 @@ internal class FixtureStorageChest(nameFun: () -> String) : FixtureBase(
(mainUI as UIStorageChest).chestInventory = this.inventory!!
(mainUI as UIStorageChest).chestNameFun = this.nameFun
setHitboxDimension(16, 16, 0, 0)
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, -1)
makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
sprite!!.setRowsAndFrames(1, 1)