Skip to content

Commit cd67656

Browse files
authored
5.1.0 (#32)
v5.1.0
1 parent 134c11d commit cd67656

File tree

14 files changed

+260
-204
lines changed

14 files changed

+260
-204
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ elseif(APPLE)
190190
"-framework Foundation"
191191
"-framework CoreServices"
192192
"-framework SystemConfiguration"
193+
"-framework Metal"
194+
"-framework MetalKit"
193195
)
194196

195197
create_source_groups(MACOS_SOURCES)

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/GALogger.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ namespace gameanalytics
2626
return;
2727
}
2828

29+
if(logType == LogInfo && !getInstance().infoLogEnabled)
30+
{
31+
return;
32+
}
33+
2934
std::string tag = getInstance().tag;
3035
tag += " :";
3136

source/gameanalytics/GAState.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ namespace gameanalytics
426426
out["session_num"] = getInstance()._sessionNum;
427427
out["connection_type"] = device::GADevice::getConnectionType();
428428

429+
// playtime metrics
430+
out["current_session_length"] = getInstance().calculateSessionLength();
431+
out["lifetime_session_length"] = getInstance().getTotalSessionLength();
432+
429433
// ---- OPTIONAL ---- //
430434

431435
// A/B testing
@@ -535,6 +539,11 @@ namespace gameanalytics
535539
return "";
536540
}
537541

542+
int64_t GAState::getLastSessionLength() const
543+
{
544+
return _lastSessionTime;
545+
}
546+
538547
int64_t GAState::getTotalSessionLength() const
539548
{
540549
return _totalElapsedSessionTime + calculateSessionLength<std::chrono::seconds>();
@@ -586,10 +595,11 @@ namespace gameanalytics
586595

587596
try
588597
{
589-
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");
590600

591-
_totalElapsedSessionTime = std::stoull(cachedSessionTime);
592-
601+
_lastSessionTime = std::stoull(cachedLastSessionTime);
602+
_totalElapsedSessionTime = std::stoull(cachedTotalSessionTime);
593603
}
594604
catch(const std::exception& e)
595605
{
@@ -1090,8 +1100,11 @@ namespace gameanalytics
10901100

10911101
void GAState::updateTotalSessionTime()
10921102
{
1093-
int64_t totalSessionTime = getTotalSessionLength();
1094-
_gaStore.setState("total_session_time", std::to_string(totalSessionTime));
1103+
_lastSessionTime = calculateSessionLength();
1104+
_totalElapsedSessionTime += _lastSessionTime;
1105+
1106+
_gaStore.setState("last_session_time", std::to_string(_lastSessionTime));
1107+
_gaStore.setState("total_session_time", std::to_string(_totalElapsedSessionTime));
10951108
}
10961109

10971110
std::string GAState::getBuild()

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/GAStore.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -206,30 +206,6 @@ namespace gameanalytics
206206
{
207207
return sqlDatabase;
208208
}
209-
210-
bool GAStore::fixOldDatabase()
211-
{
212-
std::filesystem::path oldPath = dbPath;
213-
std::filesystem::path filename = oldPath.filename();
214-
215-
oldPath = oldPath.parent_path() / ".." / filename;
216-
217-
if(std::filesystem::exists(oldPath) && !std::filesystem::exists(dbPath))
218-
{
219-
try
220-
{
221-
std::filesystem::rename(oldPath, dbPath);
222-
}
223-
catch(...)
224-
{
225-
return false;
226-
}
227-
228-
return true;
229-
}
230-
231-
return false;
232-
}
233209

234210
bool GAStore::initDatabaseLocation()
235211
{
@@ -244,8 +220,6 @@ namespace gameanalytics
244220
{
245221
if(!std::filesystem::create_directory(p))
246222
return false;
247-
248-
fixOldDatabase();
249223
}
250224

251225
return true;

source/gameanalytics/GAValidator.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ namespace gameanalytics
275275

276276
bool validateProgressionString(std::string const& progression, ValidationResult& out, int progressionLvl)
277277
{
278+
if(progressionLvl > 0 && progression.empty())
279+
return true;
280+
278281
if (!GAValidator::validateEventPartLength(progression, true))
279282
{
280283
logging::GALogger::w("Validation fail - progression event - - progression0%d: Cannot be empty or above 64 characters. String: %s", progressionLvl + 1, progression.c_str());
@@ -458,17 +461,12 @@ namespace gameanalytics
458461
{
459462
constexpr uint32_t MAX_SIZE = 64u;
460463

461-
size_t size = eventPart.length();
462-
if (allowNull == true && size == 0)
464+
if (eventPart.empty())
463465
{
464-
return true;
465-
}
466-
467-
if (size == 0)
468-
{
469-
return false;
466+
return allowNull;
470467
}
471468

469+
size_t size = eventPart.length();
472470
if (size > MAX_SIZE)
473471
{
474472
return false;

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)