Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Commit

Permalink
Data Structures Interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPatten committed Dec 11, 2013
1 parent 1375049 commit d49b1a3
Show file tree
Hide file tree
Showing 26 changed files with 560 additions and 317 deletions.
8 changes: 4 additions & 4 deletions Game/States/AiBattle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AiBattle : InterfaceGameState
public static readonly float MeterLength = 10;
//public static ListArray<Explosion> _explosions = new ListArray(10);

public Octree<Unit, string> _octree = new Octree<Unit, string>(0, 0, 0, 1000000, 10,
public OctreeLinked<Unit, string> _octree = new OctreeLinked<Unit, string>(0, 0, 0, 1000000, 10,
(Unit left, Unit right) => { return left.Id.CompareTo(right.Id); },
(Unit left, string right) => { return left.Id.CompareTo(right); });

Expand Down Expand Up @@ -146,7 +146,7 @@ private void GenerateUnits()
_killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10;
_killemMelee[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem);
_killemMelee[i].StaticModel.Scale = new Vector(20, 20, 20);
_killemMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Trigonometry.HalfPi/2);
_killemMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Trigonometry.HalfPi);
_octree.Add(_killemMelee[i]);
}

Expand All @@ -165,7 +165,7 @@ private void GenerateUnits()
_killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10;
_killemRanged[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem);
_killemRanged[i].StaticModel.Scale = new Vector(20, 20, 20);
_killemRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Trigonometry.HalfPi/2);
_killemRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Trigonometry.HalfPi);
_killemRanged[i].Id = "Ranger" + i;
_octree.Add(_killemRanged[i]);
}
Expand All @@ -185,7 +185,7 @@ private void GenerateUnits()
_killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10;
_killemKamakazi[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem);
_killemKamakazi[i].StaticModel.Scale = new Vector(20, 20, 20);
_killemKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Trigonometry.HalfPi/2);
_killemKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Trigonometry.HalfPi);
_octree.Add(_killemKamakazi[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Game/States/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GameState : InterfaceGameState

public static readonly float MeterLength = 10;

public Octree<StaticModel, string> _octree = new Octree<StaticModel, string>(0, 0, 0, 1000000, 10,
public OctreeLinked<StaticModel, string> _octree = new OctreeLinked<StaticModel, string>(0, 0, 0, 1000000, 10,
(StaticModel left, StaticModel right) => { return left.Id.CompareTo(right.Id); },
(StaticModel left, string right) => { return left.Id.CompareTo(right); } );

Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Types/Ai/KillemKamakazi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class KillemKamakazi : Kamakazi

public KillemKamakazi(string id, StaticModel staticModel) : base(id, staticModel) { }

public override void AI(Octree<Unit, string> octree)
public override void AI(OctreeLinked<Unit, string> octree)
{

}
Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Types/Ai/KillemMelee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class KillemMelee : Melee

public KillemMelee(string id, StaticModel staticModel) : base(id, staticModel) { }

public override void AI(Octree<Unit, string> octree)
public override void AI(OctreeLinked<Unit, string> octree)
{

}
Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Types/Ai/KillemRanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class KillemRanged : Ranged

public KillemRanged(string id, StaticModel staticModel) : base(id, staticModel) { }

public override void AI(Octree<Unit, string> octree)
public override void AI(OctreeLinked<Unit, string> octree)
{

}
Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Types/Ai/ZackKamakazi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ZackKamakazi : Kamakazi

public ZackKamakazi(string id, StaticModel staticModel) : base(id, staticModel) { }

public override void AI(Octree<Unit, string> octree)
public override void AI(OctreeLinked<Unit, string> octree)
{
// Targeting
if (_target == null || _target.IsDead)
Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Types/Ai/ZackMelee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ZackMelee : Melee

public ZackMelee(string id, StaticModel staticModel) : base(id, staticModel) { }

public override void AI(Octree<Unit, string> octree)
public override void AI(OctreeLinked<Unit, string> octree)
{
// Targeting
if (_target == null || _target.IsDead)
Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Types/Ai/ZackRanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ZackRanged : Ranged

public ZackRanged(string id, StaticModel staticModel) : base(id, staticModel) { }

public override void AI(Octree<Unit, string> octree)
public override void AI(OctreeLinked<Unit, string> octree)
{
// Targeting
if (_target == null || _target.IsDead)
Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Types/Kamakazi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Kamakazi(string id, StaticModel staticModel) : base(id, staticModel)
_moveSpeed = random.Next(_moveSpeedMin, _moveSpeedMax) / 1000f;
}

protected void Attack(Octree<Unit, string> octree)
protected void Attack(OctreeLinked<Unit, string> octree)
{
octree.Traverse
(
Expand Down
2 changes: 1 addition & 1 deletion Game/Units/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public Unit(string id, StaticModel staticModel)
_isDead = false;
}

public virtual void AI(Octree<Unit, string> octree) { throw new NotImplementedException(); }
public virtual void AI(OctreeLinked<Unit, string> octree) { throw new NotImplementedException(); }
}
}
32 changes: 21 additions & 11 deletions SevenEngine/DataStructures/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
// - Zachary Aaron Patten (aka Seven) seven@sevenengine.com
// Last Edited: 11-22-13

// This file contains the following classes:
// This file contains the following interfaces:
// - Array
// - ArrayException
// This file contains the following classes:
// - ArrayStandard
// - ArrayStandardException
// - ArrayCyclic
// - ArrayCyclicException

Expand All @@ -22,11 +24,19 @@

namespace SevenEngine.DataStructures
{
public interface Array<Type> : InterfaceTraversable<Type>
{
Type this[int index] { get; set; }
int Length { get; }
bool TraverseBreakable(Func<Type, bool> traversalFunction, int start, int end);
void Traverse(Action<Type> traversalAction, int start, int end);
}

#region Array

/// <summary>Implements a standard array that inherits InterfaceTraversable.</summary>
/// <typeparam name="Type">The generic type within the structure.</typeparam>
public class Array<Type> : InterfaceTraversable<Type>
public class ArrayStandard<Type> : Array<Type>
{
private Type[] _array;

Expand All @@ -46,7 +56,7 @@ public Type this[int index]
{
ReaderLock();
if (index < 0 || index > _array.Length)
throw new ArrayException("index out of bounds.");
throw new ArrayStandardException("index out of bounds.");
Type returnValue = _array[index];
ReaderUnlock();
return returnValue;
Expand All @@ -55,7 +65,7 @@ public Type this[int index]
{
WriterLock();
if (index < 0 || index > _array.Length)
throw new ArrayException("index out of bounds.");
throw new ArrayStandardException("index out of bounds.");
_array[index] = value;
WriterUnlock();
}
Expand All @@ -64,10 +74,10 @@ public Type this[int index]
/// <summary>Constructs an array that implements a traversal delegate function
/// which is an optimized "foreach" implementation.</summary>
/// <param name="size">The length of the array in memory.</param>
public Array(int size)
public ArrayStandard(int size)
{
if (size < 0)
throw new ArrayException("size of the array must be non-negative.");
throw new ArrayStandardException("size of the array must be non-negative.");
_array = new Type[size];
_lock = new Object();
_readers = 0;
Expand Down Expand Up @@ -102,7 +112,7 @@ public bool TraverseBreakable(Func<Type, bool> traversalFunction, int start, int
{
ReaderLock();
if (start > end || end > _array.Length || start < 0)
throw new ArrayException("start/end indeces out of bounds during traversal attempt.");
throw new ArrayStandardException("start/end indeces out of bounds during traversal attempt.");
for (int index = start; index < end; index++)
{
if (!traversalFunction(_array[index++]))
Expand Down Expand Up @@ -136,7 +146,7 @@ public void Traverse(Action<Type> traversalAction, int start, int end)
{
ReaderLock();
if (start > end || end > _array.Length || start < 0)
throw new ArrayException("start/end indeces out of bounds during traversal attempt.");
throw new ArrayStandardException("start/end indeces out of bounds during traversal attempt.");
for (int index = start; index < end; index++)
traversalAction(_array[index++]);
ReaderUnlock();
Expand All @@ -152,7 +162,7 @@ public void Traverse(Action<Type> traversalAction, int start, int end)
private void WriterUnlock() { lock (_lock) { _writers--; Monitor.PulseAll(_lock); } }

/// <summary>This is used for throwing AVL Tree exceptions only to make debugging faster.</summary>
private class ArrayException : Exception { public ArrayException(string message) : base(message) { } }
private class ArrayStandardException : Exception { public ArrayStandardException(string message) : base(message) { } }
}

#endregion
Expand All @@ -161,7 +171,7 @@ private class ArrayException : Exception { public ArrayException(string message)

/// <summary>Implements a cyclic array (allows overwriting) that inherits InterfaceTraversable.</summary>
/// <typeparam name="Type">The generic type within the structure.</typeparam>
public class ArrayCyclic<Type> : InterfaceTraversable<Type>
public class ArrayCyclic<Type> : Array<Type>
{
private Type[] _array;
int _start;
Expand Down
Loading

0 comments on commit d49b1a3

Please sign in to comment.