Skip to content

Commit 3ab57cf

Browse files
authored
Merge pull request #163 from runejs/texture-refactors
refactor: refactor texture and animation
2 parents d56e864 + b3e45b7 commit 3ab57cf

File tree

3 files changed

+85
-76
lines changed

3 files changed

+85
-76
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public void clearTextures() {
8484
public int[] getTexturePixels(int textureId) {
8585
Texture texture = textures[textureId];
8686
if (texture != null) {
87-
if (texture.pixels_maybe != null) {
87+
if (texture.pixels != null) {
8888
textureCache.addFirst(texture);
8989
texture.aBoolean2146 = true;
90-
return texture.pixels_maybe;
90+
return texture.pixels;
9191
}
9292

9393
boolean bool = texture.method869(brightness, textureSize, gameImageCacheArchive);
@@ -99,7 +99,7 @@ public int[] getTexturePixels(int textureId) {
9999
anInt1753--;
100100
textureCache.addFirst(texture);
101101
texture.aBoolean2146 = true;
102-
return texture.pixels_maybe;
102+
return texture.pixels;
103103
}
104104
}
105105
return null;
@@ -120,13 +120,13 @@ public void setBrightness(double brightness) {
120120
clearTextures();
121121
}
122122

123-
public void method425(int arg1) {
123+
public void animateTextures(int arg1) {
124124
int i = 0;
125125
for (/**/; i < textures.length; i++) {
126-
Texture class40_sub10 = textures[i];
127-
if (class40_sub10 != null && class40_sub10.anInt2136 != 0 && class40_sub10.aBoolean2146) {
128-
class40_sub10.method868(arg1);
129-
class40_sub10.aBoolean2146 = false;
126+
Texture texture = textures[i];
127+
if (texture != null && texture.animateDirection != 0 && texture.aBoolean2146) {
128+
texture.animate(arg1);
129+
texture.aBoolean2146 = false;
130130
}
131131
}
132132
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public static void method353() {
869869
Npc.currentScene.clearInteractiveObjectCache();
870870
Class33.draw2DActorAttachments();
871871
MovedStatics.drawPositionHintIcon();
872-
((Class35) Rasterizer3D.interface3).method425(MovedStatics.anInt199);
872+
((Class35) Rasterizer3D.interface3).animateTextures(MovedStatics.anInt199);
873873
KeyFocusListener.draw3dScreen();
874874

875875
if(ScreenController.frameMode == ScreenMode.FIXED) {

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

Lines changed: 76 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@
88
import org.runejs.client.media.renderable.GameObject;
99

1010
public class Texture extends Node {
11-
public static int[] anIntArray2141;
12-
public int anInt2136;
11+
/**
12+
* Temporary array used while animating textures.
13+
*/
14+
public static int[] animationPixels;
15+
/**
16+
* Which direction should the texture move in?
17+
*
18+
* 1: down
19+
* 2: left
20+
* 3: up
21+
* 4: right
22+
*/
23+
public int animateDirection;
1324
public int anInt2137;
1425
public int[] anIntArray2138;
15-
public int[] pixels_maybe;
26+
public int[] pixels;
1627
public int[] anIntArray2140;
17-
public int anInt2142;
28+
public int animateSpeed;
1829
public boolean opaque;
1930
public int[] spriteIds;
2031
public int[] colors;
@@ -42,65 +53,63 @@ public Texture(Buffer textureBuffer) {
4253
colors = new int[i];
4354
for(int i_33_ = 0; i_33_ < i; i_33_++)
4455
colors[i_33_] = textureBuffer.getIntBE();
45-
anInt2136 = textureBuffer.getUnsignedByte();
46-
anInt2142 = textureBuffer.getUnsignedByte();
47-
pixels_maybe = null;
56+
animateDirection = textureBuffer.getUnsignedByte();
57+
animateSpeed = textureBuffer.getUnsignedByte();
58+
pixels = null;
4859
}
4960

50-
public void method868(int arg0) {
51-
if(pixels_maybe != null) {
52-
if(anInt2136 == 1 || anInt2136 == 3) {
53-
if(anIntArray2141 == null || anIntArray2141.length < pixels_maybe.length)
54-
anIntArray2141 = new int[pixels_maybe.length];
55-
int i;
56-
if(pixels_maybe.length == 16384)
57-
i = 64;
58-
else
59-
i = 128;
60-
int i_0_ = pixels_maybe.length / 4;
61-
int i_1_ = i * arg0 * anInt2142;
62-
int i_2_ = i_0_ - 1;
63-
if(anInt2136 == 1)
64-
i_1_ = -i_1_;
65-
for(int i_3_ = 0; i_3_ < i_0_; i_3_++) {
66-
int i_4_ = i_3_ + i_1_ & i_2_;
67-
anIntArray2141[i_3_] = pixels_maybe[i_4_];
68-
anIntArray2141[i_3_ + i_0_] = pixels_maybe[i_4_ + i_0_];
69-
anIntArray2141[i_3_ + i_0_ + i_0_] = pixels_maybe[i_4_ + i_0_ + i_0_];
70-
anIntArray2141[i_3_ + i_0_ + i_0_ + i_0_] = pixels_maybe[i_4_ + i_0_ + i_0_ + i_0_];
71-
}
72-
int[] is = pixels_maybe;
73-
pixels_maybe = anIntArray2141;
74-
anIntArray2141 = is;
61+
public void animate(int deltaT) {
62+
if (pixels == null) {
63+
return;
64+
}
65+
66+
if (animationPixels == null || animationPixels.length < pixels.length)
67+
animationPixels = new int[pixels.length];
68+
69+
int dimension;
70+
if (pixels.length == 16384)
71+
dimension = 64;
72+
else
73+
dimension = 128;
74+
75+
// TODO (jkm) what is this quarterLength? Are there 4 "channels" (i.e. rgb (a?)) in the pixel array?
76+
int quarterLength = pixels.length / 4;
77+
78+
// up or down
79+
if (animateDirection == 1 || animateDirection == 3) {
80+
int offset = dimension * deltaT * animateSpeed;
81+
int i_2_ = quarterLength - 1;
82+
if (animateDirection == 1)
83+
offset = -offset;
84+
for (int counter = 0; counter < quarterLength; counter++) {
85+
int index = counter + offset & i_2_;
86+
animationPixels[counter] = pixels[index];
87+
animationPixels[counter + quarterLength] = pixels[index + quarterLength];
88+
animationPixels[counter + quarterLength + quarterLength] = pixels[index + quarterLength + quarterLength];
89+
animationPixels[counter + quarterLength + quarterLength + quarterLength] = pixels[index + quarterLength + quarterLength + quarterLength];
7590
}
76-
if(anInt2136 == 2 || anInt2136 == 4) {
77-
if(anIntArray2141 == null || anIntArray2141.length < pixels_maybe.length)
78-
anIntArray2141 = new int[pixels_maybe.length];
79-
int i;
80-
if(pixels_maybe.length == 16384)
81-
i = 64;
82-
else
83-
i = 128;
84-
int i_5_ = pixels_maybe.length / 4;
85-
int i_6_ = arg0 * anInt2142;
86-
int i_7_ = i - 1;
87-
if(anInt2136 == 2)
88-
i_6_ = -i_6_;
89-
for(int i_8_ = 0; i_8_ < i_5_; i_8_ += i) {
90-
for(int i_9_ = 0; i_9_ < i; i_9_++) {
91-
int i_10_ = i_8_ + i_9_;
92-
int i_11_ = i_8_ + (i_9_ + i_6_ & i_7_);
93-
anIntArray2141[i_10_] = pixels_maybe[i_11_];
94-
anIntArray2141[i_10_ + i_5_] = pixels_maybe[i_11_ + i_5_];
95-
anIntArray2141[i_10_ + i_5_ + i_5_] = pixels_maybe[i_11_ + i_5_ + i_5_];
96-
anIntArray2141[i_10_ + i_5_ + i_5_ + i_5_] = pixels_maybe[i_11_ + i_5_ + i_5_ + i_5_];
97-
}
91+
}
92+
// left or right
93+
if (animateDirection == 2 || animateDirection == 4) {
94+
int offset = deltaT * animateSpeed;
95+
int i_7_ = dimension - 1;
96+
if (animateDirection == 2)
97+
offset = -offset;
98+
for (int counter = 0; counter < quarterLength; counter += dimension) {
99+
for (int d = 0; d < dimension; d++) {
100+
int index = counter + d;
101+
int otherIndex = counter + (d + offset & i_7_);
102+
animationPixels[index] = pixels[otherIndex];
103+
animationPixels[index + quarterLength] = pixels[otherIndex + quarterLength];
104+
animationPixels[index + quarterLength + quarterLength] = pixels[otherIndex + quarterLength + quarterLength];
105+
animationPixels[index + quarterLength + quarterLength + quarterLength] = pixels[otherIndex + quarterLength + quarterLength + quarterLength];
98106
}
99-
int[] is = pixels_maybe;
100-
pixels_maybe = anIntArray2141;
101-
anIntArray2141 = is;
102107
}
103108
}
109+
110+
int[] tmp = pixels;
111+
pixels = animationPixels;
112+
animationPixels = tmp;
104113
}
105114

106115
public boolean method869(double arg0, int textureSize, CacheArchive imageArchive) {
@@ -109,7 +118,7 @@ public boolean method869(double arg0, int textureSize, CacheArchive imageArchive
109118
return false;
110119
}
111120
int i = textureSize * textureSize;
112-
pixels_maybe = new int[i * 4];
121+
pixels = new int[i * 4];
113122
for(int i_12_ = 0; i_12_ < spriteIds.length; i_12_++) {
114123
IndexedImage image = GameObject.method769(2, imageArchive, spriteIds[i_12_]);
115124
image.resizeToLibSize();
@@ -137,34 +146,34 @@ public boolean method869(double arg0, int textureSize, CacheArchive imageArchive
137146
if(i_20_ == 0) {
138147
if(image.imgWidth == textureSize) {
139148
for(int i_21_ = 0; i_21_ < i; i_21_++)
140-
pixels_maybe[i_21_] = imgPalette[imgPixels[i_21_] & 0xff];
149+
pixels[i_21_] = imgPalette[imgPixels[i_21_] & 0xff];
141150
} else if(image.imgWidth == 64 && textureSize == 128) {
142151
int i_22_ = 0;
143152
for(int i_23_ = 0; i_23_ < textureSize; i_23_++) {
144153
for(int i_24_ = 0; i_24_ < textureSize; i_24_++)
145-
pixels_maybe[i_22_++] = imgPalette[imgPixels[(i_24_ >> 1) + (i_23_ >> 1 << 6)] & 0xff];
154+
pixels[i_22_++] = imgPalette[imgPixels[(i_24_ >> 1) + (i_23_ >> 1 << 6)] & 0xff];
146155
}
147156
} else if(image.imgWidth == 128 && textureSize == 64) {
148157
int i_25_ = 0;
149158
for(int i_26_ = 0; i_26_ < textureSize; i_26_++) {
150159
for(int i_27_ = 0; i_27_ < textureSize; i_27_++)
151-
pixels_maybe[i_25_++] = imgPalette[imgPixels[(i_27_ << 1) + (i_26_ << 1 << 7)] & 0xff];
160+
pixels[i_25_++] = imgPalette[imgPixels[(i_27_ << 1) + (i_26_ << 1 << 7)] & 0xff];
152161
}
153162
} else
154163
throw new RuntimeException();
155164
}
156165
}
157166
for(int pixelIndex = 0; pixelIndex < i; pixelIndex++) {
158-
pixels_maybe[pixelIndex] &= 0xf8f8ff;
159-
int pixel = pixels_maybe[pixelIndex];
160-
pixels_maybe[pixelIndex + i] = pixel - (pixel >>> 3) & 0xf8f8ff;
161-
pixels_maybe[pixelIndex + i + i] = pixel - (pixel >>> 2) & 0xf8f8ff;
162-
pixels_maybe[pixelIndex + i + i + i] = pixel - (pixel >>> 2) - (pixel >>> 3) & 0xf8f8ff;
167+
pixels[pixelIndex] &= 0xf8f8ff;
168+
int pixel = pixels[pixelIndex];
169+
pixels[pixelIndex + i] = pixel - (pixel >>> 3) & 0xf8f8ff;
170+
pixels[pixelIndex + i + i] = pixel - (pixel >>> 2) & 0xf8f8ff;
171+
pixels[pixelIndex + i + i + i] = pixel - (pixel >>> 2) - (pixel >>> 3) & 0xf8f8ff;
163172
}
164173
return true;
165174
}
166175

167176
public void clearPixels() {
168-
pixels_maybe = null;
177+
pixels = null;
169178
}
170179
}

0 commit comments

Comments
 (0)