aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2018-02-01 21:43:29 +0100
committerAdam NAILI2018-02-01 21:43:29 +0100
commite587846281f52e79f983dfcf5934c65fd0577b39 (patch)
treecd4a073b6045f124a99ab206863c1d443611351e
parente6fe344a1c2666d39a7d0bde25f845e6b1d37684 (diff)
downloadwallj-e587846281f52e79f983dfcf5934c65fd0577b39.tar.gz
Refactoring Viewer.renderFrame()
-rw-r--r--src/docs/class.puml1
-rw-r--r--src/main/java/fr/umlv/java/wallj/viewer/Viewer.java22
2 files changed, 7 insertions, 16 deletions
diff --git a/src/docs/class.puml b/src/docs/class.puml
index 779f764..075aa39 100644
--- a/src/docs/class.puml
+++ b/src/docs/class.puml
@@ -13,7 +13,6 @@ package viewer {
13 final Game 13 final Game
14 Viewer(List<Board>) 14 Viewer(List<Board>)
15 void eventLoop(ApplicationContext) 15 void eventLoop(ApplicationContext)
16 void renderFrame(Graphics2D,ApplicationContext,List<Event>)
17 } 16 }
18} 17}
19 18
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java b/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java
index 030dc97..0fee046 100644
--- a/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java
+++ b/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java
@@ -49,7 +49,13 @@ public final class Viewer {
49 Duration last = lastExecDuration; 49 Duration last = lastExecDuration;
50 long timeBeforeExec = System.currentTimeMillis(); 50 long timeBeforeExec = System.currentTimeMillis();
51 applicationContext.renderFrame(graphics2D -> { 51 applicationContext.renderFrame(graphics2D -> {
52 events.addAll(renderFrame(graphics2D, applicationContext, events, last)); //add the new events returned by updates 52 InputHandler inputHandler = new InputHandler(applicationContext);
53 ScreenManager screenManager = new ScreenManager(applicationContext, graphics2D);
54 events.addAll(inputHandler.getEvents());
55 Context context = new Context(currentGame, events, screenManager.clearScreen(), last);
56 List<Event> newEvents = currentGame.update(context); //return new events created from update();
57 events.clear();
58 events.addAll(newEvents); //add the new events returned by updates
53 }); 59 });
54 long timeAfterExec = System.currentTimeMillis(); 60 long timeAfterExec = System.currentTimeMillis();
55 lastExecDuration = Duration.ofMillis(timeAfterExec - timeBeforeExec); 61 lastExecDuration = Duration.ofMillis(timeAfterExec - timeBeforeExec);
@@ -62,19 +68,5 @@ public final class Viewer {
62 } 68 }
63 applicationContext.exit(0); 69 applicationContext.exit(0);
64 } 70 }
65
66 /**
67 * @param graphics2D the graphic2D from Zen 5
68 * @param applicationContext the application context from Zen 5
69 */
70 public List<Event> renderFrame(Graphics2D graphics2D, ApplicationContext applicationContext, List<Event> events, Duration lastExecDuration) {
71 InputHandler inputHandler = new InputHandler(applicationContext);
72 ScreenManager screenManager = new ScreenManager(applicationContext, graphics2D);
73 events.addAll(inputHandler.getEvents());
74 Context context = new Context(currentGame, events, screenManager.clearScreen(), lastExecDuration);
75 List<Event> newEvents = currentGame.update(context); //return new events created from update();
76 events.clear();
77 return newEvents;
78 }
79} 71}
80 72