Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update unity plugin to work with Ecsact changes #97

Merged
merged 4 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ jobs:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/clang-format-action
- uses: actions/checkout@v4
- uses: greut/eclint-action@v0
- uses: jidicula/clang-format-action@v4.11.0
with: { clang-format-version: "18" }
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
42 changes: 30 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 Down Expand Up @@ -262,13 +262,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 +295,30 @@ public static void Build(Options options) {
Path.GetFullPath(FileUtil.GetUniqueTempPathInProject());
}

proc.StartInfo.Arguments += " ";
proc.StartInfo.Arguments += "--recipe=\"";

if(_settings.ecsactBuildEnabled) {
if(!string.IsNullOrEmpty(_settings.recipePath)) {
var recipeFullPath = Path.GetFullPath(_settings.recipePath);
proc.StartInfo.Arguments += recipeFullPath;
proc.StartInfo.Arguments += "\" ";
} else {
UnityEngine.Debug.LogError(
"A recipe path hasn't been given in Ecsact Build Settings"
);
}
}

proc.Exited +=
new System.EventHandler(delegate(object sender, System.EventArgs e) {
if(proc.ExitCode != 0) {
UnityEngine.Debug.Log("Ecsact build failed");
} else {
UnityEngine.Debug.Log("Ecsact build succeeded");
}
});

Progress.Report(progressId, 0.1f);
proc.Start();
proc.BeginOutputReadLine();
Expand Down Expand Up @@ -368,7 +386,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 +396,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
20 changes: 8 additions & 12 deletions Runtime/EcsactDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ namespace Ecsact {

static public class Defaults {
internal static EcsactRuntime? _Runtime;
public static EcsactRuntime Runtime =>
_Runtime ??
throw new Exception(
"Runtime is null, if you want to access it as early as possible " +
"use Ecsact.Defaults.WhenReady"
);
public static EcsactRuntime Runtime => _Runtime ??
throw new Exception("Runtime is null, if you want to access it as early " +
"as possible " +
"use Ecsact.Defaults.WhenReady");
internal static Ecsact.Registry? _Registry;
public static Ecsact.Registry Registry =>
_Registry ??
throw new Exception(
"Registry is null, if you want to access it as early as possible " +
"use Ecsact.Defaults.WhenReady"
);
public static Ecsact.Registry Registry => _Registry ??
throw new Exception("Registry is null, if you want to access it as early " +
"as possible " +
"use Ecsact.Defaults.WhenReady");
public static Ecsact.UnitySync.EntityGameObjectPool? Pool;
public static EcsactRunner? Runner;

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
2 changes: 1 addition & 1 deletion Runtime/EntityGameObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public GameObject? rootGameObject {

private EntityGameObjectPool() {
entityComponentIds = new List<ComponentIdsList>();
entityGameObjects = new List<GameObject?>();
entityGameObjects = new List < GameObject ? > ();
}

void OnEnable() {
Expand Down
12 changes: 8 additions & 4 deletions Runtime/Internal/EcsactRuntimeDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ internal static void Setup() {
// If async no default available registry!
if(settings.runner == EcsactRuntimeSettings.RunnerType.AsyncRunner) {
cacheRegistry = new CacheRegistry(Ecsact.Defaults.Runtime, reg);
} else if(settings.runner == EcsactRuntimeSettings.RunnerType.DefaultRunner) {
} else if(settings.runner ==
EcsactRuntimeSettings.RunnerType.DefaultRunner) {
settings.defaultRegistry!.registryId = registry_id;

Ecsact.Defaults._Registry = reg;
Expand Down Expand Up @@ -104,15 +105,18 @@ private static void SetDefaultsRunner(EcsactRuntimeSettings settings) {
var defReg = settings.defaultRegistry;

if(settings.runner == EcsactRuntimeSettings.RunnerType.DefaultRunner) {
if(defReg.updateMethod == EcsactRuntimeDefaultRegistry.UpdateMethod.None) {
if(defReg.updateMethod ==
EcsactRuntimeDefaultRegistry.UpdateMethod.None) {
Ecsact.Defaults.Runner = null;
} else if(defReg.updateMethod == EcsactRuntimeDefaultRegistry.UpdateMethod.FixedUpdate) {
} else if(defReg.updateMethod ==
EcsactRuntimeDefaultRegistry.UpdateMethod.FixedUpdate) {
Ecsact.Defaults.Runner =
EcsactRunner.CreateInstance<DefaultFixedRunner>(
settings,
"Default Fixed Runner"
);
} else if(defReg.updateMethod == EcsactRuntimeDefaultRegistry.UpdateMethod.Update) {
} else if(defReg.updateMethod ==
EcsactRuntimeDefaultRegistry.UpdateMethod.Update) {
Ecsact.Defaults.Runner = EcsactRunner.CreateInstance<DefaultRunner>(
settings,
"Default Runner"
Expand Down