Skip to content

Tracking Offline Activity

An offline activity is defined as a game state progression that happens in the game while the app is closed or in the background. These could be IGeneratorEntity automatic collection or ITimedBoost expirations. The moment the app resumes IdleKit's ActivityTrackingService will attempt to process those offline activities by simulating time since the player left the game and updating game state accordingly. This simulation starts when the player exits and brings the game up to date with SystemTime.

The Flow

Note

Any time an action is performed in the game or when the app is sent to the background the GameTime is recorded in the IUserSavedData along with the current ContentId . This serialized timestamp allows the ActivityTrackingService to know the time at which the player went offline.

activitytrackingservice

Note

Refer to the startup document to learn more about the startup process.

  • During startup or when the app is paused the ActivityTrackingService reads the timestamp in IUserSavedData corresponding to the current ContentId (the timestamp of the last activity performed in the current IContent ).

  • The timestamp from the IUserSavedData is used to set the GameTime as the starting point of the offline catchup.

  • After the IContent is initialized or the app is unpaused (returned to the foreground) before any other gameplay logic happens, the ActivityTrackingService would then catch up from the previously set GameTime to the current SystemTime.

  • The first half of the catchup process involves gathering all the timer listeners that have expired between the GameTime (start of the offline activities) and the SystemTime (end of the offline activities). The list is then filtered as we are only interested listeners that effect payout in the game (i.e., timed boosts). Lastly, the list gets sorted based on the timer listeners endTime chronologically.

  • During the second half of the catchup logic, we set the GameTime to each sorted timer listeners expiration time. Doing so allows us to perform time evaluations before each listener has expired (i.e., perform IGeneratorEntity collect evaluation before an ITimedBoost expires). After all the timer listeners have been processed, the offline catchup logic is complete, and the GameTime is set to the SystemTime.