mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
does this fix the segfault?
This commit is contained in:
@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.terrarum.*
|
||||
@@ -132,6 +133,8 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
get() = MaterialCodex.getOrDefault(materialId)
|
||||
abstract val materialId: String
|
||||
|
||||
@Transient private var itemImage0: TextureRegion? = null
|
||||
|
||||
/**
|
||||
* DO NOT READ FROM THIS VALUE: USE `ItemCodex.getItemImage(item)`;
|
||||
* this hack is needed to avoid the unsolvable issue regarding the ItemImage of the tiles, of which they
|
||||
@@ -160,23 +163,32 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
@Transient var itemImage: TextureRegion? = null
|
||||
set(tex) {
|
||||
field = tex
|
||||
tex?.let {
|
||||
val texdata = tex.texture.textureData.also {
|
||||
var itemImage: TextureRegion?
|
||||
get() = itemImage0
|
||||
set(textureRegion) {
|
||||
itemImage0 = textureRegion
|
||||
textureRegion?.let {
|
||||
val texdata = textureRegion.texture.textureData.also {
|
||||
if (!it.isPrepared) it.prepare()
|
||||
}
|
||||
itemImagePixmap = Pixmap(tex.regionWidth, tex.regionHeight, texdata.format).also {
|
||||
itemImagePixmap = Pixmap(textureRegion.regionWidth, textureRegion.regionHeight, texdata.format).also {
|
||||
it.drawPixmap(
|
||||
texdata.consumePixmap(),
|
||||
0, 0, tex.regionX, tex.regionY, tex.regionWidth, tex.regionHeight
|
||||
0, 0, textureRegion.regionX, textureRegion.regionY, textureRegion.regionWidth, textureRegion.regionHeight
|
||||
)
|
||||
App.disposables.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun setItemImage(pixmap: Pixmap) {
|
||||
val texture = TextureRegion(Texture(pixmap))
|
||||
App.disposables.add(texture.texture)
|
||||
this.itemImage0 = texture
|
||||
this.itemImagePixmap = pixmap
|
||||
}
|
||||
|
||||
@Transient open var itemImagePixmap: Pixmap? = null; internal set
|
||||
@Transient open val itemImageGlow: TextureRegion? = null
|
||||
@Transient open val itemImageEmissive: TextureRegion? = null
|
||||
|
||||
@@ -53,13 +53,13 @@ open class MusicDiscPrototype(originalID: ItemID, module: String, path: String)
|
||||
}
|
||||
|
||||
init {
|
||||
itemImage = generateSprite()
|
||||
setItemImage(generateSprite())
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a channel-wise black and white image and tints it using HSLuv colour space
|
||||
*/
|
||||
private fun generateSprite(): TextureRegion {
|
||||
private fun generateSprite(): Pixmap {
|
||||
val authorHash = XXHash64.hash(author.encodeToByteArray(), 54)
|
||||
val albumHash = XXHash64.hash(collection.encodeToByteArray(), 32)
|
||||
val nameHash = XXHash64.hash(name.encodeToByteArray(), 10)
|
||||
@@ -129,10 +129,7 @@ open class MusicDiscPrototype(originalID: ItemID, module: String, path: String)
|
||||
}
|
||||
}
|
||||
|
||||
val ret = TextureRegion(Texture(pixmap))
|
||||
pixmap.dispose()
|
||||
|
||||
return ret
|
||||
return pixmap
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user