mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
gson test in progress
This commit is contained in:
@@ -42,7 +42,6 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
override val isUnique: Boolean = false
|
||||
override var baseMass: Double = BlockCodex[i].density / 1000.0
|
||||
override var baseToolSize: Double? = null
|
||||
override var equipPosition = EquipPosition.HAND_GRIP
|
||||
override val originalName = BlockCodex[i % ItemCodex.ITEM_WALLS.first].nameKey
|
||||
override var stackable = true
|
||||
override var inventoryCategory = if (i in ItemCodex.ITEM_TILES) Category.BLOCK else Category.WALL
|
||||
@@ -50,6 +49,8 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
override val material = Material(0,0,0,0,0,0,0,0,0,0.0)
|
||||
|
||||
init {
|
||||
equipPosition = EquipPosition.HAND_GRIP
|
||||
|
||||
if (IS_DEVELOPMENT_BUILD)
|
||||
print("$originalID ")
|
||||
}
|
||||
@@ -61,7 +62,7 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
|
||||
// check for collision with actors (BLOCK only)
|
||||
if (this.inventoryCategory == Category.BLOCK) {
|
||||
ingame.actorContainer.forEach {
|
||||
ingame.actorContainerActive.forEach {
|
||||
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
*/
|
||||
//val ACTORCONTAINER_INITIAL_SIZE = 64
|
||||
val PARTICLES_MAX = AppLoader.getConfigInt("maxparticles")
|
||||
//val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
//val actorContainerActive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
//val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
|
||||
val uiContainer = ArrayList<UICanvas>()
|
||||
@@ -156,6 +156,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
lateinit var gameworld: GameWorldExtension
|
||||
lateinit var theRealGamer: IngamePlayer
|
||||
|
||||
override var actorGamer: ActorHumanoid?
|
||||
get() = theRealGamer
|
||||
set(value) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
enum class GameLoadMode {
|
||||
CREATE_NEW, LOAD_FROM
|
||||
}
|
||||
@@ -611,10 +617,10 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
* if the actor is not to be dormant, it will be just ignored.
|
||||
*/
|
||||
fun KillOrKnockdownActors() {
|
||||
var actorContainerSize = actorContainer.size
|
||||
var actorContainerSize = actorContainerActive.size
|
||||
var i = 0
|
||||
while (i < actorContainerSize) { // loop through actorContainer
|
||||
val actor = actorContainer[i]
|
||||
while (i < actorContainerSize) { // loop through actorContainerActive
|
||||
val actor = actorContainerActive[i]
|
||||
val actorIndex = i
|
||||
// kill actors flagged to despawn
|
||||
if (actor.flagDespawn) {
|
||||
@@ -627,7 +633,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
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
|
||||
}
|
||||
actorContainer.removeAt(actorIndex)
|
||||
actorContainerActive.removeAt(actorIndex)
|
||||
actorContainerSize -= 1
|
||||
i-- // array removed 1 elem, so we also decrement counter by 1
|
||||
}
|
||||
@@ -641,8 +647,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
* NOTE: concurrency for actor updating is currently disabled because of it's poor performance
|
||||
*/
|
||||
fun updateActors(delta: Float) {
|
||||
if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainer.size > Terrarum.THREADS) {
|
||||
val actors = actorContainer.size.toFloat()
|
||||
if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainerActive.size > Terrarum.THREADS) {
|
||||
val actors = actorContainerActive.size.toFloat()
|
||||
// set up indices
|
||||
for (i in 0..Terrarum.THREADS - 1) {
|
||||
ThreadParallel.map(
|
||||
@@ -659,7 +665,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
actorNowPlaying?.update(delta)
|
||||
}
|
||||
else {
|
||||
actorContainer.forEach {
|
||||
actorContainerActive.forEach {
|
||||
if (it != actorNowPlaying) {
|
||||
it.update(delta)
|
||||
|
||||
@@ -736,12 +742,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
|
||||
throw RuntimeException("Attempted to remove player.")
|
||||
val indexToDelete = actorContainer.binarySearch(actor.referenceID!!)
|
||||
val indexToDelete = actorContainerActive.binarySearch(actor.referenceID!!)
|
||||
if (indexToDelete >= 0) {
|
||||
printdbg(this, "Removing actor $actor")
|
||||
printStackTrace()
|
||||
|
||||
actorContainer.removeAt(indexToDelete)
|
||||
actorContainerActive.removeAt(indexToDelete)
|
||||
|
||||
// indexToDelete >= 0 means that the actor certainly exists in the game
|
||||
// which means we don't need to check if i >= 0 again
|
||||
@@ -785,8 +791,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
printdbg(this, "Adding actor $actor")
|
||||
printStackTrace()
|
||||
|
||||
actorContainer.add(actor)
|
||||
insertionSortLastElem(actorContainer) // we can do this as we are only adding single actor
|
||||
actorContainerActive.add(actor)
|
||||
insertionSortLastElem(actorContainerActive) // we can do this as we are only adding single actor
|
||||
|
||||
if (actor is ActorWithBody) {
|
||||
when (actor.renderOrder) {
|
||||
@@ -819,8 +825,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
else {
|
||||
actorContainerInactive.remove(actor)
|
||||
actorContainer.add(actor)
|
||||
insertionSortLastElem(actorContainer) // we can do this as we are only adding single actor
|
||||
actorContainerActive.add(actor)
|
||||
insertionSortLastElem(actorContainerActive) // we can do this as we are only adding single actor
|
||||
|
||||
if (actor is ActorWithBody) {
|
||||
when (actor.renderOrder) {
|
||||
@@ -959,7 +965,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private fun printStackTrace() {
|
||||
Thread.currentThread().getStackTrace().forEach {
|
||||
printdbg(this, "-> $it")
|
||||
printdbg(this, "--> $it")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ internal object ActorsList : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
jPanelInstances.add(ActorsLister(
|
||||
(Terrarum.ingame!! as Ingame).actorContainer,
|
||||
(Terrarum.ingame!! as Ingame).actorContainerActive,
|
||||
(Terrarum.ingame!! as Ingame).actorContainerInactive)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,17 +2,13 @@ package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.serialise.WriteLayerDataLzma
|
||||
import net.torvald.terrarum.serialise.WriteLayerDataZip
|
||||
import net.torvald.terrarum.serialise.WriteWorldInfo
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-18.
|
||||
*/
|
||||
object ExportLayerData : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
try {
|
||||
/*try {
|
||||
val outfile = WriteLayerDataZip()
|
||||
WriteWorldInfo()
|
||||
Echo("Layer data exported to ${outfile!!.canonicalPath}")
|
||||
@@ -20,7 +16,7 @@ object ExportLayerData : ConsoleCommand {
|
||||
catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
EchoError("Layer data export failed; see console for error traces.")
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
|
||||
import java.io.BufferedWriter
|
||||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
@@ -17,9 +16,25 @@ import java.io.IOException
|
||||
internal object GsonTest : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).actorNowPlaying)
|
||||
|
||||
val jsonString = avelem.toString()
|
||||
val jsonBuilder = if (AppLoader.IS_DEVELOPMENT_BUILD) {
|
||||
GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
|
||||
.serializeNulls()
|
||||
.create()
|
||||
}
|
||||
else {
|
||||
GsonBuilder()
|
||||
.serializeNulls()
|
||||
.create()
|
||||
}
|
||||
|
||||
|
||||
val jsonString = jsonBuilder.toJson((Terrarum.ingame!! as Ingame).actorNowPlaying)
|
||||
|
||||
//val avelem = Gson().toJson((Terrarum.ingame!! as Ingame).actorNowPlaying)
|
||||
//val jsonString = avelem.toString()
|
||||
|
||||
val bufferedWriter: BufferedWriter
|
||||
val writer: FileWriter
|
||||
|
||||
@@ -153,7 +153,7 @@ open class ActorHumanoid(
|
||||
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.actorNowPlaying
|
||||
|
||||
|
||||
private val nullItem = object : GameItem() {
|
||||
@Transient private val nullItem = object : GameItem() {
|
||||
override var dynamicID: Int = 0
|
||||
override val originalID = dynamicID
|
||||
override val isUnique: Boolean = false
|
||||
|
||||
@@ -20,14 +20,16 @@ import java.util.concurrent.locks.ReentrantLock
|
||||
* Created by minjaesong on 2016-03-15.
|
||||
*/
|
||||
|
||||
class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode: Int) {
|
||||
class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var capacityMode: Int) {
|
||||
|
||||
companion object {
|
||||
@Transient val CAPACITY_MODE_NO_ENCUMBER = 0
|
||||
@Transient val CAPACITY_MODE_COUNT = 1
|
||||
@Transient val CAPACITY_MODE_WEIGHT = 2
|
||||
val CAPACITY_MODE_NO_ENCUMBER = 0
|
||||
val CAPACITY_MODE_COUNT = 1
|
||||
val CAPACITY_MODE_WEIGHT = 2
|
||||
}
|
||||
|
||||
// FIXME unless absolutely necessary, don't store full item object; only store its dynamicID
|
||||
|
||||
/**
|
||||
* List of all equipped items (tools, armours, rings, necklaces, etc.)
|
||||
*/
|
||||
@@ -265,8 +267,8 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
arr[j + 1] = x
|
||||
}
|
||||
}
|
||||
private val STATIC_ID = 41324534
|
||||
private val DYNAMIC_ID = 181643953
|
||||
@Transient private val STATIC_ID = 41324534
|
||||
@Transient private val DYNAMIC_ID = 181643953
|
||||
private fun ArrayList<InventoryPair>.binarySearch(ID: ItemID, searchBy: Int): Int {
|
||||
// code from collections/Collections.kt
|
||||
var low = 0
|
||||
|
||||
@@ -31,8 +31,8 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
|
||||
private val lifetimeMax = maxLifeTime ?: 5f
|
||||
private var lifetimeCounter = 0f
|
||||
|
||||
open val velocity = Vector2(0.0, 0.0)
|
||||
open val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
|
||||
val velocity = Vector2(0.0, 0.0)
|
||||
val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
|
||||
|
||||
open lateinit var body: TextureRegion // you might want to use SpriteAnimation
|
||||
open var glow: TextureRegion? = null
|
||||
@@ -61,7 +61,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
|
||||
|
||||
// gravity, winds, etc. (external forces)
|
||||
if (!isNoSubjectToGrav) {
|
||||
velocity += (Terrarum.ingame!!.world).gravitation / dragCoefficient
|
||||
velocity.plusAssign((Terrarum.ingame!!.world).gravitation / dragCoefficient)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.gameactors.Controllable
|
||||
|
||||
/**
|
||||
* A wrapper to support instant player changing (or possessing other NPCs maybe)
|
||||
*
|
||||
@@ -9,7 +7,7 @@ import net.torvald.terrarum.gameactors.Controllable
|
||||
* Created by minjaesong on 2016-10-23.
|
||||
*/
|
||||
@Deprecated("The ingame should discriminate 'theRealGamer' and 'actorNowPlaying'")
|
||||
class PlayableActorDelegate(val actor: ActorHumanoid) {
|
||||
class PlayableActorDelegate(@Transient val actor: ActorHumanoid) {
|
||||
|
||||
/*init {
|
||||
if (actor !is Controllable)
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.torvald.terrarum.Terrarum
|
||||
class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
|
||||
override fun run() {
|
||||
for (i in startIndex..endIndex) {
|
||||
val it = Terrarum.ingame!!.actorContainer[i]
|
||||
val it = Terrarum.ingame!!.actorContainerActive[i]
|
||||
it.update(AppLoader.UPDATE_RATE.toFloat())
|
||||
|
||||
if (it is Pocketed) {
|
||||
|
||||
@@ -39,7 +39,7 @@ object CollisionSolver {
|
||||
collCandidateY.clear()
|
||||
|
||||
// mark list x
|
||||
(Terrarum.ingame!! as Ingame).actorContainer.forEach { it ->
|
||||
(Terrarum.ingame!! as Ingame).actorContainerActive.forEach { it ->
|
||||
if (it is ActorWBMovable) {
|
||||
collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it))
|
||||
collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it))
|
||||
@@ -72,7 +72,7 @@ object CollisionSolver {
|
||||
collCandidateStack.clear()
|
||||
|
||||
// mark list y
|
||||
(Terrarum.ingame!! as Ingame).actorContainer.forEach { it ->
|
||||
(Terrarum.ingame!! as Ingame).actorContainerActive.forEach { it ->
|
||||
if (it is ActorWBMovable) {
|
||||
collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it))
|
||||
collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it))
|
||||
|
||||
@@ -21,15 +21,15 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
|
||||
override var baseMass = 10.0
|
||||
override var baseToolSize: Double? = 10.0
|
||||
override var stackable = true
|
||||
override var maxDurability = 147
|
||||
override var durability = maxDurability.toFloat()
|
||||
override val equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||
override var inventoryCategory = Category.TOOL
|
||||
override val isUnique = false
|
||||
override val isDynamic = true
|
||||
override val material = Material(0,0,0,0,0,0,0,0,1,0.0)
|
||||
override var isUnique = false
|
||||
override var isDynamic = true
|
||||
override var material = Material(0,0,0,0,0,0,0,0,1,0.0)
|
||||
|
||||
init {
|
||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||
super.maxDurability = 147
|
||||
super.durability = maxDurability.toFloat()
|
||||
super.name = "Builtin Pickaxe"
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
|
||||
|
||||
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
|
||||
// return false if hitting actors
|
||||
Terrarum.ingame!!.actorContainer.forEach {
|
||||
Terrarum.ingame!!.actorContainerActive.forEach {
|
||||
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user