Skip to content

Commit

Permalink
[REFACTOR] Make Loader methods non-static
Browse files Browse the repository at this point in the history
(cherry picked from commit fb0f58d)
  • Loading branch information
heeen authored and EricBoiseLGSVL committed Aug 3, 2021
1 parent a83abe8 commit f08dd42
Showing 11 changed files with 140 additions and 140 deletions.
4 changes: 2 additions & 2 deletions Assets/Scenes/LoaderScene.unity
Git LFS file not shown
2 changes: 1 addition & 1 deletion Assets/Scripts/Api/Commands/LoadScene.cs
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ static IEnumerator LoadMapAssets(LoadScene sourceCommand, MapDetailData map, str
Loader.Instance.SimConfig.MapAssetGuid = map.AssetGuid;
}

var sim = Loader.CreateSimulatorManager();
var sim = Loader.Instance.CreateSimulatorManager();
sim.Init(seed);

if (Loader.Instance.CurrentSimulation != null)
6 changes: 3 additions & 3 deletions Assets/Scripts/Components/ConnectionUI.cs
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ public void OnQuitButtonClicked()

public void OnOfflineStartButtonClicked()
{
Loader.StartSimulation(simulationData[selectedSim]);
Loader.Instance.StartSimulation(simulationData[selectedSim]);
if (simulationData[selectedSim].ApiOnly)
{
offlineStopButton.gameObject.SetActive(true);
@@ -202,7 +202,7 @@ public void OnOfflineStartButtonClicked()

public void OnOfflineStopButtonClicked()
{
Loader.StopAsync();
Loader.Instance.StopAsync();
}

public void SetLinkingButtonActive(bool active)
@@ -263,7 +263,7 @@ public void OnUnlinkButtonClicked()

public void EnterScenarioEditor()
{
Loader.EnterScenarioEditor();
Loader.Instance.EnterScenarioEditor();
}
}
}
4 changes: 2 additions & 2 deletions Assets/Scripts/Managers/UIManager.cs
Original file line number Diff line number Diff line change
@@ -633,7 +633,7 @@ private void StopSimButtonOnClick()
private void StopSimYesButtonOnClick()
{
StopSimPanel.SetActive(false);
Loader.StopAsync();
Loader.Instance.StopAsync();
}

private void StopSimNoButtonOnClick()
@@ -643,7 +643,7 @@ private void StopSimNoButtonOnClick()

private void StopButtonOnClick()
{
Loader.StopAsync();
Loader.Instance.StopAsync();
}

public void PauseButtonOnClick()
6 changes: 3 additions & 3 deletions Assets/Scripts/Network/Client/ClientManager.cs
Original file line number Diff line number Diff line change
@@ -370,7 +370,7 @@ private IEnumerator CheckInitialTimeout()
$"{GetType().Name} could not establish the connection to the master. This client ip addresses: '{localAddressesSb}', master ip addresses: '{masterAddressesSb}', current UTC time: {DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)}.");

//Stop the simulation
Loader.StopAsync();
Loader.Instance.StopAsync();
}

/// <summary>
@@ -440,7 +440,7 @@ private void OnRunCommand(Commands.Run run)
if (State == SimulationState.Loading || State == SimulationState.Running)
return;
Debug.Assert(State == SimulationState.Ready);
Loader.StartAsync(Loader.Instance.Network.CurrentSimulation);
Loader.Instance.StartAsync(Loader.Instance.Network.CurrentSimulation);
State = SimulationState.Loading;
Log.Info(
$"{GetType().Name} received run command and started the simulation. Local UTC time: {DateTime.UtcNow}, remote UTC time: {Connection.MasterPeer.RemoteUtcTime}, time difference {Connection.MasterPeer.RemoteTimeTicksDifference}.");
@@ -458,7 +458,7 @@ private void OnStopCommand(Commands.Stop stop)

Log.Info($"{GetType().Name} received stop command and stops the simulation.");
State = SimulationState.Stopping;
Loader.StopAsync();
Loader.Instance.StopAsync();
}

/// <summary>
6 changes: 3 additions & 3 deletions Assets/Scripts/Network/Master/MasterManager.cs
Original file line number Diff line number Diff line change
@@ -335,7 +335,7 @@ private void OnClientDisconnected(IPeerManager clientPeerManager)
if (Loader.Instance.CurrentSimulation != null && State != SimulationState.Initial)
{
Log.Warning("Stopping current cluster simulation as one connection with client has been lost.");
Loader.StopAsync();
Loader.Instance.StopAsync();
}

State = SimulationState.Initial;
@@ -434,7 +434,7 @@ public void OnStopCommand(Commands.Stop stop, IPeerManager peer)
Log.Info($"{GetType().Name} received stop command and stops the simulation.");
BroadcastStopCommand();
State = SimulationState.Stopping;
Loader.StopAsync();
Loader.Instance.StopAsync();
}

/// <summary>
@@ -452,7 +452,7 @@ public void RunSimulation()
message.Type = DistributedMessageType.ReliableOrdered;
BroadcastMessage(message);

Loader.StartAsync(Loader.Instance.Network.CurrentSimulation);
Loader.Instance.StartAsync(Loader.Instance.Network.CurrentSimulation);
foreach (var clientConnection in clients)
clientConnection.State = SimulationState.Loading;
State = SimulationState.Loading;
2 changes: 1 addition & 1 deletion Assets/Scripts/ScenarioEditor/Managers/ScenarioManager.cs
Original file line number Diff line number Diff line change
@@ -309,7 +309,7 @@ private void StopInitialization()
{
isInitialized = true;
Deinitialize();
Loader.ExitScenarioEditor();
Loader.Instance.ExitScenarioEditor();
}

/// <summary>
2 changes: 1 addition & 1 deletion Assets/Scripts/ScenarioEditor/UI/FileEdit/FileEditPanel.cs
Original file line number Diff line number Diff line change
@@ -194,7 +194,7 @@ private IEnumerator DelayedExitEditor(LoadingPanel.LoadingProcess loadingProcess
{
yield return null;
loadingProcess.Update("Exiting the visual scenario editor.");
Loader.ExitScenarioEditor();
Loader.Instance.ExitScenarioEditor();
//Do not turn off loading process - loading panel will be destroyed within the scene
//loadingProcess.Update("Exited Visual scenario editor.", true);
}
23 changes: 22 additions & 1 deletion Assets/Scripts/Utilities/Utility.cs
Original file line number Diff line number Diff line change
@@ -595,10 +595,31 @@ public static Plane[] CalculateFrustum(Vector3 origin, Vector3 direction, float
new Plane(farBottomRight,farBottomLeft,farTopLeft)};
return planes;
}

public static int LoopIndex(int index, int count)
{
return (index % count + count) % count;
}

static string ByteArrayToHexString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
{
hex.AppendFormat("{0:x2}", b);
}
return hex.ToString();
}

static byte[] HexStringToByteArray(string hex)
{
int NumberChars = hex.Length;
byte[] bytes = new byte[NumberChars / 2];
for (int i = 0; i < NumberChars; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
}
}
4 changes: 2 additions & 2 deletions Assets/Scripts/Web/ConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -271,7 +271,7 @@ async Task Parse(string s)
Debug.LogException(e);
throw;
}
Loader.StartSimulation(simData);
Loader.Instance.StartSimulation(simData);
});
break;
case "Disconnect":
@@ -297,7 +297,7 @@ async Task Parse(string s)
await API.UpdateStatus("Idle", simData.Id, "");
return;
}
Loader.StopAsync();
Loader.Instance.StopAsync();
break;
default:
Debug.LogWarning($"Unknown Status '{status.ToString()}'! Disconnecting.");
Loading

0 comments on commit f08dd42

Please sign in to comment.