Skip to content

Commit 25d92b0

Browse files
authored
Merge pull request #207 from edunad/features/spdlog
Add spdlog
2 parents f93fd89 + cbf7d01 commit 25d92b0

File tree

87 files changed

+568
-594
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+568
-594
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ option(RAWRBOX_DISABLE_SUPPORT_VULKAN "Disable vulkan support" OFF)
5858

5959
# Other -----
6060
option(RAWRBOX_DEV_MODE "Builds all modules, used for developing rawrbox" OFF)
61-
option(RAWRBOX_TRACE_EXCEPTIONS "Enables exception tracing" ON)
6261
option(RAWRBOX_INTERPROCEDURAL_OPTIMIZATION "Enables IPO" ON)
6362
# ---------------
6463
# -----
@@ -103,8 +102,6 @@ if(RAWRBOX_DEV_MODE)
103102
set(RAWRBOX_BUILD_RAWRBOX_IMGUI ON)
104103
set(RAWRBOX_BUILD_QHULL ON)
105104

106-
set(RAWRBOX_TRACE_EXCEPTIONS OFF)
107-
108105
if(NOT DEFINED STEAMWORKS_APPID)
109106
message(STATUS "Set STEAMWORKS_APPID to 480 (SpaceWars example game)")
110107
set(STEAMWORKS_APPID 480) # SpaceWars example game

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ This engine started as a C++ training project, with hopes of being applied in my
155155
| -- | -- | -- |
156156
| `RAWRBOX_DEV_MODE` | Enables all the modules, used for rawrbox development | OFF |
157157
| -- | -- | -- |
158-
| `RAWRBOX_TRACE_EXCEPTIONS` | Enables exception tracing | ON |
159158
| `RAWRBOX_INTERPROCEDURAL_OPTIMIZATION` | Enables IPO compilation on release | ON |
160159

161160
<br/><br/>
@@ -199,6 +198,6 @@ This engine started as a C++ training project, with hopes of being applied in my
199198
| curl | Used for HTTP / HTTPS requests | [MIT](https://github.com/libcpr/cpr/blob/master/LICENSE) |
200199
| libcpr | Used for HTTP / HTTPS requests | [MIT](https://github.com/libcpr/cpr/blob/master/LICENSE) |
201200
| lunasvg | Used for SVG loading | [MIT](https://github.com/sammycage/lunasvg/blob/master/LICENSE) |
202-
| cpptrace | Used for easy error tracing | [MIT](https://github.com/jeremy-rifkin/cpptrace/blob/main/LICENSE) |
203201
| meshoptimizer | Used to optimize meshes | [MIT](https://github.com/zeux/meshoptimizer/blob/master/LICENSE.md) |
204202
| ozz-animation | Used to animate skinned meshes | [MIT](https://github.com/guillaumeblanc/ozz-animation/blob/master/LICENSE.md) |
203+
| spdlog | Used for logging | [MIT](https://github.com/gabime/spdlog/blob/v1.x/LICENSE) |

rawrbox.bass/include/rawrbox/bass/utils/bass.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#pragma once
2-
2+
#include <rawrbox/utils/logger.hpp>
33
namespace rawrbox {
44
class BASSUtils {
5+
protected:
6+
static std::unique_ptr<rawrbox::Logger> _logger;
7+
58
public:
69
static void checkBASSError();
710
};

rawrbox.bass/src/manager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace rawrbox {
7272

7373
void BASS::initialize() {
7474
auto fxVersion = HIWORD(BASS_FX_GetVersion());
75-
if (fxVersion != BASSVERSION) throw _logger->error("BASS Version missmatch! FX [{}] | BASS [{}]", fxVersion, BASSVERSION);
75+
if (fxVersion != BASSVERSION) CRITICAL_RAWRBOX("BASS Version missmatch! FX [{}] | BASS [{}]", fxVersion, BASSVERSION);
7676

7777
_initialized = (BASS_Init(-1, 44100, BASS_DEVICE_3D, nullptr, nullptr) != 0);
7878
if (_initialized) {
@@ -82,7 +82,7 @@ namespace rawrbox {
8282
BASS_Set3DFactors(1.0F, 10.0F, 1.0F);
8383
BASS_Apply3D();
8484
} else {
85-
throw _logger->error("BASS initialize error: {}", BASS_ErrorGetCode());
85+
CRITICAL_RAWRBOX("BASS initialize error: {}", BASS_ErrorGetCode());
8686
}
8787
}
8888

@@ -104,7 +104,7 @@ namespace rawrbox {
104104
std::string pth = path.generic_string();
105105

106106
if (sounds.find(pth) != sounds.end()) return sounds[pth].get();
107-
if (!std::filesystem::exists(path)) throw _logger->error("File '{}' not found!", pth);
107+
if (!std::filesystem::exists(path)) CRITICAL_RAWRBOX("File '{}' not found!", pth);
108108

109109
auto size = std::filesystem::file_size(path);
110110
if (path.generic_string().rfind(".3D") != std::string::npos) flags |= SoundFlags::SOUND_3D;
@@ -141,7 +141,7 @@ namespace rawrbox {
141141
}
142142

143143
rawrbox::SoundBase* BASS::loadHTTPSound(const std::string& url, uint32_t flags) {
144-
if (!url.starts_with("http://") && !url.starts_with("https://")) throw _logger->error("Invalid sound url '{}'", url);
144+
if (!url.starts_with("http://") && !url.starts_with("https://")) CRITICAL_RAWRBOX("Invalid sound url '{}'", url);
145145
if (sounds.find(url) != sounds.end()) return sounds[url].get();
146146

147147
if (url.rfind(".3D") != std::string::npos) flags |= SoundFlags::SOUND_3D;

rawrbox.bass/src/resources/sound.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ namespace rawrbox {
1515
} else {
1616
loaded = rawrbox::BASS::loadSound(this->filePath, this->flags);
1717
}
18-
#ifdef RAWRBOX_TRACE_EXCEPTIONS
19-
} catch (const cpptrace::exception_with_message& e) {
20-
#else
2118
} catch (const std::exception& e) {
22-
#endif
2319
fmt::print("\n\t{}\n\t\t └── Loading fallback sound!\n", e.what());
2420
loaded = rawrbox::BASS::loadSound("./assets/sound/error.ogg", this->flags);
2521
}

rawrbox.bass/src/sound/base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ namespace rawrbox {
2323
}
2424

2525
std::shared_ptr<rawrbox::SoundInstance> SoundBase::createInstance() {
26-
if (!this->isValid()) throw this->_logger->error("Sound sample not valid!");
26+
if (!this->isValid()) CRITICAL_RAWRBOX("Sound sample not valid!");
2727
auto ptr = std::make_shared<rawrbox::SoundInstance>(this->_sample, this->_isStream, this->_flags);
2828

2929
this->_instances.push_back(std::move(ptr));
3030
return this->_instances.front();
3131
}
3232

3333
std::shared_ptr<rawrbox::SoundInstance> SoundBase::getInstance(size_t i) {
34-
if (i >= this->_instances.size()) throw this->_logger->error("Sound instance '{}' not found!", i);
34+
if (i >= this->_instances.size()) CRITICAL_RAWRBOX("Sound instance '{}' not found!", i);
3535
return this->_instances[i];
3636
}
3737

rawrbox.bass/src/sound/instance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace rawrbox {
164164
flag = BASS_DATA_FFT4096;
165165
break;
166166
default:
167-
throw this->_logger->error("Unknown FFT length {}, should be power of 2! Check: http://bass.radio42.com/help/html/a13cfef0-1056-bb94-81c4-a4fdf21bd463.htm", bass_length);
167+
CRITICAL_RAWRBOX("Unknown FFT length {}, should be power of 2! Check: http://bass.radio42.com/help/html/a13cfef0-1056-bb94-81c4-a4fdf21bd463.htm", bass_length);
168168
}
169169

170170
buffer.resize(bass_length);
@@ -180,7 +180,7 @@ namespace rawrbox {
180180
// --------------
181181

182182
void SoundInstance::setBeatSettings(float bandwidth, float center_freq, float release_time) {
183-
if ((this->_flags & SoundFlags::BEAT_DETECTION) == 0) throw this->_logger->error("Load flag BEAT_DETECTION not set!");
183+
if ((this->_flags & SoundFlags::BEAT_DETECTION) == 0) CRITICAL_RAWRBOX("Load flag BEAT_DETECTION not set!");
184184
if (!this->isCreated()) return;
185185

186186
BASS_FX_BPM_BeatSetParameters(this->_channel, bandwidth, center_freq, release_time);

rawrbox.bass/src/utils/bass.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <fmt/format.h>
77

88
namespace rawrbox {
9+
// PRIVATE ---
10+
std::unique_ptr<rawrbox::Logger> BASSUtils::_logger = std::make_unique<rawrbox::Logger>("RawrBox-BASS");
11+
// ----------
12+
913
void BASSUtils::checkBASSError() {
1014
int err = BASS_ErrorGetCode();
1115
std::string readErr;
@@ -41,7 +45,7 @@ namespace rawrbox {
4145
break;
4246
}
4347

44-
throw rawrbox::Logger::err("RawrBox-BASS", "Bass audio error:\n\t{}", readErr);
48+
CRITICAL_RAWRBOX("Bass audio error:\n\t{}", readErr);
4549
}
4650

4751
} // namespace rawrbox

rawrbox.engine/include/rawrbox/engine/engine.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ namespace rawrbox {
3939
virtual void draw();
4040

4141
virtual void onThreadShutdown(rawrbox::ENGINE_THREADS thread);
42-
static void prettyPrintErr(const std::string& err);
4342

4443
public:
4544
virtual ~Engine() = default;

rawrbox.engine/src/engine.cpp

Lines changed: 41 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace rawrbox {
2626
}
2727

2828
// Create the GLFW window
29-
void Engine::setupGLFW() { throw this->_logger->error("Method 'setupGLFW' not implemented"); }
29+
void Engine::setupGLFW() { CRITICAL_RAWRBOX("Method 'setupGLFW' not implemented"); }
3030
void Engine::init() {}
3131
void Engine::pollEvents() {}
3232
void Engine::fixedUpdate() {}
@@ -41,12 +41,6 @@ namespace rawrbox {
4141
rawrbox::ASYNC::shutdown();
4242
}
4343

44-
void Engine::prettyPrintErr(const std::string& err) {
45-
fmt::print("\n ---- FATAL ENGINE ERROR ----\n");
46-
fmt::print(" {}\n", err);
47-
fmt::print("-------------------------------\n\n");
48-
}
49-
5044
void Engine::run() {
5145
rawrbox::ASYNC::init();
5246
rawrbox::ThreadUtils::setName("rawrbox:input");
@@ -57,82 +51,59 @@ namespace rawrbox {
5751

5852
// Setup render threading
5953
auto renderThread = std::jthread([this]() {
60-
#ifdef RAWRBOX_TRACE_EXCEPTIONS
61-
try {
62-
#endif
63-
rawrbox::RENDER_THREAD_ID = std::this_thread::get_id();
64-
rawrbox::ThreadUtils::setName("rawrbox:render");
54+
rawrbox::RENDER_THREAD_ID = std::this_thread::get_id();
55+
rawrbox::ThreadUtils::setName("rawrbox:render");
6556

66-
// INITIALIZE ENGINE ---
67-
this->init();
68-
// ---------
57+
// INITIALIZE ENGINE ---
58+
this->init();
59+
// ---------
6960

70-
while (this->_shutdown != ENGINE_THREADS::THREAD_RENDER) {
71-
rawrbox::DELTA_TIME = static_cast<float>(std::max(0.0, this->_timer.record_elapsed_seconds()));
61+
while (this->_shutdown != ENGINE_THREADS::THREAD_RENDER) {
62+
rawrbox::DELTA_TIME = static_cast<float>(std::max(0.0, this->_timer.record_elapsed_seconds()));
7263

73-
const float target_deltaTime = 1.0F / this->_fps;
74-
if (rawrbox::DELTA_TIME < target_deltaTime) {
75-
sleep((target_deltaTime - rawrbox::DELTA_TIME) * 1000);
76-
rawrbox::DELTA_TIME += static_cast<float>(std::max(0.0, this->_timer.record_elapsed_seconds()));
77-
}
78-
79-
// THREADING ----
80-
rawrbox::___runThreadInvokes();
81-
// -------
64+
const float target_deltaTime = 1.0F / this->_fps;
65+
if (rawrbox::DELTA_TIME < target_deltaTime) {
66+
sleep((target_deltaTime - rawrbox::DELTA_TIME) * 1000);
67+
rawrbox::DELTA_TIME += static_cast<float>(std::max(0.0, this->_timer.record_elapsed_seconds()));
68+
}
8269

83-
// Fixed time update --------
84-
this->_deltaTimeAccumulator += rawrbox::DELTA_TIME;
85-
if (this->_deltaTimeAccumulator > 10.F) this->_deltaTimeAccumulator = 0; // Prevent dead loop
70+
// THREADING ----
71+
rawrbox::___runThreadInvokes();
72+
// -------
8673

87-
const float targetFrameRateInv = 1.0F / this->_tps;
88-
rawrbox::FIXED_DELTA_TIME = targetFrameRateInv;
74+
// Fixed time update --------
75+
this->_deltaTimeAccumulator += rawrbox::DELTA_TIME;
76+
if (this->_deltaTimeAccumulator > 10.F) this->_deltaTimeAccumulator = 0; // Prevent dead loop
8977

90-
while (this->_deltaTimeAccumulator >= targetFrameRateInv) {
91-
this->fixedUpdate();
78+
const float targetFrameRateInv = 1.0F / this->_tps;
79+
rawrbox::FIXED_DELTA_TIME = targetFrameRateInv;
9280

93-
this->_deltaTimeAccumulator -= targetFrameRateInv;
94-
if (this->_shutdown != ENGINE_THREADS::NONE) break;
95-
}
81+
while (this->_deltaTimeAccumulator >= targetFrameRateInv) {
82+
this->fixedUpdate();
9683

84+
this->_deltaTimeAccumulator -= targetFrameRateInv;
9785
if (this->_shutdown != ENGINE_THREADS::NONE) break;
98-
// ---------------------------
86+
}
9987

100-
// VARIABLE-TIME
101-
rawrbox::TIMER::update();
102-
this->update();
103-
// ----
88+
if (this->_shutdown != ENGINE_THREADS::NONE) break;
89+
// ---------------------------
10490

105-
// ACTUAL DRAWING
106-
rawrbox::FRAME_ALPHA = this->_deltaTimeAccumulator / rawrbox::DELTA_TIME;
107-
this->draw();
108-
// ----------
109-
}
91+
// VARIABLE-TIME
92+
rawrbox::TIMER::update();
93+
this->update();
94+
// ----
11095

111-
this->_logger->warn("Thread 'rawrbox:render' shutdown");
112-
rawrbox::TIMER::clear();
113-
114-
this->onThreadShutdown(rawrbox::ENGINE_THREADS::THREAD_RENDER);
115-
this->_shutdown = rawrbox::ENGINE_THREADS::THREAD_INPUT; // Done killing rendering, now destroy glfw
116-
#ifdef RAWRBOX_TRACE_EXCEPTIONS
117-
} catch (const cpptrace::exception_with_message& err) {
118-
this->prettyPrintErr(err.message());
119-
120-
err.trace().print();
121-
throw err;
122-
} catch (const std::exception& err) {
123-
this->prettyPrintErr(err.what());
124-
125-
fmt::print("▒▒{}▒▒\n", fmt::styled(" If you are a developer, please use logger error in RAWRBOX.UTILS for a better stack trace ", fmt::bg(fmt::color::dark_red) | fmt::fg(fmt::color::white)));
126-
cpptrace::generate_trace().print();
127-
throw err;
128-
} catch (...) {
129-
this->prettyPrintErr("Unknown error");
130-
131-
fmt::print("▒▒{}▒▒\n", fmt::styled(" If you are a developer, please use logger error in RAWRBOX.UTILS for a better stack trace ", fmt::bg(fmt::color::dark_red) | fmt::fg(fmt::color::white)));
132-
cpptrace::generate_trace().print();
133-
throw std::runtime_error("Unknown error");
96+
// ACTUAL DRAWING
97+
rawrbox::FRAME_ALPHA = this->_deltaTimeAccumulator / rawrbox::DELTA_TIME;
98+
this->draw();
99+
// ----------
134100
}
135-
#endif
101+
102+
this->_logger->warn("Thread 'rawrbox:render' shutdown");
103+
rawrbox::TIMER::clear();
104+
105+
this->onThreadShutdown(rawrbox::ENGINE_THREADS::THREAD_RENDER);
106+
this->_shutdown = rawrbox::ENGINE_THREADS::THREAD_INPUT; // Done killing rendering, now destroy glfw
136107
});
137108
// ----
138109

0 commit comments

Comments
 (0)