Skip to content

Commit a349096

Browse files
authored
chore: Update unity plugin to work with Ecsact changes (#97)
1 parent e0d4fbd commit a349096

12 files changed

+81
-52
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ jobs:
1414
name: Formatting Check
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- uses: ./.github/workflows/clang-format-action
17+
- uses: actions/checkout@v4
18+
- uses: greut/eclint-action@v0
19+
- uses: jidicula/[email protected]
20+
with: { clang-format-version: "18" }

Editor/EcsactPackagesPostprocessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ List<MovedPkg> movedPkgs
125125

126126
var settings = EcsactSettings.GetOrCreateSettings();
127127

128-
if(settings.runtimeBuilderEnabled) {
128+
if(settings.ecsactBuildEnabled) {
129129
EcsactRuntimeBuilder.Build(new EcsactRuntimeBuilder.Options {
130130
ecsactFiles = packages.Select(item => item.Item2).ToList(),
131131
});

Editor/EcsactRuntimeBuilder.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using Ecsact.Editor;
8+
using UnityEngine.Rendering;
89

910
#nullable enable
1011

@@ -129,8 +130,7 @@ public static void Build(Options options) {
129130

130131
_rtSettings = EcsactRuntimeSettings.Get();
131132

132-
string runtimeBuilderExecutablePath =
133-
EcsactSdk.FindExecutable("ecsact_rtb");
133+
string runtimeBuilderExecutablePath = EcsactSdk.FindExecutable("ecsact");
134134

135135
var progressId = Progress.Start("Ecsact Runtime Builder");
136136

@@ -139,7 +139,7 @@ public static void Build(Options options) {
139139
proc.StartInfo.CreateNoWindow = true;
140140
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
141141
proc.EnableRaisingEvents = true;
142-
proc.StartInfo.Arguments = "";
142+
proc.StartInfo.Arguments = "build ";
143143
proc.StartInfo.RedirectStandardError = true;
144144
proc.StartInfo.RedirectStandardOutput = true;
145145
proc.StartInfo.UseShellExecute = false;
@@ -262,13 +262,7 @@ public static void Build(Options options) {
262262
proc.StartInfo.Arguments += " --debug ";
263263
}
264264

265-
if(_rtSettings.systemImplSource == Ecsact.SystemImplSource.WebAssembly) {
266-
proc.StartInfo.Arguments += " --wasm=wasmer ";
267-
} else if(_rtSettings.systemImplSource == Ecsact.SystemImplSource.Csharp) {
268-
proc.StartInfo.Arguments += " --wasm=none ";
269-
}
270-
271-
proc.StartInfo.Arguments += " --report_format=json ";
265+
proc.StartInfo.Arguments += " --format=json ";
272266

273267
proc.StartInfo.Arguments += "--output=\"";
274268
proc.StartInfo.Arguments +=
@@ -301,6 +295,30 @@ public static void Build(Options options) {
301295
Path.GetFullPath(FileUtil.GetUniqueTempPathInProject());
302296
}
303297

298+
proc.StartInfo.Arguments += " ";
299+
proc.StartInfo.Arguments += "--recipe=\"";
300+
301+
if(_settings.ecsactBuildEnabled) {
302+
if(!string.IsNullOrEmpty(_settings.recipePath)) {
303+
var recipeFullPath = Path.GetFullPath(_settings.recipePath);
304+
proc.StartInfo.Arguments += recipeFullPath;
305+
proc.StartInfo.Arguments += "\" ";
306+
} else {
307+
UnityEngine.Debug.LogError(
308+
"A recipe path hasn't been given in Ecsact Build Settings"
309+
);
310+
}
311+
}
312+
313+
proc.Exited +=
314+
new System.EventHandler(delegate(object sender, System.EventArgs e) {
315+
if(proc.ExitCode != 0) {
316+
UnityEngine.Debug.Log("Ecsact build failed");
317+
} else {
318+
UnityEngine.Debug.Log("Ecsact build succeeded");
319+
}
320+
});
321+
304322
Progress.Report(progressId, 0.1f);
305323
proc.Start();
306324
proc.BeginOutputReadLine();
@@ -368,7 +386,7 @@ ModuleMethodsMessage message
368386
UnityEngine.Debug.LogWarning(
369387
$"Old method '{methodName}' should be <color=red>removed</color> " +
370388
$"from module <b>{message.module_name}</b>. It no longer exists. " +
371-
"(reported by ecsact_rtb)"
389+
"(reported by ecsact build)"
372390
);
373391
}
374392
}
@@ -378,7 +396,7 @@ ModuleMethodsMessage message
378396
if(!methods.Contains(methodName)) {
379397
UnityEngine.Debug.LogWarning(
380398
$"New method '{methodName}' should be <color=green>added</color> " +
381-
$"to module <b>{message.module_name}</b>. (reported by ecsact_rtb)"
399+
$"to module <b>{message.module_name}</b>. (reported by ecsact build)"
382400
);
383401
}
384402
}

Editor/EcsactRuntimeBuilderSettings.uxml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
<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;" />
1818
<ui:Label text=".wasm" display-tooltip-when-elided="true" style="font-size: 10px; color: rgba(210, 210, 210, 0.47); padding-left: 0;" />
1919
</ui:VisualElement>
20-
<ui:Toggle label="Debug Runtime Build" binding-path="runtimeBuilderDebugBuild" />
20+
<ui:Toggle label="Debug" binding-path="runtimeBuilderDebugBuild" />
2121
<ui:Toggle label="Log Stderr" binding-path="runtimeBuilderPrintSubcommandStderr" />
2222
<ui:Toggle label="Log Stdout" binding-path="runtimeBuilderPrintSubcommandStdout" />
2323
<ui:TextField picking-mode="Ignore" label="Compiler Path" multiline="false" binding-path="runtimeBuilderCompilerPath" />
24+
<ui:TextField picking-mode="Ignore" label="Recipe Path" binding-path="recipePath" />
2425
<ui:TextField picking-mode="Ignore" label="Temp Directory" multiline="false" binding-path="runtimeBuilderTempDirectory" />
2526
</ui:VisualElement>
2627
</ui:UXML>

Editor/EcsactRuntimeSettingsEditor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private void DrawRuntimeLibrariesList(EcsactRuntimeSettings settings) {
245245
);
246246

247247
if(foldoutLibraryPaths) {
248-
if(_ecsactSettings!.runtimeBuilderEnabled) {
248+
if(_ecsactSettings!.ecsactBuildEnabled) {
249249
EditorGUI.BeginDisabledGroup(true);
250250
DrawRuntimeLibraryPath(settings, 0);
251251
EditorGUI.EndDisabledGroup();
@@ -363,8 +363,8 @@ private void DrawUnitySyncScriptsGUI(EcsactRuntimeSettings settings) {
363363
} else if(potentialUnitySyncTypes.Count == 0) {
364364
EditorGUILayout.HelpBox(
365365
"No ecsact unity sync scripts found in project. Create a " +
366-
"MonoBehaviour with one or more of the Ecsact.UnitySync interfaces - " +
367-
"IRequired<>, IOnInitComponent<>, IOnUpdateComponent<>, or " +
366+
"MonoBehaviour with one or more of the Ecsact.UnitySync interfaces " +
367+
"- " + "IRequired<>, IOnInitComponent<>, IOnUpdateComponent<>, or " +
368368
"IOnRemoveComponent<>.",
369369
type: MessageType.Warning
370370
);

Editor/EcsactSettings.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ class EcsactSettings : ScriptableObject {
1414
public const string path = "Project/Ecsact";
1515
public const SettingsScope scope = SettingsScope.Project;
1616

17-
public bool runtimeBuilderEnabled = true;
17+
public bool ecsactBuildEnabled = true;
1818
public string runtimeBuilderOutputPath = "Assets/Plugins/EcsactRuntime";
1919
public string runtimeBuilderTempDirectory = "";
2020
public bool runtimeBuilderDebugBuild = false;
2121
public bool runtimeBuilderPrintSubcommandStdout = false;
2222
public bool runtimeBuilderPrintSubcommandStderr = false;
2323

2424
public string runtimeBuilderCompilerPath = "";
25+
public string recipePath = "";
2526

2627
static EcsactSettings() {
2728
EcsactRuntimeSettings.editorValidateEvent += OnRuntimeSettingsValidate;
@@ -53,7 +54,7 @@ static void OnRuntimeSettingsValidate(EcsactRuntimeSettings rtSettings) {
5354
rtSettings.runtimeLibraryPaths.Add("");
5455
}
5556

56-
if(settings.runtimeBuilderEnabled) {
57+
if(settings.ecsactBuildEnabled) {
5758
rtSettings.runtimeLibraryPaths[0] = settings.runtimeBuilderOutputPath;
5859
} else {
5960
rtSettings.runtimeLibraryPaths[0] = "";
@@ -66,7 +67,7 @@ void OnValidate() {
6667
rtSettings.runtimeLibraryPaths.Add("");
6768
}
6869

69-
if(runtimeBuilderEnabled) {
70+
if(ecsactBuildEnabled) {
7071
rtSettings.runtimeLibraryPaths[0] = runtimeBuilderOutputPath;
7172
} else {
7273
rtSettings.runtimeLibraryPaths[0] = "";
@@ -270,9 +271,9 @@ VisualElement rootElement
270271

271272
var builderSettingsElement =
272273
ui.Q<TemplateContainer>("EcsactRuntimeBuilderSettings");
273-
var rtbEnableToggle = ui.Q<Toggle>("EnableRTB");
274+
var ecsactBuildToggle = ui.Q<Toggle>("EnableEcsactBuild");
274275

275-
rtbEnableToggle.RegisterValueChangedCallback(evt => {
276+
ecsactBuildToggle.RegisterValueChangedCallback(evt => {
276277
if(evt.newValue) {
277278
builderSettingsElement.style.display = DisplayStyle.Flex;
278279
} else {

Editor/EcsactSettings.uxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<ui:Template name="EcsactRuntimeMethodLoadedUI" src="project://database/Packages/dev.ecsact.unity/Editor/EcsactRuntimeMethodLoadedUI.uxml?fileID=9197481963319205126&amp;guid=a2a638a8b49ec24468a126f89d509035&amp;type=3#EcsactRuntimeMethodLoadedUI" />
44
<ui:ScrollView>
55
<ui:GroupBox>
6-
<ui:Label text="Runtime Builder Settings" display-tooltip-when-elided="true" style="font-size: 16px; -unity-font-style: bold;" />
7-
<ui:Toggle label="Enable RTB" value="false" name="EnableRTB" binding-path="runtimeBuilderEnabled" />
6+
<ui:Label text="Ecsact Build Settings" display-tooltip-when-elided="true" style="font-size: 16px; -unity-font-style: bold;" />
7+
<ui:Toggle label="Enable Ecsact Build" value="false" name="EnableEcsactBuild" binding-path="ecsactBuildEnabled" />
88
<ui:Instance template="EcsactRuntimeBuilderSettings" name="EcsactRuntimeBuilderSettings" style="visibility: visible;" />
99
</ui:GroupBox>
1010
<ui:GroupBox>

Runtime/EcsactDefaults.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ namespace Ecsact {
99

1010
static public class Defaults {
1111
internal static EcsactRuntime? _Runtime;
12-
public static EcsactRuntime Runtime =>
13-
_Runtime ??
14-
throw new Exception(
15-
"Runtime is null, if you want to access it as early as possible " +
16-
"use Ecsact.Defaults.WhenReady"
17-
);
12+
public static EcsactRuntime Runtime => _Runtime ??
13+
throw new Exception("Runtime is null, if you want to access it as early " +
14+
"as possible " +
15+
"use Ecsact.Defaults.WhenReady");
1816
internal static Ecsact.Registry? _Registry;
19-
public static Ecsact.Registry Registry =>
20-
_Registry ??
21-
throw new Exception(
22-
"Registry is null, if you want to access it as early as possible " +
23-
"use Ecsact.Defaults.WhenReady"
24-
);
17+
public static Ecsact.Registry Registry => _Registry ??
18+
throw new Exception("Registry is null, if you want to access it as early " +
19+
"as possible " +
20+
"use Ecsact.Defaults.WhenReady");
2521
public static Ecsact.UnitySync.EntityGameObjectPool? Pool;
2622
public static EcsactRunner? Runner;
2723

Runtime/EcsactExecutionOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public BuilderEntity AddComponent<C>(C component)
2323
private List<Int32> adds_entities;
2424
private List<EcsactRuntime.EcsactComponent> updates;
2525
private List<Int32> updates_entities;
26+
private List<IntPtr> updates_entities_indexes;
2627
private List<EcsactRuntime.EcsactComponentId> removes;
2728
private List<Int32> removes_entities;
29+
private List<IntPtr> removes_entities_indexes;
2830

2931
public List<BuilderEntity> create_entities;
3032
private List<List<EcsactRuntime.EcsactComponent>> create_entities_components;
@@ -40,8 +42,10 @@ internal ExecutionOptions() {
4042
adds_entities = new();
4143
updates = new();
4244
updates_entities = new();
45+
updates_entities_indexes = new();
4346
removes = new();
4447
removes_entities = new();
48+
removes_entities_indexes = new();
4549
executionOptions = new();
4650
create_entities = new();
4751
create_entities_components = new();

Runtime/EcsactRuntime.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,16 @@ public struct CExecutionOptions {
267267
public Int32[] updateComponentsEntities;
268268
[MarshalAs(UnmanagedType.LPArray)]
269269
public EcsactComponent[] updateComponents;
270+
[MarshalAs(UnmanagedType.LPArray)]
271+
public IntPtr[] updateComponentsIndexes;
270272

271273
public Int32 removeComponentsLength;
272274
[MarshalAs(UnmanagedType.LPArray)]
273275
public Int32[] removeComponentsEntities;
274276
[MarshalAs(UnmanagedType.LPArray)]
275277
public EcsactComponentId[] removeComponents;
278+
[MarshalAs(UnmanagedType.LPArray)]
279+
public IntPtr[] removeComponentsIndexes;
276280

277281
public Int32 actionsLength;
278282
[MarshalAs(UnmanagedType.LPArray)]
@@ -2306,7 +2310,8 @@ IntPtr userData
23062310
);
23072311

23082312
private string LastErrorMessage() {
2309-
if(ecsactsi_wasm_last_error_message == null || ecsactsi_wasm_last_error_message_length == null) {
2313+
if(ecsactsi_wasm_last_error_message == null ||
2314+
ecsactsi_wasm_last_error_message_length == null) {
23102315
return "";
23112316
}
23122317

@@ -3013,13 +3018,10 @@ public static EcsactRuntime Load(IEnumerable<string> libraryPaths) {
30133018
}
30143019

30153020
public static void Free(EcsactRuntime runtime) {
3016-
if(runtime._core == null &&
3017-
runtime._async == null &&
3018-
runtime._dynamic == null &&
3019-
runtime._meta == null &&
3020-
runtime._serialize == null &&
3021-
runtime._static == null &&
3022-
runtime._wasm == null) {
3021+
if(runtime._core == null && runtime._async == null &&
3022+
runtime._dynamic == null && runtime._meta == null &&
3023+
runtime._serialize == null && runtime._static == null &&
3024+
runtime._wasm == null) {
30233025
UnityEngine.Debug.LogError(
30243026
"Ecsact Runtime attempted to be freed multiple times."
30253027
);
@@ -3067,7 +3069,8 @@ public static void Free(EcsactRuntime runtime) {
30673069
runtime._wasm.ecsactsi_wasm_reset();
30683070
} else {
30693071
UnityEngine.Debug.LogWarning(
3070-
"ecsactsi_wasm_reset method unavailable. Unity may become unstable after unloading the Ecsact runtime."
3072+
"ecsactsi_wasm_reset method unavailable. Unity may become " +
3073+
"unstable after unloading the Ecsact runtime."
30713074
);
30723075
}
30733076
}

0 commit comments

Comments
 (0)