Advertisement
Guest User

Extremely well-written interpolation-y stuff

a guest
Aug 28th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. public void run(){
  2.             final int SKIP_TICKS = 1000 / TARGET_UPS;
  3.             final int MAX_FRAMESKIP = 1;
  4.            
  5.             long nextTick = getTickTime();
  6.             long lastTick = 0;
  7.            
  8.             while(running){
  9.                 //System.out.println(((float)(lastTick - getTickTime()) / 1000) + " seconds =D");
  10.                
  11.                 int loops = 0;
  12.                
  13.                 while(getTickTime() > nextTick && loops < MAX_FRAMESKIP){
  14.                     //System.out.println("I TICKED, OOOOOOOooooOOOOOOO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WAAHHAAHAHAHAH I AM SUCH A CRAFTY TICKER, HDSJKFKSGKDGHKJSD");
  15.                     //System.out.println((float)(getTickTime() - lastTick) / 1000f);
  16.                     lastTick = getTickTime();
  17.                    
  18.                     tick();
  19.                    
  20.                     nextTick += SKIP_TICKS;
  21.                     loops++;
  22.                 }
  23.                 repaint();
  24.                
  25.                 //System.out.println("The time is " + getTickTime() + ", mates. But wait! The next crap is at " + nextTick + ", I dare say!");
  26.                 //System.out.println("I will attempt a super-duper time travel program! Since the next crap is at " + nextTick + ", and the current time is " + getTickTime() + ", the amount of sleep needed should be the difference of the two...");
  27.                 long sleepTime = nextTick - getTickTime();
  28.                 //System.out.println("That is " + sleepTime + "!");
  29.                
  30.                 if(sleepTime > 0){
  31.                     //System.out.println("TIME TO TIME TRAVEL " + sleepTime + " MILLISECONDS, WHEEEEEE");
  32.                     try {
  33.                         Thread.sleep(Math.max(sleepTime + 1, 0));
  34.                     } catch (InterruptedException e){
  35.                         e.printStackTrace();
  36.                     }
  37.                 }
  38.             }
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement