From 22d8b35373214b6cd9581ce50ccb79cf76410f6f Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Mon, 1 Apr 2024 20:16:48 -0400 Subject: [PATCH] Updated Coral version to .Net 8 --- Nuake/src/Physics/DynamicWorld.h | 1 + .../src/Scripting/NetModules/EngineNetAPI.cpp | 4 ++-- .../src/Scripting/NetModules/InputNetAPI.cpp | 6 ++--- Nuake/src/Scripting/NetModules/NetAPIModule.h | 2 +- .../src/Scripting/NetModules/SceneNetAPI.cpp | 22 +++++++++---------- Nuake/src/Scripting/ScriptingEngineNet.cpp | 15 +++++++------ NuakeNet/premake5.lua | 2 +- premake5.lua | 22 +++++-------------- 8 files changed, 31 insertions(+), 43 deletions(-) diff --git a/Nuake/src/Physics/DynamicWorld.h b/Nuake/src/Physics/DynamicWorld.h index 5b7f9b4b..698b725b 100644 --- a/Nuake/src/Physics/DynamicWorld.h +++ b/Nuake/src/Physics/DynamicWorld.h @@ -13,6 +13,7 @@ #include "Jolt/Jolt.h" +#include namespace JPH { diff --git a/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp b/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp index 4b9725aa..34bcb0c8 100644 --- a/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp @@ -2,9 +2,9 @@ namespace Nuake { - void Log(Coral::NativeString string) + void Log(Coral::String string) { - Logger::Log(string.ToString(), ".net", VERBOSE); + Logger::Log(string, ".net", VERBOSE); } void EngineNetAPI::RegisterMethods() diff --git a/Nuake/src/Scripting/NetModules/InputNetAPI.cpp b/Nuake/src/Scripting/NetModules/InputNetAPI.cpp index e3fc1cdf..32b41358 100644 --- a/Nuake/src/Scripting/NetModules/InputNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/InputNetAPI.cpp @@ -2,7 +2,7 @@ #include "src/Core/Input.h" -#include +#include namespace Nuake { @@ -28,10 +28,10 @@ namespace Nuake { return Input::IsKeyPressed(keyCode); } - Coral::NativeArray GetMousePosition() + Coral::Array GetMousePosition() { Vector2 mousePosition = Input::GetMousePosition(); - return { mousePosition.x, mousePosition.y}; + return Coral::Array::New({ mousePosition.x, mousePosition.y }); } diff --git a/Nuake/src/Scripting/NetModules/NetAPIModule.h b/Nuake/src/Scripting/NetModules/NetAPIModule.h index b388c69b..10af937b 100644 --- a/Nuake/src/Scripting/NetModules/NetAPIModule.h +++ b/Nuake/src/Scripting/NetModules/NetAPIModule.h @@ -2,7 +2,7 @@ #include "src/Core/Core.h" #include "src/Core/Logger.h" -#include +#include namespace Nuake { diff --git a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp index f8320002..9f86644a 100644 --- a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp @@ -22,22 +22,20 @@ #include "src/Physics/PhysicsManager.h" -#include +#include namespace Nuake { - uint32_t GetEntity(Coral::NativeString entityName) + uint32_t GetEntity(Coral::String entityName) { auto scene = Engine::GetCurrentScene(); - - std::string entityNameString = entityName.ToString(); - if (!scene->EntityExists(entityNameString)) + if (!scene->EntityExists(entityName)) { return UINT32_MAX; // Error code: entity not found. } - return scene->GetEntity(entityNameString).GetHandle(); + return scene->GetEntity(entityName).GetHandle(); } static enum ComponentTypes @@ -120,7 +118,7 @@ namespace Nuake { } } - Coral::NativeArray TransformGetGlobalPosition(int entityId) + Coral::Array TransformGetGlobalPosition(int entityId) { Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; @@ -128,7 +126,7 @@ namespace Nuake { { auto& component = entity.GetComponent(); const auto& globalPosition = component.GetGlobalPosition(); - Coral::NativeArray result = { globalPosition.x, globalPosition.y, globalPosition.z }; + Coral::Array result = Coral::Array::New({ globalPosition.x, globalPosition.y, globalPosition.z }); return result; } } @@ -145,7 +143,7 @@ namespace Nuake { } } - Coral::NativeArray CameraGetDirection(int entityId) + Coral::Array CameraGetDirection(int entityId) { Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; @@ -153,7 +151,7 @@ namespace Nuake { { auto& component = entity.GetComponent(); const Vector3 camDirection = component.CameraInstance->GetDirection(); - return { camDirection.x, camDirection.y, camDirection.z }; + return Coral::Array::New({ camDirection.x, camDirection.y, camDirection.z }); } } @@ -187,7 +185,7 @@ namespace Nuake { return false; } - void Play(int entityId, Coral::NativeString animation) + void Play(int entityId, Coral::String animation) { Entity entity = Entity((entt::entity)(entityId), Engine::GetCurrentScene().get()); @@ -203,7 +201,7 @@ namespace Nuake { int animIndex = 0; for (const auto& anim : model->GetAnimations()) { - if (anim->GetName() == animation.ToString()) + if (anim->GetName() == animation) { model->PlayAnimation(animIndex); } diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index ea4fcecf..d04321ea 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include @@ -130,13 +130,15 @@ namespace Nuake for (auto& type : m_GameAssembly.GetTypes()) { - Logger::Log(std::string("Detected type: ") + std::string(type->GetName()), ".net"); - Logger::Log(std::string("Detected base type: ") + std::string(type->GetBaseType().GetName()), ".net"); + Logger::Log(std::string("Detected type: ") + std::string(type->GetFullName()), ".net"); + Logger::Log(std::string("Detected base type: ") + std::string(type->GetBaseType().GetFullName()), ".net"); - const std::string baseTypeName = std::string(type->GetBaseType().GetName()); - if (baseTypeName == "Entity") + const std::string baseTypeName = std::string(type->GetBaseType().GetFullName()); + if (baseTypeName == "Nuake.Net.Entity") { - m_GameEntityTypes[std::string(type->GetName())] = type; // We have found an entity script. + auto typeSplits = String::Split(type->GetFullName(), '.'); + std::string shortenedTypeName = typeSplits[typeSplits.size() - 1]; + m_GameEntityTypes[shortenedTypeName] = type; // We have found an entity script. } } } @@ -198,7 +200,6 @@ namespace Nuake size_t classNameLength = semiColonPos - classNameStartIndex; const std::string className = fileContent.substr(classNameStartIndex, classNameLength); - if(m_GameEntityTypes.find(className) == m_GameEntityTypes.end()) { // The class name parsed in the file was not found in the game's DLL. diff --git a/NuakeNet/premake5.lua b/NuakeNet/premake5.lua index 567d0b61..cef4d968 100644 --- a/NuakeNet/premake5.lua +++ b/NuakeNet/premake5.lua @@ -1,6 +1,6 @@ project "NuakeNet" language "C#" - dotnetframework "net7.0" + dotnetframework "net8.0" kind "SharedLib" clr "Unsafe" diff --git a/premake5.lua b/premake5.lua index 6994ebce..40230a7b 100644 --- a/premake5.lua +++ b/premake5.lua @@ -180,7 +180,7 @@ project "NuakeRuntime" "%{prj.name}/../Nuake/src/Vendors/wren/src/include", "%{prj.name}/../Nuake/dependencies/JoltPhysics/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/JoltPhysics/", "%{prj.name}/../Nuake/dependencies/soloud/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}", - "%{prj.name}/../Nuake/dependencies/Coral/NetCore/7.0.7/" + "%{prj.name}/../Nuake/dependencies/Coral/NetCore/" } links @@ -193,8 +193,6 @@ project "NuakeRuntime" "JoltPhysics", "soloud", "Coral.Native", - "nethost", - "libnethost" } filter "system:windows" @@ -211,11 +209,7 @@ project "NuakeRuntime" externalincludedirs { "%{prj.name}/../Nuake/dependencies/Coral/Coral.Native/Include/" } postbuildcommands { - '{ECHO} Copying "%{wks.location}/NetCore/7.0.7/nethost.dll" to "%{cfg.targetdir}"', - '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/NetCore/7.0.7/nethost.dll" "%{cfg.targetdir}"', - '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/Coral.Managed/Coral.Managed.runtimeconfig.json" "%{wks.location}/%{prj.name}"', - '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/Coral.Managed/Build/%{cfg.buildcfg}-%{cfg.system}/Coral.Managed.dll" "%{wks.location}/%{prj.name}"', - '{COPYFILE} "%{wks.location}/NuakeNet/bin/%{cfg.buildcfg}/NuakeNet.dll" "%{wks.location}/%{prj.name}"' + '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/Coral.Managed/Coral.Managed.runtimeconfig.json" "%{wks.location}/%{prj.name}"' } filter "system:linux" @@ -318,7 +312,7 @@ project "Editor" "%{prj.name}/../Nuake/src/Vendors/wren/src/include", "%{prj.name}/../Nuake/dependencies/JoltPhysics/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/JoltPhysics/", "%{prj.name}/../Nuake/dependencies/soloud/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}", - "%{prj.name}/../Nuake/dependencies/Coral/NetCore/7.0.7/" + "%{prj.name}/../Nuake/dependencies/Coral/NetCore/" } links @@ -330,9 +324,7 @@ project "Editor" "Freetype", "JoltPhysics", "soloud", - "Coral.Native", - "nethost", - "libnethost" + "Coral.Native" } filter "system:Windows" @@ -353,11 +345,7 @@ project "Editor" externalincludedirs { "%{prj.name}/../Nuake/dependencies/Coral/Coral.Native/Include/" } postbuildcommands { - '{ECHO} Copying "%{wks.location}/NetCore/7.0.7/nethost.dll" to "%{cfg.targetdir}"', - '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/NetCore/7.0.7/nethost.dll" "%{cfg.targetdir}"', - '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/Coral.Managed/Coral.Managed.runtimeconfig.json" "%{wks.location}/%{prj.name}"', - '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/Coral.Managed/Build/%{cfg.buildcfg}-%{cfg.system}/Coral.Managed.dll" "%{wks.location}/%{prj.name}"', - '{COPYFILE} "%{wks.location}/NuakeNet/bin/%{cfg.buildcfg}/NuakeNet.dll" "%{wks.location}/%{prj.name}"' + '{COPYFILE} "%{wks.location}/Nuake/dependencies/Coral/Coral.Managed/Coral.Managed.runtimeconfig.json" "%{wks.location}/%{prj.name}"' }