From abce2e02cda6fc27d7e2b1fa43e50fa881e062b4 Mon Sep 17 00:00:00 2001 From: jerrit Date: Mon, 29 Jan 2024 10:12:00 +0100 Subject: [PATCH] Fix DeploymentConfig for simulation players --- Runtime/Bootstrap/GameBootstrap.cs | 2 +- Runtime/Deployment/DeploymentConfiguration.cs | 4 ++-- Runtime/Deployment/DeploymentGraph.cs | 8 +++----- Runtime/Deployment/DeploymentSystem.cs | 18 +++++++++--------- .../Player/Emulation/EmulationInitSystem.cs | 6 +++++- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Runtime/Bootstrap/GameBootstrap.cs b/Runtime/Bootstrap/GameBootstrap.cs index c590a48..7a1b400 100644 --- a/Runtime/Bootstrap/GameBootstrap.cs +++ b/Runtime/Bootstrap/GameBootstrap.cs @@ -419,7 +419,7 @@ public List CreateSimulatedClientWorlds(int numSimulatedClients, string w { List newWorlds = new List(); - // Re-use Netcode for Entities ThinClient systems + // Re-use Netcode for EntitiesSim ThinClient systems //var thinClientSystems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.ThinClientSimulation); var thinClientSystems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.ClientSimulation); diff --git a/Runtime/Deployment/DeploymentConfiguration.cs b/Runtime/Deployment/DeploymentConfiguration.cs index 45a8a95..6bfcf79 100644 --- a/Runtime/Deployment/DeploymentConfiguration.cs +++ b/Runtime/Deployment/DeploymentConfiguration.cs @@ -118,7 +118,7 @@ public class WorldConfig // The ID of the node that this world (if it is a streamed client) will connect to. Can be this node, but why would you do that? public int streamingNodeID; // The number of simulated clients to create and connect. Only valid if worldType is SimulatedClient - public int numSimulatedClient; + public int numSimulatedClients; // Names of server service Types, handled according to serviceFilterType public string[] services; // How the service names are handled when instantiating this world @@ -128,6 +128,6 @@ public class WorldConfig public override string ToString() => $"[worldType: {worldType}; multiplayStreamingRoles: {multiplayStreamingRoles}; serverNodeID: {serverNodeID}; streamingNodeID: {streamingNodeID};" + - $"numSimulatedClients: {numSimulatedClient}; services: {services}; serviceFilterType: {serviceFilterType}; emulationType: {emulationType}; ]"; + $"numSimulatedClients: {numSimulatedClients}; services: {services}; serviceFilterType: {serviceFilterType}; emulationType: {emulationType}; ]"; } } \ No newline at end of file diff --git a/Runtime/Deployment/DeploymentGraph.cs b/Runtime/Deployment/DeploymentGraph.cs index b2ba2a4..f8b8ccc 100644 --- a/Runtime/Deployment/DeploymentGraph.cs +++ b/Runtime/Deployment/DeploymentGraph.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using PolkaDOTS.Configuration; using Unity.Collections; using Unity.Entities; -using Unity.NetCode; using Unity.Networking.Transport; -using Unity.VisualScripting; using UnityEngine; using WebSocketSharp; @@ -125,7 +122,8 @@ public List NodeToConfigRPCs(int nodeID) cRPC.worldType = worldConfig.worldType; cRPC.multiplayStreamingRoles = worldConfig.multiplayStreamingRoles; - + cRPC.numSimulatedClients = worldConfig.numSimulatedClients; + if (worldConfig.serverNodeID == node.id) cRPC.serverIP = "127.0.0.1"; else @@ -134,7 +132,7 @@ public List NodeToConfigRPCs(int nodeID) var serverNode = Nodes[worldConfig.serverNodeID]; // If that node is the one this system is running on, tell the remote to use our ip FixedString64Bytes endpoint = serverNode.endpoint; - if (worldConfig.serverNodeID == ApplicationConfig.DeploymentID && node.id != ApplicationConfig.DeploymentID ) + if (worldConfig.serverNodeID == ApplicationConfig.DeploymentID.Value && node.id != ApplicationConfig.DeploymentID.Value ) endpoint = "source"; cRPC.serverIP = endpoint; } diff --git a/Runtime/Deployment/DeploymentSystem.cs b/Runtime/Deployment/DeploymentSystem.cs index 2240977..d191b2f 100644 --- a/Runtime/Deployment/DeploymentSystem.cs +++ b/Runtime/Deployment/DeploymentSystem.cs @@ -46,14 +46,16 @@ public struct DeploymentConfigRPC : IRpcCommand // Multiplay streaming host/guest public FixedString64Bytes signallingIP; - public int numThinClients; + public int numSimulatedClients; + // todo // Names of server service Types, handled according to serviceFilterType // public string[] services; // How the service names are handled when instantiating this world // public ServiceFilterType serviceFilterType; + // The player emulation behaviour to use on a client world - //public EmulationType emulationType; + public EmulationType emulationType; /*public override string ToString() => $"[nodeID: { nodeID}; worldTypes: {(WorldTypes)worldTypes}; numThinClients: {numThinClients};" + @@ -203,7 +205,7 @@ protected override void OnUpdate() // Handle timing events double elapsed = World.Time.ElapsedTime - _startTime; - if (elapsed > ApplicationConfig.Duration) + if (ApplicationConfig.Duration > 0 && elapsed > ApplicationConfig.Duration) { Debug.Log($"[{DateTime.Now.TimeOfDay}]: Experiment duration of {ApplicationConfig.Duration.Value} seconds elapsed! Exiting."); BootstrapInstance.instance.ExitGame(); @@ -404,7 +406,7 @@ protected override void OnUpdate() commandBuffer.Playback(EntityManager); - if (_configReceived && (World.Time.ElapsedTime - _startTime) > ApplicationConfig.Duration) + if (ApplicationConfig.Duration > 0 && _configReceived && (World.Time.ElapsedTime - _startTime) > ApplicationConfig.Duration) { Debug.Log($"[{DateTime.Now.TimeOfDay}]: Experiment duration of {ApplicationConfig.Duration} seconds elapsed! Exiting."); BootstrapInstance.instance.ExitGame(); @@ -454,26 +456,24 @@ public static void HandleDeploymentConfigRPC(DeploymentConfigRPC cRPC, NetworkEn { string addr = sourceConn.WithPort(0).ToString(); cRPC.serverIP = addr.Substring(0, addr.Length - 2); - // todo remove this if (cRPC.serverIP == "127.0.0.1") { - cRPC.serverIP = new FixedString64Bytes(ApplicationConfig.ServerUrl); + cRPC.serverIP = new FixedString64Bytes(ApplicationConfig.ServerUrl.Value); } } if (cRPC.signallingIP == "source") { string addr = sourceConn.WithPort(0).ToString(); cRPC.signallingIP = addr.Substring(0, addr.Length - 2); - // todo remove this if (cRPC.signallingIP == "127.0.0.1") { - cRPC.serverIP = new FixedString64Bytes(ApplicationConfig.SignalingUrl); + cRPC.signallingIP = new FixedString64Bytes(ApplicationConfig.SignalingUrl.Value); } } if (create) { - BootstrapInstance.instance.SetupWorlds(cRPC.multiplayStreamingRoles, playTypes, ref newWorlds, cRPC.numThinClients, + BootstrapInstance.instance.SetupWorlds(cRPC.multiplayStreamingRoles, playTypes, ref newWorlds, cRPC.numSimulatedClients, autoStart: start, autoConnect: connect,cRPC.serverIP.ToString(), cRPC.serverPort,cRPC.signallingIP.ToString(), cRPC.worldName.ToString()); } else if (start) { diff --git a/Runtime/Player/Emulation/EmulationInitSystem.cs b/Runtime/Player/Emulation/EmulationInitSystem.cs index 0ba12d6..913485e 100644 --- a/Runtime/Player/Emulation/EmulationInitSystem.cs +++ b/Runtime/Player/Emulation/EmulationInitSystem.cs @@ -3,6 +3,7 @@ using Unity.Collections; using Unity.Entities; using Unity.NetCode; +using Unity.Networking.Transport; using UnityEngine; namespace PolkaDOTS.Emulation @@ -24,7 +25,6 @@ protected override void OnCreate() protected override void OnUpdate() { - // todo use coroutines Emulation emulation = EmulationSingleton.Instance; Multiplay.Multiplay multiplay = MultiplaySingleton.Instance; if (emulation is null || multiplay is null) @@ -37,6 +37,10 @@ protected override void OnUpdate() Enabled = false; emulation.emulationType = ApplicationConfig.EmulationType; + if (World.Unmanaged.IsSimulatedClient()) + { + emulation.emulationType = EmulationType.Simulation; + } Debug.Log($"Emulation type is {emulation.emulationType}"); // Multiplay guest emulation only supports input playback