From a49228d0a9f7cf5b7c09fe379006b1a54ed350f2 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Sat, 1 Feb 2025 15:37:43 -0800 Subject: [PATCH 1/4] feat: implement new async session api --- Runtime/EcsactRuntime.cs | 811 ++++++++++++--------------------------- 1 file changed, 235 insertions(+), 576 deletions(-) diff --git a/Runtime/EcsactRuntime.cs b/Runtime/EcsactRuntime.cs index f678408..c0f2135 100644 --- a/Runtime/EcsactRuntime.cs +++ b/Runtime/EcsactRuntime.cs @@ -24,6 +24,12 @@ public enum ConnectState : Int32 { Connected, ConnectError, } + +public enum SessionEvent : Int32 { + Stopped = 0, + Pending = 1, + Start = 2, +} } public enum AsyncError : Int32 { @@ -33,6 +39,9 @@ public enum AsyncError : Int32 { ConnectionClosed, ExecutionMergeFailure, NotConnected, + Internal = 99, + CustomBegin = 100, + CustomEnd = 200, } public enum ecsact_exec_systems_error { @@ -796,37 +805,52 @@ public class ModuleBase { public class Async : ModuleBase { public static string[] methods => new string[] { - "ecsact_async_connect", - "ecsact_async_disconnect", - "ecsact_async_enqueue_execution_options", - "ecsact_async_get_current_tick", "ecsact_async_flush_events", + "ecsact_async_start", + "ecsact_async_stop", + "ecsact_async_stop_all", + "ecsact_async_force_reset", + "ecsact_async_get_current_tick", + "ecsact_async_stream", }; internal delegate void ecsact_async_enqueue_execute_options_delegate( + Int32 sessionId, CExecutionOptions executionOptions ); - - internal - ecsact_async_enqueue_execute_options_delegate? ecsact_async_enqueue_execution_options; + internal ecsact_async_enqueue_execute_options_delegate? ecsact_async_enqueue_execution_options; internal delegate void ecsact_async_flush_events_delegate( + Int32 sessionId, in ExecutionEventsCollector executionEventsCollector, in AsyncEventsCollector asyncEventsCollector ); internal ecsact_async_flush_events_delegate? ecsact_async_flush_events; - internal delegate Int32 ecsact_async_connect_delegate([ - MarshalAs(UnmanagedType.LPStr) - ] string connectionString); - internal ecsact_async_connect_delegate? ecsact_async_connect; + internal delegate Int32 ecsact_async_start_delegate(IntPtr data, Int32 dataLength); + internal ecsact_async_start_delegate? ecsact_async_start; - internal delegate void ecsact_async_disconnect_delegate(); - internal ecsact_async_disconnect_delegate? ecsact_async_disconnect; + internal delegate void ecsact_async_stop_delegate(Int32 SessionId); + internal ecsact_async_stop_delegate? ecsact_async_stop; + + internal delegate void ecsact_async_stop_all_delegate(); + internal ecsact_async_stop_all_delegate? ecsact_async_stop_all; + + internal delegate void ecsact_async_force_reset_delegate(); + internal ecsact_async_force_reset_delegate? ecsact_async_force_reset; + + internal delegate int ecsact_async_get_current_tick_delegate(Int32 sesssionId); + internal ecsact_async_get_current_tick_delegate? ecsact_async_get_current_tick; + + internal delegate void ecsact_async_stream_delegate( + Int32 sessionId, + Int32 entity, + Int32 componentId, + IntPtr componentData, + IntPtr indexedFieldValues + ); + internal ecsact_async_stream_delegate? ecsact_async_stream; - internal delegate int ecsact_async_get_current_tick_delegate(); - internal - ecsact_async_get_current_tick_delegate? ecsact_async_get_current_tick; public delegate void AsyncErrorCallback( Ecsact.AsyncError err, @@ -850,7 +874,6 @@ Int32 connectPort public delegate void ConnectStateChangeHandler( Ecsact.Async.ConnectState newState ); - private Int32? connectRequestId = null; public Ecsact.Async.ConnectState connectState { get; private set; } public event ConnectStateChangeHandler? connectStateChange; @@ -878,21 +901,6 @@ IntPtr callbackUserData self.connectState = Ecsact.Async.ConnectState.NotConnected; self.connectStateChange?.Invoke(self.connectState); } - if(self.connectRequestId.HasValue) { - var connectReqId = self.connectRequestId.Value; - for(int i = 0; requestIdsLength > i; ++i) { - if(connectReqId == requestIds[i]) { - self.connectRequestId = null; - self.connectState = Ecsact.Async.ConnectState.ConnectError; - try { - self.connectStateChange?.Invoke(self.connectState); - } catch(global::System.Exception e) { - UnityEngine.Debug.LogException(e); - } - break; - } - } - } foreach(var cb in self._errCallbacks) { cb(err, requestIds); @@ -923,21 +931,7 @@ public static void OnAsyncReqCompleteHandler( IntPtr callbackUserData ) { var self = (GCHandle.FromIntPtr(callbackUserData).Target as Async)!; - - if(self.connectRequestId.HasValue) { - var connectReqId = self.connectRequestId.Value; - for(int i = 0; requestIdsLength > i; ++i) { - if(connectReqId == requestIds[i]) { - self.connectState = Ecsact.Async.ConnectState.Connected; - self.connectStateChange?.Invoke(self.connectState); - break; - } - } - } - - // foreach(var cb in self._sysErrCallbacks) { - // cb(systemError); - // } + // TODO: report done requests } public Action OnSystemError(SystemErrorCallback callback) { @@ -947,50 +941,42 @@ public Action OnSystemError(SystemErrorCallback callback) { } /** - * + * Wrapper for `ecsact_async_start` */ - public void Connect(string connectionString) { - if(ecsact_async_connect == null) { - throw new EcsactRuntimeMissingMethod("ecsact_async_connect"); + public Int32 Start(byte[] optionData) { + if(ecsact_async_start == null) { + throw new EcsactRuntimeMissingMethod("ecsact_async_start"); } - if(connectRequestId.HasValue) { - Disconnect(); - } - - connectRequestId = ecsact_async_connect(connectionString); - connectState = Ecsact.Async.ConnectState.Loading; - connectStateChange?.Invoke(connectState); } - public void Disconnect() { - if(ecsact_async_disconnect == null) { - throw new EcsactRuntimeMissingMethod("ecsact_async_disconnect"); - } - if(connectRequestId.HasValue) { - ecsact_async_disconnect(); - connectRequestId = null; - connectState = Ecsact.Async.ConnectState.NotConnected; - connectStateChange?.Invoke(connectState); + /** + * Wrapper for `ecsact_async_stop` + */ + public void Stop(Int32 sessionId) { + if(ecsact_async_stop == null) { + throw new EcsactRuntimeMissingMethod("ecsact_async_stop"); } + + ecsact_async_stop(sessionId); } - public Int32 GetCurrentTick() { + public Int32 GetCurrentTick(Int32 sessionId) { if(ecsact_async_get_current_tick == null) { throw new EcsactRuntimeMissingMethod("ecsact_async_get_current_tick"); } - return ecsact_async_get_current_tick(); + return ecsact_async_get_current_tick(sessionId); } - public void EnqueueExecutionOptions(CExecutionOptions executionOptions) { + public void EnqueueExecutionOptions(Int32 sessionId, CExecutionOptions executionOptions) { if(ecsact_async_enqueue_execution_options == null) { throw new EcsactRuntimeMissingMethod( "ecsact_async_enqueue_execution_options" ); } - ecsact_async_enqueue_execution_options(executionOptions); + ecsact_async_enqueue_execution_options(sessionId, executionOptions); } - public void Flush() { + public void Flush(Int32 sessionId) { if(ecsact_async_flush_events == null) { throw new EcsactRuntimeMissingMethod("ecsact_async_flush_events"); } @@ -1010,7 +996,7 @@ public void Flush() { _asyncEvs.asyncExecErrorCallbackUserData = selfIntPtr; _asyncEvs.errorCallbackUserData = selfIntPtr; _asyncEvs.asyncReqCompleteCallbackUserData = selfIntPtr; - ecsact_async_flush_events(in _owner._execEvs, in _asyncEvs); + ecsact_async_flush_events(sessionId, in _owner._execEvs, in _asyncEvs); } finally { selfPinned.Free(); ownerPinned.Free(); @@ -1020,24 +1006,28 @@ public void Flush() { public class Core : ModuleBase { public static string[] methods => new string[] { - "ecsact_add_component", - "ecsact_clear_registry", - "ecsact_count_components", - "ecsact_count_entities", - "ecsact_create_entity", "ecsact_create_registry", - "ecsact_destroy_entity", "ecsact_destroy_registry", - "ecsact_each_component", + "ecsact_clone_registry", + "ecsact_hash_registry", + "ecsact_clear_registry", + "ecsact_create_entity", "ecsact_ensure_entity", "ecsact_entity_exists", - "ecsact_execute_systems", - "ecsact_get_component", - "ecsact_get_components", + "ecsact_destroy_entity", + "ecsact_count_entities", "ecsact_get_entities", + "ecsact_add_component", "ecsact_has_component", - "ecsact_remove_component", + "ecsact_get_component", + "ecsact_count_components", + "ecsact_get_components", + "ecsact_each_component", "ecsact_update_component", + "ecsact_remove_component", + "ecsact_execute_systems", + "ecsact_get_entity_execution_status", + "ecsact_stream", }; internal void AssertEntityExists(Int32 registryId, Int32 entityId) { @@ -1122,8 +1112,6 @@ internal enum ecsact_add_error { CONSTRAINT_BROKEN = 2 } - ; - internal delegate ecsact_add_error ecsact_add_component_delegate( Int32 registryId, Int32 entityId, @@ -2204,7 +2192,7 @@ StaticReloadCallback callback // TODO(zaucy): This is misplaced here. It should be organized somewhere else // maybe in another package - // ecsactsi_* fns + // ecsact_si_* fns public class Wasm : ModuleBase { public enum ErrorCode { Ok, @@ -2223,18 +2211,18 @@ public struct Error { } public static string[] methods => new string[] { - "ecsactsi_wasm_load", - "ecsactsi_wasm_load_file", - "ecsactsi_wasm_reset", - "ecsactsi_wasm_unload", - "ecsactsi_wasm_set_trap_handler", - "ecsactsi_wasm_last_error_message", - "ecsactsi_wasm_last_error_message_length", - "ecsactsi_wasm_consume_logs", - "ecsactsi_wasm_allow_file_read_access", + "ecsact_si_wasm_load", + "ecsact_si_wasm_load_file", + "ecsact_si_wasm_reset", + "ecsact_si_wasm_unload", + "ecsact_si_wasm_set_trap_handler", + "ecsact_si_wasm_last_error_message", + "ecsact_si_wasm_last_error_message_length", + "ecsact_si_wasm_consume_logs", + "ecsact_si_wasm_allow_file_read_access", }; - internal delegate ErrorCode ecsactsi_wasm_load_delegate( + internal delegate ErrorCode ecsact_si_wasm_load_delegate( sbyte[] wasmData, Int32 wasmDataSize, Int32 systemsCount, @@ -2242,59 +2230,59 @@ internal delegate ErrorCode ecsactsi_wasm_load_delegate( string[] wasmExports ); - internal ecsactsi_wasm_load_delegate? ecsactsi_wasm_load; + internal ecsact_si_wasm_load_delegate? ecsact_si_wasm_load; - internal delegate ErrorCode ecsactsi_wasm_load_file_delegate( + internal delegate ErrorCode ecsact_si_wasm_load_file_delegate( [MarshalAs(UnmanagedType.LPStr)] string wasmFilePath, Int32 systemsCount, Int32[] systmIds, string[] wasmExports ); - internal ecsactsi_wasm_load_file_delegate? ecsactsi_wasm_load_file; + internal ecsact_si_wasm_load_file_delegate? ecsact_si_wasm_load_file; - internal delegate void ecsactsi_wasm_unload_delegate( + internal delegate void ecsact_si_wasm_unload_delegate( Int32 systemsCount, Int32[] systemIds ); - internal ecsactsi_wasm_unload_delegate? ecsactsi_wasm_unload; + internal ecsact_si_wasm_unload_delegate? ecsact_si_wasm_unload; - internal delegate void ecsactsi_wasm_reset_delegate(); + internal delegate void ecsact_si_wasm_reset_delegate(); - internal ecsactsi_wasm_reset_delegate? ecsactsi_wasm_reset; + internal ecsact_si_wasm_reset_delegate? ecsact_si_wasm_reset; - internal delegate void ecsactsi_wasm_trap_handler(Int32 systemId, [ + internal delegate void ecsact_si_wasm_trap_handler(Int32 systemId, [ MarshalAs(UnmanagedType.LPStr) ] string trapMessage); - internal delegate void ecsactsi_wasm_set_trap_handler_delegate( - ecsactsi_wasm_trap_handler handler + internal delegate void ecsact_si_wasm_set_trap_handler_delegate( + ecsact_si_wasm_trap_handler handler ); internal - ecsactsi_wasm_set_trap_handler_delegate? ecsactsi_wasm_set_trap_handler; + ecsact_si_wasm_set_trap_handler_delegate? ecsact_si_wasm_set_trap_handler; - internal delegate Int32 ecsactsi_wasm_last_error_message_length_delegate(); + internal delegate Int32 ecsact_si_wasm_last_error_message_length_delegate(); internal - ecsactsi_wasm_last_error_message_length_delegate? ecsactsi_wasm_last_error_message_length; + ecsact_si_wasm_last_error_message_length_delegate? ecsact_si_wasm_last_error_message_length; - internal delegate void ecsactsi_wasm_last_error_message_delegate( + internal delegate void ecsact_si_wasm_last_error_message_delegate( IntPtr outMessage, Int32 outMessageMaxLength ); internal - ecsactsi_wasm_last_error_message_delegate? ecsactsi_wasm_last_error_message; + ecsact_si_wasm_last_error_message_delegate? ecsact_si_wasm_last_error_message; - internal delegate void ecsactsi_wasm_consume_logs_delegate( + internal delegate void ecsact_si_wasm_consume_logs_delegate( LogConsumer consumer, IntPtr userData ); - internal ecsactsi_wasm_consume_logs_delegate? ecsactsi_wasm_consume_logs; + internal ecsact_si_wasm_consume_logs_delegate? ecsact_si_wasm_consume_logs; - internal delegate void ecsactsi_wasm_allow_file_read_access_delegate(); + internal delegate void ecsact_si_wasm_allow_file_read_access_delegate(); internal - ecsactsi_wasm_allow_file_read_access_delegate? ecsactsi_wasm_allow_file_read_access; + ecsact_si_wasm_allow_file_read_access_delegate? ecsact_si_wasm_allow_file_read_access; internal enum LogLevel : Int32 { Info = 0, @@ -2310,12 +2298,12 @@ IntPtr userData ); private string LastErrorMessage() { - if(ecsactsi_wasm_last_error_message == null || - ecsactsi_wasm_last_error_message_length == null) { + if(ecsact_si_wasm_last_error_message == null || + ecsact_si_wasm_last_error_message_length == null) { return ""; } - var errMessageLength = ecsactsi_wasm_last_error_message_length(); + var errMessageLength = ecsact_si_wasm_last_error_message_length(); if(errMessageLength == 0) { return ""; } @@ -2325,7 +2313,7 @@ private string LastErrorMessage() { var errMessagePtr = Marshal.StringToHGlobalAnsi(errMessage); try { - ecsactsi_wasm_last_error_message(errMessagePtr, errMessageLength); + ecsact_si_wasm_last_error_message(errMessagePtr, errMessageLength); errMessage = Marshal.PtrToStringAnsi(errMessagePtr, errMessageLength); } finally { Marshal.FreeHGlobal(errMessagePtr); @@ -2338,15 +2326,15 @@ public Error LoadFile( Int32 systemId, string exportName ) { - if(ecsactsi_wasm_load_file == null) { - throw new EcsactRuntimeMissingMethod("ecsactsi_wasm_load_file"); + if(ecsact_si_wasm_load_file == null) { + throw new EcsactRuntimeMissingMethod("ecsact_si_wasm_load_file"); } var systemIds = new Int32[] { systemId }; var exportNames = new string[] { exportName }; var errCode = - ecsactsi_wasm_load_file(wasmFilePath, 1, systemIds, exportNames); + ecsact_si_wasm_load_file(wasmFilePath, 1, systemIds, exportNames); return new Error { code = errCode, @@ -2359,15 +2347,15 @@ public Error LoadFile( Int32[] systemIds, string[] exportNames ) { - if(ecsactsi_wasm_load_file == null) { - throw new EcsactRuntimeMissingMethod("ecsactsi_wasm_load_file"); + if(ecsact_si_wasm_load_file == null) { + throw new EcsactRuntimeMissingMethod("ecsact_si_wasm_load_file"); } if(systemIds.Length != exportNames.Length) { throw new Exception("System IDs and exportNames length do not match"); } - var errCode = ecsactsi_wasm_load_file( + var errCode = ecsact_si_wasm_load_file( wasmFilePath, systemIds.Length, systemIds, @@ -2386,15 +2374,15 @@ public Error Load( string[] exportNames ) { AssertPlayMode(); - if(ecsactsi_wasm_load == null) { - throw new EcsactRuntimeMissingMethod("ecsactsi_wasm_load"); + if(ecsact_si_wasm_load == null) { + throw new EcsactRuntimeMissingMethod("ecsact_si_wasm_load"); } if(systemIds.Length != exportNames.Length) { throw new Exception("System IDs and exportNames length do not match"); } - var errCode = ecsactsi_wasm_load( + var errCode = ecsact_si_wasm_load( (sbyte[])(Array)wasmData, wasmData.Length, systemIds.Length, @@ -2410,8 +2398,8 @@ string[] exportNames public Error Load(byte[] wasmData, Int32 systemId, string exportName) { AssertPlayMode(); - if(ecsactsi_wasm_load == null) { - throw new EcsactRuntimeMissingMethod("ecsactsi_wasm_load"); + if(ecsact_si_wasm_load == null) { + throw new EcsactRuntimeMissingMethod("ecsact_si_wasm_load"); } var systemIds = new Int32[] { systemId }; @@ -2422,33 +2410,33 @@ public Error Load(byte[] wasmData, Int32 systemId, string exportName) { void Unload(IEnumerable systemIds) { AssertPlayMode(); - if(ecsactsi_wasm_unload == null) { - throw new EcsactRuntimeMissingMethod("ecsactsi_wasm_unload"); + if(ecsact_si_wasm_unload == null) { + throw new EcsactRuntimeMissingMethod("ecsact_si_wasm_unload"); } Int32[] systemIdsArr = systemIds.ToArray(); - ecsactsi_wasm_unload(systemIdsArr.Count(), systemIdsArr); + ecsact_si_wasm_unload(systemIdsArr.Count(), systemIdsArr); } void Reset() { AssertPlayMode(); - if(ecsactsi_wasm_reset == null) { - throw new EcsactRuntimeMissingMethod("ecsactsi_wasm_reset"); + if(ecsact_si_wasm_reset == null) { + throw new EcsactRuntimeMissingMethod("ecsact_si_wasm_reset"); } - ecsactsi_wasm_reset(); + ecsact_si_wasm_reset(); } /// /// Convenience function to pipe Ecsact Wasm logs to the Unity logger /// public void PrintAndConsumeLogs() { - if(ecsactsi_wasm_consume_logs == null) { + if(ecsact_si_wasm_consume_logs == null) { return; } - ecsactsi_wasm_consume_logs(EcsactWasmUnityLoggerConsumer, IntPtr.Zero); + ecsact_si_wasm_consume_logs(EcsactWasmUnityLoggerConsumer, IntPtr.Zero); } [AOT.MonoPInvokeCallback(typeof(LogConsumer))] @@ -2526,7 +2514,7 @@ out D? nonStandardMethodDelegate return foundMethod; } - [AOT.MonoPInvokeCallback(typeof(Wasm.ecsactsi_wasm_trap_handler))] + [AOT.MonoPInvokeCallback(typeof(Wasm.ecsact_si_wasm_trap_handler))] private static void DefaultWasmTrapHandler(Int32 systemId, [ MarshalAs(UnmanagedType.LPStr) ] string trapMessage) { @@ -2587,431 +2575,99 @@ public static EcsactRuntime Load(IEnumerable libraryPaths) { libraryPaths.Select(path => NativeLibrary.Load(path)).ToArray(); foreach(var lib in runtime._libs) { + // clang-format off // Load async methods - LoadDelegate( - lib, - "ecsact_async_enqueue_execution_options", - out runtime._async.ecsact_async_enqueue_execution_options, - runtime._async - ); - LoadDelegate( - lib, - "ecsact_async_flush_events", - out runtime._async.ecsact_async_flush_events, - runtime._async - ); - LoadDelegate( - lib, - "ecsact_async_connect", - out runtime._async.ecsact_async_connect, - runtime._async - ); - LoadDelegate( - lib, - "ecsact_async_disconnect", - out runtime._async.ecsact_async_disconnect, - runtime._async - ); - LoadDelegate( - lib, - "ecsact_async_get_current_tick", - out runtime._async.ecsact_async_get_current_tick, - runtime._async - ); + LoadDelegate(lib, "ecsact_async_flush_events", out runtime._async.ecsact_async_flush_events, runtime._async); + LoadDelegate(lib, "ecsact_async_start", out runtime._async.ecsact_async_start, runtime._async); + LoadDelegate(lib, "ecsact_async_stop", out runtime._async.ecsact_async_stop, runtime._async); + LoadDelegate(lib, "ecsact_async_stop_all", out runtime._async.ecsact_async_stop_all, runtime._async); + LoadDelegate(lib, "ecsact_async_force_reset", out runtime._async.ecsact_async_force_reset, runtime._async); + LoadDelegate(lib, "ecsact_async_get_current_tick", out runtime._async.ecsact_async_get_current_tick, runtime._async); + LoadDelegate(lib, "ecsact_async_stream", out runtime._async.ecsact_async_stream, runtime._async); // Load core methods - LoadDelegate( - lib, - "ecsact_create_registry", - out runtime._core.ecsact_create_registry, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_destroy_registry", - out runtime._core.ecsact_destroy_registry, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_clear_registry", - out runtime._core.ecsact_clear_registry, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_create_entity", - out runtime._core.ecsact_create_entity, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_ensure_entity", - out runtime._core.ecsact_ensure_entity, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_entity_exists", - out runtime._core.ecsact_entity_exists, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_destroy_entity", - out runtime._core.ecsact_destroy_entity, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_count_entities", - out runtime._core.ecsact_count_entities, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_get_entities", - out runtime._core.ecsact_get_entities, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_add_component", - out runtime._core.ecsact_add_component, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_has_component", - out runtime._core.ecsact_has_component, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_get_component", - out runtime._core.ecsact_get_component, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_each_component", - out runtime._core.ecsact_each_component, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_count_components", - out runtime._core.ecsact_count_components, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_get_components", - out runtime._core.ecsact_get_components, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_update_component", - out runtime._core.ecsact_update_component, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_remove_component", - out runtime._core.ecsact_remove_component, - runtime._core - ); - LoadDelegate( - lib, - "ecsact_execute_systems", - out runtime._core.ecsact_execute_systems, - runtime._core - ); + LoadDelegate(lib, "ecsact_create_registry", out runtime._core.ecsact_create_registry, runtime._core); + LoadDelegate(lib, "ecsact_destroy_registry", out runtime._core.ecsact_destroy_registry, runtime._core); + LoadDelegate(lib, "ecsact_clone_registry", out runtime._core.ecsact_clone_registry, runtime._core); + LoadDelegate(lib, "ecsact_hash_registry", out runtime._core.ecsact_hash_registry, runtime._core); + LoadDelegate(lib, "ecsact_clear_registry", out runtime._core.ecsact_clear_registry, runtime._core); + LoadDelegate(lib, "ecsact_create_entity", out runtime._core.ecsact_create_entity, runtime._core); + LoadDelegate(lib, "ecsact_ensure_entity", out runtime._core.ecsact_ensure_entity, runtime._core); + LoadDelegate(lib, "ecsact_entity_exists", out runtime._core.ecsact_entity_exists, runtime._core); + LoadDelegate(lib, "ecsact_destroy_entity", out runtime._core.ecsact_destroy_entity, runtime._core); + LoadDelegate(lib, "ecsact_count_entities", out runtime._core.ecsact_count_entities, runtime._core); + LoadDelegate(lib, "ecsact_get_entities", out runtime._core.ecsact_get_entities, runtime._core); + LoadDelegate(lib, "ecsact_add_component", out runtime._core.ecsact_add_component, runtime._core); + LoadDelegate(lib, "ecsact_has_component", out runtime._core.ecsact_has_component, runtime._core); + LoadDelegate(lib, "ecsact_get_component", out runtime._core.ecsact_get_component, runtime._core); + LoadDelegate(lib, "ecsact_count_components", out runtime._core.ecsact_count_components, runtime._core); + LoadDelegate(lib, "ecsact_get_components", out runtime._core.ecsact_get_components, runtime._core); + LoadDelegate(lib, "ecsact_each_component", out runtime._core.ecsact_each_component, runtime._core); + LoadDelegate(lib, "ecsact_update_component", out runtime._core.ecsact_update_component, runtime._core); + LoadDelegate(lib, "ecsact_remove_component", out runtime._core.ecsact_remove_component, runtime._core); + LoadDelegate(lib, "ecsact_execute_systems", out runtime._core.ecsact_execute_systems, runtime._core); + LoadDelegate(lib, "ecsact_get_entity_execution_status", out runtime._core.ecsact_get_entity_execution_status, runtime._core); + LoadDelegate(lib, "ecsact_stream", out runtime._core.ecsact_stream, runtime._core); // Load dynamic methods - LoadDelegate( - lib, - "ecsact_system_execution_context_action", - out runtime._dynamic.ecsact_system_execution_context_action, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_add", - out runtime._dynamic.ecsact_system_execution_context_add, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_remove", - out runtime._dynamic.ecsact_system_execution_context_remove, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_update", - out runtime._dynamic.ecsact_system_execution_context_update, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_get", - out runtime._dynamic.ecsact_system_execution_context_get, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_has", - out runtime._dynamic.ecsact_system_execution_context_has, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_generate", - out runtime._dynamic.ecsact_system_execution_context_generate, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_parent", - out runtime._dynamic.ecsact_system_execution_context_parent, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_same", - out runtime._dynamic.ecsact_system_execution_context_same, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_entity", - out runtime._dynamic.ecsact_system_execution_context_entity, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_create_system", - out runtime._dynamic.ecsact_create_system, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_set_system_execution_impl", - out runtime._dynamic.ecsact_set_system_execution_impl, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_create_action", - out runtime._dynamic.ecsact_create_action, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_create_component", - out runtime._dynamic.ecsact_create_component, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_destroy_component", - out runtime._dynamic.ecsact_destroy_component, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_id", - out runtime._dynamic.ecsact_system_execution_context_id, - runtime._dynamic - ); - LoadDelegate( - lib, - "ecsact_system_execution_context_other", - out runtime._dynamic.ecsact_system_execution_context_other, - runtime._dynamic - ); + // NOTE: not all methods are here. + LoadDelegate(lib, "ecsact_system_execution_context_action", out runtime._dynamic.ecsact_system_execution_context_action, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_add", out runtime._dynamic.ecsact_system_execution_context_add, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_remove", out runtime._dynamic.ecsact_system_execution_context_remove, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_get", out runtime._dynamic.ecsact_system_execution_context_get, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_update", out runtime._dynamic.ecsact_system_execution_context_update, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_has", out runtime._dynamic.ecsact_system_execution_context_has, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_stream_toggle", out runtime._dynamic.ecsact_system_execution_context_stream_toggle, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_generate", out runtime._dynamic.ecsact_system_execution_context_generate, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_parent", out runtime._dynamic.ecsact_system_execution_context_parent, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_same", out runtime._dynamic.ecsact_system_execution_context_same, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_other", out runtime._dynamic.ecsact_system_execution_context_other, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_entity", out runtime._dynamic.ecsact_system_execution_context_entity, runtime._dynamic); + LoadDelegate(lib, "ecsact_system_execution_context_id", out runtime._dynamic.ecsact_system_execution_context_id, runtime._dynamic); + LoadDelegate(lib, "ecsact_set_system_execution_impl", out runtime._dynamic.ecsact_set_system_execution_impl, runtime._dynamic); // Load meta methods - LoadDelegate( - lib, - "ecsact_meta_registry_name", - out runtime._meta.ecsact_meta_registry_name, - runtime._meta - ); - LoadDelegate( - lib, - "ecsact_meta_component_name", - out runtime._meta.ecsact_meta_component_name, - runtime._meta - ); - LoadDelegate( - lib, - "ecsact_meta_action_name", - out runtime._meta.ecsact_meta_action_name, - runtime._meta - ); - LoadDelegate( - lib, - "ecsact_meta_system_name", - out runtime._meta.ecsact_meta_system_name, - runtime._meta - ); - LoadDelegate( - lib, - "ecsact_meta_system_capabilities_count", - out runtime._meta.ecsact_meta_system_capabilities_count, - runtime._meta - ); - LoadDelegate( - lib, - "ecsact_meta_system_capabilities", - out runtime._meta.ecsact_meta_system_capabilities, - runtime._meta - ); + LoadDelegate(lib, "ecsact_meta_registry_name", out runtime._meta.ecsact_meta_registry_name, runtime._meta); + LoadDelegate(lib, "ecsact_meta_component_name", out runtime._meta.ecsact_meta_component_name, runtime._meta); + LoadDelegate(lib, "ecsact_meta_action_name", out runtime._meta.ecsact_meta_action_name, runtime._meta); + LoadDelegate(lib, "ecsact_meta_system_name", out runtime._meta.ecsact_meta_system_name, runtime._meta); + LoadDelegate(lib, "ecsact_meta_system_capabilities_count", out runtime._meta.ecsact_meta_system_capabilities_count, runtime._meta); + LoadDelegate(lib, "ecsact_meta_system_capabilities", out runtime._meta.ecsact_meta_system_capabilities, runtime._meta); // Load serialize methods - LoadDelegate( - lib, - "ecsact_serialize_action_size", - out runtime._serialize.ecsact_serialize_action_size, - runtime._serialize - ); - LoadDelegate( - lib, - "ecsact_serialize_component_size", - out runtime._serialize.ecsact_serialize_component_size, - runtime._serialize - ); - LoadDelegate( - lib, - "ecsact_serialize_action", - out runtime._serialize.ecsact_serialize_action, - runtime._serialize - ); - LoadDelegate( - lib, - "ecsact_serialize_component", - out runtime._serialize.ecsact_serialize_component, - runtime._serialize - ); - LoadDelegate( - lib, - "ecsact_deserialize_action", - out runtime._serialize.ecsact_deserialize_action, - runtime._serialize - ); - LoadDelegate( - lib, - "ecsact_deserialize_component", - out runtime._serialize.ecsact_deserialize_component, - runtime._serialize - ); - LoadDelegate( - lib, - "ecsact_dump_entities", - out runtime._serialize.ecsact_dump_entities, - runtime._serialize - ); + LoadDelegate(lib, "ecsact_serialize_action_size", out runtime._serialize.ecsact_serialize_action_size, runtime._serialize); + LoadDelegate(lib, "ecsact_serialize_component_size", out runtime._serialize.ecsact_serialize_component_size, runtime._serialize); + LoadDelegate(lib, "ecsact_serialize_action", out runtime._serialize.ecsact_serialize_action, runtime._serialize); + LoadDelegate(lib, "ecsact_serialize_component", out runtime._serialize.ecsact_serialize_component, runtime._serialize); + LoadDelegate(lib, "ecsact_deserialize_action", out runtime._serialize.ecsact_deserialize_action, runtime._serialize); + LoadDelegate(lib, "ecsact_deserialize_component", out runtime._serialize.ecsact_deserialize_component, runtime._serialize); + LoadDelegate(lib, "ecsact_dump_entities", out runtime._serialize.ecsact_dump_entities, runtime._serialize); // Load static methods - LoadDelegate( - lib, - "ecsact_static_components", - out runtime._static.ecsact_static_components, - runtime._static - ); - LoadDelegate( - lib, - "ecsact_static_systems", - out runtime._static.ecsact_static_systems, - runtime._static - ); - LoadDelegate( - lib, - "ecsact_static_actions", - out runtime._static.ecsact_static_actions, - runtime._static - ); - LoadDelegate( - lib, - "ecsact_static_on_reload", - out runtime._static.ecsact_static_on_reload, - runtime._static - ); - LoadDelegate( - lib, - "ecsact_static_off_reload", - out runtime._static.ecsact_static_off_reload, - runtime._static - ); + LoadDelegate(lib, "ecsact_static_components", out runtime._static.ecsact_static_components, runtime._static); + LoadDelegate(lib, "ecsact_static_systems", out runtime._static.ecsact_static_systems, runtime._static); + LoadDelegate(lib, "ecsact_static_actions", out runtime._static.ecsact_static_actions, runtime._static); + LoadDelegate(lib, "ecsact_static_on_reload", out runtime._static.ecsact_static_on_reload, runtime._static); + LoadDelegate(lib, "ecsact_static_off_reload", out runtime._static.ecsact_static_off_reload, runtime._static); // Load system implementation wasm methods - LoadDelegate( - lib, - "ecsactsi_wasm_load", - out runtime._wasm.ecsactsi_wasm_load, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_load_file", - out runtime._wasm.ecsactsi_wasm_load_file, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_reset", - out runtime._wasm.ecsactsi_wasm_reset, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_unload", - out runtime._wasm.ecsactsi_wasm_unload, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_set_trap_handler", - out runtime._wasm.ecsactsi_wasm_set_trap_handler, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_last_error_message", - out runtime._wasm.ecsactsi_wasm_last_error_message, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_last_error_message_length", - out runtime._wasm.ecsactsi_wasm_last_error_message_length, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_consume_logs", - out runtime._wasm.ecsactsi_wasm_consume_logs, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_allow_file_read_access", - out runtime._wasm.ecsactsi_wasm_allow_file_read_access, - runtime._wasm - ); - LoadDelegate( - lib, - "ecsactsi_wasm_allow_file_read_access", - out runtime._wasm.ecsactsi_wasm_allow_file_read_access, - runtime._wasm - ); + LoadDelegate(lib, "ecsact_si_wasm_load", out runtime._wasm.ecsact_si_wasm_load, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_load_file", out runtime._wasm.ecsact_si_wasm_load_file, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_reset", out runtime._wasm.ecsact_si_wasm_reset, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_unload", out runtime._wasm.ecsact_si_wasm_unload, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_set_trap_handler", out runtime._wasm.ecsact_si_wasm_set_trap_handler, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_last_error_message", out runtime._wasm.ecsact_si_wasm_last_error_message, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_last_error_message_length", out runtime._wasm.ecsact_si_wasm_last_error_message_length, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_consume_logs", out runtime._wasm.ecsact_si_wasm_consume_logs, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_allow_file_read_access", out runtime._wasm.ecsact_si_wasm_allow_file_read_access, runtime._wasm); + LoadDelegate(lib, "ecsact_si_wasm_allow_file_read_access", out runtime._wasm.ecsact_si_wasm_allow_file_read_access, runtime._wasm); + + // clang-format on } - if(runtime._wasm.ecsactsi_wasm_set_trap_handler != null) { - runtime._wasm.ecsactsi_wasm_set_trap_handler(DefaultWasmTrapHandler); + + if(runtime._wasm.ecsact_si_wasm_set_trap_handler != null) { + runtime._wasm.ecsact_si_wasm_set_trap_handler(DefaultWasmTrapHandler); } return runtime; @@ -3030,19 +2686,23 @@ public static void Free(EcsactRuntime runtime) { if(runtime._async != null) { if(runtime._async.connectState == Ecsact.Async.ConnectState.Connected) { - runtime._async.Disconnect(); + runtime._async.Stop(); } runtime._async.ecsact_async_flush_events = null; - runtime._async.ecsact_async_connect = null; - runtime._async.ecsact_async_disconnect = null; - runtime._async.ecsact_async_enqueue_execution_options = null; + runtime._async.ecsact_async_start = null; + runtime._async.ecsact_async_stop = null; + runtime._async.ecsact_async_stop_all = null; + runtime._async.ecsact_async_force_reset = null; runtime._async.ecsact_async_get_current_tick = null; + runtime._async.ecsact_async_stream = null; } if(runtime._core != null) { runtime._core.ecsact_create_registry = null; runtime._core.ecsact_destroy_registry = null; + runtime._core.ecsact_clone_registry = null; + runtime._core.ecsact_hash_registry = null; runtime._core.ecsact_clear_registry = null; runtime._core.ecsact_create_entity = null; runtime._core.ecsact_ensure_entity = null; @@ -3053,37 +2713,39 @@ public static void Free(EcsactRuntime runtime) { runtime._core.ecsact_add_component = null; runtime._core.ecsact_has_component = null; runtime._core.ecsact_get_component = null; - runtime._core.ecsact_each_component = null; runtime._core.ecsact_count_components = null; runtime._core.ecsact_get_components = null; + runtime._core.ecsact_each_component = null; runtime._core.ecsact_update_component = null; runtime._core.ecsact_remove_component = null; runtime._core.ecsact_execute_systems = null; + runtime._core.ecsact_get_entity_execution_status = null; + runtime._core.ecsact_stream = null; } if(runtime._wasm != null) { - var hasWasmLoadFn = runtime._wasm.ecsactsi_wasm_load != null || - runtime._wasm.ecsactsi_wasm_load != null; + var hasWasmLoadFn = runtime._wasm.ecsact_si_wasm_load != null || + runtime._wasm.ecsact_si_wasm_load != null; if(hasWasmLoadFn) { - if(runtime._wasm.ecsactsi_wasm_reset != null) { - runtime._wasm.ecsactsi_wasm_reset(); + if(runtime._wasm.ecsact_si_wasm_reset != null) { + runtime._wasm.ecsact_si_wasm_reset(); } else { UnityEngine.Debug.LogWarning( - "ecsactsi_wasm_reset method unavailable. Unity may become " + + "ecsact_si_wasm_reset method unavailable. Unity may become " + "unstable after unloading the Ecsact runtime." ); } } - runtime._wasm.ecsactsi_wasm_load = null; - runtime._wasm.ecsactsi_wasm_load_file = null; - runtime._wasm.ecsactsi_wasm_reset = null; - runtime._wasm.ecsactsi_wasm_unload = null; - runtime._wasm.ecsactsi_wasm_set_trap_handler = null; - runtime._wasm.ecsactsi_wasm_last_error_message_length = null; - runtime._wasm.ecsactsi_wasm_last_error_message = null; - runtime._wasm.ecsactsi_wasm_consume_logs = null; - runtime._wasm.ecsactsi_wasm_allow_file_read_access = null; + runtime._wasm.ecsact_si_wasm_load = null; + runtime._wasm.ecsact_si_wasm_load_file = null; + runtime._wasm.ecsact_si_wasm_reset = null; + runtime._wasm.ecsact_si_wasm_unload = null; + runtime._wasm.ecsact_si_wasm_set_trap_handler = null; + runtime._wasm.ecsact_si_wasm_last_error_message_length = null; + runtime._wasm.ecsact_si_wasm_last_error_message = null; + runtime._wasm.ecsact_si_wasm_consume_logs = null; + runtime._wasm.ecsact_si_wasm_allow_file_read_access = null; } if(runtime._dynamic != null) { @@ -3096,20 +2758,17 @@ public static void Free(EcsactRuntime runtime) { runtime._dynamic.ecsact_system_execution_context_action = null; runtime._dynamic.ecsact_system_execution_context_add = null; runtime._dynamic.ecsact_system_execution_context_remove = null; - runtime._dynamic.ecsact_system_execution_context_update = null; runtime._dynamic.ecsact_system_execution_context_get = null; + runtime._dynamic.ecsact_system_execution_context_update = null; runtime._dynamic.ecsact_system_execution_context_has = null; + runtime._dynamic.ecsact_system_execution_context_stream_toggle = null; runtime._dynamic.ecsact_system_execution_context_generate = null; runtime._dynamic.ecsact_system_execution_context_parent = null; runtime._dynamic.ecsact_system_execution_context_same = null; + runtime._dynamic.ecsact_system_execution_context_other = null; runtime._dynamic.ecsact_system_execution_context_entity = null; - runtime._dynamic.ecsact_create_system = null; - runtime._dynamic.ecsact_set_system_execution_impl = null; - runtime._dynamic.ecsact_create_action = null; - runtime._dynamic.ecsact_create_component = null; - runtime._dynamic.ecsact_destroy_component = null; runtime._dynamic.ecsact_system_execution_context_id = null; - runtime._dynamic.ecsact_system_execution_context_other = null; + runtime._dynamic.ecsact_set_system_execution_impl = null; } if(runtime._meta != null) { From a19ae3c6e430d6597d61b4d77fdb8036899f6c8f Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Wed, 5 Feb 2025 09:29:42 -0800 Subject: [PATCH 2/4] feat: got to a compiled state --- .editorconfig | 6 + Runtime/AsyncRunner.cs | 9 +- Runtime/EcsactRuntime.cs | 151 +++++++++++++++--- Runtime/VisualScripting/AsyncConnectEvent.cs | 50 ------ .../VisualScripting/AsyncConnectEvent.cs.meta | 11 -- Runtime/VisualScripting/AsyncConnectNode.cs | 35 ---- .../VisualScripting/AsyncConnectNode.cs.meta | 11 -- .../AsyncConnectStateChangeEvent.cs | 47 ------ .../AsyncConnectStateChangeEvent.cs.meta | 11 -- .../VisualScripting/AsyncConnectStateNode.cs | 22 --- .../AsyncConnectStateNode.cs.meta | 11 -- .../VisualScripting/AsyncDisconnectNode.cs | 29 ---- .../AsyncDisconnectNode.cs.meta | 11 -- Runtime/VisualScripting/AsyncErrorEvent.cs | 48 ------ .../VisualScripting/AsyncErrorEvent.cs.meta | 11 -- 15 files changed, 147 insertions(+), 316 deletions(-) create mode 100644 .editorconfig delete mode 100644 Runtime/VisualScripting/AsyncConnectEvent.cs delete mode 100644 Runtime/VisualScripting/AsyncConnectEvent.cs.meta delete mode 100644 Runtime/VisualScripting/AsyncConnectNode.cs delete mode 100644 Runtime/VisualScripting/AsyncConnectNode.cs.meta delete mode 100644 Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs delete mode 100644 Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs.meta delete mode 100644 Runtime/VisualScripting/AsyncConnectStateNode.cs delete mode 100644 Runtime/VisualScripting/AsyncConnectStateNode.cs.meta delete mode 100644 Runtime/VisualScripting/AsyncDisconnectNode.cs delete mode 100644 Runtime/VisualScripting/AsyncDisconnectNode.cs.meta delete mode 100644 Runtime/VisualScripting/AsyncErrorEvent.cs delete mode 100644 Runtime/VisualScripting/AsyncErrorEvent.cs.meta diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7412bcc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +insert_final_newline = true +indent_style = tab +indent_size = 4 diff --git a/Runtime/AsyncRunner.cs b/Runtime/AsyncRunner.cs index 325c42a..b4a2c77 100644 --- a/Runtime/AsyncRunner.cs +++ b/Runtime/AsyncRunner.cs @@ -9,6 +9,8 @@ namespace Ecsact { public class AsyncRunner : EcsactRunner { private EcsactRuntime? runtime; + public global::System.Int32? SessionId; + private void Enqueue() { var localExecutionOptions = executionOptions; @@ -21,6 +23,7 @@ private void Enqueue() { localExecutionOptions.create_entities_placeholders.ToArray(); localExecutionOptions.Alloc(); Ecsact.Defaults.Runtime.async.EnqueueExecutionOptions( + SessionId.Value!, localExecutionOptions.C() ); } finally { @@ -29,11 +32,15 @@ private void Enqueue() { } void Update() { + if(!SessionId.HasValue) { + return; + } + if(Ecsact.Defaults.Runtime != null) { if(!executionOptions.isEmpty()) { Enqueue(); } - Ecsact.Defaults.Runtime.async.Flush(); + Ecsact.Defaults.Runtime.async.Flush(SessionId.Value); } } } diff --git a/Runtime/EcsactRuntime.cs b/Runtime/EcsactRuntime.cs index c0f2135..289c525 100644 --- a/Runtime/EcsactRuntime.cs +++ b/Runtime/EcsactRuntime.cs @@ -17,6 +17,17 @@ class CurrentSystemExecutionState { namespace Ecsact { +public enum EntityExecutionStatus : Int32 { + Idle, + PendingLazy, +} + +public enum StreamError : Int32 { + Ok, + /// An invalid or non-stream component ID was passed into the stream. + InvalidComponentId, +} + namespace Async { public enum ConnectState : Int32 { NotConnected, @@ -753,6 +764,12 @@ public delegate void AsyncReqCompleteCallback( IntPtr callbackUserData ); + public delegate void AsyncSessionEventCallback( + Int32 sessionId, + Ecsact.Async.SessionEvent sessionEvent, + IntPtr callbackUserData + ); + public struct AsyncEventsCollector { public AsyncErrorCallback errorCallback; public IntPtr errorCallbackUserData; @@ -760,6 +777,8 @@ public struct AsyncEventsCollector { public IntPtr asyncExecErrorCallbackUserData; public AsyncReqCompleteCallback asyncReqCompleteCallback; public IntPtr asyncReqCompleteCallbackUserData; + public AsyncSessionEventCallback asyncSessionEventCallback; + public IntPtr asyncSessionEventCallbackUserData; } static EcsactRuntime() { @@ -815,23 +834,25 @@ public class Async : ModuleBase { }; internal delegate void ecsact_async_enqueue_execute_options_delegate( - Int32 sessionId, + Int32 sessionId, CExecutionOptions executionOptions ); - internal ecsact_async_enqueue_execute_options_delegate? ecsact_async_enqueue_execution_options; + internal + ecsact_async_enqueue_execute_options_delegate? ecsact_async_enqueue_execution_options; internal delegate void ecsact_async_flush_events_delegate( - Int32 sessionId, + Int32 sessionId, in ExecutionEventsCollector executionEventsCollector, in AsyncEventsCollector asyncEventsCollector ); internal ecsact_async_flush_events_delegate? ecsact_async_flush_events; - internal delegate Int32 ecsact_async_start_delegate(IntPtr data, Int32 dataLength); + internal delegate Int32 + ecsact_async_start_delegate(IntPtr data, Int32 dataLength); internal ecsact_async_start_delegate? ecsact_async_start; internal delegate void ecsact_async_stop_delegate(Int32 SessionId); - internal ecsact_async_stop_delegate? ecsact_async_stop; + internal ecsact_async_stop_delegate? ecsact_async_stop; internal delegate void ecsact_async_stop_all_delegate(); internal ecsact_async_stop_all_delegate? ecsact_async_stop_all; @@ -839,8 +860,11 @@ in AsyncEventsCollector asyncEventsCollector internal delegate void ecsact_async_force_reset_delegate(); internal ecsact_async_force_reset_delegate? ecsact_async_force_reset; - internal delegate int ecsact_async_get_current_tick_delegate(Int32 sesssionId); - internal ecsact_async_get_current_tick_delegate? ecsact_async_get_current_tick; + internal delegate int ecsact_async_get_current_tick_delegate( + Int32 sesssionId + ); + internal + ecsact_async_get_current_tick_delegate? ecsact_async_get_current_tick; internal delegate void ecsact_async_stream_delegate( Int32 sessionId, @@ -851,7 +875,6 @@ IntPtr indexedFieldValues ); internal ecsact_async_stream_delegate? ecsact_async_stream; - public delegate void AsyncErrorCallback( Ecsact.AsyncError err, Int32[] requestIds @@ -866,10 +889,11 @@ public delegate void ConnectCallback( Int32 connectPort ); - private AsyncEventsCollector _asyncEvs; - private List _errCallbacks = new(); - private List _sysErrCallbacks = new(); - private EcsactRuntime _owner; + private AsyncEventsCollector _asyncEvs; + private List _errCallbacks = new(); + private List _sysErrCallbacks = new(); + private List _sessionEvCallbacks = new(); + private EcsactRuntime _owner; public delegate void ConnectStateChangeHandler( Ecsact.Async.ConnectState newState @@ -886,6 +910,8 @@ internal Async(EcsactRuntime owner) { asyncExecErrorCallbackUserData = IntPtr.Zero, asyncReqCompleteCallback = OnAsyncReqCompleteHandler, asyncReqCompleteCallbackUserData = IntPtr.Zero, + asyncSessionEventCallback = OnAsyncSessionEventHandler, + asyncSessionEventCallbackUserData = IntPtr.Zero, }; } @@ -934,12 +960,33 @@ IntPtr callbackUserData // TODO: report done requests } + [AOT.MonoPInvokeCallback(typeof(AsyncSessionEventCallback))] + public static void OnAsyncSessionEventHandler( + Int32 sessionId, + Ecsact.Async.SessionEvent sessionEvent, + IntPtr callbackUserData + ) { + var self = (GCHandle.FromIntPtr(callbackUserData).Target as Async)!; + foreach(var cb in self._sessionEvCallbacks) { + cb(sessionId, sessionEvent); + } + } + public Action OnSystemError(SystemErrorCallback callback) { _sysErrCallbacks.Add(callback); - return () => { _sysErrCallbacks.Remove(callback); }; } + public delegate void AsyncSessionEventCallback( + Int32 sessionId, + Ecsact.Async.SessionEvent sessionEvent + ); + + public Action OnSessionEvent(AsyncSessionEventCallback callback) { + _sessionEvCallbacks.Add(callback); + return () => { _sessionEvCallbacks.Remove(callback); }; + } + /** * Wrapper for `ecsact_async_start` */ @@ -947,6 +994,8 @@ public Int32 Start(byte[] optionData) { if(ecsact_async_start == null) { throw new EcsactRuntimeMissingMethod("ecsact_async_start"); } + + throw new Exception("TODO"); } /** @@ -960,6 +1009,28 @@ public void Stop(Int32 sessionId) { ecsact_async_stop(sessionId); } + /** + * Wrapper for `ecsact_async_stop_all` + */ + public void StopAll() { + if(ecsact_async_stop_all == null) { + throw new EcsactRuntimeMissingMethod("ecsact_async_stop_all"); + } + + ecsact_async_stop_all(); + } + + /** + * Wrapper for `ecsact_async_force_reset` + */ + public void ForceReset() { + if(ecsact_async_force_reset == null) { + throw new EcsactRuntimeMissingMethod("ecsact_async_force_reset"); + } + + ecsact_async_force_reset(); + } + public Int32 GetCurrentTick(Int32 sessionId) { if(ecsact_async_get_current_tick == null) { throw new EcsactRuntimeMissingMethod("ecsact_async_get_current_tick"); @@ -967,7 +1038,10 @@ public Int32 GetCurrentTick(Int32 sessionId) { return ecsact_async_get_current_tick(sessionId); } - public void EnqueueExecutionOptions(Int32 sessionId, CExecutionOptions executionOptions) { + public void EnqueueExecutionOptions( + Int32 sessionId, + CExecutionOptions executionOptions + ) { if(ecsact_async_enqueue_execution_options == null) { throw new EcsactRuntimeMissingMethod( "ecsact_async_enqueue_execution_options" @@ -1064,10 +1138,22 @@ Int32 componentId #endif } - internal delegate Int32 ecsact_create_registry_delegate(string registryName + internal delegate Int32 ecsact_create_registry_delegate( // + string registryName ); internal ecsact_create_registry_delegate? ecsact_create_registry; + internal delegate Int32 ecsact_clone_registry_delegate( // + Int32 registry, + string registryName + ); + internal ecsact_clone_registry_delegate? ecsact_clone_registry; + + internal delegate Int64 ecsact_hash_registry_delegate( // + Int32 registry + ); + internal ecsact_hash_registry_delegate? ecsact_hash_registry; + internal delegate void ecsact_destroy_registry_delegate(Int32 registryId); internal ecsact_destroy_registry_delegate? ecsact_destroy_registry; @@ -1196,6 +1282,24 @@ in ExecutionEventsCollector eventsCollector ); internal ecsact_execute_systems_delegate? ecsact_execute_systems; + internal delegate + Ecsact.EntityExecutionStatus ecsact_get_entity_execution_status_delegate( + Int32 registry, + Int32 entity, + Int32 systemLikeId + ); + internal + ecsact_get_entity_execution_status_delegate? ecsact_get_entity_execution_status; + + internal delegate Ecsact.StreamError ecsact_stream_delegate( + Int32 registry, + Int32 entity, + Int32 component, + IntPtr componentData, + IntPtr indexedFieldValues + ); + internal ecsact_stream_delegate? ecsact_stream; + private EcsactRuntime _owner; internal Core(EcsactRuntime owner) { @@ -1791,6 +1895,16 @@ internal delegate Int32 internal ecsact_system_execution_context_entity_delegate? ecsact_system_execution_context_entity; + internal delegate void + ecsact_system_execution_context_stream_toggle_delegate( + IntPtr context, + Int32 componentId, + [MarshalAs(UnmanagedType.I1)] bool streamingEnabled, + IntPtr indexedFieldValues + ); + internal + ecsact_system_execution_context_stream_toggle_delegate? ecsact_system_execution_context_stream_toggle; + internal delegate void ecsact_set_system_execution_impl_delegate( Int32 systemId, CSystemExecutionImpl executionImpl @@ -2665,7 +2779,6 @@ public static EcsactRuntime Load(IEnumerable libraryPaths) { // clang-format on } - if(runtime._wasm.ecsact_si_wasm_set_trap_handler != null) { runtime._wasm.ecsact_si_wasm_set_trap_handler(DefaultWasmTrapHandler); } @@ -2685,8 +2798,10 @@ public static void Free(EcsactRuntime runtime) { } if(runtime._async != null) { - if(runtime._async.connectState == Ecsact.Async.ConnectState.Connected) { - runtime._async.Stop(); + if(runtime._async.ecsact_async_force_reset != null) { + runtime._async.ecsact_async_force_reset(); + } else if(runtime._async.ecsact_async_stop_all != null) { + runtime._async.ecsact_async_stop_all(); } runtime._async.ecsact_async_flush_events = null; diff --git a/Runtime/VisualScripting/AsyncConnectEvent.cs b/Runtime/VisualScripting/AsyncConnectEvent.cs deleted file mode 100644 index d3aaad9..0000000 --- a/Runtime/VisualScripting/AsyncConnectEvent.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Unity.VisualScripting; -using UnityEngine; -using System; - -namespace Ecsact.VisualScripting { - -public class AsyncConnectEventData { - public string connectAddress; - public Int32 connectPort; -} - -[UnitTitle("On Connect")] -[UnitCategory("Ecsact\\Async")] -[UnitSurtitle("Ecsact / Async")] -public class AsyncConnectEvent : EventUnit { - public const string eventName = "EcsactAsyncConnectEvent"; - - [PortLabel("Connect Address")] - [DoNotSerialize] - public ValueOutput connectAddressOutput { get; private set; } - - [PortLabel("Connect port")] - [DoNotSerialize] - public ValueOutput connectPortOutput { - get; private set; - } - - protected override bool register => true; - - public override EventHook GetHook(GraphReference reference) { - return new EventHook(eventName); - } - - protected override void Definition() { - base.Definition(); - - connectAddressOutput = ValueOutput(nameof(connectAddressOutput)); - connectPortOutput = ValueOutput(nameof(connectPortOutput)); - } - - protected override void AssignArguments( - Flow flow, - AsyncConnectEventData data - ) { - flow.SetValue(connectAddressOutput, data.connectAddress); - flow.SetValue(connectPortOutput, data.connectPort); - } -} - -} // namespace Ecsact.VisualScripting diff --git a/Runtime/VisualScripting/AsyncConnectEvent.cs.meta b/Runtime/VisualScripting/AsyncConnectEvent.cs.meta deleted file mode 100644 index 97cbf8e..0000000 --- a/Runtime/VisualScripting/AsyncConnectEvent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 758219e01a2eabe4c8056cface8bfd5a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/VisualScripting/AsyncConnectNode.cs b/Runtime/VisualScripting/AsyncConnectNode.cs deleted file mode 100644 index d65292d..0000000 --- a/Runtime/VisualScripting/AsyncConnectNode.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Unity.VisualScripting; -using UnityEngine; - -namespace Ecsact.VisualScripting { - -[UnitTitle("Connect")] -[UnitCategory("Ecsact\\Async")] -[UnitSurtitle("Ecsact / Async")] -public class AsyncConnectNode : Unit { - [PortLabelHidden] - [DoNotSerialize] - public ControlInput controlInput; - - [PortLabelHidden] - [DoNotSerialize] - public ControlOutput controlOutput; - - [DoNotSerialize] - public ValueInput connectionStringInput; - - protected override void Definition() { - connectionStringInput = ValueInput("connectionString"); - controlOutput = ControlOutput("controlOutput"); - controlInput = ControlInput("controlInput", flow => { - var connectUri = flow.GetValue(connectionStringInput); - Ecsact.Defaults.Runtime.async.Connect(connectUri); - return controlOutput; - }); - - Requirement(connectionStringInput, controlInput); - Succession(controlInput, controlOutput); - } -} - -} diff --git a/Runtime/VisualScripting/AsyncConnectNode.cs.meta b/Runtime/VisualScripting/AsyncConnectNode.cs.meta deleted file mode 100644 index 137d168..0000000 --- a/Runtime/VisualScripting/AsyncConnectNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fd5ecdb22ce6e1c43855635c294d0c62 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs b/Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs deleted file mode 100644 index 916865c..0000000 --- a/Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Unity.VisualScripting; -using UnityEngine; - -namespace Ecsact.VisualScripting { - -[UnitTitle("On Async Connect State Change")] -[UnitCategory("Events\\Ecsact")] -public class AsyncConnectStateChangeEvent - : EventUnit { - public const string eventName = "EcsactAsyncConnectStateChange"; - - [RuntimeInitializeOnLoadMethod] - private static void OnLoad() { - Ecsact.Defaults.WhenReady(OnEcsactRuntimeReady); - } - - private static void OnEcsactRuntimeReady() { - Ecsact.Defaults.Runtime.async.connectStateChange += OnConnectStateChange; - } - - private static void OnConnectStateChange(Ecsact.Async.ConnectState state) { - EventBus.Trigger(eventName, state); - } - - [DoNotSerialize] - public ValueOutput NewConnectState { get; private set; } - protected override bool register => true; - - public override EventHook GetHook(GraphReference reference) { - return new EventHook(eventName); - } - - protected override void Definition() { - base.Definition(); - NewConnectState = ValueOutput( // - nameof(NewConnectState) - ); - } - - protected override void AssignArguments( - Flow flow, - Ecsact.Async.ConnectState data - ) { - flow.SetValue(NewConnectState, data); - } -} -} diff --git a/Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs.meta b/Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs.meta deleted file mode 100644 index 56965f4..0000000 --- a/Runtime/VisualScripting/AsyncConnectStateChangeEvent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8a4005b37baad9c46b25787446b100ba -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/VisualScripting/AsyncConnectStateNode.cs b/Runtime/VisualScripting/AsyncConnectStateNode.cs deleted file mode 100644 index 31fe95e..0000000 --- a/Runtime/VisualScripting/AsyncConnectStateNode.cs +++ /dev/null @@ -1,22 +0,0 @@ - -using Unity.VisualScripting; -using UnityEngine; - -namespace Ecsact.VisualScripting { - -[UnitTitle("Get Connect State")] -[UnitCategory("Ecsact\\Async")] -[UnitSurtitle("Ecsact / Async")] -public class AsyncConnectStateNode : Unit { - [DoNotSerialize] - public ValueOutput connectStateOutput; - - protected override void Definition() { - connectStateOutput = ValueOutput( - "connectState", - _ => Ecsact.Defaults.Runtime.async.connectState - ); - } -} - -} diff --git a/Runtime/VisualScripting/AsyncConnectStateNode.cs.meta b/Runtime/VisualScripting/AsyncConnectStateNode.cs.meta deleted file mode 100644 index 9e94ca7..0000000 --- a/Runtime/VisualScripting/AsyncConnectStateNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 63595ecc4613b4f4186a0f0dda82a44c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/VisualScripting/AsyncDisconnectNode.cs b/Runtime/VisualScripting/AsyncDisconnectNode.cs deleted file mode 100644 index 8d5e5f0..0000000 --- a/Runtime/VisualScripting/AsyncDisconnectNode.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Unity.VisualScripting; -using UnityEngine; - -namespace Ecsact.VisualScripting { - -[UnitTitle("Disconnect")] -[UnitCategory("Ecsact\\Async")] -[UnitSurtitle("Ecsact / Async")] -public class AsyncDisconnectNode : Unit { - [PortLabelHidden] - [DoNotSerialize] - public ControlInput controlInput; - - [PortLabelHidden] - [DoNotSerialize] - public ControlOutput controlOutput; - - protected override void Definition() { - controlOutput = ControlOutput("controlOutput"); - controlInput = ControlInput("controlInput", flow => { - Ecsact.Defaults.Runtime.async.Disconnect(); - return controlOutput; - }); - - Succession(controlInput, controlOutput); - } -} - -} diff --git a/Runtime/VisualScripting/AsyncDisconnectNode.cs.meta b/Runtime/VisualScripting/AsyncDisconnectNode.cs.meta deleted file mode 100644 index 0da78f8..0000000 --- a/Runtime/VisualScripting/AsyncDisconnectNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 30f482bffeaec0147972364d9fac0dd2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/VisualScripting/AsyncErrorEvent.cs b/Runtime/VisualScripting/AsyncErrorEvent.cs deleted file mode 100644 index 66636bf..0000000 --- a/Runtime/VisualScripting/AsyncErrorEvent.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Unity.VisualScripting; -using UnityEngine; -using System; - -namespace Ecsact.VisualScripting { - -[Serializable] -public class AsyncErrorEventData { - public Ecsact.AsyncError error; - public Int32 requestId; -} - -[UnitTitle("On Error")] -[UnitCategory("Ecsact\\Async")] -[UnitSurtitle("Ecsact / Async")] -public class AsyncErrorEvent : EventUnit { - public const string eventName = "EcsactAsyncErrorEvent"; - - [PortLabel("Error")] - [DoNotSerialize] - public ValueOutput errorOutput { get; private set; } - - [PortLabel("Request ID")] - [DoNotSerialize] - public ValueOutput requestIdOutput { - get; private set; - } - - protected override bool register => true; - - public override EventHook GetHook(GraphReference reference) { - return new EventHook(eventName); - } - - protected override void Definition() { - base.Definition(); - - errorOutput = ValueOutput(nameof(errorOutput)); - requestIdOutput = ValueOutput(nameof(requestIdOutput)); - } - - protected override void AssignArguments(Flow flow, AsyncErrorEventData data) { - flow.SetValue(errorOutput, data.error); - flow.SetValue(requestIdOutput, data.requestId); - } -} - -} // namespace Ecsact.VisualScripting diff --git a/Runtime/VisualScripting/AsyncErrorEvent.cs.meta b/Runtime/VisualScripting/AsyncErrorEvent.cs.meta deleted file mode 100644 index 17a9f50..0000000 --- a/Runtime/VisualScripting/AsyncErrorEvent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 096ed9de536db6041b724f6153225f26 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From fa9e24d82453ad5c50b65d4e13539ff37c205208 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Wed, 5 Feb 2025 10:20:32 -0800 Subject: [PATCH 3/4] feat: working! --- Editor/EcsactBuild.cs | 19 +++++++++++++++++-- Runtime/AsyncRunner.cs | 8 ++++---- Runtime/EcsactRuntime.cs | 23 +++++++++++++++-------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Editor/EcsactBuild.cs b/Editor/EcsactBuild.cs index 2a72b2c..53975bf 100644 --- a/Editor/EcsactBuild.cs +++ b/Editor/EcsactBuild.cs @@ -156,8 +156,8 @@ public static void Build(Options options) { }; proc.OutputDataReceived += (_, ev) => { + var line = ev.Data; try { - var line = ev.Data; if(!string.IsNullOrWhiteSpace(line)) { var baseMessage = JsonUtility.FromJson(line); switch(baseMessage.type) { @@ -241,6 +241,9 @@ public static void Build(Options options) { } } } catch(System.Exception err) { + UnityEngine.Debug.LogError( + $"Exception occured while processing this line: {line}" + ); UnityEngine.Debug.LogException(err); } }; @@ -297,6 +300,15 @@ public static void Build(Options options) { proc.StartInfo.Arguments += " "; if(_settings.ecsactBuildEnabled) { + if(_settings.recipes.Count == 0) { + UnityEngine.Debug.LogError( + "No ecsact build recipes selected - please check your Ecsact Unity " + + "settings" + ); + Progress.Finish(progressId, Progress.Status.Failed); + return; + } + foreach(var recipe in _settings.recipes) { if(!string.IsNullOrEmpty(recipe)) { proc.StartInfo.Arguments += " --recipe=\""; @@ -318,7 +330,10 @@ public static void Build(Options options) { proc.Exited += new System.EventHandler(delegate(object sender, System.EventArgs e) { if(proc.ExitCode != 0) { - UnityEngine.Debug.Log("Ecsact build failed"); + UnityEngine.Debug.LogError("Ecsact build failed"); + UnityEngine.Debug.Log( + $"From Command: ecsact {proc.StartInfo.Arguments}" + ); } else { UnityEngine.Debug.Log("Ecsact build succeeded"); } diff --git a/Runtime/AsyncRunner.cs b/Runtime/AsyncRunner.cs index b4a2c77..5dcd805 100644 --- a/Runtime/AsyncRunner.cs +++ b/Runtime/AsyncRunner.cs @@ -9,7 +9,7 @@ namespace Ecsact { public class AsyncRunner : EcsactRunner { private EcsactRuntime? runtime; - public global::System.Int32? SessionId; + public global::System.Int32? sessionId; private void Enqueue() { var localExecutionOptions = executionOptions; @@ -23,7 +23,7 @@ private void Enqueue() { localExecutionOptions.create_entities_placeholders.ToArray(); localExecutionOptions.Alloc(); Ecsact.Defaults.Runtime.async.EnqueueExecutionOptions( - SessionId.Value!, + sessionId!.Value, localExecutionOptions.C() ); } finally { @@ -32,7 +32,7 @@ private void Enqueue() { } void Update() { - if(!SessionId.HasValue) { + if(!sessionId.HasValue) { return; } @@ -40,7 +40,7 @@ void Update() { if(!executionOptions.isEmpty()) { Enqueue(); } - Ecsact.Defaults.Runtime.async.Flush(SessionId.Value); + Ecsact.Defaults.Runtime.async.Flush(sessionId.Value); } } } diff --git a/Runtime/EcsactRuntime.cs b/Runtime/EcsactRuntime.cs index 289c525..ceba62f 100644 --- a/Runtime/EcsactRuntime.cs +++ b/Runtime/EcsactRuntime.cs @@ -754,11 +754,13 @@ IntPtr callbackUserData ); public delegate void AsyncExecSystemErrorCallback( + Int32 sessionId, Ecsact.ecsact_exec_systems_error systemError, IntPtr callbackUserData ); public delegate void AsyncReqCompleteCallback( + Int32 sessionId, Int32 requestIdsLength, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] Int32[] requestIds, IntPtr callbackUserData @@ -831,6 +833,7 @@ public class Async : ModuleBase { "ecsact_async_force_reset", "ecsact_async_get_current_tick", "ecsact_async_stream", + "ecsact_async_enqueue_execution_options", }; internal delegate void ecsact_async_enqueue_execute_options_delegate( @@ -848,7 +851,7 @@ in AsyncEventsCollector asyncEventsCollector internal ecsact_async_flush_events_delegate? ecsact_async_flush_events; internal delegate Int32 - ecsact_async_start_delegate(IntPtr data, Int32 dataLength); + ecsact_async_start_delegate(sbyte[] data, Int32 dataLength); internal ecsact_async_start_delegate? ecsact_async_start; internal delegate void ecsact_async_stop_delegate(Int32 SessionId); @@ -941,6 +944,7 @@ public Action OnAsyncError(AsyncErrorCallback callback) { [AOT.MonoPInvokeCallback(typeof(AsyncExecSystemErrorCallback))] private static void OnAsyncExecutionErrorHandler( + Int32 sessionId, Ecsact.ecsact_exec_systems_error systemError, IntPtr callbackUserData ) { @@ -952,11 +956,11 @@ IntPtr callbackUserData [AOT.MonoPInvokeCallback(typeof(AsyncReqCompleteCallback))] public static void OnAsyncReqCompleteHandler( + Int32 sessionId, Int32 requestIdsLength, Int32[] requestIds, IntPtr callbackUserData ) { - var self = (GCHandle.FromIntPtr(callbackUserData).Target as Async)!; // TODO: report done requests } @@ -966,10 +970,10 @@ public static void OnAsyncSessionEventHandler( Ecsact.Async.SessionEvent sessionEvent, IntPtr callbackUserData ) { - var self = (GCHandle.FromIntPtr(callbackUserData).Target as Async)!; - foreach(var cb in self._sessionEvCallbacks) { - cb(sessionId, sessionEvent); - } + // var self = (GCHandle.FromIntPtr(callbackUserData).Target as Async)!; + // foreach(var cb in self._sessionEvCallbacks) { + // cb(sessionId, sessionEvent); + // } } public Action OnSystemError(SystemErrorCallback callback) { @@ -995,7 +999,7 @@ public Int32 Start(byte[] optionData) { throw new EcsactRuntimeMissingMethod("ecsact_async_start"); } - throw new Exception("TODO"); + return ecsact_async_start((sbyte[])(Array)optionData, optionData.Length); } /** @@ -1070,7 +1074,8 @@ public void Flush(Int32 sessionId) { _asyncEvs.asyncExecErrorCallbackUserData = selfIntPtr; _asyncEvs.errorCallbackUserData = selfIntPtr; _asyncEvs.asyncReqCompleteCallbackUserData = selfIntPtr; - ecsact_async_flush_events(sessionId, in _owner._execEvs, in _asyncEvs); + _asyncEvs.asyncSessionEventCallbackUserData = selfIntPtr; + ecsact_async_flush_events(sessionId, in _owner!._execEvs, in _asyncEvs); } finally { selfPinned.Free(); ownerPinned.Free(); @@ -1808,6 +1813,7 @@ public class Dynamic : ModuleBase { "ecsact_system_execution_context_same", "ecsact_system_execution_context_update", "ecsact_system_execution_context_entity", + "ecsact_system_execution_context_stream_toggle", "ecsact_system_generates_set_component", "ecsact_system_generates_unset_component", "ecsact_unset_system_association_capability", @@ -2698,6 +2704,7 @@ public static EcsactRuntime Load(IEnumerable libraryPaths) { LoadDelegate(lib, "ecsact_async_force_reset", out runtime._async.ecsact_async_force_reset, runtime._async); LoadDelegate(lib, "ecsact_async_get_current_tick", out runtime._async.ecsact_async_get_current_tick, runtime._async); LoadDelegate(lib, "ecsact_async_stream", out runtime._async.ecsact_async_stream, runtime._async); + LoadDelegate(lib, "ecsact_async_enqueue_execution_options", out runtime._async.ecsact_async_enqueue_execution_options, runtime._async); // Load core methods LoadDelegate(lib, "ecsact_create_registry", out runtime._core.ecsact_create_registry, runtime._core); From f71747a35b25d531e7546a3603da3958c9839964 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Wed, 5 Feb 2025 10:23:02 -0800 Subject: [PATCH 4/4] chore: remove eclint --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a5221ed..fc0f45f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,5 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: greut/eclint-action@v0 - uses: jidicula/clang-format-action@v4.11.0 with: { clang-format-version: "19" }