From 49ee950035cb73d4bfc59acb1a6dc2503d308286 Mon Sep 17 00:00:00 2001 From: Lamakaio Date: Mon, 24 Jun 2024 15:20:33 +0200 Subject: [PATCH] add gdextension mode for osp --- .gitmodules | 3 + 3rdparty/CMakeLists.txt | 62 ++++-- 3rdparty/RmlUi | 1 - 3rdparty/godot-cpp | 1 + CMakeLists.txt | 37 +++- src/CMakeLists.txt | 103 ++-------- src/adera/CMakeLists.txt | 57 ++++++ src/adera_drawing_gl/CMakeLists.txt | 59 ++++++ .../flat_shader.cpp | 0 .../flat_shader.h | 2 +- .../phong_shader.cpp | 0 .../phong_shader.h | 2 +- .../plume_shader.cpp | 0 .../plume_shader.h | 0 .../visualizer_shader.cpp | 0 .../visualizer_shader.h | 2 +- src/gdextension/CMakeLists.txt | 80 ++++++++ src/gdextension/flying_scene.cpp | 191 ++++++++++++++++++ src/gdextension/flying_scene.h | 44 ++++ src/gdextension/register_types.cpp | 36 ++++ src/gdextension/register_types.h | 10 + src/gdextension/templates/CMakeLists.txt | 25 +++ src/gdextension/templates/osp.gdextension | 11 + .../templates/template.debug.gdextension.in | 11 + .../templates/template.release.gdextension.in | 11 + src/osp/CMakeLists.txt | 67 ++++++ src/osp_drawing_gl/CMakeLists.txt | 90 +++++++++ .../FullscreenTriShader.cpp | 0 .../FullscreenTriShader.h | 0 .../rendergl.cpp | 6 +- .../drawing_gl => osp_drawing_gl}/rendergl.h | 2 +- src/ospjolt/CMakeLists.txt | 54 +++++ src/ospjolt/{activescene => }/forcefactors.h | 0 src/ospjolt/{activescene => }/joltinteg.h | 3 +- .../{activescene => }/joltinteg_fn.cpp | 0 src/ospjolt/{activescene => }/joltinteg_fn.h | 0 src/planet-a/CMakeLists.txt | 51 +++++ src/testapp/CMakeLists.txt | 59 ++++++ src/testapp/identifiers.h | 17 ++ src/testapp/scenarios.h | 17 +- src/testapp/sessions/common.cpp | 1 + src/testapp/sessions/common.h | 9 +- src/testapp/sessions/jolt.cpp | 3 +- src/testapp/sessions/jolt.h | 13 +- src/testapp/sessions/misc.cpp | 2 +- src/testapp/sessions/misc.h | 9 +- src/testapp/sessions/physics.cpp | 2 +- src/testapp/sessions/physics.h | 11 +- src/testapp/sessions/shapes.cpp | 1 + src/testapp/sessions/shapes.h | 9 +- src/testapp/sessions/terrain.cpp | 2 + src/testapp/sessions/terrain.h | 9 +- src/testapp/sessions/universe.cpp | 2 + src/testapp/sessions/universe.h | 9 +- src/testapp/sessions/vehicles.cpp | 2 + src/testapp/sessions/vehicles.h | 11 +- src/testapp/sessions/vehicles_machines.cpp | 37 ++-- src/testapp/sessions/vehicles_machines.h | 9 +- src/testapp/sessions/vehicles_prebuilt.cpp | 2 + src/testapp/sessions/vehicles_prebuilt.h | 10 +- src/testapp/testapp.cpp | 2 +- src/testapp_magnum/CMakeLists.txt | 109 ++++++++++ .../MagnumApplication.cpp | 0 .../MagnumApplication.h | 0 src/{testapp => testapp_magnum}/README.md | 0 .../enginetest.cpp | 4 +- src/{testapp => testapp_magnum}/enginetest.h | 2 +- src/{testapp => testapp_magnum}/main.cpp | 6 +- src/{testapp => testapp_magnum}/scenarios.cpp | 32 ++- src/testapp_magnum/scenarios.h | 51 +++++ .../sessions/magnum.cpp | 10 +- .../sessions/magnum.h | 0 test/CMakeLists.txt | 2 +- 73 files changed, 1285 insertions(+), 200 deletions(-) delete mode 160000 3rdparty/RmlUi create mode 160000 3rdparty/godot-cpp create mode 100644 src/adera/CMakeLists.txt create mode 100644 src/adera_drawing_gl/CMakeLists.txt rename src/{adera/drawing_gl => adera_drawing_gl}/flat_shader.cpp (100%) rename src/{adera/drawing_gl => adera_drawing_gl}/flat_shader.h (99%) rename src/{adera/drawing_gl => adera_drawing_gl}/phong_shader.cpp (100%) rename src/{adera/drawing_gl => adera_drawing_gl}/phong_shader.h (99%) rename src/{adera/drawing_gl => adera_drawing_gl}/plume_shader.cpp (100%) rename src/{adera/drawing_gl => adera_drawing_gl}/plume_shader.h (100%) rename src/{adera/drawing_gl => adera_drawing_gl}/visualizer_shader.cpp (100%) rename src/{adera/drawing_gl => adera_drawing_gl}/visualizer_shader.h (98%) create mode 100644 src/gdextension/CMakeLists.txt create mode 100644 src/gdextension/flying_scene.cpp create mode 100644 src/gdextension/flying_scene.h create mode 100644 src/gdextension/register_types.cpp create mode 100644 src/gdextension/register_types.h create mode 100644 src/gdextension/templates/CMakeLists.txt create mode 100644 src/gdextension/templates/osp.gdextension create mode 100644 src/gdextension/templates/template.debug.gdextension.in create mode 100644 src/gdextension/templates/template.release.gdextension.in create mode 100644 src/osp/CMakeLists.txt create mode 100644 src/osp_drawing_gl/CMakeLists.txt rename src/{osp/drawing_gl => osp_drawing_gl}/FullscreenTriShader.cpp (100%) rename src/{osp/drawing_gl => osp_drawing_gl}/FullscreenTriShader.h (100%) rename src/{osp/drawing_gl => osp_drawing_gl}/rendergl.cpp (99%) rename src/{osp/drawing_gl => osp_drawing_gl}/rendergl.h (99%) create mode 100644 src/ospjolt/CMakeLists.txt rename src/ospjolt/{activescene => }/forcefactors.h (100%) rename src/ospjolt/{activescene => }/joltinteg.h (99%) rename src/ospjolt/{activescene => }/joltinteg_fn.cpp (100%) rename src/ospjolt/{activescene => }/joltinteg_fn.h (100%) create mode 100644 src/planet-a/CMakeLists.txt create mode 100644 src/testapp/CMakeLists.txt create mode 100644 src/testapp_magnum/CMakeLists.txt rename src/{testapp => testapp_magnum}/MagnumApplication.cpp (100%) rename src/{testapp => testapp_magnum}/MagnumApplication.h (100%) rename src/{testapp => testapp_magnum}/README.md (100%) rename src/{testapp => testapp_magnum}/enginetest.cpp (99%) rename src/{testapp => testapp_magnum}/enginetest.h (98%) rename src/{testapp => testapp_magnum}/main.cpp (99%) rename src/{testapp => testapp_magnum}/scenarios.cpp (98%) create mode 100644 src/testapp_magnum/scenarios.h rename src/{testapp => testapp_magnum}/sessions/magnum.cpp (99%) rename src/{testapp => testapp_magnum}/sessions/magnum.h (100%) diff --git a/.gitmodules b/.gitmodules index 9cdb6964..0a3c79fe 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,3 +37,6 @@ [submodule "3rdparty/JoltPhysics"] path = 3rdparty/JoltPhysics url = https://github.com/jrouwe/JoltPhysics.git +[submodule "3rdparty/godot-cpp"] + path = 3rdparty/godot-cpp + url = https://github.com/godotengine/godot-cpp diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 830c2da3..4ea3ba10 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -122,16 +122,16 @@ if(NOT OSP_USE_SYSTEM_SDL) SET(SDL_VIRTUAL_JOYSTICK ON CACHE BOOL "" FORCE) SET(LIBSAMPLERATE ON CACHE BOOL "" FORCE) - SET(LIBSAMPLERATE_SHARED ON CACHE BOOL "" FORCE) + SET(LIBSAMPLERATE_SHARED OFF CACHE BOOL "" FORCE) SET(SDL_EVENTS ON CACHE BOOL "" FORCE) SET(SDL_THREADS ON CACHE BOOL "" FORCE) # This assumes you want to have SDL as a static library. If not, set SDL_STATIC # to OFF instead. - SET(SDL_DLOPEN ON CACHE BOOL "" FORCE) - SET(SDL_SHARED ON CACHE BOOL "" FORCE) - SET(SDL_STATIC OFF CACHE BOOL "" FORCE) + SET(SDL_DLOPEN OFF CACHE BOOL "" FORCE) + SET(SDL_SHARED OFF CACHE BOOL "" FORCE) + SET(SDL_STATIC ON CACHE BOOL "" FORCE) SET(SDL2_DISABLE_SDL2MAIN ON CACHE BOOL "" FORCE) SET(SDL2_DISABLE_INSTALL ON CACHE BOOL "" FORCE) @@ -191,6 +191,16 @@ SET(MAGNUM_WITH_SHADERS ON CACHE BOOL "" FORCE) SET(MAGNUM_WITH_SHADERTOOLS OFF CACHE BOOL "" FORCE) SET(MAGNUM_WITH_TESTSUITE OFF CACHE BOOL "" FORCE) SET(MAGNUM_WITH_TEXT OFF CACHE BOOL "" FORCE) +SET(MAGNUM_WITH_GL ON CACHE BOOL "" FORCE) +SET(MAGNUM_TARGET_GL ON CACHE BOOL "" FORCE) + +IF (OSP_BUILD_GDEXTENSION) +SET(MAGNUM_WITH_SDL2APPLICATION OFF CACHE BOOL "" FORCE) +SET(MAGNUM_WITH_SHADERS OFF CACHE BOOL "" FORCE) +SET(MAGNUM_WITH_GL OFF CACHE BOOL "" FORCE) +SET(MAGNUM_TARGET_GL OFF CACHE BOOL "" FORCE) +ENDIF() + ADD_SUBDIRECTORY(magnum EXCLUDE_FROM_ALL) SET(MAGNUM_WITH_TINYGLTFIMPORTER ON CACHE BOOL "" FORCE) @@ -208,6 +218,7 @@ ADD_SUBDIRECTORY(toml11 EXCLUDE_FROM_ALL) SET(SPDLOG_ENABLE_PCH ON CACHE BOOL "" FORCE) # Not yet supported by github runners # SET(SPDLOG_USE_STD_FORMAT ON CACHE BOOL "" FORCE) +SET(SPDLOG_BUILD_PIC ON CACHE BOOL "" FORCE) ADD_SUBDIRECTORY(spdlog EXCLUDE_FROM_ALL) ADD_SUBDIRECTORY(longeronpp EXCLUDE_FROM_ALL) @@ -215,25 +226,36 @@ ADD_SUBDIRECTORY(longeronpp EXCLUDE_FROM_ALL) SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE) ADD_SUBDIRECTORY(googletest EXCLUDE_FROM_ALL) -SET(FT_DISABLE_ZLIB ON CACHE BOOL "" FORCE) -SET(FT_DISABLE_BZIP2 ON CACHE BOOL "" FORCE) -SET(FT_DISABLE_PNG ON CACHE BOOL "" FORCE) -SET(FT_DISABLE_HARFBUZZ ON CACHE BOOL "" FORCE) -SET(FT_DISABLE_BROTLI ON CACHE BOOL "" FORCE) -SET(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE) -SET(SKIP_INSTALL_LIBRARIES ON CACHE BOOL "" FORCE) -SET(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) -ADD_SUBDIRECTORY(freetype EXCLUDE_FROM_ALL) - -INSTALL(TARGETS freetype - EXPORT RmlUiTargets - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ) +# SET(FT_DISABLE_ZLIB ON CACHE BOOL "" FORCE) +# SET(FT_DISABLE_BZIP2 ON CACHE BOOL "" FORCE) +# SET(FT_DISABLE_PNG ON CACHE BOOL "" FORCE) +# SET(FT_DISABLE_HARFBUZZ ON CACHE BOOL "" FORCE) +# SET(FT_DISABLE_BROTLI ON CACHE BOOL "" FORCE) +# SET(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE) +# SET(SKIP_INSTALL_LIBRARIES ON CACHE BOOL "" FORCE) +# SET(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) +# ADD_SUBDIRECTORY(freetype EXCLUDE_FROM_ALL) + +# INSTALL(TARGETS freetype +# EXPORT RmlUiTargets +# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +# ) SET(RML_SKIP_INSTALL ON CACHE BOOL "" FORCE) SET(CUSTOM_CONFIGURATION ON CACHE BOOL "" FORCE) #ADD_SUBDIRECTORY(RmlUi EXCLUDE_FROM_ALL) SET(ENABLE_ALL_WARNINGS OFF CACHE BOOL "" FORCE) +SET(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) ADD_SUBDIRECTORY(JoltPhysics/Build EXCLUDE_FROM_ALL) +target_compile_options(Jolt PRIVATE "-fPIC") + +SET( GODOT_CPP_SYSTEM_HEADERS ON CACHE BOOL "" FORCE ) + +ADD_SUBDIRECTORY( godot-cpp EXCLUDE_FROM_ALL) + +SET_TARGET_PROPERTIES( godot-cpp + PROPERTIES + CXX_VISIBILITY_PRESET hidden # visibility needs to be the same as the main library +) diff --git a/3rdparty/RmlUi b/3rdparty/RmlUi deleted file mode 160000 index 40edf1ac..00000000 --- a/3rdparty/RmlUi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 40edf1acfa7f13f0c9b2af91d6f09ed47aa2c2c9 diff --git a/3rdparty/godot-cpp b/3rdparty/godot-cpp new file mode 160000 index 00000000..98c143a4 --- /dev/null +++ b/3rdparty/godot-cpp @@ -0,0 +1 @@ +Subproject commit 98c143a48365f3f3bf5f99d6289a2cb25e6472d1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 06f4dc94..28a16df9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,35 @@ IF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND NOT CMAKE_SYSTEM_VERSION) SET(CMAKE_SYSTEM_VERSION "10.0.18362.0" CACHE INTERNAL "" FORCE) ENDIF() +#build universally on macOS +if ( APPLE ) + set( CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" ) +endif() + # Set project name PROJECT(OSP-MAGNUM CXX) +# From: https://crascit.com/2016/04/09/using-ccache-with-cmake/ +find_program( CCACHE_PROGRAM ccache ) + +if ( CCACHE_PROGRAM ) + # get version information + execute_process( + COMMAND "${CCACHE_PROGRAM}" --version + OUTPUT_VARIABLE CCACHE_VERSION + ) + + string( REGEX MATCH "[^\r\n]*" CCACHE_VERSION ${CCACHE_VERSION} ) + + message( STATUS "Using ccache: ${CCACHE_PROGRAM} (${CCACHE_VERSION})" ) + + # Turn on ccache for all targets + set( CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" ) + set( CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" ) + + unset( CCACHE_VERSION ) +endif() + # Setup things for the test subdir below # Has to be in toplevel CMakeLists.txt or ctest gets mad. enable_testing() @@ -56,7 +82,7 @@ OPTION(OSP_ENABLE_COMPILER_WARNINGS "Build with the majority of compiler warning OPTION(OSP_ENABLE_IWYU "Build with warnings from IWYU turned on" OFF) OPTION(OSP_ENABLE_CLANG_TIDY "Build with warnings from clang-tidy turned on" OFF) OPTION(OSP_USE_SYSTEM_SDL "Build with SDL that you provide if turned on, compiles SDL if turned off. Off by default" OFF) - +OPTION(OSP_BUILD_GDEXTENSION "Build the GDExtension for osp instead of the standalone binary" OFF) # If the environment has these set, pull them into proper variables. SET(CLANG_COMPILE_FLAGS ${CLANG_COMPILE_FLAGS}) SET(GCC_COMPILE_FLAGS ${GCC_COMPILE_FLAGS}) @@ -158,9 +184,12 @@ ADD_SUBDIRECTORY(3rdparty) ADD_SUBDIRECTORY(src) # Unit Tests -ADD_SUBDIRECTORY(test) - +IF (NOT OSP_BUILD_GDEXTENSION) + ADD_SUBDIRECTORY(test) +ENDIF() # Set OSP as default startup project in Visual Studio set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT osp-magnum) # Set execution directory of osp-magnum so that we don't have to copy the files -set_property(TARGET osp-magnum PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin") +if (NOT OSP_BUILD_GDEXTENSION) + set_property(TARGET osp-magnum PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin") +endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82613809..1526fbc3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ ## # Open Space Program -# Copyright © 2019-2020 Open Space Program Project +# Copyright © 2019-2024 Open Space Program Project # # MIT License # @@ -23,20 +23,7 @@ # SOFTWARE. ## -find_package(Magnum REQUIRED - GL - Shaders - MeshTools - Primitives - #SceneGraph - Trade - Sdl2Application - AnyImageImporter - ) - -find_package(MagnumPlugins REQUIRED - TinyGltfImporter - StbImageImporter) +# TODO put that in the right place. set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) @@ -44,82 +31,24 @@ if(NOT Threads_FOUND) message(FATAL_ERROR "Can't find a thread library to use!") endif() -add_library(osp-magnum-deps INTERFACE) -add_custom_target(compile-osp-magnum-deps) - -# TODO: This list shouldn't be required, but there appears to be a bug in cmake where -# the add_custom_target() command, pointing to an INTERFACE dependency, doesn't -# result in the dependencies of the interface building. -# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23569 -SET(OSP_MAGNUM_DEPS_LIBS - Threads::Threads - EnTT::EnTT - Corrade::Main - Magnum::Application - Magnum::GL - Magnum::Magnum - Magnum::MeshTools - Magnum::Primitives - #Magnum::SceneGraph - Magnum::Shaders - Magnum::Trade - Magnum::AnyImageImporter - MagnumPlugins::TinyGltfImporter - MagnumPlugins::StbImageImporter - toml11 - spdlog - longeron - Jolt) -target_link_libraries(osp-magnum-deps INTERFACE ${OSP_MAGNUM_DEPS_LIBS}) -add_dependencies(compile-osp-magnum-deps ${OSP_MAGNUM_DEPS_LIBS}) - -add_executable(osp-magnum) - -target_compile_features(osp-magnum PUBLIC cxx_std_20) +#compile as position-independant to avoid link errors on static link +add_compile_options("-fPIC") -target_include_directories(osp-magnum PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +add_subdirectory(adera) +add_subdirectory(osp) +add_subdirectory(planet-a) +add_subdirectory(ospjolt) +add_subdirectory(testapp) -# Link it to the interface library that describes the dependencies -target_link_libraries(osp-magnum PRIVATE osp-magnum-deps) +if(OSP_BUILD_GDEXTENSION) -# Gather paths to OSP headers and sources -file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) -file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) -target_sources(osp-magnum PRIVATE "${CPP_FILES}" "${H_FILES}") +add_subdirectory(gdextension) -# Add shaders to IDE project -set(SHADERS_DIR "../bin/OSPData/adera/Shaders") -file (GLOB_RECURSE SHADER_FILES CONFIGURE_DEPENDS - "${SHADERS_DIR}/*.vert" - "${SHADERS_DIR}/*.frag" - "${SHADERS_DIR}/*.comp" -) -# For some reason, source_group() requires all files to be added to the executable -target_sources(osp-magnum PRIVATE "${SHADER_FILES}") +else() -# Segregate headers, shaders into filters -source_group("Shader Files" FILES ${SHADER_FILES}) -source_group("Header Files" FILES ${H_FILES}) +add_subdirectory(testapp_magnum) +add_subdirectory(osp_drawing_gl) +add_subdirectory(adera_drawing_gl) -# Enforce conformance mode for osp-magnum -target_compile_options(osp-magnum PRIVATE $<$:/permissive->) - -set_target_properties(osp-magnum PROPERTIES - EXPORT_COMPILE_COMMANDS TRUE - INSTALL_RPATH "$ORIGIN/lib" - C_EXTENSIONS OFF - C_STANDARD_REQUIRED ON - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) - -# Copy root/bin to build/bin after building -add_custom_command(TARGET osp-magnum - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/../bin" "${CMAKE_BINARY_DIR}/$" - VERBATIM -) +endif() -add_custom_target(run-osp-magnum - COMMAND $ - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/$) diff --git a/src/adera/CMakeLists.txt b/src/adera/CMakeLists.txt new file mode 100644 index 00000000..95f1e693 --- /dev/null +++ b/src/adera/CMakeLists.txt @@ -0,0 +1,57 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + Trade + AnyImageImporter + ) + +find_package(MagnumPlugins REQUIRED + TinyGltfImporter + StbImageImporter) + +SET(DEPS_LIBS + EnTT::EnTT + Corrade::Main + Magnum::Magnum + Magnum::Trade + longeron + spdlog + OpenSpaceProgram) + +add_library(Adera STATIC) + +target_compile_features(Adera PUBLIC cxx_std_20) + +# Link it to the interface library that describes the dependencies +target_link_libraries(Adera PRIVATE ${DEPS_LIBS}) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(Adera PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for adera +target_compile_options(Adera PRIVATE $<$:/permissive->) \ No newline at end of file diff --git a/src/adera_drawing_gl/CMakeLists.txt b/src/adera_drawing_gl/CMakeLists.txt new file mode 100644 index 00000000..31a6da07 --- /dev/null +++ b/src/adera_drawing_gl/CMakeLists.txt @@ -0,0 +1,59 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + GL + Shaders + MeshTools + Primitives + Trade + ) + +SET(DEPS_LIBS + Corrade::Main + Magnum::GL + Magnum::Magnum + Magnum::MeshTools + Magnum::Primitives + Magnum::Shaders + Magnum::Trade + OpenSpaceProgram + longeron + OspGL) + +add_library(AderaGL STATIC) + +target_compile_features(AderaGL PUBLIC cxx_std_20) + +# Link it to the interface library that describes the dependencies +target_link_libraries(AderaGL PRIVATE ${DEPS_LIBS}) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(AderaGL PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for adera +target_compile_options(AderaGL PRIVATE $<$:/permissive->) \ No newline at end of file diff --git a/src/adera/drawing_gl/flat_shader.cpp b/src/adera_drawing_gl/flat_shader.cpp similarity index 100% rename from src/adera/drawing_gl/flat_shader.cpp rename to src/adera_drawing_gl/flat_shader.cpp diff --git a/src/adera/drawing_gl/flat_shader.h b/src/adera_drawing_gl/flat_shader.h similarity index 99% rename from src/adera/drawing_gl/flat_shader.h rename to src/adera_drawing_gl/flat_shader.h index 78dcd4a0..96827379 100644 --- a/src/adera/drawing_gl/flat_shader.h +++ b/src/adera_drawing_gl/flat_shader.h @@ -24,7 +24,7 @@ */ #pragma once -#include +#include #include diff --git a/src/adera/drawing_gl/phong_shader.cpp b/src/adera_drawing_gl/phong_shader.cpp similarity index 100% rename from src/adera/drawing_gl/phong_shader.cpp rename to src/adera_drawing_gl/phong_shader.cpp diff --git a/src/adera/drawing_gl/phong_shader.h b/src/adera_drawing_gl/phong_shader.h similarity index 99% rename from src/adera/drawing_gl/phong_shader.h rename to src/adera_drawing_gl/phong_shader.h index ef09161c..e849e7ba 100644 --- a/src/adera/drawing_gl/phong_shader.h +++ b/src/adera_drawing_gl/phong_shader.h @@ -24,7 +24,7 @@ */ #pragma once -#include +#include #include diff --git a/src/adera/drawing_gl/plume_shader.cpp b/src/adera_drawing_gl/plume_shader.cpp similarity index 100% rename from src/adera/drawing_gl/plume_shader.cpp rename to src/adera_drawing_gl/plume_shader.cpp diff --git a/src/adera/drawing_gl/plume_shader.h b/src/adera_drawing_gl/plume_shader.h similarity index 100% rename from src/adera/drawing_gl/plume_shader.h rename to src/adera_drawing_gl/plume_shader.h diff --git a/src/adera/drawing_gl/visualizer_shader.cpp b/src/adera_drawing_gl/visualizer_shader.cpp similarity index 100% rename from src/adera/drawing_gl/visualizer_shader.cpp rename to src/adera_drawing_gl/visualizer_shader.cpp diff --git a/src/adera/drawing_gl/visualizer_shader.h b/src/adera_drawing_gl/visualizer_shader.h similarity index 98% rename from src/adera/drawing_gl/visualizer_shader.h rename to src/adera_drawing_gl/visualizer_shader.h index c134d234..8eaa3c8f 100644 --- a/src/adera/drawing_gl/visualizer_shader.h +++ b/src/adera_drawing_gl/visualizer_shader.h @@ -24,7 +24,7 @@ */ #pragma once -#include +#include #include diff --git a/src/gdextension/CMakeLists.txt b/src/gdextension/CMakeLists.txt new file mode 100644 index 00000000..d3475b64 --- /dev/null +++ b/src/gdextension/CMakeLists.txt @@ -0,0 +1,80 @@ +## +# Open Space Program +# Copyright © 2024-2025 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +ADD_LIBRARY( osp-gdextension SHARED) + +set( LIB_ARCH ${CMAKE_SYSTEM_PROCESSOR} ) +if ( APPLE ) + set( LIB_ARCH "universal" ) +endif() + +set( LIB_DIR "lib/${CMAKE_SYSTEM_NAME}-${LIB_ARCH}" ) +set( BUILD_OUTPUT_DIR "${CMAKE_BINARY_DIR}/$/" ) + +set_target_properties( osp-gdextension + PROPERTIES + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN true + RUNTIME_OUTPUT_DIRECTORY "${BUILD_OUTPUT_DIR}/${LIB_DIR}" + LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_DIR}/${LIB_DIR}" +) + + +# Copy over additional files from the support_files directory +add_custom_command( + TARGET osp-gdextension POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/support_files" + ${BUILD_OUTPUT_DIR} +) + +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(osp-gdextension PRIVATE "${CPP_FILES}" "${H_FILES}") + +target_include_directories(osp-gdextension PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + +target_link_libraries(osp-gdextension PRIVATE godot-cpp OpenSpaceProgram Adera PlanetA OspJolt) + +target_compile_options(osp-gdextension PRIVATE "-static") + + +# Install library, extension file, and support files in ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME} +set( INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/osp-gdextension/" ) + +add_subdirectory( templates ) + +install( TARGETS osp-gdextension +LIBRARY +DESTINATION ${INSTALL_DIR}/${LIB_DIR} +RUNTIME +DESTINATION ${INSTALL_DIR}/${LIB_DIR} +) + +# Copy over support files +install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/support_files/" +DESTINATION ${INSTALL_DIR} +PATTERN ".*" EXCLUDE +) \ No newline at end of file diff --git a/src/gdextension/flying_scene.cpp b/src/gdextension/flying_scene.cpp new file mode 100644 index 00000000..dd9324a6 --- /dev/null +++ b/src/gdextension/flying_scene.cpp @@ -0,0 +1,191 @@ +#include "flying_scene.h" +#include "ospjolt/joltinteg.h" +#include "ospjolt/joltinteg_fn.h" +#include "testapp/testapp.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace godot; + +void FlyingScene::_bind_methods() +{ +} + +FlyingScene::FlyingScene() +{ + // Initialize any variables here. + //m_testApp.m_pExecutor = new ExecutorType(); + //m_testApp.m_topData.resize(64); + //load_a_bunch_of_stuff(); +} + +FlyingScene::~FlyingScene() +{ + //delete m_joltWorld; + //delete (ExecutorType*) m_testApp.m_pExecutor; +} + +void FlyingScene::_enter_tree() +{ + RenderingServer* renderingServer = RenderingServer::get_singleton(); + m_scenario = get_world_3d()->get_scenario(); + m_viewport = get_viewport()->get_viewport_rid(); + m_mainCamera = renderingServer->camera_create(); + renderingServer->viewport_attach_camera(m_viewport, m_mainCamera); + + Transform3D cform = Transform3D(Basis(), Vector3(0, 0, 4)); + renderingServer->camera_set_transform(m_mainCamera, cform); + renderingServer->viewport_set_scenario(m_viewport, m_scenario); + + m_lightInstance = renderingServer->instance_create(); + renderingServer->instance_set_scenario(m_lightInstance, m_scenario); + + RID light = renderingServer->directional_light_create(); + renderingServer->instance_set_base(m_lightInstance, light); + + Transform3D lform = Transform3D(Basis().rotated(Vector3(1, 1, 0), -1.3), Vector3(0., 0., 0.)); + renderingServer->instance_set_transform(m_lightInstance, lform); + + godot::UtilityFunctions::print("Created viewport, camera, scenario, and light"); + + //init physics + ospjolt::ACtxJoltWorld::initJoltGlobal(); + m_joltWorld = new ospjolt::ACtxJoltWorld(); + + godot::UtilityFunctions::print("Init physics"); + +} + +void FlyingScene::_ready() +{ + RenderingServer* renderingServer = RenderingServer::get_singleton(); + RID instance = renderingServer->instance_create(); + renderingServer->instance_set_scenario(instance, m_scenario); + + RID mesh = renderingServer->make_sphere_mesh(10, 10, 1); + renderingServer->instance_set_base(instance, mesh); + + Transform3D xform = Transform3D(Basis(), Vector3(0.5, 0, 0)); + renderingServer->instance_set_transform(instance, xform); + +} + +void FlyingScene::_physics_process(double delta) +{ + // ospjolt::SysJolt::update_world() update the world +} + +// void FlyingScene::load_a_bunch_of_stuff() +// { +// using namespace osp::restypes; +// using namespace Magnum; +// using Primitives::ConeFlag; +// using Primitives::CylinderFlag; + +// osp::TopTaskBuilder builder{m_testApp.m_tasks, m_testApp.m_applicationGroup.m_edges, m_testApp.m_taskData}; +// auto const plApp = m_testApp.m_application.create_pipelines(builder); + +// builder.pipeline(plApp.mainLoop).loops(true).wait_for_signal(EStgOptn::ModifyOrSignal); + +// // declares idResources and idMainLoopCtrl +// OSP_DECLARE_CREATE_DATA_IDS(m_testApp.m_application, m_testApp.m_topData, TESTAPP_DATA_APPLICATION); + +// auto &rResources = osp::top_emplace (m_testApp.m_topData, idResources); +// /* unused */ osp::top_emplace(m_testApp.m_topData, idMainLoopCtrl); + +// builder.task() +// .name ("Schedule Main Loop") +// .schedules ({plApp.mainLoop(EStgOptn::Schedule)}) +// .push_to (m_testApp.m_application.m_tasks) +// .args ({ idMainLoopCtrl}) +// .func([] (MainLoopControl const& rMainLoopCtrl) noexcept -> osp::TaskActions +// { +// if ( ! rMainLoopCtrl.doUpdate +// && ! rMainLoopCtrl.doSync +// && ! rMainLoopCtrl.doResync +// && ! rMainLoopCtrl.doRender) +// { +// return osp::TaskAction::Cancel; +// } +// else +// { +// return { }; +// } +// }); + +// rResources.resize_types(osp::ResTypeIdReg_t::size()); + +// rResources.data_register(gc_image); +// rResources.data_register(gc_texture); +// rResources.data_register(gc_texture); +// rResources.data_register(gc_mesh); +// rResources.data_register(gc_importer); +// rResources.data_register(gc_importer); +// osp::register_tinygltf_resources(rResources); +// m_testApp.m_defaultPkg = rResources.pkg_create(); + +// // Load sturdy glTF files +// const std::string_view datapath = { "OSPData/adera/" }; +// const std::vector meshes = +// { +// "spamcan.sturdy.gltf", +// "stomper.sturdy.gltf", +// "ph_capsule.sturdy.gltf", +// "ph_fuselage.sturdy.gltf", +// "ph_engine.sturdy.gltf", +// //"ph_plume.sturdy.gltf", +// "ph_rcs.sturdy.gltf" +// //"ph_rcs_plume.sturdy.gltf" +// }; + +// // TODO: Make new gltf loader. This will read gltf files and dump meshes, +// // images, textures, and other relevant data into osp::Resources +// for (auto const& meshName : meshes) +// { +// osp::ResId res = osp::load_tinygltf_file(osp::string_concat(datapath, meshName), rResources, g_testApp.m_defaultPkg); +// osp::assigns_prefabs_tinygltf(rResources, res); +// } + +// // Add a default primitives +// auto const add_mesh_quick = [&rResources = rResources, &m_testApp = m_testApp] (std::string_view const name, Trade::MeshData&& data) +// { +// osp::ResId const meshId = rResources.create(gc_mesh, m_testApp.m_defaultPkg, osp::SharedString::create(name)); +// rResources.data_add(gc_mesh, meshId, std::move(data)); +// }; + + +// Trade::MeshData &&cylinder = Magnum::MeshTools::transform3D( Primitives::cylinderSolid(3, 16, 1.0f, CylinderFlag::CapEnds), Matrix4::rotationX(Deg(90)), 0); +// Trade::MeshData &&cone = Magnum::MeshTools::transform3D( Primitives::coneSolid(3, 16, 1.0f, ConeFlag::CapEnd), Matrix4::rotationX(Deg(90)), 0); + +// add_mesh_quick("cube", Primitives::cubeSolid()); +// add_mesh_quick("cubewire", Primitives::cubeWireframe()); +// add_mesh_quick("sphere", Primitives::icosphereSolid(2)); +// add_mesh_quick("cylinder", std::move(cylinder)); +// add_mesh_quick("cone", std::move(cone)); +// add_mesh_quick("grid64solid", Primitives::grid3DSolid({63, 63})); + +// OSP_LOG_INFO("Resource loading complete"); +// } diff --git a/src/gdextension/flying_scene.h b/src/gdextension/flying_scene.h new file mode 100644 index 00000000..491f5924 --- /dev/null +++ b/src/gdextension/flying_scene.h @@ -0,0 +1,44 @@ +#pragma once + +#include "ospjolt/joltinteg.h" +#include +#include +#include +#include + +namespace godot { + using namespace testapp; + +class FlyingScene : public Node3D { + GDCLASS(FlyingScene, Node3D) + +private: + //using ExecutorType = SingleThreadedExecutor; + + RID m_scenario; + RID m_viewport; + RID m_mainCamera; + RID m_lightInstance; + ospjolt::ACtxJoltWorld* m_joltWorld; + + //TestApp m_testApp; + //MainLoopControl m_MainLoopCtrl; + + //MainLoopSignals m_signals; + + //void load_a_bunch_of_stuff(); + +protected: + static void _bind_methods(); + +public: + FlyingScene(); + ~FlyingScene(); + + //void _process(double delta) override; + void _enter_tree() override; + void _ready() override; + void _physics_process(double delta) override; +}; + +} \ No newline at end of file diff --git a/src/gdextension/register_types.cpp b/src/gdextension/register_types.cpp new file mode 100644 index 00000000..d661b033 --- /dev/null +++ b/src/gdextension/register_types.cpp @@ -0,0 +1,36 @@ +#include "register_types.h" + +#include "flying_scene.h" + +#include +#include +#include + +using namespace godot; + +void godot::initialize_example_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } + + ClassDB::register_class(); +} + +void godot::uninitialize_example_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } +} + +extern "C" { +// Initialization. +GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) { + godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization); + + init_obj.register_initializer(initialize_example_module); + init_obj.register_terminator(uninitialize_example_module); + init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE); + + return init_obj.init(); +} +} \ No newline at end of file diff --git a/src/gdextension/register_types.h b/src/gdextension/register_types.h new file mode 100644 index 00000000..a3bc5591 --- /dev/null +++ b/src/gdextension/register_types.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace godot { + +void initialize_example_module(ModuleInitializationLevel p_level); +void uninitialize_example_module(ModuleInitializationLevel p_level); + +} \ No newline at end of file diff --git a/src/gdextension/templates/CMakeLists.txt b/src/gdextension/templates/CMakeLists.txt new file mode 100644 index 00000000..da0190cd --- /dev/null +++ b/src/gdextension/templates/CMakeLists.txt @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: Unlicense + +add_custom_target( templates + SOURCES + template.debug.gdextension.in + template.release.gdextension.in +) + +add_dependencies( osp-gdextension templates ) + +# TODO make this a bit generic with some kind of template. Currently hardcoded. + +set( GD_EXTENSION_FILE_INPUT osp.gdextension ) + +# Install the gdextension file +install( + FILES ${GD_EXTENSION_FILE_INPUT} + DESTINATION ${INSTALL_DIR} +) + +unset( ALLOWED_BUILDS ) +unset( BUILD_TYPE ) +unset( GD_EXTENSION_FILE ) +unset( GD_EXTENSION_FILE_INPUT ) +unset( LIB_PREFIX ) diff --git a/src/gdextension/templates/osp.gdextension b/src/gdextension/templates/osp.gdextension new file mode 100644 index 00000000..876303c6 --- /dev/null +++ b/src/gdextension/templates/osp.gdextension @@ -0,0 +1,11 @@ +[configuration] +entry_symbol = "example_library_init" +compatibility_minimum = 4.1 + +[icons] +Example = "icons/Example.svg" + +[libraries] +linux.debug.x86_64 = "lib/Linux-x86_64/libosp-gdextension.so" +macos.debug = "lib/Darwin-Universal/libosp-gdextension.dylib" +windows.debug.x86_64 = "lib/Windows-AMD64/osp-gdextension.dll" diff --git a/src/gdextension/templates/template.debug.gdextension.in b/src/gdextension/templates/template.debug.gdextension.in new file mode 100644 index 00000000..42c08114 --- /dev/null +++ b/src/gdextension/templates/template.debug.gdextension.in @@ -0,0 +1,11 @@ +[configuration] +entry_symbol = "GDExtensionInit" +compatibility_minimum = 4.1 + +[icons] +Example = "icons/Example.svg" + +[libraries] +linux.debug.x86_64 = "lib/Linux-x86_64/lib${PROJECT_NAME}-d.so" +macos.debug = "lib/Darwin-Universal/lib${PROJECT_NAME}-d.dylib" +windows.debug.x86_64 = "lib/Windows-AMD64/${LIB_PREFIX}${PROJECT_NAME}-d.dll" diff --git a/src/gdextension/templates/template.release.gdextension.in b/src/gdextension/templates/template.release.gdextension.in new file mode 100644 index 00000000..4d5ba9bd --- /dev/null +++ b/src/gdextension/templates/template.release.gdextension.in @@ -0,0 +1,11 @@ +[configuration] +entry_symbol = "GDExtensionInit" +compatibility_minimum = 4.1 + +[icons] +Example = "icons/Example.svg" + +[libraries] +linux.release.x86_64 = "lib/Linux-x86_64/lib${PROJECT_NAME}.so" +macos.release = "lib/Darwin-universal/lib${PROJECT_NAME}.dylib" +windows.release.x86_64 = "lib/Windows-AMD64/${LIB_PREFIX}${PROJECT_NAME}.dll" diff --git a/src/osp/CMakeLists.txt b/src/osp/CMakeLists.txt new file mode 100644 index 00000000..3cc1400a --- /dev/null +++ b/src/osp/CMakeLists.txt @@ -0,0 +1,67 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + Trade + Primitives + MeshTools + AnyImageImporter + ) + +find_package(MagnumPlugins REQUIRED + TinyGltfImporter + StbImageImporter) + +SET(OSP_DEPS_LIBS + Threads::Threads + EnTT::EnTT + Corrade::Main + Magnum::Magnum + Magnum::Trade + Magnum::Primitives + Magnum::MeshTools + Magnum::AnyImageImporter + MagnumPlugins::TinyGltfImporter + MagnumPlugins::StbImageImporter + toml11 + spdlog + longeron) + +add_library(OpenSpaceProgram STATIC) + +target_compile_features(OpenSpaceProgram PUBLIC cxx_std_20) + +target_include_directories(OpenSpaceProgram PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") + +# Link it to the interface library that describes the dependencies +target_link_libraries(OpenSpaceProgram PUBLIC ${OSP_DEPS_LIBS}) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(OpenSpaceProgram PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for osp-magnum +target_compile_options(OpenSpaceProgram PRIVATE $<$:/permissive->) \ No newline at end of file diff --git a/src/osp_drawing_gl/CMakeLists.txt b/src/osp_drawing_gl/CMakeLists.txt new file mode 100644 index 00000000..3e3c2698 --- /dev/null +++ b/src/osp_drawing_gl/CMakeLists.txt @@ -0,0 +1,90 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + GL + Shaders + MeshTools + Primitives + Trade + AnyImageImporter + ) + +find_package(MagnumPlugins REQUIRED + TinyGltfImporter + StbImageImporter) + +SET(DEPS_LIBS + Threads::Threads + EnTT::EnTT + Corrade::Main + Magnum::GL + Magnum::Magnum + Magnum::MeshTools + Magnum::Primitives + Magnum::Shaders + Magnum::Trade + Magnum::AnyImageImporter + MagnumPlugins::TinyGltfImporter + MagnumPlugins::StbImageImporter + longeron + OpenSpaceProgram) + +add_library(OspGL STATIC) + +target_compile_features(OspGL PUBLIC cxx_std_20) + +# Link it to the interface library that describes the dependencies +target_link_libraries(OspGL PRIVATE ${DEPS_LIBS}) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(OspGL PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Add shaders to IDE project +set(SHADERS_DIR "../../bin/OSPData/adera/Shaders") +file (GLOB_RECURSE SHADER_FILES CONFIGURE_DEPENDS + "${SHADERS_DIR}/*.vert" + "${SHADERS_DIR}/*.frag" + "${SHADERS_DIR}/*.comp" +) +# For some reason, source_group() requires all files to be added to the executable +target_sources(OspGL PRIVATE "${SHADER_FILES}") + +# Segregate headers, shaders into filters +source_group("Shader Files" FILES ${SHADER_FILES}) +source_group("Header Files" FILES ${H_FILES}) + +# Enforce conformance mode for OspGL +target_compile_options(OspGL PRIVATE $<$:/permissive->) + + +# Copy root/bin to build/bin after building +add_custom_command(TARGET OspGL + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/../../bin" "${CMAKE_BINARY_DIR}/$" + VERBATIM +) \ No newline at end of file diff --git a/src/osp/drawing_gl/FullscreenTriShader.cpp b/src/osp_drawing_gl/FullscreenTriShader.cpp similarity index 100% rename from src/osp/drawing_gl/FullscreenTriShader.cpp rename to src/osp_drawing_gl/FullscreenTriShader.cpp diff --git a/src/osp/drawing_gl/FullscreenTriShader.h b/src/osp_drawing_gl/FullscreenTriShader.h similarity index 100% rename from src/osp/drawing_gl/FullscreenTriShader.h rename to src/osp_drawing_gl/FullscreenTriShader.h diff --git a/src/osp/drawing_gl/rendergl.cpp b/src/osp_drawing_gl/rendergl.cpp similarity index 99% rename from src/osp/drawing_gl/rendergl.cpp rename to src/osp_drawing_gl/rendergl.cpp index b283d572..fbd7dcfd 100644 --- a/src/osp/drawing_gl/rendergl.cpp +++ b/src/osp_drawing_gl/rendergl.cpp @@ -26,9 +26,9 @@ #include "rendergl.h" #include "FullscreenTriShader.h" -#include "../core/Resources.h" -#include "../drawing/own_restypes.h" -#include "../util/logging.h" +#include +#include +#include #include diff --git a/src/osp/drawing_gl/rendergl.h b/src/osp_drawing_gl/rendergl.h similarity index 99% rename from src/osp/drawing_gl/rendergl.h rename to src/osp_drawing_gl/rendergl.h index b6f4f3d6..4877fad5 100644 --- a/src/osp/drawing_gl/rendergl.h +++ b/src/osp_drawing_gl/rendergl.h @@ -26,7 +26,7 @@ #include "FullscreenTriShader.h" -#include "../drawing/drawing_fn.h" +#include #include #include diff --git a/src/ospjolt/CMakeLists.txt b/src/ospjolt/CMakeLists.txt new file mode 100644 index 00000000..07e42771 --- /dev/null +++ b/src/ospjolt/CMakeLists.txt @@ -0,0 +1,54 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + Trade + ) + +SET(DEPS_LIBS + EnTT::EnTT + Corrade::Main + Magnum::Magnum + Magnum::Trade + longeron + spdlog + OpenSpaceProgram + Jolt) + +add_library(OspJolt STATIC) + + +target_compile_features(OspJolt PUBLIC cxx_std_20) + +# Link it to the interface library that describes the dependencies +target_link_libraries(OspJolt PUBLIC ${DEPS_LIBS}) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(OspJolt PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for OspJolt +target_compile_options(OspJolt PRIVATE $<$:/permissive->) \ No newline at end of file diff --git a/src/ospjolt/activescene/forcefactors.h b/src/ospjolt/forcefactors.h similarity index 100% rename from src/ospjolt/activescene/forcefactors.h rename to src/ospjolt/forcefactors.h diff --git a/src/ospjolt/activescene/joltinteg.h b/src/ospjolt/joltinteg.h similarity index 99% rename from src/ospjolt/activescene/joltinteg.h rename to src/ospjolt/joltinteg.h index 54be7724..a4540077 100644 --- a/src/ospjolt/activescene/joltinteg.h +++ b/src/ospjolt/joltinteg.h @@ -283,7 +283,7 @@ struct ACtxJoltWorld //Should this be called on world creation ? not ideal in case of multiple worlds. static void initJoltGlobal() { - std::call_once(ACtxJoltWorld::initFlag, ACtxJoltWorld::initJoltGlobalInternal); + ACtxJoltWorld::initJoltGlobalInternal(); } @@ -314,7 +314,6 @@ struct ACtxJoltWorld static void initJoltGlobalInternal() { - RegisterDefaultAllocator(); // Install trace and assert callbacks diff --git a/src/ospjolt/activescene/joltinteg_fn.cpp b/src/ospjolt/joltinteg_fn.cpp similarity index 100% rename from src/ospjolt/activescene/joltinteg_fn.cpp rename to src/ospjolt/joltinteg_fn.cpp diff --git a/src/ospjolt/activescene/joltinteg_fn.h b/src/ospjolt/joltinteg_fn.h similarity index 100% rename from src/ospjolt/activescene/joltinteg_fn.h rename to src/ospjolt/joltinteg_fn.h diff --git a/src/planet-a/CMakeLists.txt b/src/planet-a/CMakeLists.txt new file mode 100644 index 00000000..e402b512 --- /dev/null +++ b/src/planet-a/CMakeLists.txt @@ -0,0 +1,51 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + Trade + ) + +SET(DEPS_LIBS + EnTT::EnTT + Corrade::Main + Magnum::Magnum + Magnum::Trade + longeron + OpenSpaceProgram) + +add_library(PlanetA STATIC) + +target_compile_features(PlanetA PUBLIC cxx_std_20) + +# Link it to the interface library that describes the dependencies +target_link_libraries(PlanetA PRIVATE ${DEPS_LIBS}) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(PlanetA PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for adera +target_compile_options(PlanetA PRIVATE $<$:/permissive->) \ No newline at end of file diff --git a/src/testapp/CMakeLists.txt b/src/testapp/CMakeLists.txt new file mode 100644 index 00000000..f23ef47c --- /dev/null +++ b/src/testapp/CMakeLists.txt @@ -0,0 +1,59 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + Trade + ) + +# TODO: This list shouldn't be required, but there appears to be a bug in cmake where +# the add_custom_target() command, pointing to an INTERFACE dependency, doesn't +# result in the dependencies of the interface building. +# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23569 +SET(OSP_DEPS_LIBS + Threads::Threads + EnTT::EnTT + Corrade::Main + Magnum::Magnum + Magnum::Trade + toml11 + spdlog + longeron + OpenSpaceProgram + Adera + OspJolt + PlanetA) + +add_library(OspTestApp STATIC) +target_link_libraries(OspTestApp PRIVATE ${OSP_DEPS_LIBS}) + +target_compile_features(OspTestApp PUBLIC cxx_std_20) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(OspTestApp PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for osp-magnum +target_compile_options(OspTestApp PRIVATE $<$:/permissive->) diff --git a/src/testapp/identifiers.h b/src/testapp/identifiers.h index 1c3764a3..853c0bf7 100644 --- a/src/testapp/identifiers.h +++ b/src/testapp/identifiers.h @@ -25,6 +25,13 @@ #pragma once #include +#include +#include +#include +#include +#include + +#include #include @@ -450,4 +457,14 @@ struct PlVehicleCtrl PipelineDef selectedVehicle {"selectedVehicle"}; }; +namespace scenes { + using enum EStgOptn; + using enum EStgCont; + using enum EStgIntr; + using enum EStgRevd; + using enum EStgEvnt; + using enum EStgFBO; + using enum EStgLink; +} + } // namespace testapp diff --git a/src/testapp/scenarios.h b/src/testapp/scenarios.h index 8beed14a..6cad1c36 100644 --- a/src/testapp/scenarios.h +++ b/src/testapp/scenarios.h @@ -25,14 +25,11 @@ #pragma once #include "identifiers.h" -#include "testapp.h" // IWYU pragma: begin_exports #include // IWYU pragma: end_exports -#include - namespace testapp { @@ -55,14 +52,14 @@ struct MainLoopControl bool doRender; }; -struct ScenarioOption +struct MainLoopSignals { - std::string_view m_description; - SceneSetupFunc_t m_setup; + osp::PipelineId mainLoop; + osp::PipelineId inputs; + osp::PipelineId renderSync; + osp::PipelineId renderResync; + osp::PipelineId sceneUpdate; + osp::PipelineId sceneRender; }; -using ScenarioMap_t = std::unordered_map; - -ScenarioMap_t const& scenarios(); - } // namespace testapp diff --git a/src/testapp/sessions/common.cpp b/src/testapp/sessions/common.cpp index cf752c7e..a7cd1021 100644 --- a/src/testapp/sessions/common.cpp +++ b/src/testapp/sessions/common.cpp @@ -23,6 +23,7 @@ * SOFTWARE. */ #include "common.h" +#include "../identifiers.h" #include "../scenarios.h" #include diff --git a/src/testapp/sessions/common.h b/src/testapp/sessions/common.h index c67f95b6..986b4fba 100644 --- a/src/testapp/sessions/common.h +++ b/src/testapp/sessions/common.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include diff --git a/src/testapp/sessions/jolt.cpp b/src/testapp/sessions/jolt.cpp index 44a37292..f2394944 100644 --- a/src/testapp/sessions/jolt.cpp +++ b/src/testapp/sessions/jolt.cpp @@ -25,6 +25,7 @@ #include "jolt.h" #include "physics.h" #include "shapes.h" +#include "../identifiers.h" #include #include @@ -36,7 +37,7 @@ #include -#include +#include using namespace osp; using namespace osp::active; diff --git a/src/testapp/sessions/jolt.h b/src/testapp/sessions/jolt.h index 03d8077d..521ae6a4 100644 --- a/src/testapp/sessions/jolt.h +++ b/src/testapp/sessions/jolt.h @@ -24,15 +24,20 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include -#include -#include #include -#include +#include #include diff --git a/src/testapp/sessions/misc.cpp b/src/testapp/sessions/misc.cpp index 09967d1a..9cf7e474 100644 --- a/src/testapp/sessions/misc.cpp +++ b/src/testapp/sessions/misc.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "misc.h" -#include "physics.h" +#include "../identifiers.h" #include #include diff --git a/src/testapp/sessions/misc.h b/src/testapp/sessions/misc.h index 012b9b2a..d7d68e04 100644 --- a/src/testapp/sessions/misc.h +++ b/src/testapp/sessions/misc.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include diff --git a/src/testapp/sessions/physics.cpp b/src/testapp/sessions/physics.cpp index 0bebbd1e..67fda25a 100644 --- a/src/testapp/sessions/physics.cpp +++ b/src/testapp/sessions/physics.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "physics.h" -#include "common.h" +#include "../identifiers.h" #include #include diff --git a/src/testapp/sessions/physics.h b/src/testapp/sessions/physics.h index f8a72854..9aa8ceb5 100644 --- a/src/testapp/sessions/physics.h +++ b/src/testapp/sessions/physics.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include @@ -32,8 +39,6 @@ #include -#include - namespace testapp::scenes { diff --git a/src/testapp/sessions/shapes.cpp b/src/testapp/sessions/shapes.cpp index 1c63f583..cd971699 100644 --- a/src/testapp/sessions/shapes.cpp +++ b/src/testapp/sessions/shapes.cpp @@ -24,6 +24,7 @@ */ #include "shapes.h" #include "common.h" +#include "../identifiers.h" #include diff --git a/src/testapp/sessions/shapes.h b/src/testapp/sessions/shapes.h index c763d872..b9c57cce 100644 --- a/src/testapp/sessions/shapes.h +++ b/src/testapp/sessions/shapes.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include diff --git a/src/testapp/sessions/terrain.cpp b/src/testapp/sessions/terrain.cpp index eea97774..4f6ced0f 100644 --- a/src/testapp/sessions/terrain.cpp +++ b/src/testapp/sessions/terrain.cpp @@ -24,6 +24,8 @@ */ #include "terrain.h" #include "common.h" +#include "../identifiers.h" + #include #include diff --git a/src/testapp/sessions/terrain.h b/src/testapp/sessions/terrain.h index 13a61fde..eb18cb05 100644 --- a/src/testapp/sessions/terrain.h +++ b/src/testapp/sessions/terrain.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include "planet-a/chunk_utils.h" #include diff --git a/src/testapp/sessions/universe.cpp b/src/testapp/sessions/universe.cpp index 2537defd..7578ce1f 100644 --- a/src/testapp/sessions/universe.cpp +++ b/src/testapp/sessions/universe.cpp @@ -34,6 +34,8 @@ #include #include +#include "../identifiers.h" + #include using namespace adera; diff --git a/src/testapp/sessions/universe.h b/src/testapp/sessions/universe.h index 94039d16..2eebd69b 100644 --- a/src/testapp/sessions/universe.h +++ b/src/testapp/sessions/universe.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include diff --git a/src/testapp/sessions/vehicles.cpp b/src/testapp/sessions/vehicles.cpp index 6321ccb3..309bb459 100644 --- a/src/testapp/sessions/vehicles.cpp +++ b/src/testapp/sessions/vehicles.cpp @@ -35,6 +35,8 @@ #include #include +#include "../identifiers.h" + using namespace adera; using namespace osp::active; diff --git a/src/testapp/sessions/vehicles.h b/src/testapp/sessions/vehicles.h index 69b398a4..dfa684f1 100644 --- a/src/testapp/sessions/vehicles.h +++ b/src/testapp/sessions/vehicles.h @@ -24,11 +24,20 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include + namespace testapp::scenes { + /** * @brief Support for Parts, Machines, and Links */ diff --git a/src/testapp/sessions/vehicles_machines.cpp b/src/testapp/sessions/vehicles_machines.cpp index c79660e2..92f93846 100644 --- a/src/testapp/sessions/vehicles_machines.cpp +++ b/src/testapp/sessions/vehicles_machines.cpp @@ -35,6 +35,7 @@ #include #include #include +#include "../identifiers.h" using namespace adera; @@ -223,24 +224,26 @@ Session setup_thrust_indicators( ActiveEnt const partEnt = rScnParts.partToActive[part]; for (MachinePair const pair : rScnParts.partToMachines[part]) - if (pair.type == gc_mtMagicRocket) { - DrawEnt const drawEnt = rThrustIndicator.rktToDrawEnt[pair.local]; - MachAnyId const anyId = rockets.localToAny[pair.local]; - - auto const& portSpan = floats.machToNode[anyId]; - NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); - NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); - - float const throttle = std::clamp(rSigValFloat[throttleIn], 0.0f, 1.0f); - float const multiplier = rSigValFloat[multiplierIn]; - float const thrustMag = throttle * multiplier; - - rCtxScnRdr.m_drawTransform[drawEnt] - = drawTf - * Matrix4::scaling({1.0f, 1.0f, thrustMag * rThrustIndicator.indicatorScale}) - * Matrix4::translation({0.0f, 0.0f, -1.0f}) - * Matrix4::scaling({0.2f, 0.2f, 1.0f}); + if (pair.type == gc_mtMagicRocket) + { + DrawEnt const drawEnt = rThrustIndicator.rktToDrawEnt[pair.local]; + MachAnyId const anyId = rockets.localToAny[pair.local]; + + auto const& portSpan = floats.machToNode[anyId]; + NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); + NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); + + float const throttle = std::clamp(rSigValFloat[throttleIn], 0.0f, 1.0f); + float const multiplier = rSigValFloat[multiplierIn]; + float const thrustMag = throttle * multiplier; + + rCtxScnRdr.m_drawTransform[drawEnt] + = drawTf + * Matrix4::scaling({1.0f, 1.0f, thrustMag * rThrustIndicator.indicatorScale}) + * Matrix4::translation({0.0f, 0.0f, -1.0f}) + * Matrix4::scaling({0.2f, 0.2f, 1.0f}); + } } }; diff --git a/src/testapp/sessions/vehicles_machines.h b/src/testapp/sessions/vehicles_machines.h index 95139245..39062656 100644 --- a/src/testapp/sessions/vehicles_machines.h +++ b/src/testapp/sessions/vehicles_machines.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include diff --git a/src/testapp/sessions/vehicles_prebuilt.cpp b/src/testapp/sessions/vehicles_prebuilt.cpp index 08f1d0f5..7878d95d 100644 --- a/src/testapp/sessions/vehicles_prebuilt.cpp +++ b/src/testapp/sessions/vehicles_prebuilt.cpp @@ -28,6 +28,8 @@ #include +#include "../identifiers.h" + using namespace adera; using namespace osp::link; diff --git a/src/testapp/sessions/vehicles_prebuilt.h b/src/testapp/sessions/vehicles_prebuilt.h index 4f2dabea..df15198b 100644 --- a/src/testapp/sessions/vehicles_prebuilt.h +++ b/src/testapp/sessions/vehicles_prebuilt.h @@ -24,12 +24,18 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include -#include #include #include diff --git a/src/testapp/testapp.cpp b/src/testapp/testapp.cpp index 81a086f8..c2c815c9 100644 --- a/src/testapp/testapp.cpp +++ b/src/testapp/testapp.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "testapp.h" -#include "identifiers.h" +#include #include #include diff --git a/src/testapp_magnum/CMakeLists.txt b/src/testapp_magnum/CMakeLists.txt new file mode 100644 index 00000000..38d638e4 --- /dev/null +++ b/src/testapp_magnum/CMakeLists.txt @@ -0,0 +1,109 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + GL + Shaders + MeshTools + Primitives + Trade + Sdl2Application + AnyImageImporter + ) + +find_package(MagnumPlugins REQUIRED + TinyGltfImporter + StbImageImporter) + +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads) +if(NOT Threads_FOUND) + message(FATAL_ERROR "Can't find a thread library to use!") +endif() + + +add_library(osp-magnum-deps INTERFACE) +add_custom_target(compile-osp-magnum-deps) + +# TODO: This list shouldn't be required, but there appears to be a bug in cmake where +# the add_custom_target() command, pointing to an INTERFACE dependency, doesn't +# result in the dependencies of the interface building. +# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23569 +SET(OSP_MAGNUM_DEPS_LIBS + Threads::Threads + EnTT::EnTT + Corrade::Main + Magnum::Application + Magnum::GL + Magnum::Magnum + Magnum::MeshTools + Magnum::Primitives + Magnum::Shaders + Magnum::Trade + Magnum::AnyImageImporter + MagnumPlugins::TinyGltfImporter + MagnumPlugins::StbImageImporter + toml11 + spdlog + longeron + OpenSpaceProgram + Adera + AderaGL + OspGL + OspJolt + PlanetA + OspTestApp) +target_link_libraries(osp-magnum-deps INTERFACE ${OSP_MAGNUM_DEPS_LIBS}) +add_dependencies(compile-osp-magnum-deps ${OSP_MAGNUM_DEPS_LIBS}) + +add_executable(osp-magnum) + +target_compile_features(osp-magnum PUBLIC cxx_std_20) + +target_include_directories(osp-magnum PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +# Link it to the interface library that describes the dependencies +target_link_libraries(osp-magnum PRIVATE osp-magnum-deps) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(osp-magnum PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for osp-magnum +target_compile_options(osp-magnum PRIVATE $<$:/permissive->) + +set_target_properties(osp-magnum PROPERTIES + EXPORT_COMPILE_COMMANDS TRUE + INSTALL_RPATH "$ORIGIN/lib" + C_EXTENSIONS OFF + C_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON +) + +add_custom_target(run-osp-magnum + COMMAND $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/$) diff --git a/src/testapp/MagnumApplication.cpp b/src/testapp_magnum/MagnumApplication.cpp similarity index 100% rename from src/testapp/MagnumApplication.cpp rename to src/testapp_magnum/MagnumApplication.cpp diff --git a/src/testapp/MagnumApplication.h b/src/testapp_magnum/MagnumApplication.h similarity index 100% rename from src/testapp/MagnumApplication.h rename to src/testapp_magnum/MagnumApplication.h diff --git a/src/testapp/README.md b/src/testapp_magnum/README.md similarity index 100% rename from src/testapp/README.md rename to src/testapp_magnum/README.md diff --git a/src/testapp/enginetest.cpp b/src/testapp_magnum/enginetest.cpp similarity index 99% rename from src/testapp/enginetest.cpp rename to src/testapp_magnum/enginetest.cpp index 86ca9a5b..0a1c7bfa 100644 --- a/src/testapp/enginetest.cpp +++ b/src/testapp_magnum/enginetest.cpp @@ -29,10 +29,10 @@ #include #include #include -#include +#include #include -#include +#include #include #include diff --git a/src/testapp/enginetest.h b/src/testapp_magnum/enginetest.h similarity index 98% rename from src/testapp/enginetest.h rename to src/testapp_magnum/enginetest.h index 38438315..2961deb8 100644 --- a/src/testapp/enginetest.h +++ b/src/testapp_magnum/enginetest.h @@ -26,7 +26,7 @@ #include "MagnumApplication.h" -#include +#include namespace testapp::enginetest { diff --git a/src/testapp/main.cpp b/src/testapp_magnum/main.cpp similarity index 99% rename from src/testapp/main.cpp rename to src/testapp_magnum/main.cpp index fd01a140..400e4ac7 100644 --- a/src/testapp/main.cpp +++ b/src/testapp_magnum/main.cpp @@ -24,10 +24,10 @@ */ #include "MagnumApplication.h" -#include "testapp.h" +#include #include "scenarios.h" -#include "identifiers.h" -#include "sessions/common.h" +#include +#include #include "sessions/magnum.h" #include diff --git a/src/testapp/scenarios.cpp b/src/testapp_magnum/scenarios.cpp similarity index 98% rename from src/testapp/scenarios.cpp rename to src/testapp_magnum/scenarios.cpp index 6a7d2a56..77ed882f 100644 --- a/src/testapp/scenarios.cpp +++ b/src/testapp_magnum/scenarios.cpp @@ -25,19 +25,19 @@ #include "scenarios.h" #include "enginetest.h" -#include "identifiers.h" +#include -#include "sessions/common.h" +#include #include "sessions/magnum.h" -#include "sessions/misc.h" -#include "sessions/jolt.h" -#include "sessions/physics.h" -#include "sessions/shapes.h" -#include "sessions/terrain.h" -#include "sessions/universe.h" -#include "sessions/vehicles.h" -#include "sessions/vehicles_machines.h" -#include "sessions/vehicles_prebuilt.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "MagnumApplication.h" @@ -459,15 +459,7 @@ ScenarioMap_t const& scenarios() //----------------------------------------------------------------------------- -struct MainLoopSignals -{ - PipelineId mainLoop; - PipelineId inputs; - PipelineId renderSync; - PipelineId renderResync; - PipelineId sceneUpdate; - PipelineId sceneRender; -}; + /** * @brief Runs Task/Pipeline main loop within MagnumApplication diff --git a/src/testapp_magnum/scenarios.h b/src/testapp_magnum/scenarios.h new file mode 100644 index 00000000..9081d6f6 --- /dev/null +++ b/src/testapp_magnum/scenarios.h @@ -0,0 +1,51 @@ +/** + * Open Space Program + * Copyright © 2019-2021 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + +#include +#include +#include + +// IWYU pragma: begin_exports +#include +// IWYU pragma: end_exports + +#include +#include + +namespace testapp +{ + +struct ScenarioOption +{ + std::string_view m_description; + SceneSetupFunc_t m_setup; +}; + +using ScenarioMap_t = std::unordered_map; + +ScenarioMap_t const& scenarios(); + +} // namespace testapp diff --git a/src/testapp/sessions/magnum.cpp b/src/testapp_magnum/sessions/magnum.cpp similarity index 99% rename from src/testapp/sessions/magnum.cpp rename to src/testapp_magnum/sessions/magnum.cpp index 01d1722f..9253cafd 100644 --- a/src/testapp/sessions/magnum.cpp +++ b/src/testapp_magnum/sessions/magnum.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "magnum.h" -#include "common.h" +#include #include "../MagnumApplication.h" @@ -31,12 +31,12 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include -#include +#include #include #include diff --git a/src/testapp/sessions/magnum.h b/src/testapp_magnum/sessions/magnum.h similarity index 100% rename from src/testapp/sessions/magnum.h rename to src/testapp_magnum/sessions/magnum.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f9fcf1f7..ac805025 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,7 +32,7 @@ include(GoogleTest) add_library(test-deps INTERFACE) add_custom_target(compile-test-deps) -set(TEST_DEPS_LIBRARIES gtest_main longeron EnTT::EnTT Magnum::Magnum) +set(TEST_DEPS_LIBRARIES gtest_main longeron EnTT::EnTT Magnum::Magnum OpenSpaceProgram) target_link_libraries(test-deps INTERFACE ${TEST_DEPS_LIBRARIES}) add_dependencies(compile-test-deps ${TEST_DEPS_LIBRARIES})