Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Fix bug where CommandSender would not reenable after being disabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Brynes authored Jul 17, 2020
1 parent bfe5c43 commit 593bc38
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

- Fixed a bug in the Worker Inspector where component foldouts were being rendered too often, causing poor performance when the entity had many components or very complex components. [#1403](https://github.com/spatialos/gdk-for-unity/pull/1403)
- Fixed minor indentation issue in generated code caused by newline formatting. [#1424](https://github.com/spatialos/gdk-for-unity/pull/1424)
- Fixed a bug where `CommandSender` objects would not be made valid again after being _re-injected_. [#1429](https://github.com/spatialos/gdk-for-unity/pull/1429)

### Internal

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using Improbable.Gdk.Core;
using Improbable.Gdk.PlayerLifecycle;
using Improbable.Gdk.Subscriptions;
using Improbable.Gdk.Test;
using Improbable.Gdk.TestUtils;
using Improbable.Worker.CInterop;
using NUnit.Framework;
using UnityEngine;


namespace Improbable.Gdk.EditmodeTests
{
[TestFixture]
public class RequireablesReenableTests : MockBase
{
private const long EntityId = 100;

[Test]
public void CommandSenders_and_Receivers_are_valid_after_reinjection()
{
World
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate()))
.Step(world =>
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
.Step(world =>
{
var (_, behaviour) = world.CreateGameObject<CommandSenderReceiverTestBehaviour>(EntityId);
return behaviour;
})
.Step((world, behaviour) =>
{
Assert.IsNotNull(behaviour.CommandReceiver);
Assert.IsNotNull(behaviour.CommandSender);
Assert.IsTrue(behaviour.CommandReceiver.IsValid);
Assert.IsTrue(behaviour.CommandSender.IsValid);
})
.Step(world =>
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.NotAuthoritative))
.Step((world, behaviour) =>
{
Assert.IsNull(behaviour.CommandReceiver);
Assert.IsNull(behaviour.CommandSender);
})
.Step(world =>
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
.Step((world, behaviour) =>
{
Assert.IsNotNull(behaviour.CommandReceiver);
Assert.IsNotNull(behaviour.CommandSender);
Assert.IsTrue(behaviour.CommandReceiver.IsValid);
Assert.IsTrue(behaviour.CommandSender.IsValid);
});
}

[Test]
public void Readers_and_Writers_are_valid_after_reinjection()
{
World
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate()))
.Step(world =>
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
.Step(world =>
{
var (_, behaviour) = world.CreateGameObject<ReaderWriterTestBehaviour>(EntityId);
return behaviour;
})
.Step((world, behaviour) =>
{
Assert.IsNotNull(behaviour.Writer);
Assert.IsNotNull(behaviour.Reader);
Assert.IsTrue(behaviour.Writer.IsValid);
Assert.IsTrue(behaviour.Reader.IsValid);
})
.Step(world =>
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.NotAuthoritative))
.Step((world, behaviour) =>
{
Assert.IsNull(behaviour.Writer);
Assert.IsNull(behaviour.Reader);
})
.Step(world =>
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
.Step((world, behaviour) =>
{
Assert.IsNotNull(behaviour.Writer);
Assert.IsNotNull(behaviour.Reader);
Assert.IsTrue(behaviour.Writer.IsValid);
Assert.IsTrue(behaviour.Reader.IsValid);
});
}

private static EntityTemplate GetTemplate()
{
var template = new EntityTemplate();
template.AddComponent(new Position.Snapshot(), "worker");
template.AddComponent(new TestCommands.Snapshot(), "worker");
return template;
}

private class CommandSenderReceiverTestBehaviour : MonoBehaviour
{
#pragma warning disable 649
[Require] public TestCommandsCommandReceiver CommandReceiver;
[Require] public PlayerHeartbeatClientCommandSender CommandSender;
#pragma warning restore 649
}

private class ReaderWriterTestBehaviour : MonoBehaviour
{
#pragma warning disable 649
[Require] public TestCommandsWriter Writer;
[Require] public TestCommandsReader Reader;
#pragma warning restore 649
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@

namespace Improbable.Gdk.Subscriptions
{
public interface ICommandSender
public interface ICommandSender : IRequireable
{
bool IsValid { get; set; }
void RemoveAllCallbacks();
}

public interface ICommandReceiver
public interface ICommandReceiver : IRequireable
{
bool IsValid { get; set; }
void RemoveAllCallbacks();
}

public abstract class CommandSenderSubscriptionManagerBase<T> : SubscriptionManager<T>
Expand Down

0 comments on commit 593bc38

Please sign in to comment.