@@ -76,9 +76,28 @@ typedef enum {
76
76
ECSACT_ASYNC_ERR_CUSTOM_END = 200 ,
77
77
} ecsact_async_error ;
78
78
79
+ typedef enum {
80
+ /**
81
+ * The session has stopped
82
+ */
83
+ ECSACT_ASYNC_SESSION_STOPPED = 0 ,
84
+
85
+ /**
86
+ * The session is attempting to start but hasn't yet.
87
+ */
88
+ ECSACT_ASYNC_SESSION_PENDING = 1 ,
89
+
90
+ /**
91
+ * The session has started
92
+ */
93
+ ECSACT_ASYNC_SESSION_START = 2 ,
94
+ } ecsact_async_session_event ;
95
+
79
96
/**
80
97
* When an error occurs due to an async request this callback is invoked.
81
98
*
99
+ * @param session_id the session that received the error
100
+ *
82
101
* @param async_err when there is no async error this will be @ref
83
102
* ECSACT_ASYNC_OK otherwise @see ecsact_async_error
84
103
@@ -89,6 +108,7 @@ typedef enum {
89
108
* ecsact_async_events_collector::error_callback_user_data
90
109
*/
91
110
typedef void (* ecsact_async_error_callback )( //
111
+ ecsact_async_session_id session_id ,
92
112
ecsact_async_error async_err ,
93
113
int request_ids_length ,
94
114
ecsact_async_request_id * request_ids ,
@@ -98,10 +118,12 @@ typedef void (*ecsact_async_error_callback)( //
98
118
/**
99
119
* When an occurs from the system execution this callback is invoked.
100
120
*
121
+ * @param session_id the session that received the error
101
122
* @param execute_err when there is no system execution error, this will be
102
123
* @ref ECSACT_EXEC_SYS_OK other @see ecsact_execute_systems_error
103
124
*/
104
125
typedef void (* ecsact_execute_sys_error_callback )( //
126
+ ecsact_async_session_id session_id ,
105
127
ecsact_execute_systems_error execute_err ,
106
128
void * callback_user_data
107
129
);
@@ -110,11 +132,21 @@ typedef void (*ecsact_execute_sys_error_callback)( //
110
132
* Handler for when a request is done (error or success)
111
133
*/
112
134
typedef void (* ecsact_async_request_done_callback )( //
135
+ ecsact_async_session_id session_id ,
113
136
int request_ids_length ,
114
137
ecsact_async_request_id * request_ids ,
115
138
void * callback_user_data
116
139
);
117
140
141
+ /**
142
+ * Handler async session events
143
+ */
144
+ typedef void (* ecsact_async_session_event_callback )( //
145
+ ecsact_async_session_id session_id ,
146
+ ecsact_async_session_event event ,
147
+ void * callback_user_data
148
+ );
149
+
118
150
typedef struct ecsact_async_events_collector {
119
151
/**
120
152
* invoked when an async request failed.
@@ -151,6 +183,16 @@ typedef struct ecsact_async_events_collector {
151
183
* `callback_user_data` passed to `async_request_done_callback`
152
184
*/
153
185
void * async_request_done_callback_user_data ;
186
+
187
+ /**
188
+ * invoked when a session event has occurred. @see ecsact_async_session_event
189
+ */
190
+ ecsact_async_session_event_callback async_session_event_callback ;
191
+
192
+ /**
193
+ * `callback_user_data` passed to `async_session_event_callback`
194
+ */
195
+ void * async_session_event_callback_user_data ;
154
196
} ecsact_async_events_collector ;
155
197
156
198
/**
@@ -166,6 +208,7 @@ ECSACT_ASYNC_API_FN(
166
208
ecsact_async_enqueue_execution_options
167
209
)
168
210
( //
211
+ ecsact_async_session_id session_id ,
169
212
const ecsact_execution_options options
170
213
);
171
214
@@ -176,34 +219,59 @@ ECSACT_ASYNC_API_FN(
176
219
*/
177
220
ECSACT_ASYNC_API_FN (void , ecsact_async_flush_events )
178
221
( //
222
+ ecsact_async_session_id session_id ,
179
223
const ecsact_execution_events_collector * execution_events ,
180
224
const ecsact_async_events_collector * async_events
181
225
);
182
226
183
227
/**
184
- * @param connection_string - null-terminated string used to connect to the
185
- * underlying async runtime. This may be a hostname/ip address + port or
186
- * some other string deinfed by the implementation. Please review
187
- * documentation for your ecsact async api provider. May be NULL to
188
- * indicate wanting to connect to the 'default' if available.
189
- * @returns a request ID representing this async request. Later used in @ref
190
- * ecsact_async_error_callback if an error occurs
228
+ * @param option_data implementation defined options used to start the async
229
+ * session. This usually contains information such as the host/ip, port, and
230
+ * authentication for a network connection or various settings that affect the
231
+ * simulation. It is recommended that all implementations handle `NULL` as the
232
+ * 'default' options. You should refer to the implementations documentation for
233
+ * what should be passed here.
234
+ *
235
+ * @param option_data_size length (in bytes) of @p option_data
236
+ *
237
+ * @returns an ID that represents the session that all other async functions
238
+ * take in
239
+ */
240
+ ECSACT_ASYNC_API_FN (ecsact_async_session_id , ecsact_async_start )
241
+ ( //
242
+ const void * option_data ,
243
+ int32_t option_data_size
244
+ );
245
+
246
+ /**
247
+ * Begins stopping the session. May happen in background.
248
+ * @param session_id the session that should stop
191
249
*/
192
- ECSACT_ASYNC_API_FN (ecsact_async_request_id , ecsact_async_connect )
250
+ ECSACT_ASYNC_API_FN (void , ecsact_async_stop )
193
251
( //
194
- const char * connection_string
252
+ ecsact_async_session_id session_id
195
253
);
196
254
197
255
/**
198
- * Starts a disconnect. May happen in background, but is guaranteed to
199
- * disconnect before any new @ref ecsact_async_connect resolves.
256
+ * Begins stopping all active sessions. May happen in background.
200
257
*/
201
- ECSACT_ASYNC_API_FN (void , ecsact_async_disconnect )(void );
258
+ ECSACT_ASYNC_API_FN (void , ecsact_async_stop_all )();
259
+
260
+ /**
261
+ * Stops all active sessions immediately making all session IDs invalid.
262
+ *
263
+ * NOTE: `ecsact_async_stop_all` is a more graceful option and should be
264
+ * preferred.
265
+ */
266
+ ECSACT_ASYNC_API_FN (void , ecsact_async_force_reset )();
202
267
203
268
/**
204
269
* Gets the current tick
205
270
*/
206
- ECSACT_ASYNC_API_FN (int32_t , ecsact_async_get_current_tick )(void );
271
+ ECSACT_ASYNC_API_FN (int32_t , ecsact_async_get_current_tick )
272
+ ( //
273
+ ecsact_async_session_id session_id
274
+ );
207
275
208
276
/**
209
277
* Sends Ecsact stream data to the specified registry. Stream data will be
@@ -215,10 +283,11 @@ ECSACT_ASYNC_API_FN(int32_t, ecsact_async_get_current_tick)(void);
215
283
*/
216
284
ECSACT_ASYNC_API_FN (void , ecsact_async_stream )
217
285
( //
218
- ecsact_entity_id entity ,
219
- ecsact_component_id component_id ,
220
- const void * component_data ,
221
- const void * indexed_field_values
286
+ ecsact_async_session_id session_id ,
287
+ ecsact_entity_id entity ,
288
+ ecsact_component_id component_id ,
289
+ const void * component_data ,
290
+ const void * indexed_field_values
222
291
);
223
292
224
293
#ifdef ECSACT_MSVC_TRADITIONAL
@@ -227,8 +296,10 @@ ECSACT_ASYNC_API_FN(void, ecsact_async_stream)
227
296
# define FOR_EACH_ECSACT_ASYNC_API_FN (fn , ...) \
228
297
fn(ecsact_async_enqueue_execution_options, __VA_ARGS__); \
229
298
fn(ecsact_async_flush_events, __VA_ARGS__); \
230
- fn(ecsact_async_connect, __VA_ARGS__); \
231
- fn(ecsact_async_disconnect, __VA_ARGS__); \
299
+ fn(ecsact_async_start, __VA_ARGS__); \
300
+ fn(ecsact_async_stop, __VA_ARGS__); \
301
+ fn(ecsact_async_stop_all, __VA_ARGS__); \
302
+ fn(ecsact_async_force_reset, __VA_ARGS__); \
232
303
fn(ecsact_async_get_current_tick, __VA_ARGS__); \
233
304
fn(ecsact_async_stream, __VA_ARGS__)
234
305
#endif
0 commit comments