diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b7bc75a..cedde44 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -239,6 +239,7 @@ frequency: 0.2 frequencyVariance: 0.1 roads: {fileID: 1714391592} + spawnCars: 1 --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b7bc75a..cedde44 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -239,6 +239,7 @@ frequency: 0.2 frequencyVariance: 0.1 roads: {fileID: 1714391592} + spawnCars: 1 --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CameraControl.cs b/Assets/Scripts/CameraControl.cs index e043c87..79c8513 100644 --- a/Assets/Scripts/CameraControl.cs +++ b/Assets/Scripts/CameraControl.cs @@ -45,7 +45,7 @@ float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { scale += scroll * (-scrollSpeed); - scale = Mathf.Clamp(scale, -2, 2); + scale = Mathf.Clamp(scale, -2, 4); float realScale = Mathf.Pow(2, scale); transform.localScale = new Vector3(realScale, realScale, realScale); } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b7bc75a..cedde44 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -239,6 +239,7 @@ frequency: 0.2 frequencyVariance: 0.1 roads: {fileID: 1714391592} + spawnCars: 1 --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CameraControl.cs b/Assets/Scripts/CameraControl.cs index e043c87..79c8513 100644 --- a/Assets/Scripts/CameraControl.cs +++ b/Assets/Scripts/CameraControl.cs @@ -45,7 +45,7 @@ float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { scale += scroll * (-scrollSpeed); - scale = Mathf.Clamp(scale, -2, 2); + scale = Mathf.Clamp(scale, -2, 4); float realScale = Mathf.Pow(2, scale); transform.localScale = new Vector3(realScale, realScale, realScale); } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 6f80d5e..6540b77 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -107,7 +107,7 @@ float otherTraveledDistance = car.speed * time; float currentCarDistance = thisDistance - otherDistance; float projectedDistance = otherTraveledDistance - otherDistance; - float savetyDistance = 3f + speed * 1.8f; + float savetyDistance = 3.5f + speed * 1.8f; if (currentCarDistance < 0 || currentCarDistance > car.brakingDistance + savetyDistance) { return false; } @@ -124,7 +124,7 @@ } private bool isBraking() { - float stoppingDistance = brakingDistance + 3f + 1.8f * speed + 1f; + float stoppingDistance = Mathf.Max(1.8f * speed, brakingDistance + speed) + 3.5f; Road currentRoad = road; float currentRoadPosition = roadPositon; int currentRoadIndex = roadIndex; @@ -133,10 +133,10 @@ currentRoadPosition += stoppingDistance / steps; float totalDistance = stoppingDistance / steps * i; while (currentRoadPosition >= currentRoad.path.length) { - currentRoadIndex++; - if (currentRoadIndex == route.roads.Count) { + if (currentRoadIndex == route.roads.Count - 1) { goto end; } + currentRoadIndex++; currentRoadPosition -= currentRoad.path.length; currentRoad = route.roads[currentRoadIndex]; } @@ -153,7 +153,7 @@ } end: List carsToCheck = new List(); - for (int i = this.roadIndex; i < this.route.roads.Count; i++) { + for (int i = this.roadIndex; i <= currentRoadIndex; i++) { foreach (Car car in this.route.roads[i].carsOnRoute) { if (!carsToCheck.Contains(car)) { carsToCheck.Add(car); diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b7bc75a..cedde44 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -239,6 +239,7 @@ frequency: 0.2 frequencyVariance: 0.1 roads: {fileID: 1714391592} + spawnCars: 1 --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CameraControl.cs b/Assets/Scripts/CameraControl.cs index e043c87..79c8513 100644 --- a/Assets/Scripts/CameraControl.cs +++ b/Assets/Scripts/CameraControl.cs @@ -45,7 +45,7 @@ float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { scale += scroll * (-scrollSpeed); - scale = Mathf.Clamp(scale, -2, 2); + scale = Mathf.Clamp(scale, -2, 4); float realScale = Mathf.Pow(2, scale); transform.localScale = new Vector3(realScale, realScale, realScale); } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 6f80d5e..6540b77 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -107,7 +107,7 @@ float otherTraveledDistance = car.speed * time; float currentCarDistance = thisDistance - otherDistance; float projectedDistance = otherTraveledDistance - otherDistance; - float savetyDistance = 3f + speed * 1.8f; + float savetyDistance = 3.5f + speed * 1.8f; if (currentCarDistance < 0 || currentCarDistance > car.brakingDistance + savetyDistance) { return false; } @@ -124,7 +124,7 @@ } private bool isBraking() { - float stoppingDistance = brakingDistance + 3f + 1.8f * speed + 1f; + float stoppingDistance = Mathf.Max(1.8f * speed, brakingDistance + speed) + 3.5f; Road currentRoad = road; float currentRoadPosition = roadPositon; int currentRoadIndex = roadIndex; @@ -133,10 +133,10 @@ currentRoadPosition += stoppingDistance / steps; float totalDistance = stoppingDistance / steps * i; while (currentRoadPosition >= currentRoad.path.length) { - currentRoadIndex++; - if (currentRoadIndex == route.roads.Count) { + if (currentRoadIndex == route.roads.Count - 1) { goto end; } + currentRoadIndex++; currentRoadPosition -= currentRoad.path.length; currentRoad = route.roads[currentRoadIndex]; } @@ -153,7 +153,7 @@ } end: List carsToCheck = new List(); - for (int i = this.roadIndex; i < this.route.roads.Count; i++) { + for (int i = this.roadIndex; i <= currentRoadIndex; i++) { foreach (Car car in this.route.roads[i].carsOnRoute) { if (!carsToCheck.Contains(car)) { carsToCheck.Add(car); diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 1de8e19..419ffb2 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using System.Globalization; +using System; public class Config : MonoBehaviour { public Material roadMaterial, roadEditMaterial, carBrakingMaterial, carAccelerationMaterial; @@ -21,12 +22,12 @@ private string roadNetworkFileName, outputFileName; private float time; public Transform roads; - + public bool spawnCars = true; private static string getCLIArgumentValue(string name) { string[] arguments = System.Environment.GetCommandLineArgs(); - for (int i = 0; i < arguments.Length; i++) { - if (arguments[i] == name && arguments.Length > i + 1) { + for (int i = 0; i < arguments.Length - 1; i++) { + if (arguments[i] == name) { return arguments[i + 1]; } } @@ -47,16 +48,32 @@ private void Start() { roadNetworkFileName = getCLIArgumentValue("-i"); outputFileName = getCLIArgumentValue("-o"); - string timeString = getCLIArgumentValue("-t"); if (roadNetworkFileName.Length > 0) { LoadButton.loadRoadNetworkFromFile(roadNetworkFileName, this); } + string timeString = getCLIArgumentValue("-t"); if (timeString.Length > 0) { time = float.Parse(timeString, CultureInfo.InvariantCulture.NumberFormat); } else { time = float.PositiveInfinity; } + string frequencyString = getCLIArgumentValue("-f"); + if (frequencyString.Length > 0) { + frequency = float.Parse(frequencyString, CultureInfo.InvariantCulture.NumberFormat); + } + string redTimeString = getCLIArgumentValue("-red"); + if (redTimeString.Length > 0) { + trafficLights.redTime = float.Parse(redTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string greenTimeString = getCLIArgumentValue("-green"); + if (greenTimeString.Length > 0) { + trafficLights.greenTime = float.Parse(greenTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string invertLightsString = getCLIArgumentValue("-invert"); + if (invertLightsString.Length > 0) { + trafficLights.invert = bool.Parse(invertLightsString); + } } private void Update() { @@ -65,7 +82,9 @@ } time -= Time.deltaTime; if (time <= 0) { - SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + if (outputFileName.Length > 0) { + SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + } Application.Quit(); } } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b7bc75a..cedde44 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -239,6 +239,7 @@ frequency: 0.2 frequencyVariance: 0.1 roads: {fileID: 1714391592} + spawnCars: 1 --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CameraControl.cs b/Assets/Scripts/CameraControl.cs index e043c87..79c8513 100644 --- a/Assets/Scripts/CameraControl.cs +++ b/Assets/Scripts/CameraControl.cs @@ -45,7 +45,7 @@ float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { scale += scroll * (-scrollSpeed); - scale = Mathf.Clamp(scale, -2, 2); + scale = Mathf.Clamp(scale, -2, 4); float realScale = Mathf.Pow(2, scale); transform.localScale = new Vector3(realScale, realScale, realScale); } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 6f80d5e..6540b77 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -107,7 +107,7 @@ float otherTraveledDistance = car.speed * time; float currentCarDistance = thisDistance - otherDistance; float projectedDistance = otherTraveledDistance - otherDistance; - float savetyDistance = 3f + speed * 1.8f; + float savetyDistance = 3.5f + speed * 1.8f; if (currentCarDistance < 0 || currentCarDistance > car.brakingDistance + savetyDistance) { return false; } @@ -124,7 +124,7 @@ } private bool isBraking() { - float stoppingDistance = brakingDistance + 3f + 1.8f * speed + 1f; + float stoppingDistance = Mathf.Max(1.8f * speed, brakingDistance + speed) + 3.5f; Road currentRoad = road; float currentRoadPosition = roadPositon; int currentRoadIndex = roadIndex; @@ -133,10 +133,10 @@ currentRoadPosition += stoppingDistance / steps; float totalDistance = stoppingDistance / steps * i; while (currentRoadPosition >= currentRoad.path.length) { - currentRoadIndex++; - if (currentRoadIndex == route.roads.Count) { + if (currentRoadIndex == route.roads.Count - 1) { goto end; } + currentRoadIndex++; currentRoadPosition -= currentRoad.path.length; currentRoad = route.roads[currentRoadIndex]; } @@ -153,7 +153,7 @@ } end: List carsToCheck = new List(); - for (int i = this.roadIndex; i < this.route.roads.Count; i++) { + for (int i = this.roadIndex; i <= currentRoadIndex; i++) { foreach (Car car in this.route.roads[i].carsOnRoute) { if (!carsToCheck.Contains(car)) { carsToCheck.Add(car); diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 1de8e19..419ffb2 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using System.Globalization; +using System; public class Config : MonoBehaviour { public Material roadMaterial, roadEditMaterial, carBrakingMaterial, carAccelerationMaterial; @@ -21,12 +22,12 @@ private string roadNetworkFileName, outputFileName; private float time; public Transform roads; - + public bool spawnCars = true; private static string getCLIArgumentValue(string name) { string[] arguments = System.Environment.GetCommandLineArgs(); - for (int i = 0; i < arguments.Length; i++) { - if (arguments[i] == name && arguments.Length > i + 1) { + for (int i = 0; i < arguments.Length - 1; i++) { + if (arguments[i] == name) { return arguments[i + 1]; } } @@ -47,16 +48,32 @@ private void Start() { roadNetworkFileName = getCLIArgumentValue("-i"); outputFileName = getCLIArgumentValue("-o"); - string timeString = getCLIArgumentValue("-t"); if (roadNetworkFileName.Length > 0) { LoadButton.loadRoadNetworkFromFile(roadNetworkFileName, this); } + string timeString = getCLIArgumentValue("-t"); if (timeString.Length > 0) { time = float.Parse(timeString, CultureInfo.InvariantCulture.NumberFormat); } else { time = float.PositiveInfinity; } + string frequencyString = getCLIArgumentValue("-f"); + if (frequencyString.Length > 0) { + frequency = float.Parse(frequencyString, CultureInfo.InvariantCulture.NumberFormat); + } + string redTimeString = getCLIArgumentValue("-red"); + if (redTimeString.Length > 0) { + trafficLights.redTime = float.Parse(redTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string greenTimeString = getCLIArgumentValue("-green"); + if (greenTimeString.Length > 0) { + trafficLights.greenTime = float.Parse(greenTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string invertLightsString = getCLIArgumentValue("-invert"); + if (invertLightsString.Length > 0) { + trafficLights.invert = bool.Parse(invertLightsString); + } } private void Update() { @@ -65,7 +82,9 @@ } time -= Time.deltaTime; if (time <= 0) { - SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + if (outputFileName.Length > 0) { + SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + } Application.Quit(); } } diff --git a/Assets/Scripts/Roads/Node/SpawnNodeData.cs b/Assets/Scripts/Roads/Node/SpawnNodeData.cs index 55e2a3e..2c81d1e 100644 --- a/Assets/Scripts/Roads/Node/SpawnNodeData.cs +++ b/Assets/Scripts/Roads/Node/SpawnNodeData.cs @@ -12,7 +12,7 @@ timeLeft = Random.Range(1 / (config.frequency * (1 - config.frequencyVariance)), 1 / (config.frequency * (1 + config.frequencyVariance))); ExitNodeData target = targets[Random.Range(0, targets.Count)]; Route route = new Route(node, target.node); - bool canSummon = route.isValid; + bool canSummon = route.isValid && config.spawnCars; foreach (Car car in route.roads[0].carsOnRoute) { if (car.roadPositon <= 3f) { canSummon = false; diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b7bc75a..cedde44 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -239,6 +239,7 @@ frequency: 0.2 frequencyVariance: 0.1 roads: {fileID: 1714391592} + spawnCars: 1 --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CameraControl.cs b/Assets/Scripts/CameraControl.cs index e043c87..79c8513 100644 --- a/Assets/Scripts/CameraControl.cs +++ b/Assets/Scripts/CameraControl.cs @@ -45,7 +45,7 @@ float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { scale += scroll * (-scrollSpeed); - scale = Mathf.Clamp(scale, -2, 2); + scale = Mathf.Clamp(scale, -2, 4); float realScale = Mathf.Pow(2, scale); transform.localScale = new Vector3(realScale, realScale, realScale); } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 6f80d5e..6540b77 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -107,7 +107,7 @@ float otherTraveledDistance = car.speed * time; float currentCarDistance = thisDistance - otherDistance; float projectedDistance = otherTraveledDistance - otherDistance; - float savetyDistance = 3f + speed * 1.8f; + float savetyDistance = 3.5f + speed * 1.8f; if (currentCarDistance < 0 || currentCarDistance > car.brakingDistance + savetyDistance) { return false; } @@ -124,7 +124,7 @@ } private bool isBraking() { - float stoppingDistance = brakingDistance + 3f + 1.8f * speed + 1f; + float stoppingDistance = Mathf.Max(1.8f * speed, brakingDistance + speed) + 3.5f; Road currentRoad = road; float currentRoadPosition = roadPositon; int currentRoadIndex = roadIndex; @@ -133,10 +133,10 @@ currentRoadPosition += stoppingDistance / steps; float totalDistance = stoppingDistance / steps * i; while (currentRoadPosition >= currentRoad.path.length) { - currentRoadIndex++; - if (currentRoadIndex == route.roads.Count) { + if (currentRoadIndex == route.roads.Count - 1) { goto end; } + currentRoadIndex++; currentRoadPosition -= currentRoad.path.length; currentRoad = route.roads[currentRoadIndex]; } @@ -153,7 +153,7 @@ } end: List carsToCheck = new List(); - for (int i = this.roadIndex; i < this.route.roads.Count; i++) { + for (int i = this.roadIndex; i <= currentRoadIndex; i++) { foreach (Car car in this.route.roads[i].carsOnRoute) { if (!carsToCheck.Contains(car)) { carsToCheck.Add(car); diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 1de8e19..419ffb2 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using System.Globalization; +using System; public class Config : MonoBehaviour { public Material roadMaterial, roadEditMaterial, carBrakingMaterial, carAccelerationMaterial; @@ -21,12 +22,12 @@ private string roadNetworkFileName, outputFileName; private float time; public Transform roads; - + public bool spawnCars = true; private static string getCLIArgumentValue(string name) { string[] arguments = System.Environment.GetCommandLineArgs(); - for (int i = 0; i < arguments.Length; i++) { - if (arguments[i] == name && arguments.Length > i + 1) { + for (int i = 0; i < arguments.Length - 1; i++) { + if (arguments[i] == name) { return arguments[i + 1]; } } @@ -47,16 +48,32 @@ private void Start() { roadNetworkFileName = getCLIArgumentValue("-i"); outputFileName = getCLIArgumentValue("-o"); - string timeString = getCLIArgumentValue("-t"); if (roadNetworkFileName.Length > 0) { LoadButton.loadRoadNetworkFromFile(roadNetworkFileName, this); } + string timeString = getCLIArgumentValue("-t"); if (timeString.Length > 0) { time = float.Parse(timeString, CultureInfo.InvariantCulture.NumberFormat); } else { time = float.PositiveInfinity; } + string frequencyString = getCLIArgumentValue("-f"); + if (frequencyString.Length > 0) { + frequency = float.Parse(frequencyString, CultureInfo.InvariantCulture.NumberFormat); + } + string redTimeString = getCLIArgumentValue("-red"); + if (redTimeString.Length > 0) { + trafficLights.redTime = float.Parse(redTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string greenTimeString = getCLIArgumentValue("-green"); + if (greenTimeString.Length > 0) { + trafficLights.greenTime = float.Parse(greenTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string invertLightsString = getCLIArgumentValue("-invert"); + if (invertLightsString.Length > 0) { + trafficLights.invert = bool.Parse(invertLightsString); + } } private void Update() { @@ -65,7 +82,9 @@ } time -= Time.deltaTime; if (time <= 0) { - SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + if (outputFileName.Length > 0) { + SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + } Application.Quit(); } } diff --git a/Assets/Scripts/Roads/Node/SpawnNodeData.cs b/Assets/Scripts/Roads/Node/SpawnNodeData.cs index 55e2a3e..2c81d1e 100644 --- a/Assets/Scripts/Roads/Node/SpawnNodeData.cs +++ b/Assets/Scripts/Roads/Node/SpawnNodeData.cs @@ -12,7 +12,7 @@ timeLeft = Random.Range(1 / (config.frequency * (1 - config.frequencyVariance)), 1 / (config.frequency * (1 + config.frequencyVariance))); ExitNodeData target = targets[Random.Range(0, targets.Count)]; Route route = new Route(node, target.node); - bool canSummon = route.isValid; + bool canSummon = route.isValid && config.spawnCars; foreach (Car car in route.roads[0].carsOnRoute) { if (car.roadPositon <= 3f) { canSummon = false; diff --git a/Assets/Scripts/TrafficLights.cs b/Assets/Scripts/TrafficLights.cs index 63d841c..a0e405a 100644 --- a/Assets/Scripts/TrafficLights.cs +++ b/Assets/Scripts/TrafficLights.cs @@ -14,19 +14,20 @@ public float greenTime = 10f; public float redTime = 2f; public int lightPhase = 1; + public bool invert = false; private void handleTurnGreen(List nodes) { foreach (CustomNode node in nodes) { if (node.lightPhase != lightPhase) { continue; } - node.isPassable = true; + node.isPassable = !invert; } } private void handleTurnRed(List nodes) { foreach (CustomNode node in nodes) { - node.isPassable = false; + node.isPassable = invert; } } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b7bc75a..cedde44 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -239,6 +239,7 @@ frequency: 0.2 frequencyVariance: 0.1 roads: {fileID: 1714391592} + spawnCars: 1 --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CameraControl.cs b/Assets/Scripts/CameraControl.cs index e043c87..79c8513 100644 --- a/Assets/Scripts/CameraControl.cs +++ b/Assets/Scripts/CameraControl.cs @@ -45,7 +45,7 @@ float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { scale += scroll * (-scrollSpeed); - scale = Mathf.Clamp(scale, -2, 2); + scale = Mathf.Clamp(scale, -2, 4); float realScale = Mathf.Pow(2, scale); transform.localScale = new Vector3(realScale, realScale, realScale); } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 6f80d5e..6540b77 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -107,7 +107,7 @@ float otherTraveledDistance = car.speed * time; float currentCarDistance = thisDistance - otherDistance; float projectedDistance = otherTraveledDistance - otherDistance; - float savetyDistance = 3f + speed * 1.8f; + float savetyDistance = 3.5f + speed * 1.8f; if (currentCarDistance < 0 || currentCarDistance > car.brakingDistance + savetyDistance) { return false; } @@ -124,7 +124,7 @@ } private bool isBraking() { - float stoppingDistance = brakingDistance + 3f + 1.8f * speed + 1f; + float stoppingDistance = Mathf.Max(1.8f * speed, brakingDistance + speed) + 3.5f; Road currentRoad = road; float currentRoadPosition = roadPositon; int currentRoadIndex = roadIndex; @@ -133,10 +133,10 @@ currentRoadPosition += stoppingDistance / steps; float totalDistance = stoppingDistance / steps * i; while (currentRoadPosition >= currentRoad.path.length) { - currentRoadIndex++; - if (currentRoadIndex == route.roads.Count) { + if (currentRoadIndex == route.roads.Count - 1) { goto end; } + currentRoadIndex++; currentRoadPosition -= currentRoad.path.length; currentRoad = route.roads[currentRoadIndex]; } @@ -153,7 +153,7 @@ } end: List carsToCheck = new List(); - for (int i = this.roadIndex; i < this.route.roads.Count; i++) { + for (int i = this.roadIndex; i <= currentRoadIndex; i++) { foreach (Car car in this.route.roads[i].carsOnRoute) { if (!carsToCheck.Contains(car)) { carsToCheck.Add(car); diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 1de8e19..419ffb2 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using System.Globalization; +using System; public class Config : MonoBehaviour { public Material roadMaterial, roadEditMaterial, carBrakingMaterial, carAccelerationMaterial; @@ -21,12 +22,12 @@ private string roadNetworkFileName, outputFileName; private float time; public Transform roads; - + public bool spawnCars = true; private static string getCLIArgumentValue(string name) { string[] arguments = System.Environment.GetCommandLineArgs(); - for (int i = 0; i < arguments.Length; i++) { - if (arguments[i] == name && arguments.Length > i + 1) { + for (int i = 0; i < arguments.Length - 1; i++) { + if (arguments[i] == name) { return arguments[i + 1]; } } @@ -47,16 +48,32 @@ private void Start() { roadNetworkFileName = getCLIArgumentValue("-i"); outputFileName = getCLIArgumentValue("-o"); - string timeString = getCLIArgumentValue("-t"); if (roadNetworkFileName.Length > 0) { LoadButton.loadRoadNetworkFromFile(roadNetworkFileName, this); } + string timeString = getCLIArgumentValue("-t"); if (timeString.Length > 0) { time = float.Parse(timeString, CultureInfo.InvariantCulture.NumberFormat); } else { time = float.PositiveInfinity; } + string frequencyString = getCLIArgumentValue("-f"); + if (frequencyString.Length > 0) { + frequency = float.Parse(frequencyString, CultureInfo.InvariantCulture.NumberFormat); + } + string redTimeString = getCLIArgumentValue("-red"); + if (redTimeString.Length > 0) { + trafficLights.redTime = float.Parse(redTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string greenTimeString = getCLIArgumentValue("-green"); + if (greenTimeString.Length > 0) { + trafficLights.greenTime = float.Parse(greenTimeString, CultureInfo.InvariantCulture.NumberFormat); + } + string invertLightsString = getCLIArgumentValue("-invert"); + if (invertLightsString.Length > 0) { + trafficLights.invert = bool.Parse(invertLightsString); + } } private void Update() { @@ -65,7 +82,9 @@ } time -= Time.deltaTime; if (time <= 0) { - SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + if (outputFileName.Length > 0) { + SaveTravelTimes.saveTravelTimesToFile(outputFileName, this); + } Application.Quit(); } } diff --git a/Assets/Scripts/Roads/Node/SpawnNodeData.cs b/Assets/Scripts/Roads/Node/SpawnNodeData.cs index 55e2a3e..2c81d1e 100644 --- a/Assets/Scripts/Roads/Node/SpawnNodeData.cs +++ b/Assets/Scripts/Roads/Node/SpawnNodeData.cs @@ -12,7 +12,7 @@ timeLeft = Random.Range(1 / (config.frequency * (1 - config.frequencyVariance)), 1 / (config.frequency * (1 + config.frequencyVariance))); ExitNodeData target = targets[Random.Range(0, targets.Count)]; Route route = new Route(node, target.node); - bool canSummon = route.isValid; + bool canSummon = route.isValid && config.spawnCars; foreach (Car car in route.roads[0].carsOnRoute) { if (car.roadPositon <= 3f) { canSummon = false; diff --git a/Assets/Scripts/TrafficLights.cs b/Assets/Scripts/TrafficLights.cs index 63d841c..a0e405a 100644 --- a/Assets/Scripts/TrafficLights.cs +++ b/Assets/Scripts/TrafficLights.cs @@ -14,19 +14,20 @@ public float greenTime = 10f; public float redTime = 2f; public int lightPhase = 1; + public bool invert = false; private void handleTurnGreen(List nodes) { foreach (CustomNode node in nodes) { if (node.lightPhase != lightPhase) { continue; } - node.isPassable = true; + node.isPassable = !invert; } } private void handleTurnRed(List nodes) { foreach (CustomNode node in nodes) { - node.isPassable = false; + node.isPassable = invert; } } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 83acfd7..a40d2cb 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -88,7 +88,7 @@ bakeCollisionMeshes: 0 forceSingleInstance: 0 useFlipModelSwapchain: 1 - resizableWindow: 0 + resizableWindow: 1 useMacAppStoreValidation: 0 macAppStoreCategory: public.app-category.games gpuSkinning: 1 @@ -152,7 +152,8 @@ resolutionScalingMode: 0 androidSupportedAspectRatio: 1 androidMaxAspectRatio: 2.1 - applicationIdentifier: {} + applicationIdentifier: + Standalone: com.DefaultCompany.Traffic buildNumber: Standalone: 0 iPhone: 0