Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void run()
- {
- long lastTime = System.nanoTime(); //get nanoTime
- double nsPerTick = 1000000000d/60d; //calcuates how many ns in 1 tick
- int ticks = 0;
- int frames = 0;
- long lastTimer = System.currentTimeMillis();
- double delta = 0; //how many nano seconds have gone by
- init();
- while(running)
- {
- long now = System.nanoTime();
- delta +=(now - lastTime) / nsPerTick;
- lastTime = now;
- boolean shouldRender = true;
- while(delta >= 1)
- {
- ticks++;
- tick();
- delta-=1;
- shouldRender = true;
- }
- try {
- Thread.sleep(2);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if(shouldRender)
- {
- frames++;
- render();
- }
- if(System.currentTimeMillis() - lastTimer >= 1000)
- {
- lastTimer += 1000;
- System.out.println(ticks + "ticks, " + frames + "frames");
- frames = 0;
- ticks = 0;
- }
- }
- }
- public void tick()
- {
- tickCount++;
- //TODO: Add some shitty movement code
- //TODO: Rendering stuff?
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement