diff --git a/README.md b/README.md index 5f07675..adc0aec 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ $ ./build/ouros # or on windows: .\build\Debug\ouros.exe ``` +For control on debugging: +```bash +$ ./build/ouros --debug 0b00111111 +``` +where each bit in the mask corresponds to a debug level, in order: unused, unused, fatal, trace, error, warning, notice, and info. `0b1111111` enables all debug messages. ## Additional Resources - https://howtovulkan.com/ diff --git a/src/app/App.cpp b/src/app/App.cpp index 705f48f..175e46b 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -5,7 +5,7 @@ App::App() { - utils::debugPrint(__FUNCTION__, __LINE__, "App constructor."); + utils::debugPrint(__FUNCTION__, __LINE__, "App constructor.", utils::DebugLevel::Trace); init(); @@ -13,7 +13,7 @@ App::App() { void App::init() { - utils::debugPrint(__FUNCTION__, __LINE__, "Init app."); + utils::debugPrint(__FUNCTION__, __LINE__, "Init app.", utils::DebugLevel::Trace); window_ = new Window(); @@ -21,12 +21,11 @@ void App::init() { int App::run() { - utils::debugPrint(__FUNCTION__, __LINE__, "Run app."); + utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace); bool quit = false; while (!quit) { // app loop for as long as the window is open - // poll events here // other threads might be able to change quit to true to auto close SDL_Event event; diff --git a/src/main.cpp b/src/main.cpp index 40b4577..b2fd944 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,23 @@ #include +#include #include "app/App.hpp" #include "utils/utils.hpp" -int main(int arg, char *argv[]) { +int main(int argc, char *argv[]) { - std::string message = "main()"; - utils::debugPrint(__FUNCTION__, __LINE__, message); + // parsing executable arguments + // TODO: move elsewhere + // this is for the debug mask + for(int i = 1; i < argc; i++) { + if(std::strncmp(argv[i], "--debug=", 8) == 0) { + std::string debugMaskString = argv[i] + 8; + utils::parseDebugMaskString(debugMaskString); + } + } + + utils::debugPrint(__FUNCTION__, __LINE__, "main()", utils::DebugLevel::Trace); // maybe do some exceptions here App app = App(); diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index 0a67836..4260b6c 100644 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -1,22 +1,57 @@ +#pragma once + #include #include #include +// TODO: might move a lot of this into a debug.h file +// TODO: logging ? but i dont care enough + namespace utils { - // TODO: implement - enum class DebugLevel { + enum DebugLevel : size_t { Info = 0, Notice, - Error + Warning, + Error, + Trace, + Fatal, + Extra1, + Extra2 }; - static void debugPrint(const char* function, int line, std::string message) { + static const char* debugTypeStrings[] = { + "Info", + "Notice", + "Warning", + "Error", + "Trace", + "Fatal", + "Extra1", + "Extra2" + }; + // the idea is to have a debug bitmask, maybe 8 bits wide, where the bits can be set via compiler flags - std::cout << "[ " << std::left << std::setw(16) << function << ": " << std::right << std::setw(4) << line << " ] " << message << std::endl; + inline uint8_t debugMask; + + static void debugPrint(const char* function, int line, std::string message, size_t debugLevel) { + + if(!(debugMask >> debugLevel)) return; // then ignore this debug level + + std::cout << "[ " << std::left << std::setw(16) << function << ": " << std::right << std::setw(4) << line << ", " << std::left << std::setw(8) << debugTypeStrings[debugLevel] << " ] " << message << std::endl; return; } + static void parseDebugMaskString(std::string& debugMaskString) { + std::string value = debugMaskString; + if(value.rfind("0b", 0) == 0) { + value = value.substr(2); // strip the binary literal identifier + } else { + std::cout << "Unsupported debug key." << std::endl; + } + debugMask = static_cast(std::stoul(value, nullptr, 2)); // interpret a string as a uint + } + } \ No newline at end of file