diff --git a/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp b/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp index a975736a6..02c7b1c26 100644 --- a/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp +++ b/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp @@ -12,6 +12,7 @@ #include "Engine/Scripting/MException.h" #include "Engine/Content/Assets/SkinnedModel.h" +#if !COMPILE_WITHOUT_CSHARP #if USE_MONO #include #endif @@ -86,6 +87,8 @@ namespace AnimGraphInternal } } +#endif + void AnimGraphExecutor::initRuntime() { #if USE_MONO diff --git a/Source/Engine/Networking/NetworkReplicator.cpp b/Source/Engine/Networking/NetworkReplicator.cpp index 532e148c1..13986db1e 100644 --- a/Source/Engine/Networking/NetworkReplicator.cpp +++ b/Source/Engine/Networking/NetworkReplicator.cpp @@ -1387,7 +1387,7 @@ void NetworkInternal::OnNetworkMessageObjectSpawn(NetworkEvent& event, NetworkCl // Reuse parent object as prefab instance prefabInstance = parentActor; } - else if (parentActor = Scripting::TryFindObject(rootItem.ParentId)) + else if ((parentActor = Scripting::TryFindObject(rootItem.ParentId))) { // Try to find that spawned prefab (eg. prefab with networked script was spawned before so now we need to link it) for (Actor* child : parentActor->Children) diff --git a/Source/Engine/Scripting/DotNet/CoreCLR.cpp b/Source/Engine/Scripting/DotNet/CoreCLR.cpp index cf427d3c1..210a454f1 100644 --- a/Source/Engine/Scripting/DotNet/CoreCLR.cpp +++ b/Source/Engine/Scripting/DotNet/CoreCLR.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. #include "CoreCLR.h" +#if USE_NETCORE #include "Engine/Core/Log.h" #include "Engine/Platform/Platform.h" #include "Engine/Platform/FileSystem.h" @@ -130,3 +131,5 @@ void CoreCLR::Free(void* ptr) { Platform::Free(ptr); } + +#endif diff --git a/Source/Engine/Scripting/DotNet/CoreCLR.h b/Source/Engine/Scripting/DotNet/CoreCLR.h index 3a8d3e480..c90961a24 100644 --- a/Source/Engine/Scripting/DotNet/CoreCLR.h +++ b/Source/Engine/Scripting/DotNet/CoreCLR.h @@ -6,6 +6,8 @@ #include "Engine/Core/Collections/Array.h" #include "Engine/Scripting/Types.h" +#if USE_NETCORE + #if defined(_WIN32) #define CORECLR_DELEGATE_CALLTYPE __stdcall #define FLAX_CORECLR_STRING String @@ -59,5 +61,7 @@ public: static bool HasCustomAttribute(void* klass, void* attribClass); static bool HasCustomAttribute(void* klass); static void* GetCustomAttribute(void* klass, void* attribClass); - static Array GetCustomAttributes(void* klass); + static Array GetCustomAttributes(void* klass); }; + +#endif diff --git a/Source/Engine/Scripting/DotNet/MonoApi.cpp b/Source/Engine/Scripting/DotNet/MonoApi.cpp index 8f90bfa32..7d874e965 100644 --- a/Source/Engine/Scripting/DotNet/MonoApi.cpp +++ b/Source/Engine/Scripting/DotNet/MonoApi.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. #include "CoreCLR.h" +#if USE_NETCORE #include "Engine/Scripting/Types.h" #include "Engine/Core/Collections/Dictionary.h" #include "Engine/Graphics/RenderView.h" @@ -614,24 +615,25 @@ bool CoreCLR::HasCustomAttribute(void* klass, void* attribClass) { return CoreCLR::GetCustomAttribute(klass, attribClass) != nullptr; } + bool CoreCLR::HasCustomAttribute(void* klass) { return CoreCLR::GetCustomAttribute(klass, nullptr) != nullptr; } + void* CoreCLR::GetCustomAttribute(void* klass, void* attribClass) { static void* GetCustomAttributePtr = CoreCLR::GetStaticMethodPointer(TEXT("GetCustomAttribute")); return CoreCLR::CallStaticMethod(GetCustomAttributePtr, ((CoreCLRClass*)klass)->GetTypeHandle(), ((CoreCLRClass*)attribClass)->GetTypeHandle()); } -Array CoreCLR::GetCustomAttributes(void* klass) + +Array CoreCLR::GetCustomAttributes(void* klass) { - Array attribs = ((CoreCLRClass*)klass)->GetCustomAttributes(); - - Array attributes; + const Array& attribs = ((CoreCLRClass*)klass)->GetCustomAttributes(); + Array attributes; attributes.Resize(attribs.Count(), false); - for (int i = 0; i < attribs.Count(); i++) - attributes.Add(attribs[i]->GetHandle()); - + for (int32 i = 0; i < attribs.Count(); i++) + attributes.Add((MObject*)attribs[i]->GetHandle()); return attributes; } @@ -1616,3 +1618,5 @@ MONO_API void mono_gc_finalize_notify(void) } #pragma warning(default : 4297) + +#endif diff --git a/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp b/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp index 3e636a65d..680da5ad6 100644 --- a/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp +++ b/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp @@ -6,6 +6,8 @@ #include "Engine/Scripting/MException.h" #include "Engine/Scripting/ManagedCLR/MUtils.h" +#if !COMPILE_WITHOUT_CSHARP + namespace UtilsInternal { MonoObject* ExtractArrayFromList(MonoObject* obj) @@ -84,6 +86,8 @@ namespace FlaxLogWriterInternal } } +#endif + void registerFlaxEngineInternalCalls() { AnimGraphExecutor::initRuntime(); diff --git a/Source/Engine/Scripting/ManagedCLR/MClass.cpp b/Source/Engine/Scripting/ManagedCLR/MClass.cpp index 9475e78d6..1d348f9c1 100644 --- a/Source/Engine/Scripting/ManagedCLR/MClass.cpp +++ b/Source/Engine/Scripting/ManagedCLR/MClass.cpp @@ -336,7 +336,6 @@ const Array& MClass::GetProperties() { if (_hasCachedProperties) return _properties; - #if USE_MONO void* iter = nullptr; MonoProperty* curClassProperty; @@ -346,7 +345,6 @@ const Array& MClass::GetProperties() GetProperty(propertyName); } #endif - _hasCachedProperties = true; return _properties; } @@ -416,10 +414,9 @@ const Array& MClass::GetAttributes() { if (_hasCachedAttributes) return _attributes; - _hasCachedAttributes = true; #if USE_NETCORE - _attributes = *(Array*)(&CoreCLR::GetCustomAttributes(_monoClass)); + _attributes = MoveTemp(CoreCLR::GetCustomAttributes(_monoClass)); #elif USE_MONO MonoCustomAttrInfo* attrInfo = GET_CUSTOM_ATTR(); if (attrInfo == nullptr) diff --git a/Source/Engine/Scripting/ManagedCLR/MUtils.h b/Source/Engine/Scripting/ManagedCLR/MUtils.h index a100cce9f..1181e7a5a 100644 --- a/Source/Engine/Scripting/ManagedCLR/MUtils.h +++ b/Source/Engine/Scripting/ManagedCLR/MUtils.h @@ -16,10 +16,11 @@ #if USE_NETCORE #include "Engine/Scripting/DotNet/CoreCLR.h" -#include "Engine/Core/Collections/BitArray.h" #endif struct Version; +template +class BitArray; namespace MUtils { @@ -612,13 +613,25 @@ namespace MUtils /// /// The input data. /// The output array. - FORCE_INLINE bool* ToBoolArray(const BitArray<>& data) + template + FORCE_INLINE bool* ToBoolArray(const BitArray& data) { bool* arr = (bool*)CoreCLR::Allocate(data.Count() * sizeof(bool)); for (int i = 0; i < data.Count(); i++) arr[i] = data[i]; return arr; } +#else + FORCE_INLINE bool* ToBoolArray(const Array& data) + { + return nullptr; + } + + template + FORCE_INLINE bool* ToBoolArray(const BitArray& data) + { + return nullptr; + } #endif FORCE_INLINE MGCHandle NewGCHandle(MonoObject* obj, bool pinned) @@ -635,7 +648,7 @@ namespace MUtils #if USE_NETCORE return CoreCLR::NewGCHandleWeakref(obj, track_resurrection); #else - return mono_gchandle_new_weak_ref(obj, track_resurrection); + return mono_gchandle_new_weakref(obj, track_resurrection); #endif } diff --git a/Source/Engine/Scripting/Scripting.Build.cs b/Source/Engine/Scripting/Scripting.Build.cs index 2acb906d7..c96f47268 100644 --- a/Source/Engine/Scripting/Scripting.Build.cs +++ b/Source/Engine/Scripting/Scripting.Build.cs @@ -15,7 +15,7 @@ public class Scripting : EngineModule if (EngineConfiguration.WithCSharp(options)) { - if (EngineConfiguration.UseDotNet) + if (EngineConfiguration.WithDotNet(options)) options.PublicDependencies.Add("nethost"); else options.PublicDependencies.Add("mono"); diff --git a/Source/Engine/Scripting/Types.h b/Source/Engine/Scripting/Types.h index d59bb33e2..38e25de98 100644 --- a/Source/Engine/Scripting/Types.h +++ b/Source/Engine/Scripting/Types.h @@ -27,11 +27,16 @@ class MType; #define USE_MONO 0 #define USE_NETCORE 0 typedef void MObject; +typedef unsigned int MGCHandle; #else #define USE_MONO 1 +#if COMPILE_WITH_MONO +#define USE_NETCORE 0 +#else #define USE_NETCORE 1 +#endif // Enables using single (root) app domain for the user scripts #define USE_SCRIPTING_SINGLE_DOMAIN 1 @@ -42,7 +47,7 @@ typedef void MObject; #define USE_MONO_PROFILER (COMPILE_WITH_PROFILER) // Enable/disable mono debugging -#define MONO_DEBUG_ENABLE (!BUILD_RELEASE && !USE_MONO) +#define MONO_DEBUG_ENABLE (!BUILD_RELEASE && !USE_NETCORE) #ifndef USE_MONO_AOT #define USE_MONO_AOT 0 @@ -57,7 +62,7 @@ struct _MonoThread {}; #if USE_NETCORE typedef unsigned long long MGCHandle; #else -typedef uint32 MGCHandle; +typedef unsigned int MGCHandle; #endif // Mono types declarations diff --git a/Source/ThirdParty/nethost/nethost.Build.cs b/Source/ThirdParty/nethost/nethost.Build.cs index 383153477..fb425a3c0 100644 --- a/Source/ThirdParty/nethost/nethost.Build.cs +++ b/Source/ThirdParty/nethost/nethost.Build.cs @@ -8,7 +8,7 @@ using Microsoft.Win32; using System.Linq; /// -/// Module for nethost (.NET runtime host library) +/// Module for nethost (.NET runtime host library). /// public class nethost : ThirdPartyModule { @@ -24,19 +24,6 @@ public class nethost : ThirdPartyModule BinaryModuleName = "FlaxEngine"; } - private static Version ParseVersion(string version) - { - // Give precedence to final releases over release candidate / beta releases - int rev = 9999; - if (version.Contains("-")) // e.g. 7.0.0-rc.2.22472.3 - { - version = version.Substring(0, version.IndexOf("-")); - rev = 0; - } - Version ver = new Version(version); - return new Version(ver.Major, ver.Minor, ver.Build, rev); - } - /// public override void Setup(BuildOptions options) { diff --git a/Source/Tools/Flax.Build/Build/ProjectTarget.cs b/Source/Tools/Flax.Build/Build/ProjectTarget.cs index d0a212d9c..ff74c1ad3 100644 --- a/Source/Tools/Flax.Build/Build/ProjectTarget.cs +++ b/Source/Tools/Flax.Build/Build/ProjectTarget.cs @@ -71,6 +71,10 @@ namespace Flax.Build { options.CompileEnv.PreprocessorDefinitions.Add("COMPILE_WITHOUT_CSHARP"); } + else if (!EngineConfiguration.WithDotNet(options)) + { + options.CompileEnv.PreprocessorDefinitions.Add("COMPILE_WITH_MONO"); + } if (EngineConfiguration.WithLargeWorlds(options)) { options.CompileEnv.PreprocessorDefinitions.Add("USE_LARGE_WORLDS"); diff --git a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs index 2904b89a7..301d9c510 100644 --- a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs @@ -95,6 +95,7 @@ namespace Flax.Build.Platforms args.Add("-pthread"); args.Add("-ldl"); args.Add("-lrt"); + args.Add("-lz"); // Link X11 args.Add("-L/usr/X11R6/lib");