X2CommunityCore / X2WOTCCommunityHighlander

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

Allow mods to gracefully prevent geoscape tick #425

Closed Xymanek closed 3 years ago

Xymanek commented 5 years ago

XGGeoscape:

event Tick( float fDeltaT )
{
    fGameTime = fDeltaT * m_fTimeScale;

    // ....

    // IF( PAUSED )
    if (fGameTime == 0)
    {
        UpdateUIVisualsOnly();
        return;
    }

Adding an event before if (fGameTime == 0) will allow mods to prevent the game tick. Eg. opening a screen upon entering geoscape, but only when the game is ready to tick (no other interactions are going on)

Iridar commented 3 years ago

Purely out of curiosity, what are the go-to use cases for this?

Also, isn't ticking done a lot? Triggering an event for every tick is not deemed excessive?

Xymanek commented 3 years ago

CI has 2 uses for this:

1) Opening the covert actions screen (which needs to be on top of the geospace) from the event queue in the avenger 2) Preventing time from progressing when the game is in a "must launch infiltration" state

In both cases, nothing must happen between opening the geoscape and the screen opening on top of it. Geoscape is actually a bit of a painful opening and at least one tick will happen even if you try to instantly open another screen on top (which normally pauses the time).

Also, isn't ticking done a lot? Triggering an event for every tick is not deemed excessive?

Robojumper has done testing and triggering events with 0 listeners is extremely cheap. So subscribing to this with a listener template is indeed a bad idea, but CI doesn't do that, it uses "temporary" listener registrations only.

In hindsight, the only bad aspect is the GC thrashing with a new tuple every frame. I don't expect unreal's GC to break apart due to this (especially since the reachability path is very simple - it's either directly in a root or not reachable at all), but it could've been easily avoided using either a singleton tuple or the delegates approach. Alas, it is too late now due to BC