Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
Changes to try and fix loading system and compatibility issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
seiggy committed Aug 4, 2015
1 parent 57c6de1 commit 24097aa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
2 changes: 1 addition & 1 deletion TLM/TLM/CustomAI/CustomCargoTruckAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void RemoveOffers(ushort vehicleId, ref Vehicle data)
}
}

protected void BaseSimulationStep(ushort vehicleId, ref Vehicle data, Vector3 physicsLodRefPos)
private void BaseSimulationStep(ushort vehicleId, ref Vehicle data, Vector3 physicsLodRefPos)
{
if ((data.m_flags & Vehicle.Flags.WaitingPath) != Vehicle.Flags.None)
{
Expand Down
8 changes: 8 additions & 0 deletions TLM/TLM/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class Log

public static void Message(object s)
{
#if DEBUG
try
{
if (InGameDebug)
Expand All @@ -21,10 +22,12 @@ public static void Message(object s)
// cross thread issue?
}
Debug.Log(Prefix + s.ToString());
#endif
}

public static void Error(object s)
{
#if DEBUG
try
{
if (InGameDebug)
Expand All @@ -35,10 +38,12 @@ public static void Error(object s)
// cross thread issue?
}
Debug.LogError(Prefix + s.ToString());
#endif
}

public static void Warning(object s)
{
#if DEBUG
try
{
if (InGameDebug)
Expand All @@ -49,14 +54,17 @@ public static void Warning(object s)
// cross thread issue?
}
Debug.LogWarning(Prefix + s.ToString());
#endif
}


internal static void Warning(InstanceType instanceType)
{
#if DEBUG
if (InGameDebug)
DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Warning, Prefix);
Debug.LogWarning(Prefix);
#endif
}
}

Expand Down
55 changes: 44 additions & 11 deletions TLM/TLM/SerializableDataExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ private void DeserializeData(byte[] data)
}
ConfigLoaded = true;

//LoadDataState();
//StateLoaded = true;

Log.Message("Setting timer to load data.");
var timer = new Timer(5000);
var timer = new Timer(1500);
timer.Elapsed += (sender, args) =>
{
if (!ConfigLoaded || StateLoaded) return;
Expand Down Expand Up @@ -279,20 +282,41 @@ var segmentData in
catch (Exception e)
{
// ignore as it's probably bad save data.
//Log.Warning("Error setting the NodeTrafficLights: " + e.Message);
Log.Warning("Error setting the NodeTrafficLights: " + e.Message);
}
}


// For Traffic++ compatibility
if (!LoadingExtension.IsPathManagerCompatibile)
return;

Log.Message($"LaneFlags: {_configuration.LaneFlags}");
var lanes = _configuration.LaneFlags.Split(',');

if (lanes.Length <= 1)
return;
foreach (var split in lanes.Select(lane => lane.Split(':')).Where(split => split.Length > 1))
{
Log.Message($"Split Data: {split[0]} , {split[1]}");
Singleton<NetManager>.instance.m_lanes.m_buffer[Convert.ToInt32(split[0])].m_flags =
Convert.ToUInt16(split[1]);
try
{
Log.Message($"Split Data: {split[0]} , {split[1]}");
var laneIndex = Convert.ToInt32(split[0]);

//make sure we don't cause any overflows because of bad save data.
if (Singleton<NetManager>.instance.m_lanes.m_buffer.Length <= laneIndex)
continue;

if (Convert.ToInt32(split[1]) > ushort.MaxValue)
continue;

Singleton<NetManager>.instance.m_lanes.m_buffer[Convert.ToInt32(split[0])].m_flags =
Convert.ToUInt16(split[1]);
}
catch (Exception e)
{
Log.Error(
$"Error loading Lane Split data. Length: {split.Length} value: {split}\nError: {e.Message}");
}
}
}

Expand Down Expand Up @@ -414,15 +438,24 @@ public override void OnSaveData()
Convert.ToInt16((nodeFlags & NetNode.Flags.Junction) != NetNode.Flags.None);
}

for (var i = 0; i < Singleton<NetManager>.instance.m_lanes.m_buffer.Length; i++)
// Traffic++ compatibility
if (LoadingExtension.IsPathManagerCompatibile)
{
var laneSegment = Singleton<NetManager>.instance.m_lanes.m_buffer[i].m_segment;

if (TrafficPriority.PrioritySegments.ContainsKey(laneSegment))
for (var i = 0; i < Singleton<NetManager>.instance.m_lanes.m_buffer.Length; i++)
{
configuration.LaneFlags += i + ":" + Singleton<NetManager>.instance.m_lanes.m_buffer[i].m_flags + ",";
var laneSegment = Singleton<NetManager>.instance.m_lanes.m_buffer[i].m_segment;

if (TrafficPriority.PrioritySegments.ContainsKey(laneSegment))
{
configuration.LaneFlags += i + ":" + Singleton<NetManager>.instance.m_lanes.m_buffer[i].m_flags +
",";
}
}
}
else
{
configuration.LaneFlags = "";
}

var binaryFormatter = new BinaryFormatter();
var memoryStream = new MemoryStream();
Expand Down
4 changes: 3 additions & 1 deletion TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
Expand Down

0 comments on commit 24097aa

Please sign in to comment.