change the way RemainingElements calculates and remove safety from MoveNext/Previous
This is mainly to fix a problem where it's not exactly intuitive to code a loop which runs through a buffer using MoveNext() up until the end of RemainingElements. When the loop ends, you'd expect to be able to take that same buffer, Extend() it, and be able to immediately start running through it again without calling MoveNext() one extra time inbetween both loops. This fix makes it so this kind of "intuitive" usage pattern works, at the expense of no automatic bounds safety with CurrentPosition
This commit is contained in:
parent
5a37b8bdfe
commit
55f697ae6c
|
@ -10,7 +10,7 @@ namespace Blarg.GameFramework.Graphics
|
|||
|
||||
public int RemainingElements
|
||||
{
|
||||
get { return (NumElements - 1) - CurrentPosition; }
|
||||
get { return NumElements - CurrentPosition; }
|
||||
}
|
||||
|
||||
public override int NumElements
|
||||
|
@ -91,10 +91,7 @@ namespace Blarg.GameFramework.Graphics
|
|||
{
|
||||
++CurrentPosition;
|
||||
if (CurrentPosition >= NumElements)
|
||||
{
|
||||
--CurrentPosition;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
@ -104,10 +101,7 @@ namespace Blarg.GameFramework.Graphics
|
|||
if (CurrentPosition == 0)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
--CurrentPosition;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Move(int amount)
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Blarg.GameFramework.Graphics
|
|||
|
||||
public int RemainingElements
|
||||
{
|
||||
get { return (NumElements - 1) - CurrentPosition; }
|
||||
get { return NumElements - CurrentPosition; }
|
||||
}
|
||||
|
||||
public override int NumElements
|
||||
|
@ -143,10 +143,7 @@ namespace Blarg.GameFramework.Graphics
|
|||
{
|
||||
++CurrentPosition;
|
||||
if (CurrentPosition >= NumElements)
|
||||
{
|
||||
--CurrentPosition;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
@ -156,10 +153,7 @@ namespace Blarg.GameFramework.Graphics
|
|||
if (CurrentPosition == 0)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
--CurrentPosition;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Move(int amount)
|
||||
|
|
Reference in a new issue