Skip to content

Commit 30f2945

Browse files
authored
Merge pull request #14 from SpaRcle-Studio/dev
(Merge) Merge dev to features/new_cpp_scripting.
2 parents 4e864c2 + dd83c30 commit 30f2945

File tree

722 files changed

+343
-208186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

722 files changed

+343
-208186
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
[submodule "libs/rapidyaml"]
1111
path = libs/rapidyaml
1212
url = https://github.com/SpaRcle-Studio/rapidyaml.git
13-
[submodule "libs/cppcoro"]
14-
path = libs/cppcoro
15-
url = https://github.com/SpaRcle-Studio/cppcoro
1613
[submodule "libs/zlib"]
1714
path = libs/zlib
1815
url = https://github.com/SpaRcle-Studio/zlib.git
@@ -43,6 +40,9 @@
4340
[submodule "libs/entt"]
4441
path = libs/entt
4542
url = https://github.com/SpaRcle-Studio/entt
43+
[submodule "libs/asio"]
44+
path = libs/asio
45+
url = https://github.com/SpaRcle-Studio/asio
4646
[submodule "libs/efsw"]
4747
path = libs/efsw
4848
url = https://github.com/SpaRcle-Studio/efsw

CMakeLists.txt

Lines changed: 84 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ option(SR_COMMON_OPENSSL "" ON)
99
option(SR_COMMON_SDL "" OFF)
1010
option(SR_COMMON_CURL "" OFF)
1111
option(SR_COMMON_JSON "" OFF)
12-
option(SR_COMMON_MYHTML "" ON)
12+
option(SR_COMMON_MYHTML "" OFF)
1313
option(SR_COMMON_LITEHTML "" OFF)
1414

1515
option(SR_COMMON_DLL_EXPORTS "" ON)
@@ -18,13 +18,23 @@ option(SR_COMMON_STATIC_LIBRARY "" ON)
1818
option(SR_COMMON_EMBED_RESOURCES "" OFF)
1919
option(SR_COMMON_CI_BUILD "" OFF)
2020

21+
22+
if (SR_COMMON_CURL)
23+
set(SR_COMMON_OPENSSL ON)
24+
endif()
25+
26+
if (SR_COMMON_OPENSSL)
27+
add_compile_definitions(SR_COMMON_OPENSSL)
28+
endif()
29+
2130
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
2231

2332
add_subdirectory(libs/tree-sitter-cpp)
2433
add_subdirectory(libs/tree-sitter/lib)
2534

2635
include(cmake/Linker.cmake)
2736

37+
2838
if (SR_COMMON_SDL)
2939
add_compile_definitions(SR_COMMON_SDL)
3040
endif()
@@ -119,10 +129,75 @@ if (SR_COMMON_GIT_METADATA)
119129
add_subdirectory(libs/cmake-git-version-tracking)
120130
endif()
121131

122-
if (SR_COMMON_CURL OR SR_COMMON_OPENSSL)
123-
add_compile_definitions(SR_COMMON_OPENSSL)
132+
set(SR_COMMON_CPPTRACE_ENABLED OFF)
133+
if (NOT ANDROID_NDK AND UNIX)
134+
set(SR_COMMON_CPPTRACE_ENABLED ON)
135+
add_subdirectory(libs/cpptrace)
124136
endif()
125137

138+
#if (SR_COMMON_OPENSSL)
139+
# # Prefer static linking
140+
# set(OPENSSL_USE_STATIC_LIBS TRUE)
141+
# set(OPENSSL_MSVC_STATIC_RUNTIME TRUE)
142+
#
143+
# # Additional paths to search for OpenSSL
144+
# if (UNIX AND NOT ANDROID_NDK)
145+
# # Common Linux OpenSSL paths
146+
# list(APPEND CMAKE_PREFIX_PATH
147+
# "/usr/local/openssl"
148+
# "/usr/local/ssl"
149+
# "/usr/local"
150+
# "/usr"
151+
# )
152+
#
153+
# # Additional library and include paths
154+
# list(APPEND CMAKE_LIBRARY_PATH
155+
# "/usr/local/openssl/lib"
156+
# "/usr/local/ssl/lib"
157+
# "/usr/local/lib"
158+
# "/usr/lib/x86_64-linux-gnu"
159+
# )
160+
#
161+
# list(APPEND CMAKE_INCLUDE_PATH
162+
# "/usr/local/openssl/include"
163+
# "/usr/local/ssl/include"
164+
# "/usr/local/include"
165+
# "/usr/include/openssl"
166+
# )
167+
# endif()
168+
#
169+
# # On macOS
170+
# if (APPLE)
171+
# # Homebrew OpenSSL paths
172+
# list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/openssl")
173+
# list(APPEND CMAKE_LIBRARY_PATH "/usr/local/opt/openssl/lib")
174+
# list(APPEND CMAKE_INCLUDE_PATH "/usr/local/opt/openssl/include")
175+
# endif()
176+
#
177+
# # On Windows
178+
# if (WIN32)
179+
# # Potential OpenSSL installation paths
180+
# list(APPEND CMAKE_PREFIX_PATH
181+
# "C:/OpenSSL-Win64"
182+
# "C:/Program Files/OpenSSL"
183+
# "C:/Program Files/OpenSSL-Win64"
184+
# )
185+
# endif()
186+
#
187+
# add_compile_definitions(SR_COMMON_OPENSSL)
188+
# find_package(OpenSSL REQUIRED)
189+
#
190+
# include_directories(${OPENSSL_INCLUDE_DIR})
191+
#
192+
# if (OpenSSL_FOUND)
193+
# message(STATUS "OpenSSL version: ${OPENSSL_VERSION}")
194+
# message(STATUS "OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
195+
# message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
196+
# else()
197+
# message(FATAL_ERROR "System OpenSSL is not found.")
198+
# endif()
199+
#endif()
200+
126201
if (SR_COMMON_CURL)
127202
set(BUILD_LIBCURL_DOCS OFF CACHE INTERNAL "" FORCE)
128203
set(ENABLE_CURL_MANUAL OFF CACHE INTERNAL "" FORCE)
@@ -167,20 +242,6 @@ if (SR_TRACY_ENABLE)
167242
endif()
168243

169244
add_subdirectory(libs/rapidyaml)
170-
171-
set(SR_COMMON_CPPCORO_ENABLED OFF)
172-
if (NOT ANDROID_NDK)
173-
set(SR_COMMON_CPPCORO_ENABLED ON)
174-
add_compile_definitions(SR_USE_CPP_CORO)
175-
add_subdirectory(libs/cppcoro)
176-
endif()
177-
178-
set(SR_COMMON_CPPTRACE_ENABLED OFF)
179-
if (NOT ANDROID_NDK AND UNIX)
180-
set(SR_COMMON_CPPTRACE_ENABLED ON)
181-
add_subdirectory(libs/cpptrace)
182-
endif()
183-
184245
add_subdirectory(libs/entt)
185246

186247
list(APPEND SR_UTILS_LINK_LIBRARIES cxx/ICU.cxx)
@@ -206,7 +267,7 @@ if (SR_COMMON_ZLIB)
206267
endif()
207268

208269
if (SR_COMMON_GIT_METADATA)
209-
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cmake-get-version-tracking)
270+
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cmake-git-version-tracking)
210271
endif()
211272

212273
if (SR_COMMON_ASSIMP)
@@ -222,7 +283,7 @@ if (SR_COMMON_JSON)
222283
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/json/include)
223284
endif()
224285

225-
if (SR_COMMON_CURL OR SR_COMMON_OPENSSL)
286+
if (SR_COMMON_OPENSSL)
226287
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/openssl/include)
227288
endif()
228289

@@ -238,10 +299,6 @@ SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs)
238299
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/glm)
239300
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/fmt/include)
240301

241-
if (SR_COMMON_CPPCORO_ENABLED)
242-
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cppcoro/include)
243-
endif()
244-
245302
if (SR_COMMON_CPPTRACE_ENABLED)
246303
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cpptrace/include)
247304
endif()
@@ -257,8 +314,8 @@ SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_BINARY_DIR}/libs/tree-sitter
257314

258315
add_library(asio INTERFACE)
259316

260-
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libs/asio/include)
261-
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/libs/asio/include)
317+
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libs/asio/asio/include)
318+
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/libs/asio/asio/include)
262319

263320
if (SR_ICU)
264321
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_BINARY_DIR}/include/icu)
@@ -319,6 +376,8 @@ if (SR_COMMON_MYHTML)
319376
set(MyHTML_BUILD_SHARED OFF CACHE INTERNAL "" FORCE)
320377
set(PROJECT_OPTIMIZATION_LEVEL "" CACHE INTERNAL "" FORCE)
321378

379+
add_compile_definitions(SR_COMMON_MYHTML)
380+
322381
add_subdirectory(libs/myhtml)
323382
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/myhtml/include)
324383
target_link_libraries(Utils myhtml_static)
@@ -382,10 +441,6 @@ if (SR_COMMON_CPPTRACE_ENABLED)
382441
target_link_libraries(Utils cpptrace::cpptrace)
383442
endif()
384443

385-
if (SR_COMMON_CPPCORO_ENABLED)
386-
target_link_libraries(Utils cppcoro)
387-
endif()
388-
389444
get_property(SR_UTILS_INCLUDE_DIRECTORIES_CONTENT GLOBAL PROPERTY SR_UTILS_INCLUDE_DIRECTORIES)
390445
message("SRCommon include directories: ${SR_UTILS_INCLUDE_DIRECTORIES_CONTENT}")
391446
target_include_directories(Utils PUBLIC ${SR_UTILS_INCLUDE_DIRECTORIES_CONTENT})

inc/Utils/Common/EnumReflector.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <Utils/Common/HashManager.h>
1010
#include <Utils/Types/Map.h>
1111
#include <Utils/Types/StringAtom.h>
12+
#include <Utils/Types/Function.h>
1213

1314
#include <Codegen/EnumsFwd.generated.hpp>
1415

@@ -76,6 +77,8 @@ namespace SR_UTILS_NS {
7677
~EnumReflector() override;
7778

7879
public:
80+
template<typename EnumType> static void ForEach(SR_HTYPES_NS::Function<void(EnumType)> func);
81+
7982
template<typename EnumType> SR_NODISCARD static EnumReflector* GetReflector();
8083
template<typename EnumType> SR_NODISCARD static uint64_t Count();
8184
template<typename EnumType> SR_NODISCARD static SR_UTILS_NS::StringAtom ToStringAtom(EnumType value);
@@ -320,6 +323,13 @@ namespace SR_UTILS_NS {
320323
return GetReflector<EnumType>()->GetEnumVariantInternal();
321324
}
322325

326+
template <typename EnumType>
327+
void EnumReflector::ForEach(Types::Function<void(EnumType)> func) {
328+
for (auto&& item : GetReflector<EnumType>()->m_data->values) {
329+
func(static_cast<EnumType>(item.value));
330+
}
331+
}
332+
323333
template<typename EnumType> EnumReflector* EnumReflector::GetReflector() {
324334
if constexpr (std::is_class_v<EnumType>) {
325335
if constexpr (std::is_enum_v<EnumType>) {

inc/Utils/Common/StringUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ namespace SR_UTILS_NS {
223223
static std::string GetExtensionFromFilePath(std::string path);
224224
static std::string Reverse(const std::string& str);
225225

226+
static std::string ToKebabCase(std::string_view str);
227+
226228
static glm::vec2 MakeVec2FromString(const char* source, char chr, unsigned short start);
227229
static glm::vec3 MakeVec3FromString(const char* source, char chr, unsigned short start);
228230

inc/Utils/Input/InputSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace SR_UTILS_NS {
4949

5050
void LockCursor();
5151
void UnlockCursor();
52+
void ForceUnlockCursor();
5253

5354
private:
5455
void Reset();

inc/Utils/Network/Asio/AsioTCPAcceptor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <Utils/Network/Acceptor.h>
99

1010
#include <asio/ip/tcp.hpp>
11-
#include <asio/io_service.hpp>
1211

1312
namespace SR_NETWORK_NS {
1413
class AsioContext;

inc/Utils/Network/Message.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// Created by innerviewer on 2025-03-30.
3+
//
4+
5+
#ifndef SR_COMMON_NETWORK_MESSAGE_H
6+
#define SR_COMMON_NETWORK_MESSAGE_H
7+
8+
namespace SR_NETWORK_NS {
9+
class IMessage {
10+
public:
11+
virtual ~IMessage() = default;
12+
13+
// For type-safe message identification
14+
template<typename T>
15+
SR_NODISCARD bool is() const {
16+
static_assert(std::is_enum_v<T>, "Message ID must be an enum type");
17+
return getTypeID() == typeid(T);
18+
}
19+
20+
// For getting the actual message ID value
21+
template<typename T>
22+
T getID() const {
23+
static_assert(std::is_enum_v<T>, "Message ID must be an enum type");
24+
return static_cast<T>(getRawID());
25+
}
26+
27+
protected:
28+
SR_NODISCARD virtual std::size_t getTypeID() const = 0;
29+
SR_NODISCARD virtual int64_t getRawID() const = 0;
30+
};
31+
32+
// Message data interface
33+
class IMessageData {
34+
public:
35+
virtual ~IMessageData() = default;
36+
SR_NODISCARD virtual std::unique_ptr<IMessageData> clone() const = 0;
37+
};
38+
39+
// Concrete message implementation
40+
template<typename T, typename DataT = void>
41+
class Message final : public IMessage {
42+
static_assert(std::is_enum_v<T>, "Message ID must be an enum type");
43+
44+
public:
45+
explicit Message(T id) : m_id(id) {}
46+
47+
Message(T id, DataT data) : m_id(id), m_data(std::move(data)) {}
48+
49+
// Type identification
50+
SR_NODISCARD std::size_t getTypeID() const override {
51+
return typeid(T).hash_code();
52+
}
53+
54+
// Get the raw message ID
55+
SR_NODISCARD int64_t getRawID() const override {
56+
return static_cast<int64_t>(m_id);
57+
}
58+
59+
// Check if message has data
60+
SR_NODISCARD bool hasData() const {
61+
return !std::is_same_v<DataT, void>;
62+
}
63+
64+
// Get message data (only if DataT is not void)
65+
template<typename U = DataT>
66+
std::enable_if_t<!std::is_same_v<U, void>, const U&> getData() const {
67+
return m_data;
68+
}
69+
70+
private:
71+
T m_id;
72+
DataT m_data;
73+
};
74+
75+
// Message handler interface
76+
class IMessageHandler {
77+
public:
78+
virtual ~IMessageHandler() = default;
79+
virtual void handleMessage(const IMessage& message) = 0;
80+
};
81+
}
82+
83+
#endif //SR_COMMON_NETWORK_MESSAGE_H

inc/Utils/Platform/Platform.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ namespace SR_UTILS_NS::Platform {
9696

9797
SR_COMMON_DLL_API extern void SetMousePos(const SR_MATH_NS::IVector2& pos);
9898
SR_COMMON_DLL_API extern void SetCursorVisible(bool isVisible);
99+
SR_COMMON_DLL_API extern void ConfineCursor(); // TODO: add ability to confine cursor to a specific window
100+
SR_COMMON_DLL_API extern void ReleaseCursorConfinement(); // TODO: add ability to confine cursor to a specific window
99101
SR_COMMON_DLL_API extern void SetThreadPriority(void* nativeHandle, ThreadPriority priority);
100102
SR_COMMON_DLL_API extern void CopyPermissions(const SR_UTILS_NS::Path& source, const SR_UTILS_NS::Path& destination);
101-
102103
}
103104
#endif //SR_ENGINE_UTILS_PLATFORM_H

inc/Utils/macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
#define SR_FORCE_INLINE SR_INLINE
161161
#elif defined(SR_GCC)
162162
#define SR_FASTCALL
163-
#define SR_FORCE_INLINE SR_INLINE
163+
#define SR_FORCE_INLINE __attribute__((always_inline))
164164
#else
165165
#define SR_FASTCALL __fastcall
166166
#define SR_FORCE_INLINE __forceinline

libs/asio

Submodule asio added at a892f73

0 commit comments

Comments
 (0)