parent
							
								
									a641cba9e1
								
							
						
					
					
						commit
						086a630fb9
					
				@ -0,0 +1,46 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Constraint cache | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 * @param <C> constraint type | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface ConstraintCache<C> extends Pollable { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Called after the cache has changed value (and digest). | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						void onChange(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * @return the cached value | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						C getCacheSource(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Enable caching & digest caching | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @param yes enable caching | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						void enableCaching(boolean yes); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * @return true if caching is on | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						boolean isCachingEnabled(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Update cached value and cached digest (if digest caching is enabled).<br> | 
				
			||||||
 | 
						 * source constraint is polled beforehand. | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						void poll(); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,60 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Parametrized implementation of a {@link Digestable} | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 * @param <D> digest class
 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public abstract class DigestCache<D> implements Digestable<D> { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private D digest; | 
				
			||||||
 | 
						private boolean enabled; | 
				
			||||||
 | 
						private boolean dirty; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final D digest() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (enabled) { | 
				
			||||||
 | 
								if (dirty || digest == null) { | 
				
			||||||
 | 
									digest = createDigest(); | 
				
			||||||
 | 
									dirty = false; | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								return digest; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return createDigest(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * @return fresh new digest | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						protected abstract D createDigest(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void enableDigestCaching(boolean yes) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							enabled = yes; | 
				
			||||||
 | 
							markDigestDirty(); // mark dirty
 | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final boolean isDigestCachingEnabled() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return enabled; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void markDigestDirty() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							dirty = true; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.gamecore.control.timing; | 
					package mightypork.utils.math.constraints; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.gamecore.control.timing; | 
					package mightypork.utils.math.constraints; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.LinkedHashSet; | 
					import java.util.LinkedHashSet; | 
				
			||||||
@ -1,49 +0,0 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * <p> | 
					 | 
				
			||||||
 * A num cache. | 
					 | 
				
			||||||
 * </p> | 
					 | 
				
			||||||
 * <p> | 
					 | 
				
			||||||
 * Values are held in a caching VectVar, and digest caching is enabled by | 
					 | 
				
			||||||
 * default. | 
					 | 
				
			||||||
 * </p> | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public class NumCache extends NumAdapter { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private final NumVar cache = Num.makeVar(); | 
					 | 
				
			||||||
	private final Num source; | 
					 | 
				
			||||||
	private boolean inited = false; | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public NumCache(Num source) { | 
					 | 
				
			||||||
		this.source = source; | 
					 | 
				
			||||||
		enableDigestCaching(true); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	protected Num getSource() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (!inited) poll(); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		return cache; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * Update cached value and cached digest (if digest caching is enabled) | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void poll() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		inited = true; | 
					 | 
				
			||||||
		cache.setTo(source); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		super.poll(); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -0,0 +1,82 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints.num.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.ConstraintCache; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.mutable.NumVar; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.proxy.NumAdapter; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * <p> | 
				
			||||||
 | 
					 * A Num cache. | 
				
			||||||
 | 
					 * </p> | 
				
			||||||
 | 
					 * <p> | 
				
			||||||
 | 
					 * Values are held in a caching VectVar, and digest caching is enabled by | 
				
			||||||
 | 
					 * default. | 
				
			||||||
 | 
					 * </p> | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public abstract class AbstractNumCache extends NumAdapter implements ConstraintCache<Num> { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private final NumVar cache = Num.makeVar(); | 
				
			||||||
 | 
						private boolean inited = false; | 
				
			||||||
 | 
						private boolean cachingEnabled = true; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public AbstractNumCache() { | 
				
			||||||
 | 
							enableDigestCaching(true); // it changes only on poll
 | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						protected final Num getSource() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (!inited) markDigestDirty(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return (cachingEnabled ? cache : getCacheSource()); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void poll() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							inited = true; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							// poll source
 | 
				
			||||||
 | 
							final Num source = getCacheSource(); | 
				
			||||||
 | 
							source.markDigestDirty(); // poll cached
 | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							// store source value
 | 
				
			||||||
 | 
							cache.setTo(source); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							// mark my digest dirty
 | 
				
			||||||
 | 
							markDigestDirty(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							onChange(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public abstract void onChange(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public abstract Num getCacheSource(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void enableCaching(boolean yes) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							cachingEnabled = yes; | 
				
			||||||
 | 
							enableDigestCaching(yes); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final boolean isCachingEnabled() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return cachingEnabled; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,35 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints.num.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.annotations.DefaultImpl; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Num cache implementation | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class NumCache extends AbstractNumCache { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private final Num source; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public NumCache(Num source) { | 
				
			||||||
 | 
							this.source = source; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final Num getCacheSource() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return source; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						@DefaultImpl | 
				
			||||||
 | 
						public void onChange() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class NumDigest { | 
					public class NumDigest { | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import mightypork.gamecore.control.timing.Pauseable; | 
					import mightypork.gamecore.control.timing.Pauseable; | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import mightypork.utils.math.Calc; | 
					import mightypork.utils.math.Calc; | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import mightypork.utils.math.Calc; | 
					import mightypork.utils.math.Calc; | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public abstract class NumAdapter extends Num { | 
					public abstract class NumAdapter extends Num { | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class NumBoundAdapter extends NumAdapter implements PluggableNumBound { | 
					public class NumBoundAdapter extends NumAdapter implements PluggableNumBound { | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.num.Num; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class NumProxy extends NumAdapter { | 
					public class NumProxy extends NumAdapter { | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.num; | 
					package mightypork.utils.math.constraints.num.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,49 +0,0 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * <p> | 
					 | 
				
			||||||
 * A rect cache. | 
					 | 
				
			||||||
 * </p> | 
					 | 
				
			||||||
 * <p> | 
					 | 
				
			||||||
 * Values are held in a caching VectVar, and digest caching is enabled by | 
					 | 
				
			||||||
 * default. | 
					 | 
				
			||||||
 * </p> | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public class RectCache extends RectAdapter { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private final RectVar cache = Rect.makeVar(); | 
					 | 
				
			||||||
	private final Rect source; | 
					 | 
				
			||||||
	private boolean inited = false; | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public RectCache(Rect source) { | 
					 | 
				
			||||||
		this.source = source; | 
					 | 
				
			||||||
		enableDigestCaching(true); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	protected Rect getSource() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (!inited) poll(); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		return cache; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * Update cached value and cached digest (if digest caching is enabled) | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void poll() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		inited = true; | 
					 | 
				
			||||||
		cache.setTo(source); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		super.poll(); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -0,0 +1,73 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints.rect.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.ConstraintCache; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.mutable.RectVar; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.proxy.RectAdapter; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * <p> | 
				
			||||||
 | 
					 * A rect cache. | 
				
			||||||
 | 
					 * </p> | 
				
			||||||
 | 
					 * <p> | 
				
			||||||
 | 
					 * Values are held in a caching VectVar, and digest caching is enabled by | 
				
			||||||
 | 
					 * default. | 
				
			||||||
 | 
					 * </p> | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public abstract class AbstractRectCache extends RectAdapter implements ConstraintCache<Rect> { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private final RectVar cache = Rect.makeVar(); | 
				
			||||||
 | 
						private boolean inited = false; | 
				
			||||||
 | 
						private boolean cachingEnabled = true; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public AbstractRectCache() { | 
				
			||||||
 | 
							enableDigestCaching(true); // it changes only on poll
 | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						protected final Rect getSource() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (!inited) markDigestDirty(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return (cachingEnabled ? cache : getCacheSource()); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void poll() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							inited = true; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							// poll source
 | 
				
			||||||
 | 
							final Rect source = getCacheSource(); | 
				
			||||||
 | 
							source.markDigestDirty(); // poll cached
 | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							// store source value
 | 
				
			||||||
 | 
							cache.setTo(source); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							markDigestDirty(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							onChange(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void enableCaching(boolean yes) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							cachingEnabled = yes; | 
				
			||||||
 | 
							enableDigestCaching(yes); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final boolean isCachingEnabled() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return cachingEnabled; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,36 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints.rect.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.annotations.DefaultImpl; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Rect cache implementation | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class RectCache extends AbstractRectCache { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private final Rect source; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public RectCache(Rect source) { | 
				
			||||||
 | 
							this.source = source; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final Rect getCacheSource() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return source; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						@DefaultImpl | 
				
			||||||
 | 
						public void onChange() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,4 +1,7 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.RectConst; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class RectDigest { | 
					public class RectDigest { | 
				
			||||||
@ -1,6 +1,7 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
import mightypork.utils.math.constraints.vect.Vect; | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1,8 +1,8 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import mightypork.utils.math.constraints.vect.Vect; | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
import mightypork.utils.math.constraints.vect.VectVar; | 
					import mightypork.utils.math.constraints.vect.mutable.VectVar; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class RectVar extends RectMutable { | 
					public class RectVar extends RectMutable { | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,8 +1,9 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
import mightypork.utils.math.constraints.vect.Vect; | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
import mightypork.utils.math.constraints.vect.VectAdapter; | 
					import mightypork.utils.math.constraints.vect.proxy.VectAdapter; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.rect; | 
					package mightypork.utils.math.constraints.rect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.rect.Rect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class RectProxy extends RectAdapter { | 
					public class RectProxy extends RectAdapter { | 
				
			||||||
@ -1,49 +0,0 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * <p> | 
					 | 
				
			||||||
 * A vect cache. | 
					 | 
				
			||||||
 * </p> | 
					 | 
				
			||||||
 * <p> | 
					 | 
				
			||||||
 * Values are held in a caching VectVar, and digest caching is enabled by | 
					 | 
				
			||||||
 * default. | 
					 | 
				
			||||||
 * </p> | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public class VectCache extends VectAdapter { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private final VectVar cache = Vect.makeVar(); | 
					 | 
				
			||||||
	private final Vect source; | 
					 | 
				
			||||||
	private boolean inited = false; | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public VectCache(Vect source) { | 
					 | 
				
			||||||
		this.source = source; | 
					 | 
				
			||||||
		enableDigestCaching(true); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	protected Vect getSource() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (!inited) poll(); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		return cache; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * Update cached value and cached digest (if digest caching is enabled) | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void poll() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		inited = true; | 
					 | 
				
			||||||
		cache.setTo(source); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		super.poll(); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -0,0 +1,73 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints.vect.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.ConstraintCache; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.mutable.VectVar; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.proxy.VectAdapter; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * <p> | 
				
			||||||
 | 
					 * A vect cache. | 
				
			||||||
 | 
					 * </p> | 
				
			||||||
 | 
					 * <p> | 
				
			||||||
 | 
					 * Values are held in a caching VectVar, and digest caching is enabled by | 
				
			||||||
 | 
					 * default. | 
				
			||||||
 | 
					 * </p> | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public abstract class AbstractVectCache extends VectAdapter implements ConstraintCache<Vect> { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private final VectVar cache = Vect.makeVar(); | 
				
			||||||
 | 
						private boolean inited = false; | 
				
			||||||
 | 
						private boolean cachingEnabled = true; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public AbstractVectCache() { | 
				
			||||||
 | 
							enableDigestCaching(true); // it changes only on poll
 | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						protected final Vect getSource() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (!inited) markDigestDirty(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return (cachingEnabled ? cache : getCacheSource()); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void poll() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							inited = true; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							// poll source
 | 
				
			||||||
 | 
							final Vect source = getCacheSource(); | 
				
			||||||
 | 
							source.markDigestDirty(); // poll cached
 | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							// store source value
 | 
				
			||||||
 | 
							cache.setTo(source); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							markDigestDirty(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							onChange(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final void enableCaching(boolean yes) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							cachingEnabled = yes; | 
				
			||||||
 | 
							enableDigestCaching(yes); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public final boolean isCachingEnabled() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return cachingEnabled; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,36 @@ | 
				
			|||||||
 | 
					package mightypork.utils.math.constraints.vect.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.annotations.DefaultImpl; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Vect cache implementation | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class VectCache extends AbstractVectCache { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private final Vect source; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public VectCache(Vect source) { | 
				
			||||||
 | 
							this.source = source; | 
				
			||||||
 | 
							enableDigestCaching(true); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public Vect getCacheSource() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return source; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						@DefaultImpl | 
				
			||||||
 | 
						public void onChange() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					package mightypork.utils.math.constraints.vect.caching; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class VectDigest { | 
					public class VectDigest { | 
				
			||||||
@ -1,11 +1,12 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					package mightypork.utils.math.constraints.vect.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import mightypork.gamecore.control.timing.Pauseable; | 
					import mightypork.gamecore.control.timing.Pauseable; | 
				
			||||||
import mightypork.gamecore.control.timing.Updateable; | 
					import mightypork.gamecore.control.timing.Updateable; | 
				
			||||||
import mightypork.utils.annotations.FactoryMethod; | 
					import mightypork.utils.annotations.FactoryMethod; | 
				
			||||||
import mightypork.utils.math.Easing; | 
					import mightypork.utils.math.Easing; | 
				
			||||||
import mightypork.utils.math.constraints.num.NumAnimated; | 
					import mightypork.utils.math.constraints.num.mutable.NumAnimated; | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					package mightypork.utils.math.constraints.vect.mutable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,4 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					package mightypork.utils.math.constraints.vect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					package mightypork.utils.math.constraints.vect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					package mightypork.utils.math.constraints.vect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** | 
					/** | 
				
			||||||
@ -1,4 +1,6 @@ | 
				
			|||||||
package mightypork.utils.math.constraints.vect; | 
					package mightypork.utils.math.constraints.vect.proxy; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.math.constraints.vect.Vect; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class VectBoundAdapter extends VectAdapter implements PluggableVectBound { | 
					public class VectBoundAdapter extends VectAdapter implements PluggableVectBound { | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue