diff --git a/src/external/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java b/src/external/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java index b62defd0..27d72da0 100644 --- a/src/external/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java +++ b/src/external/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java @@ -2,9 +2,30 @@ package com.minelittlepony.model.anim; import java.util.HashMap; import java.util.Map; +import java.util.UUID; + +import com.minelittlepony.util.chron.ChronicCache; +import com.minelittlepony.util.chron.Touchable; //#MineLittlePony# -public class BasicEasingInterpolator implements IInterpolator { +public class BasicEasingInterpolator extends Touchable implements IInterpolator { + + private static ChronicCache instanceCache = new ChronicCache<>(); + + /** + * Gets or creates a new basic, linear interpolator for the provided id. + */ + public static IInterpolator getInstance(UUID id) { + return instanceCache.retrieve(id, BasicEasingInterpolator::new); + } + + public BasicEasingInterpolator() { + + } + + private BasicEasingInterpolator(UUID id) { + + } private final Map properties = new HashMap(); diff --git a/src/external/java/com/minelittlepony/util/chron/ChronicCache.java b/src/external/java/com/minelittlepony/util/chron/ChronicCache.java new file mode 100644 index 00000000..dc132852 --- /dev/null +++ b/src/external/java/com/minelittlepony/util/chron/ChronicCache.java @@ -0,0 +1,18 @@ +package com.minelittlepony.util.chron; + +import java.util.HashMap; +import java.util.function.Function; + +//#MineLittlePony# +public class ChronicCache> extends HashMap { + private static final long serialVersionUID = 6454924015818181978L; + + public V retrieve(K key, Function mappingFunction) { + V result = computeIfAbsent(key, mappingFunction).touch(); + + entrySet().removeIf(entry -> entry.getValue().hasExpired()); + + return result; + } + +} diff --git a/src/external/java/com/minelittlepony/util/chron/Touchable.java b/src/external/java/com/minelittlepony/util/chron/Touchable.java new file mode 100644 index 00000000..6a50c3e5 --- /dev/null +++ b/src/external/java/com/minelittlepony/util/chron/Touchable.java @@ -0,0 +1,17 @@ +package com.minelittlepony.util.chron; + +//#MineLittlePony# +public abstract class Touchable> { + + private long expirationPeriod; + + public boolean hasExpired() { + return expirationPeriod <= System.currentTimeMillis(); + } + + @SuppressWarnings("unchecked") + public T touch() { + expirationPeriod = System.currentTimeMillis() + 30000; + return (T)this; + } +}