Move CachedTransform to OpenRA.Primitives.
This commit is contained in:
committed by
Gustas
parent
88fb83bc57
commit
b8756c4737
@@ -396,66 +396,4 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
notificationWidget.Bounds.Width = boxWidth - notificationWidget.Bounds.X;
|
||||
}
|
||||
}
|
||||
|
||||
public class CachedTransform<T, U>
|
||||
{
|
||||
readonly Func<T, U> transform;
|
||||
|
||||
bool initialized;
|
||||
T lastInput;
|
||||
U lastOutput;
|
||||
|
||||
public CachedTransform(Func<T, U> transform)
|
||||
{
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
public U Update(T input)
|
||||
{
|
||||
if (initialized && ((input == null && lastInput == null) || (input != null && input.Equals(lastInput))))
|
||||
return lastOutput;
|
||||
|
||||
lastInput = input;
|
||||
lastOutput = transform(input);
|
||||
initialized = true;
|
||||
|
||||
return lastOutput;
|
||||
}
|
||||
}
|
||||
|
||||
public class PredictedCachedTransform<T, U>
|
||||
{
|
||||
readonly Func<T, U> transform;
|
||||
|
||||
bool initialized;
|
||||
T lastInput;
|
||||
U lastOutput;
|
||||
|
||||
bool predicted;
|
||||
U prediction;
|
||||
|
||||
public PredictedCachedTransform(Func<T, U> transform)
|
||||
{
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
public void Predict(U value)
|
||||
{
|
||||
predicted = true;
|
||||
prediction = value;
|
||||
}
|
||||
|
||||
public U Update(T input)
|
||||
{
|
||||
if ((predicted || initialized) && ((input == null && lastInput == null) || (input != null && input.Equals(lastInput))))
|
||||
return predicted ? prediction : lastOutput;
|
||||
|
||||
predicted = false;
|
||||
initialized = true;
|
||||
lastInput = input;
|
||||
lastOutput = transform(input);
|
||||
|
||||
return lastOutput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user