Example #1
0
        public static void PositionCompressionTest(float x, float y, float z)
        {
            var defaultPositionBounds = ByteCompression.PositionBounds;

            try
            {
                var position = new Vector3(x, y, z);
                TestSinglePosition(position);
                var maxElementSize = Mathf.Max(Mathf.Abs(x), Mathf.Abs(y), Mathf.Abs(z)) * 2;
                ByteCompression.SetPositionBounds(
                    new Bounds(Vector3.zero, new Vector3(maxElementSize, maxElementSize, maxElementSize)));
                TestSinglePosition(position);
                ByteCompression.SetPositionBounds(new Bounds(position, Vector3.one));
                TestSinglePosition(position);
                ByteCompression.SetPositionBounds(
                    new Bounds(
                        new Vector3(-maxElementSize / 3, maxElementSize / 3, -maxElementSize / 5),
                        new Vector3(2 * maxElementSize, 2 * maxElementSize, 2 * maxElementSize)));
                TestSinglePosition(position);
            }
            finally
            {
                ByteCompression.SetPositionBounds(defaultPositionBounds);
            }
        }
Example #2
0
    public void Init(int?seed = null)
    {
        if (ApiManager.Instance != null)
        {
            FixedUpdateManager = ApiManager.Instance;
            IsAPI = true;
        }
        else
        {
            FixedUpdateManager = Instance;
            IsAPI = false;
        }

        controls = new SimulatorControls();
        controls.Enable();

        SimulationConfig config = null;

        if (Loader.Instance != null)
        {
            config = Loader.Instance.SimConfig;
        }

        var masterSeed = seed ?? config?.Seed ?? new System.Random().Next();

        RandomGenerator = new System.Random(masterSeed);

        //Calculate map bounds and limit position compression
        if (Loader.Instance != null && Loader.Instance.Network.IsClusterSimulation)
        {
            var mapBounds = CalculateMapBounds();
            //Add margin to the bounds
            mapBounds.size += Vector3.one * 10;
            ByteCompression.SetPositionBounds(mapBounds);
        }

        ManagerHolder = new GameObject("ManagerHolder");
        ManagerHolder.transform.SetParent(transform);
        AnalysisManager     = Instantiate(analysisManagerPrefab, ManagerHolder.transform);
        AgentManager        = Instantiate(agentManagerPrefab, ManagerHolder.transform);
        CameraManager       = Instantiate(cameraManagerPrefab, ManagerHolder.transform);
        ControllableManager = Instantiate(controllableManagerPrefab, ManagerHolder.transform);
        MapManager          = Instantiate(mapManagerPrefab, ManagerHolder.transform);
        NPCManager          = Instantiate(npcManagerPrefab, ManagerHolder.transform);
        NPCManager.InitRandomGenerator(RandomGenerator.Next());
        PedestrianManager = Instantiate(pedestrianManagerPrefab, ManagerHolder.transform);
        PedestrianManager.InitRandomGenerator(RandomGenerator.Next());
        EnvironmentEffectsManager = Instantiate(environmentEffectsManagerPrefab, ManagerHolder.transform);
        EnvironmentEffectsManager.InitRandomGenerator(RandomGenerator.Next());
        UIManager = Instantiate(uiManagerPrefab, ManagerHolder.transform);

        if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux && Application.isEditor)
        {
            // empty
        }
        else
        {
            controls.Simulator.ToggleNPCS.performed        += ctx => NPCManager.NPCActive = !NPCManager.NPCActive;
            controls.Simulator.TogglePedestrians.performed += ctx => PedestrianManager.PedestriansActive = !PedestrianManager.PedestriansActive;
            controls.Simulator.ToggleAgent.performed       += ctx =>
            {
                if (int.TryParse(ctx.control.name, out int index))
                {
                    AgentManager.SetCurrentActiveAgent(index - 1);
                }
            };
            controls.Simulator.ToggleReset.performed      += ctx => AgentManager.ResetAgent();
            controls.Simulator.ToggleControlsUI.performed += ctx => UIManager.UIActive = !UIManager.UIActive;
        }

        if (config != null)
        {
            simulationName       = config.Name;
            clusterName          = config.ClusterName;
            mapName              = config.MapName;
            NPCManager.NPCActive = config.UseTraffic;
            PedestrianManager.PedestriansActive = config.UsePedestrians;
            if (config.Agents != null)
            {
                AgentManager.SpawnAgents(config.Agents);
            }
            apiMode     = config.ApiOnly;
            headless    = config.Headless;
            interactive = config.Interactive;
            useSeed     = config.Seed.HasValue;
            npc         = config.UseTraffic;
            pedestrian  = config.UsePedestrians;
            timeOfDay   = config.TimeOfDay.ToString("HH:mm");
            rain        = config.Rain;
            wet         = config.Wetness;
            fog         = config.Fog;
            cloud       = config.Cloudiness;

            if (headless)
            {
                controls.Disable();
            }
        }
        SIM.APIOnly = apiMode;
        SIM.LogSimulation(SIM.Simulation.SimulationStart, simulationName);
        SIM.LogSimulation(SIM.Simulation.ClusterNameStart, clusterName);
        SIM.LogSimulation(SIM.Simulation.MapStart, string.IsNullOrEmpty(mapName) ? UnityEngine.SceneManagement.SceneManager.GetActiveScene().name : mapName);
        SIM.LogSimulation(SIM.Simulation.HeadlessModeStart, state: headless);
        SIM.LogSimulation(SIM.Simulation.InteractiveModeStart, state: interactive);
        SIM.LogSimulation(SIM.Simulation.UsePredefinedSeedStart, state: useSeed);
        SIM.LogSimulation(SIM.Simulation.NPCStart, state: npc);
        SIM.LogSimulation(SIM.Simulation.RandomPedestrianStart, state: pedestrian);
        SIM.LogSimulation(SIM.Simulation.TimeOfDayStart, timeOfDay == "" ? string.Format("{0:hh}:{0:mm}", TimeSpan.FromHours(EnvironmentEffectsManager.currentTimeOfDay)) : timeOfDay);
        SIM.LogSimulation(SIM.Simulation.RainStart, rain == 0f ? EnvironmentEffectsManager.rain.ToString() : rain.ToString());
        SIM.LogSimulation(SIM.Simulation.WetnessStart, wet == 0f ? EnvironmentEffectsManager.wet.ToString() : wet.ToString());
        SIM.LogSimulation(SIM.Simulation.FogStart, fog == 0f ? EnvironmentEffectsManager.fog.ToString() : fog.ToString());
        SIM.LogSimulation(SIM.Simulation.CloudinessStart, cloud == 0f ? EnvironmentEffectsManager.cloud.ToString() : cloud.ToString());
        InitSegmenationColors();
        WireframeBoxes = gameObject.AddComponent <WireframeBoxes>();
        if (Loader.Instance != null)
        {
            TimeManager.Initialize(Loader.Instance.Network.MessagesManager);
        }
        Sensors.Initialize();
        Loader.ResetMaterials(); // TODO remove Editor hack for 2019.3.3 bug once fixed
        IsInitialized = true;
    }
Example #3
0
    public void Init(int?seed = null)
    {
        if (ApiManager.Instance != null)
        {
            FixedUpdateManager = ApiManager.Instance;
            IsAPI = true;
        }
        else
        {
            FixedUpdateManager = Instance;
            IsAPI = false;
        }

        controls = new SimulatorControls();
        controls.Enable();

        SimulationConfig config = null;

        if (Loader.Instance != null)
        {
            config = Loader.Instance.SimConfig;
        }

        var masterSeed = seed ?? config?.Seed ?? new System.Random().Next();

        RandomGenerator       = new System.Random(masterSeed);
        segmentationIdMapping = new SegmentationIdMapping();

        //Calculate map bounds and limit position compression
        if (Loader.Instance != null && Loader.Instance.Network.IsClusterSimulation)
        {
            var mapBounds = CalculateMapBounds();
            //Add margin to the bounds
            mapBounds.size += Vector3.one * 50;
            ByteCompression.SetPositionBounds(mapBounds);
        }

        ManagerHolder = new GameObject("ManagerHolder");
        ManagerHolder.transform.SetParent(transform);
        BridgeMessageDispatcher = new BridgeMessageDispatcher();
        AnalysisManager         = InstantiateManager(analysisManagerPrefab, ManagerHolder.transform);
        AgentManager            = InstantiateManager(agentManagerPrefab, ManagerHolder.transform);
        CameraManager           = InstantiateManager(cameraManagerPrefab, ManagerHolder.transform);
        ControllableManager     = InstantiateManager(controllableManagerPrefab, ManagerHolder.transform);
        MapManager = InstantiateManager(mapManagerPrefab, ManagerHolder.transform);
        NPCManager = InstantiateManager(npcManagerPrefab, ManagerHolder.transform);
        NPCManager.InitRandomGenerator(RandomGenerator.Next());
        PedestrianManager = InstantiateManager(pedestrianManagerPrefab, ManagerHolder.transform);
        PedestrianManager.InitRandomGenerator(RandomGenerator.Next());
        EnvironmentEffectsManager = InstantiateManager(environmentEffectsManagerPrefab, ManagerHolder.transform);
        EnvironmentEffectsManager.InitRandomGenerator(RandomGenerator.Next());
        CustomPassManager = InstantiateManager(customPassManagerPrefab, ManagerHolder.transform);
        UIManager         = InstantiateManager(uiManagerPrefab, ManagerHolder.transform);

        controls.Simulator.ToggleNPCS.performed        += ctx => NPCManager.NPCActive = !NPCManager.NPCActive;
        controls.Simulator.TogglePedestrians.performed += ctx => PedestrianManager.PedestriansActive = !PedestrianManager.PedestriansActive;
        controls.Simulator.ToggleAgent.performed       += ctx =>
        {
            if (int.TryParse(ctx.control.name, out int index))
            {
                AgentManager.SetCurrentActiveAgent(index - 1);
            }
        };
        controls.Simulator.ToggleReset.performed      += ctx => AgentManager.ResetAgent();
        controls.Simulator.ToggleControlsUI.performed += ctx => UIManager.UIActive = !UIManager.UIActive;

        if (config != null)
        {
            simulationName       = config.Name;
            clusterName          = config.ClusterName;
            mapName              = config.MapName;
            NPCManager.NPCActive = config.UseTraffic;
            PedestrianManager.PedestriansActive = config.UsePedestrians;
            if (config.Agents != null)
            {
                AgentManager.SpawnAgents(config.Agents);
            }
            apiMode     = config.ApiOnly;
            headless    = config.Headless;
            interactive = config.Interactive;
            useSeed     = config.Seed.HasValue;
            npc         = config.UseTraffic;
            pedestrian  = config.UsePedestrians;
            timeOfDay   = config.TimeOfDay.ToString("HH:mm");
            rain        = config.Rain;
            wet         = config.Wetness;
            fog         = config.Fog;
            cloud       = config.Cloudiness;
            Damage      = config.Damage;

            if (headless)
            {
                controls.Disable();
            }
        }
        InitSegmenationColors();
        WireframeBoxes = gameObject.AddComponent <WireframeBoxes>();
        if (Loader.Instance != null)
        {
            TimeManager.Initialize(Loader.Instance.Network.MessagesManager);
        }
        Sensors.Initialize();
        IsInitialized = true;
    }