Refactor classes to structs
This commit is contained in:
@@ -117,7 +117,7 @@ namespace OpenRA
|
|||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class CellRegionEnumerator : IEnumerator<CPos>
|
public struct CellRegionEnumerator : IEnumerator<CPos>
|
||||||
{
|
{
|
||||||
readonly CellRegion r;
|
readonly CellRegion r;
|
||||||
|
|
||||||
@@ -128,9 +128,11 @@ namespace OpenRA
|
|||||||
CPos current;
|
CPos current;
|
||||||
|
|
||||||
public CellRegionEnumerator(CellRegion region)
|
public CellRegionEnumerator(CellRegion region)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
r = region;
|
r = region;
|
||||||
Reset();
|
Reset();
|
||||||
|
current = new MPos(u, v).ToCPos(r.gridType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MoveNext()
|
public bool MoveNext()
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace OpenRA
|
|||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ProjectedCellRegionEnumerator : IEnumerator<PPos>
|
public struct ProjectedCellRegionEnumerator : IEnumerator<PPos>
|
||||||
{
|
{
|
||||||
readonly ProjectedCellRegion r;
|
readonly ProjectedCellRegion r;
|
||||||
|
|
||||||
@@ -86,9 +86,11 @@ namespace OpenRA
|
|||||||
PPos current;
|
PPos current;
|
||||||
|
|
||||||
public ProjectedCellRegionEnumerator(ProjectedCellRegion region)
|
public ProjectedCellRegionEnumerator(ProjectedCellRegion region)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
r = region;
|
r = region;
|
||||||
Reset();
|
Reset();
|
||||||
|
current = new PPos(u, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MoveNext()
|
public bool MoveNext()
|
||||||
|
|||||||
@@ -179,13 +179,14 @@ namespace OpenRA
|
|||||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultipleEnumerator : IEnumerator<T>
|
struct MultipleEnumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
readonly List<Actor> actors;
|
readonly List<Actor> actors;
|
||||||
readonly List<T> traits;
|
readonly List<T> traits;
|
||||||
readonly uint actor;
|
readonly uint actor;
|
||||||
int index;
|
int index;
|
||||||
public MultipleEnumerator(TraitContainer<T> container, uint actor)
|
public MultipleEnumerator(TraitContainer<T> container, uint actor)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
actors = container.actors;
|
actors = container.actors;
|
||||||
traits = container.traits;
|
traits = container.traits;
|
||||||
@@ -236,7 +237,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AllEnumerable : IEnumerable<TraitPair<T>>
|
struct AllEnumerable : IEnumerable<TraitPair<T>>
|
||||||
{
|
{
|
||||||
readonly TraitContainer<T> container;
|
readonly TraitContainer<T> container;
|
||||||
public AllEnumerable(TraitContainer<T> container) { this.container = container; }
|
public AllEnumerable(TraitContainer<T> container) { this.container = container; }
|
||||||
@@ -244,12 +245,13 @@ namespace OpenRA
|
|||||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class AllEnumerator : IEnumerator<TraitPair<T>>
|
struct AllEnumerator : IEnumerator<TraitPair<T>>
|
||||||
{
|
{
|
||||||
readonly List<Actor> actors;
|
readonly List<Actor> actors;
|
||||||
readonly List<T> traits;
|
readonly List<T> traits;
|
||||||
int index;
|
int index;
|
||||||
public AllEnumerator(TraitContainer<T> container)
|
public AllEnumerator(TraitContainer<T> container)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
actors = container.actors;
|
actors = container.actors;
|
||||||
traits = container.traits;
|
traits = container.traits;
|
||||||
|
|||||||
@@ -216,21 +216,32 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class ActorsAtEnumerator : IEnumerator<Actor>
|
struct ActorsAtEnumerator : IEnumerator<Actor>
|
||||||
{
|
{
|
||||||
InfluenceNode node;
|
InfluenceNode node;
|
||||||
public ActorsAtEnumerator(InfluenceNode node) { this.node = node; }
|
Actor current;
|
||||||
|
|
||||||
|
public ActorsAtEnumerator(InfluenceNode node)
|
||||||
|
{
|
||||||
|
this.node = node;
|
||||||
|
current = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void Reset() { throw new NotSupportedException(); }
|
public void Reset() { throw new NotSupportedException(); }
|
||||||
public Actor Current { get; private set; }
|
public Actor Current
|
||||||
object IEnumerator.Current { get { return Current; } }
|
{
|
||||||
|
get { return current; }
|
||||||
|
}
|
||||||
|
|
||||||
|
object IEnumerator.Current { get { return current; } }
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
public bool MoveNext()
|
public bool MoveNext()
|
||||||
{
|
{
|
||||||
while (node != null)
|
while (node != null)
|
||||||
{
|
{
|
||||||
Current = node.Actor;
|
current = node.Actor;
|
||||||
node = node.Next;
|
node = node.Next;
|
||||||
if (!Current.Disposed)
|
if (!current.Disposed)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +249,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class ActorsAtEnumerable : IEnumerable<Actor>
|
struct ActorsAtEnumerable : IEnumerable<Actor>
|
||||||
{
|
{
|
||||||
readonly InfluenceNode node;
|
readonly InfluenceNode node;
|
||||||
public ActorsAtEnumerable(InfluenceNode node) { this.node = node; }
|
public ActorsAtEnumerable(InfluenceNode node) { this.node = node; }
|
||||||
|
|||||||
Reference in New Issue
Block a user