Skip to content

Commit e55ab8c

Browse files
committed
refactor: split Game and GameShell apart, move main(..) to GameShell
1 parent 8ffd1f7 commit e55ab8c

File tree

4 files changed

+105
-77
lines changed

4 files changed

+105
-77
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414
}
1515

1616
application {
17-
mainClassName 'org.runejs.client.Game'
17+
mainClassName 'org.runejs.client.GameShell'
1818
}
1919

2020
jar {

src/main/java/org/runejs/client/Game.java

Lines changed: 16 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import java.net.InetAddress;
5353
import java.net.Socket;
5454

55-
public class Game extends GameShell {
55+
public class Game {
5656

5757
/**
5858
* The codec currently in use to encode and decode packets.
@@ -116,6 +116,8 @@ public static int getMinimapRotation() {
116116
public static int currentPort;
117117
private static int drawCount = 0;
118118

119+
private GameErrorHandler errorHandler;
120+
119121
/**
120122
* This method is used to draw interfaces on the client. It uses the parent of -1,
121123
* which means it will render the widget on the top most level. It takes in a widget ID
@@ -673,67 +675,6 @@ else if (MovedStatics.anInt2613 > 256)
673675
}
674676
}
675677

676-
public static void main(String[] args) {
677-
Configuration.read();
678-
Native.username = Configuration.getUsername();
679-
Native.password = Configuration.getPassword();
680-
String[] params = new String[]{"1", "live", "live", "highmem", "members"};
681-
if(args.length != 0) {
682-
params = args;
683-
}
684-
try {
685-
if (params.length != 5)
686-
printHelp();
687-
688-
Player.worldId = Integer.parseInt(params[0]);
689-
690-
// Location argument (to set server IP based on JMod location?)
691-
if (params[1].equals("live")) {
692-
modewhere = 0;
693-
} else if (params[1].equals("office")) {
694-
modewhere = 1;
695-
} else if (params[1].equals("local")) {
696-
modewhere = 2;
697-
} else {
698-
printHelp();
699-
}
700-
701-
if (params[2].equals("live"))
702-
modewhat = 0;
703-
else if (!params[2].equals("rc")) {
704-
if (params[2].equals("wip"))
705-
modewhat = 2;
706-
else
707-
printHelp();
708-
} else
709-
modewhat = 1;
710-
711-
// Memory argument
712-
if (params[3].equals("lowmem")) {
713-
Class59.setLowMemory();
714-
} else if (params[3].equals("highmem")) {
715-
MovedStatics.setHighMemory();
716-
} else {
717-
printHelp();
718-
}
719-
720-
// Player membership argument
721-
if (params[4].equals("free")) {
722-
MovedStatics.membersWorld = false;
723-
} else if (params[4].equals("members")) {
724-
MovedStatics.membersWorld = true;
725-
} else {
726-
printHelp();
727-
}
728-
729-
Game game = new Game();
730-
game.openClientApplet("client435", 13, 32 + modewhat, InetAddress.getByName(Configuration.SERVER_ADDRESS), 435);
731-
732-
} catch (Exception exception) {
733-
exception.printStackTrace();
734-
}
735-
}
736-
737678

738679
public static void setConfigToDefaults() {
739680
aLong1203 = 0L;
@@ -2061,7 +2002,7 @@ public void updateStatusText() {
20612002
if (MovedStatics.aBoolean1575) {
20622003
MovedStatics.method311(MouseHandler.gameCanvas);
20632004
Class55.method965(32, MouseHandler.gameCanvas);
2064-
this.setCanvas();
2005+
// this.setCanvas();
20652006
GameInterface.method642(MouseHandler.gameCanvas);
20662007
RSRuntimeException.method1056(MouseHandler.gameCanvas);
20672008
}
@@ -2170,6 +2111,18 @@ public void connectUpdateServer() {
21702111
}
21712112
}
21722113

2114+
public void setErrorHandler(GameErrorHandler errorHandler) {
2115+
this.errorHandler = errorHandler;
2116+
}
2117+
2118+
private void openErrorPage(String error) {
2119+
if (this.errorHandler == null) {
2120+
return;
2121+
}
2122+
2123+
this.errorHandler.handleGameError(error);
2124+
}
2125+
21732126
public void close() {
21742127
if (mouseCapturer != null)
21752128
mouseCapturer.aBoolean913 = false;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.runejs.client;
2+
3+
public interface GameErrorHandler {
4+
void handleGameError(String errorMessage);
5+
}

src/main/java/org/runejs/client/GameShell.java

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import org.runejs.client.frame.ScreenController;
44
import org.runejs.client.frame.ScreenMode;
55
import org.runejs.client.input.MouseHandler;
6+
import org.runejs.client.language.Native;
67
import org.runejs.client.media.renderable.actor.Actor;
8+
import org.runejs.client.media.renderable.actor.Player;
79
import org.runejs.client.media.renderable.actor.PlayerAppearance;
810
import org.runejs.client.net.PacketBuffer;
911
import org.runejs.client.scene.SceneCluster;
@@ -19,7 +21,7 @@
1921
import java.net.InetAddress;
2022
import java.net.URL;
2123

22-
public abstract class GameShell extends Canvas implements Runnable, FocusListener, WindowListener {
24+
public class GameShell extends Canvas implements GameErrorHandler, Runnable, FocusListener, WindowListener {
2325
public static long[] tickSamples = new long[32];
2426

2527
public static long exitTimeInMillis = 0L;
@@ -30,6 +32,74 @@ public abstract class GameShell extends Canvas implements Runnable, FocusListene
3032
private final int millisPerTick = 20;
3133
public boolean gameShellError = false;
3234

35+
private Game game;
36+
37+
public GameShell(Game game) {
38+
this.game = game;
39+
}
40+
41+
public static void main(String[] args) {
42+
Configuration.read();
43+
Native.username = Configuration.getUsername();
44+
Native.password = Configuration.getPassword();
45+
String[] params = new String[]{"1", "live", "live", "highmem", "members"};
46+
if(args.length != 0) {
47+
params = args;
48+
}
49+
try {
50+
if (params.length != 5)
51+
Game.printHelp();
52+
53+
Player.worldId = Integer.parseInt(params[0]);
54+
55+
// Location argument (to set server IP based on JMod location?)
56+
if (params[1].equals("live")) {
57+
Game.modewhere = 0;
58+
} else if (params[1].equals("office")) {
59+
Game.modewhere = 1;
60+
} else if (params[1].equals("local")) {
61+
Game.modewhere = 2;
62+
} else {
63+
Game.printHelp();
64+
}
65+
66+
if (params[2].equals("live"))
67+
Game.modewhat = 0;
68+
else if (!params[2].equals("rc")) {
69+
if (params[2].equals("wip"))
70+
Game.modewhat = 2;
71+
else
72+
Game.printHelp();
73+
} else
74+
Game.modewhat = 1;
75+
76+
// Memory argument
77+
if (params[3].equals("lowmem")) {
78+
Class59.setLowMemory();
79+
} else if (params[3].equals("highmem")) {
80+
MovedStatics.setHighMemory();
81+
} else {
82+
Game.printHelp();
83+
}
84+
85+
// Player membership argument
86+
if (params[4].equals("free")) {
87+
MovedStatics.membersWorld = false;
88+
} else if (params[4].equals("members")) {
89+
MovedStatics.membersWorld = true;
90+
} else {
91+
Game.printHelp();
92+
}
93+
94+
Game game = new Game();
95+
GameShell shell = new GameShell(game);
96+
game.setErrorHandler(shell);
97+
shell.openClientApplet("client435", 13, 32 + Game.modewhat, InetAddress.getByName(Configuration.SERVER_ADDRESS), 435);
98+
99+
} catch (Exception exception) {
100+
exception.printStackTrace();
101+
}
102+
}
33103

34104
public void run() {
35105
if (Signlink.javaVendor != null) {
@@ -59,7 +129,7 @@ public void run() {
59129
}
60130
setCanvas();
61131
ProducingGraphicsBuffer_Sub1.aProducingGraphicsBuffer_2213 = MovedStatics.createGraphicsBuffer(Class12.width, MovedStatics.height, MouseHandler.gameCanvas);
62-
startup();
132+
this.game.startup();
63133
SceneCluster.gameTimer = Timer.create();
64134
SceneCluster.gameTimer.start();
65135

@@ -80,7 +150,7 @@ public void run() {
80150
MovedStatics.aBoolean571 = clientFocused;
81151
}
82152

83-
processGameLoop();
153+
this.game.processGameLoop();
84154
}
85155

86156
runAfterGameLoop();
@@ -99,7 +169,7 @@ public synchronized void closeGameShell() {
99169
/* empty */
100170
}
101171
try {
102-
close();
172+
this.game.close();
103173
} catch (Exception exception) {
104174
/* empty */
105175
}
@@ -160,14 +230,10 @@ public void start() {
160230
exitTimeInMillis = 0L;
161231
}
162232

163-
public abstract void processGameLoop();
164-
165233
public void focusLost(FocusEvent arg0) {
166234
clientFocused = false;
167235
}
168236

169-
public abstract void close();
170-
171237
public synchronized void paint(Graphics arg0) {
172238
if (this == currentGameShell && !PacketBuffer.closedClient) {
173239
MovedStatics.clearScreen = true;
@@ -255,7 +321,10 @@ public void runAfterGameLoop() {
255321
MouseHandler.gameCanvas.setLocation(insets.left, insets.top);
256322
}
257323
}
258-
updateStatusText();
324+
if (MovedStatics.aBoolean1575) {
325+
this.setCanvas();
326+
}
327+
this.game.updateStatusText();
259328
}
260329

261330
// public AppletContext getAppletContext() {
@@ -297,8 +366,6 @@ public URL getCodeBase() {
297366
return this.getDocumentBase();
298367
}
299368

300-
public abstract void startup();
301-
302369
public void update(Graphics graphics) {
303370
paint(graphics);
304371
}
@@ -342,8 +409,6 @@ public synchronized void setCanvas() {
342409
MovedStatics.aLong174 = System.currentTimeMillis();
343410
}
344411

345-
public abstract void updateStatusText();
346-
347412
public void windowDeiconified(WindowEvent windowEvent) {
348413
}
349414

@@ -352,4 +417,9 @@ public void windowClosed(WindowEvent windowEvent) {
352417

353418
public void windowActivated(WindowEvent windowEvent) {
354419
}
420+
421+
@Override
422+
public void handleGameError(String errorMessage) {
423+
this.openErrorPage(errorMessage);
424+
}
355425
}

0 commit comments

Comments
 (0)