Skip to content

Commit

Permalink
Fix DeploymentConfig for simulation players
Browse files Browse the repository at this point in the history
  • Loading branch information
JerritEic committed Jan 29, 2024
1 parent 482aed6 commit abce2e0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Runtime/Bootstrap/GameBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public List<World> CreateSimulatedClientWorlds(int numSimulatedClients, string w
{
List<World> newWorlds = new List<World>();

// 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);

Expand Down
4 changes: 2 additions & 2 deletions Runtime/Deployment/DeploymentConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}; ]";
}
}
8 changes: 3 additions & 5 deletions Runtime/Deployment/DeploymentGraph.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -125,7 +122,8 @@ public List<DeploymentConfigRPC> 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
Expand All @@ -134,7 +132,7 @@ public List<DeploymentConfigRPC> 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;
}
Expand Down
18 changes: 9 additions & 9 deletions Runtime/Deployment/DeploymentSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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};" +
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion Runtime/Player/Emulation/EmulationInitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using Unity.Networking.Transport;
using UnityEngine;

namespace PolkaDOTS.Emulation
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit abce2e0

Please sign in to comment.