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: async connect/disconnect subsystem #16

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunner.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "EcsactUnreal/EcsactRunner.h"
#include "EcsactUnreal/EcsactAsyncRunnerEvents.h"
#include "EcsactUnreal/EcsactUnrealExecutionOptions.h"
#include "UObject/ObjectMacros.h"
#include "UObject/UObjectIterator.h"
Expand Down Expand Up @@ -45,6 +46,10 @@ auto UEcsactRunner::IsStopped() const -> bool {
return bIsStopped;
}

auto UEcsactRunner::HasAsyncEvents() const -> bool {
return Cast<IEcsactAsyncRunnerEvents>(this) != nullptr;
}

auto UEcsactRunner::Tick(float DeltaTime) -> void {
}

Expand Down Expand Up @@ -177,6 +182,13 @@ auto UEcsactRunner::OnEntityCreatedRaw(
) -> void {
auto self = static_cast<ThisClass*>(callback_user_data);

UE_LOG(
LogTemp,
Warning,
TEXT("Received entity created callback for %i"),
static_cast<int>(entity_id)
);

auto create_callback =
self->CreateEntityCallbacks.Find(placeholder_entity_id);
if(create_callback) {
Expand Down
3 changes: 3 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class ECSACT_API UEcsactRunner : public UObject, public FTickableGameObject {
virtual auto Stop() -> void;
virtual auto IsStopped() const -> bool;

UFUNCTION(BlueprintPure)
bool HasAsyncEvents() const;

auto Tick(float DeltaTime) -> void override;
auto GetStatId() const -> TStatId override;
auto IsTickable() const -> bool override;
Expand Down
15 changes: 15 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "EcsactRunnerSubsystem.h"
#include "EcsactRunner.h"

auto UEcsactRunnerSubsystem::InitComponentRaw(
ecsact_entity_id EntityId,
Expand Down Expand Up @@ -29,6 +30,20 @@ auto UEcsactRunnerSubsystem::GetRunner() const -> const class UEcsactRunner* {
return OwningRunner;
}

auto UEcsactRunnerSubsystem::GetWorld() const -> class UWorld* {
if(OwningRunner != nullptr) {
return OwningRunner->GetWorld();
} else {
return nullptr;
}
}

auto UEcsactRunnerSubsystem::AsyncConnected_Implementation() -> void {
}

auto UEcsactRunnerSubsystem::AsyncDisconnected_Implementation() -> void {
}

auto UEcsactRunnerSubsystem::RunnerStart_Implementation(
class UEcsactRunner* Runner
) -> void {
Expand Down
21 changes: 21 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ECSACT_API UEcsactRunnerSubsystem : public UObject {
auto GetRunner() const -> const class UEcsactRunner*;

public:
auto GetWorld() const -> class UWorld* override;

UFUNCTION(BlueprintNativeEvent, Category = "Ecsact Runner")
void RunnerStart(class UEcsactRunner* Runner);

Expand All @@ -45,6 +47,25 @@ class ECSACT_API UEcsactRunnerSubsystem : public UObject {
class UEcsactRunner* Runner
) -> void;

/**
* Called when an ecsact_async_connect succeeds
* NOTE: For 'async' runners only
*/
UFUNCTION(BlueprintNativeEvent, Category = "Ecsact Runner")
void AsyncConnected();

virtual auto AsyncConnected_Implementation() -> void;

/**
* Called when an ecsact_async_disconnect is called or if an error that
* triggers a disconnect occurs.
* NOTE: For 'async' runners only
*/
UFUNCTION(BlueprintNativeEvent, Category = "Ecsact Runner")
void AsyncDisconnected();

virtual auto AsyncDisconnected_Implementation() -> void;

UFUNCTION(BlueprintNativeEvent, Category = "Ecsact Runner")
void EntityCreated(int32 Entity);

Expand Down