diff --git a/CMakeLists.txt b/CMakeLists.txt index 9473a5f..ad8603b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,8 +73,10 @@ endif() # External Dep paths set(GLFW_PATH ../glfw/) set(GLAD_PATH ../glad/) +set(STBIMAGE_PATH ../stbi_image) get_filename_component(GLFW_PATH ${GLFW_PATH} ABSOLUTE) get_filename_component(GLAD_PATH ${GLAD_PATH} ABSOLUTE) +get_filename_component(STBIMAGE_PATH ${STBIMAGE_PATH} ABSOLUTE) add_subdirectory(./engine) diff --git a/engine/NBCore/ErrorsImpl.hpp b/engine/NBCore/ErrorsImpl.hpp index c5b8589..eecc50b 100644 --- a/engine/NBCore/ErrorsImpl.hpp +++ b/engine/NBCore/ErrorsImpl.hpp @@ -9,15 +9,11 @@ #include #include "StringUtils.hpp" -#include "TypeTraits.hpp" namespace nb { typedef std::unordered_map ErrorCodeMap; -template -class Error; - class ErrorBase { protected: @@ -136,40 +132,40 @@ class Error : public ErrorBase { using ErrorBase::type; }; - -template<> -class Error : public Error> { - using Base = Error>; +class NBError : public Error { + protected: + using Base = Error; public: - using Base::Base; - - Error(unsigned int code_=1) noexcept : Base(code_) {} + enum Codes : unsigned int { + STANDARD, UNDEFINED, INDEX_ERROR + }; - Error(const std::exception& err) : Base( - Codes::STANDARD, + NBError(unsigned int code_=1) noexcept : Base(code_) {} + NBError(const std::exception& err) : Base( + STANDARD, std::string(err.what()), "std::exception", nullptr ) {} // fix - Error(std::string msg_) noexcept : Base( + NBError(std::string msg_) noexcept : Base( Codes::UNDEFINED, msg_ ) {} - enum Codes : unsigned int { - STANDARD, UNDEFINED + inline static const std::string type = "nb::Error"; + inline static const ErrorCodeMap ErrorMessages = { + {STANDARD, "std::exception"}, + {UNDEFINED, "Error"}, + {INDEX_ERROR, "Indexing error"} }; - - using Base::what; - using Base::code; - using Base::msg; - using Base::trace; - static const std::string type; - static const ErrorCodeMap ErrorMessages; }; + +// template +// Error(Args...) -> Error; + } // namespace nb #endif // _NB_ERRORS_IMPL \ No newline at end of file diff --git a/engine/NBCore/Logger.hpp b/engine/NBCore/Logger.hpp index f4e79be..f24181e 100644 --- a/engine/NBCore/Logger.hpp +++ b/engine/NBCore/Logger.hpp @@ -138,6 +138,15 @@ public: static_cast(this)->write_message(err.what(), lvl, file, line); } + template + std::enable_if_t, void> write_message( + const U& val, + uint8_t lvl=0x00, + std::string file="", + unsigned int line=0 + ) { + static_cast(this)->write_message(std::to_string(val), lvl, file, line); + } }; class DefaultDebugLogger : public DebugLogger { diff --git a/engine/NBCore/TypeTraits.hpp b/engine/NBCore/TypeTraits.hpp index fb990fe..93d32b6 100644 --- a/engine/NBCore/TypeTraits.hpp +++ b/engine/NBCore/TypeTraits.hpp @@ -33,6 +33,9 @@ namespace detail { struct NoneType{}; +template +using Const_t = std::integral_constant; + template < template class Op, class... Args @@ -109,6 +112,41 @@ ForEach(std::tuple& tup, Func f, const Args& arg) { ForEach(tup, f, arg); } +template +struct Find; + +template +struct Find { + protected: + using here = Find; + static constexpr unsigned int downstream = std::conditional_t< + here::value, + Const_t, + Find + >::value; + + public: + static constexpr unsigned int value = std::conditional_t< + here::value, + Const_t, + std::conditional_t< + downstream, + Const_t, + Const_t + > + >::value; +}; + +template +struct Find { + public: + static constexpr unsigned int value = std::conditional_t< + std::is_base_of::value, + std::integral_constant, + std::integral_constant + >::value; +}; + template struct RefPackToPtrVec { RefPackToPtrVec(std::vector _vec, Pack1& p1, Pack&... packs) diff --git a/engine/NBCore/Utils.hpp b/engine/NBCore/Utils.hpp index 76ae1ed..b704a86 100644 --- a/engine/NBCore/Utils.hpp +++ b/engine/NBCore/Utils.hpp @@ -54,7 +54,9 @@ ByteVector concatVectorBytes(const std::vector& vec1, const std::vector& v template std::vector bytesToVector(const ByteVector& vec) { if (vec.size() % sizeof(T) != 0) { - THROW(std::runtime_error("Data size does not align to std::vector<" + std::string(typeid(T).name()) + ">.")); + THROW(Error( + std::runtime_error("Data size does not align to std::vector<" + std::string(typeid(T).name()) + ">.") + )); } unsigned int num_elmts = vec.size() / sizeof(T); std::vector ret(num_elmts); diff --git a/engine/NBCore/src/ErrorsImpl.cpp b/engine/NBCore/src/ErrorsImpl.cpp index a36b110..44bc1ad 100644 --- a/engine/NBCore/src/ErrorsImpl.cpp +++ b/engine/NBCore/src/ErrorsImpl.cpp @@ -2,15 +2,10 @@ namespace nb { -const std::string Error<>::type = "nb::Error"; -const ErrorCodeMap Error<>::ErrorMessages = { - {Error::Codes::STANDARD, "std::exception"}, - {Error::Codes::UNDEFINED, "Error"} -}; - //ErrorBase:: - ErrorBase::ErrorBase(const std::exception& exception_) noexcept -: ErrorBase(Error(exception_)) {} +: ErrorBase(NBError(exception_)) {} + +} // namespace nb + -}