Tracking Offline Activity
An offline activity is defined as a game state progression that happens in the game (i.e., IGeneratorEntity automatic collection or ITimedBoost expirations) while the app is closed or in the background. The moment the app resumes, IdleKit's ActivityTrackingService
will attempt to process those offline activities by stepping through the various points in time that they occur from the moment the player left the game to the current systemTime.
The Flow
Note
Any time when a 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 Contents instanceId . This serialized timestamp allows the ActivityTrackingService
to know the time at which the player went offline.
Note
Refer to the startup document to learn more about the startup process.
During startup or when the app is paused (sent to the background), the
ActivityTrackingService
reads the timestamp in IUserSavedData corresponding to the current contentInstanceId (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.