Closed winex closed 7 months ago
damn! with this applied, i just got client-2 desync (gui opened for some minutes: TH->Basic->Construction Materials)
client-1 log has this, desync in 10 seconds after startConstruction()
was successful"
17723.113 Script @__tycoon__/city.lua:829: startConstruction(): coordinates: {x = 13, y = 6}
17734.212 Info ClientMultiplayerManager.cpp:747: updateTick(1558806) received player (2) desynced
after looking some more into this - i see many more calls from gui events, which we probably need to move out:
in Consumption::
getSupplyLevels()
calls updateProvidedAmounts()
. but we want separate calls for this because of gui
...or maybe i'm just missing something easier! :(
...converting PR to draft as it needs some more work!
so, these gui events might not caused desyncs, see https://github.com/bahrmichael/factorio-tycoon/issues/245#issuecomment-2006917728 and #289
but i still think this should be merged in some way as this is sooo hard to track! let's keep it here for some time until i get more data...
ok, finally returned to this PR and reworked it. looks ready. this can also improve performance on top of #303, can you re-profile it the same way?
can you re-profile it the same way?
Can't do that here unfortunately, as it needs a lot of clicking which is not as predictable as a loop that's just running all the time.
The change looks good to me, and it showed no bugs in testing 👍
best to be merged after #300 (or #308 at least) don't squash, pls
ok, i've reworked this, it's now not
fix-desync
, but "do less on gui events", but should still help against possible desyncs. didn't test it in multiplayer as #245 is not yet fixed fullyno need to call
Consumption::updateNeeds()
from gui as it is already called from:CityPlanner::initializeCity()
City::growCitizenCount()
on_entity_destroyed_event
(after #300 is merged)added:
Constants.CITY_STATS_LIFETIME_TICKS
-- 30 seconds should be finecity.stats.providedUpdateTick
little cleanup of
control.lua
byConstants
reusalnow,
Consumption.updateProvidedAmounts()
doesn't get called on each gui event for a city, only after its lifetime has passed. full code path is still a bit complex for my understanding, so i hope this doesn't conflict with original designplease review if i did this correctly, i.e.
game.tick
checktests
get no desyncs in 24 hours with this fix applied - then it can be merged asap.failedTODO: TEST: gui events setting 1 global var not to cause any desyncs againpostponedtodowe need to trigger
updateProvidedAmounts()
in deferred mode on gui events, update can be called fromcontrol.lua
's main loops. such vars are usually calleddirty
flag until it is cleared like that:old, already-merged, etc...
note: if some event calls
updateNeeds()
in similar "async" mode, likeon_construction...()
oron_built()
or w/e <-- should be looked into this first if desyncs happen again... ~~funcs such asgrowCitizenCount()
should not be written in handlers, so i reused better one fromCity::
class. yeah i know, that was a big refactoring - i've dug into some history...~~btw, i didn't testUtil.findCityByTownHallUnitNumber()
- i hopeassert()
works inon_gui_opened()
:)