Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions inc/Utils/Common/HashManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ namespace SR_UTILS_NS {
constexpr uint64_t ConstexprStringsMaxEntries = 512;

struct GlobalStringRegistry {
mutable std::array<ConstexprStringHashEntry, ConstexprStringsMaxEntries> entries = {};
mutable uint64_t count = 0;
constexpr GlobalStringRegistry()
: entries{}
, count(0)
{ }

mutable std::array<ConstexprStringHashEntry, ConstexprStringsMaxEntries> entries;
mutable uint64_t count;


constexpr uint64_t Register(std::string_view str, uint64_t hash) const {
if (count < ConstexprStringsMaxEntries) {
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion inc/Utils/Common/Hashes.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace SR_UTILS_NS {
};

template<typename T> constexpr uint64_t CalculateHash(const T& value) {
static SRHash<T> h;
constexpr SRHash<T> h;
return h(value);
}

Expand Down
4 changes: 2 additions & 2 deletions inc/Utils/Common/StringAtomLiterals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 13 additions & 4 deletions inc/Utils/ECS/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
#ifndef SR_ENGINE_UTILS_COMPONENT_H
#define SR_ENGINE_UTILS_COMPONENT_H

#include <Utils/Common/Singleton.h>
#include <Utils/Common/Hashes.h>
#include <Utils/Common/StringUtils.h>
#include <Utils/Common/CollisionData.h>
#include <Utils/Common/CollisionData.h>
#include <Utils/Common/CollisionData.h>

#include <Utils/ECS/EntityManager.h>

#include <Utils/Math/Vector3.h>

#include <Utils/World/Scene.h>

#include <Utils/Types/SafePointer.h>
#include <Utils/Types/SharedPtr.h>
#include <Utils/Common/Singleton.h>
#include <Utils/Common/Hashes.h>
#include <Utils/Common/StringUtils.h>
#include <Utils/Types/Marshal.h>
#include <Utils/Types/SafeVariable.h>
#include <Utils/Common/CollisionData.h>
#include <Utils/Types/SharedPtr.h>
#include <Utils/Types/SharedPtr.h>

#include <Utils/TypeTraits/Properties.h>

/**
Expand Down
1 change: 1 addition & 0 deletions inc/Utils/ECS/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Utils/ECS/SceneObject.h>
#include <Utils/ECS/TagManager.h>
#include <Utils/ECS/Prefab.h>
#include <Utils/ECS/Transform.h>

#include <Utils/Math/Vector3.h>
#include <Utils/Types/SafePointer.h>
Expand Down
13 changes: 11 additions & 2 deletions inc/Utils/TypeTraits/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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;
}

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;
Expand All @@ -48,6 +48,15 @@ namespace SR_UTILS_NS {
char name[MaxNameLength]{};
};

template <typename T, typename = void>
struct IsCompleteType : std::false_type {};

template <typename T>
struct IsCompleteType<T, std::void_t<decltype(sizeof(T))>> : std::true_type {};

template <typename T>
constexpr bool IsCompleteTypeV = IsCompleteType<T>::value;

template<template<typename, size_t> typename Tmpl1>
struct IsStdArrayTemplate : std::false_type
{};
Expand Down
6 changes: 5 additions & 1 deletion inc/Utils/Types/SharedPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Utils/Common/TypeInfo.h>
#include <Utils/Debug.h>
#include <Utils/Platform/Platform.h>
#include <Utils/TypeTraits/TypeTraits.h>

namespace SR_UTILS_NS {
enum class SharedPtrPolicy : uint8_t {
Expand Down Expand Up @@ -231,7 +232,10 @@ namespace SR_HTYPES_NS {
return;
}

if constexpr (SR_UTILS_NS::IsDerivedFrom<SharedPtr, T>::value) {
if constexpr (!SR_UTILS_NS::IsCompleteTypeV<T>) {
SR_SAFE_PTR_ASSERT(ptr == nullptr, "Ptr is not nullptr!");
}
else if constexpr (SR_UTILS_NS::IsDerivedFrom<SharedPtr, T>::value) {
if ((m_data = ptr->GetPtrData())) {
m_data->IncrementStrong();
m_ptr = ptr;
Expand Down
2 changes: 1 addition & 1 deletion inc/Utils/Types/StringAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions inc/Utils/Web/HTML/HTML.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
#include <Utils/Types/SharedPtr.h>
#include <Utils/Common/PassKey.h>

#include <litehtml.h>
#ifdef SR_COMMON_LITEHTML
#include <litehtml.h>
#endif

namespace SR_UTILS_NS::Web {
class HTMLPage;


#ifdef SR_COMMON_LITEHTML
class HTMLContainerInterface : public SR_HTYPES_NS::SharedPtr<HTMLContainerInterface>, public litehtml::document_container {
using Super = SR_HTYPES_NS::SharedPtr<HTMLContainerInterface>;
public:
Expand Down Expand Up @@ -77,6 +81,12 @@ namespace SR_UTILS_NS::Web {

};

#else
class HTMLContainerInterface : public SR_HTYPES_NS::SharedPtr<HTMLContainerInterface> {

};
#endif

class HTMLPage final : public SR_HTYPES_NS::SharedPtr<HTMLPage> {
using Super = SR_HTYPES_NS::SharedPtr<HTMLPage>;
private:
Expand All @@ -92,13 +102,22 @@ namespace SR_UTILS_NS::Web {

SR_NODISCARD const std::vector<SR_UTILS_NS::Path>& 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

};
}
Expand Down
2 changes: 2 additions & 0 deletions inc/Utils/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions py/ResourceEmbedder.py
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Common/HashManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Types/StringAtom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{ }

Expand Down