Skip to content

Commit

Permalink
chore: Update unity plugin to work with Ecsact changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelwan committed Jun 28, 2024
1 parent e0d4fbd commit c21cac1
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Editor/EcsactPackagesPostprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ List<MovedPkg> movedPkgs

var settings = EcsactSettings.GetOrCreateSettings();

if(settings.runtimeBuilderEnabled) {
if(settings.ecsactBuildEnabled) {
EcsactRuntimeBuilder.Build(new EcsactRuntimeBuilder.Options {
ecsactFiles = packages.Select(item => item.Item2).ToList(),
});
Expand Down
35 changes: 23 additions & 12 deletions Editor/EcsactRuntimeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using Ecsact.Editor;
using UnityEngine.Rendering;

#nullable enable

Expand Down Expand Up @@ -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");

Expand All @@ -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;
Expand All @@ -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<MessageBase>(line);
switch(baseMessage.type) {
case AlertMessage.type:
Expand Down Expand Up @@ -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 +=
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -368,7 +379,7 @@ ModuleMethodsMessage message
UnityEngine.Debug.LogWarning(
$"Old method '{methodName}' should be <color=red>removed</color> " +
$"from module <b>{message.module_name}</b>. It no longer exists. " +
"(reported by ecsact_rtb)"
"(reported by ecsact build)"
);
}
}
Expand All @@ -378,7 +389,7 @@ ModuleMethodsMessage message
if(!methods.Contains(methodName)) {
UnityEngine.Debug.LogWarning(
$"New method '{methodName}' should be <color=green>added</color> " +
$"to module <b>{message.module_name}</b>. (reported by ecsact_rtb)"
$"to module <b>{message.module_name}</b>. (reported by ecsact build)"
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion Editor/EcsactRuntimeBuilderSettings.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
<ui:Label text="Assets/Plugins/EcsactRuntime" display-tooltip-when-elided="true" binding-path="runtimeBuilderOutputPath" style="padding-left: 160px; font-size: 10px; color: rgba(210, 210, 210, 0.47); padding-right: 0;" />
<ui:Label text=".wasm" display-tooltip-when-elided="true" style="font-size: 10px; color: rgba(210, 210, 210, 0.47); padding-left: 0;" />
</ui:VisualElement>
<ui:Toggle label="Debug Runtime Build" binding-path="runtimeBuilderDebugBuild" />
<ui:Toggle label="Debug" binding-path="runtimeBuilderDebugBuild" />
<ui:Toggle label="Log Stderr" binding-path="runtimeBuilderPrintSubcommandStderr" />
<ui:Toggle label="Log Stdout" binding-path="runtimeBuilderPrintSubcommandStdout" />
<ui:TextField picking-mode="Ignore" label="Compiler Path" multiline="false" binding-path="runtimeBuilderCompilerPath" />
<ui:TextField picking-mode="Ignore" label="Recipe Path" binding-path="recipePath" />
<ui:TextField picking-mode="Ignore" label="Temp Directory" multiline="false" binding-path="runtimeBuilderTempDirectory" />
</ui:VisualElement>
</ui:UXML>
6 changes: 3 additions & 3 deletions Editor/EcsactRuntimeSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
);
Expand Down
11 changes: 6 additions & 5 deletions Editor/EcsactSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ 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;
public bool runtimeBuilderPrintSubcommandStdout = false;
public bool runtimeBuilderPrintSubcommandStderr = false;

public string runtimeBuilderCompilerPath = "";
public string recipePath = "";

static EcsactSettings() {
EcsactRuntimeSettings.editorValidateEvent += OnRuntimeSettingsValidate;
Expand Down Expand Up @@ -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] = "";
Expand All @@ -66,7 +67,7 @@ void OnValidate() {
rtSettings.runtimeLibraryPaths.Add("");
}

if(runtimeBuilderEnabled) {
if(ecsactBuildEnabled) {
rtSettings.runtimeLibraryPaths[0] = runtimeBuilderOutputPath;
} else {
rtSettings.runtimeLibraryPaths[0] = "";
Expand Down Expand Up @@ -270,9 +271,9 @@ VisualElement rootElement

var builderSettingsElement =
ui.Q<TemplateContainer>("EcsactRuntimeBuilderSettings");
var rtbEnableToggle = ui.Q<Toggle>("EnableRTB");
var ecsactBuildToggle = ui.Q<Toggle>("EnableEcsactBuild");

rtbEnableToggle.RegisterValueChangedCallback(evt => {
ecsactBuildToggle.RegisterValueChangedCallback(evt => {
if(evt.newValue) {
builderSettingsElement.style.display = DisplayStyle.Flex;
} else {
Expand Down
4 changes: 2 additions & 2 deletions Editor/EcsactSettings.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<ui:Template name="EcsactRuntimeMethodLoadedUI" src="project://database/Packages/dev.ecsact.unity/Editor/EcsactRuntimeMethodLoadedUI.uxml?fileID=9197481963319205126&amp;guid=a2a638a8b49ec24468a126f89d509035&amp;type=3#EcsactRuntimeMethodLoadedUI" />
<ui:ScrollView>
<ui:GroupBox>
<ui:Label text="Runtime Builder Settings" display-tooltip-when-elided="true" style="font-size: 16px; -unity-font-style: bold;" />
<ui:Toggle label="Enable RTB" value="false" name="EnableRTB" binding-path="runtimeBuilderEnabled" />
<ui:Label text="Ecsact Build Settings" display-tooltip-when-elided="true" style="font-size: 16px; -unity-font-style: bold;" />
<ui:Toggle label="Enable Ecsact Build" value="false" name="EnableEcsactBuild" binding-path="ecsactBuildEnabled" />
<ui:Instance template="EcsactRuntimeBuilderSettings" name="EcsactRuntimeBuilderSettings" style="visibility: visible;" />
</ui:GroupBox>
<ui:GroupBox>
Expand Down
4 changes: 4 additions & 0 deletions Runtime/EcsactExecutionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public BuilderEntity AddComponent<C>(C component)
private List<Int32> adds_entities;
private List<EcsactRuntime.EcsactComponent> updates;
private List<Int32> updates_entities;
private List<IntPtr> updates__entities_indexes;
private List<EcsactRuntime.EcsactComponentId> removes;
private List<Int32> removes_entities;
private List<IntPtr> removes_entities_indexes;

public List<BuilderEntity> create_entities;
private List<List<EcsactRuntime.EcsactComponent>> create_entities_components;
Expand All @@ -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();
Expand Down
21 changes: 12 additions & 9 deletions Runtime/EcsactRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 "";
}

Expand Down Expand Up @@ -3013,13 +3018,10 @@ public static EcsactRuntime Load(IEnumerable<string> 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."
);
Expand Down Expand Up @@ -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."
);
}
}
Expand Down

0 comments on commit c21cac1

Please sign in to comment.