Solved concurrent modification problems from TechManager.researchedTechnologies and civInfo.exploredTiles

This commit is contained in:
Yair Morgenstern 2018-11-27 22:48:41 +02:00
parent 6096bde9cd
commit ea68a70823
4 changed files with 367 additions and 365 deletions

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

View File

@ -71,7 +71,7 @@ class CivilizationInfo {
toReturn.scienceVictory = scienceVictory.clone()
toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
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
}
@ -222,13 +222,17 @@ class CivilizationInfo {
fun updateViewableTiles() {
viewableTiles.clear()
viewableTiles.addAll(cities.flatMap { it.getTiles() }.flatMap { it.neighbors }) // tiles adjacent to city tiles
viewableTiles.addAll(getCivUnits().flatMap { it.getViewableTiles()})
val newViewableTiles = HashSet<TileInfo>()
newViewableTiles.addAll(cities.flatMap { it.getTiles() }.flatMap { it.neighbors }) // tiles adjacent to city tiles
newViewableTiles.addAll(getCivUnits().flatMap { it.getViewableTiles()})
viewableTiles = newViewableTiles // to avoid concurrent modification problems
// 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>()

View File

@ -10,7 +10,7 @@ import java.util.*
class TechManager {
@Transient lateinit var civInfo: CivilizationInfo
@Transient val researchedTechnologies=ArrayList<Technology>()
@Transient var researchedTechnologies=ArrayList<Technology>()
var freeTechs = 0
var techsResearched = HashSet<String>()
@ -75,7 +75,12 @@ class TechManager {
if(currentTechnology!="Future Tech")
techsToResearch.remove(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)
val currentEra = civInfo.getEra()