More concurrency problems avoided by creating a second cityStats to run the values on

This should also help speed things up, since we don't need to run the update() again to revert it!
This commit is contained in:
Yair Morgenstern 2021-01-26 22:34:38 +02:00
parent 3199098ae8
commit 894e520319

View File

@ -208,13 +208,15 @@ class CityConstructions {
We don't want to change our current construction queue - what if we have an empty queue,
this can affect the city if we run it on another thread like in ConstructionsTable -
So we run the numbers for the other construction
ALSO apparently if we run on the actual cityStats from another thread,
we get all sorts of fun concurrency problems when accessing various parts of the cityStats.
SO, we create an entirely new CityStats and iterate there - problem solve!
*/
val cityStats = CityStats()
cityStats.cityInfo = cityInfo
val construction = cityInfo.cityConstructions.getConstruction(constructionName)
cityInfo.cityStats.update(construction)
cityStatsForConstruction = cityInfo.cityStats.currentCityStats
// revert!
cityInfo.cityStats.update()
cityStats.update(construction)
cityStatsForConstruction = cityStats.currentCityStats
}
val production = cityStatsForConstruction.production.roundToInt()