Skip to content

Commit b70f18a

Browse files
authored
Merge pull request #192 from runejs/refactoring/split-render
move loading text to abstract SoftwareRenderer
2 parents d786c11 + 68024d2 commit b70f18a

File tree

6 files changed

+85
-57
lines changed

6 files changed

+85
-57
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.runejs.client.net.*;
2424
import org.runejs.client.net.codec.MessagePacketCodec;
2525
import org.runejs.client.net.codec.runejs435.RuneJS435PacketCodec;
26+
import org.runejs.client.renderer.ScreenRenderer;
2627
import org.runejs.client.scene.*;
2728
import org.runejs.client.scene.camera.Camera;
2829
import org.runejs.client.scene.camera.CameraRotation;
@@ -49,6 +50,8 @@
4950

5051
public class Game {
5152

53+
public static ScreenRenderer renderer;
54+
5255
/**
5356
* The codec currently in use to encode and decode packets.
5457
*
@@ -2193,7 +2196,7 @@ public void updateStatusText() {
21932196
MouseHandler.addListeners(gameCanvas);
21942197
}
21952198
if (gameStatusCode == 0)
2196-
MovedStatics.drawLoadingText(MovedStatics.anInt1607, null, Native.currentLoadingText);
2199+
renderer.drawLoadingText(MovedStatics.anInt1607, null, Native.currentLoadingText);
21972200
else if (gameStatusCode == 5) {
21982201
Class60.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall);
21992202
} else if (gameStatusCode == 10) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.runejs.client.frame.ScreenMode;
55
import org.runejs.client.language.Native;
66
import org.runejs.client.media.renderable.actor.Player;
7+
import org.runejs.client.renderer.SoftwareRenderer;
78
import org.runejs.client.util.Signlink;
89
import org.runejs.client.util.Timer;
910

@@ -272,6 +273,7 @@ public void windowDeactivated(WindowEvent windowEvent) {
272273
}
273274

274275
public synchronized void setCanvas() {
276+
Game.renderer = new SoftwareRenderer();
275277
Container container = clientFrame;
276278
if (Game.gameCanvas != null) {
277279
Game.gameCanvas.removeFocusListener(this);

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

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ public class MovedStatics {
238238
*/
239239
public static IndexedImage tabHighlightImageBottomRight;
240240
public static ProducingGraphicsBuffer chatboxTop;
241-
public static Font helveticaBold;
242241
public static int deregisterActorCount = 0;
243242
public static int[] anIntArray456;
244243
public static int regionY;
@@ -887,7 +886,7 @@ public static void method1013() {
887886
public static void processGameStatus(int statusCode) {
888887
if (statusCode != Game.gameStatusCode) {
889888
if (Game.gameStatusCode == 0)
890-
method144(12433);
889+
Game.renderer.disposeLoadingText();
891890
if (statusCode == 20 || statusCode == 40) {
892891
Game.anInt1756 = 0;
893892
anInt2321 = 0;
@@ -1224,7 +1223,6 @@ public static void animateNpcs() {
12241223

12251224
}
12261225

1227-
public static FontMetrics fontMetrics;
12281226

12291227
public static void drawMenu(int xOffSet, int yOffSet) {
12301228
int height = menuHeight;
@@ -3086,51 +3084,6 @@ public static IndexedImage method769(int arg0, CacheArchive imageArchive, int ar
30863084
return method538();
30873085
}
30883086

3089-
public static void drawLoadingText(int percent, Color color, String desc) {
3090-
try {
3091-
Graphics graphics = Game.gameCanvas.getGraphics();
3092-
if(helveticaBold == null) {
3093-
helveticaBold = new Font("Helvetica", Font.BOLD, 13);
3094-
fontMetrics = Game.gameCanvas.getFontMetrics(helveticaBold);
3095-
}
3096-
if(clearScreen) {
3097-
clearScreen = false;
3098-
graphics.setColor(Color.black);
3099-
graphics.fillRect(0, 0, width, height);
3100-
}
3101-
if(color == null)
3102-
color = new Color(140, 17, 17);
3103-
try {
3104-
if(loadingBoxImage == null)
3105-
loadingBoxImage = Game.gameCanvas.createImage(304, 34);
3106-
Graphics loadingBoxGraphics = loadingBoxImage.getGraphics();
3107-
loadingBoxGraphics.setColor(color);
3108-
loadingBoxGraphics.drawRect(0, 0, 303, 33);
3109-
loadingBoxGraphics.fillRect(2, 2, percent * 3, 30);
3110-
loadingBoxGraphics.setColor(Color.black);
3111-
loadingBoxGraphics.drawRect(1, 1, 301, 31);
3112-
loadingBoxGraphics.fillRect(2 + 3 * percent, 2, 300 - 3 * percent, 30);
3113-
loadingBoxGraphics.setFont(helveticaBold);
3114-
loadingBoxGraphics.setColor(Color.white);
3115-
loadingBoxGraphics.drawString(desc, (304 - (fontMetrics.stringWidth(desc))) / 2, 22);
3116-
graphics.drawImage(loadingBoxImage, width / 2 - 152, height / 2 - 18, null);
3117-
} catch(Exception exception) {
3118-
int centerWidth = width / 2 - 152;
3119-
int centerHeight = height / 2 - 18;
3120-
graphics.setColor(color);
3121-
graphics.drawRect(centerWidth, centerHeight, 303, 33);
3122-
graphics.fillRect(2 + centerWidth, centerHeight + 2, 3 * percent, 30);
3123-
graphics.setColor(Color.black);
3124-
graphics.drawRect(centerWidth + 1, 1 + centerHeight, 301, 31);
3125-
graphics.fillRect(percent * 3 + 2 + centerWidth, 2 + centerHeight, 300 + -(3 * percent), 30);
3126-
graphics.setFont(helveticaBold);
3127-
graphics.setColor(Color.white);
3128-
graphics.drawString(desc, (304 - (fontMetrics.stringWidth(desc))) / 2+ centerWidth, 22 + centerHeight);
3129-
}
3130-
} catch(Exception exception) {
3131-
Game.gameCanvas.repaint();
3132-
}
3133-
}
31343087

31353088
public static void method778(HuffmanEncoding arg1) {
31363089
aHuffmanEncoding_2590 = arg1;
@@ -3316,14 +3269,7 @@ public static void method1057() {
33163269
ticksPerLoop = 0;
33173270
}
33183271

3319-
public static void method144(int arg0) {
3320-
3321-
fontMetrics = null;
3322-
helveticaBold = null;
3323-
if(arg0 == 12433)
3324-
loadingBoxImage = null;
33253272

3326-
}
33273273

33283274
public static ImageRGB method578() {
33293275
ImageRGB class40_sub5_sub14_sub4 = new ImageRGB();

src/main/java/org/runejs/client/frame/ScreenController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static void refreshFrameSize() {
8282
}
8383

8484
public static void setBounds() {
85-
if (Game.gameCanvas == null) {
85+
if (Game.gameCanvas == null || Game.signlink.gameShell == null) {
8686
return;
8787
}
8888
Dimension innerSize = getInnerSize(GameShell.clientFrame);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.runejs.client.renderer;
2+
3+
import java.awt.*;
4+
5+
public abstract class ScreenRenderer {
6+
7+
public abstract void drawLoadingText(int percent, Color color, String desc);
8+
9+
public abstract void disposeLoadingText();
10+
11+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.runejs.client.renderer;
2+
3+
import org.runejs.client.Game;
4+
5+
import java.awt.*;
6+
7+
import static org.runejs.client.MovedStatics.*;
8+
9+
public class SoftwareRenderer extends ScreenRenderer {
10+
private Font helveticaBold;
11+
private FontMetrics helveticaBoldMetrics;
12+
13+
@Override
14+
public void drawLoadingText(int percent, Color color, String desc) {
15+
try {
16+
Graphics graphics = Game.gameCanvas.getGraphics();
17+
if (helveticaBold == null) {
18+
helveticaBold = new Font("Helvetica", Font.BOLD, 13);
19+
helveticaBoldMetrics = Game.gameCanvas.getFontMetrics(helveticaBold);
20+
}
21+
if (clearScreen) {
22+
clearScreen = false;
23+
graphics.setColor(Color.black);
24+
graphics.fillRect(0, 0, width, height);
25+
}
26+
if (color == null)
27+
color = new Color(140, 17, 17);
28+
try {
29+
if (loadingBoxImage == null)
30+
loadingBoxImage = Game.gameCanvas.createImage(304, 34);
31+
Graphics loadingBoxGraphics = loadingBoxImage.getGraphics();
32+
loadingBoxGraphics.setColor(color);
33+
loadingBoxGraphics.drawRect(0, 0, 303, 33);
34+
loadingBoxGraphics.fillRect(2, 2, percent * 3, 30);
35+
loadingBoxGraphics.setColor(Color.black);
36+
loadingBoxGraphics.drawRect(1, 1, 301, 31);
37+
loadingBoxGraphics.fillRect(2 + 3 * percent, 2, 300 - 3 * percent, 30);
38+
loadingBoxGraphics.setFont(helveticaBold);
39+
loadingBoxGraphics.setColor(Color.white);
40+
loadingBoxGraphics.drawString(desc, (304 - (helveticaBoldMetrics.stringWidth(desc))) / 2, 22);
41+
graphics.drawImage(loadingBoxImage, width / 2 - 152, height / 2 - 18, null);
42+
} catch (Exception exception) {
43+
int centerWidth = width / 2 - 152;
44+
int centerHeight = height / 2 - 18;
45+
graphics.setColor(color);
46+
graphics.drawRect(centerWidth, centerHeight, 303, 33);
47+
graphics.fillRect(2 + centerWidth, centerHeight + 2, 3 * percent, 30);
48+
graphics.setColor(Color.black);
49+
graphics.drawRect(centerWidth + 1, 1 + centerHeight, 301, 31);
50+
graphics.fillRect(percent * 3 + 2 + centerWidth, 2 + centerHeight, 300 + -(3 * percent), 30);
51+
graphics.setFont(helveticaBold);
52+
graphics.setColor(Color.white);
53+
graphics.drawString(desc, (304 - (helveticaBoldMetrics.stringWidth(desc))) / 2 + centerWidth, 22 + centerHeight);
54+
}
55+
} catch (Exception exception) {
56+
Game.gameCanvas.repaint();
57+
}
58+
}
59+
60+
@Override
61+
public void disposeLoadingText() {
62+
helveticaBoldMetrics = null;
63+
helveticaBold = null;
64+
loadingBoxImage = null;
65+
}
66+
}

0 commit comments

Comments
 (0)