|
| 1 | + |
| 2 | +#pragma once |
| 3 | + |
| 4 | +#include "CoreMinimal.h" |
| 5 | +#include "ecsact/runtime/common.h" |
| 6 | +#include "EcsactUnrealExecutionOptions.generated.h" |
| 7 | + |
| 8 | +UCLASS() |
| 9 | + |
| 10 | +class UEcsactUnrealExecutionOptions : public UObject { |
| 11 | + GENERATED_BODY() |
| 12 | + |
| 13 | + TArray<ecsact_action> ActionList; |
| 14 | + TArray<ecsact_component> AddComponentList; |
| 15 | + TArray<ecsact_component> UpdateComponentList; |
| 16 | + TArray<ecsact_component_id> RemoveComponentList; |
| 17 | + ecsact_execution_options ExecOpts; |
| 18 | + |
| 19 | +public: |
| 20 | + UEcsactUnrealExecutionOptions(); |
| 21 | + |
| 22 | + auto Clear() -> void; |
| 23 | + auto IsNotEmpty() const -> bool; |
| 24 | + |
| 25 | + /** |
| 26 | + * Get's the C `ecsact_execution_options` pointer typically passed to |
| 27 | + * `ecsact_execute_systems` or `ecsact_async_enqueue_execution_options`. The |
| 28 | + * lifetime of this pointer is the same as the owning |
| 29 | + * `UEcsactUnrealExecutionOptions`. |
| 30 | + */ |
| 31 | + auto GetCPtr() -> ecsact_execution_options*; |
| 32 | + |
| 33 | + template<typename A> |
| 34 | + auto PushAction(const A& Action) -> void { |
| 35 | + auto action_data = FMemory::Malloc(sizeof(A)); |
| 36 | + FMemory::Memcpy(action_data, &Action, sizeof(A)); |
| 37 | + ActionList.Push(ecsact_action{ |
| 38 | + .action_id = A::id, |
| 39 | + .action_data = action_data, |
| 40 | + }); |
| 41 | + |
| 42 | + ExecOpts.actions_length = ActionList.Num(); |
| 43 | + ExecOpts.actions = ActionList.GetData(); |
| 44 | + } |
| 45 | + |
| 46 | + template<typename C> |
| 47 | + auto AddComponent(ecsact_entity_id Entity, const C& Component) -> void { |
| 48 | + auto component_data = FMemory::Malloc(sizeof(C)); |
| 49 | + FMemory::Memcpy(component_data, &Component, sizeof(C)); |
| 50 | + AddComponentList.Push(ecsact_component{ |
| 51 | + .component_id = C::id, |
| 52 | + .component_data = component_data, |
| 53 | + }); |
| 54 | + |
| 55 | + ExecOpts.add_components_length = AddComponentList.Num(); |
| 56 | + ExecOpts.add_components = AddComponentList.GetData(); |
| 57 | + } |
| 58 | + |
| 59 | + template<typename C> |
| 60 | + auto UpdateComponent(ecsact_entity_id Entity, const C& Component) -> void { |
| 61 | + auto component_data = FMemory::Malloc(sizeof(C)); |
| 62 | + FMemory::Memcpy(component_data, &Component, sizeof(C)); |
| 63 | + UpdateComponentList.Push(ecsact_component{ |
| 64 | + .component_id = C::id, |
| 65 | + .component_data = component_data, |
| 66 | + }); |
| 67 | + |
| 68 | + ExecOpts.update_components_length = UpdateComponentList.Num(); |
| 69 | + ExecOpts.update_components = UpdateComponentList.GetData(); |
| 70 | + } |
| 71 | + |
| 72 | + template<typename C> |
| 73 | + auto RemoveComponent(ecsact_entity_id Entity) -> void { |
| 74 | + RemoveComponentList.Push(C::id); |
| 75 | + |
| 76 | + ExecOpts.remove_components_length = RemoveComponentList.Num(); |
| 77 | + ExecOpts.remove_components = RemoveComponentList.GetData(); |
| 78 | + } |
| 79 | + |
| 80 | + inline auto DestroyEntity(ecsact_entity_id Entity) -> void { |
| 81 | + } |
| 82 | +}; |
0 commit comments