public void run() {
		running = true;
		
		int frames = 0;
		long frameCounter = 0;
		
		final double frameTime = 1.0 / Constants.FRAME_CAP;
		
		long lastTime = Time.getTime();
		double unprocessedTime = 0;		
		
		while(running) {
			boolean render = false;
			
			long startTime = Time.getTime();
			long passedTime = startTime - lastTime;
			lastTime = startTime;
			
			unprocessedTime += passedTime / (double) Time.SECOND;
			frameCounter += passedTime;
			
			while(unprocessedTime > frameTime) {
				render = true;
				
				unprocessedTime -= frameTime;
				update();
				
				if(frameCounter >= Time.SECOND) {
					fps = frames;
					frames = 0;
					frameCounter = 0;
				}
			}
			
			if(render) {
				repaint();
				frames++;
			} else {
				Util.sleep(1);
			}
		}
	}