SetNodeMarkers() private method

private SetNodeMarkers ( ushort nodeId, FastList nodeMarkers ) : void
nodeId ushort
nodeMarkers FastList
return void
Exemplo n.º 1
0
            public override void OnLoadData()
            {
                if ((CSLTraffic.Options & OptionsManager.ModOptions.BetaTestRoadCustomizerTool) == OptionsManager.ModOptions.None || (CSLTraffic.Options & OptionsManager.ModOptions.GhostMode) == OptionsManager.ModOptions.GhostMode)
                {
                    return;
                }

                Debug.Log("Traffic++: Loading road data!");
                byte[] data = serializableDataManager.LoadData(LANE_DATA_ID);
                if (data == null)
                {
                    Debug.Log("Traffic++: No road data to load!");
                    return;
                }

                MemoryStream memStream = new MemoryStream();

                memStream.Write(data, 0, data.Length);
                memStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    RoadManager.sm_lanes = (Lane[])binaryFormatter.Deserialize(memStream);

                    FastList <ushort> nodesList = new FastList <ushort>();
                    foreach (Lane lane in RoadManager.sm_lanes)
                    {
                        if (lane == null)
                        {
                            continue;
                        }

                        lane.UpdateArrows();
                        if (lane.ConnectionCount() > 0)
                        {
                            nodesList.Add(lane.m_nodeId);
                        }
                    }

                    RoadCustomizerTool customizerTool = ToolsModifierControl.GetTool <RoadCustomizerTool>();
                    foreach (ushort nodeId in nodesList)
                    {
                        customizerTool.SetNodeMarkers(nodeId);
                    }
                }
                catch (Exception e)
                {
                    Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " loading road data.");
                }
                finally
                {
                    memStream.Close();
                }
            }
Exemplo n.º 2
0
        public static void Initialize()
        {
            try
            {
                FastList <ushort> nodesList = new FastList <ushort>();
                var i = 0;
                foreach (Lane lane in RoadManager.sm_lanes)
                {
                    if (lane == null)
                    {
                        continue;
                    }

                    i++;
                    lane.UpdateArrows();
                    if (lane.ConnectionCount() > 0)
                    {
                        nodesList.Add(lane.m_nodeId);
                    }
                }

                Debug.Log("setting node markers for " + nodesList.m_size + " nodes with " + i + " lanes");
                RoadCustomizerTool customizerTool = ToolsModifierControl.GetTool <RoadCustomizerTool>();
                customizerTool.ClearNodeMarkers();
                foreach (ushort nodeId in nodesList)
                {
                    customizerTool.SetNodeMarkers(nodeId, true);
                }

                Debug.Log("Finished loading road data. Time: " + Time.realtimeSinceStartup);
            }
            catch (Exception e)
            {
                Debug.Log("Unexpected " + e.GetType().Name + " loading road data.");
            }
        }
Exemplo n.º 3
0
        public override void OnLoadData()
        {
            if ((TrafficMod.Options & OptionsManager.ModOptions.RoadCustomizerTool) == OptionsManager.ModOptions.None)
                return;
                

            Logger.LogInfo("Loading road data. Time: " + Time.realtimeSinceStartup);
            byte[] data = serializableDataManager.LoadData(LANE_DATA_ID);
            if (data == null)
            {
                Logger.LogInfo("No road data to load.");
                return;
            }

            MemoryStream memStream = new MemoryStream();
            memStream.Write(data, 0, data.Length);
            memStream.Position = 0;

            BinaryFormatter binaryFormatter = new BinaryFormatter()
            {
                Binder = new LaneSerializationBinder()
            };
            try
            {
                LaneManager.sm_lanes = (Lane[]) binaryFormatter.Deserialize(memStream);
                    
                FastList<ushort> nodesList = new FastList<ushort>();
                foreach (Lane lane in LaneManager.sm_lanes)
                {
                    if (lane == null)
                        continue;

                    lane.UpdateArrows();
                    if (lane.ConnectionCount() > 0)
                        nodesList.Add(lane.m_nodeId);

                    if (lane.m_speed == 0)
                    {
                        NetSegment segment = NetManager.instance.m_segments.m_buffer[NetManager.instance.m_lanes.m_buffer[lane.m_laneId].m_segment];
                        NetInfo info = segment.Info;
                        uint l = segment.m_lanes;
                        int n = 0;
                        while (l != lane.m_laneId && n < info.m_lanes.Length)
                        {
                            l = NetManager.instance.m_lanes.m_buffer[l].m_nextLane;
                            n++;
                        }

                        if (n < info.m_lanes.Length)
                            lane.m_speed = info.m_lanes[n].m_speedLimit;
                    }

                }

                RoadCustomizerTool customizerTool = ToolsModifierControl.GetTool<RoadCustomizerTool>();
                foreach (ushort nodeId in nodesList)
                    customizerTool.SetNodeMarkers(nodeId);

                Logger.LogInfo("Finished loading road data. Time: " + Time.realtimeSinceStartup);
            }
            catch (Exception e)
            {
                Logger.LogError("Unexpected " + e.GetType().Name + " loading road data.");
            }
            finally
            {
                memStream.Close();
            }
        }
Exemplo n.º 4
0
            public override void OnLoadData()
            {
                if ((CSLTraffic.Options & OptionsManager.ModOptions.BetaTestRoadCustomizerTool) == OptionsManager.ModOptions.None || (CSLTraffic.Options & OptionsManager.ModOptions.GhostMode) == OptionsManager.ModOptions.GhostMode)
                {
                    return;
                }


                Logger.LogInfo("Loading road data. Time: " + Time.realtimeSinceStartup);
                byte[] data = serializableDataManager.LoadData(LANE_DATA_ID);
                if (data == null)
                {
                    Logger.LogInfo("No road data to load.");
                    return;
                }

                MemoryStream memStream = new MemoryStream();

                memStream.Write(data, 0, data.Length);
                memStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    RoadManager.sm_lanes = (Lane[])binaryFormatter.Deserialize(memStream);

                    FastList <ushort> nodesList = new FastList <ushort>();
                    foreach (Lane lane in RoadManager.sm_lanes)
                    {
                        if (lane == null)
                        {
                            continue;
                        }

                        if ((CSLTraffic.Options & OptionsManager.ModOptions.FixCargoTrucksNotSpawning) == OptionsManager.ModOptions.FixCargoTrucksNotSpawning && lane.m_vehicleTypes == (VehicleType.ServiceVehicles | VehicleType.PassengerCar))
                        {
                            lane.m_vehicleTypes = VehicleType.All;
                        }

                        lane.UpdateArrows();
                        if (lane.ConnectionCount() > 0)
                        {
                            nodesList.Add(lane.m_nodeId);
                        }

                        if (lane.m_speed == 0)
                        {
                            NetSegment segment = NetManager.instance.m_segments.m_buffer[NetManager.instance.m_lanes.m_buffer[lane.m_laneId].m_segment];
                            NetInfo    info    = segment.Info;
                            uint       l       = segment.m_lanes;
                            int        n       = 0;
                            while (l != lane.m_laneId && n < info.m_lanes.Length)
                            {
                                l = NetManager.instance.m_lanes.m_buffer[l].m_nextLane;
                                n++;
                            }

                            if (n < info.m_lanes.Length)
                            {
                                lane.m_speed = info.m_lanes[n].m_speedLimit;
                            }
                        }
                    }

                    RoadCustomizerTool customizerTool = ToolsModifierControl.GetTool <RoadCustomizerTool>();
                    foreach (ushort nodeId in nodesList)
                    {
                        customizerTool.SetNodeMarkers(nodeId);
                    }

                    Logger.LogInfo("Finished loading road data. Time: " + Time.realtimeSinceStartup);
                }
                catch (Exception e)
                {
                    Logger.LogInfo("Unexpected " + e.GetType().Name + " loading road data.");
                }
                finally
                {
                    memStream.Close();
                }
            }