Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

UNR-925: exposing connection events #637

Merged
merged 19 commits into from
Feb 12, 2019

Conversation

padhansell
Copy link
Contributor

@padhansell padhansell commented Feb 5, 2019

Description

This PR exposes connection events to the user through the USpatialNetDriver (OnConnected, OnDisconnected, OnConnectionFailure). It also makes the USpatialWorkerConnection private in order to better encapsulate it and prevent people from relying on its availability - after discussing with @joshuahuburn and @improbable-valentyn, we'd like to move ownership of this in to the NetDriver down the line anyway.
Also note that the existing delegates have been converted to events so that they cannot be invoked outside of the NetDriver

Tests

This was tested manually in the editor by going through these cases:

  • starting the game
  • stopping the game
  • killing the runtime while the game is running
  • attempting to connect when the runtime is not up

Documentation

In-code comments in USpatialNetDriver

Release note

Feature: Exposed SpatialOS connection events in USpatialNetDriver

@padhansell padhansell self-assigned this Feb 5, 2019
@improbable-prow-robot improbable-prow-robot added the size/L Denotes a PR that changes 150-299 lines, ignoring generated files. label Feb 5, 2019
@padhansell padhansell added size/S Denotes a PR that changes 15-39 lines, ignoring generated files. and removed size/L Denotes a PR that changes 150-299 lines, ignoring generated files. labels Feb 5, 2019
@@ -67,7 +67,8 @@ bool USpatialGameInstance::HasSpatialNetDriver() const

void USpatialGameInstance::CreateNewSpatialWorkerConnection()
{
SpatialConnection = NewObject<USpatialWorkerConnection>();
SpatialConnection = NewObject<USpatialWorkerConnection>(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make the GameInstance the outer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always explicitly add outers to highlight who is supposed to be owning the object. Seems like that's not the case elsewhere in the codebase though so happy to change


void USpatialGameInstance::Shutdown()
{
auto World = GetWorld();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto World = GetWorld();
UWorld* World = GetWorld();

void USpatialGameInstance::Shutdown()
{
auto World = GetWorld();
if (World && SpatialConnection->IsConnected())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (World && SpatialConnection->IsConnected())
if (World != nullptr && SpatialConnection->IsConnected())

@improbable-prow-robot improbable-prow-robot added size/L Denotes a PR that changes 150-299 lines, ignoring generated files. and removed size/S Denotes a PR that changes 15-39 lines, ignoring generated files. labels Feb 5, 2019
@@ -2,6 +2,7 @@

#include "Interop/Connection/SpatialWorkerConnection.h"

#include "EngineClasses//SpatialNetDriver.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "EngineClasses//SpatialNetDriver.h"
#include "EngineClasses/SpatialNetDriver.h"

@padhansell
Copy link
Contributor Author

@Vatyx after talking with @m-samiec, i've decided to leave this logic as is for now and have raised https://improbableio.atlassian.net/browse/UNR-962 for the next bit of work

@padhansell
Copy link
Contributor Author

@Vatyx @m-samiec can you take another look at this plz

@@ -67,7 +67,8 @@ bool USpatialGameInstance::HasSpatialNetDriver() const

void USpatialGameInstance::CreateNewSpatialWorkerConnection()
{
SpatialConnection = NewObject<USpatialWorkerConnection>();
SpatialConnection = NewObject<USpatialWorkerConnection>(this);
SpatialConnection->Init(GetWorld());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to be null at the point of initilisation for StartPlayInEditorGameInstance and StartGameInstance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean World will be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen, we always have a World at this point

bIsConnected = false;

Worker_OpList* OpList = Worker_Connection_GetOpList(WorkerConnection, 0);
for (int i = 0; i < static_cast<int>(OpList->op_count); i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other place we iterate over the OpList, we use a size_t as the type for i. Could we do the same here just to be consistent?

// TODO: Move SpatialConnection ownership to NetDriver
friend class USpatialNetDriver;
UPROPERTY()
USpatialWorkerConnection* SpatialConnection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to break server travel in the deployments right? I'm not sure we want to do this at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if ownership of SpatialConnection was moved to the NetDriver that would break ServerTravel I think - how to support that would have to be part of a bigger discussion. For now, this shouldn't break anything

@DW-Sebastien
Copy link
Contributor

DW-Sebastien commented Feb 11, 2019

Hey @padhansell, I wanted to use this, but I hit an issue (might be related to the comment from @joshuahuburn above):

I don't see how to access these new events in the following way;

void UCorvusGameInstance::OnPostStart()
{
	USpatialNetDriver* spatialNetDriver = Cast<USpatialNetDriver>(GetWorld()->GetNetDriver());
	if (spatialNetDriver)
	{
		spatialNetDriver->OnConnected.AddUObject(this, &UCorvusGameInstance::OnSpatialOsConnected);
	}
}

But my problem is that the NetDriver is nullptr on the client at this stage (I call OnPostStart() at the end of StartPlayInEditorGameInstance and StartGameInstance.

On the server the NetDriver is set during StartGameInstance, and on the client I can wait until LoadCompleted where it is set... but all this is a bit cumbersome.

Copy link
Contributor

@joshuahuburn joshuahuburn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, could you also please add a release note

@padhansell
Copy link
Contributor Author

Hey @padhansell, I wanted to use this, but I hit an issue (might be related to the comment from @joshuahuburn above):

I don't see how to access these new events in the following way;

void UCorvusGameInstance::OnPostStart()
{
	USpatialNetDriver* spatialNetDriver = Cast<USpatialNetDriver>(GetWorld()->GetNetDriver());
	if (spatialNetDriver)
	{
		spatialNetDriver->OnConnected.AddUObject(this, &UCorvusGameInstance::OnSpatialOsConnected);
	}
}

But my problem is that the NetDriver is nullptr on the client at this stage (I call OnPostStart() at the end of StartPlayInEditorGameInstance and StartGameInstance.

On the server the NetDriver is set during StartGameInstance, and on the client I can wait until LoadCompleted where it is set... but all this is a bit cumbersome.

Thanks for flagging this up @DW-Sebastien. You're right that it's not an ideal flow - once connection handling has been refactored, we'll be able to expose this same functionality through core engine delegates/virtual calls and avoid this altogether

@m-samiec m-samiec merged commit 233cf40 into master Feb 12, 2019
@m-samiec m-samiec deleted the feature/UNR-925-exposing-connection-events branch February 12, 2019 14:01
Vatyx pushed a commit that referenced this pull request Feb 26, 2019
* Moving events to NetDriver

* Adding disconnection callback

* Tidying up

* Adding comments

* Adding additional check for when Spatial networking is disabled

* Addressing review comments

* Adding getter for NetDriver

* Adding TODO comment

* Adding missing declaration

* Review feedback

Co-Authored-By: padhansell <[email protected]>

* Changing iterator type

* Remove whitespace

Co-Authored-By: padhansell <[email protected]>

* Update SpatialReceiver.h

* Including World

* Changing World access

* Adding GEngine check
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
size/L Denotes a PR that changes 150-299 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants