Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rogue-savage-rats/src/mightypork/utils/math/constraints/RectCache.java

57 lines
1.0 KiB

package mightypork.utils.math.constraints;
import mightypork.gamecore.control.timing.Pollable;
import mightypork.gamecore.control.timing.Poller;
import mightypork.utils.math.rect.RectMutable;
import mightypork.utils.math.rect.RectView;
/**
* {@link RectBound} cache, used for caching computed Rect from a complex
* {@link RectBound}.<br>
* Calculates only when polled.
*
* @author MightyPork
*/
public class RectCache implements RectBound, Pollable {
private final RectBound observed;
private final RectMutable cached = RectMutable.zero();
/**
* @param observed cached constraint
*/
public RectCache(RectBound observed) {
this.observed = observed;
poll();
}
/**
* Create and join a poller
*
* @param poller poller to join
* @param rc observed constraint
*/
public RectCache(Poller poller, RectBound rc) {
this(rc);
poller.add(this);
}
@Override
public RectView getRect()
{
return cached;
}
@Override
public void poll()
{
cached.setTo(observed.getRect());
}
}