Skip to content

Commit

Permalink
Merge pull request #207 from edunad/features/spdlog
Browse files Browse the repository at this point in the history
Add spdlog
  • Loading branch information
edunad authored Oct 9, 2024
2 parents f93fd89 + cbf7d01 commit 25d92b0
Show file tree
Hide file tree
Showing 87 changed files with 568 additions and 594 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ option(RAWRBOX_DISABLE_SUPPORT_VULKAN "Disable vulkan support" OFF)

# Other -----
option(RAWRBOX_DEV_MODE "Builds all modules, used for developing rawrbox" OFF)
option(RAWRBOX_TRACE_EXCEPTIONS "Enables exception tracing" ON)
option(RAWRBOX_INTERPROCEDURAL_OPTIMIZATION "Enables IPO" ON)
# ---------------
# -----
Expand Down Expand Up @@ -103,8 +102,6 @@ if(RAWRBOX_DEV_MODE)
set(RAWRBOX_BUILD_RAWRBOX_IMGUI ON)
set(RAWRBOX_BUILD_QHULL ON)

set(RAWRBOX_TRACE_EXCEPTIONS OFF)

if(NOT DEFINED STEAMWORKS_APPID)
message(STATUS "Set STEAMWORKS_APPID to 480 (SpaceWars example game)")
set(STEAMWORKS_APPID 480) # SpaceWars example game
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ This engine started as a C++ training project, with hopes of being applied in my
| -- | -- | -- |
| `RAWRBOX_DEV_MODE` | Enables all the modules, used for rawrbox development | OFF |
| -- | -- | -- |
| `RAWRBOX_TRACE_EXCEPTIONS` | Enables exception tracing | ON |
| `RAWRBOX_INTERPROCEDURAL_OPTIMIZATION` | Enables IPO compilation on release | ON |

<br/><br/>
Expand Down Expand Up @@ -199,6 +198,6 @@ This engine started as a C++ training project, with hopes of being applied in my
| curl | Used for HTTP / HTTPS requests | [MIT](https://github.com/libcpr/cpr/blob/master/LICENSE) |
| libcpr | Used for HTTP / HTTPS requests | [MIT](https://github.com/libcpr/cpr/blob/master/LICENSE) |
| lunasvg | Used for SVG loading | [MIT](https://github.com/sammycage/lunasvg/blob/master/LICENSE) |
| cpptrace | Used for easy error tracing | [MIT](https://github.com/jeremy-rifkin/cpptrace/blob/main/LICENSE) |
| meshoptimizer | Used to optimize meshes | [MIT](https://github.com/zeux/meshoptimizer/blob/master/LICENSE.md) |
| ozz-animation | Used to animate skinned meshes | [MIT](https://github.com/guillaumeblanc/ozz-animation/blob/master/LICENSE.md) |
| spdlog | Used for logging | [MIT](https://github.com/gabime/spdlog/blob/v1.x/LICENSE) |
5 changes: 4 additions & 1 deletion rawrbox.bass/include/rawrbox/bass/utils/bass.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once

#include <rawrbox/utils/logger.hpp>
namespace rawrbox {
class BASSUtils {
protected:
static std::unique_ptr<rawrbox::Logger> _logger;

public:
static void checkBASSError();
};
Expand Down
8 changes: 4 additions & 4 deletions rawrbox.bass/src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace rawrbox {

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

_initialized = (BASS_Init(-1, 44100, BASS_DEVICE_3D, nullptr, nullptr) != 0);
if (_initialized) {
Expand All @@ -82,7 +82,7 @@ namespace rawrbox {
BASS_Set3DFactors(1.0F, 10.0F, 1.0F);
BASS_Apply3D();
} else {
throw _logger->error("BASS initialize error: {}", BASS_ErrorGetCode());
CRITICAL_RAWRBOX("BASS initialize error: {}", BASS_ErrorGetCode());
}
}

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

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

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

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

if (url.rfind(".3D") != std::string::npos) flags |= SoundFlags::SOUND_3D;
Expand Down
4 changes: 0 additions & 4 deletions rawrbox.bass/src/resources/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ namespace rawrbox {
} else {
loaded = rawrbox::BASS::loadSound(this->filePath, this->flags);
}
#ifdef RAWRBOX_TRACE_EXCEPTIONS
} catch (const cpptrace::exception_with_message& e) {
#else
} catch (const std::exception& e) {
#endif
fmt::print("\n\t{}\n\t\t └── Loading fallback sound!\n", e.what());
loaded = rawrbox::BASS::loadSound("./assets/sound/error.ogg", this->flags);
}
Expand Down
4 changes: 2 additions & 2 deletions rawrbox.bass/src/sound/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ namespace rawrbox {
}

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions rawrbox.bass/src/sound/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace rawrbox {
flag = BASS_DATA_FFT4096;
break;
default:
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);
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);
}

buffer.resize(bass_length);
Expand All @@ -180,7 +180,7 @@ namespace rawrbox {
// --------------

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

BASS_FX_BPM_BeatSetParameters(this->_channel, bandwidth, center_freq, release_time);
Expand Down
6 changes: 5 additions & 1 deletion rawrbox.bass/src/utils/bass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <fmt/format.h>

namespace rawrbox {
// PRIVATE ---
std::unique_ptr<rawrbox::Logger> BASSUtils::_logger = std::make_unique<rawrbox::Logger>("RawrBox-BASS");
// ----------

void BASSUtils::checkBASSError() {
int err = BASS_ErrorGetCode();
std::string readErr;
Expand Down Expand Up @@ -41,7 +45,7 @@ namespace rawrbox {
break;
}

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

} // namespace rawrbox
1 change: 0 additions & 1 deletion rawrbox.engine/include/rawrbox/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ namespace rawrbox {
virtual void draw();

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

public:
virtual ~Engine() = default;
Expand Down
111 changes: 41 additions & 70 deletions rawrbox.engine/src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace rawrbox {
}

// Create the GLFW window
void Engine::setupGLFW() { throw this->_logger->error("Method 'setupGLFW' not implemented"); }
void Engine::setupGLFW() { CRITICAL_RAWRBOX("Method 'setupGLFW' not implemented"); }
void Engine::init() {}
void Engine::pollEvents() {}
void Engine::fixedUpdate() {}
Expand All @@ -41,12 +41,6 @@ namespace rawrbox {
rawrbox::ASYNC::shutdown();
}

void Engine::prettyPrintErr(const std::string& err) {
fmt::print("\n ---- FATAL ENGINE ERROR ----\n");
fmt::print(" {}\n", err);
fmt::print("-------------------------------\n\n");
}

void Engine::run() {
rawrbox::ASYNC::init();
rawrbox::ThreadUtils::setName("rawrbox:input");
Expand All @@ -57,82 +51,59 @@ namespace rawrbox {

// Setup render threading
auto renderThread = std::jthread([this]() {
#ifdef RAWRBOX_TRACE_EXCEPTIONS
try {
#endif
rawrbox::RENDER_THREAD_ID = std::this_thread::get_id();
rawrbox::ThreadUtils::setName("rawrbox:render");
rawrbox::RENDER_THREAD_ID = std::this_thread::get_id();
rawrbox::ThreadUtils::setName("rawrbox:render");

// INITIALIZE ENGINE ---
this->init();
// ---------
// INITIALIZE ENGINE ---
this->init();
// ---------

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

const float target_deltaTime = 1.0F / this->_fps;
if (rawrbox::DELTA_TIME < target_deltaTime) {
sleep((target_deltaTime - rawrbox::DELTA_TIME) * 1000);
rawrbox::DELTA_TIME += static_cast<float>(std::max(0.0, this->_timer.record_elapsed_seconds()));
}

// THREADING ----
rawrbox::___runThreadInvokes();
// -------
const float target_deltaTime = 1.0F / this->_fps;
if (rawrbox::DELTA_TIME < target_deltaTime) {
sleep((target_deltaTime - rawrbox::DELTA_TIME) * 1000);
rawrbox::DELTA_TIME += static_cast<float>(std::max(0.0, this->_timer.record_elapsed_seconds()));
}

// Fixed time update --------
this->_deltaTimeAccumulator += rawrbox::DELTA_TIME;
if (this->_deltaTimeAccumulator > 10.F) this->_deltaTimeAccumulator = 0; // Prevent dead loop
// THREADING ----
rawrbox::___runThreadInvokes();
// -------

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

while (this->_deltaTimeAccumulator >= targetFrameRateInv) {
this->fixedUpdate();
const float targetFrameRateInv = 1.0F / this->_tps;
rawrbox::FIXED_DELTA_TIME = targetFrameRateInv;

this->_deltaTimeAccumulator -= targetFrameRateInv;
if (this->_shutdown != ENGINE_THREADS::NONE) break;
}
while (this->_deltaTimeAccumulator >= targetFrameRateInv) {
this->fixedUpdate();

this->_deltaTimeAccumulator -= targetFrameRateInv;
if (this->_shutdown != ENGINE_THREADS::NONE) break;
// ---------------------------
}

// VARIABLE-TIME
rawrbox::TIMER::update();
this->update();
// ----
if (this->_shutdown != ENGINE_THREADS::NONE) break;
// ---------------------------

// ACTUAL DRAWING
rawrbox::FRAME_ALPHA = this->_deltaTimeAccumulator / rawrbox::DELTA_TIME;
this->draw();
// ----------
}
// VARIABLE-TIME
rawrbox::TIMER::update();
this->update();
// ----

this->_logger->warn("Thread 'rawrbox:render' shutdown");
rawrbox::TIMER::clear();

this->onThreadShutdown(rawrbox::ENGINE_THREADS::THREAD_RENDER);
this->_shutdown = rawrbox::ENGINE_THREADS::THREAD_INPUT; // Done killing rendering, now destroy glfw
#ifdef RAWRBOX_TRACE_EXCEPTIONS
} catch (const cpptrace::exception_with_message& err) {
this->prettyPrintErr(err.message());

err.trace().print();
throw err;
} catch (const std::exception& err) {
this->prettyPrintErr(err.what());

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)));
cpptrace::generate_trace().print();
throw err;
} catch (...) {
this->prettyPrintErr("Unknown error");

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)));
cpptrace::generate_trace().print();
throw std::runtime_error("Unknown error");
// ACTUAL DRAWING
rawrbox::FRAME_ALPHA = this->_deltaTimeAccumulator / rawrbox::DELTA_TIME;
this->draw();
// ----------
}
#endif

this->_logger->warn("Thread 'rawrbox:render' shutdown");
rawrbox::TIMER::clear();

this->onThreadShutdown(rawrbox::ENGINE_THREADS::THREAD_RENDER);
this->_shutdown = rawrbox::ENGINE_THREADS::THREAD_INPUT; // Done killing rendering, now destroy glfw
});
// ----

Expand Down
4 changes: 2 additions & 2 deletions rawrbox.gltf/include/rawrbox/gltf/importer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ namespace rawrbox {
template <typename T, std::size_t Extent>
fastgltf::span<T, fastgltf::dynamic_extent> subspan(fastgltf::span<T, Extent> span, size_t offset, size_t count = fastgltf::dynamic_extent) {
if (offset >= span.size()) {
throw _logger->error("Offset is out of range");
CRITICAL_RAWRBOX("Offset is out of range");
}

if (count != fastgltf::dynamic_extent && count > span.size() - offset) {
throw _logger->error("Count is out of range");
CRITICAL_RAWRBOX("Count is out of range");
}

if (count == fastgltf::dynamic_extent) {
Expand Down
Loading

0 comments on commit 25d92b0

Please sign in to comment.