From 5390f1916129ab41450b33380d3c4db64654d93a Mon Sep 17 00:00:00 2001 From: FlayaN Date: Wed, 30 Aug 2023 22:02:05 +0200 Subject: [PATCH 1/2] build: Added automatic plugin deployment fixes issue #63 --- .gitignore | 3 +- Build Release.bat | 7 ---- CMakeLists.txt | 75 ++++++++++++++++++++++++++++++++++ CMakeUserPresets.json.template | 15 +++++++ 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 CMakeUserPresets.json.template diff --git a/.gitignore b/.gitignore index c2322688b..8f1ef6b69 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ dist/ -.vs*/ \ No newline at end of file +.vs*/ +CMakeUserPresets.json \ No newline at end of file diff --git a/Build Release.bat b/Build Release.bat index 62a75e087..88e457d40 100644 --- a/Build Release.bat +++ b/Build Release.bat @@ -1,15 +1,8 @@ @echo off -RMDIR dist /S /Q - cmake -S . --preset=ALL --check-stamp-file "build\CMakeFiles\generate.stamp" if %ERRORLEVEL% NEQ 0 exit 1 cmake --build build --config Release if %ERRORLEVEL% NEQ 0 exit 1 -xcopy "build\release\*.dll" "dist\SKSE\Plugins\" /I /Y -xcopy "build\release\*.pdb" "dist\SKSE\Plugins\" /I /Y - -xcopy "package" "dist" /I /Y /E - pause \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a835edf9..11b74f240 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,24 @@ project( ) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + +# ######################################################################################################################## +# ## Build options +# ######################################################################################################################## +message("Options:") +option(AUTO_PLUGIN_DEPLOYMENT "Copy the build output and addons to env:CommunityShadersOutputDir." OFF) +option(ZIP_TO_DIST "Zip the base mod and addons to their own 7z file in dist." ON) +message("\tAuto plugin deployment: ${AUTO_PLUGIN_DEPLOYMENT}") +message("\tZip to dist: ${ZIP_TO_DIST}") + +# ####################################################################################################################### +# # Add CMake features +# ####################################################################################################################### include(XSEPlugin) +# ####################################################################################################################### +# # Find dependencies +# ####################################################################################################################### find_package(magic_enum CONFIG REQUIRED) find_package(xbyak CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED) @@ -57,3 +73,62 @@ if(MSVC_VERSION GREATER_EQUAL 1936 AND MSVC_IDE) # 17.6+ ]==] @ONLY) endif() + +# ####################################################################################################################### +# # Automatic deployment +# ####################################################################################################################### + +file(GLOB FEATURE_PATHS LIST_DIRECTORIES true ${CMAKE_SOURCE_DIR}/features/*) + +# Automatic deployment to CommunityShaders output directory. +if (AUTO_PLUGIN_DEPLOYMENT) + foreach(DEPLOY_TARGET $ENV{CommunityShadersOutputDir}) + message("Copying package folder with dll/pdb with all features to ${DEPLOY_TARGET}") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/package "${DEPLOY_TARGET}" + COMMAND ${CMAKE_COMMAND} -E copy $ "${DEPLOY_TARGET}/SKSE/Plugins/" + COMMAND ${CMAKE_COMMAND} -E copy $ "${DEPLOY_TARGET}/SKSE/Plugins/" + ) + foreach(FEATURE_PATH ${FEATURE_PATHS}) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${FEATURE_PATH} "${DEPLOY_TARGET}" + ) + endforeach() + endforeach() + if (NOT DEFINED ENV{CommunityShadersOutputDir}) + message("When using AUTO_PLUGIN_DEPLOYMENT option, you need to set environment variable 'CommunityShadersOutputDir'") + endif() +endif() + +# Zip base CommunityShaders and all addons as their own 7z in dist folder +if(ZIP_TO_DIST) + set(ZIP_DIR "${CMAKE_CURRENT_BINARY_DIR}/zip") + file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/test/) + add_custom_target(build-time-make-directory ALL + COMMAND ${CMAKE_COMMAND} -E remove_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist + COMMAND ${CMAKE_COMMAND} -E make_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist + ) + + message("Copying base CommunityShader into ${ZIP_DIR}.") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/package "${ZIP_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy $ "${ZIP_DIR}/SKSE/Plugins/" + COMMAND ${CMAKE_COMMAND} -E copy $ "${ZIP_DIR}/SKSE/Plugins/" + ) + + set(TARGET_ZIP "${PROJECT_NAME}.7z") + message("Zipping ${ZIP_DIR} to ${CMAKE_SOURCE_DIR}/dist/${TARGET_ZIP}") + ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_SOURCE_DIR}/dist/${TARGET_ZIP} --format=7zip -- . + WORKING_DIRECTORY ${ZIP_DIR} + ) + + foreach(FEATURE_PATH ${FEATURE_PATHS}) + get_filename_component(FEATURE ${FEATURE_PATH} NAME) + message("Zipping ${FEATURE_PATH} to ${CMAKE_SOURCE_DIR}/dist/${FEATURE}.7z") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_SOURCE_DIR}/dist/${FEATURE}.7z --format=7zip -- . + WORKING_DIRECTORY ${FEATURE_PATH} + ) + endforeach() +endif() diff --git a/CMakeUserPresets.json.template b/CMakeUserPresets.json.template new file mode 100644 index 000000000..3e643c3aa --- /dev/null +++ b/CMakeUserPresets.json.template @@ -0,0 +1,15 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "ALL-WITH-AUTO-DEPLOYMENT", + "cacheVariables": { + "AUTO_PLUGIN_DEPLOYMENT": "ON" + }, + "environment": { + "CommunityShadersOutputDir": "F:/MySkyrimModpack/mods/CommunityShaders;F:/SteamLibrary/steamapps/common/SkyrimVR/Data;F:/SteamLibrary/steamapps/common/Skyrim Special Edition/Data" + }, + "inherits": "ALL" + } + ] +} \ No newline at end of file From 150a1790b77d6b555a5785a83823bb96fed62a37 Mon Sep 17 00:00:00 2001 From: FlayaN Date: Wed, 30 Aug 2023 20:14:22 +0000 Subject: [PATCH 2/2] =?UTF-8?q?style:=20=F0=9F=8E=A8=20apply=20clang-forma?= =?UTF-8?q?t=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Features/LightLimitFix.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Features/LightLimitFix.cpp b/src/Features/LightLimitFix.cpp index fb44000f7..ca18b28b5 100644 --- a/src/Features/LightLimitFix.cpp +++ b/src/Features/LightLimitFix.cpp @@ -200,10 +200,10 @@ void LightLimitFix::SetLightPosition(LightLimitFix::LightData& a_light, RE::NiPo for (int eyeIndex = 0; eyeIndex < eyeCount; eyeIndex++) { auto eyePosition = eyeCount == 1 ? state->GetRuntimeData().posAdjust.getEye(eyeIndex) : - state->GetVRRuntimeData().posAdjust.getEye(eyeIndex); + state->GetVRRuntimeData().posAdjust.getEye(eyeIndex); auto viewMatrix = eyeCount == 1 ? state->GetRuntimeData().cameraData.getEye(eyeIndex).viewMat : - state->GetVRRuntimeData().cameraData.getEye(eyeIndex).viewMat; + state->GetVRRuntimeData().cameraData.getEye(eyeIndex).viewMat; auto worldPos = a_initialPosition - eyePosition; a_light.positionWS[eyeIndex].x = worldPos.x; a_light.positionWS[eyeIndex].y = worldPos.y; @@ -316,7 +316,7 @@ void LightLimitFix::Bind() auto reflections = (!REL::Module::IsVR() ? RE::BSGraphics::RendererShadowState::GetSingleton()->GetRuntimeData().cubeMapRenderTarget : - RE::BSGraphics::RendererShadowState::GetSingleton()->GetVRRuntimeData().cubeMapRenderTarget) == RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS; + RE::BSGraphics::RendererShadowState::GetSingleton()->GetVRRuntimeData().cubeMapRenderTarget) == RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS; if (reflections || accumulator->GetRuntimeData().activeShadowSceneNode != RE::BSShaderManager::State::GetSingleton().shadowSceneNode[0]) { PerPass perPassData{}; @@ -629,12 +629,12 @@ bool LightLimitFix::AddCachedParticleLights(eastl::vector& lightsData auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); auto eyePosition = eyeCount == 1 ? state->GetRuntimeData().posAdjust.getEye(a_eyeIndex) : - state->GetVRRuntimeData().posAdjust.getEye(a_eyeIndex); + state->GetVRRuntimeData().posAdjust.getEye(a_eyeIndex); cachedParticleLight.position = { light.positionWS[a_eyeIndex].x + eyePosition.x, light.positionWS[a_eyeIndex].y + eyePosition.y, light.positionWS[a_eyeIndex].z + eyePosition.z }; for (int eyeIndex = 0; eyeIndex < eyeCount; eyeIndex++) { auto viewMatrix = eyeCount == 1 ? state->GetRuntimeData().cameraData.getEye(eyeIndex).viewMat : - state->GetVRRuntimeData().cameraData.getEye(eyeIndex).viewMat; + state->GetVRRuntimeData().cameraData.getEye(eyeIndex).viewMat; light.positionVS[eyeIndex] = DirectX::SimpleMath::Vector3::Transform(light.positionWS[eyeIndex], viewMatrix); } for (int eyeIndex = 0; eyeIndex < eyeCount; eyeIndex++) { @@ -758,7 +758,7 @@ void LightLimitFix::UpdateLights() auto eyeIndex = 0; // only calculate for left eye auto eyePosition = eyeCount == 1 ? state->GetRuntimeData().posAdjust.getEye(eyeIndex) : - state->GetVRRuntimeData().posAdjust.getEye(eyeIndex); + state->GetVRRuntimeData().posAdjust.getEye(eyeIndex); for (const auto& particleLight : particleLights) { if (const auto particleSystem = netimmerse_cast(particleLight.first);