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

View file

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

View file

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

View file

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