@Override
	public void run() {
		//~!!!!!
		int fps = 0; int updates = 0;
		long fpsTimer = System.currentTimeMillis();
		double nsPerUpdate = 1000000000.0/60;
		
		//last update time in nanoseconds
		double then = System.nanoTime();
		double unprocessed = 0;
		
		while(running){
			
			boolean shouldRender = false;
			double now = System.nanoTime();
			unprocessed += (now - then)/nsPerUpdate;
			then = now;
			
			//update queue
			while(unprocessed >= 1){
				updates++;
				update();
				unprocessed--;
				shouldRender = true;
			}
			
			//render
			if(shouldRender){
				fps++;
				render();
				shouldRender = false;
			}
			else{
				try{
					Thread.sleep(1);
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
		
		///FPS Timer
		if(System.currentTimeMillis() - fpsTimer > 1000){
			System.out.printf("%d fps %d updates", fps, updates);
			System.out.println();
			fps = 0;
			updates = 0;
			fpsTimer += 1000;
		}
	}