Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void run(){
- final int SKIP_TICKS = 1000 / TARGET_UPS;
- final int MAX_FRAMESKIP = 1;
- long nextTick = getTickTime();
- long lastTick = 0;
- while(running){
- //System.out.println(((float)(lastTick - getTickTime()) / 1000) + " seconds =D");
- int loops = 0;
- while(getTickTime() > nextTick && loops < MAX_FRAMESKIP){
- //System.out.println("I TICKED, OOOOOOOooooOOOOOOO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WAAHHAAHAHAHAH I AM SUCH A CRAFTY TICKER, HDSJKFKSGKDGHKJSD");
- //System.out.println((float)(getTickTime() - lastTick) / 1000f);
- lastTick = getTickTime();
- tick();
- nextTick += SKIP_TICKS;
- loops++;
- }
- repaint();
- //System.out.println("The time is " + getTickTime() + ", mates. But wait! The next crap is at " + nextTick + ", I dare say!");
- //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...");
- long sleepTime = nextTick - getTickTime();
- //System.out.println("That is " + sleepTime + "!");
- if(sleepTime > 0){
- //System.out.println("TIME TO TIME TRAVEL " + sleepTime + " MILLISECONDS, WHEEEEEE");
- try {
- Thread.sleep(Math.max(sleepTime + 1, 0));
- } catch (InterruptedException e){
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement