public static bool applyLaneArrowFlags(uint laneId, bool check = true) { if (laneId <= 0) { return(true); } uint laneFlags = (uint)Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags; if (check && !mayHaveLaneArrows(laneId)) { return(false); } LaneArrows?hwArrows = highwayLaneArrowFlags[laneId]; LaneArrows?arrows = laneArrowFlags[laneId]; if (hwArrows != null) { laneFlags &= ~lfr; // remove all arrows laneFlags |= (uint)hwArrows; // add highway arrows } else if (arrows != null) { LaneArrows flags = (LaneArrows)arrows; laneFlags &= ~lfr; // remove all arrows laneFlags |= (uint)flags; // add desired arrows } //Log._Debug($"Setting lane flags @ lane {laneId}, seg. {Singleton<NetManager>.instance.m_lanes.m_buffer[laneId].m_segment} to {((NetLane.Flags)laneFlags).ToString()}"); Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags = Convert.ToUInt16(laneFlags); return(true); }
public static bool toggleLaneArrowFlags(uint laneId, LaneArrows flags) { if (!mayHaveLaneArrows(laneId)) { removeLaneArrowFlags(laneId); return(false); } if (highwayLaneArrowFlags[laneId] != null) { return(false); // disallow custom lane arrows in highway rule mode } LaneArrows?arrows = laneArrowFlags[laneId]; if (arrows == null) { // read currently defined arrows uint laneFlags = (uint)Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags; laneFlags &= lfr; // filter arrows arrows = (LaneArrows)laneFlags; } arrows ^= flags; laneArrowFlags[laneId] = arrows; applyLaneArrowFlags(laneId, false); return(true); }
public List <Configuration.LaneArrowData> SaveData(ref bool success) { var ret = new List <Configuration.LaneArrowData>(); for (uint i = 0; i < Singleton <NetManager> .instance.m_lanes.m_buffer.Length; i++) { try { LaneArrows?laneArrows = Flags.GetLaneArrowFlags(i); if (laneArrows == null) { continue; } uint laneArrowInt = (uint)laneArrows; #if DEBUGSAVE Log._Debug($"Saving lane arrows for lane {i}, setting to {laneArrows} ({laneArrowInt})"); #endif ret.Add(new Configuration.LaneArrowData(i, laneArrowInt)); } catch (Exception e) { Log.Error($"Exception occurred while saving lane arrows @ {i}: {e}"); success = false; } } return(ret); }
public static bool ToggleLaneArrowFlags(uint laneId, bool startNode, LaneArrows flags, out SetLaneArrowError res) { if (!CanHaveLaneArrows(laneId)) { RemoveLaneArrowFlags(laneId); res = SetLaneArrowError.Invalid; return(false); } if (highwayLaneArrowFlags[laneId] != null) { res = SetLaneArrowError.HighwayArrows; return(false); // disallow custom lane arrows in highway rule mode } if (LaneConnectionManager.Instance.HasConnections(laneId, startNode)) { // TODO refactor res = SetLaneArrowError.LaneConnection; return(false); // custom lane connection present } LaneArrows?arrows = laneArrowFlags[laneId]; if (arrows == null) { // read currently defined arrows uint laneFlags = Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags; laneFlags &= lfr; // filter arrows arrows = (LaneArrows)laneFlags; } arrows ^= flags; laneArrowFlags[laneId] = arrows; if (ApplyLaneArrowFlags(laneId, false)) { res = SetLaneArrowError.Success; return(true); } res = SetLaneArrowError.Invalid; return(false); }
public static bool ApplyLaneArrowFlags(uint laneId, bool check = true) { #if DEBUGFLAGS Log._Debug($"Flags.applyLaneArrowFlags({laneId}, {check}) called"); #endif if (laneId <= 0) { return(true); } if (check && !CanHaveLaneArrows(laneId)) { RemoveLaneArrowFlags(laneId); return(false); } LaneArrows?hwArrows = highwayLaneArrowFlags[laneId]; LaneArrows?arrows = laneArrowFlags[laneId]; uint laneFlags = Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags; if (hwArrows != null) { laneFlags &= ~lfr; // remove all arrows laneFlags |= (uint)hwArrows; // add highway arrows } else if (arrows != null) { LaneArrows flags = (LaneArrows)arrows; laneFlags &= ~lfr; // remove all arrows laneFlags |= (uint)flags; // add desired arrows } #if DEBUGFLAGS Log._Debug($"Flags.applyLaneArrowFlags: Setting lane flags of lane {laneId} to " + $"{(NetLane.Flags)laneFlags}"); #endif Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags = Convert.ToUInt16(laneFlags); return(true); }
public static LaneArrows GetFinalLaneArrowFlags(uint laneId, bool check = true) { if (!CanHaveLaneArrows(laneId)) { #if DEBUGFLAGS Log._Debug($"Lane {laneId} may not have lane arrows"); #endif return(LaneArrows.None); } uint ret = 0; LaneArrows?hwArrows = highwayLaneArrowFlags[laneId]; LaneArrows?arrows = laneArrowFlags[laneId]; if (hwArrows != null) { ret &= ~lfr; // remove all arrows ret |= (uint)hwArrows; // add highway arrows } else if (arrows != null) { LaneArrows flags = (LaneArrows)arrows; ret &= ~lfr; // remove all arrows ret |= (uint)flags; // add desired arrows } else { Constants.ServiceFactory.NetService.ProcessLane( laneId, delegate(uint lId, ref NetLane lane) { ret = lane.m_flags; ret &= (uint)LaneArrows.LeftForwardRight; return(true); }); } return((LaneArrows)ret); }
public void Record() { arrows_ = Flags.GetLaneArrowFlags(LaneId); }