Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
[submodule "libs/rapidyaml"]
path = libs/rapidyaml
url = https://github.com/SpaRcle-Studio/rapidyaml.git
[submodule "libs/cppcoro"]
path = libs/cppcoro
url = https://github.com/SpaRcle-Studio/cppcoro
[submodule "libs/zlib"]
path = libs/zlib
url = https://github.com/SpaRcle-Studio/zlib.git
Expand Down Expand Up @@ -43,6 +40,9 @@
[submodule "libs/entt"]
path = libs/entt
url = https://github.com/SpaRcle-Studio/entt
[submodule "libs/asio"]
path = libs/asio
url = https://github.com/SpaRcle-Studio/asio
[submodule "libs/efsw"]
path = libs/efsw
url = https://github.com/SpaRcle-Studio/efsw
Expand Down
113 changes: 84 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ option(SR_COMMON_OPENSSL "" ON)
option(SR_COMMON_SDL "" OFF)
option(SR_COMMON_CURL "" OFF)
option(SR_COMMON_JSON "" OFF)
option(SR_COMMON_MYHTML "" ON)
option(SR_COMMON_MYHTML "" OFF)
option(SR_COMMON_LITEHTML "" OFF)

option(SR_COMMON_DLL_EXPORTS "" ON)
Expand All @@ -18,13 +18,23 @@ option(SR_COMMON_STATIC_LIBRARY "" ON)
option(SR_COMMON_EMBED_RESOURCES "" OFF)
option(SR_COMMON_CI_BUILD "" OFF)


if (SR_COMMON_CURL)
set(SR_COMMON_OPENSSL ON)
endif()

if (SR_COMMON_OPENSSL)
add_compile_definitions(SR_COMMON_OPENSSL)
endif()

set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)

add_subdirectory(libs/tree-sitter-cpp)
add_subdirectory(libs/tree-sitter/lib)

include(cmake/Linker.cmake)


if (SR_COMMON_SDL)
add_compile_definitions(SR_COMMON_SDL)
endif()
Expand Down Expand Up @@ -119,10 +129,75 @@ if (SR_COMMON_GIT_METADATA)
add_subdirectory(libs/cmake-git-version-tracking)
endif()

if (SR_COMMON_CURL OR SR_COMMON_OPENSSL)
add_compile_definitions(SR_COMMON_OPENSSL)
set(SR_COMMON_CPPTRACE_ENABLED OFF)
if (NOT ANDROID_NDK AND UNIX)
set(SR_COMMON_CPPTRACE_ENABLED ON)
add_subdirectory(libs/cpptrace)
endif()

#if (SR_COMMON_OPENSSL)
# # Prefer static linking
# set(OPENSSL_USE_STATIC_LIBS TRUE)
# set(OPENSSL_MSVC_STATIC_RUNTIME TRUE)
#
# # Additional paths to search for OpenSSL
# if (UNIX AND NOT ANDROID_NDK)
# # Common Linux OpenSSL paths
# list(APPEND CMAKE_PREFIX_PATH
# "/usr/local/openssl"
# "/usr/local/ssl"
# "/usr/local"
# "/usr"
# )
#
# # Additional library and include paths
# list(APPEND CMAKE_LIBRARY_PATH
# "/usr/local/openssl/lib"
# "/usr/local/ssl/lib"
# "/usr/local/lib"
# "/usr/lib/x86_64-linux-gnu"
# )
#
# list(APPEND CMAKE_INCLUDE_PATH
# "/usr/local/openssl/include"
# "/usr/local/ssl/include"
# "/usr/local/include"
# "/usr/include/openssl"
# )
# endif()
#
# # On macOS
# if (APPLE)
# # Homebrew OpenSSL paths
# list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/openssl")
# list(APPEND CMAKE_LIBRARY_PATH "/usr/local/opt/openssl/lib")
# list(APPEND CMAKE_INCLUDE_PATH "/usr/local/opt/openssl/include")
# endif()
#
# # On Windows
# if (WIN32)
# # Potential OpenSSL installation paths
# list(APPEND CMAKE_PREFIX_PATH
# "C:/OpenSSL-Win64"
# "C:/Program Files/OpenSSL"
# "C:/Program Files/OpenSSL-Win64"
# )
# endif()
#
# add_compile_definitions(SR_COMMON_OPENSSL)
# find_package(OpenSSL REQUIRED)
#
# include_directories(${OPENSSL_INCLUDE_DIR})
#
# if (OpenSSL_FOUND)
# message(STATUS "OpenSSL version: ${OPENSSL_VERSION}")
# message(STATUS "OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
# message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
# else()
# message(FATAL_ERROR "System OpenSSL is not found.")
# endif()
#endif()

if (SR_COMMON_CURL)
set(BUILD_LIBCURL_DOCS OFF CACHE INTERNAL "" FORCE)
set(ENABLE_CURL_MANUAL OFF CACHE INTERNAL "" FORCE)
Expand Down Expand Up @@ -167,20 +242,6 @@ if (SR_TRACY_ENABLE)
endif()

add_subdirectory(libs/rapidyaml)

set(SR_COMMON_CPPCORO_ENABLED OFF)
if (NOT ANDROID_NDK)
set(SR_COMMON_CPPCORO_ENABLED ON)
add_compile_definitions(SR_USE_CPP_CORO)
add_subdirectory(libs/cppcoro)
endif()

set(SR_COMMON_CPPTRACE_ENABLED OFF)
if (NOT ANDROID_NDK AND UNIX)
set(SR_COMMON_CPPTRACE_ENABLED ON)
add_subdirectory(libs/cpptrace)
endif()

add_subdirectory(libs/entt)

list(APPEND SR_UTILS_LINK_LIBRARIES cxx/ICU.cxx)
Expand All @@ -206,7 +267,7 @@ if (SR_COMMON_ZLIB)
endif()

if (SR_COMMON_GIT_METADATA)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cmake-get-version-tracking)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cmake-git-version-tracking)
endif()

if (SR_COMMON_ASSIMP)
Expand All @@ -222,7 +283,7 @@ if (SR_COMMON_JSON)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/json/include)
endif()

if (SR_COMMON_CURL OR SR_COMMON_OPENSSL)
if (SR_COMMON_OPENSSL)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/openssl/include)
endif()

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

if (SR_COMMON_CPPCORO_ENABLED)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cppcoro/include)
endif()

if (SR_COMMON_CPPTRACE_ENABLED)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/cpptrace/include)
endif()
Expand All @@ -257,8 +314,8 @@ SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_BINARY_DIR}/libs/tree-sitter

add_library(asio INTERFACE)

target_include_directories(asio INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libs/asio/include)
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/libs/asio/include)
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libs/asio/asio/include)
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/libs/asio/asio/include)

if (SR_ICU)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_BINARY_DIR}/include/icu)
Expand Down Expand Up @@ -319,6 +376,8 @@ if (SR_COMMON_MYHTML)
set(MyHTML_BUILD_SHARED OFF CACHE INTERNAL "" FORCE)
set(PROJECT_OPTIMIZATION_LEVEL "" CACHE INTERNAL "" FORCE)

add_compile_definitions(SR_COMMON_MYHTML)

add_subdirectory(libs/myhtml)
SR_UTILS_INCLUDE_DIRECTORIES_APPEND(${CMAKE_CURRENT_SOURCE_DIR}/libs/myhtml/include)
target_link_libraries(Utils myhtml_static)
Expand Down Expand Up @@ -382,10 +441,6 @@ if (SR_COMMON_CPPTRACE_ENABLED)
target_link_libraries(Utils cpptrace::cpptrace)
endif()

if (SR_COMMON_CPPCORO_ENABLED)
target_link_libraries(Utils cppcoro)
endif()

get_property(SR_UTILS_INCLUDE_DIRECTORIES_CONTENT GLOBAL PROPERTY SR_UTILS_INCLUDE_DIRECTORIES)
message("SRCommon include directories: ${SR_UTILS_INCLUDE_DIRECTORIES_CONTENT}")
target_include_directories(Utils PUBLIC ${SR_UTILS_INCLUDE_DIRECTORIES_CONTENT})
Expand Down
10 changes: 10 additions & 0 deletions inc/Utils/Common/EnumReflector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <Utils/Common/HashManager.h>
#include <Utils/Types/Map.h>
#include <Utils/Types/StringAtom.h>
#include <Utils/Types/Function.h>

#include <Codegen/EnumsFwd.generated.hpp>

Expand Down Expand Up @@ -76,6 +77,8 @@ namespace SR_UTILS_NS {
~EnumReflector() override;

public:
template<typename EnumType> static void ForEach(SR_HTYPES_NS::Function<void(EnumType)> func);

template<typename EnumType> SR_NODISCARD static EnumReflector* GetReflector();
template<typename EnumType> SR_NODISCARD static uint64_t Count();
template<typename EnumType> SR_NODISCARD static SR_UTILS_NS::StringAtom ToStringAtom(EnumType value);
Expand Down Expand Up @@ -320,6 +323,13 @@ namespace SR_UTILS_NS {
return GetReflector<EnumType>()->GetEnumVariantInternal();
}

template <typename EnumType>
void EnumReflector::ForEach(Types::Function<void(EnumType)> func) {
for (auto&& item : GetReflector<EnumType>()->m_data->values) {
func(static_cast<EnumType>(item.value));
}
}

template<typename EnumType> EnumReflector* EnumReflector::GetReflector() {
if constexpr (std::is_class_v<EnumType>) {
if constexpr (std::is_enum_v<EnumType>) {
Expand Down
2 changes: 2 additions & 0 deletions inc/Utils/Common/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ namespace SR_UTILS_NS {
static std::string GetExtensionFromFilePath(std::string path);
static std::string Reverse(const std::string& str);

static std::string ToKebabCase(std::string_view str);

static glm::vec2 MakeVec2FromString(const char* source, char chr, unsigned short start);
static glm::vec3 MakeVec3FromString(const char* source, char chr, unsigned short start);

Expand Down
1 change: 1 addition & 0 deletions inc/Utils/Input/InputSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace SR_UTILS_NS {

void LockCursor();
void UnlockCursor();
void ForceUnlockCursor();

private:
void Reset();
Expand Down
1 change: 0 additions & 1 deletion inc/Utils/Network/Asio/AsioTCPAcceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <Utils/Network/Acceptor.h>

#include <asio/ip/tcp.hpp>
#include <asio/io_service.hpp>

namespace SR_NETWORK_NS {
class AsioContext;
Expand Down
83 changes: 83 additions & 0 deletions inc/Utils/Network/Message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Created by innerviewer on 2025-03-30.
//

#ifndef SR_COMMON_NETWORK_MESSAGE_H
#define SR_COMMON_NETWORK_MESSAGE_H

namespace SR_NETWORK_NS {
class IMessage {
public:
virtual ~IMessage() = default;

// For type-safe message identification
template<typename T>
SR_NODISCARD bool is() const {
static_assert(std::is_enum_v<T>, "Message ID must be an enum type");
return getTypeID() == typeid(T);
}

// For getting the actual message ID value
template<typename T>
T getID() const {
static_assert(std::is_enum_v<T>, "Message ID must be an enum type");
return static_cast<T>(getRawID());
}

protected:
SR_NODISCARD virtual std::size_t getTypeID() const = 0;
SR_NODISCARD virtual int64_t getRawID() const = 0;
};

// Message data interface
class IMessageData {
public:
virtual ~IMessageData() = default;
SR_NODISCARD virtual std::unique_ptr<IMessageData> clone() const = 0;
};

// Concrete message implementation
template<typename T, typename DataT = void>
class Message final : public IMessage {
static_assert(std::is_enum_v<T>, "Message ID must be an enum type");

public:
explicit Message(T id) : m_id(id) {}

Message(T id, DataT data) : m_id(id), m_data(std::move(data)) {}

// Type identification
SR_NODISCARD std::size_t getTypeID() const override {
return typeid(T).hash_code();
}

// Get the raw message ID
SR_NODISCARD int64_t getRawID() const override {
return static_cast<int64_t>(m_id);
}

// Check if message has data
SR_NODISCARD bool hasData() const {
return !std::is_same_v<DataT, void>;
}

// Get message data (only if DataT is not void)
template<typename U = DataT>
std::enable_if_t<!std::is_same_v<U, void>, const U&> getData() const {
return m_data;
}

private:
T m_id;
DataT m_data;
};

// Message handler interface
class IMessageHandler {
public:
virtual ~IMessageHandler() = default;
virtual void handleMessage(const IMessage& message) = 0;
};
}

#endif //SR_COMMON_NETWORK_MESSAGE_H
3 changes: 2 additions & 1 deletion inc/Utils/Platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ namespace SR_UTILS_NS::Platform {

SR_COMMON_DLL_API extern void SetMousePos(const SR_MATH_NS::IVector2& pos);
SR_COMMON_DLL_API extern void SetCursorVisible(bool isVisible);
SR_COMMON_DLL_API extern void ConfineCursor(); // TODO: add ability to confine cursor to a specific window
SR_COMMON_DLL_API extern void ReleaseCursorConfinement(); // TODO: add ability to confine cursor to a specific window
SR_COMMON_DLL_API extern void SetThreadPriority(void* nativeHandle, ThreadPriority priority);
SR_COMMON_DLL_API extern void CopyPermissions(const SR_UTILS_NS::Path& source, const SR_UTILS_NS::Path& destination);

}
#endif //SR_ENGINE_UTILS_PLATFORM_H
2 changes: 1 addition & 1 deletion inc/Utils/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
#define SR_FORCE_INLINE SR_INLINE
#elif defined(SR_GCC)
#define SR_FASTCALL
#define SR_FORCE_INLINE SR_INLINE
#define SR_FORCE_INLINE __attribute__((always_inline))
#else
#define SR_FASTCALL __fastcall
#define SR_FORCE_INLINE __forceinline
Expand Down
1 change: 1 addition & 0 deletions libs/asio
Submodule asio added at a892f7
4 changes: 0 additions & 4 deletions libs/asio/COPYING

This file was deleted.

5 changes: 0 additions & 5 deletions libs/asio/INSTALL

This file was deleted.

Loading
Loading