@Test public void testSingleRunError() throws Exception { GameScene theScene = mock(GameScene.class); GameView theGameView = mock(GameView.class); GameRuntime theRuntime = mock(GameRuntime.class); GameEventManager theManager = mock(GameEventManager.class); when(theRuntime.getEventManager()).thenReturn(theManager); GameLoop theLoop = new GameLoop(theScene, theGameView, theRuntime); theLoop.singleRun(); Thread.sleep(10); theLoop.singleRun(); verify(theManager, times(2)).fire(any(GameEvent.class)); }
public void singleRun() { if (lastInvocation == 0) { lastInvocation = System.currentTimeMillis(); runtime.getEventManager().fire(new SceneStarted()); return; } long theCurrentTime = System.currentTimeMillis(); long theGameTime = theCurrentTime - statistics.getStartTime(); long theElapsedTime = theCurrentTime - lastInvocation; if (theElapsedTime > 0) { try { long theNumberOfTicks = statistics.incrementTicks(); statistics.beginGameLoop(); Map<GameSystem, GameSystemWork> theFutures = new HashMap<>(); for (GameSystem theSystem : runtime.getSystems()) { GameSystemWork theWork = theSystem.proceedGame(theNumberOfTicks, theGameTime, theElapsedTime); theWork.runInFrame(); theFutures.put(theSystem, theWork); }; for (GameView theGameView : gameViews) { theGameView.renderGame(theGameTime, theElapsedTime, scene, statistics); } for (Map.Entry<GameSystem, GameSystemWork> theEntry : theFutures.entrySet()) { theEntry.getValue().runAfterFrame(); } lastInvocation = theCurrentTime; } catch (Exception e) { runtime.getEventManager().fire(new SystemException(e)); } finally { statistics.endGameLoop(); } } }
GameLoop implements Runnable { public void singleRun() { if (lastInvocation == 0) { lastInvocation = System.currentTimeMillis(); runtime.getEventManager().fire(new SceneStarted()); return; } long theCurrentTime = System.currentTimeMillis(); long theGameTime = theCurrentTime - statistics.getStartTime(); long theElapsedTime = theCurrentTime - lastInvocation; if (theElapsedTime > 0) { try { long theNumberOfTicks = statistics.incrementTicks(); statistics.beginGameLoop(); Map<GameSystem, GameSystemWork> theFutures = new HashMap<>(); for (GameSystem theSystem : runtime.getSystems()) { GameSystemWork theWork = theSystem.proceedGame(theNumberOfTicks, theGameTime, theElapsedTime); theWork.runInFrame(); theFutures.put(theSystem, theWork); }; for (GameView theGameView : gameViews) { theGameView.renderGame(theGameTime, theElapsedTime, scene, statistics); } for (Map.Entry<GameSystem, GameSystemWork> theEntry : theFutures.entrySet()) { theEntry.getValue().runAfterFrame(); } lastInvocation = theCurrentTime; } catch (Exception e) { runtime.getEventManager().fire(new SystemException(e)); } finally { statistics.endGameLoop(); } } } }
GameLoop implements Runnable { public void singleRun() { if (lastInvocation == 0) { lastInvocation = System.currentTimeMillis(); runtime.getEventManager().fire(new SceneStarted()); return; } long theCurrentTime = System.currentTimeMillis(); long theGameTime = theCurrentTime - statistics.getStartTime(); long theElapsedTime = theCurrentTime - lastInvocation; if (theElapsedTime > 0) { try { long theNumberOfTicks = statistics.incrementTicks(); statistics.beginGameLoop(); Map<GameSystem, GameSystemWork> theFutures = new HashMap<>(); for (GameSystem theSystem : runtime.getSystems()) { GameSystemWork theWork = theSystem.proceedGame(theNumberOfTicks, theGameTime, theElapsedTime); theWork.runInFrame(); theFutures.put(theSystem, theWork); }; for (GameView theGameView : gameViews) { theGameView.renderGame(theGameTime, theElapsedTime, scene, statistics); } for (Map.Entry<GameSystem, GameSystemWork> theEntry : theFutures.entrySet()) { theEntry.getValue().runAfterFrame(); } lastInvocation = theCurrentTime; } catch (Exception e) { runtime.getEventManager().fire(new SystemException(e)); } finally { statistics.endGameLoop(); } } } GameLoop(GameScene aScene, GameView aHumanGameView, GameRuntime aRuntime); }
GameLoop implements Runnable { public void singleRun() { if (lastInvocation == 0) { lastInvocation = System.currentTimeMillis(); runtime.getEventManager().fire(new SceneStarted()); return; } long theCurrentTime = System.currentTimeMillis(); long theGameTime = theCurrentTime - statistics.getStartTime(); long theElapsedTime = theCurrentTime - lastInvocation; if (theElapsedTime > 0) { try { long theNumberOfTicks = statistics.incrementTicks(); statistics.beginGameLoop(); Map<GameSystem, GameSystemWork> theFutures = new HashMap<>(); for (GameSystem theSystem : runtime.getSystems()) { GameSystemWork theWork = theSystem.proceedGame(theNumberOfTicks, theGameTime, theElapsedTime); theWork.runInFrame(); theFutures.put(theSystem, theWork); }; for (GameView theGameView : gameViews) { theGameView.renderGame(theGameTime, theElapsedTime, scene, statistics); } for (Map.Entry<GameSystem, GameSystemWork> theEntry : theFutures.entrySet()) { theEntry.getValue().runAfterFrame(); } lastInvocation = theCurrentTime; } catch (Exception e) { runtime.getEventManager().fire(new SystemException(e)); } finally { statistics.endGameLoop(); } } } GameLoop(GameScene aScene, GameView aHumanGameView, GameRuntime aRuntime); void addGameView(GameView aNewGameView); GameView getHumanGameView(); GameScene getScene(); @Override void run(); void singleRunOnlyUpdateGameView(); void singleRun(); void shutdown(); boolean isShutdown(); }
GameLoop implements Runnable { public void singleRun() { if (lastInvocation == 0) { lastInvocation = System.currentTimeMillis(); runtime.getEventManager().fire(new SceneStarted()); return; } long theCurrentTime = System.currentTimeMillis(); long theGameTime = theCurrentTime - statistics.getStartTime(); long theElapsedTime = theCurrentTime - lastInvocation; if (theElapsedTime > 0) { try { long theNumberOfTicks = statistics.incrementTicks(); statistics.beginGameLoop(); Map<GameSystem, GameSystemWork> theFutures = new HashMap<>(); for (GameSystem theSystem : runtime.getSystems()) { GameSystemWork theWork = theSystem.proceedGame(theNumberOfTicks, theGameTime, theElapsedTime); theWork.runInFrame(); theFutures.put(theSystem, theWork); }; for (GameView theGameView : gameViews) { theGameView.renderGame(theGameTime, theElapsedTime, scene, statistics); } for (Map.Entry<GameSystem, GameSystemWork> theEntry : theFutures.entrySet()) { theEntry.getValue().runAfterFrame(); } lastInvocation = theCurrentTime; } catch (Exception e) { runtime.getEventManager().fire(new SystemException(e)); } finally { statistics.endGameLoop(); } } } GameLoop(GameScene aScene, GameView aHumanGameView, GameRuntime aRuntime); void addGameView(GameView aNewGameView); GameView getHumanGameView(); GameScene getScene(); @Override void run(); void singleRunOnlyUpdateGameView(); void singleRun(); void shutdown(); boolean isShutdown();  }