aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl')
-rw-r--r--src/ch/epfl/xblast/server/Server.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/ch/epfl/xblast/server/Server.java b/src/ch/epfl/xblast/server/Server.java
index 0989d55..6d8db2c 100644
--- a/src/ch/epfl/xblast/server/Server.java
+++ b/src/ch/epfl/xblast/server/Server.java
@@ -20,6 +20,8 @@ import java.util.*;
20public class Server { 20public class Server {
21 21
22 public static final int DEFAULT_PORT = 2016; 22 public static final int DEFAULT_PORT = 2016;
23
24 private static final long REFRESH_RATE = (long) (50 * 1E6); // nanosecond
23 private static final int DEFAULT_EXPECTED_CLIENTS = PlayerID.values().length; 25 private static final int DEFAULT_EXPECTED_CLIENTS = PlayerID.values().length;
24 26
25 private static class Channel { 27 private static class Channel {
@@ -133,6 +135,14 @@ public class Server {
133 135
134 } 136 }
135 137
138 private static void delay(long ns) {
139 try {
140 Thread.sleep((long) (ns / 1E6), (int) (ns % 1E6));
141 } catch (InterruptedException e) {
142 e.printStackTrace();
143 }
144 }
145
136 private final Channel channel; 146 private final Channel channel;
137 private final int expectedClients; 147 private final int expectedClients;
138 148
@@ -160,15 +170,11 @@ public class Server {
160 GameState gameState = GameState.DEFAULT_GAME_STATE; 170 GameState gameState = GameState.DEFAULT_GAME_STATE;
161 171
162 while (!gameState.isGameOver()) { 172 while (!gameState.isGameOver()) {
173 long computationStartTime = System.nanoTime();
174
163 gameState = updateGameState(updateGameState(gameState)); 175 gameState = updateGameState(updateGameState(gameState));
164 // TODO: send updated game state to clients
165 176
166 try { 177 delay(REFRESH_RATE - (computationStartTime - System.nanoTime()));
167 Thread.sleep(10000);
168 // TODO: adapt sleeping time
169 } catch (InterruptedException e) {
170 e.printStackTrace();
171 }
172 } 178 }
173 } 179 }
174 180