package io.nub.core.extras;

import io.nub.core.util.Function;

/**
 * @author Nektro
 */
public class Looper
{
	private final Loop loop;
	private final int rate;
	private int frame;
	private Function func;
	
	public boolean running;
	
	public Looper(int min, int max, int startFrame, int rate, Function f)
	{
		this.loop = new Loop(min, max, startFrame);
		this.rate = rate;
		this.running = true;
		this.func = f;
	}
	public Looper(int min, int max, int startFrame, int rate) {
		this(min, max, startFrame, rate, new Function(){
			@Override
			public void call() {
			}
		});
	}
	
	public int val()
	{
		return loop.val();
	}
	
	public void update()
	{
		if (running) {
			int f = (int) (System.currentTimeMillis() / rate);
			if (f != frame) {
				loop.inc();
				func.call();
			}
			frame = f;
		}
	}
	
	public void inc()
	{
		this.loop.inc();
	}
}

@@ -412,16 +412,18 @@
 = f;%0A%09%7D%0A
+%09%0A
 %09public 
@@ -524,16 +524,17 @@
 nction()
+ 
 %7B%0A%09%09%09@Ov

fix spacing