private void loop(){
  final int frameLength=(int)(1000.0 / stendhal.FPS_LIMIT);
  int fps=0;
  long refreshTime=System.currentTimeMillis();
  long lastFpsTime=refreshTime;
  while (running) {
    try {
      fps++;
      final long now=System.currentTimeMillis();
      final int delta=(int)(now - refreshTime);
      refreshTime=now;
      persistentTask.run(delta);
      Runnable tempTask=temporaryTasks.poll();
      while (tempTask != null) {
        tempTask.run();
        tempTask=temporaryTasks.poll();
      }
      if (logger.isDebugEnabled()) {
        reportClientInfo(refreshTime,lastFpsTime,fps);
        fps=0;
        lastFpsTime=refreshTime;
      }
      logger.debug("Start sleeping");
      long wait=frameLength + refreshTime - System.currentTimeMillis();
      if (wait > 0) {
        if (wait > 100L) {
          logger.info("Waiting " + wait + " ms");
          wait=100L;
        }
        try {
          Thread.sleep(wait);
        }
 catch (        final InterruptedException e) {
          logger.error(e,e);
        }
      }
      logger.debug("End sleeping");
    }
 catch (    RuntimeException e) {
      logger.error(e,e);
    }
  }
}

private void loop ( ) { final int frameLength = ( int ) ( 1000.0 / stendhal . FPS_LIMIT ) ; int fps = 0 ; long refreshTime = System . currentTimeMillis ( ) ; long lastFpsTime = refreshTime ; while ( running ) { try { fps ++ ; final long now = System . currentTimeMillis ( ) ; final int delta = ( int ) ( now - refreshTime ) ; refreshTime = now ; persistentTask . run ( delta ) ; Runnable tempTask = temporaryTasks . poll ( ) ; while ( tempTask != null ) { tempTask . run ( ) ; tempTask = temporaryTasks . poll ( ) ; } if ( logger . isDebugEnabled ( ) ) { reportClientInfo ( refreshTime , lastFpsTime , fps ) ; fps = 0 ; lastFpsTime = refreshTime ; } logger . debug ( "Start sleeping" ) ; long wait = frameLength + refreshTime - System . currentTimeMillis ( ) ; if ( wait > 0 ) { if ( wait > 100L ) { logger . info ( "Waiting " + wait + " ms" ) ; wait = 100L ; } try { Thread . sleep ( wait ) ; } catch ( final InterruptedException e ) { logger . error ( e , e ) ; } } logger . debug ( "End sleeping" ) ; } catch ( RuntimeException e ) { logger . error ( e , e ) ; } } }
the actual game loop .
