Various improvements

This commit is contained in:
2015-06-10 14:43:57 +03:00
parent 3ab95e13fe
commit 52548b09e1
20 changed files with 45 additions and 55 deletions

View File

@ -144,10 +144,10 @@ namespace TransportGame.Generator
Polygon GeneratePrimitivePolygon(BuildingLot lot)
{
int sides = random.Next(3, 8); // Number of sides
int sides = random.Next(3, 6); // Number of sides
float angle = 2 * (float)Math.PI / sides; // Angle between sides
float radius = random.NextSingle(lot.Size * 0.25f, lot.Size * 0.75f) / 2; // Length of a side
float radius = random.NextSingle(lot.Size * 0.15f, lot.Size * 0.4f); // Length of a side
Vector2 current = lot.Position + new Vector2(random.NextSingle(-lot.Size / 4, lot.Size / 4), random.NextSingle(-lot.Size / 4, lot.Size / 4));
Vector2 dir = new Vector2(random.NextSingle(), random.NextSingle()).Normalized * radius;
@ -185,7 +185,7 @@ namespace TransportGame.Generator
}
else
{
b.LevelHeights[i] = random.NextSingle(0, ConfigManager.Buildgen.MaxBuildingHeight);
b.LevelHeights[i] = random.NextSingle(ConfigManager.Buildgen.MinBuildingHeight, ConfigManager.Buildgen.MaxBuildingHeight);
}
for (int j = 0; j < random.Next(ConfigManager.Buildgen.MaxPolygonsPerLevel); j++)

View File

@ -36,6 +36,7 @@ namespace TransportGame.Model.Config
/// Maximum height for a building
/// </summary>
public float MaxBuildingHeight { get; set; }
public float MinBuildingHeight { get; set; }
/// <summary>
/// Maximum number of primitive polygons to be generated per level
@ -49,8 +50,9 @@ namespace TransportGame.Model.Config
LotSpacing = 0.1f;
MaxLotAttempts = 3;
MaxBuildingHeight = 20f;
MaxBuildingLevels = 5;
MaxPolygonsPerLevel = 3;
MinBuildingHeight = 4f;
MaxBuildingLevels = 7;
MaxPolygonsPerLevel = 4;
}
}
}

View File

@ -73,11 +73,11 @@ namespace TransportGame.Model.Config
HighwayBranchDelay = 3;
MaximumIntersectingRoads = 5;
SidewalkWidth = .8f;
LaneWidth = 1f;
SidewalkWidth = 1f;
LaneWidth = 1.3f;
RaiseOffset = 0.8f;
SidewalkHeight = 0.1f;
SideCoverHeight = 0.1f;
SideCoverHeight = 0.4f;
}
}
}

View File

@ -132,35 +132,16 @@ public class TerrainGeneratorScript : MonoBehaviour
}
}
// Generate road & building mesh (we run the loops in parallel)
// Generate road & building mesh (we run the loops in parallel), and apply textures
Logger.Info("Generating buildings and roads...");
BuildingMeshGenerator buildingMeshGenerator = new BuildingMeshGenerator();
buildingMeshGenerator.BuildingMaterial = BuildingMaterial;
var it1 = buildingMeshGenerator.Generate(map).GetEnumerator();
RoadMeshGenerator roadMeshGenerator = new RoadMeshGenerator();
roadMeshGenerator.RoadMaterial = RoadMaterial;
var it2 = roadMeshGenerator.Generate(map).GetEnumerator();
bool stop;
do
{
stop = true;
if (it1.MoveNext())
{
yield return it1.Current;
stop = false;
}
if (it2.MoveNext())
{
yield return it2.Current;
stop = false;
}
} while (!stop);
// Finish setting up textures
foreach (var i in EndSetupSplatmaps(terrainData))
foreach (var i in Task.InParallel(buildingMeshGenerator.Generate(map), roadMeshGenerator.Generate(map), EndSetupSplatmaps(terrainData)))
yield return i;
}

View File

@ -66,5 +66,26 @@ namespace TransportGame.Utils
if (Success.HasValue && !Success.Value)
throw new Exception("Task failed", thrownException);
}
public static IEnumerable InParallel(params IEnumerable[] funcs)
{
// Obtain iterators
var iterators = funcs.Select(enumerable => enumerable.GetEnumerator()).ToArray();
// Execute a slice of each
bool stop;
do
{
stop = true;
foreach (var it in iterators)
if (it.MoveNext())
{
yield return it.Current;
stop = false;
}
} while (!stop);
}
}
}