-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added runner and events collector
- Loading branch information
Showing
7 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
#include "EcsactAsyncRunner.h" | ||
#include "Ecsact.h" | ||
#include "EcsactUnrealEventsCollector.h" | ||
#include "ecsact/runtime/async.h" | ||
#include "ecsact/runtime/common.h" | ||
|
||
auto UEcsactAsyncRunner::Tick(float DeltaTime) -> void { | ||
if(ecsact_async_flush_events == nullptr) { | ||
UE_LOG(Ecsact, Error, TEXT("ecsact_async_flush_events is unavailable")); | ||
} else { | ||
ecsact_async_flush_events(nullptr, nullptr); | ||
ecsact_execution_events_collector* evc_c = nullptr; | ||
if(EventsCollector != nullptr) { | ||
evc_c = EventsCollector->GetCEVC(); | ||
} | ||
ecsact_async_flush_events(evc_c, nullptr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "EcsactUnrealEventsCollector.h" | ||
#include "Ecsact.h" | ||
|
||
UEcsactUnrealEventsCollector::UEcsactUnrealEventsCollector() : evc{} { | ||
evc.init_callback_user_data = this; | ||
evc.update_callback_user_data = this; | ||
evc.remove_callback_user_data = this; | ||
evc.entity_created_callback_user_data = this; | ||
evc.entity_destroyed_callback_user_data = this; | ||
|
||
evc.init_callback = ThisClass::OnInitComponentRaw; | ||
evc.update_callback = ThisClass::OnUpdateComponentRaw; | ||
evc.remove_callback = ThisClass::OnRemoveComponentRaw; | ||
evc.entity_created_callback = ThisClass::OnEntityCreatedRaw; | ||
evc.entity_destroyed_callback = ThisClass::OnEntityDestroyedRaw; | ||
} | ||
|
||
auto UEcsactUnrealEventsCollector::OnInitComponentRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_component_id component_id, | ||
const void* component_data, | ||
void* callback_user_data | ||
) -> void { | ||
auto self = static_cast<ThisClass*>(callback_user_data); | ||
|
||
UE_LOG( | ||
Ecsact, | ||
Log, | ||
TEXT("OnInitComponent (entity=%i, component=%i)"), | ||
static_cast<int32_t>(entity_id), | ||
static_cast<int32_t>(component_id) | ||
); | ||
|
||
self->InitComponentRawEvent | ||
.Broadcast(entity_id, component_id, component_data); | ||
} | ||
|
||
auto UEcsactUnrealEventsCollector::OnUpdateComponentRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_component_id component_id, | ||
const void* component_data, | ||
void* callback_user_data | ||
) -> void { | ||
auto self = static_cast<ThisClass*>(callback_user_data); | ||
|
||
UE_LOG( | ||
Ecsact, | ||
Log, | ||
TEXT("OnUpdateComponent (entity=%i, component=%i)"), | ||
static_cast<int32_t>(entity_id), | ||
static_cast<int32_t>(component_id) | ||
); | ||
|
||
self->UpdateComponentRawEvent | ||
.Broadcast(entity_id, component_id, component_data); | ||
} | ||
|
||
auto UEcsactUnrealEventsCollector::OnRemoveComponentRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_component_id component_id, | ||
const void* component_data, | ||
void* callback_user_data | ||
) -> void { | ||
auto self = static_cast<ThisClass*>(callback_user_data); | ||
|
||
UE_LOG( | ||
Ecsact, | ||
Log, | ||
TEXT("OnRemoveComponent (entity=%i, component=%i)"), | ||
static_cast<int32_t>(entity_id), | ||
static_cast<int32_t>(component_id) | ||
); | ||
self->RemoveComponentRawEvent | ||
.Broadcast(entity_id, component_id, component_data); | ||
} | ||
|
||
auto UEcsactUnrealEventsCollector::OnEntityCreatedRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_placeholder_entity_id placeholder_entity_id, | ||
void* callback_user_data | ||
) -> void { | ||
auto self = static_cast<ThisClass*>(callback_user_data); | ||
|
||
UE_LOG( | ||
Ecsact, | ||
Log, | ||
TEXT("OnEntityCreated (entity=%i)"), | ||
static_cast<int32_t>(entity_id) | ||
); | ||
self->CreatedEntityRawEvent.Broadcast(entity_id, placeholder_entity_id); | ||
} | ||
|
||
auto UEcsactUnrealEventsCollector::OnEntityDestroyedRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_placeholder_entity_id placeholder_entity_id, | ||
void* callback_user_data | ||
) -> void { | ||
auto self = static_cast<ThisClass*>(callback_user_data); | ||
|
||
UE_LOG( | ||
Ecsact, | ||
Log, | ||
TEXT("OnEntityDestroyed (entity=%i)"), | ||
static_cast<int32_t>(entity_id) | ||
); | ||
self->DestroyedEntityRawEvent.Broadcast(entity_id, placeholder_entity_id); | ||
} | ||
|
||
auto UEcsactUnrealEventsCollector::GetCEVC() | ||
-> ecsact_execution_events_collector* { | ||
return &evc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "ecsact/runtime/common.h" | ||
#include "EcsactUnrealEventsCollector.generated.h" | ||
|
||
UCLASS() | ||
|
||
class UEcsactUnrealEventsCollector : public UObject { | ||
GENERATED_BODY() | ||
|
||
ecsact_execution_events_collector evc; | ||
|
||
static auto OnInitComponentRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_component_id component_id, | ||
const void* component_data, | ||
void* callback_user_data | ||
) -> void; | ||
|
||
static auto OnUpdateComponentRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_component_id component_id, | ||
const void* component_data, | ||
void* callback_user_data | ||
) -> void; | ||
|
||
static auto OnRemoveComponentRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_component_id component_id, | ||
const void* component_data, | ||
void* callback_user_data | ||
) -> void; | ||
|
||
static auto OnEntityCreatedRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_placeholder_entity_id placeholder_entity_id, | ||
void* callback_user_data | ||
) -> void; | ||
|
||
static auto OnEntityDestroyedRaw( | ||
ecsact_event event, | ||
ecsact_entity_id entity_id, | ||
ecsact_placeholder_entity_id placeholder_entity_id, | ||
void* callback_user_data | ||
) -> void; | ||
|
||
public: | ||
DECLARE_MULTICAST_DELEGATE_ThreeParams( // | ||
FRawComponentEventDelegate, | ||
ecsact_entity_id, | ||
ecsact_component_id, | ||
const void* | ||
); | ||
DECLARE_MULTICAST_DELEGATE_TwoParams( // | ||
FRawEntityEventDelegate, | ||
ecsact_entity_id, | ||
ecsact_placeholder_entity_id | ||
); | ||
|
||
FRawComponentEventDelegate InitComponentRawEvent; | ||
FRawComponentEventDelegate UpdateComponentRawEvent; | ||
FRawComponentEventDelegate RemoveComponentRawEvent; | ||
|
||
FRawEntityEventDelegate CreatedEntityRawEvent; | ||
FRawEntityEventDelegate DestroyedEntityRawEvent; | ||
|
||
UEcsactUnrealEventsCollector(); | ||
|
||
/** | ||
* Get's the C `ecsact_execution_events_collector` pointer typically passed to | ||
* `ecsact_execute_systems` or `ecsact_async_flush_events`. The lifetime of | ||
* this pointer is the same as the owning `EcsactUnrealEventsCollector`. | ||
*/ | ||
auto GetCEVC() -> ecsact_execution_events_collector*; | ||
}; |