Skip to content

Commit

Permalink
most Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
killzoms committed Nov 23, 2023
1 parent 07d7202 commit 02dde6d
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nitrox.Test.Client.Communication;
using NitroxClient.Map;
using NitroxModel.Core;
using NitroxModel.DataStructures.GameLogic;
using NitroxModel.DataStructures.Unity;
using NitroxModel.Packets;
Expand All @@ -23,6 +24,10 @@ public class DeferredPacketReceiverTest
public void TestInitialize()
{
packetReceiver = new PacketReceiver();
ClientAutoFacRegistrar registrar = new ClientAutoFacRegistrar();
NitroxServiceLocator.InitializeDependencyContainer(registrar);
NitroxServiceLocator.BeginNewLifetimeScope();

loadedCell = new AbsoluteEntityCell(loadedActionPosition, CELL_LEVEL);
visibleCells.Add(loadedCell);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
public class DisconnectedStateTests
{
[TestMethod]
public void NegotiateShouldStartTheClientOnTheContext()
public async Task NegotiateShouldStartTheClientOnTheContext()
{
// Arrange
IClient serverClient = Substitute.For<IClient>();
Expand All @@ -29,14 +29,14 @@ public void NegotiateShouldStartTheClientOnTheContext()
Disconnected connectionState = new Disconnected();

// Act
connectionState.NegotiateReservationAsync(connectionContext).RunSynchronously();
await connectionState.NegotiateReservationAsync(connectionContext);

// Assert
serverClient.IsConnected.Should().BeTrue();
}

[TestMethod]
public void NegotiateShouldSendMultiplayerSessionPolicyRequestPacketToClient()
public async Task NegotiateShouldSendMultiplayerSessionPolicyRequestPacketToClient()
{
// Arrange
IClient serverClient = Substitute.For<IClient>();
Expand All @@ -52,14 +52,14 @@ public void NegotiateShouldSendMultiplayerSessionPolicyRequestPacketToClient()
Disconnected connectionState = new Disconnected();

// Act
connectionState.NegotiateReservationAsync(connectionContext).RunSynchronously();
await connectionState.NegotiateReservationAsync(connectionContext);

// Assert
serverClient.Received().Send(Arg.Any<MultiplayerSessionPolicyRequest>());
}

[TestMethod]
public void NegotiateShouldTransitionToEstablishingSessionPolicyState()
public async Task NegotiateShouldTransitionToEstablishingSessionPolicyState()
{
// Arrange
IClient serverClient = Substitute.For<IClient>();
Expand All @@ -75,7 +75,7 @@ public void NegotiateShouldTransitionToEstablishingSessionPolicyState()
Disconnected connectionState = new Disconnected();

// Act
connectionState.NegotiateReservationAsync(connectionContext).RunSynchronously();
await connectionState.NegotiateReservationAsync(connectionContext);

// Assert
connectionContext.Received().UpdateConnectionState(Arg.Any<EstablishingSessionPolicy>());
Expand Down
3 changes: 3 additions & 0 deletions Nitrox.Test/Model/Packets/Processors/PacketProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public void AllPacketsAreHandled()
List<Type> packetTypes = typeof(DefaultServerPacketProcessor).Assembly.GetTypes()
.Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract)
.ToList();
ServerAutoFacRegistrar serverDependencyRegistrar = new ServerAutoFacRegistrar();
NitroxServiceLocator.InitializeDependencyContainer(serverDependencyRegistrar);
NitroxServiceLocator.BeginNewLifetimeScope();

List<Type> abstractProcessorTypes = new();

Expand Down
12 changes: 6 additions & 6 deletions NitroxClient/ClientAutoFacRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
{
#if DEBUG
containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<BaseDebugger>()
.As<BaseDebugger>()
.AssignableTo<Debuggers.BaseDebugger>()
.As<Debuggers.BaseDebugger>()
.AsImplementedInterfaces()
.AsSelf()
.SingleInstance();

containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<IDrawer>()
.As<IDrawer>()
.AssignableTo<Debuggers.Drawer.IDrawer>()
.As<Debuggers.Drawer.IDrawer>()
.SingleInstance();

containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<IStructDrawer>()
.As<IStructDrawer>()
.AssignableTo<Debuggers.Drawer.IStructDrawer>()
.As<Debuggers.Drawer.IStructDrawer>()
.SingleInstance();
#endif
containerBuilder.Register(c => new NitroxProtobufSerializer($"{nameof(NitroxModel)}.dll"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BasicMovementProcessor : ClientPacketProcessor<BasicMovement>
{
public override void Process(BasicMovement movement)
{
if (!NitroxEntity.TryGetMovementControllerFrom(movement.Id, out MovementController mc) && NitroxEntity.TryGetObjectFrom(movement.Id, out GameObject gameObject))
if (!MovementController.TryGetMovementControllerFrom(movement.Id, out MovementController mc) && NitroxEntity.TryGetObjectFrom(movement.Id, out GameObject gameObject))
{
mc = gameObject.EnsureComponent<MovementController>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualW
yield break;
}

Player.main.cinematicModeActive = false;
Player.main.UpdateIsUnderwater();
}
Player.main.cinematicModeActive = false;
Player.main.UpdateIsUnderwater();
}

private void AttachPlayerToEscapePod(NitroxId escapePodId)
{
Expand All @@ -94,5 +94,4 @@ private void AttachPlayerToEscapePod(NitroxId escapePodId)

Player.main.currentEscapePod = escapePod.GetComponent<EscapePod>();
}

}
49 changes: 23 additions & 26 deletions NitroxClient/GameLogic/LocalPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class LocalPlayer : ILocalNitroxPlayer
private readonly Lazy<GameObject> body;
private readonly Lazy<GameObject> playerModel;
private readonly Lazy<GameObject> bodyPrototype;
private readonly NitroxEntity entity;
private readonly Lazy<NitroxEntity> entity;

public GameObject Body => body.Value;

Expand All @@ -38,34 +38,31 @@ public class LocalPlayer : ILocalNitroxPlayer

public Perms Permissions;

public LocalPlayer(IMultiplayerSession multiplayerSession, IPacketSender packetSender, ThrottledPacketSender throttledPacketSender)
public LocalPlayer(IMultiplayerSession multiplayerSession, IPacketSender packetSender, ThrottledPacketSender throttledPacketSender)
{
this.multiplayerSession = multiplayerSession;
this.packetSender = packetSender;
this.throttledPacketSender = throttledPacketSender;

body = new Lazy<GameObject>(() => Player.main.RequireGameObject("body"));
playerModel = new Lazy<GameObject>(() => Body.RequireGameObject("player_view"));
bodyPrototype = new Lazy<GameObject>(CreateBodyPrototype);
Permissions = Perms.PLAYER;

entity = new Lazy<NitroxEntity>(() => Player.mainObject.EnsureComponent<NitroxEntity>());
}

public void BroadcastLocation(Vector3 location, Quaternion bodyRotation, Quaternion aimingRotation, Optional<VehicleMovementData> vehicle)
{
Movement movement;
if (vehicle.HasValue)
{
this.multiplayerSession = multiplayerSession;
this.packetSender = packetSender;
this.throttledPacketSender = throttledPacketSender;
body = new Lazy<GameObject>(() => Player.main.RequireGameObject("body"));
playerModel = new Lazy<GameObject>(() => Body.RequireGameObject("player_view"));
bodyPrototype = new Lazy<GameObject>(CreateBodyPrototype);
Permissions = Perms.PLAYER;

if (!Player.mainObject.TryGetComponent(out NitroxEntity nitroxEntity))
{
nitroxEntity = Player.mainObject.AddComponent<NitroxEntity>();
}
entity = nitroxEntity;
movement = new VehicleMovement(entity.Value.Id, vehicle.Value);
}

public void BroadcastLocation(Vector3 location, Quaternion bodyRotation, Quaternion aimingRotation, Optional<VehicleMovementData> vehicle)
else
{
Movement movement;
if (vehicle.HasValue)
{
movement = new VehicleMovement(entity.Id, vehicle.Value);
}
else
{
movement = new PlayerMovement(entity.Id, location.ToDto(), bodyRotation.ToDto(), aimingRotation.ToDto());
}
movement = new PlayerMovement(entity.Value.Id, location.ToDto(), bodyRotation.ToDto(), aimingRotation.ToDto());
}

packetSender.Send(movement);
}
Expand Down
1 change: 0 additions & 1 deletion NitroxClient/GameLogic/SimulationOwnership.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void SimulateEntity(NitroxId id, SimulationLockType lockType)
public void StopSimulatingEntity(NitroxId id)
{
simulatedIdsByLockType.Remove(id);

StoppedSimulatingEntity?.Invoke(id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override IEnumerator SpawnAsync(BuildEntity entity, TaskResult<Optiona
}

#if DEBUG
Stopwatch stopwatch = Stopwatch.StartNew();
System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
#endif
GameObject newBase = UnityEngine.Object.Instantiate(BaseGhost._basePrefab, LargeWorldStreamer.main.globalRoot.transform, entity.Transform.LocalPosition.ToUnity(), entity.Transform.LocalRotation.ToUnity(), entity.Transform.LocalScale.ToUnity(), false);
if (LargeWorld.main)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public VehicleWorldEntitySpawner(Entities entities)
{
this.entities = entities;
}

public VehicleWorldEntitySpawner(SimulationOwnership simulationOwnership)
{
this.simulationOwnership = simulationOwnership;
Expand Down Expand Up @@ -173,7 +174,7 @@ private void AddCinematicControllers(GameObject gameObject)
private void RemoveConstructionAnimations(GameObject gameObject)
{
VFXConstructing[] vfxConstructions = gameObject.GetComponentsInChildren<VFXConstructing>();

foreach (VFXConstructing vfxConstructing in vfxConstructions)
{
vfxConstructing.EndGracefully();
Expand All @@ -198,19 +199,19 @@ private void DockVehicle(GameObject gameObject, GameObject parent)
return;
}

dockingBay.DockVehicle(vehicle);
dockingBay.DockVehicle(vehicle);
}

public bool SpawnsOwnChildren()
{
return false;
}

private float GetCraftDuration(TechType techType)
{
// UWE hard codes the build times into if/else logic inside ConstructorInput.Craft().

switch(techType)
switch (techType)
{
case TechType.Seamoth:
return 10f;
Expand Down
Loading

0 comments on commit 02dde6d

Please sign in to comment.