From c21cac19f28118cff020a0bb22531dcfb5a5ad54 Mon Sep 17 00:00:00 2001 From: Kelwan Date: Fri, 28 Jun 2024 16:24:57 -0700 Subject: [PATCH] chore: Update unity plugin to work with Ecsact changes --- Editor/EcsactPackagesPostprocessor.cs | 2 +- Editor/EcsactRuntimeBuilder.cs | 35 ++++++++++++++++-------- Editor/EcsactRuntimeBuilderSettings.uxml | 3 +- Editor/EcsactRuntimeSettingsEditor.cs | 6 ++-- Editor/EcsactSettings.cs | 11 ++++---- Editor/EcsactSettings.uxml | 4 +-- Runtime/EcsactExecutionOptions.cs | 4 +++ Runtime/EcsactRuntime.cs | 21 ++++++++------ 8 files changed, 53 insertions(+), 33 deletions(-) diff --git a/Editor/EcsactPackagesPostprocessor.cs b/Editor/EcsactPackagesPostprocessor.cs index 761352d..c7ea552 100644 --- a/Editor/EcsactPackagesPostprocessor.cs +++ b/Editor/EcsactPackagesPostprocessor.cs @@ -125,7 +125,7 @@ List movedPkgs var settings = EcsactSettings.GetOrCreateSettings(); - if(settings.runtimeBuilderEnabled) { + if(settings.ecsactBuildEnabled) { EcsactRuntimeBuilder.Build(new EcsactRuntimeBuilder.Options { ecsactFiles = packages.Select(item => item.Item2).ToList(), }); diff --git a/Editor/EcsactRuntimeBuilder.cs b/Editor/EcsactRuntimeBuilder.cs index b20f78c..f343871 100644 --- a/Editor/EcsactRuntimeBuilder.cs +++ b/Editor/EcsactRuntimeBuilder.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using Ecsact.Editor; +using UnityEngine.Rendering; #nullable enable @@ -129,8 +130,7 @@ public static void Build(Options options) { _rtSettings = EcsactRuntimeSettings.Get(); - string runtimeBuilderExecutablePath = - EcsactSdk.FindExecutable("ecsact_rtb"); + string runtimeBuilderExecutablePath = EcsactSdk.FindExecutable("ecsact"); var progressId = Progress.Start("Ecsact Runtime Builder"); @@ -139,7 +139,7 @@ public static void Build(Options options) { proc.StartInfo.CreateNoWindow = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.EnableRaisingEvents = true; - proc.StartInfo.Arguments = ""; + proc.StartInfo.Arguments = "build "; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; @@ -160,6 +160,7 @@ public static void Build(Options options) { try { var line = ev.Data; if(!string.IsNullOrWhiteSpace(line)) { + UnityEngine.Debug.Log("fromJSON: " + line); var baseMessage = JsonUtility.FromJson(line); switch(baseMessage.type) { case AlertMessage.type: @@ -262,13 +263,7 @@ public static void Build(Options options) { proc.StartInfo.Arguments += " --debug "; } - if(_rtSettings.systemImplSource == Ecsact.SystemImplSource.WebAssembly) { - proc.StartInfo.Arguments += " --wasm=wasmer "; - } else if(_rtSettings.systemImplSource == Ecsact.SystemImplSource.Csharp) { - proc.StartInfo.Arguments += " --wasm=none "; - } - - proc.StartInfo.Arguments += " --report_format=json "; + proc.StartInfo.Arguments += " --format=json "; proc.StartInfo.Arguments += "--output=\""; proc.StartInfo.Arguments += @@ -301,6 +296,22 @@ public static void Build(Options options) { Path.GetFullPath(FileUtil.GetUniqueTempPathInProject()); } + proc.StartInfo.Arguments += " "; + proc.StartInfo.Arguments += "--recipe=\""; + if(!string.IsNullOrEmpty(_settings.recipePath)) { + var recipeFullPath = Path.GetFullPath(_settings.recipePath); + proc.StartInfo.Arguments += recipeFullPath; + proc.StartInfo.Arguments += "\" "; + } else { + // Throw? bad? + } + UnityEngine.Debug.Log("passing in args: " + proc.StartInfo.Arguments); + + proc.Exited += + new System.EventHandler(delegate(object sender, System.EventArgs e) { + UnityEngine.Debug.Log("Process exited: " + proc.ExitCode); + }); + Progress.Report(progressId, 0.1f); proc.Start(); proc.BeginOutputReadLine(); @@ -368,7 +379,7 @@ ModuleMethodsMessage message UnityEngine.Debug.LogWarning( $"Old method '{methodName}' should be removed " + $"from module {message.module_name}. It no longer exists. " + - "(reported by ecsact_rtb)" + "(reported by ecsact build)" ); } } @@ -378,7 +389,7 @@ ModuleMethodsMessage message if(!methods.Contains(methodName)) { UnityEngine.Debug.LogWarning( $"New method '{methodName}' should be added " + - $"to module {message.module_name}. (reported by ecsact_rtb)" + $"to module {message.module_name}. (reported by ecsact build)" ); } } diff --git a/Editor/EcsactRuntimeBuilderSettings.uxml b/Editor/EcsactRuntimeBuilderSettings.uxml index ef716ab..f7d2aec 100644 --- a/Editor/EcsactRuntimeBuilderSettings.uxml +++ b/Editor/EcsactRuntimeBuilderSettings.uxml @@ -17,10 +17,11 @@ - + + diff --git a/Editor/EcsactRuntimeSettingsEditor.cs b/Editor/EcsactRuntimeSettingsEditor.cs index d924318..52a7afc 100644 --- a/Editor/EcsactRuntimeSettingsEditor.cs +++ b/Editor/EcsactRuntimeSettingsEditor.cs @@ -245,7 +245,7 @@ private void DrawRuntimeLibrariesList(EcsactRuntimeSettings settings) { ); if(foldoutLibraryPaths) { - if(_ecsactSettings!.runtimeBuilderEnabled) { + if(_ecsactSettings!.ecsactBuildEnabled) { EditorGUI.BeginDisabledGroup(true); DrawRuntimeLibraryPath(settings, 0); EditorGUI.EndDisabledGroup(); @@ -363,8 +363,8 @@ private void DrawUnitySyncScriptsGUI(EcsactRuntimeSettings settings) { } else if(potentialUnitySyncTypes.Count == 0) { EditorGUILayout.HelpBox( "No ecsact unity sync scripts found in project. Create a " + - "MonoBehaviour with one or more of the Ecsact.UnitySync interfaces - " + - "IRequired<>, IOnInitComponent<>, IOnUpdateComponent<>, or " + + "MonoBehaviour with one or more of the Ecsact.UnitySync interfaces " + + "- " + "IRequired<>, IOnInitComponent<>, IOnUpdateComponent<>, or " + "IOnRemoveComponent<>.", type: MessageType.Warning ); diff --git a/Editor/EcsactSettings.cs b/Editor/EcsactSettings.cs index 30e488f..0b1fa2a 100644 --- a/Editor/EcsactSettings.cs +++ b/Editor/EcsactSettings.cs @@ -14,7 +14,7 @@ class EcsactSettings : ScriptableObject { public const string path = "Project/Ecsact"; public const SettingsScope scope = SettingsScope.Project; - public bool runtimeBuilderEnabled = true; + public bool ecsactBuildEnabled = true; public string runtimeBuilderOutputPath = "Assets/Plugins/EcsactRuntime"; public string runtimeBuilderTempDirectory = ""; public bool runtimeBuilderDebugBuild = false; @@ -22,6 +22,7 @@ class EcsactSettings : ScriptableObject { public bool runtimeBuilderPrintSubcommandStderr = false; public string runtimeBuilderCompilerPath = ""; + public string recipePath = ""; static EcsactSettings() { EcsactRuntimeSettings.editorValidateEvent += OnRuntimeSettingsValidate; @@ -53,7 +54,7 @@ static void OnRuntimeSettingsValidate(EcsactRuntimeSettings rtSettings) { rtSettings.runtimeLibraryPaths.Add(""); } - if(settings.runtimeBuilderEnabled) { + if(settings.ecsactBuildEnabled) { rtSettings.runtimeLibraryPaths[0] = settings.runtimeBuilderOutputPath; } else { rtSettings.runtimeLibraryPaths[0] = ""; @@ -66,7 +67,7 @@ void OnValidate() { rtSettings.runtimeLibraryPaths.Add(""); } - if(runtimeBuilderEnabled) { + if(ecsactBuildEnabled) { rtSettings.runtimeLibraryPaths[0] = runtimeBuilderOutputPath; } else { rtSettings.runtimeLibraryPaths[0] = ""; @@ -270,9 +271,9 @@ VisualElement rootElement var builderSettingsElement = ui.Q("EcsactRuntimeBuilderSettings"); - var rtbEnableToggle = ui.Q("EnableRTB"); + var ecsactBuildToggle = ui.Q("EnableEcsactBuild"); - rtbEnableToggle.RegisterValueChangedCallback(evt => { + ecsactBuildToggle.RegisterValueChangedCallback(evt => { if(evt.newValue) { builderSettingsElement.style.display = DisplayStyle.Flex; } else { diff --git a/Editor/EcsactSettings.uxml b/Editor/EcsactSettings.uxml index 7819d70..5d3ad4a 100644 --- a/Editor/EcsactSettings.uxml +++ b/Editor/EcsactSettings.uxml @@ -3,8 +3,8 @@ - - + + diff --git a/Runtime/EcsactExecutionOptions.cs b/Runtime/EcsactExecutionOptions.cs index f0e8e4d..b41e1e3 100644 --- a/Runtime/EcsactExecutionOptions.cs +++ b/Runtime/EcsactExecutionOptions.cs @@ -23,8 +23,10 @@ public BuilderEntity AddComponent(C component) private List adds_entities; private List updates; private List updates_entities; + private List updates__entities_indexes; private List removes; private List removes_entities; + private List removes_entities_indexes; public List create_entities; private List> create_entities_components; @@ -40,8 +42,10 @@ internal ExecutionOptions() { adds_entities = new(); updates = new(); updates_entities = new(); + updates__entities_indexes = new(); removes = new(); removes_entities = new(); + removes_entities_indexes = new(); executionOptions = new(); create_entities = new(); create_entities_components = new(); diff --git a/Runtime/EcsactRuntime.cs b/Runtime/EcsactRuntime.cs index f6fb0c4..f678408 100644 --- a/Runtime/EcsactRuntime.cs +++ b/Runtime/EcsactRuntime.cs @@ -267,12 +267,16 @@ public struct CExecutionOptions { public Int32[] updateComponentsEntities; [MarshalAs(UnmanagedType.LPArray)] public EcsactComponent[] updateComponents; + [MarshalAs(UnmanagedType.LPArray)] + public IntPtr[] updateComponentsIndexes; public Int32 removeComponentsLength; [MarshalAs(UnmanagedType.LPArray)] public Int32[] removeComponentsEntities; [MarshalAs(UnmanagedType.LPArray)] public EcsactComponentId[] removeComponents; + [MarshalAs(UnmanagedType.LPArray)] + public IntPtr[] removeComponentsIndexes; public Int32 actionsLength; [MarshalAs(UnmanagedType.LPArray)] @@ -2306,7 +2310,8 @@ IntPtr userData ); private string LastErrorMessage() { - if(ecsactsi_wasm_last_error_message == null || ecsactsi_wasm_last_error_message_length == null) { + if(ecsactsi_wasm_last_error_message == null || + ecsactsi_wasm_last_error_message_length == null) { return ""; } @@ -3013,13 +3018,10 @@ public static EcsactRuntime Load(IEnumerable libraryPaths) { } public static void Free(EcsactRuntime runtime) { - if(runtime._core == null && - runtime._async == null && - runtime._dynamic == null && - runtime._meta == null && - runtime._serialize == null && - runtime._static == null && - runtime._wasm == null) { + if(runtime._core == null && runtime._async == null && + runtime._dynamic == null && runtime._meta == null && + runtime._serialize == null && runtime._static == null && + runtime._wasm == null) { UnityEngine.Debug.LogError( "Ecsact Runtime attempted to be freed multiple times." ); @@ -3067,7 +3069,8 @@ public static void Free(EcsactRuntime runtime) { runtime._wasm.ecsactsi_wasm_reset(); } else { UnityEngine.Debug.LogWarning( - "ecsactsi_wasm_reset method unavailable. Unity may become unstable after unloading the Ecsact runtime." + "ecsactsi_wasm_reset method unavailable. Unity may become " + + "unstable after unloading the Ecsact runtime." ); } }