Skip to content

Commit 84c1809

Browse files
committed
refactor: move cache clearing out of MovedStatics
1 parent a673a65 commit 84c1809

File tree

16 files changed

+104
-115
lines changed

16 files changed

+104
-115
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.runejs.client.cache.CacheIndex;
44
import org.runejs.client.cache.CacheArchive;
55
import org.runejs.client.cache.CacheFileChannel;
6+
import org.runejs.client.cache.cs.ClientScript;
67
import org.runejs.client.frame.*;
78
import org.runejs.client.frame.console.Console;
89
import org.runejs.client.input.KeyFocusListener;
@@ -1928,7 +1929,7 @@ public static void logout() {
19281929
MovedStatics.gameServerSocket.kill();
19291930
MovedStatics.gameServerSocket = null;
19301931
}
1931-
MovedStatics.clearCaches();
1932+
clearCaches();
19321933
currentScene.initToNull();
19331934
int i = 0;
19341935
for(/**/; i < 4; i++)
@@ -2045,6 +2046,35 @@ else if (MovedStatics.obfuscatedKeyStatus[99] && !Console.console.consoleOpen)
20452046
SceneCamera.setMaxSurroundingTerrainHeight(i_3_);
20462047
}
20472048

2049+
public static void clearCaches() {
2050+
OverlayDefinition.clearOverlayDefinitionCache();
2051+
UnderlayDefinition.clearUnderlayDefinitionCache();
2052+
IdentityKit.clearIdentityKitCache();
2053+
GameObjectDefinition.clearGameObjectModelCache();
2054+
ActorDefinition.clearActorCache();
2055+
ItemDefinition.clearItemCache();
2056+
AnimationSequence.clearAnimationCache();
2057+
SpotAnimDefinition.clearSpotAnimCache();
2058+
VarbitDefinition.clearVarbitDefinitionCache();
2059+
VarPlayerDefinition.clearVarPlayerDefinitionCache();
2060+
PlayerAppearance.clearPlayerModelCache();
2061+
GameInterface.clearInterfaceCaches();
2062+
((Class35) Rasterizer3D.interface3).clearTextures();
2063+
ClientScript.clientScriptCache.clear();
2064+
CacheArchive.skeletonCacheArchive.clearCache();
2065+
CacheArchive.skinDefinitionCacheArchive.clearCache();
2066+
CacheArchive.gameInterfaceCacheArchive.clearCache();
2067+
CacheArchive.soundEffectCacheArchive.clearCache();
2068+
CacheArchive.gameWorldMapCacheArchive.clearCache();
2069+
CacheArchive.musicCacheArchive.clearCache();
2070+
CacheArchive.modelCacheArchive.clearCache();
2071+
CacheArchive.gameImageCacheArchive.clearCache();
2072+
CacheArchive.gameTextureCacheArchive.clearCache();
2073+
CacheArchive.huffmanCacheArchive.clearCache();
2074+
CacheArchive.jingleCacheArchive.clearCache();
2075+
CacheArchive.clientScriptCacheArchive.clearCache();
2076+
}
2077+
20482078
public void method35(int arg1) {
20492079
if (currentPort != gameServerPort)
20502080
currentPort = gameServerPort;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void loadRegion() {
9090
if(bool) {
9191
if(MovedStatics.anInt1634 != 0)
9292
MovedStatics.method940(English.loadingPleaseWait, true, Native.percent100Parentheses);
93-
MovedStatics.clearCaches();
93+
Game.clearCaches();
9494
Game.currentScene.initToNull();
9595
System.gc();
9696
for(int z = 0; z < 4; z++)
@@ -204,7 +204,7 @@ public static void loadRegion() {
204204
}
205205
}
206206
method364(true);
207-
MovedStatics.clearCaches();
207+
Game.clearCaches();
208208
createRegion(Game.currentScene, currentCollisionMap);
209209
method364(true);
210210
int z = lowestPlane;

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

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.runejs.client.net.*;
2121
import org.runejs.client.node.Class40_Sub6;
2222
import org.runejs.client.node.HashTable;
23-
import org.runejs.client.node.NodeCache;
2423
import org.runejs.client.cache.CacheArchive;
2524
import org.runejs.client.cache.media.AnimationSequence;
2625
import org.runejs.client.cache.media.IndexedImage;
@@ -93,7 +92,6 @@ public class MovedStatics {
9392
public static int anInt1586 = -1;
9493
public static boolean reportMutePlayer = false;
9594
public static int anInt1607 = 10;
96-
public static NodeCache aClass9_1611 = new NodeCache(50);
9795
public static long[] tickSamples = new long[32];
9896
/**
9997
* The image used for the highlighted (selected) tab button,
@@ -105,7 +103,6 @@ public class MovedStatics {
105103
* Up/down arrow images for the scrollbar.
106104
*/
107105
public static IndexedImage[] scrollbarArrowImages;
108-
public static NodeCache modelCache = new NodeCache(260);
109106
public static boolean showChatPanelRedrawnText = false;
110107
public static int lastContinueTextWidgetId = -1;
111108
public static GameSocket gameServerSocket;
@@ -154,7 +151,6 @@ public class MovedStatics {
154151
*/
155152
public static IndexedImage[] mapSceneIcons;
156153
public static int baseX;
157-
public static NodeCache aClass9_998 = new NodeCache(100);
158154
/**
159155
* Something to do with flames, maybe
160156
*/
@@ -696,11 +692,6 @@ public static void method184(byte[] data, int arg1) {
696692
}
697693
}
698694

699-
public static void method188() {
700-
MovedStatics.aClass9_2439.clear();
701-
aClass9_998.clear();
702-
}
703-
704695
public static String method204(int arg0) {
705696
return (0xff & arg0 >> 24) + Native.period + ((arg0 & 0xffca88) >> 16) + Native.period + ((0xfff8 & arg0) >> 8) + Native.period + (0xff & arg0);
706697
}
@@ -1337,14 +1328,7 @@ public static void handleInterfaceActions(GameInterfaceArea area, int mouseX, in
13371328

13381329
public static int modifiedWidgetId = 0;
13391330

1340-
public static void method211() {
1341-
ItemDefinition.itemDefinitionNodeCache.clear();
1342-
ItemDefinition.groundItemModelNodeCache.clear();
1343-
Buffer.rgbImageCache.clear();
1344-
1345-
}
1346-
1347-
public static void setHighMemory() {
1331+
public static void setHighMemory() {
13481332
VertexNormal.lowMemory = false;
13491333
Scene.lowMemory = false;
13501334

@@ -1411,14 +1395,6 @@ public static void drawMenu(int xOffSet, int yOffSet) {
14111395
'9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', '=', '\243',
14121396
'$', '%', '"', '[', ']'};
14131397

1414-
public static void method586(int arg0) {
1415-
ActorDefinition.actorDefinitionNodeCache.clear();
1416-
aClass9_1611.clear();
1417-
if(arg0 <= 63)
1418-
English.errorConnectingToServer = null;
1419-
}
1420-
1421-
public static NodeCache aClass9_2439 = new NodeCache(64);
14221398
/**
14231399
* Something to do with flames, maybe
14241400
*/
@@ -3126,10 +3102,6 @@ public static boolean method735(int arg1) {
31263102
return false;
31273103
}
31283104

3129-
public static void clearModelCache() {
3130-
modelCache.clear();
3131-
}
3132-
31333105
public static int getVisibilityPlaneFor(int arg0, int arg1, int arg2, int arg3) {
31343106
if(arg2 != 0)
31353107
getVisibilityPlaneFor(-73, 123, 115, 98);
@@ -3322,35 +3294,6 @@ public static int method1052(String value, Buffer buffer) {
33223294

33233295
}
33243296

3325-
public static void clearCaches() {
3326-
OverlayDefinition.method233();
3327-
UnderlayDefinition.clearUnderlayDefinitionCache();
3328-
GameInterface.method640();
3329-
GameObjectDefinition.clearGameObjectModelCache();
3330-
method586(64);
3331-
method211();
3332-
method188();
3333-
SpotAnimDefinition.clearSpotAnimDefinitionCache();
3334-
VarbitDefinition.clearVarbitDefinitionCache();
3335-
VarPlayerDefinition.clearVarPlayerDefinitionCache();
3336-
clearModelCache();
3337-
Actor.clearCaches();
3338-
((Class35) Rasterizer3D.interface3).clearTextures();
3339-
ClientScript.clientScriptCache.clear();
3340-
CacheArchive.skeletonCacheArchive.clearCache();
3341-
CacheArchive.skinDefinitionCacheArchive.clearCache();
3342-
CacheArchive.gameInterfaceCacheArchive.clearCache();
3343-
CacheArchive.soundEffectCacheArchive.clearCache();
3344-
CacheArchive.gameWorldMapCacheArchive.clearCache();
3345-
CacheArchive.musicCacheArchive.clearCache();
3346-
CacheArchive.modelCacheArchive.clearCache();
3347-
CacheArchive.gameImageCacheArchive.clearCache();
3348-
CacheArchive.gameTextureCacheArchive.clearCache();
3349-
CacheArchive.huffmanCacheArchive.clearCache();
3350-
CacheArchive.jingleCacheArchive.clearCache();
3351-
CacheArchive.clientScriptCacheArchive.clearCache();
3352-
}
3353-
33543297
public static long nameToLong(String arg0) {
33553298
long l = 0L;
33563299
for(int i = 0; i < arg0.length(); i++) {
@@ -3490,7 +3433,7 @@ public static void drawLoadingText(int percent, Color color, String desc) {
34903433
}
34913434

34923435
public static void clearImageCache() {
3493-
Buffer.rgbImageCache.clear();
3436+
ItemDefinition.itemImageCache.clear();
34943437
}
34953438

34963439
public static void method778(HuffmanEncoding arg1) {

src/main/java/org/runejs/client/cache/def/ActorDefinition.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ActorDefinition extends CachedNode implements EntityDefinition {
2222

2323
public static int count;
2424
public static NodeCache actorDefinitionNodeCache = new NodeCache(64);
25+
public static NodeCache actorChildModelCache = new NodeCache(50);
2526

2627
public boolean isClickable = true;
2728
public int boundaryDimension = 1;
@@ -129,6 +130,11 @@ public static ActorDefinition getDefinition(int id) {
129130
return definition;
130131
}
131132

133+
public static void clearActorCache() {
134+
actorDefinitionNodeCache.clear();
135+
actorChildModelCache.clear();
136+
}
137+
132138
public Model getChildModel(AnimationSequence animation1, AnimationSequence animation2, int arg3, int arg4) {
133139
if(childIds != null) {
134140
ActorDefinition actorDefinition = getChildDefinition();
@@ -137,7 +143,7 @@ public Model getChildModel(AnimationSequence animation1, AnimationSequence anima
137143
}
138144
return actorDefinition.getChildModel(animation1, animation2, arg3, arg4);
139145
}
140-
Model model1 = (Model) MovedStatics.aClass9_1611.get(id);
146+
Model model1 = (Model) actorChildModelCache.get(id);
141147
if(model1 == null) {
142148
boolean bool = false;
143149
for(int model : models) {
@@ -166,7 +172,7 @@ public Model getChildModel(AnimationSequence animation1, AnimationSequence anima
166172
assert model1 != null;
167173
model1.createBones();
168174
model1.applyLighting(ambient + 64, 850 + contrast, -30, -50, -30, true);
169-
MovedStatics.aClass9_1611.put(id, model1);
175+
actorChildModelCache.put(id, model1);
170176
}
171177
Model class40_sub5_sub17_sub5_0_;
172178
if(animation1 != null && animation2 != null) {

src/main/java/org/runejs/client/cache/def/IdentityKit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public static IdentityKit cache(int arg1) {
3737
return identityKit;
3838
}
3939

40+
public static void clearIdentityKitCache() {
41+
identityKitNodeCache.clear();
42+
}
43+
4044
public void readValues(Buffer buffer) {
4145
while(true) {
4246
int opcode = buffer.getUnsignedByte();

src/main/java/org/runejs/client/cache/def/ItemDefinition.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class ItemDefinition extends CachedNode implements EntityDefinition {
1616
public static CacheArchive itemDefinitionCache;
1717
public static NodeCache itemDefinitionNodeCache = new NodeCache(64);
1818
public static NodeCache groundItemModelNodeCache = new NodeCache(50);
19+
public static NodeCache itemImageCache = new NodeCache(100);
1920

2021
public int stackable;
2122
public String name;
@@ -117,7 +118,7 @@ public static ItemDefinition forId(int id, int arg1) {
117118

118119
public static ImageRGB sprite(int stackSize, int id, int backColour) {
119120
if(backColour == 0) {
120-
ImageRGB sprite = (ImageRGB) Buffer.rgbImageCache.get((long) id);
121+
ImageRGB sprite = (ImageRGB) itemImageCache.get((long) id);
121122
if(sprite != null && sprite.maxHeight != stackSize && sprite.maxHeight != -1) {
122123
sprite.unlink();
123124
sprite = null;
@@ -219,7 +220,7 @@ else if(i_13_ <= 0 || rendered.pixels[i_15_ + (i_13_ + -1) * 32] != 1) {
219220
notedSprite.maxHeight = i_17_;
220221
}
221222
if(backColour == 0)
222-
Buffer.rgbImageCache.put((long) id, rendered);
223+
itemImageCache.put((long) id, rendered);
223224
Rasterizer.prepare(pixels, i_1_, i);
224225
Rasterizer.setBounds(i_2_, i_5_, i_4_, i_6_);
225226
Rasterizer3D.setLineOffsets(lineOffsets);
@@ -236,6 +237,12 @@ else if(i_13_ <= 0 || rendered.pixels[i_15_ + (i_13_ + -1) * 32] != 1) {
236237

237238
}
238239

240+
public static void clearItemCache() {
241+
itemDefinitionNodeCache.clear();
242+
groundItemModelNodeCache.clear();
243+
itemImageCache.clear();
244+
}
245+
239246
public boolean headPieceReady(boolean female) {
240247
int primaryId = primaryMaleHeadPiece;
241248
int secondaryId = secondaryMaleHeadPiece;

src/main/java/org/runejs/client/cache/def/OverlayDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void initializeOverlayDefinitionCache(CacheArchive cacheArchive) {
4444
gameDefinitionsCacheArchive = cacheArchive;
4545
}
4646

47-
public static void method233() {
47+
public static void clearOverlayDefinitionCache() {
4848
overlayDefinitionCache.clear();
4949
}
5050

src/main/java/org/runejs/client/cache/def/SpotAnimDefinition.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class SpotAnimDefinition extends CachedNode {
1212

1313
public static CacheArchive gameDefinitionsCacheArchive;
1414
public static NodeCache spotAnimDefinitionCache = new NodeCache(64);
15-
public static NodeCache modelCache = new NodeCache(30);
15+
public static NodeCache spotAnimModelCache = new NodeCache(30);
1616
public int animationId;
1717
public int modelId;
1818
public int contrast = 0;
@@ -45,9 +45,9 @@ public static SpotAnimDefinition forId(int id) {
4545
return spotAnimDefinition;
4646
}
4747

48-
public static void clearSpotAnimDefinitionCache() {
48+
public static void clearSpotAnimCache() {
4949
spotAnimDefinitionCache.clear();
50-
modelCache.clear();
50+
spotAnimModelCache.clear();
5151
}
5252

5353
public static void initializeSpotAnimCache(CacheArchive arg1, CacheArchive arg2) {
@@ -88,7 +88,7 @@ public void readValue(int opcode, Buffer buffer) {
8888
}
8989

9090
public Model getModel(int arg0) {
91-
Model model = (Model) modelCache.get((long) id);
91+
Model model = (Model) spotAnimModelCache.get((long) id);
9292
if (model == null) {
9393
model = Model.getModel(MovedStatics. aCacheArchive_2582, modelId);
9494
if (model == null) {
@@ -101,7 +101,7 @@ public Model getModel(int arg0) {
101101
}
102102
model.createBones();
103103
model.applyLighting(64 + ambient, contrast + 850, -30, -50, -30, true);
104-
modelCache.put((long) id, model);
104+
spotAnimModelCache.put((long) id, model);
105105
}
106106
Model class40_sub5_sub17_sub5_0_;
107107
if (animationId == -1 || arg0 == -1) {

0 commit comments

Comments
 (0)