diff --git a/CMakeLists.txt b/CMakeLists.txt index 5616ad52..33f67795 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ option(SR_COMMON_SDL "" OFF) option(SR_COMMON_CURL "" OFF) option(SR_COMMON_JSON "" OFF) option(SR_COMMON_MYHTML "" ON) -option(SR_COMMON_LITEHTML "" ON) +option(SR_COMMON_LITEHTML "" OFF) option(SR_COMMON_DLL_EXPORTS "" ON) option(SR_COMMON_GIT_METADATA "" ON) @@ -22,6 +22,10 @@ if (SR_COMMON_SDL) add_compile_definitions(SR_COMMON_SDL) endif() +if (SR_COMMON_LITEHTML) + add_compile_definitions(SR_COMMON_LITEHTML) +endif() + if (SR_COMMON_EMBED_RESOURCES) add_compile_definitions(SR_COMMON_EMBED_RESOURCES) endif() diff --git a/inc/Utils/Common/HashManager.h b/inc/Utils/Common/HashManager.h index 28463522..82cdfa96 100644 --- a/inc/Utils/Common/HashManager.h +++ b/inc/Utils/Common/HashManager.h @@ -62,8 +62,14 @@ namespace SR_UTILS_NS { constexpr uint64_t ConstexprStringsMaxEntries = 512; struct GlobalStringRegistry { - mutable std::array entries = {}; - mutable uint64_t count = 0; + constexpr GlobalStringRegistry() + : entries{} + , count(0) + { } + + mutable std::array entries; + mutable uint64_t count; + constexpr uint64_t Register(std::string_view str, uint64_t hash) const { if (count < ConstexprStringsMaxEntries) { @@ -91,7 +97,7 @@ namespace SR_UTILS_NS { }; /// TODO: может быть баг при использовании dll - inline constexpr GlobalStringRegistry g_StringRegistry = {}; + //inline constexpr GlobalStringRegistry g_StringRegistry = GlobalStringRegistry(); } #define SR_HASH_CONSTEXPR_STR_VIEW_REGISTER(x) (SR_UTILS_NS::g_StringRegistry.Register(x, SR_HASH_STR_VIEW(x))) diff --git a/inc/Utils/Common/Hashes.h b/inc/Utils/Common/Hashes.h index fa340359..a0f4d571 100644 --- a/inc/Utils/Common/Hashes.h +++ b/inc/Utils/Common/Hashes.h @@ -178,7 +178,7 @@ namespace SR_UTILS_NS { }; template constexpr uint64_t CalculateHash(const T& value) { - static SRHash h; + constexpr SRHash h; return h(value); } diff --git a/inc/Utils/Common/StringAtomLiterals.h b/inc/Utils/Common/StringAtomLiterals.h index 5a1840d7..6730a1d2 100644 --- a/inc/Utils/Common/StringAtomLiterals.h +++ b/inc/Utils/Common/StringAtomLiterals.h @@ -20,9 +20,9 @@ SR_INLINE uint64_t operator"" _atom_hash(const char* str, size_t) { /// return SR_UTILS_NS::StringAtom(str); /// } -constexpr uint64_t operator"" _atom_hash_cexpr(const char* str, size_t size) { +/*constexpr uint64_t operator"" _atom_hash_cexpr(const char* str, size_t size) { const auto strView = std::string_view(str, size); return SR_HASH_CONSTEXPR_STR_VIEW_REGISTER(strView); -} +}*/ #endif //SR_COMMON_STRING_ATOM_LITERALS_H diff --git a/inc/Utils/ECS/Component.h b/inc/Utils/ECS/Component.h index 25f3e7f0..5ec925ba 100644 --- a/inc/Utils/ECS/Component.h +++ b/inc/Utils/ECS/Component.h @@ -5,17 +5,26 @@ #ifndef SR_ENGINE_UTILS_COMPONENT_H #define SR_ENGINE_UTILS_COMPONENT_H +#include +#include +#include +#include +#include +#include + #include + #include + +#include + #include #include -#include -#include -#include #include #include -#include #include +#include + #include /** diff --git a/inc/Utils/ECS/GameObject.h b/inc/Utils/ECS/GameObject.h index 030a8c89..204923ec 100644 --- a/inc/Utils/ECS/GameObject.h +++ b/inc/Utils/ECS/GameObject.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/inc/Utils/TypeTraits/TypeTraits.h b/inc/Utils/TypeTraits/TypeTraits.h index bad2ce19..3ca3cdaa 100644 --- a/inc/Utils/TypeTraits/TypeTraits.h +++ b/inc/Utils/TypeTraits/TypeTraits.h @@ -25,7 +25,7 @@ namespace SR_UTILS_NS { static SerializationId CreateFromCStr(const char* text) noexcept { SerializationId id; - strncpy_s(id.name, text, MaxNameLength - 1); + SR_STRNCPY(id.name, text, MaxNameLength - 1); id.name[MaxNameLength - 1] = '\0'; id.hash = ComputeHash(text); return id; @@ -33,7 +33,7 @@ namespace SR_UTILS_NS { static SerializationId CreateFromString(const std::string_view text) noexcept { SerializationId id; - strncpy_s(id.name, text.data(), std::min(text.size(), MaxNameLength - 1)); + SR_STRNCPY(id.name, text.data(), std::min(text.size(), MaxNameLength - 1)); id.name[MaxNameLength - 1] = '\0'; id.hash = ComputeHash(text); return id; @@ -48,6 +48,15 @@ namespace SR_UTILS_NS { char name[MaxNameLength]{}; }; + template + struct IsCompleteType : std::false_type {}; + + template + struct IsCompleteType> : std::true_type {}; + + template + constexpr bool IsCompleteTypeV = IsCompleteType::value; + template typename Tmpl1> struct IsStdArrayTemplate : std::false_type {}; diff --git a/inc/Utils/Types/SharedPtr.h b/inc/Utils/Types/SharedPtr.h index 7c0f9158..abecde5b 100644 --- a/inc/Utils/Types/SharedPtr.h +++ b/inc/Utils/Types/SharedPtr.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace SR_UTILS_NS { enum class SharedPtrPolicy : uint8_t { @@ -231,7 +232,10 @@ namespace SR_HTYPES_NS { return; } - if constexpr (SR_UTILS_NS::IsDerivedFrom::value) { + if constexpr (!SR_UTILS_NS::IsCompleteTypeV) { + SR_SAFE_PTR_ASSERT(ptr == nullptr, "Ptr is not nullptr!"); + } + else if constexpr (SR_UTILS_NS::IsDerivedFrom::value) { if ((m_data = ptr->GetPtrData())) { m_data->IncrementStrong(); m_ptr = ptr; diff --git a/inc/Utils/Types/StringAtom.h b/inc/Utils/Types/StringAtom.h index 3c1b8543..5a7bb8b5 100644 --- a/inc/Utils/Types/StringAtom.h +++ b/inc/Utils/Types/StringAtom.h @@ -22,7 +22,7 @@ namespace SR_UTILS_NS { constexpr StringAtom(StringHashInfo* pInfo); /// NOLINT constexpr StringAtom(const char* str); /// NOLINT constexpr StringAtom(const std::string& str); /// NOLINT - constexpr StringAtom(const std::string_view& str); /// NOLINT + StringAtom(std::string_view str); /// NOLINT public: operator const std::string&() const noexcept; /// NOLINT diff --git a/inc/Utils/Web/HTML/HTML.h b/inc/Utils/Web/HTML/HTML.h index 32176d99..fcf0c0dd 100644 --- a/inc/Utils/Web/HTML/HTML.h +++ b/inc/Utils/Web/HTML/HTML.h @@ -11,11 +11,15 @@ #include #include -#include +#ifdef SR_COMMON_LITEHTML + #include +#endif namespace SR_UTILS_NS::Web { class HTMLPage; + +#ifdef SR_COMMON_LITEHTML class HTMLContainerInterface : public SR_HTYPES_NS::SharedPtr, public litehtml::document_container { using Super = SR_HTYPES_NS::SharedPtr; public: @@ -77,6 +81,12 @@ namespace SR_UTILS_NS::Web { }; +#else + class HTMLContainerInterface : public SR_HTYPES_NS::SharedPtr { + + }; +#endif + class HTMLPage final : public SR_HTYPES_NS::SharedPtr { using Super = SR_HTYPES_NS::SharedPtr; private: @@ -92,13 +102,22 @@ namespace SR_UTILS_NS::Web { SR_NODISCARD const std::vector& GetPaths() const; SR_NODISCARD HTMLContainerInterface::Ptr GetContainer() const { return m_container; } - SR_NODISCARD litehtml::document::ptr GetDocument() const { return m_document; } - protected: + + #ifdef SR_COMMON_LITEHTML + SR_NODISCARD litehtml::document::ptr GetDocument() const { return m_document; } + #else + SR_NODISCARD void* GetDocument() const { return nullptr; } + #endif private: HTMLContainerInterface::Ptr m_container; + + #ifdef SR_COMMON_LITEHTML litehtml::document::ptr m_document; + #else + void* m_document; + #endif }; } diff --git a/inc/Utils/macros.h b/inc/Utils/macros.h index b8c816b3..c020f839 100644 --- a/inc/Utils/macros.h +++ b/inc/Utils/macros.h @@ -299,8 +299,10 @@ #if defined(SR_MSVC) #define SR_STRCMPI _strcmpi + #define SR_STRNCPY strncpy_s #else #define SR_STRCMPI strcasecmp + #define SR_STRNCPY strncpy #endif #ifdef SR_MSVC diff --git a/py/ResourceEmbedder.py b/py/ResourceEmbedder.py index 39b81d5a..6abc9762 100644 --- a/py/ResourceEmbedder.py +++ b/py/ResourceEmbedder.py @@ -1,5 +1,7 @@ from Common import * +print("ResourceEmbedder.py: running...") + def needs_update(path, export_path): if not os.path.exists(path): print(f"Path does not exist: {path}") diff --git a/src/Utils/Common/HashManager.cpp b/src/Utils/Common/HashManager.cpp index 77b25560..1f335d9c 100644 --- a/src/Utils/Common/HashManager.cpp +++ b/src/Utils/Common/HashManager.cpp @@ -39,9 +39,9 @@ namespace SR_UTILS_NS { return pIt->second->view; } - if (const auto str = g_StringRegistry.FindConstexprStringByHash(hash)) { + /*if (const auto str = g_StringRegistry.FindConstexprStringByHash(hash)) { return str.value(); - } + }*/ return gDefault; } diff --git a/src/Utils/Types/StringAtom.cpp b/src/Utils/Types/StringAtom.cpp index edd99bea..17b35fc8 100644 --- a/src/Utils/Types/StringAtom.cpp +++ b/src/Utils/Types/StringAtom.cpp @@ -20,7 +20,7 @@ namespace SR_UTILS_NS { : StringAtom(SR_UTILS_NS::HashManager::Instance().GetOrAddInfo(str)) { } - constexpr StringAtom::StringAtom(const std::string_view& str) + StringAtom::StringAtom(std::string_view str) : StringAtom(SR_UTILS_NS::HashManager::Instance().GetOrAddInfo(str)) { }