Worked on map viewer

This commit is contained in:
2015-03-13 17:36:12 +02:00
parent c71b8ddd3e
commit c96de53ec8
66 changed files with 1770 additions and 1440 deletions

View File

@ -1,21 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace Assets.Scripts.Model.Config
{
[XmlRoot("terrgenConfig")]
public class TerrainGeneratorConfig
{
[XmlElement("noiseOctaves")]
public int NoiseOctaves { get; set; }
[XmlElement("noiseNonLinearPower")]
public float NoiseNonLinearPower { get; set; }
[XmlElement("elevationScale")]
public float ElevationScale { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace Assets.Scripts.Model.Config
{
[XmlRoot("terrgenConfig")]
public class TerrainGeneratorConfig
{
[XmlElement("noiseOctaves")]
public int NoiseOctaves { get; set; }
[XmlElement("noiseNonLinearPower")]
public float NoiseNonLinearPower { get; set; }
[XmlElement("elevationScale")]
public float ElevationScale { get; set; }
[XmlElement("waterNonLinearPower")]
public float WaterNonLinearPower { get; set; }
}
}

View File

@ -1,83 +1,146 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace TransportGame.Model
{
public class Map
{
private float[,] grid;
/// <summary>
/// Gets or sets the water level
/// </summary>
public float WaterLevel { get; set; }
/// <summary>
/// Gets or sets the biome
/// </summary>
public Biome Biome { get; set; }
/// <summary>
/// Gets the heights array
/// </summary>
public float[,] Heights
{
get
{
return grid;
}
}
/// <summary>
/// Initializes the map
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
public Map(int width, int height)
{
grid = new float[width, height];
}
/// <summary>
/// Gets or sets the cell at specified position
/// </summary>
/// <param name="x">X</param>
/// <param name="y">Y</param>
/// <returns>Cell</returns>
public float this[int x, int y]
{
get
{
return grid[x, y];
}
set
{
grid[x, y] = value;
}
}
/// <summary>
/// Gets width of map
/// </summary>
public int Width { get { return grid.GetLength(0); } }
/// <summary>
/// Gets height of map
/// </summary>
public int Height { get { return grid.GetLength(1); } }
/// <summary>
/// Returns true if specified cell is a water cell
/// </summary>
/// <param name="x">X</param>
/// <param name="y">Y</param>
/// <returns></returns>
public bool IsWater(int x, int y)
{
return grid[x, y] <= WaterLevel;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace TransportGame.Model
{
[XmlRoot("map")]
public class Map
{
private float[,] grid;
/// <summary>
/// Gets or sets the water level
/// </summary>
[XmlElement("waterLevel")]
public float WaterLevel { get; set; }
/// <summary>
/// Gets or sets the biome
/// </summary>
[XmlElement("biome")]
public Biome Biome { get; set; }
/// <summary>
/// Gets the heights array
/// </summary>
[XmlIgnore()]
public float[,] Heights
{
get
{
return grid;
}
}
/// <summary>
/// Gets or sets the heights as raw bytes
/// </summary>
/// <remarks>
/// Bytes are stored as such:
///
/// Offset Size Content
/// ------------------------
/// 0 4 Width
/// 4 8 Height
/// 8 var 32bit floating point values
///
/// </remarks>
[XmlElement("heights")]
public byte[] HeightsRaw
{
get
{
List<byte> bytes = new List<byte>();
bytes.AddRange(BitConverter.GetBytes(Width));
bytes.AddRange(BitConverter.GetBytes(Height));
for (int x = 0; x < Width; x++)
for (int y = 0; y < Height; y++)
bytes.AddRange(BitConverter.GetBytes(grid[x, y]));
return bytes.ToArray();
}
set
{
int pos = 0;
int w = BitConverter.ToInt32(value, pos); pos += sizeof(int);
int h = BitConverter.ToInt32(value, pos); pos += sizeof(int);
grid = new float[w, h];
for (int x = 0; x < w; x++)
for (int y = 0; y < h; y++)
{
grid[x, y] = BitConverter.ToSingle(value, pos);
pos += sizeof(float);
}
}
}
/// <summary>
/// Initializes the map
/// </summary>
/// <remarks>
/// Warning: heights array will be null.
/// </remarks>
public Map()
{
}
/// <summary>
/// Initializes the map
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
public Map(int width, int height)
{
grid = new float[width, height];
}
/// <summary>
/// Gets or sets the cell at specified position
/// </summary>
/// <param name="x">X</param>
/// <param name="y">Y</param>
/// <returns>Cell</returns>
[XmlIgnore]
public float this[int x, int y]
{
get
{
return grid[x, y];
}
set
{
grid[x, y] = value;
}
}
/// <summary>
/// Gets width of map
/// </summary>
[XmlIgnore]
public int Width { get { return grid.GetLength(0); } }
/// <summary>
/// Gets height of map
/// </summary>
[XmlIgnore]
public int Height { get { return grid.GetLength(1); } }
/// <summary>
/// Returns true if specified cell is a water cell
/// </summary>
/// <param name="x">X</param>
/// <param name="y">Y</param>
/// <returns></returns>
public bool IsWater(int x, int y)
{
return grid[x, y] <= WaterLevel;
}
}
}