From 66a5a91b4804943b865d7e5c9ca0c4f872e6f815 Mon Sep 17 00:00:00 2001
From: Pan Hu
Date: Tue, 21 May 2019 10:57:54 +1200
Subject: [PATCH] h
---
core/mainThread.java | 43 +++++++------------------------------------
1 file changed, 7 insertions(+), 36 deletions(-)
diff --git a/core/mainThread.java b/core/mainThread.java
index f73bfbf..23b3b57 100644
--- a/core/mainThread.java
+++ b/core/mainThread.java
@@ -28,7 +28,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
public static int gameFrame;
public static long lastDraw;
public static long delta;
- public static int sleepTime;
+ public static long sleepTime;
public static int framePerSecond, cpuUsage;
public static double thisTime, lastTime;
public static boolean JavaRTSLoaded;
@@ -589,48 +589,19 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
}
public void regulateFramerate(){
- //if(frameIndex%35==0){
- // double thisTime = System.currentTimeMillis();
- // framePerSecond = (int)(1000/((thisTime - lastTime)/35));
- // lastTime = thisTime;
- //}
-
- long currentTime = System.nanoTime();
+ //frameInterval is a constant 25 milliseconds.
+ sleepTime = frameInterval - (System.currentTimeMillis()-lastDraw);
+
try {
- long timeSpent = currentTime - lastDraw;
-
- int sleeptime = (int)(frameInterval - timeSpent/1000000);
-
-
- if(delta >= 1000000) {
- sleeptime--;
- delta-=1000000;
- }
-
- if(sleeptime > 0)
- Thread.sleep(sleeptime);
- delta+=timeSpent%1000000;
+ if(sleepTime > 0)
+ Thread.sleep(sleepTime);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
-
- /*sleepTime = 0;
- while(System.currentTimeMillis()-lastDraw