package com.betato.gamedisplay;

public class GameLoop {
		
	private int targetFps = 60;
	private int nanoFps = 1000000000 / targetFps;
	private int targetUps = 60;
	private int nanoUps = 1000000000 / targetUps;
	
	public boolean running = true;
	public long deltaUps = 0;
	
	public GameLoop(int targetFps, int targetUps) {
		this.targetFps = targetFps;
		this.targetUps = targetUps;
		nanoFps = 1000000000 / targetFps;
		nanoUps = 1000000000 / targetUps;
	}
	
	// Runs the GameLoop
	public void run(GameWindow game) {
		
		long startTime = System.nanoTime();
		long deltaFps = 0;
		long deltaDisplay = 0;
		int framecount = 0;
		int updatecount = 0;
		
		while (running) {
			// Get current time
			long currentTime = System.nanoTime();
			// Get time since last loop
			deltaFps += currentTime - startTime;
			deltaUps += currentTime - startTime;
			deltaDisplay += currentTime - startTime;

			// Set start time of this loop for use in next cycle
			startTime = currentTime;

			// Render if target time has been reached
			if (deltaFps >= nanoFps) {
				// Render
				game.render();
				framecount++;
				deltaFps = 0;
			}

			// Update if target time has been reached
			if (deltaUps >= nanoUps) {
				// Update
				game.update();
				updatecount++;
				deltaUps = 0;
			}

			// Update fps and ups if one second has passed
			if (deltaDisplay >= 1000000000) {
				game.updateFps(framecount, updatecount);
				framecount = 0;
				updatecount = 0;
				deltaDisplay = 0;
			}
		}
	}
}

@@ -26,16 +26,99 @@
 splay;%0A%0A
+/**%0A * A game loop to run a GameWindow at the specified frame and update rate.%0A */%0A
 public c
@@ -133,19 +133,17 @@
 eLoop %7B%0A
-%09%09
 %0A
+
 %09private
@@ -286,18 +286,17 @@
 getUps;%0A
-%09
 %0A
+
 %09public 
@@ -346,17 +346,289 @@
 ps = 0;%0A
-%09
+%0A%09/**%0A%09 * Creates a new GameLoop with the specified frame rate and update rate.%0A%09 * %0A%09 * @param targetFps%0A%09 *            The frame rate for the GameWindow in frames per second%0A%09 * @param targetUps%0A%09 *            The update rate for the GameWindow in updates per second%0A%09 */
 %0A%09public
@@ -808,40 +808,10 @@
 %0A%09%7D%0A
-%09
 %0A%09
-// Runs the GameLoop%0A%09public 
 void
@@ -834,18 +834,16 @@
 game) %7B%0A
-%09%09
 %0A%09%09long 
@@ -964,18 +964,16 @@
 nt = 0;%0A
-%09%09
 %0A%09%09while

Add Javadoc comments for GameLoop