mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 17:28:57 +07:00
Solved concurrent modification problems from TechManager.researchedTechnologies and civInfo.exploredTiles
This commit is contained in:
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 790 KiB After Width: | Height: | Size: 792 KiB |
@ -71,7 +71,7 @@ class CivilizationInfo {
|
|||||||
toReturn.scienceVictory = scienceVictory.clone()
|
toReturn.scienceVictory = scienceVictory.clone()
|
||||||
toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
|
toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
|
||||||
toReturn.cities = cities.map { it.clone() }
|
toReturn.cities = cities.map { it.clone() }
|
||||||
toReturn.exploredTiles.addAll(exploredTiles.toList()) // we actually fot a concurrent modification exception here, the toList should solve that
|
toReturn.exploredTiles.addAll(exploredTiles)
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,13 +222,17 @@ class CivilizationInfo {
|
|||||||
|
|
||||||
|
|
||||||
fun updateViewableTiles() {
|
fun updateViewableTiles() {
|
||||||
viewableTiles.clear()
|
val newViewableTiles = HashSet<TileInfo>()
|
||||||
viewableTiles.addAll(cities.flatMap { it.getTiles() }.flatMap { it.neighbors }) // tiles adjacent to city tiles
|
newViewableTiles.addAll(cities.flatMap { it.getTiles() }.flatMap { it.neighbors }) // tiles adjacent to city tiles
|
||||||
viewableTiles.addAll(getCivUnits().flatMap { it.getViewableTiles()})
|
newViewableTiles.addAll(getCivUnits().flatMap { it.getViewableTiles()})
|
||||||
|
viewableTiles = newViewableTiles // to avoid concurrent modification problems
|
||||||
|
|
||||||
// updating the viewable tiles also affects the explored tiles, obvs
|
// updating the viewable tiles also affects the explored tiles, obvs
|
||||||
viewableTiles.asSequence().map { it.position }
|
|
||||||
.filterNot { exploredTiles.contains(it) }.toCollection(exploredTiles)
|
val newExploredTiles = HashSet<Vector2>(exploredTiles)
|
||||||
|
newExploredTiles.addAll(newViewableTiles.asSequence().map { it.position }
|
||||||
|
.filterNot { exploredTiles.contains(it) })
|
||||||
|
exploredTiles = newExploredTiles // ditto
|
||||||
|
|
||||||
|
|
||||||
val viewedCivs = HashSet<CivilizationInfo>()
|
val viewedCivs = HashSet<CivilizationInfo>()
|
||||||
|
@ -10,7 +10,7 @@ import java.util.*
|
|||||||
|
|
||||||
class TechManager {
|
class TechManager {
|
||||||
@Transient lateinit var civInfo: CivilizationInfo
|
@Transient lateinit var civInfo: CivilizationInfo
|
||||||
@Transient val researchedTechnologies=ArrayList<Technology>()
|
@Transient var researchedTechnologies=ArrayList<Technology>()
|
||||||
|
|
||||||
var freeTechs = 0
|
var freeTechs = 0
|
||||||
var techsResearched = HashSet<String>()
|
var techsResearched = HashSet<String>()
|
||||||
@ -75,7 +75,12 @@ class TechManager {
|
|||||||
if(currentTechnology!="Future Tech")
|
if(currentTechnology!="Future Tech")
|
||||||
techsToResearch.remove(currentTechnology)
|
techsToResearch.remove(currentTechnology)
|
||||||
techsResearched.add(currentTechnology)
|
techsResearched.add(currentTechnology)
|
||||||
researchedTechnologies.add(GameBasics.Technologies[currentTechnology]!!)
|
|
||||||
|
// this is to avoid concurrent modification problems
|
||||||
|
val newResearchedTechnologies = ArrayList(researchedTechnologies)
|
||||||
|
newResearchedTechnologies.add(GameBasics.Technologies[currentTechnology]!!)
|
||||||
|
researchedTechnologies = newResearchedTechnologies
|
||||||
|
|
||||||
civInfo.addNotification("Research of [$currentTechnology] has completed!", null, Color.BLUE)
|
civInfo.addNotification("Research of [$currentTechnology] has completed!", null, Color.BLUE)
|
||||||
|
|
||||||
val currentEra = civInfo.getEra()
|
val currentEra = civInfo.getEra()
|
||||||
|
Reference in New Issue
Block a user