X2CommunityCore / X2WOTCCommunityHighlander

https://steamcommunity.com/workshop/filedetails/?id=1134256495
MIT License
60 stars 68 forks source link

Cleanup Tactical Gamestate #178

Open Danice123 opened 6 years ago

Danice123 commented 6 years ago

Port from LW2 code CleanupObsoleteTacticalGamestate()

Switch blacklist to whitelist to prevent killing mod characters

Musashi1584 commented 6 years ago

@robojumper @Danice123 What is the purpose of this? Prevent crashes? improve performance?

RealityMachina commented 5 years ago

So to bump this a bit since I imagine we'll want to get around to this by the end of 2019 :

XCOM 2 for Shen's Last Gift, stopped cleaning up tactical only game states to accommodate tactical mission to tactical mission transfers, since the way vanilla XCOM 2 had done it (just caring only about what was brought into the mission originally) meant strategy information would've been lost, so Firaxis just went "alright we'll just take everything then".

But this now means that the game was effectively tracking the information of everything that happens in throughout a campaign. When LW2 came out, they dealt with this via creating their own custom cleanup code that this PR uses.

For WotC, this got resolved somewhat: stuff like ability and effect states are no longer passed over, but item states and unit states are still retained from previous missions.

This can bloat save files by a lot, to the point that when robojumper last tested this, it reduced the save file he used to test it by half.

Xymanek commented 4 years ago

Since the recent discord discussion on this topic, I would like to suggest a new heuristic that should cover most cases and not interfere with mod-added content

1) In the tactical ruleset, right at the beginning of "create tactical game", record1 the ObjectIDs of existing units 2) Right before the tactical game is unloaded, diff the current list of units with the recorded one, and the record the units that were added 3) Repeat 1 and 2 for every leg/path of the mission, collecting the results of 2. 4) When launching the next mission from strategy, loop through the recorded units and check whether they were modified since strategy start state. If they weren't2, delete them


1 We cannot rely on looking backwards through history as preplaced enemies are created during tactical start state 2 The assumption here is that the start state is barely used in strategy, so if anything actually makes use of these units post-mission then it would actually "touch" them in a (change) state


This would require creating a new XCGS_[...] class, but IMO this will allow to safely get rid of 90% of garbage units in the saves. That said, this approach has a downside that it won't automatically clean up units from previous missions - it will only work for missions started after this feature is released

Iridar commented 3 years ago

As I understand it, the problem is that the game preserves unit states and item states in History. Specifically the problem is with the History being bloated by dead enemies and their items, since XCOM's own units are typically much less numerous, and we actually need records about them for the purposes of memorial / reviving them later.

If that is the case, why is the need for the complicated "two steps forward, one step backward" approach? Why not just clean up all dead non-XCOM units and their items at the end of the mission?

Dragon-32 commented 2 years ago

FYI, released as a separate mod: Tactical State Cleaner

Looks like that originally implemented Danice's code as is, then updated with some checks for Rulers and other units to leave alone.