Make research internally use identity hash map
This commit is contained in:
parent
2042b8a9ab
commit
1df4ed809f
@ -52,7 +52,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
|
|
||||||
private var willBecomeAndroidNetwork = false
|
private var willBecomeAndroidNetwork = false
|
||||||
private var shouldPlaySound = false
|
private var shouldPlaySound = false
|
||||||
private val research = ArrayList<AndroidResearch>()
|
private val research = IdentityHashMap<AndroidResearchType<*>, AndroidResearch>()
|
||||||
|
|
||||||
private var remoteBattery = ImpreciseFraction(-1)
|
private var remoteBattery = ImpreciseFraction(-1)
|
||||||
private var remoteMaxBattery = ImpreciseFraction(-1)
|
private var remoteMaxBattery = ImpreciseFraction(-1)
|
||||||
@ -117,7 +117,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
|
|
||||||
fun obliviate(refund: Boolean = true) {
|
fun obliviate(refund: Boolean = true) {
|
||||||
if (refund) {
|
if (refund) {
|
||||||
for (instance in research) {
|
for (instance in research.values) {
|
||||||
if (instance.isResearched) {
|
if (instance.isResearched) {
|
||||||
instance.unResearch()
|
instance.unResearch()
|
||||||
instance.refund(simulate = false)
|
instance.refund(simulate = false)
|
||||||
@ -133,15 +133,9 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun <T : AndroidResearch> getResearch(type: AndroidResearchType<T>): T {
|
fun <T : AndroidResearch> getResearch(type: AndroidResearchType<T>): T {
|
||||||
for (instance in research) {
|
return research.computeIfAbsent(type) {
|
||||||
if (instance.type === type) {
|
return@computeIfAbsent type.factory(this)
|
||||||
return instance as T
|
} as T
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val instance = type.factory(this)
|
|
||||||
research.add(instance)
|
|
||||||
return instance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addFeature(feature: AndroidFeature): Boolean {
|
private fun addFeature(feature: AndroidFeature): Boolean {
|
||||||
@ -257,10 +251,10 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
|
|
||||||
val list = ListTag()
|
val list = ListTag()
|
||||||
|
|
||||||
for (instance in research) {
|
for ((type, instance) in research) {
|
||||||
val researchTag = instance.serializeNBT()
|
val researchTag = instance.serializeNBT()
|
||||||
|
|
||||||
researchTag["id"] = instance.type.registryName!!.toString()
|
researchTag["id"] = type.registryName!!.toString()
|
||||||
list.add(researchTag)
|
list.add(researchTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +310,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
if (research != null) {
|
if (research != null) {
|
||||||
val instance = research.factory(this)
|
val instance = research.factory(this)
|
||||||
instance.deserializeNBT(tag)
|
instance.deserializeNBT(tag)
|
||||||
this.research.add(instance)
|
this.research[research] = instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -448,7 +442,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
remoteIsAndroid = false
|
remoteIsAndroid = false
|
||||||
willBecomeAndroidNetwork = false
|
willBecomeAndroidNetwork = false
|
||||||
|
|
||||||
for (instance in research) {
|
for (instance in research.values) {
|
||||||
instance.isDirty = true
|
instance.isDirty = true
|
||||||
instance.invalidateNetwork()
|
instance.invalidateNetwork()
|
||||||
}
|
}
|
||||||
@ -495,7 +489,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, IMatteryEn
|
|||||||
sendNetwork(WillBecomeAndroidPacket(willBecomeAndroid))
|
sendNetwork(WillBecomeAndroidPacket(willBecomeAndroid))
|
||||||
}
|
}
|
||||||
|
|
||||||
for (instance in research) {
|
for (instance in research.values) {
|
||||||
if (instance.isDirty) {
|
if (instance.isDirty) {
|
||||||
instance.isDirty = false
|
instance.isDirty = false
|
||||||
sendNetwork(AndroidResearchSyncPacket(instance))
|
sendNetwork(AndroidResearchSyncPacket(instance))
|
||||||
|
Loading…
Reference in New Issue
Block a user