discarding the idea of baking assembledsprite onto a spritesheet; revert to the commit right before this to completely scrap the efforts

This commit is contained in:
minjaesong
2022-03-23 17:43:56 +09:00
parent ab73511042
commit 765ece0635
21 changed files with 360 additions and 108 deletions

View File

@@ -375,6 +375,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
// don't put it on the postInit() or render(); postInitForNewGame calls this function on the savegamewriter's callback
makeSavegameBackupCopy(getWorldSaveFiledesc(worldSavefileName))
makeSavegameBackupCopy(getPlayerSaveFiledesc(playerSavefileName))
printdbg(this, "postInitForLoadFromSave exit")
}
private val autosaveOnErrorAction = { e: Throwable -> uiAutosaveNotifier.setAsError() }
@@ -703,7 +705,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
gameFullyLoaded = true
}
ingameController.update()
@@ -725,8 +726,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
}
setDebugTime("Ingame.UpdateCounter", i)
/** RENDER CODE GOES HERE */
measureDebugTime("Ingame.Render") { renderGame() }
@@ -768,7 +767,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
////////////////////////////
FeaturesDrawer.update(delta)
///////////////////////////
// actor-related updates //
///////////////////////////
@@ -822,6 +820,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
WORLD_UPDATE_TIMER += 1
}
if (!paused || newWorldLoadedLatch) {
// completely consume block change queues because why not
terrainChangeQueue.clear()
@@ -831,7 +830,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
oldSelectedWireRenderClass = selectedWireRenderClass
}
////////////////////////
// ui-related updates //
////////////////////////
@@ -1105,7 +1103,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
// rebuild the disk skimmers
INGAME.actorContainerActive.filterIsInstance<IngamePlayer>().forEach {
printdbg(this, "Game Save callback -- rebuilding the disk skimmer for IngamePlayer ${it.actorValue.getAsString(AVKey.NAME)}")
it.rebuildingDiskSkimmer?.rebuild()
// it.rebuildingDiskSkimmer?.rebuild()
}
// return to normal state

View File

@@ -4,7 +4,9 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec
import net.torvald.spriteanimation.AssembledSpriteAnimation
import net.torvald.spriteanimation.HasAssembledSprite
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
@@ -722,8 +724,14 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
if (walledBottom && controllerV?.x != 0.0) {
//switch row
sprite?.switchRow(SPRITE_ROW_WALK)
spriteGlow?.switchRow(SPRITE_ROW_WALK)
if (this is HasAssembledSprite) {
(sprite as? AssembledSpriteAnimation)?.currentAnimation = "ANIM_RUN"
(spriteGlow as? AssembledSpriteAnimation)?.currentAnimation = "ANIM_RUN"
}
else {
(sprite as? SheetSpriteAnimation)?.switchRow(SPRITE_ROW_WALK)
(spriteGlow as? SheetSpriteAnimation)?.switchRow(SPRITE_ROW_WALK)
}
// set anim frame delay
if (this is HasAssembledSprite) {
@@ -736,8 +744,8 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
val finalDelay = baseDelay * (scaleCompensation / moveSpeedMult)
sprite?.delays?.set(SPRITE_ROW_WALK, finalDelay)
spriteGlow?.delays?.set(SPRITE_ROW_WALK, finalDelay)
(sprite as? AssembledSpriteAnimation)?.overrideDelay = finalDelay
(spriteGlow as? AssembledSpriteAnimation)?.overrideDelay = finalDelay
}
catch (e: NullPointerException) {
println(animDesc!!.animations.keys.joinToString())
@@ -757,8 +765,17 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
}
}
else {
sprite?.switchRow(SPRITE_ROW_IDLE)
spriteGlow?.switchRow(SPRITE_ROW_IDLE)
if (this is HasAssembledSprite) {
(sprite as? AssembledSpriteAnimation)?.currentAnimation = "ANIM_IDLE"
(spriteGlow as? AssembledSpriteAnimation)?.currentAnimation = "ANIM_IDLE"
(sprite as? AssembledSpriteAnimation)?.overrideDelay = 0f
(spriteGlow as? AssembledSpriteAnimation)?.overrideDelay = 0f
}
else {
(sprite as? SheetSpriteAnimation)?.switchRow(SPRITE_ROW_IDLE)
(spriteGlow as? SheetSpriteAnimation)?.switchRow(SPRITE_ROW_IDLE)
}
}
}
}

View File

@@ -29,8 +29,9 @@ class FixtureLogicSignalEmitter : FixtureBase, Electric {
density = 1400.0
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, -1)
makeNewSprite(TextureRegionPack(itemImage.texture, TILE_SIZE, TILE_SIZE))
sprite!!.setRowsAndFrames(1, 1)
makeNewSprite(TextureRegionPack(itemImage.texture, TILE_SIZE, TILE_SIZE)).let {
it.setRowsAndFrames(1,1)
}
actorValue[AVKey.BASEMASS] = MASS
}

View File

@@ -40,8 +40,9 @@ internal class FixtureStorageChest : FixtureBase {
setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, -1)
makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
sprite!!.setRowsAndFrames(1, 1)
makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16)).let {
it.setRowsAndFrames(1,1)
}
actorValue[AVKey.BASEMASS] = MASS

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ModMgr
@@ -52,8 +53,9 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
lightBoxList.add(Lightbox(Hitbox(6.0, 5.0, 4.0, 3.0), color))
makeNewSprite(FixtureBase.getSpritesheet("basegame", "sprites/fixtures/tiki_torch.tga", 16, 32))
sprite!!.setRowsAndFrames(1, 2)
makeNewSprite(FixtureBase.getSpritesheet("basegame", "sprites/fixtures/tiki_torch.tga", 16, 32)).let {
it.setRowsAndFrames(1,2)
}
actorValue[AVKey.BASEMASS] = MASS
}
@@ -73,7 +75,7 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
spawnTimer -= nextDelay
nextDelay = rng.nextFloat() * 0.25f + 0.25f
sprite?.delays?.set(0, rng.nextFloat() * 0.4f + 0.1f)
(sprite as? SheetSpriteAnimation)?.delays?.set(0, rng.nextFloat() * 0.4f + 0.1f)
}
spawnTimer += delta

View File

@@ -83,9 +83,9 @@ class IngamePlayer : ActorHumanoid, HasAssembledSprite {
/** To be used later by the game to rebuild the sprite.
* Which `_rebuild` function to use is determined at the load time.
*/
@Transient private lateinit var rebuildfun: (item: GameItem?) -> Unit
@Transient private lateinit var rebuildfunGlow: (item: GameItem?) -> Unit
@Transient internal var rebuildingDiskSkimmer: DiskSkimmer? = null
// @Transient private lateinit var rebuildfun: (item: GameItem?) -> Unit
// @Transient private lateinit var rebuildfunGlow: (item: GameItem?) -> Unit
// @Transient internal var rebuildingDiskSkimmer: DiskSkimmer? = null
/**
* Example usage:
@@ -97,7 +97,7 @@ class IngamePlayer : ActorHumanoid, HasAssembledSprite {
* reassembleSprite(this.sprite, this.spriteGlow)
* ```
*/
override fun reassembleSprite(sprite: SpriteAnimation?, spriteGlow: SpriteAnimation?, heldItem: GameItem?) {
/*override fun reassembleSprite(sprite: SpriteAnimation?, spriteGlow: SpriteAnimation?, heldItem: GameItem?) {
if (animDesc != null && sprite != null) {
rebuildfun = { item: GameItem? -> _rebuild(animDesc!!, sprite, item) }; rebuildfun(heldItem)
spriteHeadTexture = AssembleSheetPixmap.getMugshotFromAssetsDir(animDesc!!)
@@ -119,9 +119,9 @@ class IngamePlayer : ActorHumanoid, HasAssembledSprite {
}
if (animDescGlow != null && spriteGlow != null)
rebuildfunGlow = { item: GameItem? -> _rebuild(disk, -1026L, animDescGlow!!, spriteGlow, item) }; rebuildfunGlow(heldItem)
}
}*/
private fun _rebuild(ad: ADProperties, sprite: SpriteAnimation, item: GameItem?) {
/*private fun _rebuild(ad: ADProperties, sprite: SpriteAnimation, item: GameItem?) {
// TODO injecting held item/armour pictures? Would it be AssembleSheetPixmap's job?
val pixmap = AssembleSheetPixmap.fromAssetsDir(ad, item)
@@ -167,15 +167,15 @@ class IngamePlayer : ActorHumanoid, HasAssembledSprite {
sprite.delays = newAnimDelays
sprite.nFrames = newAnimFrames
sprite.nRows = newAnimDelays.size
}
}*/
override fun getSpriteHead(): TextureRegion? {
/*override fun getSpriteHead(): TextureRegion? {
return spriteHeadTexture
}
}*/
@Transient private var unequipNoSpriteUpdate = false
override fun equipItem(item: GameItem) {
/*override fun equipItem(item: GameItem) {
val oldItemID = inventory.itemEquipped[item.equipPosition]
unequipNoSpriteUpdate = true
@@ -208,5 +208,5 @@ class IngamePlayer : ActorHumanoid, HasAssembledSprite {
// println("IngamePlayer.unequipItem")
// printStackTrace(this)
}
}*/
}

View File

@@ -10,7 +10,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2016-03-25.
*/
object PlayerBuilderCynthia {
/*object PlayerBuilderCynthia {
operator fun invoke(): ActorWithBody {
//val p: IngamePlayer = IngamePlayer(GameDate(100, 143)) // random value thrown
@@ -44,4 +44,4 @@ object PlayerBuilderCynthia {
}
}
}*/

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.spriteanimation.AssembledSpriteAnimation
import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.AVKey
@@ -27,9 +28,9 @@ object PlayerBuilderTestSubject1 {
p.sprite!!.delays = floatArrayOf(2f, 1f/12f) // second value does nothing -- overridden by ActorHumanoid.updateSprite(float)
p.sprite!!.setRowsAndFrames(2, 4)*/
p.sprite = SpriteAnimation(p)
p.spriteGlow = SpriteAnimation(p)
p.reassembleSprite(p.sprite, p.spriteGlow, null)
p.animDesc?.let { p.sprite = AssembledSpriteAnimation(it, p) }
p.animDescGlow?.let { p.spriteGlow = AssembledSpriteAnimation(it, p) }
//p.reassembleSprite(p.sprite, p.spriteGlow, null)
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT) ?: ActorHumanoid.BASE_HEIGHT, 21, 0)
// ingame must teleport the player to the spawn point

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.spriteanimation.AssembledSpriteAnimation
import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
@@ -28,9 +29,9 @@ object PlayerBuilderWerebeastTest {
p.sprite!!.delays = floatArrayOf(2f, 1f/12f) // second value does nothing -- overridden by ActorHumanoid.updateSprite(float)
p.sprite!!.setRowsAndFrames(2, 4)*/
p.sprite = SpriteAnimation(p)
p.spriteGlow = SpriteAnimation(p)
p.reassembleSprite(p.sprite, p.spriteGlow, null)
p.animDesc?.let { p.sprite = AssembledSpriteAnimation(it, p) }
p.animDescGlow?.let { p.spriteGlow = AssembledSpriteAnimation(it, p) }
//p.reassembleSprite(p.sprite, p.spriteGlow, null)
p.setHitboxDimension(22, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 30, 0)
p.setPosition(3.0 * TILE_SIZE, 3.0 * TILE_SIZE)

View File

@@ -120,7 +120,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
// rebuild the disk skimmers
INGAME.actorContainerActive.filterIsInstance<IngamePlayer>().forEach {
printdbg(this, "Game Save callback -- rebuilding the disk skimmer for IngamePlayer ${it.actorValue.getAsString(AVKey.NAME)}")
it.rebuildingDiskSkimmer?.rebuild()
// it.rebuildingDiskSkimmer?.rebuild()
}
// return to normal state

View File

@@ -3,6 +3,8 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.spriteanimation.AssembledSpriteAnimation
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.itemListHeight
@@ -85,11 +87,17 @@ class UIItemInventoryEquippedView(
blendNormal(batch)
batch.color = SPRITE_DRAW_COL
batch.draw(
it.textureRegion.get(0, 0),
posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(),
posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat()
)
if (it is SheetSpriteAnimation) {
batch.draw(
it.textureRegion.get(0, 0),
posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(),
posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat()
)
}
else if (it is AssembledSpriteAnimation) {
// TODO
}
}

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.utils.GdxRuntimeException
import com.badlogic.gdx.utils.JsonReader
import com.jme3.math.FastMath
import net.torvald.unicode.EMDASH
@@ -28,6 +29,8 @@ import net.torvald.terrarum.serialise.SaveLoadError
import net.torvald.terrarum.spriteassembler.ADProperties
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_X
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_Y
import net.torvald.terrarum.spriteassembler.AssembleFrameBase
import net.torvald.terrarum.spriteassembler.AssembleSheetPixmap
import net.torvald.terrarum.ui.Movement
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
@@ -531,7 +534,7 @@ class UIItemPlayerCells(
"${d}d${h.toString().padStart(2,'0')}h${m.toString().padStart(2,'0')}m${s.toString().padStart(2,'0')}s"
}
private var sprite: SpriteAnimation? = null
private var sprite: TextureRegion? = null
internal var hasTexture = false
private set
@@ -556,16 +559,47 @@ class UIItemPlayerCells(
if (skimmer.initialised && !hasTexture) {
skimmer.getFile(-1L)?.bytes?.let {
try {
val frameName = "ANIM_IDLE_1"
val animFile = skimmer.getFile(-2L)!!
val p = ReadPlayer(skimmer, ByteArray64Reader(it, Common.CHARSET))
p.sprite = SpriteAnimation(p)
p.animDesc = ADProperties(ByteArray64Reader(animFile.bytes, Common.CHARSET))
p.reassembleSpriteFromDisk(skimmer, p.sprite, null, null)
p.sprite!!.textureRegion.get(0,0).let {
thumb = it
thumb!!.flip(false, false)
}
this.sprite = p.sprite
val properties = ADProperties(ByteArray64Reader(animFile.bytes, Common.CHARSET))
val imagesSelfContained = skimmer.hasEntry(-1025L)
val bodypartMapping = Properties().also { if (imagesSelfContained) it.load(ByteArray64Reader(skimmer.getFile(-1025L)!!.bytes, Common.CHARSET)) }
val fileGetter = if (imagesSelfContained)
AssembleSheetPixmap.getVirtualDiskFileGetter(bodypartMapping, skimmer)
else
AssembleSheetPixmap.getAssetsDirFileGetter(properties)
// println(properties.transforms.keys)
val canvas = Pixmap(properties.cols * (properties.frameWidth), properties.rows * (properties.frameHeight), Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.SourceOver }
val theAnim = properties.getAnimByFrameName(frameName)
val skeleton = theAnim.skeleton.joints.reversed()
val transforms = properties.getTransform(frameName)
val bodypartOrigins = properties.bodypartJoints
val bodypartImages = properties.bodypartJoints.keys.map { partname ->
fileGetter(partname).let { file ->
if (file == null) partname to null
else {
try {
val bytes = file.readAllBytes()
partname to Pixmap(bytes, 0, bytes.size)
}
catch (e: GdxRuntimeException) {
partname to null
}
}
}
}.toMap()
val transformList = AssembleFrameBase.makeTransformList(skeleton, transforms)
// manually draw 0th frame of ANIM_IDLE
AssembleSheetPixmap.drawFrame(0, 0, canvas, properties, bodypartOrigins, bodypartImages, transformList, null)
bodypartImages.values.forEach { it?.dispose() }
this.sprite = TextureRegion(Texture(canvas))
}
catch (e: Throwable) {
throw SaveLoadError(skimmer.diskFile, e)
@@ -620,7 +654,7 @@ class UIItemPlayerCells(
override fun dispose() {
thumb?.texture?.dispose()
thumbPixmap?.dispose()
sprite?.dispose()
sprite?.texture?.dispose()
}