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

Implement more entities #2087

Merged
merged 6 commits into from
Dec 3, 2023
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
20 changes: 20 additions & 0 deletions Nitrox.Test/Patcher/Patches/Dynamic/Flare_Update_PatchTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using HarmonyLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NitroxTest.Patcher;

namespace NitroxPatcher.Patches.Dynamic;

[TestClass]
public class Flare_Update_PatchTest
{
[TestMethod]
public void Sanity()
{
IEnumerable<CodeInstruction> originalIl = PatchTestHelper.GetInstructionsFromMethod(Flare_Update_Patch.TARGET_METHOD);
IEnumerable<CodeInstruction> transformedIl = Flare_Update_Patch.Transpiler(originalIl);
transformedIl.Count().Should().Be(originalIl.Count());
}
}
15 changes: 15 additions & 0 deletions Nitrox.Test/Server/Serialization/WorldPersistenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ private static void EntityTest(Entity entity, Entity entityAfter)
Assert.AreEqual(metadata.TimeNextBreed, metadataAfter.TimeNextBreed);
Assert.AreEqual(metadata.BornInside, metadataAfter.BornInside);
break;
case FlareMetadata metadata when entityAfter.Metadata is FlareMetadata metadataAfter:
Assert.AreEqual(metadata.EnergyLeft, metadataAfter.EnergyLeft);
Assert.AreEqual(metadata.HasBeenThrown, metadataAfter.HasBeenThrown);
Assert.AreEqual(metadata.FlareActivateTime, metadataAfter.FlareActivateTime);
break;
case BeaconMetadata metadata when entityAfter.Metadata is BeaconMetadata metadataAfter:
Assert.AreEqual(metadata.Label, metadataAfter.Label);
break;
default:
Assert.Fail($"Runtime type of {nameof(Entity)}.{nameof(Entity.Metadata)} is not equal: {entity.Metadata?.GetType().Name} - {entityAfter.Metadata?.GetType().Name}");
break;
Expand Down Expand Up @@ -332,6 +340,13 @@ private static void EntityTest(Entity entity, Entity entityAfter)
break;
case CellRootEntity _ when worldEntityAfter is CellRootEntity _:
break;
case PlacedWorldEntity _ when worldEntityAfter is PlacedWorldEntity _:
break;
case OxygenPipeEntity oxygenPipeEntity when worldEntityAfter is OxygenPipeEntity oxygenPipeEntityAfter:
Assert.AreEqual(oxygenPipeEntity.ParentPipeId, oxygenPipeEntityAfter.ParentPipeId);
Assert.AreEqual(oxygenPipeEntity.RootPipeId, oxygenPipeEntityAfter.RootPipeId);
Assert.AreEqual(oxygenPipeEntity.ParentPosition, oxygenPipeEntityAfter.ParentPosition);
break;
case GlobalRootEntity globalRootEntity when worldEntityAfter is GlobalRootEntity globalRootEntityAfter:
if (globalRootEntity.GetType() != typeof(GlobalRootEntity))
{
Expand Down
25 changes: 13 additions & 12 deletions NitroxClient/ClientAutoFacRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void RegisterDependencies(ContainerBuilder containerBuilder)
}

RegisterCoreDependencies(containerBuilder);
RegisterMetadataDependencies(containerBuilder);
RegisterPacketProcessors(containerBuilder);
RegisterColorSwapManagers(containerBuilder);
RegisterInitialSyncProcessors(containerBuilder);
Expand Down Expand Up @@ -99,18 +100,6 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
.As<IMap>()
.InstancePerLifetimeScope();

containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<EntityMetadataExtractor>()
.As<EntityMetadataExtractor>()
.AsSelf()
.SingleInstance();

containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<EntityMetadataProcessor>()
.As<EntityMetadataProcessor>()
.AsSelf()
.SingleInstance();

containerBuilder.RegisterType<PlayerManager>().InstancePerLifetimeScope();
containerBuilder.RegisterType<PlayerModelManager>().InstancePerLifetimeScope();
containerBuilder.RegisterType<PlayerVitalsManager>().InstancePerLifetimeScope();
Expand Down Expand Up @@ -144,6 +133,18 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
containerBuilder.RegisterType<TimeManager>().InstancePerLifetimeScope();
}

private void RegisterMetadataDependencies(ContainerBuilder containerBuilder)
{
containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<EntityMetadataExtractor>()
.As<EntityMetadataExtractor>()
.InstancePerLifetimeScope();
containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<EntityMetadataProcessor>()
.As<EntityMetadataProcessor>()
.InstancePerLifetimeScope();
}

private void RegisterPacketProcessors(ContainerBuilder containerBuilder)
{
containerBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using NitroxClient.Communication.Abstract;
Expand Down Expand Up @@ -38,21 +38,17 @@ public override void Process(InitialPlayerSync packet)

private IEnumerator ProcessInitialSyncPacket(object sender, EventArgs eventArgs)
{
// Some packets should not fire during game session join but only afterwards so that initialized/spawned game objects don't trigger packet sending again.
using (PacketSuppressor<PingRenamed>.Suppress())
bool moreProcessorsToRun;
do
{
bool moreProcessorsToRun;
do
yield return Multiplayer.Main.StartCoroutine(RunPendingProcessors());

moreProcessorsToRun = alreadyRan.Count < processors.Count;
if (moreProcessorsToRun && processorsRanLastCycle == 0)
{
yield return Multiplayer.Main.StartCoroutine(RunPendingProcessors());

moreProcessorsToRun = alreadyRan.Count < processors.Count;
if (moreProcessorsToRun && processorsRanLastCycle == 0)
{
throw new Exception($"Detected circular dependencies in initial packet sync between: {GetRemainingProcessorsText()}");
}
} while (moreProcessorsToRun);
}
throw new Exception($"Detected circular dependencies in initial packet sync between: {GetRemainingProcessorsText()}");
}
} while (moreProcessorsToRun);

WaitScreen.Remove(loadingMultiplayerWaitItem);
Multiplayer.Main.InitialSyncCompleted = true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures;
using NitroxModel.Packets;
using UnityEngine;

namespace NitroxClient.Communication.Packets.Processors;

Expand Down Expand Up @@ -47,6 +48,12 @@ public override void Process(SimulationOwnershipChange simulationOwnershipChange
simulationOwnershipManager.StopSimulatingEntity(simulatedEntity.Id);
EntityPositionBroadcaster.StopWatchingEntity(simulatedEntity.Id);
}

// Avoid keeping artifacts of the entity's previous ChangesPosition state
if (!simulatedEntity.ChangesPosition && NitroxEntity.TryGetComponentFrom(simulatedEntity.Id, out RemotelyControlled remotelyControlled))
{
Object.Destroy(remotelyControlled);
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions NitroxClient/GameLogic/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NitroxClient.GameLogic.Spawning.Bases;
using NitroxClient.GameLogic.Spawning.Metadata;
using NitroxClient.GameLogic.Spawning.Metadata.Extractor;
using NitroxClient.GameLogic.Spawning.WorldEntities;
using NitroxClient.MonoBehaviours;
using NitroxClient.Unity.Helper;
using NitroxModel.DataStructures;
Expand Down Expand Up @@ -54,11 +55,13 @@ public Entities(IPacketSender packetSender, ThrottledPacketSender throttledPacke
entitySpawnersByType[typeof(EscapePodWorldEntity)] = entitySpawnersByType[typeof(WorldEntity)];
entitySpawnersByType[typeof(PlayerWorldEntity)] = entitySpawnersByType[typeof(WorldEntity)];
entitySpawnersByType[typeof(VehicleWorldEntity)] = entitySpawnersByType[typeof(WorldEntity)];
entitySpawnersByType[typeof(GlobalRootEntity)] = entitySpawnersByType[typeof(WorldEntity)];
entitySpawnersByType[typeof(GlobalRootEntity)] = new GlobalRootEntitySpawner();
entitySpawnersByType[typeof(BuildEntity)] = new BuildEntitySpawner(this);
entitySpawnersByType[typeof(ModuleEntity)] = new ModuleEntitySpawner(this);
entitySpawnersByType[typeof(GhostEntity)] = new GhostEntitySpawner();
entitySpawnersByType[typeof(InteriorPieceEntity)] = new InteriorPieceEntitySpawner(this);
entitySpawnersByType[typeof(OxygenPipeEntity)] = new OxygenPipeEntitySpawner(this, (WorldEntitySpawner)entitySpawnersByType[typeof(WorldEntity)]);
entitySpawnersByType[typeof(PlacedWorldEntity)] = new PlacedWorldEntitySpawner((WorldEntitySpawner)entitySpawnersByType[typeof(WorldEntity)]);
}

public void EntityMetadataChanged(object o, NitroxId id)
Expand Down Expand Up @@ -279,7 +282,7 @@ public Type RequireEntityType(NitroxId id)

public bool IsParentReady(NitroxId id)
{
return WasParentSpawned(id) || (NitroxEntity.TryGetObjectFrom(id, out GameObject o) && o);
return WasParentSpawned(id) || NitroxEntity.TryGetObjectFrom(id, out GameObject _);
Jannify marked this conversation as resolved.
Show resolved Hide resolved
}

public bool WasParentSpawned(NitroxId id)
Expand Down
Loading