Esempio n. 1
0
        public void Execute(JSONNode args)
        {
            var api = ApiManager.Instance;
            var sim = SimulatorManager.Instance;

            var timeScale = args["time_scale"];

            if (timeScale == null || timeScale.IsNull)
            {
                api.TimeScale = 1f;
            }
            else
            {
                api.TimeScale = timeScale.AsFloat;
            }

            SimulatorManager.SetTimeScale(api.TimeScale);

            var timeLimit = args["time_limit"].AsFloat;

            if (timeLimit != 0)
            {
                var frameLimit = (int)(timeLimit / Time.fixedDeltaTime);
                api.FrameLimit = api.CurrentFrame + frameLimit;
            }
            else
            {
                api.FrameLimit = 0;
            }

            sim.AnalysisManager.AnalysisInit();
        }
Esempio n. 2
0
        public void Execute(JSONNode args)
        {
            var api = ApiManager.Instance;

            var timeScale = args["time_scale"];

            if (timeScale == null || timeScale.IsNull)
            {
                api.TimeScale = 1f;
            }
            else
            {
                api.TimeScale = timeScale.AsFloat;
            }

            SimulatorManager.SetTimeScale(api.TimeScale);

            var timeLimit = args["time_limit"].AsFloat;

            if (timeLimit != 0)
            {
                var frameLimit = (int)(timeLimit / Time.fixedDeltaTime);
                api.FrameLimit = api.CurrentFrame + frameLimit;
            }
            else
            {
                api.FrameLimit = 0;
            }

            SIM.LogAPI(SIM.API.SimulationRun, timeLimit.ToString());
        }
Esempio n. 3
0
        public void Reset()
        {
            Events.Clear();

            Agents.Clear();
            AgentUID.Clear();
            Sensors.Clear();
            SensorUID.Clear();
            Controllables.Clear();
            ControllablesUID.Clear();

            Collisions.Clear();
            Waypoints.Clear();
            StopLine.Clear();
            LaneChange.Clear();

            StopAllCoroutines();

            var sim = SimulatorManager.Instance;

            sim.AgentManager.Reset();
            sim.NPCManager.Reset();
            sim.PedestrianManager.Reset();
            sim.EnvironmentEffectsManager.Reset();
            sim.MapManager.Reset();
            sim.CurrentFrame = 0;
            sim.GTIDs        = 0;
            sim.SignalIDs    = 0;

            FrameLimit   = 0;
            CurrentTime  = 0.0;
            CurrentFrame = 0;

            SimulatorManager.SetTimeScale(0.0f);
        }
Esempio n. 4
0
        public void OnRunCommand(Commands.Run run)
        {
            Debug.Assert(ClientState == State.Ready);
            ClientState = State.Running;

            SimulatorManager.SetTimeScale(1.0f);
        }
Esempio n. 5
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. 6
0
        void OnDestroy()
        {
            if (Server != null)
            {
                Server.Stop();
                Server = null;
            }

            Instance = null;
            SimulatorManager.SetTimeScale(1.0f);
            Loader.Instance.Network.MessagesManager?.UnregisterObject(this);
            ApiLock.Deinitialize();
        }
Esempio n. 7
0
        void OnDestroy()
        {
            if (Server != null)
            {
                Server.Stop();
                Server = null;
            }

            Instance = null;
            SimulatorManager.SetTimeScale(1.0f);
            SIM.LogAPI(SIM.API.SimulationDestroy);
            SIM.APIOnly = false;
        }
Esempio n. 8
0
        void OnDestroy()
        {
            if (Server != null)
            {
                Server.Stop();
                Server = null;
            }

            Instance = null;
            SimulatorManager.SetTimeScale(1.0f);
            SIM.LogAPI(SIM.API.SimulationDestroy);
            SIM.APIOnly = false;
            Loader.Instance.Network.MessagesManager?.UnregisterObject(this);
        }
Esempio n. 9
0
        public async Task Reset()
        {
            await SimulatorManager.Instance.AnalysisManager.AnalysisSave();

            Events.Clear();
            Agents.Clear();
            AgentUID.Clear();
            if (SimulatorManager.InstanceAvailable)
            {
                SimulatorManager.Instance.Sensors.ClearSensorsRegistry();
            }
            AgentFollowingWaypoints.Clear();

            Collisions.Clear();
            Waypoints.Clear();
            StopLine.Clear();
            LaneChange.Clear();
            Destinations.Clear();

            StopAllCoroutines();

            var sim = SimulatorManager.Instance;

            sim.AgentManager.Reset();
            sim.NPCManager.Reset();
            sim.PedestrianManager.Reset();
            sim.EnvironmentEffectsManager.Reset();
            sim.ControllableManager.Reset();
            sim.MapManager.Reset();
            sim.CameraManager.Reset();
            sim.UIManager.Reset();

            sim.CurrentFrame = 0;
            sim.GTIDs        = 0;
            sim.SignalIDs    = 0;

            FrameLimit   = 0;
            CurrentTime  = 0.0;
            CurrentFrame = 0;

            SimulatorManager.SetTimeScale(0.0f);

            Resources.UnloadUnusedAssets();
#if UNITY_EDITOR
            UnityEditor.EditorUtility.UnloadUnusedAssetsImmediate();
#endif
        }
Esempio n. 10
0
        public void Execute(JSONNode args)
        {
            var api = ApiManager.Instance;

            var timeScale = args["time_scale"];

            if (timeScale == null || timeScale.IsNull)
            {
                api.TimeScale = 1f;
            }
            else
            {
                api.TimeScale = timeScale.AsFloat;
            }

            SimulatorManager.SetTimeScale(api.TimeScale);

            var timeLimit = args["time_limit"].AsFloat;

            if (timeLimit != 0)
            {
                var frameLimit = (int)(timeLimit / Time.fixedDeltaTime);
                api.FrameLimit = api.CurrentFrame + frameLimit;
            }
            else
            {
                api.FrameLimit = 0;
            }

            //Start the scenario runner here
            var use_case_id  = args["use_case_id"].AsInt;
            var scenario_id  = args["scenario_id"].AsInt;
            var test_case_id = args["test_case_id"].AsInt;

            //ArrayList results;
            SimulatorManager.Instance.Scenario_Config(use_case_id, scenario_id, test_case_id);
            // var results_json = new JSONArray();

            // foreach(String result in results)
            // {
            //     results_json.Add(new JSONString(result));
            // }
            // api.SendResult(results_json);
            SIM.LogAPI(SIM.API.SimulationRun, timeLimit.ToString());
        }
Esempio n. 11
0
        public void Reset()
        {
            Events.Clear();

            Agents.Clear();
            AgentUID.Clear();
            Sensors.Clear();
            SensorUID.Clear();
            Controllables.Clear();
            ControllablesUID.Clear();

            Collisions.Clear();
            Waypoints.Clear();
            StopLine.Clear();
            LaneChange.Clear();

            StopAllCoroutines();

            var sim = SimulatorManager.Instance;

            sim.AgentManager.Reset();
            sim.NPCManager.Reset();
            sim.PedestrianManager.Reset();
            sim.EnvironmentEffectsManager.Reset();
            sim.ControllableManager.Reset();
            sim.MapManager.Reset();
            sim.CameraManager.Reset();
            sim.UIManager.Reset();

            sim.CurrentFrame = 0;
            sim.GTIDs        = 0;
            sim.SignalIDs    = 0;

            FrameLimit   = 0;
            CurrentTime  = 0.0;
            CurrentFrame = 0;

            SimulatorManager.SetTimeScale(0.0f);

            Resources.UnloadUnusedAssets();
#if UNITY_EDITOR
            UnityEditor.EditorUtility.UnloadUnusedAssetsImmediate();
#endif
        }
Esempio n. 12
0
        void FixedUpdate()
        {
            if (Events.Count != 0)
            {
                var events = new JSONArray();
                for (int i = 0; i < Events.Count; i++)
                {
                    events[i] = Events[i];
                }
                Events.Clear();

                var msg = new JSONObject();
                msg["events"] = events;

                SendResult(msg);

                SimulatorManager.SetTimeScale(0.0f);
                return;
            }

            if (Time.timeScale != 0.0f)
            {
                if (FrameLimit != 0 && CurrentFrame >= FrameLimit)
                {
                    SimulatorManager.SetTimeScale(0.0f);
                    SendResult();
                }
                else
                {
                    CurrentTime  += Time.fixedDeltaTime;
                    CurrentFrame += 1;

                    if (!CurrentScene.IsNullOrEmpty())
                    {
                        SimulatorManager.Instance.PhysicsUpdate();
                    }
                }
            }
        }
Esempio n. 13
0
 public void Execute(JSONNode args)
 {
     SimulatorManager.SetTimeScale(ApiManager.Instance.TimeScale);
 }