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.
57 lines
978 B
57 lines
978 B
11 years ago
|
package mightypork.utils.math.constraints;
|
||
11 years ago
|
|
||
|
|
||
11 years ago
|
import mightypork.gamecore.control.timing.Pollable;
|
||
|
import mightypork.gamecore.control.timing.Poller;
|
||
11 years ago
|
import mightypork.utils.math.rect.Rect;
|
||
11 years ago
|
|
||
|
|
||
|
/**
|
||
|
* {@link RectConstraint} cache, used to reduce CPU load with very complex
|
||
|
* constraints.<br>
|
||
|
* Calculates only when polled.
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
|
public class RectCache implements RectConstraint, Pollable {
|
||
|
|
||
|
private final RectConstraint observed;
|
||
|
private final Rect cached = new Rect();
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param observed cached constraint
|
||
|
*/
|
||
|
public RectCache(RectConstraint observed) {
|
||
|
this.observed = observed;
|
||
|
poll();
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Create and join a poller
|
||
|
*
|
||
|
* @param poller poller to join
|
||
|
* @param rc observed constraint
|
||
|
*/
|
||
|
public RectCache(Poller poller, RectConstraint rc) {
|
||
|
this(rc);
|
||
|
poller.add(this);
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public Rect getRect()
|
||
|
{
|
||
|
return cached;
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void poll()
|
||
|
{
|
||
|
cached.setTo(observed.getRect());
|
||
|
}
|
||
|
|
||
|
}
|