feat(debug): add basic debug functions

This commit is contained in:
fallenoak 2023-03-03 11:55:23 -06:00 committed by GitHub
parent 3728c3d167
commit d817c41985
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 0 deletions

11
bc/Debug.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "bc/Debug.hpp"
void Blizzard::Debug::Assert(const char* a1, const char* a2, uint32_t a3) {
if (System_Debug::s_assertCallback) {
System_Debug::s_assertCallback(a1, "", a2, a3);
}
}
void Blizzard::Debug::SetAssertHandler(Blizzard::System_Debug::AssertCallback callback) {
System_Debug::s_assertCallback = callback;
}

29
bc/Debug.hpp Normal file
View file

@ -0,0 +1,29 @@
#ifndef BC_DEBUG_HPP
#define BC_DEBUG_HPP
#include "bc/System_Debug.hpp"
#include <cstdint>
#if defined(NDEBUG)
#define BLIZZARD_ASSERT(x) \
if (!(x)) { \
return 0; \
}
#else
#define BLIZZARD_ASSERT(x) \
if (!(x)) { \
Blizzard::Debug::Assert(#x, __FILE__, __LINE__); \
}
#endif
namespace Blizzard {
namespace Debug {
// Functions
void Assert(const char* a1, const char* a2, uint32_t a3);
void SetAssertHandler(Blizzard::System_Debug::AssertCallback callback);
} // namespace Debug
} // namespace Blizzard
#endif

3
bc/System_Debug.cpp Normal file
View file

@ -0,0 +1,3 @@
#include "bc/System_Debug.hpp"
Blizzard::System_Debug::AssertCallback Blizzard::System_Debug::s_assertCallback;

18
bc/System_Debug.hpp Normal file
View file

@ -0,0 +1,18 @@
#ifndef BC_SYSTEM_DEBUG_HPP
#define BC_SYSTEM_DEBUG_HPP
#include <cstdint>
namespace Blizzard {
namespace System_Debug {
// Types
typedef void (*AssertCallback)(const char*, const char*, const char*, uint32_t);
// Variables
extern AssertCallback s_assertCallback;
} // namespace System_Debug
} // namespace Blizzard
#endif