Skip to content

Commit 9ec48cd

Browse files
committed
added previous session time
1 parent fe8d56b commit 9ec48cd

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

include/GameAnalytics/GameAnalytics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ namespace gameanalytics
120120

121121
static int64_t getElapsedSessionTime();
122122
static int64_t getElapsedTimeFromAllSessions();
123+
static int64_t getElapsedTimeForPreviousSession();
123124

124125
// game state changes
125126
// will affect how session is started / ended

source/gameanalytics/GAState.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ namespace gameanalytics
539539
return "";
540540
}
541541

542+
int64_t GAState::getLastSessionLength() const
543+
{
544+
return _lastSessionTime;
545+
}
546+
542547
int64_t GAState::getTotalSessionLength() const
543548
{
544549
return _totalElapsedSessionTime + calculateSessionLength<std::chrono::seconds>();
@@ -590,10 +595,11 @@ namespace gameanalytics
590595

591596
try
592597
{
593-
std::string cachedSessionTime = utilities::getOptionalValue<std::string>(state_dict, "total_session_time", "0");
598+
std::string cachedLastSessionTime = utilities::getOptionalValue<std::string>(state_dict, "last_session_time", "0");
599+
std::string cachedTotalSessionTime = utilities::getOptionalValue<std::string>(state_dict, "total_session_time", "0");
594600

595-
_totalElapsedSessionTime = std::stoull(cachedSessionTime);
596-
601+
_lastSessionTime = std::stoull(cachedTotalSessionTime);
602+
_totalElapsedSessionTime = std::stoull(cachedTotalSessionTime);
597603
}
598604
catch(const std::exception& e)
599605
{
@@ -1094,7 +1100,10 @@ namespace gameanalytics
10941100

10951101
void GAState::updateTotalSessionTime()
10961102
{
1097-
_totalElapsedSessionTime = getTotalSessionLength();
1103+
_lastSessionTime = calculateSessionLength();
1104+
_totalElapsedSessionTime += _lastSessionTime;
1105+
1106+
_gaStore.setState("last_session_time", std::to_string(_lastSessionTime));
10981107
_gaStore.setState("total_session_time", std::to_string(_totalElapsedSessionTime));
10991108
}
11001109

source/gameanalytics/GAState.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ namespace gameanalytics
169169

170170
int64_t getTotalSessionLength() const;
171171

172+
int64_t getLastSessionLength() const;
173+
172174
void populateConfigurations(json& sdkConfig);
173175

174176
json getRemoteConfigAnnotations();
@@ -229,6 +231,7 @@ namespace gameanalytics
229231
int64_t _sessionNum = 0;
230232
int64_t _transactionNum = 0;
231233

234+
int64_t _lastSessionTime = 0;
232235
int64_t _totalElapsedSessionTime = 0;
233236
std::chrono::high_resolution_clock::time_point _startTimepoint;
234237

source/gameanalytics/GameAnalytics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,4 +998,9 @@ namespace gameanalytics
998998
return state::GAState::getInstance().calculateSessionLength<std::chrono::seconds>();
999999
}
10001000

1001+
int64_t GameAnalytics::getElapsedTimeForPreviousSession()
1002+
{
1003+
return state::GAState::getInstance().getLastSessionLength();
1004+
}
1005+
10011006
} // namespace gameanalytics

0 commit comments

Comments
 (0)