Merge pull request #120 from Caraxi/fix-actortable-enumerator

This commit is contained in:
goaaats 2020-06-05 13:38:28 +02:00 committed by GitHub
commit ca1ed75cf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 55 deletions

View file

@ -85,34 +85,12 @@ namespace Dalamud.Game.ClientState.Actors {
}
}
private class ActorTableEnumerator : IEnumerator<Actor> {
private readonly ActorTable table;
private int currentIndex;
public ActorTableEnumerator(ActorTable table) {
this.table = table;
}
public bool MoveNext() {
this.currentIndex++;
return this.currentIndex != this.table.Length;
}
public void Reset() {
this.currentIndex = 0;
}
public Actor Current => this.table[this.currentIndex];
object IEnumerator.Current => Current;
// Required by IEnumerator<T> even though we have nothing we want to dispose here.
public void Dispose() {}
}
public IEnumerator<Actor> GetEnumerator() {
return new ActorTableEnumerator(this);
for (int i=0;i<Length;i++){
if (this[i] != null) {
yield return this[i];
}
}
}
IEnumerator IEnumerable.GetEnumerator() {

View file

@ -73,37 +73,14 @@ namespace Dalamud.Game.ClientState
}
}
private class PartyListEnumerator : IEnumerator<PartyMember>
{
private readonly PartyList party;
private int currentIndex;
public PartyListEnumerator(PartyList list)
{
this.party = list;
public IEnumerator<PartyMember> GetEnumerator() {
for (var i = 0; i < Length; i++) {
if (this[i] != null) {
yield return this[i];
}
}
public bool MoveNext()
{
this.currentIndex++;
return this.currentIndex != this.party.Length;
}
public void Reset()
{
this.currentIndex = 0;
}
public PartyMember Current => this.party[this.currentIndex];
object IEnumerator.Current => Current;
// Required by IEnumerator<T> even though we have nothing we want to dispose here.
public void Dispose() {}
}
public IEnumerator<PartyMember> GetEnumerator() => new PartyListEnumerator(this);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public int Length => !this.isReady ? 0 : Marshal.ReadByte(partyListBegin + 0xF0);