Skip to content

Commit 869eee4

Browse files
authored
Merge pull request #171 from runejs/split-gameshell
refactor: split Game and GameShell
2 parents af1b284 + e55ab8c commit 869eee4

27 files changed

+257
-249
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.Main'
17+
mainClassName 'org.runejs.client.GameShell'
1818
}
1919

2020
jar {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public static synchronized byte[] method246(int arg1) {
8686
GroundItemTile.aByteArrayArray1377[anInt356] = null;
8787
return is;
8888
}
89-
if(arg1 == 5000 && Main.anInt1764 > 0) {
90-
byte[] is = Class44.aByteArrayArray1039[--Main.anInt1764];
91-
Class44.aByteArrayArray1039[Main.anInt1764] = null;
89+
if(arg1 == 5000 && Game.anInt1764 > 0) {
90+
byte[] is = Class44.aByteArrayArray1039[--Game.anInt1764];
91+
Class44.aByteArrayArray1039[Game.anInt1764] = null;
9292
return is;
9393
}
9494
if(arg1 == 30000 && MovedStatics.anInt2359 > 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Class37 {
1111
public static ImageRGB[] cursorCross;
1212

1313
static {
14-
Main.anInt874 = 0;
14+
Game.anInt874 = 0;
1515
}
1616

1717
public static void method434() {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static void startup() {
111111
}
112112
} else if (MovedStatics.loadingPercent == 45) {
113113
MusicSystem.initialiseMusic(0);
114-
SoundSystem.initialiseSound(Main.signlink);
114+
SoundSystem.initialiseSound(Game.signlink);
115115
MovedStatics.loadingPercent = 50;
116116
Native.currentLoadingText = English.preparedSoundEngine;
117117
MovedStatics.anInt1607 = 35;
@@ -156,7 +156,7 @@ public static void startup() {
156156
UnderlayDefinition.initializeUnderlayDefinitionCache(CacheArchive.gameDefinitionsCacheArchive);
157157
initializeIdentityKitDefinitionCache(CacheArchive.gameDefinitionsCacheArchive, CacheArchive.modelCacheArchive);
158158
initializeGameObjectDefinitionCache(CacheArchive.modelCacheArchive, VertexNormal.lowMemory, CacheArchive.gameDefinitionsCacheArchive);
159-
Main.method357(CacheArchive.modelCacheArchive, CacheArchive.gameDefinitionsCacheArchive);
159+
Game.method357(CacheArchive.modelCacheArchive, CacheArchive.gameDefinitionsCacheArchive);
160160
MovedStatics.initializeItemDefinitionCache(CacheArchive.gameDefinitionsCacheArchive, MovedStatics.membersWorld, CacheArchive.modelCacheArchive);
161161
MovedStatics.initializeAnimationCaches(CacheArchive.skinDefinitionCacheArchive, CacheArchive.gameDefinitionsCacheArchive, CacheArchive.skeletonCacheArchive);
162162
Class55.method966(CacheArchive.modelCacheArchive, CacheArchive.gameDefinitionsCacheArchive);
@@ -268,8 +268,8 @@ public static void startup() {
268268
MovedStatics.anInt1607 = 90;
269269
}
270270
} else if (MovedStatics.loadingPercent == 110) {
271-
Main.mouseCapturer = new Class39();
272-
Main.signlink.createThreadNode(10, Main.mouseCapturer);
271+
Game.mouseCapturer = new Class39();
272+
Game.signlink.createThreadNode(10, Game.mouseCapturer);
273273
Native.currentLoadingText = English.loadedInputHandler;
274274
MovedStatics.loadingPercent = 120;
275275
MovedStatics.anInt1607 = 94;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static boolean method840(byte[] arg1, int arg2, int arg3) {
4444
bool_2_ = true;
4545
if(!gameObjectDefinition.method612()) {
4646
bool = false;
47-
Main.anInt2591++;
47+
Game.anInt2591++;
4848
}
4949
}
5050
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public static void drawTabArea() {
3636
MovedStatics.showSidePanelRedrawnText = true;
3737
MovedStatics.method996();
3838
if(GameInterface.tabAreaInterfaceId != -1) {
39-
boolean bool = Main.drawParentInterface(1, 0, 0, 190, 261, GameInterface.tabAreaInterfaceId);
39+
boolean bool = Game.drawParentInterface(1, 0, 0, 190, 261, GameInterface.tabAreaInterfaceId);
4040
if(!bool)
4141
GameInterface.redrawTabArea = true;
4242
} else if(Player.tabWidgetIds[Player.currentTabId] != -1) {
43-
boolean bool = Main.drawParentInterface(1, 0, 0, 190, 261, Player.tabWidgetIds[Player.currentTabId]);
43+
boolean bool = Game.drawParentInterface(1, 0, 0, 190, 261, Player.tabWidgetIds[Player.currentTabId]);
4444
if(!bool)
4545
GameInterface.redrawTabArea = true;
4646
}
@@ -164,7 +164,7 @@ public static void method398() {
164164
if(i > 190)
165165
i = 190;
166166
int i_1_ = CollisionMap.menuHeight;
167-
int i_2_ = Main.menuOffsetY;
167+
int i_2_ = Game.menuOffsetY;
168168
if(i_0_ < 0)
169169
i_0_ = 0;
170170
int i_3_ = 6116423;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void determineMenuSize() {
7878
y = 334 - height;
7979
if(y < 0)
8080
y = 0;
81-
Main.menuOffsetY = y;
81+
Game.menuOffsetY = y;
8282
}
8383
if(MouseHandler.clickX > 553 && MouseHandler.clickY > 205 && MouseHandler.clickX < 743 && MouseHandler.clickY < 466) {
8484
CollisionMap.menuHeight = 22 + 15 * MovedStatics.menuActionRow;
@@ -97,7 +97,7 @@ else if(width + x > 190)
9797
} else
9898
y = 0;
9999
VertexNormal.menuWidth = width;
100-
Main.menuOffsetY = y;
100+
Game.menuOffsetY = y;
101101
}
102102
if(MouseHandler.clickX > 17 && MouseHandler.clickY > 357 && MouseHandler.clickX < 496 && MouseHandler.clickY < 453) {
103103
VertexNormal.menuWidth = width;
@@ -111,7 +111,7 @@ else if(width + x > 190)
111111
y = 0;
112112
int x = -(width / 2) + -17 + MouseHandler.clickX;
113113
MovedStatics.menuOpen = true;
114-
Main.menuOffsetY = y;
114+
Game.menuOffsetY = y;
115115
if(x < 0)
116116
x = 0;
117117
else if(x + width > 479)
@@ -137,7 +137,7 @@ else if(x + width > 479)
137137
x = ScreenController.drawWidth - width;
138138
MovedStatics.menuOpen = true;
139139
InteractiveObject.menuOffsetX = x;
140-
Main.menuOffsetY = y;
140+
Game.menuOffsetY = y;
141141
VertexNormal.menuWidth = width;
142142
CollisionMap.menuHeight = MovedStatics.menuActionRow * 15 + 22;
143143
}
@@ -158,7 +158,7 @@ else if(x + width > 479)
158158
// } else
159159
// y = 0;
160160
// VertexNormal.menuWidth = width;
161-
// Main.menuOffsetY = y;
161+
// Game.menuOffsetY = y;
162162
// }
163163
// if(Class57.clickX > 17 && RSString.clickY > 357 && Class57.clickX < 496 && RSString.clickY < 453) {
164164
// VertexNormal.menuWidth = width;
@@ -172,7 +172,7 @@ else if(x + width > 479)
172172
// y = 0;
173173
// int x = -(width / 2) + -17 + Class57.clickX;
174174
// Class4.menuOpen = true;
175-
// Main.menuOffsetY = y;
175+
// Game.menuOffsetY = y;
176176
// if(x < 0)
177177
// x = 0;
178178
// else if(x + width > 479)
@@ -423,7 +423,7 @@ public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) {
423423
Rasterizer.drawDiagonalLine(0,0, 42,42, 0xFF0000);
424424
}
425425

426-
Main.renderFlames();
426+
Game.renderFlames();
427427

428428
try {
429429
int offsetX = 0;
@@ -601,8 +601,8 @@ public static void renderLoginScreen(Component arg0, CacheArchive huffmanCacheAr
601601

602602
logo.drawImage(-128 + 382 + -(logo.imageWidth / 2), 18);
603603

604-
Class40_Sub5_Sub15.loginScreenBox = Main.method359(Native.titleBox, "", gameImageCacheArchive);
605-
Class59.imgLoginScreenButton = Main.method359(Native.titleButton, "", gameImageCacheArchive);
604+
Class40_Sub5_Sub15.loginScreenBox = Game.method359(Native.titleBox, "", gameImageCacheArchive);
605+
Class59.imgLoginScreenButton = Game.method359(Native.titleButton, "", gameImageCacheArchive);
606606
MovedStatics.aClass40_Sub5_Sub14_Sub2Array535 = IndexedImage.getMultipleIndexedImages(gameImageCacheArchive, Native.runes, "");
607607

608608
Class39.aClass40_Sub5_Sub14_Sub4_918 = new ImageRGB(128, 265);

src/main/java/org/runejs/client/Main.java renamed to src/main/java/org/runejs/client/Game.java

Lines changed: 24 additions & 71 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 Main 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-
Main main = new Main();
730-
main.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;
@@ -764,7 +705,7 @@ public static void setConfigToDefaults() {
764705
SoundSystem.reset();
765706
widgetSelected = 0;
766707
// TODO is this necessary? or should it be removed alongside other randomisation
767-
Main.playerCamera.setYaw(0x7ff & -10 + (int) (20.0 * Math.random()));
708+
Game.playerCamera.setYaw(0x7ff & -10 + (int) (20.0 * Math.random()));
768709
Minimap.minimapState = 0;
769710
Player.localPlayerCount = 0;
770711
Class55.destinationY = 0;
@@ -825,7 +766,7 @@ public static void method353() {
825766
MovedStatics.renderProjectiles();
826767
MovedStatics.renderSpotAnims();
827768
if(!Player.cutsceneActive) {
828-
int pitch = Main.playerCamera.getPitch();
769+
int pitch = Game.playerCamera.getPitch();
829770
if(SceneCamera.cameraTerrainMinScaledPitch / 256 > pitch) {
830771
pitch = SceneCamera.cameraTerrainMinScaledPitch / 256;
831772
}
@@ -834,7 +775,7 @@ public static void method353() {
834775
pitch = 128 + SceneCamera.customCameraAmplitude[4];
835776
}
836777

837-
Main.playerCamera.setPitch(pitch);
778+
Game.playerCamera.setPitch(pitch);
838779
}
839780

840781
int i;
@@ -916,7 +857,7 @@ public static void method353() {
916857
* Get the currently active camera.
917858
*/
918859
public static Camera getActiveCamera() {
919-
return Player.cutsceneActive ? Main.cutsceneCamera : Main.playerCamera;
860+
return Player.cutsceneActive ? Game.cutsceneCamera : Game.playerCamera;
920861
}
921862

922863
public static void method357(CacheArchive arg0, CacheArchive arg2) {
@@ -1209,7 +1150,7 @@ public static void method164() {
12091150

12101151
public static void moveTowardsTarget() {
12111152
// TODO (James) this moves the cutscene camera towards its target, we should move this into the CutsceneCamera class
1212-
CutsceneCamera camera = Main.cutsceneCamera;
1153+
CutsceneCamera camera = Game.cutsceneCamera;
12131154

12141155
int i = camera.getMoveTo().y;
12151156
int i_3_ = camera.getMoveTo().x;
@@ -1428,8 +1369,8 @@ else if(x > 764)
14281369
InteractiveObject.anInt487 = 20;
14291370
MovedStatics.aBoolean565 = false;
14301371
SceneCluster.packetBuffer.putPacket(58);
1431-
SceneCluster.packetBuffer.putShortBE(Main.playerCamera.getYaw());
1432-
SceneCluster.packetBuffer.putShortBE(Main.playerCamera.getPitch());
1372+
SceneCluster.packetBuffer.putShortBE(Game.playerCamera.getYaw());
1373+
SceneCluster.packetBuffer.putShortBE(Game.playerCamera.getPitch());
14331374
}
14341375
if(MovedStatics.aBoolean571 && !aBoolean1735) {
14351376
aBoolean1735 = true;
@@ -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,7 +2111,19 @@ public void connectUpdateServer() {
21702111
}
21712112
}
21722113

2173-
public void method24() {
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+
2126+
public void close() {
21742127
if (mouseCapturer != null)
21752128
mouseCapturer.aBoolean913 = false;
21762129
mouseCapturer = null;
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+
}

0 commit comments

Comments
 (0)