forked from Xeeynamo/sonic-hybrid-rsdk
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
sonic3air-main/Oxygen/oxygenengine/source/oxygen/helper/HighResolutionTimer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Part of the Oxygen Engine / Sonic 3 A.I.R. software distribution. | ||
* Copyright (C) 2017-2024 by Eukaryot | ||
* | ||
* Published under the GNU GPLv3 open source software license, see license.txt | ||
* or https://www.gnu.org/licenses/gpl-3.0.en.html | ||
*/ | ||
|
||
#include "oxygen/pch.h" | ||
#include "oxygen/helper/HighResolutionTimer.h" | ||
|
||
|
||
void HighResolutionTimer::reset() | ||
{ | ||
mRunning = false; | ||
} | ||
|
||
void HighResolutionTimer::start() | ||
{ | ||
mStart = std::chrono::high_resolution_clock::now(); | ||
mRunning = true; | ||
} | ||
|
||
double HighResolutionTimer::getSecondsSinceStart() const | ||
{ | ||
if (mRunning) | ||
{ | ||
const Duration duration = (std::chrono::high_resolution_clock::now() - mStart); | ||
return duration.count(); | ||
} | ||
return 0.0; | ||
} | ||
|
||
|
||
void AccumulativeTimer::resetTiming() | ||
{ | ||
reset(); | ||
mAccumulatedTime = Duration::zero(); | ||
} | ||
|
||
void AccumulativeTimer::resumeTiming() | ||
{ | ||
if (!mRunning) | ||
{ | ||
start(); | ||
} | ||
} | ||
|
||
void AccumulativeTimer::pauseTiming() | ||
{ | ||
if (mRunning) | ||
{ | ||
mAccumulatedTime += (std::chrono::high_resolution_clock::now() - mStart); | ||
mRunning = false; | ||
} | ||
} | ||
|
||
double AccumulativeTimer::getAccumulatedSeconds() const | ||
{ | ||
Duration totalDuration = mAccumulatedTime; | ||
if (mRunning) | ||
{ | ||
totalDuration += (std::chrono::high_resolution_clock::now() - mStart); | ||
} | ||
return totalDuration.count(); | ||
} | ||
|
||
double AccumulativeTimer::getAccumulatedSecondsAndRestart() | ||
{ | ||
const TimePoint now = std::chrono::high_resolution_clock::now(); | ||
Duration totalDuration = mAccumulatedTime; | ||
if (mRunning) | ||
{ | ||
totalDuration += (now - mStart); | ||
} | ||
|
||
mStart = now; | ||
mAccumulatedTime = Duration::zero(); | ||
mRunning = true; | ||
return totalDuration.count(); | ||
} |
44 changes: 44 additions & 0 deletions
44
sonic3air-main/Oxygen/oxygenengine/source/oxygen/helper/HighResolutionTimer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Part of the Oxygen Engine / Sonic 3 A.I.R. software distribution. | ||
* Copyright (C) 2017-2024 by Eukaryot | ||
* | ||
* Published under the GNU GPLv3 open source software license, see license.txt | ||
* or https://www.gnu.org/licenses/gpl-3.0.en.html | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
|
||
|
||
class HighResolutionTimer | ||
{ | ||
public: | ||
void reset(); | ||
void start(); | ||
|
||
inline bool isRunning() const { return mRunning; } | ||
double getSecondsSinceStart() const; | ||
|
||
protected: | ||
typedef std::chrono::time_point<std::chrono::high_resolution_clock> TimePoint; | ||
typedef std::chrono::duration<double> Duration; | ||
|
||
TimePoint mStart; | ||
bool mRunning = false; | ||
}; | ||
|
||
|
||
class AccumulativeTimer : protected HighResolutionTimer | ||
{ | ||
public: | ||
void resetTiming(); | ||
void resumeTiming(); | ||
void pauseTiming(); | ||
|
||
double getAccumulatedSeconds() const; | ||
double getAccumulatedSecondsAndRestart(); | ||
|
||
private: | ||
Duration mAccumulatedTime; | ||
}; |
35 changes: 35 additions & 0 deletions
35
sonic3air-main/Oxygen/oxygenengine/source/oxygen/helper/JsonHelper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Part of the Oxygen Engine / Sonic 3 A.I.R. software distribution. | ||
* Copyright (C) 2017-2024 by Eukaryot | ||
* | ||
* Published under the GNU GPLv3 open source software license, see license.txt | ||
* or https://www.gnu.org/licenses/gpl-3.0.en.html | ||
*/ | ||
|
||
#include "oxygen/pch.h" | ||
#include "oxygen/helper/JsonHelper.h" | ||
|
||
|
||
Json::Value JsonHelper::loadFile(const std::wstring& filename) | ||
{ | ||
std::vector<uint8> content; | ||
if (FTX::FileSystem->readFile(filename, content)) | ||
{ | ||
if (!content.empty()) // Silently ignore empty JSON files | ||
{ | ||
std::string errors; | ||
Json::Value result = loadFromMemory(content, &errors); | ||
if (errors.empty()) | ||
return result; | ||
|
||
RMX_ERROR("Error parsing JSON file '" << *WString(filename).toString() << "':\n" << errors, ); | ||
} | ||
} | ||
return Json::Value(); | ||
} | ||
|
||
bool JsonHelper::saveFile(const std::wstring& filename, const Json::Value& value) | ||
{ | ||
const String output(value.toStyledString()); | ||
return FTX::FileSystem->saveFile(filename, *output, output.length()); | ||
} |
22 changes: 22 additions & 0 deletions
22
sonic3air-main/Oxygen/oxygenengine/source/oxygen/helper/JsonHelper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Part of the Oxygen Engine / Sonic 3 A.I.R. software distribution. | ||
* Copyright (C) 2017-2024 by Eukaryot | ||
* | ||
* Published under the GNU GPLv3 open source software license, see license.txt | ||
* or https://www.gnu.org/licenses/gpl-3.0.en.html | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <rmxbase.h> | ||
|
||
|
||
class JsonHelper : public rmx::JsonHelper | ||
{ | ||
public: | ||
static Json::Value loadFile(const std::wstring& filename); | ||
static bool saveFile(const std::wstring& filename, const Json::Value& value); | ||
|
||
public: | ||
inline JsonHelper(const Json::Value& json) : rmx::JsonHelper(json) {} | ||
}; |