8
8
import org .runejs .client .media .renderable .GameObject ;
9
9
10
10
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 ;
13
24
public int anInt2137 ;
14
25
public int [] anIntArray2138 ;
15
- public int [] pixels_maybe ;
26
+ public int [] pixels ;
16
27
public int [] anIntArray2140 ;
17
- public int anInt2142 ;
28
+ public int animateSpeed ;
18
29
public boolean opaque ;
19
30
public int [] spriteIds ;
20
31
public int [] colors ;
@@ -42,65 +53,63 @@ public Texture(Buffer textureBuffer) {
42
53
colors = new int [i ];
43
54
for (int i_33_ = 0 ; i_33_ < i ; i_33_ ++)
44
55
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 ;
48
59
}
49
60
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 ];
75
90
}
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 ];
98
106
}
99
- int [] is = pixels_maybe ;
100
- pixels_maybe = anIntArray2141 ;
101
- anIntArray2141 = is ;
102
107
}
103
108
}
109
+
110
+ int [] tmp = pixels ;
111
+ pixels = animationPixels ;
112
+ animationPixels = tmp ;
104
113
}
105
114
106
115
public boolean method869 (double arg0 , int textureSize , CacheArchive imageArchive ) {
@@ -109,7 +118,7 @@ public boolean method869(double arg0, int textureSize, CacheArchive imageArchive
109
118
return false ;
110
119
}
111
120
int i = textureSize * textureSize ;
112
- pixels_maybe = new int [i * 4 ];
121
+ pixels = new int [i * 4 ];
113
122
for (int i_12_ = 0 ; i_12_ < spriteIds .length ; i_12_ ++) {
114
123
IndexedImage image = GameObject .method769 (2 , imageArchive , spriteIds [i_12_ ]);
115
124
image .resizeToLibSize ();
@@ -137,34 +146,34 @@ public boolean method869(double arg0, int textureSize, CacheArchive imageArchive
137
146
if (i_20_ == 0 ) {
138
147
if (image .imgWidth == textureSize ) {
139
148
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 ];
141
150
} else if (image .imgWidth == 64 && textureSize == 128 ) {
142
151
int i_22_ = 0 ;
143
152
for (int i_23_ = 0 ; i_23_ < textureSize ; i_23_ ++) {
144
153
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 ];
146
155
}
147
156
} else if (image .imgWidth == 128 && textureSize == 64 ) {
148
157
int i_25_ = 0 ;
149
158
for (int i_26_ = 0 ; i_26_ < textureSize ; i_26_ ++) {
150
159
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 ];
152
161
}
153
162
} else
154
163
throw new RuntimeException ();
155
164
}
156
165
}
157
166
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 ;
163
172
}
164
173
return true ;
165
174
}
166
175
167
176
public void clearPixels () {
168
- pixels_maybe = null ;
177
+ pixels = null ;
169
178
}
170
179
}
0 commit comments