This commit is contained in:
Pan 2019-05-21 08:22:30 +12:00
parent 5a6e65b196
commit 051d1e56a7
2 changed files with 4 additions and 11 deletions

View File

@ -318,7 +318,6 @@ public class AssetManager {
rockets = null; rockets = null;
mainThread.gridMap.reset(); mainThread.gridMap.reset();
mainThread.totalGameTime = 0;
solidObject.globalUniqID = 0; solidObject.globalUniqID = 0;
postProcessingThread.reset(); postProcessingThread.reset();

View File

@ -26,7 +26,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
public static int frameInterval; public static int frameInterval;
public static int frameIndex; public static int frameIndex;
public static int gameFrame; public static int gameFrame;
public static long lastDraw, lastFrameTime, frameTime, totalGameTime; public static long lastDraw;
public static long delta; public static long delta;
public static int sleepTime; public static int sleepTime;
public static int framePerSecond, cpuUsage; public static int framePerSecond, cpuUsage;
@ -251,9 +251,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
if(!gamePaused) { if(!gamePaused) {
if(gameStarted) if(gameStarted)
gameFrame++; gameFrame++;
if(gameFrame > 0)
totalGameTime+=frameTime; timeString = secondsToString((int)(gameFrame*0.025));
timeString = secondsToString((int)(totalGameTime/1000000000));
//handle user's interaction with game GUI //handle user's interaction with game GUI
if(gameFrame == 1 && gameStarted){ if(gameFrame == 1 && gameStarted){
@ -597,19 +596,15 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
//} //}
long currentTime = System.nanoTime(); long currentTime = System.nanoTime();
frameTime = currentTime - lastFrameTime;
try { try {
long timeSpent = currentTime - lastDraw; long timeSpent = currentTime - lastDraw;
int sleeptime = (int)(frameInterval - timeSpent/1000000); int sleeptime = (int)(frameInterval - timeSpent/1000000);
if(delta >= 1000000) { if(delta >= 1000000) {
sleeptime-=1; sleeptime--;
delta-=1000000; delta-=1000000;
} }
if(sleeptime > 0) if(sleeptime > 0)
@ -636,7 +631,6 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
lastDraw=System.nanoTime(); lastDraw=System.nanoTime();
lastFrameTime= currentTime;
} }
public static String secondsToString(int pTime) { public static String secondsToString(int pTime) {