Work on architecture. A lot of refractoring. Updated to unity 5.

This commit is contained in:
2015-03-12 10:44:44 +02:00
parent c51c5abbb1
commit c71b8ddd3e
436 changed files with 2144 additions and 17293 deletions

View File

@ -1,155 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using TransportGame.Model;
using TransportGame.Utils;
using UnityEngine;
namespace TransportGame.Generators
{
public static class MapImageRenderer
{
[Flags]
public enum Layers
{
None = 0,
Elevation = 1,
Grid = 2,
Centers = 4,
All = Elevation | Grid | Centers
};
private const int Scale = 20;
/// <summary>
/// Renders a map to a file
/// </summary>
/// <param name="file"></param>
/// <param name="map"></param>
/// <param name="layers"></param>
//public static void Render(this Map map, string file, Layers layers = Layers.All)
//{
// // Create texture on which to draw
// Texture2D texture = new Texture2D(
// map.Width * Scale,
// map.Height * Scale,
// TextureFormat.RGB24,
// false);
// // First layer - cells
// DrawCells(texture, map, (layers & Layers.Elevation) > 0, (layers & Layers.Centers) > 0);
// // Second layer - grid
// if ((layers & Layers.Grid) > 0)
// DrawGrid(texture, map);
// // Write to file
// File.WriteAllBytes(file + ".png", texture.EncodeToPNG());
//}
//private static void DrawCells(Texture2D texture, Map map, bool elevation, bool centers)
//{
// for (int x = 0; x < map.Width; x++)
// for (int y = 0; y < map.Height; y++)
// {
// // Calculate scaled corners
// Vector2 c00 = new Vector2(
// map[x, y].Corner00.Pos.x * Scale,
// map[x, y].Corner00.Pos.y * Scale);
// Vector2 c01 = new Vector2(
// map[x, y].Corner01.Pos.x * Scale,
// map[x, y].Corner01.Pos.y * Scale);
// Vector2 c10 = new Vector2(
// map[x, y].Corner10.Pos.x * Scale,
// map[x, y].Corner10.Pos.y * Scale);
// Vector2 c11 = new Vector2(
// map[x, y].Corner11.Pos.x * Scale,
// map[x, y].Corner11.Pos.y * Scale);
// // Calculate color
// Color c = ColorHelper.FromArgb(0x555500);
// // Water - always blue
// if (map.IsWater(x, y))
// c = Color.blue;
// // Map type is elevation map - get elevation color
// else if (elevation)
// c = GetCollorOfTerrain(map[x, y].Elevation);
// // Draw polygon
// texture.FillPolygon(c, c00, c01, c11, c10);
// // Draw center
// if (centers)
// texture.DrawPoint(Color.red,
// Convert.ToInt32(map[x, y].Center.x * Scale),
// Convert.ToInt32(map[x, y].Center.y * Scale),
// 2);
// }
//}
//private static void DrawGrid(Texture2D texture, Map map)
//{
// for (int x = 0; x < map.Width + 1; x++)
// for (int y = 0; y < map.Height + 1; y++)
// {
// Corner c0 = map.Corner(x, y);
// Vector2 c0pos = new Vector2(c0.Pos.x * Scale, c0.Pos.y * Scale);
// // Draw edges
// if (x > 0)
// {
// Corner c1 = map.Corner(x - 1, y);
// Vector2 c1pos = new Vector2(c1.Pos.x * Scale, c1.Pos.y * Scale);
// texture.DrawLine(Color.white, c0pos, c1pos);
// }
// if (y > 0)
// {
// Corner c1 = map.Corner(x, y - 1);
// Vector2 c1pos = new Vector2(c1.Pos.x * Scale, c1.Pos.y * Scale);
// texture.DrawLine(Color.white, c0pos, c1pos);
// }
// // Draw corner
// texture.DrawPoint(Color.white, c0pos, 2);
// }
//}
private static Color GetCollorOfTerrain(float height)
{
Color color1, color2;
float alpha;
if (height < 10f)
{
color1 = ColorHelper.FromArgb(0x00ffa2);
color2 = ColorHelper.FromArgb(0xFCD628);
alpha = height / 10f;
}
else if (height < 25f)
{
color1 = ColorHelper.FromArgb(0xFCD628);
color2 = ColorHelper.FromArgb(0x9C6713);
alpha = (height - 10f) / 15f;
}
else if (height < 50f)
{
color1 = ColorHelper.FromArgb(0xaaaaaa);
color2 = ColorHelper.FromArgb(0xffffff);
alpha = (height - 25f) / 25f;
}
else
{
color1 = color2 = Color.white;
alpha = 1;
}
return Color.Lerp(color1, color2, alpha);
}
}
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: d89d584776261fe4b81720b3615755bb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -20,6 +20,10 @@ namespace TransportGame.Generator
public TerrainGenerator()
{
Noise = new PerlinNoiseGenerator();
if (ConfigurationManager.TerrGenConfig == null)
throw new Exception("WTF?");
Noise.Octaves = ConfigurationManager.TerrGenConfig.NoiseOctaves;
Noise.NonLinearPower = ConfigurationManager.TerrGenConfig.NoiseNonLinearPower;
Noise.Scale = ConfigurationManager.TerrGenConfig.ElevationScale;
@ -32,6 +36,7 @@ namespace TransportGame.Generator
// Pick a random biome
map.Biome = PickBiome();
Logger.Info("Picked biome: {0}", map.Biome.Name);
// Generate elevation
GenerateElevation(map);
@ -40,6 +45,7 @@ namespace TransportGame.Generator
float waterAmount = random.NextSingle(map.Biome.Moisture.Minimum, map.Biome.Moisture.Maximum);
map.WaterLevel = Mathf.Pow(waterAmount, 3) * (map.Biome.HeightRange.Maximum - map.Biome.HeightRange.Minimum) + map.Biome.HeightRange.Minimum;
DumpData(map);
return map;
}
@ -57,5 +63,22 @@ namespace TransportGame.Generator
for (int y = 0; y < map.Height; ++y)
map[x, y] = Noise.Generate(x, y, map.Biome.HeightRange.Minimum, map.Biome.HeightRange.Maximum);
}
private void DumpData(Map map)
{
StringBuilder builder = new StringBuilder();
for (int x = 0; x < map.Width; ++x)
{
for (int y = 0; y < map.Height; ++y)
{
builder.Append(map[x, y]);
builder.Append(';');
}
builder.AppendLine();
}
Logger.Info("Generated map: \n{0}", builder.ToString());
}
}
}