diff --git a/deps/ox/src/ox/std/bitops.hpp b/deps/ox/src/ox/std/bitops.hpp index 61607d75..febc9cb0 100644 --- a/deps/ox/src/ox/std/bitops.hpp +++ b/deps/ox/src/ox/std/bitops.hpp @@ -8,8 +8,6 @@ #pragma once -#include "types.hpp" - namespace ox { template @@ -18,4 +16,13 @@ inline constexpr T rotateLeft(T i, int shift) { return (i << shift) | (i >> (bits - shift)); } +template +constexpr T onMask(int bits) { + T out = 0; + for (auto i = 0; i < bits; i++) { + out |= 1 << i; + } + return out; +} + } diff --git a/deps/ox/src/ox/std/random.hpp b/deps/ox/src/ox/std/random.hpp index a6be6b02..ce089d1c 100644 --- a/deps/ox/src/ox/std/random.hpp +++ b/deps/ox/src/ox/std/random.hpp @@ -8,15 +8,13 @@ #pragma once -uint64_t ox_rand(); +#include "types.hpp" namespace ox { -typedef uint64_t RandomSeed[2]; +using RandomSeed = uint64_t[2]; class Random { - public: - private: RandomSeed m_seed; diff --git a/deps/ox/src/ox/std/types.hpp b/deps/ox/src/ox/std/types.hpp index 0bff8d03..20b96063 100644 --- a/deps/ox/src/ox/std/types.hpp +++ b/deps/ox/src/ox/std/types.hpp @@ -8,6 +8,8 @@ #pragma once +#include "bitops.hpp" + #if OX_USE_STDLIB #include @@ -52,7 +54,39 @@ typedef uint32_t uintptr_t; namespace ox { -using Error = uint32_t; +using Error = uint64_t; + +struct ErrorInfo { + const char *file = nullptr; + int line = -1; + Error errCode = 0; + + ErrorInfo() = default; + + ErrorInfo(Error err) { + this->file = reinterpret_cast(err & onMask(48)); + this->line = static_cast((err >> 48) & onMask(5)); + this->errCode = (err >> 59) & onMask(11); + } +}; + +constexpr Error ErrorTags(Error line, Error errCode) { + line &= onMask(5); + line <<= 48; + errCode &= onMask(11); + errCode <<= 59; + return errCode | line; +} + +} + +#ifdef DEBUG +#define OxError(x) reinterpret_cast(__FILE__) | ErrorTags(__LINE__, x) +#else +#define OxError(x) x +#endif + +namespace ox { template struct ValErr {