Esempio n. 1
0
        public void OnRunCommand(Commands.Run run)
        {
            Debug.Assert(ClientState == State.Ready);
            ClientState = State.Running;

            SimulatorManager.SetTimeScale(1.0f);
        }
Esempio n. 2
0
 /// <summary>
 /// Method invoked when manager receives run command
 /// </summary>
 /// <param name="run">Received run command</param>
 private void OnRunCommand(Commands.Run run)
 {
     Debug.Assert(State == SimulationState.Ready);
     Loader.Instance.LoaderUI.DisableUI();
     SceneManager.UnloadSceneAsync(Loader.Instance.LoaderScene);
     State = SimulationState.Running;
 }
Esempio n. 3
0
        public void OnLoadResultCommand(Commands.LoadResult res, NetPeer peer)
        {
            Debug.Assert(MasterState == State.Loading);
            var client = Clients.Find(c => c.Peer == peer);

            Debug.Assert(client != null);
            Debug.Assert(client.State == State.Loading);

            if (res.Success)
            {
                Debug.Log("Client loaded");
            }
            else
            {
                // TODO: stop simulation / cancel loading for other clients
                Debug.LogError($"Client failed to load: ${res.ErrorMessage}");

                // TODO: reset all other clients

                Debug.Log($"Failed to start '{Simulation.Name}' simulation");

                // TODO: update simulation status in DB
                // simulation.Status = "Invalid";
                // db.Update(simulation);

                // NotificationManager.SendNotification("simulation", SimulationResponse.Create(simulation), simulation.Owner);

                Loader.ResetLoaderScene();

                Clients.Clear();
                return;
            }

            client.State = State.Ready;

            if (!Loader.Instance.PendingSimulation.ApiOnly.GetValueOrDefault())
            {
                if (Clients.All(c => c.State == State.Ready))
                {
                    Debug.Log("All clients are ready. Resuming time.");

                    var run = new Commands.Run();
                    foreach (var c in Clients)
                    {
                        Packets.Send(c.Peer, run, DeliveryMethod.ReliableOrdered);
                        c.State = State.Running;
                    }

                    MasterState = State.Running;

                    Loader.Instance.CurrentSimulation = Loader.Instance.PendingSimulation;
                    Loader.Instance.PendingSimulation = null;

                    SimulatorManager.SetTimeScale(1.0f);
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Method invoked when manager receives run command
 /// </summary>
 /// <param name="run">Received run command</param>
 private void OnRunCommand(Commands.Run run)
 {
     //Check if the simulation is already loading or running
     if (State == SimulationState.Loading || State == SimulationState.Running)
     {
         return;
     }
     Debug.Assert(State == SimulationState.Ready);
     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}.");
 }