@Override
	public void run()
	{
		
		long startSecond=0;
		long timeTick=0;
		long timeFrame=0;
		long time=0;
		long wait=0;
		long leftover=0;
		
		elapsedTime=0;
		
		try
		{
			while(running())
			{
				time=System.nanoTime();
				sleep(0,1);
				time=System.nanoTime()-time;
				elapsedTime+=time;
				timeTick+=time;
				timeFrame+=time;
				time=System.nanoTime();
				while(timeTick>=NANOSECOND/ticksPerSecond)
				{
					timeTick-=NANOSECOND/ticksPerSecond;
					engine().tick();
					totalTicks++;
				}
				if(timeFrame>=NANOSECOND/framesPerSecond)
				{
					timeFrame-=NANOSECOND/framesPerSecond;
					engine().redraw();
					totalFrames++;
				}
				time=System.nanoTime()-time;
				elapsedTime+=time;
				timeTick+=time;
				timeFrame+=time;
				
				if(elapsedTime>NANOSECOND*2)
				{
					elapsedTime-=NANOSECOND;
					totalTicks-=ticksPerSecond;
					totalFrames-=framesPerSecond;
				}
			}
		}
		catch(InterruptedException e)
		{
			e.printStackTrace();
			running(false);
		}
		
		engine().kill();
	}