Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ jobs:
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ubuntu-22.04, windows-latest, macOS-latest]
build_type: ${{ fromJSON(format('[{0}]', inputs.build_type || '"Debug","Release"')) }}
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
- os: ubuntu-22.04
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
- os: ubuntu-22.04
c_compiler: clang
cpp_compiler: clang++
- os: macOS-latest
Expand All @@ -52,7 +52,7 @@ jobs:
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
- os: ubuntu-22.04
c_compiler: cl
- os: macOS-latest
c_compiler: cl
Expand All @@ -71,22 +71,8 @@ jobs:
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Install Clang and Libraries
if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'clang'
run: |
sudo apt-get update
sudo apt-get install -y clang libc++-dev libc++abi-dev

- name: Set Clang 16 as Default
if: matrix.os == 'ubuntu-24.04' && matrix.c_compiler == 'clang'
run: |
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 100
sudo update-alternatives --set clang /usr/bin/clang-16
sudo update-alternatives --set clang++ /usr/bin/clang++-16

- name: Check Clang Settings
if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'clang'
if: matrix.os == 'ubuntu-22.04' && matrix.c_compiler == 'clang'
run: |
clang --version
clang++ --version
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

# 5.1.0

### Added

- **Previous session time**: functionality to get the last session time

### Fixed

- **Playtime Metrics**: Fixed annotations for session time and total session time
- **MacOS**: GPU model detection

## 5.0.0

### Added
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ elseif(APPLE)
"-framework Foundation"
"-framework CoreServices"
"-framework SystemConfiguration"
"-framework Metal"
"-framework MetalKit"
)

create_source_groups(MACOS_SOURCES)
Expand Down
1 change: 1 addition & 0 deletions include/GameAnalytics/GameAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ namespace gameanalytics

static int64_t getElapsedSessionTime();
static int64_t getElapsedTimeFromAllSessions();
static int64_t getElapsedTimeForPreviousSession();

// game state changes
// will affect how session is started / ended
Expand Down
2 changes: 1 addition & 1 deletion source/gameanalytics/GACommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace gameanalytics
class GAState;
}

constexpr const char* GA_VERSION_STR = "cpp 5.0.0";
constexpr const char* GA_VERSION_STR = "cpp 5.1.0";

constexpr int MAX_CUSTOM_FIELDS_COUNT = 50;
constexpr int MAX_CUSTOM_FIELDS_KEY_LENGTH = 64;
Expand Down
5 changes: 5 additions & 0 deletions source/gameanalytics/GALogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ namespace gameanalytics
return;
}

if(logType == LogInfo && !getInstance().infoLogEnabled)
{
return;
}

std::string tag = getInstance().tag;
tag += " :";

Expand Down
23 changes: 18 additions & 5 deletions source/gameanalytics/GAState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ namespace gameanalytics
out["session_num"] = getInstance()._sessionNum;
out["connection_type"] = device::GADevice::getConnectionType();

// playtime metrics
out["current_session_length"] = getInstance().calculateSessionLength();
out["lifetime_session_length"] = getInstance().getTotalSessionLength();

// ---- OPTIONAL ---- //

// A/B testing
Expand Down Expand Up @@ -535,6 +539,11 @@ namespace gameanalytics
return "";
}

int64_t GAState::getLastSessionLength() const
{
return _lastSessionTime;
}

int64_t GAState::getTotalSessionLength() const
{
return _totalElapsedSessionTime + calculateSessionLength<std::chrono::seconds>();
Expand Down Expand Up @@ -586,10 +595,11 @@ namespace gameanalytics

try
{
std::string cachedSessionTime = utilities::getOptionalValue<std::string>(state_dict, "total_session_time", "0");
std::string cachedLastSessionTime = utilities::getOptionalValue<std::string>(state_dict, "last_session_time", "0");
std::string cachedTotalSessionTime = utilities::getOptionalValue<std::string>(state_dict, "total_session_time", "0");

_totalElapsedSessionTime = std::stoull(cachedSessionTime);

_lastSessionTime = std::stoull(cachedLastSessionTime);
_totalElapsedSessionTime = std::stoull(cachedTotalSessionTime);
}
catch(const std::exception& e)
{
Expand Down Expand Up @@ -1090,8 +1100,11 @@ namespace gameanalytics

void GAState::updateTotalSessionTime()
{
int64_t totalSessionTime = getTotalSessionLength();
_gaStore.setState("total_session_time", std::to_string(totalSessionTime));
_lastSessionTime = calculateSessionLength();
_totalElapsedSessionTime += _lastSessionTime;

_gaStore.setState("last_session_time", std::to_string(_lastSessionTime));
_gaStore.setState("total_session_time", std::to_string(_totalElapsedSessionTime));
}

std::string GAState::getBuild()
Expand Down
3 changes: 3 additions & 0 deletions source/gameanalytics/GAState.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ namespace gameanalytics

int64_t getTotalSessionLength() const;

int64_t getLastSessionLength() const;

void populateConfigurations(json& sdkConfig);

json getRemoteConfigAnnotations();
Expand Down Expand Up @@ -229,6 +231,7 @@ namespace gameanalytics
int64_t _sessionNum = 0;
int64_t _transactionNum = 0;

int64_t _lastSessionTime = 0;
int64_t _totalElapsedSessionTime = 0;
std::chrono::high_resolution_clock::time_point _startTimepoint;

Expand Down
26 changes: 0 additions & 26 deletions source/gameanalytics/GAStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,6 @@ namespace gameanalytics
{
return sqlDatabase;
}

bool GAStore::fixOldDatabase()
{
std::filesystem::path oldPath = dbPath;
std::filesystem::path filename = oldPath.filename();

oldPath = oldPath.parent_path() / ".." / filename;

if(std::filesystem::exists(oldPath) && !std::filesystem::exists(dbPath))
{
try
{
std::filesystem::rename(oldPath, dbPath);
}
catch(...)
{
return false;
}

return true;
}

return false;
}

bool GAStore::initDatabaseLocation()
{
Expand All @@ -244,8 +220,6 @@ namespace gameanalytics
{
if(!std::filesystem::create_directory(p))
return false;

fixOldDatabase();
}

return true;
Expand Down
14 changes: 6 additions & 8 deletions source/gameanalytics/GAValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ namespace gameanalytics

bool validateProgressionString(std::string const& progression, ValidationResult& out, int progressionLvl)
{
if(progressionLvl > 0 && progression.empty())
return true;

if (!GAValidator::validateEventPartLength(progression, true))
{
logging::GALogger::w("Validation fail - progression event - - progression0%d: Cannot be empty or above 64 characters. String: %s", progressionLvl + 1, progression.c_str());
Expand Down Expand Up @@ -458,17 +461,12 @@ namespace gameanalytics
{
constexpr uint32_t MAX_SIZE = 64u;

size_t size = eventPart.length();
if (allowNull == true && size == 0)
if (eventPart.empty())
{
return true;
}

if (size == 0)
{
return false;
return allowNull;
}

size_t size = eventPart.length();
if (size > MAX_SIZE)
{
return false;
Expand Down
5 changes: 5 additions & 0 deletions source/gameanalytics/GameAnalytics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,4 +998,9 @@ namespace gameanalytics
return state::GAState::getInstance().calculateSessionLength<std::chrono::seconds>();
}

int64_t GameAnalytics::getElapsedTimeForPreviousSession()
{
return state::GAState::getInstance().getLastSessionLength();
}

} // namespace gameanalytics
Loading