From e7774836f68f55b27590eb35ac8af854486ea7d6 Mon Sep 17 00:00:00 2001 From: Craxy Date: Fri, 17 Apr 2015 19:57:20 +0200 Subject: [PATCH] fixes #14: Not a valid NetNode Exception additional: contains some tests for highlighting of all intersections (WIP; does not work) --- ToggleTrafficLights.sln | 1 + src/ToggleTrafficLights/Game/Options.cs | 10 + .../Game/UI/HighlightTest.cs | 376 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 8 +- .../ToggleTrafficLights.csproj | 5 +- .../Tools/DefaultToolWithNetNodeDetection.cs | 1 + .../Tools/ToggleTrafficLightsTool.cs | 135 ++++--- .../Utils/Extensions/ArrayExtensions.cs | 32 -- src/ToggleTrafficLights/Utils/MeshHelper.cs | 110 +++++ src/ToggleTrafficLights/Utils/Tuple.cs | 22 + 10 files changed, 605 insertions(+), 95 deletions(-) create mode 100644 src/ToggleTrafficLights/Game/Options.cs create mode 100644 src/ToggleTrafficLights/Game/UI/HighlightTest.cs delete mode 100644 src/ToggleTrafficLights/Utils/Extensions/ArrayExtensions.cs create mode 100644 src/ToggleTrafficLights/Utils/MeshHelper.cs create mode 100644 src/ToggleTrafficLights/Utils/Tuple.cs diff --git a/ToggleTrafficLights.sln b/ToggleTrafficLights.sln index 345c7f3..383aeb4 100644 --- a/ToggleTrafficLights.sln +++ b/ToggleTrafficLights.sln @@ -7,6 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DBCE62E6-905 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7773097-D1BB-4231-BBF7-13C1821F3744}" ProjectSection(SolutionItems) = preProject + build.fsx = build.fsx README.md = README.md EndProjectSection EndProject diff --git a/src/ToggleTrafficLights/Game/Options.cs b/src/ToggleTrafficLights/Game/Options.cs new file mode 100644 index 0000000..01a155d --- /dev/null +++ b/src/ToggleTrafficLights/Game/Options.cs @@ -0,0 +1,10 @@ + +namespace Craxy.CitiesSkylines.ToggleTrafficLights.Game +{ + public static class Options + { + #region ToggleTrafficLightsTool + public static bool HighlightAllIntersections = true; + #endregion + } +} \ No newline at end of file diff --git a/src/ToggleTrafficLights/Game/UI/HighlightTest.cs b/src/ToggleTrafficLights/Game/UI/HighlightTest.cs new file mode 100644 index 0000000..f5158e2 --- /dev/null +++ b/src/ToggleTrafficLights/Game/UI/HighlightTest.cs @@ -0,0 +1,376 @@ +using System.Linq; +using ColossalFramework; +using Craxy.CitiesSkylines.ToggleTrafficLights.Tools; +using Craxy.CitiesSkylines.ToggleTrafficLights.Utils; +using JetBrains.Annotations; +using UnityEngine; + +namespace Craxy.CitiesSkylines.ToggleTrafficLights.Game.UI +{ + public class HighlightTest : ToolBase + { + + #region fields + private Vector2 _scrollPosition; + #endregion + + #region MonoBehaviour + + protected override void Awake() + { + DebugLog.Info("HighlightTest: Awake"); + } + + protected override void OnDestroy() + { + DebugLog.Info("HighlightTest: OnDestroy"); + } + + protected override void OnEnable() + { + DebugLog.Info("HighlightTest: OnEnable"); + } + + protected override void OnDisable() + { + DebugLog.Info("HighlightTest: OnDisable"); + } + + +// protected override void OnToolGUI() +// { +// +// const float left = 0f; +// const float top = 50f; +// const float width = 225f; +// const float height = 510f; +// const float padding = 5f; +// +// +// GUILayout.BeginArea(new Rect(left, top, width, height)); +// +// var bgTexture = new Texture2D(1, 1); +// bgTexture.SetPixel(0, 0, new Color(0.321f, 0.321f, 0.321f, 1.0f)); +// bgTexture.Apply(); +// GUI.Box(new Rect(0f, 0f, width, height), bgTexture); +// { +// GUILayout.BeginArea(new Rect(padding, padding, width - 2 * padding, height - 2 * padding)); +// _scrollPosition = GUILayout.BeginScrollView(_scrollPosition); +// +// GUILayout.Label("Highlight stuff"); +// +// GUILayout.Space(10f); +// +// +// +// +// +// GUILayout.Space(10f); +// +// GUILayout.Label("Statistics:"); +// GUILayout.Label("Number of"); +// if (_statistics == null || _updateStatisticsCounter++ >= UpdateStatisticsEveryNthUpdate) +// { +// _statistics = Statistics.Collect(); +// _updateStatisticsCounter = 0; +// } +// _statistics.DrawGuiTable(); +// +// GUILayout.Space(10f); +// +// GUILayout.Label("Batch Commands:"); +// if (GUILayout.Button("Remove all Traffic Lights")) +// { +// RemoveAllTrafficLights(); +// } +// if (GUILayout.Button("Add all Traffic Lights")) +// { +// AddAllTrafficLights(); +// } +// if (GUILayout.Button("Reset all to default")) +// { +// ResetAllTrafficLights(); +// } +// +// GUILayout.Space(5f); +// if (_changedStatistics != null && _updateChangedStatisticsCounter > 0) +// { +// _changedStatistics.DrawGuiTable(); +// _updateChangedStatisticsCounter--; +// } +// +// GUILayout.EndScrollView(); +// GUILayout.EndArea(); +// } +// +// GUILayout.EndArea(); +// } + + + public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) + { + base.RenderOverlay(cameraInfo); + + HighlightAllIntersections(); + } + + #endregion + + + + #region Highlighting + private void HighlightAllIntersections() + { + var nodes = Singleton.instance.m_nodes.m_buffer + .Where(n => !n.m_flags.IsFlagSet(NetNode.Flags.None)) + .Where(n => n.m_flags.IsFlagSet(NetNode.Flags.Junction)) + .Where(ToggleTrafficLightsTool.IsValidRoadNode); + + var bm = Singleton.instance; + + var material = new Material(bm.m_properties.m_highlightMaterial) + { + color = Color.red + }; + var mesh = CreateHighlightMesh(); + var id = Shader.PropertyToID("_BuildingSize"); + + + foreach (var node in nodes) + { + var info = node.Info; + + + + var d = info.m_halfWidth * 2; + var position = node.m_position; + + var v = new Vector3(15f, 15f, 15f); + + material.SetVector(id, v); + + + if (material.SetPass(0)) + { + ++Singleton.instance.m_drawCallData.m_overlayCalls; + Graphics.DrawMeshNow(mesh, position, Quaternion.AngleAxis(0, Vector3.down)); + } + + } + } + private Mesh CreateHighlightMesh() + { + //Source: BuildingManager + + var m = new Mesh(); + + + //http://wiki.unity3d.com/index.php/ProceduralPrimitives#C.23_-_Tube + + + return m; + + + //4 corners + Vector3[] vector3Array1 = new Vector3[8]; + int[] numArray1 = new int[24]; + int num1 = 0; + int num2 = 0; + Vector3[] vector3Array2 = vector3Array1; + int index1 = num1; + int num3 = 1; + int num4 = index1 + num3; + vector3Array2[index1] = new Vector3(-0.5f, 0.0f, -0.5f); + Vector3[] vector3Array3 = vector3Array1; + int index2 = num4; + int num5 = 1; + int num6 = index2 + num5; + vector3Array3[index2] = new Vector3(-0.5f, 0.0f, 0.5f); + Vector3[] vector3Array4 = vector3Array1; + int index3 = num6; + int num7 = 1; + int num8 = index3 + num7; + vector3Array4[index3] = new Vector3(0.5f, 0.0f, 0.5f); + Vector3[] vector3Array5 = vector3Array1; + int index4 = num8; + int num9 = 1; + int num10 = index4 + num9; + vector3Array5[index4] = new Vector3(0.5f, 0.0f, -0.5f); + Vector3[] vector3Array6 = vector3Array1; + int index5 = num10; + int num11 = 1; + int num12 = index5 + num11; + vector3Array6[index5] = new Vector3(-0.5f, 1f, -0.5f); + Vector3[] vector3Array7 = vector3Array1; + int index6 = num12; + int num13 = 1; + int num14 = index6 + num13; + vector3Array7[index6] = new Vector3(-0.5f, 1f, 0.5f); + Vector3[] vector3Array8 = vector3Array1; + int index7 = num14; + int num15 = 1; + int num16 = index7 + num15; + vector3Array8[index7] = new Vector3(0.5f, 1f, 0.5f); + Vector3[] vector3Array9 = vector3Array1; + int index8 = num16; + int num17 = 1; + int num18 = index8 + num17; + vector3Array9[index8] = new Vector3(0.5f, 1f, -0.5f); + int[] numArray2 = numArray1; + int index9 = num2; + int num19 = 1; + int num20 = index9 + num19; + int num21 = num18 - 8; + numArray2[index9] = num21; + int[] numArray3 = numArray1; + int index10 = num20; + int num22 = 1; + int num23 = index10 + num22; + int num24 = num18 - 4; + numArray3[index10] = num24; + int[] numArray4 = numArray1; + int index11 = num23; + int num25 = 1; + int num26 = index11 + num25; + int num27 = num18 - 7; + numArray4[index11] = num27; + int[] numArray5 = numArray1; + int index12 = num26; + int num28 = 1; + int num29 = index12 + num28; + int num30 = num18 - 7; + numArray5[index12] = num30; + int[] numArray6 = numArray1; + int index13 = num29; + int num31 = 1; + int num32 = index13 + num31; + int num33 = num18 - 4; + numArray6[index13] = num33; + int[] numArray7 = numArray1; + int index14 = num32; + int num34 = 1; + int num35 = index14 + num34; + int num36 = num18 - 3; + numArray7[index14] = num36; + int[] numArray8 = numArray1; + int index15 = num35; + int num37 = 1; + int num38 = index15 + num37; + int num39 = num18 - 7; + numArray8[index15] = num39; + int[] numArray9 = numArray1; + int index16 = num38; + int num40 = 1; + int num41 = index16 + num40; + int num42 = num18 - 3; + numArray9[index16] = num42; + int[] numArray10 = numArray1; + int index17 = num41; + int num43 = 1; + int num44 = index17 + num43; + int num45 = num18 - 6; + numArray10[index17] = num45; + int[] numArray11 = numArray1; + int index18 = num44; + int num46 = 1; + int num47 = index18 + num46; + int num48 = num18 - 6; + numArray11[index18] = num48; + int[] numArray12 = numArray1; + int index19 = num47; + int num49 = 1; + int num50 = index19 + num49; + int num51 = num18 - 3; + numArray12[index19] = num51; + int[] numArray13 = numArray1; + int index20 = num50; + int num52 = 1; + int num53 = index20 + num52; + int num54 = num18 - 2; + numArray13[index20] = num54; + int[] numArray14 = numArray1; + int index21 = num53; + int num55 = 1; + int num56 = index21 + num55; + int num57 = num18 - 6; + numArray14[index21] = num57; + int[] numArray15 = numArray1; + int index22 = num56; + int num58 = 1; + int num59 = index22 + num58; + int num60 = num18 - 2; + numArray15[index22] = num60; + int[] numArray16 = numArray1; + int index23 = num59; + int num61 = 1; + int num62 = index23 + num61; + int num63 = num18 - 5; + numArray16[index23] = num63; + int[] numArray17 = numArray1; + int index24 = num62; + int num64 = 1; + int num65 = index24 + num64; + int num66 = num18 - 5; + numArray17[index24] = num66; + int[] numArray18 = numArray1; + int index25 = num65; + int num67 = 1; + int num68 = index25 + num67; + int num69 = num18 - 2; + numArray18[index25] = num69; + int[] numArray19 = numArray1; + int index26 = num68; + int num70 = 1; + int num71 = index26 + num70; + int num72 = num18 - 1; + numArray19[index26] = num72; + int[] numArray20 = numArray1; + int index27 = num71; + int num73 = 1; + int num74 = index27 + num73; + int num75 = num18 - 5; + numArray20[index27] = num75; + int[] numArray21 = numArray1; + int index28 = num74; + int num76 = 1; + int num77 = index28 + num76; + int num78 = num18 - 1; + numArray21[index28] = num78; + int[] numArray22 = numArray1; + int index29 = num77; + int num79 = 1; + int num80 = index29 + num79; + int num81 = num18 - 8; + numArray22[index29] = num81; + int[] numArray23 = numArray1; + int index30 = num80; + int num82 = 1; + int num83 = index30 + num82; + int num84 = num18 - 8; + numArray23[index30] = num84; + int[] numArray24 = numArray1; + int index31 = num83; + int num85 = 1; + int num86 = index31 + num85; + int num87 = num18 - 1; + numArray24[index31] = num87; + int[] numArray25 = numArray1; + int index32 = num86; + int num88 = 1; + int num89 = index32 + num88; + int num90 = num18 - 4; + numArray25[index32] = num90; + var mesh = new Mesh + { + vertices = vector3Array1, + triangles = numArray1, + bounds = new Bounds(new Vector3(0.0f, 256f, 0.0f), new Vector3(128f, 512f, 128f)) + }; + + + return mesh; + } + #endregion + + } +} \ No newline at end of file diff --git a/src/ToggleTrafficLights/Properties/AssemblyInfo.cs b/src/ToggleTrafficLights/Properties/AssemblyInfo.cs index 2e440fd..3c65ea7 100644 --- a/src/ToggleTrafficLights/Properties/AssemblyInfo.cs +++ b/src/ToggleTrafficLights/Properties/AssemblyInfo.cs @@ -33,9 +33,9 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] #if DEBUG -[assembly: AssemblyVersion("0.4.2.*")] -[assembly: AssemblyFileVersion("0.4.2.*")] +[assembly: AssemblyVersion("0.4.3.*")] +[assembly: AssemblyFileVersion("0.4.3.*")] #else -[assembly: AssemblyVersion("0.4.2")] -[assembly: AssemblyFileVersion("0.4.2")] +[assembly: AssemblyVersion("0.4.3")] +[assembly: AssemblyFileVersion("0.4.3")] #endif diff --git a/src/ToggleTrafficLights/ToggleTrafficLights.csproj b/src/ToggleTrafficLights/ToggleTrafficLights.csproj index bb39bc7..14f811f 100644 --- a/src/ToggleTrafficLights/ToggleTrafficLights.csproj +++ b/src/ToggleTrafficLights/ToggleTrafficLights.csproj @@ -59,7 +59,9 @@ + + @@ -83,11 +85,12 @@ - + + diff --git a/src/ToggleTrafficLights/Tools/DefaultToolWithNetNodeDetection.cs b/src/ToggleTrafficLights/Tools/DefaultToolWithNetNodeDetection.cs index 6311c4d..d844ca8 100644 --- a/src/ToggleTrafficLights/Tools/DefaultToolWithNetNodeDetection.cs +++ b/src/ToggleTrafficLights/Tools/DefaultToolWithNetNodeDetection.cs @@ -1,4 +1,5 @@ using ColossalFramework; +using Craxy.CitiesSkylines.ToggleTrafficLights.Utils; namespace Craxy.CitiesSkylines.ToggleTrafficLights.Tools { diff --git a/src/ToggleTrafficLights/Tools/ToggleTrafficLightsTool.cs b/src/ToggleTrafficLights/Tools/ToggleTrafficLightsTool.cs index 7111540..5fff146 100644 --- a/src/ToggleTrafficLights/Tools/ToggleTrafficLightsTool.cs +++ b/src/ToggleTrafficLights/Tools/ToggleTrafficLightsTool.cs @@ -1,7 +1,7 @@ using System; using ColossalFramework; -using ColossalFramework.Steamworks; using Craxy.CitiesSkylines.ToggleTrafficLights.Utils; +using JetBrains.Annotations; using UnityEngine; namespace Craxy.CitiesSkylines.ToggleTrafficLights.Tools @@ -9,6 +9,8 @@ namespace Craxy.CitiesSkylines.ToggleTrafficLights.Tools public class ToggleTrafficLightsTool : DefaultToolWithNetNodeDetection { #region Start/End + + [UsedImplicitly] private void Start() { DebugLog.Message("ToggleTrafficLightsTool start"); @@ -46,14 +48,16 @@ protected override void OnToolUpdate() { base.OnToolUpdate(); - if (!m_toolController.IsInsideUI && Cursor.visible && IsValidRoadNode()) + var nodeId = GetCurrentNetNodeId(); + + if (!m_toolController.IsInsideUI && Cursor.visible && IsValidRoadNode(nodeId)) { - var node = GetNetNode(); + var node = GetNetNode(nodeId); var hasTrafficLight = CitiesHelper.HasTrafficLights(node.m_flags); var txt = string.Join("\n", new[] { string.Format("Traffic lights: {0}", hasTrafficLight), - string.Format(" Original: {0}", WantTrafficLights()), + string.Format(" Original: {0}", WantTrafficLights(nodeId)), #if DEBUG string.Format(" Node: {0}", m_hoverInstance.NetNode), @@ -71,22 +75,24 @@ protected override void OnToolGUI() { base.OnToolGUI(); - if (!m_toolController.IsInsideUI && Cursor.visible && IsValidRoadNode()) + var nodeId = GetCurrentNetNodeId(); + + if (!m_toolController.IsInsideUI && Cursor.visible && IsValidRoadNode(nodeId)) { var current = Event.current; //button=0 -> left click if (current.type == EventType.MouseDown && current.button == 0) { - ToggleTrafficLights(); + ToggleTrafficLights(nodeId); } else if (current.type == EventType.MouseDown && current.button == 1) { - var wantLights = WantTrafficLights(); - var hasLights = HasTrafficLights(GetNetNode().m_flags); + var wantLights = WantTrafficLights(nodeId); + var hasLights = HasTrafficLights(GetNetNode(nodeId).m_flags); if (hasLights != wantLights) { - ToggleTrafficLights(); + ToggleTrafficLights(nodeId); } } } @@ -96,28 +102,40 @@ public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) { base.RenderOverlay(cameraInfo); - if (IsValidRoadNode()) - { - var node = GetNetNode(); - var position = node.m_position; + var nodeId = GetCurrentNetNodeId(); - var info = node.Info; +// if (Options.HighlightAllIntersections) +// { +// HighlightAllIntersections(); +// } - var color = GetToolColor(false, false); - //http://paletton.com/#uid=13r0u0k++++qKZWAF+V+VAFZWqK - if (HasTrafficLights(node.m_flags)) - { - color = new Color(0.2f, 0.749f, 0.988f, color.a); - } - else - { - color = new Color(0.0f, 0.369f, 0.525f, color.a); - } - ++Singleton.instance.m_drawCallData.m_overlayCalls; - Singleton.instance.OverlayEffect.DrawCircle(cameraInfo, color, position, info.m_halfWidth * 2, -1f, 1280f, false, false); + if (IsValidRoadNode(nodeId)) + { + HighlightNode(cameraInfo, nodeId); } } + + + #endregion + + #region overlays + private void HighlightNode(RenderManager.CameraInfo cameraInfo, int nodeId) + { + var node = GetNetNode(nodeId); + var position = node.m_position; + + var info = node.Info; + + var color = GetToolColor(false, false); + //http://paletton.com/#uid=13r0u0k++++qKZWAF+V+VAFZWqK + color = HasTrafficLights(node.m_flags) + ? new Color(0.2f, 0.749f, 0.988f, color.a) + : new Color(0.0f, 0.369f, 0.525f, color.a); + + ++Singleton.instance.m_drawCallData.m_overlayCalls; + Singleton.instance.OverlayEffect.DrawCircle(cameraInfo, color, position, info.m_halfWidth * 2, -1f, 1280f, false, false); + } #endregion #region Events @@ -135,16 +153,17 @@ protected virtual void OnOnEnabledChanged(bool isEnabled) #endregion #region Node - private bool IsValidRoadNode() + + private static bool IsValidRoadNode(int nodeId) { - if (m_hoverInstance.NetNode == 0) + if (nodeId == 0) { return false; } - //detect only road intersections - var node = GetNetNode(); + var node = GetNetNode(nodeId); return IsValidRoadNode(node); + } public static bool IsValidRoadNode(NetNode node) @@ -155,19 +174,19 @@ public static bool IsValidRoadNode(NetNode node) return ai is RoadBaseAI; } - private int GetNetNodeId() + private int GetCurrentNetNodeId() { return m_hoverInstance.NetNode; } - private NetNode GetNetNode() + private static NetNode GetNetNode(int nodeId) { - if (m_hoverInstance.NetNode == 0) + if (nodeId == 0) { throw new InvalidOperationException("Not a valid NetNode"); } - return Singleton.instance.m_nodes.m_buffer[GetNetNodeId()]; + return Singleton.instance.m_nodes.m_buffer[nodeId]; } #endregion @@ -201,38 +220,38 @@ public static NetNode.Flags UnsetTrafficLights(NetNode.Flags flags) { return flags & ~NetNode.Flags.TrafficLights; } - private void ToggleTrafficLights() + private static void ToggleTrafficLights(int nodeId) { - var node = GetNetNode(); + var node = GetNetNode(nodeId); node.m_flags = ToggleTrafficLights(node.m_flags); - Singleton.instance.m_nodes.m_buffer[GetNetNodeId()] = node; + Singleton.instance.m_nodes.m_buffer[nodeId] = node; } - private bool WantTrafficLights() + private static bool WantTrafficLights(int nodeId) { - return WantTrafficLights((ushort) GetNetNodeId(), GetNetNode()); + return WantTrafficLights((ushort) nodeId, GetNetNode(nodeId)); } public static bool WantTrafficLights(ushort nodeId, NetNode node) { //Source: RoadBaseAI.UpdateNodeFlags //seems pretty......human unfriendly.... - NetNode.Flags flags1 = node.m_flags; - uint num1 = 0U; - int num2 = 0; - NetManager instance = Singleton.instance; - int num3 = 0; - int num4 = 0; - int num5 = 0; - bool flag = ((RoadBaseAI)node.Info.GetAI()).WantTrafficLights(); - for (int index = 0; index < 8; ++index) + var flags1 = node.m_flags; + var num1 = 0U; + var num2 = 0; + var instance = Singleton.instance; + var num3 = 0; + var num4 = 0; + var num5 = 0; + var flag = ((RoadBaseAI)node.Info.GetAI()).WantTrafficLights(); + for (var index = 0; index < 8; ++index) { - ushort segment = node.GetSegment(index); - if ((int)segment != 0) + var segment = node.GetSegment(index); + if (segment != 0) { - NetInfo info = instance.m_segments.m_buffer[(int)segment].Info; - uint num6 = 1U << (int)(info.m_class.m_level & (ItemClass.Level)31); + var info = instance.m_segments.m_buffer[segment].Info; + var num6 = 1U << (int)(info.m_class.m_level & (ItemClass.Level)31); if (((int)num1 & (int)num6) == 0) { num1 |= num6; @@ -240,10 +259,10 @@ public static bool WantTrafficLights(ushort nodeId, NetNode node) } if (info.m_netAI.WantTrafficLights()) flag = true; - int forward = 0; - int backward = 0; - instance.m_segments.m_buffer[(int)segment].CountLanes(segment, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Car, ref forward, ref backward); - if ((int)instance.m_segments.m_buffer[(int)segment].m_endNode == (int)nodeId) + var forward = 0; + var backward = 0; + instance.m_segments.m_buffer[segment].CountLanes(segment, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Car, ref forward, ref backward); + if (instance.m_segments.m_buffer[segment].m_endNode == nodeId) { if (forward != 0) { @@ -260,8 +279,8 @@ public static bool WantTrafficLights(ushort nodeId, NetNode node) ++num5; } } - NetNode.Flags flags2 = num2 < 2 ? flags1 & ~NetNode.Flags.Transition : flags1 | NetNode.Flags.Transition; - NetNode.Flags flags3 = !flag || + var flags2 = num2 < 2 ? flags1 & ~NetNode.Flags.Transition : flags1 | NetNode.Flags.Transition; + var flags3 = !flag || num3 <= 2 && (num3 < 2 || num5 < 3 || num4 <= 6) || (flags2 & NetNode.Flags.Junction) == NetNode.Flags.None ? flags2 & ~NetNode.Flags.TrafficLights : flags2 | NetNode.Flags.TrafficLights; diff --git a/src/ToggleTrafficLights/Utils/Extensions/ArrayExtensions.cs b/src/ToggleTrafficLights/Utils/Extensions/ArrayExtensions.cs deleted file mode 100644 index 17caa7a..0000000 --- a/src/ToggleTrafficLights/Utils/Extensions/ArrayExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; - -namespace Craxy.CitiesSkylines.ToggleTrafficLights.Utils.Extensions -{ - public static class ArrayExtension - { - public static IEnumerable ToSeq(this Array16 arr) - { - for (int i = 0; i < arr.m_size; i++) - { - yield return arr.m_buffer[i]; - } - } - - public static IEnumerable ToSeq(this Array32 arr) - { - for (int i = 0; i < arr.m_size; i++) - { - yield return arr.m_buffer[i]; - } - } - - public static IEnumerable ToSeq(this Array8 arr) - { - for (int i = 0; i < arr.m_size; i++) - { - yield return arr.m_buffer[i]; - } - } - } - -} \ No newline at end of file diff --git a/src/ToggleTrafficLights/Utils/MeshHelper.cs b/src/ToggleTrafficLights/Utils/MeshHelper.cs new file mode 100644 index 0000000..13ef51b --- /dev/null +++ b/src/ToggleTrafficLights/Utils/MeshHelper.cs @@ -0,0 +1,110 @@ +//using System; +//using System.Linq; +//using UnityEngine; +// +//namespace Craxy.CitiesSkylines.ToggleTrafficLights.Utils +//{ +// public static class MeshHelper +// { +// public static Mesh CreateCylinder(int numberOfSides) +// { +// //http://wiki.unity3d.com/index.php/ProceduralPrimitives#C.23_-_Tube +// //http://jacksondunstan.com/articles/1924 +// //http://gamedev.stackexchange.com/questions/17214/create-vertices-indices-for-cylinder-with-triangle-strips +// +// var mesh = new Mesh(); +// +// //BuildingManager.CreateHighlightMesh +// //(-0.5,0,-0.5) to (0.5,1,0.5) +// +// //diameter: 1 +// //center: 0 +// //radius: 0.5 +// var r = 0.5f; +// //height: 1 +// var h = 1f; +// +// +// //no caps +// //top,bottom,top,bottom,top,bottom,... +// var vertices = Enumerable.Range(0, numberOfSides) +// .Select(i => (2.0f*Mathf.PI)/numberOfSides*i) +// .Select( +// rad => +// new[] +// { +// new Vector3(Mathf.Cos(rad)*0.5f, 0.5f, Mathf.Sin(rad)*0.5f), +// new Vector3(Mathf.Cos(rad)*0.5f, -0.5f, Mathf.Sin(rad)*0.5f) +// }) +// .SelectMany(v => v) +// .ToArray(); +// +// checked +// { +// for (int i = 0; i < numberOfSides; i++) +// { +// var vi = 2*i; +// +// var t1 = vi; +// var b1 = vi + 1; +// var t2 = (vi + 2)%vertices.Length; +// var b2 = (vi + 3)%vertices.Length; +// +// mesh.triangles +// +// var tri1 = new Vector3(t1, b2, b1); +// var tri2 = new Ve +// +// } +// } +// +// mesh.triangles +// +// +// +// +//// var numberOfCapVertices = numberOfSides + 1; +//// //increase for each step while iteration circle +//// var stepTheta = (Math.PI*2.0)/numberOfSides; +//// +//// //verticies +//// var vs = new Vector3[numberOfSides + 2*numberOfCapVertices + 2]; +//// //triangles +//// var ts = new int[0]; +// +// +//// //vertices index +//// var vi = 0; +//// //triangles index +//// var ti = 0; +//// +//// //TODO: sind caps überhaupt notwendig? +//// //top cap +//// for (int i = 0; i < numberOfCapVertices; i++) +//// { +//// var rad = (2.0f*Mathf.PI)/numberOfSides*i; +//// vs[vi++] = new Vector3(Mathf.Cos(rad)*0.5f, 0.5f, Mathf.Sin(rad)*0.5f); +//// } +//// //bottom cap +//// for (int i = 0; i < numberOfCapVertices; i++) +//// { +//// var rad = (2.0f*Mathf.PI)/numberOfSides*i; +//// vs[vi++] = new Vector3(Mathf.Cos(rad)*0.5f, -0.5f, Mathf.Sin(rad)*0.5f); +//// } +//// //sides +//// for (int i = 0; i < numberOfSides; i++) +//// { +//// //every side has 2 triangles +//// +//// //fetch points for side +//// var top1 = vs[i]; +//// var top2 = vs[(i + 1) % numberOfCapVertices]; +//// +//// var bot1 = vs[i + numberOfCapVertices]; +//// var bot2 = vs[(i + 1 numberOfCapVertices]; +//// } +// +// return mesh; +// } +// } +//} \ No newline at end of file diff --git a/src/ToggleTrafficLights/Utils/Tuple.cs b/src/ToggleTrafficLights/Utils/Tuple.cs new file mode 100644 index 0000000..eb21c8e --- /dev/null +++ b/src/ToggleTrafficLights/Utils/Tuple.cs @@ -0,0 +1,22 @@ +namespace Craxy.CitiesSkylines.ToggleTrafficLights.Utils +{ + public class Tuple + { + public T1 Item1 { get; private set; } + public T2 Item2 { get; private set; } + internal Tuple(T1 item1, T2 item2) + { + Item1 = item1; + Item2 = item2; + } + } + + public static class Tuple + { + public static Tuple Create(T1 item1, T2 item2) + { + var tuple = new Tuple(item1, item2); + return tuple; + } + } +} \ No newline at end of file