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

feat: API for streaming components #262

Merged
merged 11 commits into from
Oct 14, 2024
18 changes: 17 additions & 1 deletion ecsact/runtime/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,28 @@ ECSACT_ASYNC_API_FN(void, ecsact_async_disconnect)(void);
*/
ECSACT_ASYNC_API_FN(int32_t, ecsact_async_get_current_tick)(void);

/**
* Sends Ecsact stream data to the specified registry. Stream data will be
* applied on the next ecsact_execute_systems call.
*
* @param ... if the component has indexed fields then those fields must be
* supplied to the variadic arguments in declaration order.
*/
ECSACT_CORE_API_FN(ecsact_async_request_id, ecsact_async_stream)
( //
ecsact_entity_id entity,
ecsact_component_id component_id,
const void* component_data,
...
);

#define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) \
fn(ecsact_async_enqueue_execution_options, __VA_ARGS__); \
fn(ecsact_async_flush_events, __VA_ARGS__); \
fn(ecsact_async_connect, __VA_ARGS__); \
fn(ecsact_async_disconnect, __VA_ARGS__); \
fn(ecsact_async_get_current_tick, __VA_ARGS__);
fn(ecsact_async_get_current_tick, __VA_ARGS__); \
fn(ecsact_async_stream, __VA_ARGS__)

#undef ECSACT_ASYNC_API
#undef ECSACT_ASYNC_API_FN
Expand Down
43 changes: 42 additions & 1 deletion ecsact/runtime/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ typedef enum {
ECSACT_EXEC_SYS_ERR_ACTION_ENTITY_CONSTRAINT_BROKEN = 2,
} ecsact_execute_systems_error;

typedef enum {
ECSACT_STREAM_OK = 0,

/**
* An invalid or non-stream component ID was passed into the stream.
*/
ECSACT_STREAM_INVALID_COMPONENT_ID = 1,
} ecsact_stream_error;

typedef enum {
/**
* System has no capabilities for this component.
Expand All @@ -287,7 +296,8 @@ typedef enum {

/**
* System may only write to component.
* NOTE: This flag is only valid if accompanied by `ECSACT_SYS_CAP_READONLY`.
* NOTE: This flag is only valid if accompanied by
* `ECSACT_SYS_CAP_READONLY`.
*/
ECSACT_SYS_CAP_WRITEONLY = 2,

Expand Down Expand Up @@ -342,6 +352,11 @@ typedef enum {
* `ECSACT_SYS_CAP_INCLUDE`
*/
ECSACT_SYS_CAP_REMOVES = 64 | ECSACT_SYS_CAP_INCLUDE,

/**
* System may enable or disable streaming data for this component.
*/
ECSACT_SYS_CAP_STREAM_TOGGLE = 128,
} ecsact_system_capability;

/**
Expand Down Expand Up @@ -661,6 +676,32 @@ typedef enum {
ECSACT_EVENT_DESTROY_ENTITY = 4,
} ecsact_event;

typedef enum ecsact_component_type {
/**
* The component has no unique type
*/
ECSACT_COMPONENT_TYPE_NONE = 0,

/*
* The component takes in a continuous feed of data. Look at stream toggle to
* see how you can set the component to receive updates from either
* ecsact_stream or systems.
*/
ECSACT_COMPONENT_TYPE_STREAM = 1,

/*
* The component is a stream component (@see ECSACT_COMPONENT_TYPE_STREAM) but
* may be updated overtime instead of all at once.
*/
ECSACT_COMPONENT_TYPE_LAZY_STREAM = 2,

/**
* The component only lives during system execution and is automatically
* removed.
*/
ECSACT_COMPONENT_TYPE_TRANSIENT = 3
} ecsact_component_stream;

/**
* Component event callback
*/
Expand Down
58 changes: 38 additions & 20 deletions ecsact/runtime/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,30 +264,48 @@ ECSACT_CORE_API_FN(ecsact_ees, ecsact_get_entity_execution_status)
ecsact_system_like_id system_like_id
);

/**
* Sends Ecsact stream data to the specified registry. Stream data will be
* applied on the next ecsact_execute_systems call. The last set of stream data
* is always used.
*
* @param ... if the component has indexed fields then those fields must be
* supplied to the variadic arguments in declaration order.
*/
ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream)
( //
ecsact_registry_id registry_id,
ecsact_entity_id entity,
ecsact_component_id component_id,
const void* component_data,
...
);

// # BEGIN FOR_EACH_ECSACT_CORE_API_FN
#ifdef ECSACT_MSVC_TRADITIONAL
# define FOR_EACH_ECSACT_CORE_API_FN(fn, ...) ECSACT_MSVC_TRADITIONAL_ERROR()
#else
# define FOR_EACH_ECSACT_CORE_API_FN(fn, ...) \
fn(ecsact_create_registry, __VA_ARGS__); \
fn(ecsact_destroy_registry, __VA_ARGS__); \
fn(ecsact_clear_registry, __VA_ARGS__); \
fn(ecsact_create_entity, __VA_ARGS__); \
fn(ecsact_ensure_entity, __VA_ARGS__); \
fn(ecsact_entity_exists, __VA_ARGS__); \
fn(ecsact_destroy_entity, __VA_ARGS__); \
fn(ecsact_count_entities, __VA_ARGS__); \
fn(ecsact_get_entities, __VA_ARGS__); \
fn(ecsact_add_component, __VA_ARGS__); \
fn(ecsact_has_component, __VA_ARGS__); \
fn(ecsact_get_component, __VA_ARGS__); \
fn(ecsact_count_components, __VA_ARGS__); \
fn(ecsact_get_components, __VA_ARGS__); \
fn(ecsact_each_component, __VA_ARGS__); \
fn(ecsact_update_component, __VA_ARGS__); \
fn(ecsact_remove_component, __VA_ARGS__); \
fn(ecsact_execute_systems, __VA_ARGS__); \
fn(ecsact_get_entity_execution_status, __VA_ARGS__)
# define FOR_EACH_ECSACT_CORE_API_FN(fn, ...) \
fn(ecsact_create_registry, __VA_ARGS__); \
fn(ecsact_destroy_registry, __VA_ARGS__); \
fn(ecsact_clear_registry, __VA_ARGS__); \
fn(ecsact_create_entity, __VA_ARGS__); \
fn(ecsact_ensure_entity, __VA_ARGS__); \
fn(ecsact_entity_exists, __VA_ARGS__); \
fn(ecsact_destroy_entity, __VA_ARGS__); \
fn(ecsact_count_entities, __VA_ARGS__); \
fn(ecsact_get_entities, __VA_ARGS__); \
fn(ecsact_add_component, __VA_ARGS__); \
fn(ecsact_has_component, __VA_ARGS__); \
fn(ecsact_get_component, __VA_ARGS__); \
fn(ecsact_count_components, __VA_ARGS__); \
fn(ecsact_get_components, __VA_ARGS__); \
fn(ecsact_each_component, __VA_ARGS__); \
fn(ecsact_update_component, __VA_ARGS__); \
fn(ecsact_remove_component, __VA_ARGS__); \
fn(ecsact_execute_systems, __VA_ARGS__); \
fn(ecsact_get_entity_execution_status, __VA_ARGS__); \
fn(ecsact_stream, __VA_ARGS__)
#endif

#endif // ECSACT_RUNTIME_CORE_H
126 changes: 75 additions & 51 deletions ecsact/runtime/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ ECSACT_DYNAMIC_API_FN(bool, ecsact_system_execution_context_has)
...
);

/**
* Enable or disable streaming data for the given component.
* @param ... if the component has indexed fields then those fields must be
* supplied to the variadic arguments in declaration order.
*/
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_stream_toggle)
( //
struct ecsact_system_execution_context* context,
ecsact_component_id component_id,
bool streaming_enabled,
...
);

/**
* Generate a new entity with specified components.
*
Expand Down Expand Up @@ -515,62 +528,73 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_set_system_notify_component_setting)
ecsact_system_notify_setting setting
);

/**
* Sets a components type
*/
ECSACT_DYNAMIC_API_FN(void, ecsact_set_component_type)
( //
ecsact_component_id component_id,
ecsact_component_type component_type
);

// # BEGIN FOR_EACH_ECSACT_DYNAMIC_API_FN
#ifdef ECSACT_MSVC_TRADITIONAL
# define FOR_EACH_ECSACT_DYNAMIC_API_FN(fn, ...) \
ECSACT_MSVC_TRADITIONAL_ERROR()
#else
# define FOR_EACH_ECSACT_DYNAMIC_API_FN(fn, ...) \
fn(ecsact_system_execution_context_action, __VA_ARGS__); \
fn(ecsact_system_execution_context_add, __VA_ARGS__); \
fn(ecsact_system_execution_context_remove, __VA_ARGS__); \
fn(ecsact_system_execution_context_get, __VA_ARGS__); \
fn(ecsact_system_execution_context_update, __VA_ARGS__); \
fn(ecsact_system_execution_context_has, __VA_ARGS__); \
fn(ecsact_system_execution_context_generate, __VA_ARGS__); \
fn(ecsact_system_execution_context_parent, __VA_ARGS__); \
fn(ecsact_system_execution_context_same, __VA_ARGS__); \
fn(ecsact_system_execution_context_other, __VA_ARGS__); \
fn(ecsact_system_execution_context_entity, __VA_ARGS__); \
fn(ecsact_system_execution_context_id, __VA_ARGS__); \
fn(ecsact_create_package, __VA_ARGS__); \
fn(ecsact_set_package_source_file_path, __VA_ARGS__); \
fn(ecsact_add_dependency, __VA_ARGS__); \
fn(ecsact_remove_dependency, __VA_ARGS__); \
fn(ecsact_destroy_package, __VA_ARGS__); \
fn(ecsact_create_system, __VA_ARGS__); \
fn(ecsact_set_system_lazy_iteration_rate, __VA_ARGS__); \
fn(ecsact_add_child_system, __VA_ARGS__); \
fn(ecsact_remove_child_system, __VA_ARGS__); \
fn(ecsact_reorder_system, __VA_ARGS__); \
fn(ecsact_set_system_execution_impl, __VA_ARGS__); \
fn(ecsact_create_action, __VA_ARGS__); \
fn(ecsact_create_component, __VA_ARGS__); \
fn(ecsact_create_transient, __VA_ARGS__); \
fn(ecsact_add_field, __VA_ARGS__); \
fn(ecsact_remove_field, __VA_ARGS__); \
fn(ecsact_destroy_component, __VA_ARGS__); \
fn(ecsact_destroy_transient, __VA_ARGS__); \
fn(ecsact_create_enum, __VA_ARGS__); \
fn(ecsact_destroy_enum, __VA_ARGS__); \
fn(ecsact_add_enum_value, __VA_ARGS__); \
fn(ecsact_remove_enum_value, __VA_ARGS__); \
fn(ecsact_set_system_capability, __VA_ARGS__); \
fn(ecsact_unset_system_capability, __VA_ARGS__); \
fn(ecsact_add_system_assoc, __VA_ARGS__); \
fn(ecsact_remove_system_assoc, __VA_ARGS__); \
fn(ecsact_add_system_assoc_field, __VA_ARGS__); \
fn(ecsact_remove_system_assoc_field, __VA_ARGS__); \
fn(ecsact_set_system_assoc_capability, __VA_ARGS__); \
fn(ecsact_set_system_association_capability, __VA_ARGS__); \
fn(ecsact_unset_system_association_capability, __VA_ARGS__); \
fn(ecsact_add_system_generates, __VA_ARGS__); \
fn(ecsact_remove_system_generates, __VA_ARGS__); \
fn(ecsact_system_generates_set_component, __VA_ARGS__); \
fn(ecsact_system_generates_unset_component, __VA_ARGS__); \
fn(ecsact_set_entity_execution_status, __VA_ARGS__); \
fn(ecsact_set_system_parallel_execution, __VA_ARGS__); \
fn(ecsact_set_system_notify_component_setting, __VA_ARGS__)
# define FOR_EACH_ECSACT_DYNAMIC_API_FN(fn, ...) \
fn(ecsact_system_execution_context_action, __VA_ARGS__); \
fn(ecsact_system_execution_context_add, __VA_ARGS__); \
fn(ecsact_system_execution_context_remove, __VA_ARGS__); \
fn(ecsact_system_execution_context_get, __VA_ARGS__); \
fn(ecsact_system_execution_context_update, __VA_ARGS__); \
fn(ecsact_system_execution_context_has, __VA_ARGS__); \
fn(ecsact_system_execution_context_stream_toggle, __VA_ARGS__); \
fn(ecsact_system_execution_context_generate, __VA_ARGS__); \
fn(ecsact_system_execution_context_parent, __VA_ARGS__); \
fn(ecsact_system_execution_context_same, __VA_ARGS__); \
fn(ecsact_system_execution_context_other, __VA_ARGS__); \
fn(ecsact_system_execution_context_entity, __VA_ARGS__); \
fn(ecsact_system_execution_context_id, __VA_ARGS__); \
fn(ecsact_create_package, __VA_ARGS__); \
fn(ecsact_set_package_source_file_path, __VA_ARGS__); \
fn(ecsact_add_dependency, __VA_ARGS__); \
fn(ecsact_remove_dependency, __VA_ARGS__); \
fn(ecsact_destroy_package, __VA_ARGS__); \
fn(ecsact_create_system, __VA_ARGS__); \
fn(ecsact_set_system_lazy_iteration_rate, __VA_ARGS__); \
fn(ecsact_add_child_system, __VA_ARGS__); \
fn(ecsact_remove_child_system, __VA_ARGS__); \
fn(ecsact_reorder_system, __VA_ARGS__); \
fn(ecsact_set_system_execution_impl, __VA_ARGS__); \
fn(ecsact_create_action, __VA_ARGS__); \
fn(ecsact_create_component, __VA_ARGS__); \
fn(ecsact_create_transient, __VA_ARGS__); \
fn(ecsact_add_field, __VA_ARGS__); \
fn(ecsact_remove_field, __VA_ARGS__); \
fn(ecsact_destroy_component, __VA_ARGS__); \
fn(ecsact_destroy_transient, __VA_ARGS__); \
fn(ecsact_create_enum, __VA_ARGS__); \
fn(ecsact_destroy_enum, __VA_ARGS__); \
fn(ecsact_add_enum_value, __VA_ARGS__); \
fn(ecsact_remove_enum_value, __VA_ARGS__); \
fn(ecsact_set_system_capability, __VA_ARGS__); \
fn(ecsact_unset_system_capability, __VA_ARGS__); \
fn(ecsact_add_system_assoc, __VA_ARGS__); \
fn(ecsact_remove_system_assoc, __VA_ARGS__); \
fn(ecsact_add_system_assoc_field, __VA_ARGS__); \
fn(ecsact_remove_system_assoc_field, __VA_ARGS__); \
fn(ecsact_set_system_assoc_capability, __VA_ARGS__); \
fn(ecsact_set_system_association_capability, __VA_ARGS__); \
fn(ecsact_unset_system_association_capability, __VA_ARGS__); \
fn(ecsact_add_system_generates, __VA_ARGS__); \
fn(ecsact_remove_system_generates, __VA_ARGS__); \
fn(ecsact_system_generates_set_component, __VA_ARGS__); \
fn(ecsact_system_generates_unset_component, __VA_ARGS__); \
fn(ecsact_set_entity_execution_status, __VA_ARGS__); \
fn(ecsact_set_system_parallel_execution, __VA_ARGS__); \
fn(ecsact_set_system_notify_component_setting, __VA_ARGS__); \
fn(ecsact_set_component_type, __VA_ARGS__)
#endif

#endif // ECSACT_RUNTIME_DYNAMIC_H
11 changes: 10 additions & 1 deletion ecsact/runtime/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ ECSACT_META_API_FN(void, ecsact_meta_system_notify_settings)
int32_t* out_notifies_count
);

/**
* Check the type of a component.
*/
ECSACT_META_API_FN(ecsact_component_type, ecsact_meta_component_type)
( //
ecsact_component_like_id component_id
);

// # BEGIN FOR_EACH_ECSACT_META_API_FN
#ifdef ECSACT_MSVC_TRADITIONAL
# define FOR_EACH_ECSACT_META_API_FN(fn, ...) ECSACT_MSVC_TRADITIONAL_ERROR()
Expand Down Expand Up @@ -575,7 +583,8 @@ ECSACT_META_API_FN(void, ecsact_meta_system_notify_settings)
fn(ecsact_meta_get_lazy_iteration_rate, __VA_ARGS__); \
fn(ecsact_meta_get_system_parallel_execution, __VA_ARGS__); \
fn(ecsact_meta_system_notify_settings_count, __VA_ARGS__); \
fn(ecsact_meta_system_notify_settings, __VA_ARGS__)
fn(ecsact_meta_system_notify_settings, __VA_ARGS__); \
fn(ecsact_meta_component_type, __VA_ARGS__)
#endif

#endif // ECSACT_RUNTIME_META_H
Loading