add #regions

This commit is contained in:
Gered 2013-08-28 18:33:38 -04:00
parent 68ea526f34
commit 6ba60825ce
4 changed files with 66 additions and 2 deletions

View file

@ -4,6 +4,8 @@ namespace Blarg.GameFramework.TileMap.Prefabs
{
public class TilePrefab : TileContainer, TileRawDataContainer
{
#region Fields
Tile[] _data;
int _width;
int _height;
@ -21,6 +23,10 @@ namespace Blarg.GameFramework.TileMap.Prefabs
int _rotationZPreMultiplier;
BoundingBox _rotationBounds;
#endregion
#region Properties
public override int Width
{
get { return _width; }
@ -101,6 +107,8 @@ namespace Blarg.GameFramework.TileMap.Prefabs
get { return _data; }
}
#endregion
public TilePrefab(int width, int height, int depth)
{
if (width <= 0)
@ -147,6 +155,8 @@ namespace Blarg.GameFramework.TileMap.Prefabs
return (y * _width * _depth) + (z * _width) + x;
}
#region Rotation Handling
public void Rotate(Rotation rotation)
{
_rotation = rotation;
@ -253,6 +263,8 @@ namespace Blarg.GameFramework.TileMap.Prefabs
+ ((_rotationZPreMultiplier * z + _rotationZOffset) * _rotationZMultiplier)
+ ((_rotationXPreMultiplier * x + _rotationXOffset) * _rotationXMultiplier);
}
#endregion
}
}

View file

@ -5,6 +5,8 @@ namespace Blarg.GameFramework.TileMap
{
public class TileChunk : TileContainer, TileRawDataContainer, IDisposable
{
#region Fields
readonly Tile[] _data;
readonly int _x;
readonly int _y;
@ -19,6 +21,10 @@ namespace Blarg.GameFramework.TileMap
int _numAlphaMeshVertices;
VertexBuffer _alphaMesh;
#endregion
#region Properties
public readonly TileMap TileMap;
public Tile[] Data
@ -101,6 +107,8 @@ namespace Blarg.GameFramework.TileMap
get { return _alphaMesh; }
}
#endregion
public TileChunk(int x, int y, int z, int width, int height, int depth, TileMap tileMap)
{
if (tileMap == null)
@ -146,6 +154,8 @@ namespace Blarg.GameFramework.TileMap
_numAlphaMeshVertices = numAlphaMeshVertices;
}
#region Tile Retrieval
public Tile GetWithinSelfOrNeighbour(int x, int y, int z)
{
int checkX = x + _x;
@ -184,6 +194,10 @@ namespace Blarg.GameFramework.TileMap
return (y * _width * _depth) + (z * _width) + x;
}
#endregion
#region IDisposable
public void Dispose()
{
if (Mesh != null)
@ -191,6 +205,8 @@ namespace Blarg.GameFramework.TileMap
if (AlphaMesh != null)
AlphaMesh.Dispose();
}
#endregion
}
}

View file

@ -5,6 +5,8 @@ namespace Blarg.GameFramework.TileMap
{
public abstract class TileContainer
{
#region Properties
public abstract int Width { get; }
public abstract int Height { get; }
public abstract int Depth { get; }
@ -18,9 +20,13 @@ namespace Blarg.GameFramework.TileMap
public abstract Vector3 Position { get; }
public abstract BoundingBox Bounds { get; }
#endregion
public abstract Tile Get(int x, int y, int z);
public abstract Tile GetSafe(int x, int y, int z);
#region Bounds Checks
public bool IsWithinBounds(int x, int y, int z)
{
if (x < MinX || x > MaxX)
@ -95,6 +101,10 @@ namespace Blarg.GameFramework.TileMap
return true;
}
#endregion
#region Collision Checks
public bool CheckForCollision(Ray ray, ref Point3 collisionCoords)
{
// make sure that the ray and this TileContainer can actually collide in the first place
@ -306,6 +316,8 @@ namespace Blarg.GameFramework.TileMap
return collided;
}
#endregion
}
}

View file

@ -6,9 +6,15 @@ namespace Blarg.GameFramework.TileMap
{
public class TileMap : TileContainer, IDisposable
{
#region Fields
readonly Vector3 _position;
readonly BoundingBox _bounds;
#endregion
#region Properties
public readonly TileChunk[] Chunks;
public readonly TileMeshCollection TileMeshes;
public readonly ChunkVertexGenerator VertexGenerator;
@ -78,6 +84,8 @@ namespace Blarg.GameFramework.TileMap
get { return _bounds; }
}
#endregion
public TileMap(int chunkWidth, int chunkHeight, int chunkDepth,
int widthInChunks, int heightInChunks, int depthInChunks,
TileMeshCollection tileMeshes,
@ -134,7 +142,7 @@ namespace Blarg.GameFramework.TileMap
_bounds.Max.Set(Width, Height, Depth);
}
public void updateVertices()
public void UpdateVertices()
{
for (int i = 0; i < Chunks.Length; ++i)
UpdateChunkVertices(Chunks[i]);
@ -151,6 +159,8 @@ namespace Blarg.GameFramework.TileMap
Lighter.Light(this);
}
#region Bounds Checks
public bool GetOverlappedChunks(BoundingBox box, Point3 min, Point3 max)
{
// make sure the given box actually intersects with the map in the first place
@ -198,6 +208,10 @@ namespace Blarg.GameFramework.TileMap
return true;
}
#endregion
#region Tile Retrieval
public override Tile Get(int x, int y, int z)
{
var chunk = GetChunkContaining(x, y, z);
@ -216,6 +230,10 @@ namespace Blarg.GameFramework.TileMap
return Get(x, y, z);
}
#endregion
#region Chunk Retrieval
public TileChunk GetChunk(int chunkX, int chunkY, int chunkZ)
{
int index = GetChunkIndex(chunkX, chunkY, chunkZ);
@ -263,11 +281,17 @@ namespace Blarg.GameFramework.TileMap
return (chunkY * WidthInChunks * DepthInChunks) + (chunkZ * WidthInChunks) + chunkX;
}
#endregion
#region IDisposable
public void Dispose()
{
for (int i = 0; i < Chunks.Length; ++i)
Chunks[i].Dispose();
}
#endregion
}
}