@Override
	public void run() {
		int frames = 0;
		int tickCount = 0;
		double unprocessedSeconds = 0;
		double secondsPerTick = 1 / 60.0;
		long lastTime = System.nanoTime();
		
		while (running) {
			long now = System.nanoTime();
			long passedTime = now - lastTime;
			lastTime = now;
			
			if (passedTime < 0) passedTime = 0;
			if (passedTime > 100000000) passedTime = 100000000;
			
			unprocessedSeconds += passedTime / 1000000000.0;
			
			boolean ticked = false;
			while (unprocessedSeconds > secondsPerTick) {
				tick();
				unprocessedSeconds -= secondsPerTick;
				ticked = true;
				
				tickCount++;
				if (tickCount % 60 == 0) {
					String perfData = "FPS: " + frames + ", Ticks: " + tickCount;
					//System.out.println(perfData);
					if (game.capFrameRate) {
						frame.setTitle(TITLE + "  |  " + perfData + ", FPS Cap: Yes");
					} else {
						frame.setTitle(TITLE + "  |  " + perfData + ", FPS Cap: Yes");
					}
					lastTime += 1000;
					frames = 0;
					tickCount = 0;
				}
			}
			
			if (game.capFrameRate) {
				if (ticked) {
					render();
					frames++;
				}
			} else {
				render();
				frames++;
			}
			
		}
	}