Skip to content

Commit 7f82510

Browse files
committed
Added headless mode for the realtime server
1 parent 55b69a5 commit 7f82510

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Examples/Realtime/Server/src/Realtime/Game.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ public class Game implements Runnable {
3434
/**
3535
* Object representation of the realtime game
3636
*/
37-
public Game() {
37+
public Game(boolean headless) {
3838
this.messages = new ConcurrentLinkedQueue<NetLibPacket>();
3939
this.players = new Player[32];
4040
this.objs = new LinkedList<GameObject>();
4141
this.obj_npc = new GameObject(new Vector2D(320/2, 240/2));
4242
this.obj_npc.SetSpeed(100);
4343
this.obj_npc.SetBounce(true);
4444
this.objs.add(this.obj_npc);
45-
this.window = new PreviewWindow(this);
45+
if (!headless)
46+
this.window = new PreviewWindow(this);
47+
else
48+
this.window = null;
4649
this.gametime = 0;
4750
System.out.println("Realtime initialized");
4851
}
@@ -76,8 +79,11 @@ public void run() {
7679
}
7780

7881
// Draw the frame
79-
this.window.repaint();
80-
Toolkit.getDefaultToolkit().sync();
82+
if (this.window != null)
83+
{
84+
this.window.repaint();
85+
Toolkit.getDefaultToolkit().sync();
86+
}
8187

8288
// Sleep for a bit
8389
Thread.sleep(10);

Examples/Realtime/Server/src/RealtimeServer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class RealtimeServer {
2424
private static int port = 6462;
2525
private static boolean useupnp = true;
2626
private static boolean register = true;
27+
private static boolean headless = false;
2728
private static String servername = "";
2829
private static int maxplayers = 2;
2930
private static String masteraddress = MASTER_DEFAULTADDRESS + ":" + MASTER_DEFAULTPORT;
@@ -106,7 +107,7 @@ public void run() {
106107
}
107108

108109
// Begin the game
109-
game = new Realtime.Game();
110+
game = new Realtime.Game(headless);
110111
new Thread(game).start();
111112

112113
// Allow clients to connect, and pass messages over to them
@@ -186,6 +187,9 @@ private static void ReadArguments(String args[]) {
186187
case "-noregister":
187188
register = false;
188189
break;
190+
case "-headless":
191+
headless = true;
192+
break;
189193
case "-noupnp":
190194
useupnp = false;
191195
break;

0 commit comments

Comments
 (0)