add TileContainer Get/GetSafe overloads accepting a Point3
This commit is contained in:
parent
fe023e684b
commit
f4c7dd9f50
|
@ -142,6 +142,12 @@ namespace Blarg.GameFramework.TileMap.Prefabs
|
||||||
return _data[index];
|
return _data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Tile Get(Point3 p)
|
||||||
|
{
|
||||||
|
int index = GetIndexOf(p.X, p.Y, p.Z);
|
||||||
|
return _data[index];
|
||||||
|
}
|
||||||
|
|
||||||
public override Tile GetSafe(int x, int y, int z)
|
public override Tile GetSafe(int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (!IsWithinLocalBounds(x, y, z))
|
if (!IsWithinLocalBounds(x, y, z))
|
||||||
|
@ -150,6 +156,14 @@ namespace Blarg.GameFramework.TileMap.Prefabs
|
||||||
return Get(x, y, z);
|
return Get(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Tile GetSafe(Point3 p)
|
||||||
|
{
|
||||||
|
if (!IsWithinLocalBounds(p.X, p.Y, p.Z))
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return Get(p.X, p.Y, p.Z);
|
||||||
|
}
|
||||||
|
|
||||||
private int GetIndexOf(int x, int y, int z)
|
private int GetIndexOf(int x, int y, int z)
|
||||||
{
|
{
|
||||||
return (y * _width * _depth) + (z * _width) + x;
|
return (y * _width * _depth) + (z * _width) + x;
|
||||||
|
|
|
@ -181,6 +181,12 @@ namespace Blarg.GameFramework.TileMap
|
||||||
return _data[index];
|
return _data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Tile Get(Point3 p)
|
||||||
|
{
|
||||||
|
int index = GetIndexOf(p.X, p.Y, p.Z);
|
||||||
|
return _data[index];
|
||||||
|
}
|
||||||
|
|
||||||
public override Tile GetSafe(int x, int y, int z)
|
public override Tile GetSafe(int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (!IsWithinLocalBounds(x, y, z))
|
if (!IsWithinLocalBounds(x, y, z))
|
||||||
|
@ -189,6 +195,14 @@ namespace Blarg.GameFramework.TileMap
|
||||||
return Get(x, y, z);
|
return Get(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Tile GetSafe(Point3 p)
|
||||||
|
{
|
||||||
|
if (!IsWithinLocalBounds(p.X, p.Y, p.Z))
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return Get(p.X, p.Y, p.Z);
|
||||||
|
}
|
||||||
|
|
||||||
private int GetIndexOf(int x, int y, int z)
|
private int GetIndexOf(int x, int y, int z)
|
||||||
{
|
{
|
||||||
return (y * _width * _depth) + (z * _width) + x;
|
return (y * _width * _depth) + (z * _width) + x;
|
||||||
|
|
|
@ -23,7 +23,9 @@ namespace Blarg.GameFramework.TileMap
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public abstract Tile Get(int x, int y, int z);
|
public abstract Tile Get(int x, int y, int z);
|
||||||
|
public abstract Tile Get(Point3 p);
|
||||||
public abstract Tile GetSafe(int x, int y, int z);
|
public abstract Tile GetSafe(int x, int y, int z);
|
||||||
|
public abstract Tile GetSafe(Point3 p);
|
||||||
|
|
||||||
#region Bounds Checks
|
#region Bounds Checks
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,16 @@ namespace Blarg.GameFramework.TileMap
|
||||||
return chunk.Get(chunkX, chunkY, chunkZ);
|
return chunk.Get(chunkX, chunkY, chunkZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Tile Get(Point3 p)
|
||||||
|
{
|
||||||
|
var chunk = GetChunkContaining(p.X, p.Y, p.Z);
|
||||||
|
int chunkX = p.X - chunk.MinX;
|
||||||
|
int chunkY = p.Y - chunk.MinY;
|
||||||
|
int chunkZ = p.Z - chunk.MinZ;
|
||||||
|
|
||||||
|
return chunk.Get(chunkX, chunkY, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
public override Tile GetSafe(int x, int y, int z)
|
public override Tile GetSafe(int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (!IsWithinBounds(x, y, z))
|
if (!IsWithinBounds(x, y, z))
|
||||||
|
@ -230,6 +240,14 @@ namespace Blarg.GameFramework.TileMap
|
||||||
return Get(x, y, z);
|
return Get(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Tile GetSafe(Point3 p)
|
||||||
|
{
|
||||||
|
if (!IsWithinBounds(p.X, p.Y, p.Z))
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return Get(p.X, p.Y, p.Z);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Chunk Retrieval
|
#region Chunk Retrieval
|
||||||
|
|
|
@ -11,7 +11,9 @@ namespace Blarg.GameFramework.TileMap
|
||||||
int Depth { get; }
|
int Depth { get; }
|
||||||
|
|
||||||
Tile Get(int x, int y, int z);
|
Tile Get(int x, int y, int z);
|
||||||
|
Tile Get(Point3 p);
|
||||||
Tile GetSafe(int x, int y, int z);
|
Tile GetSafe(int x, int y, int z);
|
||||||
|
Tile GetSafe(Point3 p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue