diff --git a/CMakeLists.txt b/CMakeLists.txt index 988a0e66..99a70261 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,21 +26,14 @@ include(Modules) include(Shaders) # Subdirectories for engine libs -add_subdirectory(engine/native) +add_subdirectory(engine) # Main Executable add_executable(draconic engine/native/main/main.cpp) target_link_libraries(draconic PRIVATE - core - math - io - memory - platform - input - rendering - scene + native bgfx bx bimg diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt new file mode 100644 index 00000000..b2417e14 --- /dev/null +++ b/engine/CMakeLists.txt @@ -0,0 +1,2 @@ +add_modules_library(native) +target_link_libraries(native PUBLIC platform core input scene rendering) \ No newline at end of file diff --git a/engine/native/CMakeLists.txt b/engine/native/CMakeLists.txt index f712b79d..a8974d19 100644 --- a/engine/native/CMakeLists.txt +++ b/engine/native/CMakeLists.txt @@ -1,12 +1,13 @@ +add_subdirectory(thirdparty SYSTEM) + +add_modules_library(platform) add_modules_library(core SHARED) add_modules_library(input) add_modules_library(rendering) add_modules_library(scene) -add_subdirectory(thirdparty SYSTEM) -add_subdirectory(platform) - +target_link_libraries(platform PUBLIC platform_impl) target_link_libraries(core PUBLIC definitions math io memory) -target_link_libraries(input PRIVATE SDL3::SDL3-static core) +target_link_libraries(input PRIVATE SDL3::SDL3-static platform core) target_link_libraries(rendering PUBLIC rhi rendergraph mesh material quad_renderer renderer) target_link_libraries(scene PUBLIC renderable transform_component camera) diff --git a/engine/native/draconic.cppm b/engine/native/draconic.cppm new file mode 100644 index 00000000..f7973318 --- /dev/null +++ b/engine/native/draconic.cppm @@ -0,0 +1,7 @@ +export module draconic; + +export import platform; +export import core; +export import input; +export import scene; +export import rendering; \ No newline at end of file diff --git a/engine/native/main/main.cpp b/engine/native/main/main.cpp index 85419af9..726ea8e1 100644 --- a/engine/native/main/main.cpp +++ b/engine/native/main/main.cpp @@ -6,11 +6,7 @@ #include #include -import core; -import input; -import platform; -import scene; -import rendering; +import draconic; int main(int argc, char* argv[]) { diff --git a/engine/native/platform/CMakeLists.txt b/engine/native/platform/CMakeLists.txt index 1088303f..b9da42ce 100644 --- a/engine/native/platform/CMakeLists.txt +++ b/engine/native/platform/CMakeLists.txt @@ -1,36 +1 @@ -# Platform-specific source selection -if(WIN32) - set(PLATFORM_SRC "win32/win32.cpp") - set(PLATFORM_DEPS "") -elseif(APPLE) - set(PLATFORM_SRC "mac/mac.mm") - set(PLATFORM_DEPS "-framework Cocoa -framework Metal -framework QuartzCore") -else() - set(PLATFORM_SRC "linux/linux.cpp") - find_package(PkgConfig REQUIRED) - pkg_check_modules(X11_LIBS REQUIRED IMPORTED_TARGET x11 xext xcursor xrandr xrender xi xfixes) - pkg_check_modules(WAYLAND_LIBS IMPORTED_TARGET wayland-client wayland-egl wayland-cursor egl) - set(PLATFORM_DEPS PkgConfig::X11_LIBS) - if(WAYLAND_LIBS_FOUND) - list(APPEND PLATFORM_DEPS PkgConfig::WAYLAND_LIBS) - endif() -endif() - -add_library(platform STATIC) - -target_sources(platform - PUBLIC FILE_SET CXX_MODULES - BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" - FILES platform.cppm - - PRIVATE - ${PLATFORM_SRC} -) - -target_include_directories(platform INTERFACE $) - -target_link_libraries(platform PRIVATE SDL3::SDL3-static ${PLATFORM_DEPS} core) - -if(DRACO_HAS_WAYLAND) - target_compile_definitions(platform PRIVATE DRACO_HAS_WAYLAND=1) -endif() \ No newline at end of file +add_subdirectory(impl) diff --git a/engine/native/platform/impl/CMakeLists.txt b/engine/native/platform/impl/CMakeLists.txt new file mode 100644 index 00000000..3a6608ad --- /dev/null +++ b/engine/native/platform/impl/CMakeLists.txt @@ -0,0 +1,29 @@ +# Platform-specific source selection +if(WIN32) + set(PLATFORM_SRC "win32/win32.cpp") + set(PLATFORM_DEPS "") +elseif(APPLE) + set(PLATFORM_SRC "mac/mac.mm") + set(PLATFORM_DEPS "-framework Cocoa -framework Metal -framework QuartzCore") +else() + set(PLATFORM_SRC "linux/linux.cpp") + find_package(PkgConfig REQUIRED) + pkg_check_modules(X11_LIBS REQUIRED IMPORTED_TARGET x11 xext xcursor xrandr xrender xi xfixes) + pkg_check_modules(WAYLAND_LIBS IMPORTED_TARGET wayland-client wayland-egl wayland-cursor egl) + set(PLATFORM_DEPS PkgConfig::X11_LIBS) + if(WAYLAND_LIBS_FOUND) + list(APPEND PLATFORM_DEPS PkgConfig::WAYLAND_LIBS) + endif() +endif() + +add_library(platform_impl STATIC + ${PLATFORM_SRC} +) +target_include_directories(platform_impl + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + INTERFACE $ +) +target_link_libraries(platform_impl PUBLIC SDL3::SDL3-static PRIVATE ${PLATFORM_DEPS}) +if(DRACO_HAS_WAYLAND) + target_compile_definitions(platform_impl PRIVATE DRACO_HAS_WAYLAND=1) +endif() \ No newline at end of file diff --git a/engine/native/platform/linux/linux.cpp b/engine/native/platform/impl/linux/linux.cpp similarity index 86% rename from engine/native/platform/linux/linux.cpp rename to engine/native/platform/impl/linux/linux.cpp index 3ca59d90..c917791a 100644 --- a/engine/native/platform/linux/linux.cpp +++ b/engine/native/platform/impl/linux/linux.cpp @@ -1,15 +1,13 @@ -module; +#include "platform_impl.h" #include #include #include -module platform; +#include -import core.stdtypes; - -namespace draco::platform { +namespace draco::platform::impl { NativeWindowFrame get_native_handles(void* sdl_window_ptr) { SDL_Window* window = static_cast(sdl_window_ptr); NativeWindowFrame frame; @@ -19,7 +17,7 @@ namespace draco::platform { if (std::string_view(driver) == "x11") { frame.ndt = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, nullptr); - frame.nwh = (void*)(uintptr)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); + frame.nwh = (void*)(std::uintptr_t)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); frame.type = NativeWindowType::X11; } else if (std::string_view(driver) == "wayland") { frame.ndt = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nullptr); diff --git a/engine/native/platform/mac/mac.mm b/engine/native/platform/impl/mac/mac.mm similarity index 88% rename from engine/native/platform/mac/mac.mm rename to engine/native/platform/impl/mac/mac.mm index 885b018f..31cbae88 100644 --- a/engine/native/platform/mac/mac.mm +++ b/engine/native/platform/impl/mac/mac.mm @@ -1,12 +1,8 @@ -module; - -#include +#include "platform_impl.h" #include -module platform; - -namespace draco::platform { +namespace draco::platform::impl { NativeWindowFrame get_native_handles(void* sdl_window_ptr) { SDL_Window* window = static_cast(sdl_window_ptr); NativeWindowFrame frame; diff --git a/engine/native/platform/impl/platform_impl.h b/engine/native/platform/impl/platform_impl.h new file mode 100644 index 00000000..58159ac8 --- /dev/null +++ b/engine/native/platform/impl/platform_impl.h @@ -0,0 +1,29 @@ +#pragma once + +namespace draco::platform::impl { + + enum class NativeWindowType + { + None, + Default, + Win32, + Wayland, + X11, + Cocoa + }; + + struct NativeWindowFrame + { + void* nwh = nullptr; // Native Window Handle + void* ndt = nullptr; // Native Display Type + + int width = 0; + int height = 0; + + bool valid = false; + + NativeWindowType type = NativeWindowType::None; // Track the type of the native window + }; + + NativeWindowFrame get_native_handles(void* sdl_window_ptr); +} \ No newline at end of file diff --git a/engine/native/platform/win32/win32.cpp b/engine/native/platform/impl/win32/win32.cpp similarity index 90% rename from engine/native/platform/win32/win32.cpp rename to engine/native/platform/impl/win32/win32.cpp index 1e34f9e1..fe89073d 100644 --- a/engine/native/platform/win32/win32.cpp +++ b/engine/native/platform/impl/win32/win32.cpp @@ -1,12 +1,8 @@ -module; - -#include +#include "platform_impl.h" #include -module platform; - -namespace draco::platform { +namespace draco::platform::impl { NativeWindowFrame get_native_handles(void* sdl_window_ptr) { SDL_Window* window = static_cast(sdl_window_ptr); NativeWindowFrame frame; diff --git a/engine/native/platform/platform.cppm b/engine/native/platform/platform.cppm index 88955014..6ee8a0ef 100644 --- a/engine/native/platform/platform.cppm +++ b/engine/native/platform/platform.cppm @@ -1,32 +1,15 @@ module; -#include +#include "impl/platform_impl.h" export module platform; export namespace draco::platform { - enum class NativeWindowType - { - None, - Default, - Win32, - Wayland, - X11, - Cocoa - }; - struct NativeWindowFrame - { - void* nwh = nullptr; // Native Window Handle - void* ndt = nullptr; // Native Display Type + using NativeWindowType = impl::NativeWindowType; + using NativeWindowFrame = impl::NativeWindowFrame; - int width = 0; - int height = 0; - - bool valid = false; - - NativeWindowType type = NativeWindowType::None; // Track the type of the native window - }; - - NativeWindowFrame get_native_handles(void* sdl_window_ptr); + NativeWindowFrame get_native_handles(void* sdl_window_ptr) { + return impl::get_native_handles(sdl_window_ptr); + } }