private void doWork()
	{
		double fps = getFramesPerSecond();

		if (fps < FPS_STOP)
		{
			tick();
			realFPS++;
			return;
		}
		else if (fps == FPS_STOP)
		{
			return;
		}

		long time = System.nanoTime();
		long elapsedTime = time - lastTime;
		int timeForOneFrame = (int) (Time.NANOSECONDS_PER_SECOND / fps);

		if (elapsedTime >= timeForOneFrame)
		{
			long ticks = elapsedTime / timeForOneFrame;

			for (int i = 0; i < ticks && i >= 0; i++)
			{
				tick();
				realFPS++;
			}

			lastTime += ticks * timeForOneFrame;
		}
		else
		{
			long timeToTick = timeForOneFrame - elapsedTime;

			try
			{
				Thread.sleep(timeToTick / Time.NANOSECONDS_PER_MILLISECOND,
					(int) (timeToTick % Time.NANOSECONDS_PER_MILLISECOND));
			}
			catch (InterruptedException e)
			{
			}
		}
	}