A RuneTek3 client (377) that is deobfuscated, converted to Kotlin, and includes QoL improvements.
0

Configure Feed

Select the types of activity you want to include in your feed.

Convert Rasterizer3D, Model, Scene to Kotlin with deob-driven renames

Using openrs2-nonfree 377 branch as reference, renamed all obfuscated
fields and methods in the rendering pipeline before converting to Kotlin:

- Rasterizer3D: reciprocal16 (was anIntArray1469), removed dead code
- Model: 19 field renames (depth buckets, priority sorting, clipping
buffers, lighting info), 4 method renames (renderTriangles,
drawTriangle, drawClippedTriangle, isPointInTriangle)
- Scene: 19 field renames (tile render cycle, viewport bounds, wall
flags, occlusion, culling), plus InteractiveObject.renderPriority
and GroundItemTile.heightOffset
- Animation: transformCount (was anInt433)
- Fix stopMidi NPE on logout when MIDI sequencer not initialized

All three files converted with correct Kotlin bitwise precedence,
compound assignment splits, and @JvmStatic/@JvmField for Java interop.

+6977 -6520
.DS_Store

This is a binary file and will not be displayed.

+3 -1
src/main/java/com/jagex/runescape/Game.java
··· 10574 10574 } 10575 10575 10576 10576 private void stopMidi() { 10577 - SignLink.music.stop(); 10577 + if (SignLink.music != null) { 10578 + SignLink.music.stop(); 10579 + } 10578 10580 SignLink.fadeMidi = 0; 10579 10581 SignLink.midi = "stop"; 10580 10582 }
+5 -5
src/main/java/com/jagex/runescape/cache/def/ActorDefinition.kt
··· 120 120 if (cached) return null 121 121 122 122 val headModels = Array(indexes.size) { Model.getModel(indexes[it]) } 123 - var headModel: Model = if (headModels.size == 1) headModels[0] 123 + var headModel: Model = if (headModels.size == 1) headModels[0]!! 124 124 else Model(headModels.size, headModels) 125 125 126 126 if (modifiedModelColors != null) { ··· 159 159 if (cached) return null 160 160 161 161 val childModels = Array(modelIds!!.size) { Model.getModel(modelIds!![it]) } 162 - childIdModel = if (childModels.size == 1) childModels[0] 162 + childIdModel = if (childModels.size == 1) childModels[0]!! 163 163 else Model(childModels.size, childModels) 164 164 165 165 if (modifiedModelColors != null) { 166 166 for (colour in modifiedModelColors!!.indices) 167 - childIdModel.replaceColor(modifiedModelColors!![colour], originalModelColors!![colour]) 167 + childIdModel!!.replaceColor(modifiedModelColors!![colour], originalModelColors!![colour]) 168 168 } 169 - childIdModel.createBones() 169 + childIdModel!!.createBones() 170 170 childIdModel.applyLighting(64 + brightness, 850 + contrast, -30, -50, -30, true) 171 171 modelCache!!.put(childIdModel, id) 172 172 } 173 173 val childModel = Model.EMPTY_MODEL 174 - childModel.replaceWithModel(childIdModel, Animation.exists(frameId2) and Animation.exists(frameId)) 174 + childModel.replaceWithModel(childIdModel!!, Animation.exists(frameId2) and Animation.exists(frameId)) 175 175 if (frameId2 != -1 && frameId != -1) 176 176 childModel.mixAnimationFrames(frameId, 0, frameId2, framesFrom2) 177 177 else if (frameId2 != -1)
+2 -2
src/main/java/com/jagex/runescape/cache/def/GameObjectDefinition.kt
··· 257 257 } 258 258 val scale = modelSizeX != 128 || modelSizeY != 128 || modelSizeZ != 128 259 259 val needsTranslation = translateX != 0 || translateY != 0 || translateZ != 0 260 - val animatedModel = Model(modifiedModelColors == null, subModel, Animation.exists(animationId)) 260 + val animatedModel = Model(modifiedModelColors == null, subModel!!, Animation.exists(animationId)) 261 261 if (animationId != -1) { 262 262 animatedModel.createBones() 263 263 animatedModel.applyTransform(animationId) ··· 278 278 64 + modelLightFalloff, 768 + modelLightAmbient * 5, -50, -10, -50, !nonFlatShading 279 279 ) 280 280 if (anInt794 == 1) 281 - animatedModel.anInt1675 = animatedModel.modelHeight 281 + animatedModel.objectHeight = animatedModel.modelHeight 282 282 animatedModelCache!!.put(animatedModel, hash) 283 283 return animatedModel 284 284 }
+8 -8
src/main/java/com/jagex/runescape/cache/def/ItemDefinition.kt
··· 118 118 tertiaryId = tertiaryFemaleEquipmentModel 119 119 } 120 120 if (primaryId == -1) return null 121 - var primary = Model.getModel(primaryId) 121 + var primary: Model? = Model.getModel(primaryId) 122 122 if (secondaryId != -1) { 123 123 primary = if (tertiaryId == -1) { 124 124 val secondary = Model.getModel(secondaryId) ··· 130 130 } 131 131 } 132 132 if (gender == 0 && maleTranslation.toInt() != 0) 133 - primary.translate(0, 0, maleTranslation.toInt()) 133 + primary!!.translate(0, 0, maleTranslation.toInt()) 134 134 if (gender == 1 && femaleTranslation.toInt() != 0) 135 - primary.translate(0, 0, femaleTranslation.toInt()) 135 + primary!!.translate(0, 0, femaleTranslation.toInt()) 136 136 if (originalColours != null) { 137 137 for (color in originalColours!!.indices) 138 - primary.replaceColor(originalColours!![color], destColors!![color]) 138 + primary!!.replaceColor(originalColours!![color], destColors!![color]) 139 139 } 140 140 return primary 141 141 } ··· 280 280 secondaryId = secondaryFemaleHeadPiece 281 281 } 282 282 if (primaryId == -1) return null 283 - var primary = Model.getModel(primaryId) 283 + var primary: Model? = Model.getModel(primaryId) 284 284 if (secondaryId != -1) { 285 285 val secondary = Model.getModel(secondaryId) 286 286 primary = Model(2, arrayOf(primary, secondary)) 287 287 } 288 288 if (originalColours != null) { 289 289 for (index in originalColours!!.indices) 290 - primary.replaceColor(originalColours!![index], destColors!![index]) 290 + primary!!.replaceColor(originalColours!![index], destColors!![index]) 291 291 } 292 292 return primary 293 293 } ··· 418 418 scale = (scale * 1.5).toInt() 419 419 if (backColour > 0) 420 420 scale = (scale * 1.04).toInt() 421 - val sin = Rasterizer3D.SINE[definition.modelRotationX] * scale shr 16 422 - val cos = Rasterizer3D.COSINE[definition.modelRotationX] * scale shr 16 421 + val sin = Rasterizer3D.SINE!![definition.modelRotationX] * scale shr 16 422 + val cos = Rasterizer3D.COSINE!![definition.modelRotationX] * scale shr 16 423 423 model.render( 424 424 0, definition.modelRotationY, definition.anInt339, definition.modelRotationX, 425 425 definition.modelOffsetX,
+1 -1
src/main/java/com/jagex/runescape/cache/media/IdentityKit.kt
··· 43 43 fun getBodyModel(): Model? { 44 44 if (modelId == null) return null 45 45 val models = Array(modelId!!.size) { Model.getModel(modelId!![it]) } 46 - val model = if (models.size == 1) models[0] else Model(models.size, models) 46 + val model: Model = if (models.size == 1) models[0]!! else Model(models.size, models) 47 47 for (color in 0 until 6) { 48 48 if (originalModelColors[color] == 0) break 49 49 model.replaceColor(originalModelColors[color], modifiedModelColors[color])
+2 -2
src/main/java/com/jagex/runescape/media/Animation.java
··· 6 6 public static Animation[] cache; 7 7 public int anInt431; 8 8 public Skins animationSkins; 9 - public int anInt433; 9 + public int transformCount; 10 10 public int opcodeTable[]; 11 11 public int modifier1[]; 12 12 public int modifier2[]; ··· 96 96 } 97 97 } 98 98 99 - animation.anInt433 = k2; 99 + animation.transformCount = k2; 100 100 animation.opcodeTable = new int[k2]; 101 101 animation.modifier1 = new int[k2]; 102 102 animation.modifier2 = new int[k2];
-2243
src/main/java/com/jagex/runescape/media/Rasterizer3D.java
··· 1 - package com.jagex.runescape.media; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.cache.media.IndexedImage; 5 - 6 - public class Rasterizer3D extends Rasterizer { 7 - 8 - public static boolean lowMemory = true; 9 - public static boolean restrict_edges; 10 - public static boolean opaque; 11 - public static boolean notTextured = true; 12 - public static int alpha; 13 - public static int center_x; 14 - public static int center_y; 15 - public static int[] shadowDecay = new int[512]; 16 - public static int[] anIntArray1469 = new int[2048]; 17 - public static int[] SINE = new int[2048]; 18 - public static int[] COSINE = new int[2048]; 19 - public static int[] lineOffsets; 20 - public static int loadedTextureCount; 21 - public static IndexedImage textureImages[] = new IndexedImage[50]; 22 - public static boolean textureIsTransparent[] = new boolean[50]; 23 - public static int averageTextureColour[] = new int[50]; 24 - public static int textureTexelPoolPointer; 25 - public static int texelArrayPool[][]; 26 - public static int texelCache[][] = new int[50][]; 27 - public static int textureLastUsed[] = new int[50]; 28 - public static int textureGetCount; 29 - public static int hsl2rgb[] = new int[0x10000]; 30 - public static int texturePalettes[][] = new int[50][]; 31 - private static boolean useLatestShadeLine = true; 32 - 33 - 34 - public static void reset() { 35 - shadowDecay = null; 36 - SINE = null; 37 - COSINE = null; 38 - lineOffsets = null; 39 - textureImages = null; 40 - textureIsTransparent = null; 41 - averageTextureColour = null; 42 - texelArrayPool = null; 43 - texelCache = null; 44 - textureLastUsed = null; 45 - hsl2rgb = null; 46 - texturePalettes = null; 47 - } 48 - 49 - public static void setDefaultBounds() { 50 - lineOffsets = new int[Rasterizer.height]; 51 - for (int i = 0; i < height; i++) { 52 - lineOffsets[i] = width * i; 53 - } 54 - center_x = width / 2; 55 - center_y = height / 2; 56 - } 57 - 58 - public static void setBounds(int width, int height) { 59 - lineOffsets = new int[height]; 60 - for (int i = 0; i < height; i++) { 61 - lineOffsets[i] = width * i; 62 - } 63 - center_x = width / 2; 64 - center_y = height / 2; 65 - } 66 - 67 - public static void clearTextureCache() { 68 - texelArrayPool = null; 69 - for (int i = 0; i < 50; i++) { 70 - texelCache[i] = null; 71 - } 72 - } 73 - 74 - public static void resetTextures(int texturePoolSize) { 75 - if (texelArrayPool == null) { 76 - textureTexelPoolPointer = texturePoolSize;//was parameter 77 - if (lowMemory) { 78 - texelArrayPool = new int[textureTexelPoolPointer][16384]; 79 - } else { 80 - texelArrayPool = new int[textureTexelPoolPointer][0x10000]; 81 - } 82 - for (int k = 0; k < 50; k++) { 83 - texelCache[k] = null; 84 - } 85 - 86 - } 87 - } 88 - 89 - public static void unpackTextures(Archive jagexArchive) { 90 - loadedTextureCount = 0; 91 - for (int i = 0; i < 50; i++) { 92 - try { 93 - textureImages[i] = new IndexedImage(jagexArchive, String.valueOf(i), 0); 94 - if (lowMemory && textureImages[i].maxWidth == 128) { 95 - textureImages[i].resizeToHalfLibSize(); 96 - } else { 97 - textureImages[i].resizeToLibSize(); 98 - } 99 - loadedTextureCount++; 100 - } catch (Exception exception) { 101 - } 102 - }/* 103 - for (int k = 0;k < textureImagesHD.length;k++) 104 - try{ 105 - textureImagesHD[k] = new RgbImage("./hddata/texture/"+k+".png"); 106 - } catch (Exception ignored){ 107 - textureImagesHD[k] = textureImagesHD[k - 1]; 108 - } 109 - */ 110 - } 111 - 112 - public static int getAverageRgbColorForTexture(int textureId) { 113 - if (averageTextureColour[textureId] != 0) { 114 - return averageTextureColour[textureId]; 115 - } 116 - int red = 0; 117 - int green = 0; 118 - int blue = 0; 119 - int colourCount = texturePalettes[textureId].length; 120 - for (int ptr = 0; ptr < colourCount; ptr++) { 121 - red += texturePalettes[textureId][ptr] >> 16 & 0xff; 122 - green += texturePalettes[textureId][ptr] >> 8 & 0xff; 123 - blue += texturePalettes[textureId][ptr] & 0xff; 124 - } 125 - 126 - int rgb = (red / colourCount << 16) + (green / colourCount << 8) + blue / colourCount; 127 - rgb = adjustBrightness(rgb, 1.3999999999999999D); 128 - if (rgb == 0) { 129 - rgb = 1; 130 - } 131 - averageTextureColour[textureId] = rgb; 132 - return rgb; 133 - } 134 - 135 - public static void resetTexture(int textureId) { 136 - if (texelCache[textureId] == null) { 137 - return; 138 - } 139 - texelArrayPool[textureTexelPoolPointer++] = texelCache[textureId]; 140 - texelCache[textureId] = null; 141 - } 142 - 143 - public static int[] getTexturePixels(int textureId) { 144 - textureLastUsed[textureId] = textureGetCount++; 145 - if (texelCache[textureId] != null) { 146 - return texelCache[textureId]; 147 - } 148 - int texels[]; 149 - //Start of mem management code 150 - if (textureTexelPoolPointer > 0) { //Freed texture data arrays available 151 - texels = texelArrayPool[--textureTexelPoolPointer]; 152 - texelArrayPool[textureTexelPoolPointer] = null; 153 - } else { //No freed texture data arrays available, recycle least used texture's array 154 - int lastUsed = 0; 155 - int target = -1; 156 - for (int i = 0; i < loadedTextureCount; i++) { 157 - if (texelCache[i] != null && (textureLastUsed[i] < lastUsed || target == -1)) { 158 - lastUsed = textureLastUsed[i]; 159 - target = i; 160 - } 161 - } 162 - 163 - texels = texelCache[target]; 164 - texelCache[target] = null; 165 - } 166 - texelCache[textureId] = texels; 167 - //End of mem management code 168 - IndexedImage indexedImage = textureImages[textureId]; 169 - int texturePalette[] = texturePalettes[textureId]; 170 - if (lowMemory) { 171 - textureIsTransparent[textureId] = false; 172 - for (int texelPtr = 0; texelPtr < 4096; texelPtr++) { 173 - int texel = texels[texelPtr] = texturePalette[indexedImage.imgPixels[texelPtr]] & 0xf8f8ff; 174 - if (texel == 0) { 175 - textureIsTransparent[textureId] = true; 176 - } 177 - texels[4096 + texelPtr] = texel - (texel >>> 3) & 0xf8f8ff; 178 - texels[8192 + texelPtr] = texel - (texel >>> 2) & 0xf8f8ff; 179 - texels[12288 + texelPtr] = texel - (texel >>> 2) - (texel >>> 3) & 0xf8f8ff; 180 - } 181 - 182 - } else { 183 - if (indexedImage.imgWidth == 64) { 184 - for (int y = 0; y < 128; y++) { 185 - for (int x = 0; x < 128; x++) { 186 - texels[x + (y << 7)] = texturePalette[indexedImage.imgPixels[(x >> 1) + ((y >> 1) << 6)]]; 187 - } 188 - 189 - } 190 - 191 - } else { 192 - for (int texelPtr = 0; texelPtr < 16384; texelPtr++) { 193 - texels[texelPtr] = texturePalette[indexedImage.imgPixels[texelPtr]]; 194 - } 195 - 196 - } 197 - textureIsTransparent[textureId] = false; 198 - for (int texelPtr = 0; texelPtr < 16384; texelPtr++) { 199 - texels[texelPtr] &= 0xf8f8ff; 200 - int texel = texels[texelPtr]; 201 - if (texel == 0) { 202 - textureIsTransparent[textureId] = true; 203 - } 204 - texels[16384 + texelPtr] = texel - (texel >>> 3) & 0xf8f8ff; 205 - texels[32768 + texelPtr] = texel - (texel >>> 2) & 0xf8f8ff; 206 - texels[49152 + texelPtr] = texel - (texel >>> 2) - (texel >>> 3) & 0xf8f8ff; 207 - } 208 - 209 - } 210 - return texels; 211 - } 212 - 213 - public static void calculatePalette(double brightness) { 214 - brightness += Math.random() * 0.029999999999999999D - 0.014999999999999999D; 215 - int hsl = 0; 216 - for (int k = 0; k < 512; k++) { 217 - double d1 = (double) (k / 8) / 64D + 0.0078125D; 218 - double d2 = (double) (k & 7) / 8D + 0.0625D; 219 - for (int k1 = 0; k1 < 128; k1++) { 220 - double d3 = (double) k1 / 128D; 221 - double r = d3; 222 - double g = d3; 223 - double b = d3; 224 - if (d2 != 0.0D) { 225 - double d7; 226 - if (d3 < 0.5D) { 227 - d7 = d3 * (1.0D + d2); 228 - } else { 229 - d7 = (d3 + d2) - d3 * d2; 230 - } 231 - double d8 = 2D * d3 - d7; 232 - double d9 = d1 + 0.33333333333333331D; 233 - if (d9 > 1.0D) { 234 - d9--; 235 - } 236 - double d10 = d1; 237 - double d11 = d1 - 0.33333333333333331D; 238 - if (d11 < 0.0D) { 239 - d11++; 240 - } 241 - if (6D * d9 < 1.0D) { 242 - r = d8 + (d7 - d8) * 6D * d9; 243 - } else if (2D * d9 < 1.0D) { 244 - r = d7; 245 - } else if (3D * d9 < 2D) { 246 - r = d8 + (d7 - d8) * (0.66666666666666663D - d9) * 6D; 247 - } else { 248 - r = d8; 249 - } 250 - if (6D * d10 < 1.0D) { 251 - g = d8 + (d7 - d8) * 6D * d10; 252 - } else if (2D * d10 < 1.0D) { 253 - g = d7; 254 - } else if (3D * d10 < 2D) { 255 - g = d8 + (d7 - d8) * (0.66666666666666663D - d10) * 6D; 256 - } else { 257 - g = d8; 258 - } 259 - if (6D * d11 < 1.0D) { 260 - b = d8 + (d7 - d8) * 6D * d11; 261 - } else if (2D * d11 < 1.0D) { 262 - b = d7; 263 - } else if (3D * d11 < 2D) { 264 - b = d8 + (d7 - d8) * (0.66666666666666663D - d11) * 6D; 265 - } else { 266 - b = d8; 267 - } 268 - } 269 - int byteR = (int) (r * 256D); 270 - int byteG = (int) (g * 256D); 271 - int byteB = (int) (b * 256D); 272 - int rgb = (byteR << 16) + (byteG << 8) + byteB; 273 - rgb = adjustBrightness(rgb, brightness); 274 - if (rgb == 0) { 275 - rgb = 1; 276 - } 277 - hsl2rgb[hsl++] = rgb; 278 - } 279 - 280 - } 281 - 282 - for (int textureId = 0; textureId < 50; textureId++) { 283 - if (textureImages[textureId] != null) { 284 - int palette[] = textureImages[textureId].palette; 285 - texturePalettes[textureId] = new int[palette.length]; 286 - for (int colourIdx = 0; colourIdx < palette.length; colourIdx++) { 287 - texturePalettes[textureId][colourIdx] = adjustBrightness(palette[colourIdx], brightness); 288 - if ((texturePalettes[textureId][colourIdx] & 0xf8f8ff) == 0 && colourIdx != 0) { 289 - texturePalettes[textureId][colourIdx] = 1; 290 - } 291 - } 292 - 293 - } 294 - } 295 - 296 - for (int textureId = 0; textureId < 50; textureId++) { 297 - resetTexture(textureId); 298 - } 299 - 300 - } 301 - 302 - private static int adjustBrightness(int rgb, double intensity) { 303 - double r = (double) (rgb >> 16) / 256D; 304 - double g = (double) (rgb >> 8 & 0xff) / 256D; 305 - double b = (double) (rgb & 0xff) / 256D; 306 - r = Math.pow(r, intensity); 307 - g = Math.pow(g, intensity); 308 - b = Math.pow(b, intensity); 309 - int r_byte = (int) (r * 256D); 310 - int g_byte = (int) (g * 256D); 311 - int b_byte = (int) (b * 256D); 312 - return (r_byte << 16) + (g_byte << 8) + b_byte; 313 - } 314 - 315 - public static void drawShadedTriangle(int y_a, int y_b, int y_c, int x_a, int x_b, int x_c, int z_a, int z_b, int z_c) { 316 - int x_a_off = 0; 317 - int z_a_off = 0; 318 - if (y_b != y_a) { 319 - x_a_off = (x_b - x_a << 16) / (y_b - y_a); 320 - z_a_off = (z_b - z_a << 15) / (y_b - y_a); 321 - } 322 - int x_b_off = 0; 323 - int z_b_off = 0; 324 - if (y_c != y_b) { 325 - x_b_off = (x_c - x_b << 16) / (y_c - y_b); 326 - z_b_off = (z_c - z_b << 15) / (y_c - y_b); 327 - } 328 - int x_c_off = 0; 329 - int z_c_off = 0; 330 - if (y_c != y_a) { 331 - x_c_off = (x_a - x_c << 16) / (y_a - y_c); 332 - z_c_off = (z_a - z_c << 15) / (y_a - y_c); 333 - } 334 - if (y_a <= y_b && y_a <= y_c) { 335 - if (y_a >= bottomY) { 336 - return; 337 - } 338 - if (y_b > bottomY) { 339 - y_b = bottomY; 340 - } 341 - if (y_c > bottomY) { 342 - y_c = bottomY; 343 - } 344 - if (y_b < y_c) { 345 - x_c = x_a <<= 16; 346 - z_c = z_a <<= 15; 347 - if (y_a < 0) { 348 - x_c -= x_c_off * y_a; 349 - x_a -= x_a_off * y_a; 350 - z_c -= z_c_off * y_a; 351 - z_a -= z_a_off * y_a; 352 - y_a = 0; 353 - } 354 - x_b <<= 16; 355 - z_b <<= 15; 356 - if (y_b < 0) { 357 - x_b -= x_b_off * y_b; 358 - z_b -= z_b_off * y_b; 359 - y_b = 0; 360 - } 361 - if (y_a != y_b && x_c_off < x_a_off || y_a == y_b && x_c_off > x_b_off) { 362 - y_c -= y_b; 363 - y_b -= y_a; 364 - for (y_a = lineOffsets[y_a]; --y_b >= 0; y_a += width) { 365 - drawShadedLine(pixels, y_a, x_c >> 16, x_a >> 16, z_c >> 7, z_a >> 7); 366 - x_c += x_c_off; 367 - x_a += x_a_off; 368 - z_c += z_c_off; 369 - z_a += z_a_off; 370 - } 371 - 372 - while (--y_c >= 0) { 373 - drawShadedLine(pixels, y_a, x_c >> 16, x_b >> 16, z_c >> 7, z_b >> 7); 374 - x_c += x_c_off; 375 - x_b += x_b_off; 376 - z_c += z_c_off; 377 - z_b += z_b_off; 378 - y_a += width; 379 - } 380 - return; 381 - } 382 - y_c -= y_b; 383 - y_b -= y_a; 384 - for (y_a = lineOffsets[y_a]; --y_b >= 0; y_a += width) { 385 - drawShadedLine(pixels, y_a, x_a >> 16, x_c >> 16, z_a >> 7, z_c >> 7); 386 - x_c += x_c_off; 387 - x_a += x_a_off; 388 - z_c += z_c_off; 389 - z_a += z_a_off; 390 - } 391 - 392 - while (--y_c >= 0) { 393 - drawShadedLine(pixels, y_a, x_b >> 16, x_c >> 16, z_b >> 7, z_c >> 7); 394 - x_c += x_c_off; 395 - x_b += x_b_off; 396 - z_c += z_c_off; 397 - z_b += z_b_off; 398 - y_a += width; 399 - } 400 - return; 401 - } 402 - x_b = x_a <<= 16; 403 - z_b = z_a <<= 15; 404 - if (y_a < 0) { 405 - x_b -= x_c_off * y_a; 406 - x_a -= x_a_off * y_a; 407 - z_b -= z_c_off * y_a; 408 - z_a -= z_a_off * y_a; 409 - y_a = 0; 410 - } 411 - x_c <<= 16; 412 - z_c <<= 15; 413 - if (y_c < 0) { 414 - x_c -= x_b_off * y_c; 415 - z_c -= z_b_off * y_c; 416 - y_c = 0; 417 - } 418 - if (y_a != y_c && x_c_off < x_a_off || y_a == y_c && x_b_off > x_a_off) { 419 - y_b -= y_c; 420 - y_c -= y_a; 421 - for (y_a = lineOffsets[y_a]; --y_c >= 0; y_a += width) { 422 - drawShadedLine(pixels, y_a, x_b >> 16, x_a >> 16, z_b >> 7, z_a >> 7); 423 - x_b += x_c_off; 424 - x_a += x_a_off; 425 - z_b += z_c_off; 426 - z_a += z_a_off; 427 - } 428 - 429 - while (--y_b >= 0) { 430 - drawShadedLine(pixels, y_a, x_c >> 16, x_a >> 16, z_c >> 7, z_a >> 7); 431 - x_c += x_b_off; 432 - x_a += x_a_off; 433 - z_c += z_b_off; 434 - z_a += z_a_off; 435 - y_a += width; 436 - } 437 - return; 438 - } 439 - y_b -= y_c; 440 - y_c -= y_a; 441 - for (y_a = lineOffsets[y_a]; --y_c >= 0; y_a += width) { 442 - drawShadedLine(pixels, y_a, x_a >> 16, x_b >> 16, z_a >> 7, z_b >> 7); 443 - x_b += x_c_off; 444 - x_a += x_a_off; 445 - z_b += z_c_off; 446 - z_a += z_a_off; 447 - } 448 - 449 - while (--y_b >= 0) { 450 - drawShadedLine(pixels, y_a, x_a >> 16, x_c >> 16, z_a >> 7, z_c >> 7); 451 - x_c += x_b_off; 452 - x_a += x_a_off; 453 - z_c += z_b_off; 454 - z_a += z_a_off; 455 - y_a += width; 456 - } 457 - return; 458 - } 459 - if (y_b <= y_c) { 460 - if (y_b >= bottomY) { 461 - return; 462 - } 463 - if (y_c > bottomY) { 464 - y_c = bottomY; 465 - } 466 - if (y_a > bottomY) { 467 - y_a = bottomY; 468 - } 469 - if (y_c < y_a) { 470 - x_a = x_b <<= 16; 471 - z_a = z_b <<= 15; 472 - if (y_b < 0) { 473 - x_a -= x_a_off * y_b; 474 - x_b -= x_b_off * y_b; 475 - z_a -= z_a_off * y_b; 476 - z_b -= z_b_off * y_b; 477 - y_b = 0; 478 - } 479 - x_c <<= 16; 480 - z_c <<= 15; 481 - if (y_c < 0) { 482 - x_c -= x_c_off * y_c; 483 - z_c -= z_c_off * y_c; 484 - y_c = 0; 485 - } 486 - if (y_b != y_c && x_a_off < x_b_off || y_b == y_c && x_a_off > x_c_off) { 487 - y_a -= y_c; 488 - y_c -= y_b; 489 - for (y_b = lineOffsets[y_b]; --y_c >= 0; y_b += width) { 490 - drawShadedLine(pixels, y_b, x_a >> 16, x_b >> 16, z_a >> 7, z_b >> 7); 491 - x_a += x_a_off; 492 - x_b += x_b_off; 493 - z_a += z_a_off; 494 - z_b += z_b_off; 495 - } 496 - 497 - while (--y_a >= 0) { 498 - drawShadedLine(pixels, y_b, x_a >> 16, x_c >> 16, z_a >> 7, z_c >> 7); 499 - x_a += x_a_off; 500 - x_c += x_c_off; 501 - z_a += z_a_off; 502 - z_c += z_c_off; 503 - y_b += width; 504 - } 505 - return; 506 - } 507 - y_a -= y_c; 508 - y_c -= y_b; 509 - for (y_b = lineOffsets[y_b]; --y_c >= 0; y_b += width) { 510 - drawShadedLine(pixels, y_b, x_b >> 16, x_a >> 16, z_b >> 7, z_a >> 7); 511 - x_a += x_a_off; 512 - x_b += x_b_off; 513 - z_a += z_a_off; 514 - z_b += z_b_off; 515 - } 516 - 517 - while (--y_a >= 0) { 518 - drawShadedLine(pixels, y_b, x_c >> 16, x_a >> 16, z_c >> 7, z_a >> 7); 519 - x_a += x_a_off; 520 - x_c += x_c_off; 521 - z_a += z_a_off; 522 - z_c += z_c_off; 523 - y_b += width; 524 - } 525 - return; 526 - } 527 - x_c = x_b <<= 16; 528 - z_c = z_b <<= 15; 529 - if (y_b < 0) { 530 - x_c -= x_a_off * y_b; 531 - x_b -= x_b_off * y_b; 532 - z_c -= z_a_off * y_b; 533 - z_b -= z_b_off * y_b; 534 - y_b = 0; 535 - } 536 - x_a <<= 16; 537 - z_a <<= 15; 538 - if (y_a < 0) { 539 - x_a -= x_c_off * y_a; 540 - z_a -= z_c_off * y_a; 541 - y_a = 0; 542 - } 543 - if (x_a_off < x_b_off) { 544 - y_c -= y_a; 545 - y_a -= y_b; 546 - for (y_b = lineOffsets[y_b]; --y_a >= 0; y_b += width) { 547 - drawShadedLine(pixels, y_b, x_c >> 16, x_b >> 16, z_c >> 7, z_b >> 7); 548 - x_c += x_a_off; 549 - x_b += x_b_off; 550 - z_c += z_a_off; 551 - z_b += z_b_off; 552 - } 553 - 554 - while (--y_c >= 0) { 555 - drawShadedLine(pixels, y_b, x_a >> 16, x_b >> 16, z_a >> 7, z_b >> 7); 556 - x_a += x_c_off; 557 - x_b += x_b_off; 558 - z_a += z_c_off; 559 - z_b += z_b_off; 560 - y_b += width; 561 - } 562 - return; 563 - } 564 - y_c -= y_a; 565 - y_a -= y_b; 566 - for (y_b = lineOffsets[y_b]; --y_a >= 0; y_b += width) { 567 - drawShadedLine(pixels, y_b, x_b >> 16, x_c >> 16, z_b >> 7, z_c >> 7); 568 - x_c += x_a_off; 569 - x_b += x_b_off; 570 - z_c += z_a_off; 571 - z_b += z_b_off; 572 - } 573 - 574 - while (--y_c >= 0) { 575 - drawShadedLine(pixels, y_b, x_b >> 16, x_a >> 16, z_b >> 7, z_a >> 7); 576 - x_a += x_c_off; 577 - x_b += x_b_off; 578 - z_a += z_c_off; 579 - z_b += z_b_off; 580 - y_b += width; 581 - } 582 - return; 583 - } 584 - if (y_c >= bottomY) { 585 - return; 586 - } 587 - if (y_a > bottomY) { 588 - y_a = bottomY; 589 - } 590 - if (y_b > bottomY) { 591 - y_b = bottomY; 592 - } 593 - if (y_a < y_b) { 594 - x_b = x_c <<= 16; 595 - z_b = z_c <<= 15; 596 - if (y_c < 0) { 597 - x_b -= x_b_off * y_c; 598 - x_c -= x_c_off * y_c; 599 - z_b -= z_b_off * y_c; 600 - z_c -= z_c_off * y_c; 601 - y_c = 0; 602 - } 603 - x_a <<= 16; 604 - z_a <<= 15; 605 - if (y_a < 0) { 606 - x_a -= x_a_off * y_a; 607 - z_a -= z_a_off * y_a; 608 - y_a = 0; 609 - } 610 - if (x_b_off < x_c_off) { 611 - y_b -= y_a; 612 - y_a -= y_c; 613 - for (y_c = lineOffsets[y_c]; --y_a >= 0; y_c += width) { 614 - drawShadedLine(pixels, y_c, x_b >> 16, x_c >> 16, z_b >> 7, z_c >> 7); 615 - x_b += x_b_off; 616 - x_c += x_c_off; 617 - z_b += z_b_off; 618 - z_c += z_c_off; 619 - } 620 - 621 - while (--y_b >= 0) { 622 - drawShadedLine(pixels, y_c, x_b >> 16, x_a >> 16, z_b >> 7, z_a >> 7); 623 - x_b += x_b_off; 624 - x_a += x_a_off; 625 - z_b += z_b_off; 626 - z_a += z_a_off; 627 - y_c += width; 628 - } 629 - return; 630 - } 631 - y_b -= y_a; 632 - y_a -= y_c; 633 - for (y_c = lineOffsets[y_c]; --y_a >= 0; y_c += width) { 634 - drawShadedLine(pixels, y_c, x_c >> 16, x_b >> 16, z_c >> 7, z_b >> 7); 635 - x_b += x_b_off; 636 - x_c += x_c_off; 637 - z_b += z_b_off; 638 - z_c += z_c_off; 639 - } 640 - 641 - while (--y_b >= 0) { 642 - drawShadedLine(pixels, y_c, x_a >> 16, x_b >> 16, z_a >> 7, z_b >> 7); 643 - x_b += x_b_off; 644 - x_a += x_a_off; 645 - z_b += z_b_off; 646 - z_a += z_a_off; 647 - y_c += width; 648 - } 649 - return; 650 - } 651 - x_a = x_c <<= 16; 652 - z_a = z_c <<= 15; 653 - if (y_c < 0) { 654 - x_a -= x_b_off * y_c; 655 - x_c -= x_c_off * y_c; 656 - z_a -= z_b_off * y_c; 657 - z_c -= z_c_off * y_c; 658 - y_c = 0; 659 - } 660 - x_b <<= 16; 661 - z_b <<= 15; 662 - if (y_b < 0) { 663 - x_b -= x_a_off * y_b; 664 - z_b -= z_a_off * y_b; 665 - y_b = 0; 666 - } 667 - if (x_b_off < x_c_off) { 668 - y_a -= y_b; 669 - y_b -= y_c; 670 - for (y_c = lineOffsets[y_c]; --y_b >= 0; y_c += width) { 671 - drawShadedLine(pixels, y_c, x_a >> 16, x_c >> 16, z_a >> 7, z_c >> 7); 672 - x_a += x_b_off; 673 - x_c += x_c_off; 674 - z_a += z_b_off; 675 - z_c += z_c_off; 676 - } 677 - 678 - while (--y_a >= 0) { 679 - drawShadedLine(pixels, y_c, x_b >> 16, x_c >> 16, z_b >> 7, z_c >> 7); 680 - x_b += x_a_off; 681 - x_c += x_c_off; 682 - z_b += z_a_off; 683 - z_c += z_c_off; 684 - y_c += width; 685 - } 686 - return; 687 - } 688 - y_a -= y_b; 689 - y_b -= y_c; 690 - for (y_c = lineOffsets[y_c]; --y_b >= 0; y_c += width) { 691 - drawShadedLine(pixels, y_c, x_c >> 16, x_a >> 16, z_c >> 7, z_a >> 7); 692 - x_a += x_b_off; 693 - x_c += x_c_off; 694 - z_a += z_b_off; 695 - z_c += z_c_off; 696 - } 697 - 698 - while (--y_a >= 0) { 699 - drawShadedLine(pixels, y_c, x_c >> 16, x_b >> 16, z_c >> 7, z_b >> 7); 700 - x_b += x_a_off; 701 - x_c += x_c_off; 702 - z_b += z_a_off; 703 - z_c += z_c_off; 704 - y_c += width; 705 - } 706 - } 707 - 708 - //562 drawshadedline 709 - //has vertex blending :O 710 - public static void drawShadedLine562(int dest[], int dest_off, int startX, int endX, int colorIndex, int grad) { 711 - int off = 0; 712 - int color; 713 - int loops; 714 - if (restrict_edges) { 715 - if (endX > viewportRx) 716 - endX = viewportRx; 717 - if (startX < 0) { 718 - //colorIndex -= startX * off;//not sure if needed 719 - startX = 0; 720 - } 721 - } 722 - if (startX < endX) { 723 - dest_off += startX - 1; 724 - colorIndex += off * startX; 725 - if (notTextured) { 726 - loops = endX - startX >> 2; 727 - if (loops > 0) 728 - off = (grad - colorIndex) * shadowDecay[loops] >> 15; 729 - else 730 - off = 0; 731 - if (alpha == 0) { 732 - if (loops > 0) { 733 - do { 734 - color = hsl2rgb[colorIndex >> 8]; 735 - colorIndex += off; 736 - dest[++dest_off] = color; 737 - dest[++dest_off] = color; 738 - dest[++dest_off] = color; 739 - dest[++dest_off] = color; 740 - } while (--loops > 0); 741 - } 742 - loops = endX - startX & 0x3; 743 - if (loops > 0) { 744 - color = hsl2rgb[colorIndex >> 8]; 745 - do 746 - dest[++dest_off] = color; 747 - while (--loops > 0); 748 - } 749 - } else { 750 - int src_alpha = alpha; 751 - int dest_alpha = 256 - alpha; 752 - if (loops > 0) { 753 - do { 754 - color = hsl2rgb[colorIndex >> 8]; 755 - colorIndex += off; 756 - color = (((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) * dest_alpha >> 8 & 0xff00)); 757 - int i_169_ = dest[++dest_off]; 758 - dest[dest_off] = (color + ((i_169_ & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i_169_ & 0xff00) * src_alpha >> 8 & 0xff00)); 759 - i_169_ = dest[++dest_off]; 760 - dest[dest_off] = (color + ((i_169_ & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i_169_ & 0xff00) * src_alpha >> 8 & 0xff00)); 761 - i_169_ = dest[++dest_off]; 762 - dest[dest_off] = (color + ((i_169_ & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i_169_ & 0xff00) * src_alpha >> 8 & 0xff00)); 763 - i_169_ = dest[++dest_off]; 764 - dest[dest_off] = (color + ((i_169_ & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i_169_ & 0xff00) * src_alpha >> 8 & 0xff00)); 765 - } while (--loops > 0); 766 - } 767 - loops = endX - startX & 0x3; 768 - if (loops > 0) { 769 - color = hsl2rgb[colorIndex >> 8]; 770 - color = (((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) * dest_alpha >> 8 & 0xff00)); 771 - do { 772 - int i_170_ = dest[++dest_off]; 773 - dest[dest_off] = (color + ((i_170_ & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i_170_ & 0xff00) * src_alpha >> 8 & 0xff00)); 774 - } while (--loops > 0); 775 - } 776 - } 777 - } else { 778 - loops = endX - startX; 779 - if (alpha == 0) { 780 - do { 781 - dest[++dest_off] = hsl2rgb[colorIndex >> 8]; 782 - colorIndex += off; 783 - } while (--loops > 0); 784 - } else { 785 - int i = alpha; 786 - int i_171_ = 256 - alpha; 787 - do { 788 - color = hsl2rgb[colorIndex >> 8]; 789 - colorIndex += off; 790 - color = (((color & 0xff00ff) * i_171_ >> 8 & 0xff00ff) + ((color & 0xff00) * i_171_ >> 8 & 0xff00)); 791 - int i_ = dest[++dest_off]; 792 - dest[dest_off] = (color + ((i_ & 0xff00ff) * i >> 8 & 0xff00ff) + ((i_ & 0xff00) * i >> 8 & 0xff00)); 793 - } while (--loops > 0); 794 - } 795 - } 796 - } 797 - } 798 - 799 - public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end_x, int color_index, int grad) { 800 - if (!useLatestShadeLine) {//divert all calls to the new method as its better 801 - drawShadedLine562(dest, dest_off, start_x, end_x, color_index, grad); 802 - // drawShadedLine656(dest, dest_off, start_x, end_x, color_index, grad); 803 - return; 804 - } 805 - 806 - int color; 807 - int loops; 808 - int off = 0; 809 - if (restrict_edges) { 810 - if (end_x > viewportRx) { 811 - end_x = viewportRx; 812 - } 813 - if (start_x < 0) { 814 - color_index -= start_x * off; 815 - start_x = 0; 816 - } 817 - } 818 - if (start_x < end_x) { 819 - dest_off += start_x; 820 - color_index += off * start_x; 821 - //if(1 != 1)//if the below code is dead only textured parts of models appear 822 - if (notTextured) {//ifNontexturedModel? 823 - loops = end_x - start_x >> 2; 824 - if (loops > 0) { 825 - off = (grad - color_index) * shadowDecay[loops] >> 15; 826 - } else { 827 - off = 0; 828 - } 829 - if (alpha == 0) { 830 - if (loops > 0) { 831 - do { 832 - color = hsl2rgb[color_index >> 8]; 833 - color_index += off; 834 - dest[dest_off++] = color; 835 - dest[dest_off++] = color; 836 - dest[dest_off++] = color; 837 - dest[dest_off++] = color; 838 - } while (--loops > 0); 839 - } 840 - loops = end_x - start_x & 0x3; 841 - if (loops > 0) { 842 - color = hsl2rgb[color_index >> 8]; 843 - do { 844 - dest[dest_off++] = color; 845 - } 846 - while (--loops > 0); 847 - } 848 - } else { 849 - int src_alpha = alpha; 850 - int dest_alpha = 256 - alpha; 851 - if (loops > 0) { 852 - do { 853 - color = hsl2rgb[color_index >> 8]; 854 - color_index += off; 855 - color = (((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) * dest_alpha >> 8 & 0xff00)); 856 - int i = dest[dest_off]; 857 - dest[dest_off++] = (color + ((i & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i & 0xff00) * src_alpha >> 8 & 0xff00)); 858 - i = dest[dest_off]; 859 - dest[dest_off++] = (color 860 - + ((i & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i & 0xff00) 861 - * src_alpha >> 8 & 0xff00)); 862 - i = dest[dest_off]; 863 - dest[dest_off++] = (color 864 - + ((i & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i & 0xff00) 865 - * src_alpha >> 8 & 0xff00)); 866 - i = dest[dest_off]; 867 - dest[dest_off++] = (color 868 - + ((i & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i & 0xff00) 869 - * src_alpha >> 8 & 0xff00)); 870 - } while (--loops > 0); 871 - } 872 - loops = end_x - start_x & 0x3; 873 - if (loops > 0) { 874 - color = hsl2rgb[color_index >> 8]; 875 - color = (((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) 876 - * dest_alpha >> 8 & 0xff00)); 877 - do { 878 - int i = dest[dest_off]; 879 - dest[dest_off++] = (color 880 - + ((i & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i & 0xff00) 881 - * src_alpha >> 8 & 0xff00)); 882 - } while (--loops > 0); 883 - } 884 - } 885 - } else { 886 - int col_off = (grad - color_index) / (end_x - start_x); 887 - loops = end_x - start_x; 888 - if (alpha == 0) { 889 - do { 890 - dest[dest_off++] = hsl2rgb[color_index >> 8]; 891 - color_index += col_off; 892 - } while (--loops > 0); 893 - } else { 894 - int src_alpha = alpha; 895 - int dest_alpha = 256 - alpha; 896 - do { 897 - color = hsl2rgb[color_index >> 8]; 898 - color_index += col_off; 899 - color = (((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) 900 - * dest_alpha >> 8 & 0xff00)); 901 - int i = dest[dest_off]; 902 - dest[dest_off++] = (color 903 - + ((i & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((i & 0xff00) 904 - * src_alpha >> 8 & 0xff00)); 905 - } while (--loops > 0); 906 - } 907 - } 908 - } 909 - } 910 - 911 - // public static void drawShadedLine(int[] ai, int i, int l, int i1, int j1, int k1, int j, int k) { 912 - // if (notTextured) { 913 - // int l1; 914 - // if (restrict_edges) { 915 - // if (i1 - l > 3) 916 - // l1 = (k1 - j1) / (i1 - l); 917 - // else 918 - // l1 = 0; 919 - // if (i1 > Rasterizer.viewportRx) 920 - // i1 = Rasterizer.viewportRx; 921 - // if (l < 0) { 922 - // j1 -= l * l1; 923 - // l = 0; 924 - // } 925 - // if (l >= i1) 926 - // return; 927 - // i += l; 928 - // k = i1 - l >> 2; 929 - // l1 <<= 2; 930 - // } else { 931 - // if (l >= i1) 932 - // return; 933 - // i += l; 934 - // k = i1 - l >> 2; 935 - // if (k > 0) 936 - // l1 = (k1 - j1) * shadowDecay[k] >> 15; 937 - // else 938 - // l1 = 0; 939 - // } 940 - // if (alpha == 0) { 941 - // while (--k >= 0) { 942 - // j = hsl2rgb[j1 >> 8]; 943 - // j1 += l1; 944 - // ai[i++] = j; 945 - // ai[i++] = j; 946 - // ai[i++] = j; 947 - // ai[i++] = j; 948 - // } 949 - // k = i1 - l & 3; 950 - // if (k > 0) { 951 - // j = hsl2rgb[j1 >> 8]; 952 - // do 953 - // ai[i++] = j; 954 - // while (--k > 0); 955 - // return; 956 - // } 957 - // } else { 958 - // int j2 = alpha; 959 - // int l2 = 256 - alpha; 960 - // while (--k >= 0) { 961 - // j = hsl2rgb[j1 >> 8]; 962 - // j1 += l1; 963 - // j = ((j & 0xff00ff) * l2 >> 8 & 0xff00ff) + ((j & 0xff00) * l2 >> 8 & 0xff00); 964 - // ai[i++] = j + ((ai[i] & 0xff00ff) * j2 >> 8 & 0xff00ff) + ((ai[i] & 0xff00) * j2 >> 8 & 0xff00); 965 - // ai[i++] = j + ((ai[i] & 0xff00ff) * j2 >> 8 & 0xff00ff) + ((ai[i] & 0xff00) * j2 >> 8 & 0xff00); 966 - // ai[i++] = j + ((ai[i] & 0xff00ff) * j2 >> 8 & 0xff00ff) + ((ai[i] & 0xff00) * j2 >> 8 & 0xff00); 967 - // ai[i++] = j + ((ai[i] & 0xff00ff) * j2 >> 8 & 0xff00ff) + ((ai[i] & 0xff00) * j2 >> 8 & 0xff00); 968 - // } 969 - // k = i1 - l & 3; 970 - // if (k > 0) { 971 - // j = hsl2rgb[j1 >> 8]; 972 - // j = ((j & 0xff00ff) * l2 >> 8 & 0xff00ff) + ((j & 0xff00) * l2 >> 8 & 0xff00); 973 - // do 974 - // ai[i++] = j + ((ai[i] & 0xff00ff) * j2 >> 8 & 0xff00ff) + ((ai[i] & 0xff00) * j2 >> 8 & 0xff00); 975 - // while (--k > 0); 976 - // } 977 - // } 978 - // return; 979 - // } 980 - // if (l >= i1) 981 - // return; 982 - // int i2 = (k1 - j1) / (i1 - l); 983 - // if (restrict_edges) { 984 - // if (i1 > Rasterizer.viewportRx) 985 - // i1 = Rasterizer.viewportRx; 986 - // if (l < 0) { 987 - // j1 -= l * i2; 988 - // l = 0; 989 - // } 990 - // if (l >= i1) 991 - // return; 992 - // } 993 - // i += l; 994 - // k = i1 - l; 995 - // if (alpha == 0) { 996 - // do { 997 - // ai[i++] = hsl2rgb[j1 >> 8]; 998 - // j1 += i2; 999 - // } while (--k > 0); 1000 - // return; 1001 - // } 1002 - // int k2 = alpha; 1003 - // int i3 = 256 - alpha; 1004 - // do { 1005 - // j = hsl2rgb[j1 >> 8]; 1006 - // j1 += i2; 1007 - // j = ((j & 0xff00ff) * i3 >> 8 & 0xff00ff) + ((j & 0xff00) * i3 >> 8 & 0xff00); 1008 - // ai[i++] = j + ((ai[i] & 0xff00ff) * k2 >> 8 & 0xff00ff) + ((ai[i] & 0xff00) * k2 >> 8 & 0xff00); 1009 - // } while (--k > 0); 1010 - // } 1011 - 1012 - public static void drawFlatTriangle(int y_a, int y_b, int y_c, int x_a, int x_b, int x_c, int color) { 1013 - int x_a_off = 0; 1014 - if (y_b != y_a) { 1015 - x_a_off = (x_b - x_a << 16) / (y_b - y_a); 1016 - } 1017 - int x_b_off = 0; 1018 - if (y_c != y_b) { 1019 - x_b_off = (x_c - x_b << 16) / (y_c - y_b); 1020 - } 1021 - int x_c_off = 0; 1022 - if (y_c != y_a) { 1023 - x_c_off = (x_a - x_c << 16) / (y_a - y_c); 1024 - } 1025 - if (y_a <= y_b && y_a <= y_c) { 1026 - if (y_a >= bottomY) { 1027 - return; 1028 - } 1029 - if (y_b > bottomY) { 1030 - y_b = bottomY; 1031 - } 1032 - if (y_c > bottomY) { 1033 - y_c = bottomY; 1034 - } 1035 - if (y_b < y_c) { 1036 - x_c = x_a <<= 16; 1037 - if (y_a < 0) { 1038 - x_c -= x_c_off * y_a; 1039 - x_a -= x_a_off * y_a; 1040 - y_a = 0; 1041 - } 1042 - x_b <<= 16; 1043 - if (y_b < 0) { 1044 - x_b -= x_b_off * y_b; 1045 - y_b = 0; 1046 - } 1047 - if (y_a != y_b && x_c_off < x_a_off || y_a == y_b && x_c_off > x_b_off) { 1048 - y_c -= y_b; 1049 - y_b -= y_a; 1050 - for (y_a = lineOffsets[y_a]; --y_b >= 0; y_a += width) { 1051 - drawScanLine(pixels, y_a, color, x_c >> 16, x_a >> 16); 1052 - x_c += x_c_off; 1053 - x_a += x_a_off; 1054 - } 1055 - 1056 - while (--y_c >= 0) { 1057 - drawScanLine(pixels, y_a, color, x_c >> 16, x_b >> 16); 1058 - x_c += x_c_off; 1059 - x_b += x_b_off; 1060 - y_a += width; 1061 - } 1062 - return; 1063 - } 1064 - y_c -= y_b; 1065 - y_b -= y_a; 1066 - for (y_a = lineOffsets[y_a]; --y_b >= 0; y_a += width) { 1067 - drawScanLine(pixels, y_a, color, x_a >> 16, x_c >> 16); 1068 - x_c += x_c_off; 1069 - x_a += x_a_off; 1070 - } 1071 - 1072 - while (--y_c >= 0) { 1073 - drawScanLine(pixels, y_a, color, x_b >> 16, x_c >> 16); 1074 - x_c += x_c_off; 1075 - x_b += x_b_off; 1076 - y_a += width; 1077 - } 1078 - return; 1079 - } 1080 - x_b = x_a <<= 16; 1081 - if (y_a < 0) { 1082 - x_b -= x_c_off * y_a; 1083 - x_a -= x_a_off * y_a; 1084 - y_a = 0; 1085 - } 1086 - x_c <<= 16; 1087 - if (y_c < 0) { 1088 - x_c -= x_b_off * y_c; 1089 - y_c = 0; 1090 - } 1091 - if (y_a != y_c && x_c_off < x_a_off || y_a == y_c && x_b_off > x_a_off) { 1092 - y_b -= y_c; 1093 - y_c -= y_a; 1094 - for (y_a = lineOffsets[y_a]; --y_c >= 0; y_a += width) { 1095 - drawScanLine(pixels, y_a, color, x_b >> 16, x_a >> 16); 1096 - x_b += x_c_off; 1097 - x_a += x_a_off; 1098 - } 1099 - 1100 - while (--y_b >= 0) { 1101 - drawScanLine(pixels, y_a, color, x_c >> 16, x_a >> 16); 1102 - x_c += x_b_off; 1103 - x_a += x_a_off; 1104 - y_a += width; 1105 - } 1106 - return; 1107 - } 1108 - y_b -= y_c; 1109 - y_c -= y_a; 1110 - for (y_a = lineOffsets[y_a]; --y_c >= 0; y_a += width) { 1111 - drawScanLine(pixels, y_a, color, x_a >> 16, x_b >> 16); 1112 - x_b += x_c_off; 1113 - x_a += x_a_off; 1114 - } 1115 - 1116 - while (--y_b >= 0) { 1117 - drawScanLine(pixels, y_a, color, x_a >> 16, x_c >> 16); 1118 - x_c += x_b_off; 1119 - x_a += x_a_off; 1120 - y_a += width; 1121 - } 1122 - return; 1123 - } 1124 - if (y_b <= y_c) { 1125 - if (y_b >= bottomY) { 1126 - return; 1127 - } 1128 - if (y_c > bottomY) { 1129 - y_c = bottomY; 1130 - } 1131 - if (y_a > bottomY) { 1132 - y_a = bottomY; 1133 - } 1134 - if (y_c < y_a) { 1135 - x_a = x_b <<= 16; 1136 - if (y_b < 0) { 1137 - x_a -= x_a_off * y_b; 1138 - x_b -= x_b_off * y_b; 1139 - y_b = 0; 1140 - } 1141 - x_c <<= 16; 1142 - if (y_c < 0) { 1143 - x_c -= x_c_off * y_c; 1144 - y_c = 0; 1145 - } 1146 - if (y_b != y_c && x_a_off < x_b_off || y_b == y_c && x_a_off > x_c_off) { 1147 - y_a -= y_c; 1148 - y_c -= y_b; 1149 - for (y_b = lineOffsets[y_b]; --y_c >= 0; y_b += width) { 1150 - drawScanLine(pixels, y_b, color, x_a >> 16, x_b >> 16); 1151 - x_a += x_a_off; 1152 - x_b += x_b_off; 1153 - } 1154 - 1155 - while (--y_a >= 0) { 1156 - drawScanLine(pixels, y_b, color, x_a >> 16, x_c >> 16); 1157 - x_a += x_a_off; 1158 - x_c += x_c_off; 1159 - y_b += width; 1160 - } 1161 - return; 1162 - } 1163 - y_a -= y_c; 1164 - y_c -= y_b; 1165 - for (y_b = lineOffsets[y_b]; --y_c >= 0; y_b += width) { 1166 - drawScanLine(pixels, y_b, color, x_b >> 16, x_a >> 16); 1167 - x_a += x_a_off; 1168 - x_b += x_b_off; 1169 - } 1170 - 1171 - while (--y_a >= 0) { 1172 - drawScanLine(pixels, y_b, color, x_c >> 16, x_a >> 16); 1173 - x_a += x_a_off; 1174 - x_c += x_c_off; 1175 - y_b += width; 1176 - } 1177 - return; 1178 - } 1179 - x_c = x_b <<= 16; 1180 - if (y_b < 0) { 1181 - x_c -= x_a_off * y_b; 1182 - x_b -= x_b_off * y_b; 1183 - y_b = 0; 1184 - } 1185 - x_a <<= 16; 1186 - if (y_a < 0) { 1187 - x_a -= x_c_off * y_a; 1188 - y_a = 0; 1189 - } 1190 - if (x_a_off < x_b_off) { 1191 - y_c -= y_a; 1192 - y_a -= y_b; 1193 - for (y_b = lineOffsets[y_b]; --y_a >= 0; y_b += width) { 1194 - drawScanLine(pixels, y_b, color, x_c >> 16, x_b >> 16); 1195 - x_c += x_a_off; 1196 - x_b += x_b_off; 1197 - } 1198 - 1199 - while (--y_c >= 0) { 1200 - drawScanLine(pixels, y_b, color, x_a >> 16, x_b >> 16); 1201 - x_a += x_c_off; 1202 - x_b += x_b_off; 1203 - y_b += width; 1204 - } 1205 - return; 1206 - } 1207 - y_c -= y_a; 1208 - y_a -= y_b; 1209 - for (y_b = lineOffsets[y_b]; --y_a >= 0; y_b += width) { 1210 - drawScanLine(pixels, y_b, color, x_b >> 16, x_c >> 16); 1211 - x_c += x_a_off; 1212 - x_b += x_b_off; 1213 - } 1214 - 1215 - while (--y_c >= 0) { 1216 - drawScanLine(pixels, y_b, color, x_b >> 16, x_a >> 16); 1217 - x_a += x_c_off; 1218 - x_b += x_b_off; 1219 - y_b += width; 1220 - } 1221 - return; 1222 - } 1223 - if (y_c >= bottomY) { 1224 - return; 1225 - } 1226 - if (y_a > bottomY) { 1227 - y_a = bottomY; 1228 - } 1229 - if (y_b > bottomY) { 1230 - y_b = bottomY; 1231 - } 1232 - if (y_a < y_b) { 1233 - x_b = x_c <<= 16; 1234 - if (y_c < 0) { 1235 - x_b -= x_b_off * y_c; 1236 - x_c -= x_c_off * y_c; 1237 - y_c = 0; 1238 - } 1239 - x_a <<= 16; 1240 - if (y_a < 0) { 1241 - x_a -= x_a_off * y_a; 1242 - y_a = 0; 1243 - } 1244 - if (x_b_off < x_c_off) { 1245 - y_b -= y_a; 1246 - y_a -= y_c; 1247 - for (y_c = lineOffsets[y_c]; --y_a >= 0; y_c += width) { 1248 - drawScanLine(pixels, y_c, color, x_b >> 16, x_c >> 16); 1249 - x_b += x_b_off; 1250 - x_c += x_c_off; 1251 - } 1252 - 1253 - while (--y_b >= 0) { 1254 - drawScanLine(pixels, y_c, color, x_b >> 16, x_a >> 16); 1255 - x_b += x_b_off; 1256 - x_a += x_a_off; 1257 - y_c += width; 1258 - } 1259 - return; 1260 - } 1261 - y_b -= y_a; 1262 - y_a -= y_c; 1263 - for (y_c = lineOffsets[y_c]; --y_a >= 0; y_c += width) { 1264 - drawScanLine(pixels, y_c, color, x_c >> 16, x_b >> 16); 1265 - x_b += x_b_off; 1266 - x_c += x_c_off; 1267 - } 1268 - 1269 - while (--y_b >= 0) { 1270 - drawScanLine(pixels, y_c, color, x_a >> 16, x_b >> 16); 1271 - x_b += x_b_off; 1272 - x_a += x_a_off; 1273 - y_c += width; 1274 - } 1275 - return; 1276 - } 1277 - x_a = x_c <<= 16; 1278 - if (y_c < 0) { 1279 - x_a -= x_b_off * y_c; 1280 - x_c -= x_c_off * y_c; 1281 - y_c = 0; 1282 - } 1283 - x_b <<= 16; 1284 - if (y_b < 0) { 1285 - x_b -= x_a_off * y_b; 1286 - y_b = 0; 1287 - } 1288 - if (x_b_off < x_c_off) { 1289 - y_a -= y_b; 1290 - y_b -= y_c; 1291 - for (y_c = lineOffsets[y_c]; --y_b >= 0; y_c += width) { 1292 - drawScanLine(pixels, y_c, color, x_a >> 16, x_c >> 16); 1293 - x_a += x_b_off; 1294 - x_c += x_c_off; 1295 - } 1296 - 1297 - while (--y_a >= 0) { 1298 - drawScanLine(pixels, y_c, color, x_b >> 16, x_c >> 16); 1299 - x_b += x_a_off; 1300 - x_c += x_c_off; 1301 - y_c += width; 1302 - } 1303 - return; 1304 - } 1305 - y_a -= y_b; 1306 - y_b -= y_c; 1307 - for (y_c = lineOffsets[y_c]; --y_b >= 0; y_c += width) { 1308 - drawScanLine(pixels, y_c, color, x_c >> 16, x_a >> 16); 1309 - x_a += x_b_off; 1310 - x_c += x_c_off; 1311 - } 1312 - 1313 - while (--y_a >= 0) { 1314 - drawScanLine(pixels, y_c, color, x_c >> 16, x_b >> 16); 1315 - x_b += x_a_off; 1316 - x_c += x_c_off; 1317 - y_c += width; 1318 - } 1319 - } 1320 - 1321 - 1322 - public static void drawScanLine(int[] dest, int dest_off, int loops, int start_x, int end_x) { 1323 - int rgb;//was parameter 1324 - if (restrict_edges) { 1325 - if (end_x > viewportRx) { 1326 - end_x = viewportRx; 1327 - } 1328 - if (start_x < 0) { 1329 - start_x = 0; 1330 - } 1331 - } 1332 - if (start_x >= end_x) { 1333 - return; 1334 - } 1335 - dest_off += start_x; 1336 - rgb = end_x - start_x >> 2; 1337 - if (alpha == 0) { 1338 - while (--rgb >= 0) { 1339 - dest[dest_off++] = loops; 1340 - dest[dest_off++] = loops; 1341 - dest[dest_off++] = loops; 1342 - dest[dest_off++] = loops; 1343 - } 1344 - for (rgb = end_x - start_x & 3; --rgb >= 0; ) { 1345 - dest[dest_off++] = loops; 1346 - } 1347 - 1348 - return; 1349 - } 1350 - int dest_alpha = alpha; 1351 - int src_alpha = 256 - alpha; 1352 - loops = ((loops & 0xff00ff) * src_alpha >> 8 & 0xff00ff) + ((loops & 0xff00) * src_alpha >> 8 & 0xff00); 1353 - while (--rgb >= 0) {//alpha channel fix 1354 - dest[dest_off] = loops + ((dest[dest_off] & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((dest[dest_off] & 0xff00) * dest_alpha >> 8 & 0xff00); 1355 - dest_off++; 1356 - dest[dest_off] = loops + ((dest[dest_off] & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((dest[dest_off] & 0xff00) * dest_alpha >> 8 & 0xff00); 1357 - dest_off++; 1358 - dest[dest_off] = loops + ((dest[dest_off] & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((dest[dest_off] & 0xff00) * dest_alpha >> 8 & 0xff00); 1359 - dest_off++; 1360 - dest[dest_off] = loops + ((dest[dest_off] & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((dest[dest_off] & 0xff00) * dest_alpha >> 8 & 0xff00); 1361 - dest_off++; 1362 - } 1363 - for (rgb = end_x - start_x & 3; --rgb >= 0; ) { 1364 - dest[dest_off] = loops + ((dest[dest_off] & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((dest[dest_off] & 0xff00) * dest_alpha >> 8 & 0xff00); 1365 - dest_off++; 1366 - } 1367 - 1368 - } 1369 - 1370 - public static void drawTexturedTriangle(int y_a, int y_b, int y_c, int x_a, int x_b, int x_c, int grad_a, int grad_b, int grad_c, int Px, int Mx, 1371 - int Nx, int Pz, int Mz, int Nz, int Py, int My, int Ny, int t_id) { 1372 - int texture[] = getTexturePixels(t_id); 1373 - opaque = !textureIsTransparent[t_id]; 1374 - Mx = Px - Mx; 1375 - Mz = Pz - Mz; 1376 - My = Py - My; 1377 - Nx -= Px; 1378 - Nz -= Pz; 1379 - Ny -= Py; 1380 - int Oa = Nx * Pz - Nz * Px << 14; 1381 - int Ha = Nz * Py - Ny * Pz << 8; 1382 - int Va = Ny * Px - Nx * Py << 5; 1383 - int Ob = Mx * Pz - Mz * Px << 14; 1384 - int Hb = Mz * Py - My * Pz << 8; 1385 - int Vb = My * Px - Mx * Py << 5; 1386 - int Oc = Mz * Nx - Mx * Nz << 14; 1387 - int Hc = My * Nz - Mz * Ny << 8; 1388 - int Vc = Mx * Ny - My * Nx << 5; 1389 - int x_a_off = 0; 1390 - int grad_a_off = 0; 1391 - if (y_b != y_a) { 1392 - x_a_off = (x_b - x_a << 16) / (y_b - y_a); 1393 - grad_a_off = (grad_b - grad_a << 16) / (y_b - y_a); 1394 - } 1395 - int x_b_off = 0; 1396 - int grad_b_off = 0; 1397 - if (y_c != y_b) { 1398 - x_b_off = (x_c - x_b << 16) / (y_c - y_b); 1399 - grad_b_off = (grad_c - grad_b << 16) / (y_c - y_b); 1400 - } 1401 - int x_c_off = 0; 1402 - int grad_c_off = 0; 1403 - if (y_c != y_a) { 1404 - x_c_off = (x_a - x_c << 16) / (y_a - y_c); 1405 - grad_c_off = (grad_a - grad_c << 16) / (y_a - y_c); 1406 - } 1407 - if (y_a <= y_b && y_a <= y_c) { 1408 - if (y_a >= bottomY) { 1409 - return; 1410 - } 1411 - if (y_b > bottomY) { 1412 - y_b = bottomY; 1413 - } 1414 - if (y_c > bottomY) { 1415 - y_c = bottomY; 1416 - } 1417 - if (y_b < y_c) { 1418 - x_c = x_a <<= 16; 1419 - grad_c = grad_a <<= 16; 1420 - if (y_a < 0) { 1421 - x_c -= x_c_off * y_a; 1422 - x_a -= x_a_off * y_a; 1423 - grad_c -= grad_c_off * y_a; 1424 - grad_a -= grad_a_off * y_a; 1425 - y_a = 0; 1426 - } 1427 - x_b <<= 16; 1428 - grad_b <<= 16; 1429 - if (y_b < 0) { 1430 - x_b -= x_b_off * y_b; 1431 - grad_b -= grad_b_off * y_b; 1432 - y_b = 0; 1433 - } 1434 - int jA = y_a - center_y; 1435 - Oa += Va * jA; 1436 - Ob += Vb * jA; 1437 - Oc += Vc * jA; 1438 - if (y_a != y_b && x_c_off < x_a_off || y_a == y_b && x_c_off > x_b_off) { 1439 - y_c -= y_b; 1440 - y_b -= y_a; 1441 - y_a = lineOffsets[y_a]; 1442 - while (--y_b >= 0) { 1443 - drawTexturedLine(pixels, texture, y_a, x_c >> 16, x_a >> 16, grad_c >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1444 - x_c += x_c_off; 1445 - x_a += x_a_off; 1446 - grad_c += grad_c_off; 1447 - grad_a += grad_a_off; 1448 - y_a += width; 1449 - Oa += Va; 1450 - Ob += Vb; 1451 - Oc += Vc; 1452 - } 1453 - while (--y_c >= 0) { 1454 - drawTexturedLine(pixels, texture, y_a, x_c >> 16, x_b >> 16, grad_c >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1455 - x_c += x_c_off; 1456 - x_b += x_b_off; 1457 - grad_c += grad_c_off; 1458 - grad_b += grad_b_off; 1459 - y_a += width; 1460 - Oa += Va; 1461 - Ob += Vb; 1462 - Oc += Vc; 1463 - } 1464 - return; 1465 - } 1466 - y_c -= y_b; 1467 - y_b -= y_a; 1468 - y_a = lineOffsets[y_a]; 1469 - while (--y_b >= 0) { 1470 - drawTexturedLine(pixels, texture, y_a, x_a >> 16, x_c >> 16, grad_a >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1471 - x_c += x_c_off; 1472 - x_a += x_a_off; 1473 - grad_c += grad_c_off; 1474 - grad_a += grad_a_off; 1475 - y_a += width; 1476 - Oa += Va; 1477 - Ob += Vb; 1478 - Oc += Vc; 1479 - } 1480 - while (--y_c >= 0) { 1481 - drawTexturedLine(pixels, texture, y_a, x_b >> 16, x_c >> 16, grad_b >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1482 - x_c += x_c_off; 1483 - x_b += x_b_off; 1484 - grad_c += grad_c_off; 1485 - grad_b += grad_b_off; 1486 - y_a += width; 1487 - Oa += Va; 1488 - Ob += Vb; 1489 - Oc += Vc; 1490 - } 1491 - return; 1492 - } 1493 - x_b = x_a <<= 16; 1494 - grad_b = grad_a <<= 16; 1495 - if (y_a < 0) { 1496 - x_b -= x_c_off * y_a; 1497 - x_a -= x_a_off * y_a; 1498 - grad_b -= grad_c_off * y_a; 1499 - grad_a -= grad_a_off * y_a; 1500 - y_a = 0; 1501 - } 1502 - x_c <<= 16; 1503 - grad_c <<= 16; 1504 - if (y_c < 0) { 1505 - x_c -= x_b_off * y_c; 1506 - grad_c -= grad_b_off * y_c; 1507 - y_c = 0; 1508 - } 1509 - int l8 = y_a - center_y; 1510 - Oa += Va * l8; 1511 - Ob += Vb * l8; 1512 - Oc += Vc * l8; 1513 - if (y_a != y_c && x_c_off < x_a_off || y_a == y_c && x_b_off > x_a_off) { 1514 - y_b -= y_c; 1515 - y_c -= y_a; 1516 - y_a = lineOffsets[y_a]; 1517 - while (--y_c >= 0) { 1518 - drawTexturedLine(pixels, texture, y_a, x_b >> 16, x_a >> 16, grad_b >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1519 - x_b += x_c_off; 1520 - x_a += x_a_off; 1521 - grad_b += grad_c_off; 1522 - grad_a += grad_a_off; 1523 - y_a += width; 1524 - Oa += Va; 1525 - Ob += Vb; 1526 - Oc += Vc; 1527 - } 1528 - while (--y_b >= 0) { 1529 - drawTexturedLine(pixels, texture, y_a, x_c >> 16, x_a >> 16, grad_c >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1530 - x_c += x_b_off; 1531 - x_a += x_a_off; 1532 - grad_c += grad_b_off; 1533 - grad_a += grad_a_off; 1534 - y_a += width; 1535 - Oa += Va; 1536 - Ob += Vb; 1537 - Oc += Vc; 1538 - } 1539 - return; 1540 - } 1541 - y_b -= y_c; 1542 - y_c -= y_a; 1543 - y_a = lineOffsets[y_a]; 1544 - while (--y_c >= 0) { 1545 - drawTexturedLine(pixels, texture, y_a, x_a >> 16, x_b >> 16, grad_a >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1546 - x_b += x_c_off; 1547 - x_a += x_a_off; 1548 - grad_b += grad_c_off; 1549 - grad_a += grad_a_off; 1550 - y_a += width; 1551 - Oa += Va; 1552 - Ob += Vb; 1553 - Oc += Vc; 1554 - } 1555 - while (--y_b >= 0) { 1556 - drawTexturedLine(pixels, texture, y_a, x_a >> 16, x_c >> 16, grad_a >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1557 - x_c += x_b_off; 1558 - x_a += x_a_off; 1559 - grad_c += grad_b_off; 1560 - grad_a += grad_a_off; 1561 - y_a += width; 1562 - Oa += Va; 1563 - Ob += Vb; 1564 - Oc += Vc; 1565 - } 1566 - return; 1567 - } 1568 - if (y_b <= y_c) { 1569 - if (y_b >= bottomY) { 1570 - return; 1571 - } 1572 - if (y_c > bottomY) { 1573 - y_c = bottomY; 1574 - } 1575 - if (y_a > bottomY) { 1576 - y_a = bottomY; 1577 - } 1578 - if (y_c < y_a) { 1579 - x_a = x_b <<= 16; 1580 - grad_a = grad_b <<= 16; 1581 - if (y_b < 0) { 1582 - x_a -= x_a_off * y_b; 1583 - x_b -= x_b_off * y_b; 1584 - grad_a -= grad_a_off * y_b; 1585 - grad_b -= grad_b_off * y_b; 1586 - y_b = 0; 1587 - } 1588 - x_c <<= 16; 1589 - grad_c <<= 16; 1590 - if (y_c < 0) { 1591 - x_c -= x_c_off * y_c; 1592 - grad_c -= grad_c_off * y_c; 1593 - y_c = 0; 1594 - } 1595 - int i9 = y_b - center_y; 1596 - Oa += Va * i9; 1597 - Ob += Vb * i9; 1598 - Oc += Vc * i9; 1599 - if (y_b != y_c && x_a_off < x_b_off || y_b == y_c && x_a_off > x_c_off) { 1600 - y_a -= y_c; 1601 - y_c -= y_b; 1602 - y_b = lineOffsets[y_b]; 1603 - while (--y_c >= 0) { 1604 - drawTexturedLine(pixels, texture, y_b, x_a >> 16, x_b >> 16, grad_a >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1605 - x_a += x_a_off; 1606 - x_b += x_b_off; 1607 - grad_a += grad_a_off; 1608 - grad_b += grad_b_off; 1609 - y_b += width; 1610 - Oa += Va; 1611 - Ob += Vb; 1612 - Oc += Vc; 1613 - } 1614 - while (--y_a >= 0) { 1615 - drawTexturedLine(pixels, texture, y_b, x_a >> 16, x_c >> 16, grad_a >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1616 - x_a += x_a_off; 1617 - x_c += x_c_off; 1618 - grad_a += grad_a_off; 1619 - grad_c += grad_c_off; 1620 - y_b += width; 1621 - Oa += Va; 1622 - Ob += Vb; 1623 - Oc += Vc; 1624 - } 1625 - return; 1626 - } 1627 - y_a -= y_c; 1628 - y_c -= y_b; 1629 - y_b = lineOffsets[y_b]; 1630 - while (--y_c >= 0) { 1631 - drawTexturedLine(pixels, texture, y_b, x_b >> 16, x_a >> 16, grad_b >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1632 - x_a += x_a_off; 1633 - x_b += x_b_off; 1634 - grad_a += grad_a_off; 1635 - grad_b += grad_b_off; 1636 - y_b += width; 1637 - Oa += Va; 1638 - Ob += Vb; 1639 - Oc += Vc; 1640 - } 1641 - while (--y_a >= 0) { 1642 - drawTexturedLine(pixels, texture, y_b, x_c >> 16, x_a >> 16, grad_c >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1643 - x_a += x_a_off; 1644 - x_c += x_c_off; 1645 - grad_a += grad_a_off; 1646 - grad_c += grad_c_off; 1647 - y_b += width; 1648 - Oa += Va; 1649 - Ob += Vb; 1650 - Oc += Vc; 1651 - } 1652 - return; 1653 - } 1654 - x_c = x_b <<= 16; 1655 - grad_c = grad_b <<= 16; 1656 - if (y_b < 0) { 1657 - x_c -= x_a_off * y_b; 1658 - x_b -= x_b_off * y_b; 1659 - grad_c -= grad_a_off * y_b; 1660 - grad_b -= grad_b_off * y_b; 1661 - y_b = 0; 1662 - } 1663 - x_a <<= 16; 1664 - grad_a <<= 16; 1665 - if (y_a < 0) { 1666 - x_a -= x_c_off * y_a; 1667 - grad_a -= grad_c_off * y_a; 1668 - y_a = 0; 1669 - } 1670 - int j9 = y_b - center_y; 1671 - Oa += Va * j9; 1672 - Ob += Vb * j9; 1673 - Oc += Vc * j9; 1674 - if (x_a_off < x_b_off) { 1675 - y_c -= y_a; 1676 - y_a -= y_b; 1677 - y_b = lineOffsets[y_b]; 1678 - while (--y_a >= 0) { 1679 - drawTexturedLine(pixels, texture, y_b, x_c >> 16, x_b >> 16, grad_c >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1680 - x_c += x_a_off; 1681 - x_b += x_b_off; 1682 - grad_c += grad_a_off; 1683 - grad_b += grad_b_off; 1684 - y_b += width; 1685 - Oa += Va; 1686 - Ob += Vb; 1687 - Oc += Vc; 1688 - } 1689 - while (--y_c >= 0) { 1690 - drawTexturedLine(pixels, texture, y_b, x_a >> 16, x_b >> 16, grad_a >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1691 - x_a += x_c_off; 1692 - x_b += x_b_off; 1693 - grad_a += grad_c_off; 1694 - grad_b += grad_b_off; 1695 - y_b += width; 1696 - Oa += Va; 1697 - Ob += Vb; 1698 - Oc += Vc; 1699 - } 1700 - return; 1701 - } 1702 - y_c -= y_a; 1703 - y_a -= y_b; 1704 - y_b = lineOffsets[y_b]; 1705 - while (--y_a >= 0) { 1706 - drawTexturedLine(pixels, texture, y_b, x_b >> 16, x_c >> 16, grad_b >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1707 - x_c += x_a_off; 1708 - x_b += x_b_off; 1709 - grad_c += grad_a_off; 1710 - grad_b += grad_b_off; 1711 - y_b += width; 1712 - Oa += Va; 1713 - Ob += Vb; 1714 - Oc += Vc; 1715 - } 1716 - while (--y_c >= 0) { 1717 - drawTexturedLine(pixels, texture, y_b, x_b >> 16, x_a >> 16, grad_b >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1718 - x_a += x_c_off; 1719 - x_b += x_b_off; 1720 - grad_a += grad_c_off; 1721 - grad_b += grad_b_off; 1722 - y_b += width; 1723 - Oa += Va; 1724 - Ob += Vb; 1725 - Oc += Vc; 1726 - } 1727 - return; 1728 - } 1729 - if (y_c >= bottomY) { 1730 - return; 1731 - } 1732 - if (y_a > bottomY) { 1733 - y_a = bottomY; 1734 - } 1735 - if (y_b > bottomY) { 1736 - y_b = bottomY; 1737 - } 1738 - if (y_a < y_b) { 1739 - x_b = x_c <<= 16; 1740 - grad_b = grad_c <<= 16; 1741 - if (y_c < 0) { 1742 - x_b -= x_b_off * y_c; 1743 - x_c -= x_c_off * y_c; 1744 - grad_b -= grad_b_off * y_c; 1745 - grad_c -= grad_c_off * y_c; 1746 - y_c = 0; 1747 - } 1748 - x_a <<= 16; 1749 - grad_a <<= 16; 1750 - if (y_a < 0) { 1751 - x_a -= x_a_off * y_a; 1752 - grad_a -= grad_a_off * y_a; 1753 - y_a = 0; 1754 - } 1755 - int k9 = y_c - center_y; 1756 - Oa += Va * k9; 1757 - Ob += Vb * k9; 1758 - Oc += Vc * k9; 1759 - if (x_b_off < x_c_off) { 1760 - y_b -= y_a; 1761 - y_a -= y_c; 1762 - y_c = lineOffsets[y_c]; 1763 - while (--y_a >= 0) { 1764 - drawTexturedLine(pixels, texture, y_c, x_b >> 16, x_c >> 16, grad_b >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1765 - x_b += x_b_off; 1766 - x_c += x_c_off; 1767 - grad_b += grad_b_off; 1768 - grad_c += grad_c_off; 1769 - y_c += width; 1770 - Oa += Va; 1771 - Ob += Vb; 1772 - Oc += Vc; 1773 - } 1774 - while (--y_b >= 0) { 1775 - drawTexturedLine(pixels, texture, y_c, x_b >> 16, x_a >> 16, grad_b >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1776 - x_b += x_b_off; 1777 - x_a += x_a_off; 1778 - grad_b += grad_b_off; 1779 - grad_a += grad_a_off; 1780 - y_c += width; 1781 - Oa += Va; 1782 - Ob += Vb; 1783 - Oc += Vc; 1784 - } 1785 - return; 1786 - } 1787 - y_b -= y_a; 1788 - y_a -= y_c; 1789 - y_c = lineOffsets[y_c]; 1790 - while (--y_a >= 0) { 1791 - drawTexturedLine(pixels, texture, y_c, x_c >> 16, x_b >> 16, grad_c >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1792 - x_b += x_b_off; 1793 - x_c += x_c_off; 1794 - grad_b += grad_b_off; 1795 - grad_c += grad_c_off; 1796 - y_c += width; 1797 - Oa += Va; 1798 - Ob += Vb; 1799 - Oc += Vc; 1800 - } 1801 - while (--y_b >= 0) { 1802 - drawTexturedLine(pixels, texture, y_c, x_a >> 16, x_b >> 16, grad_a >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1803 - x_b += x_b_off; 1804 - x_a += x_a_off; 1805 - grad_b += grad_b_off; 1806 - grad_a += grad_a_off; 1807 - y_c += width; 1808 - Oa += Va; 1809 - Ob += Vb; 1810 - Oc += Vc; 1811 - } 1812 - return; 1813 - } 1814 - x_a = x_c <<= 16; 1815 - grad_a = grad_c <<= 16; 1816 - if (y_c < 0) { 1817 - x_a -= x_b_off * y_c; 1818 - x_c -= x_c_off * y_c; 1819 - grad_a -= grad_b_off * y_c; 1820 - grad_c -= grad_c_off * y_c; 1821 - y_c = 0; 1822 - } 1823 - x_b <<= 16; 1824 - grad_b <<= 16; 1825 - if (y_b < 0) { 1826 - x_b -= x_a_off * y_b; 1827 - grad_b -= grad_a_off * y_b; 1828 - y_b = 0; 1829 - } 1830 - int l9 = y_c - center_y; 1831 - Oa += Va * l9; 1832 - Ob += Vb * l9; 1833 - Oc += Vc * l9; 1834 - if (x_b_off < x_c_off) { 1835 - y_a -= y_b; 1836 - y_b -= y_c; 1837 - y_c = lineOffsets[y_c]; 1838 - while (--y_b >= 0) { 1839 - drawTexturedLine(pixels, texture, y_c, x_a >> 16, x_c >> 16, grad_a >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1840 - x_a += x_b_off; 1841 - x_c += x_c_off; 1842 - grad_a += grad_b_off; 1843 - grad_c += grad_c_off; 1844 - y_c += width; 1845 - Oa += Va; 1846 - Ob += Vb; 1847 - Oc += Vc; 1848 - } 1849 - while (--y_a >= 0) { 1850 - drawTexturedLine(pixels, texture, y_c, x_b >> 16, x_c >> 16, grad_b >> 8, grad_c >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1851 - x_b += x_a_off; 1852 - x_c += x_c_off; 1853 - grad_b += grad_a_off; 1854 - grad_c += grad_c_off; 1855 - y_c += width; 1856 - Oa += Va; 1857 - Ob += Vb; 1858 - Oc += Vc; 1859 - } 1860 - return; 1861 - } 1862 - y_a -= y_b; 1863 - y_b -= y_c; 1864 - y_c = lineOffsets[y_c]; 1865 - while (--y_b >= 0) { 1866 - drawTexturedLine(pixels, texture, y_c, x_c >> 16, x_a >> 16, grad_c >> 8, grad_a >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1867 - x_a += x_b_off; 1868 - x_c += x_c_off; 1869 - grad_a += grad_b_off; 1870 - grad_c += grad_c_off; 1871 - y_c += width; 1872 - Oa += Va; 1873 - Ob += Vb; 1874 - Oc += Vc; 1875 - } 1876 - while (--y_a >= 0) { 1877 - drawTexturedLine(pixels, texture, y_c, x_c >> 16, x_b >> 16, grad_c >> 8, grad_b >> 8, Oa, Ob, Oc, Ha, Hb, Hc); 1878 - x_b += x_a_off; 1879 - x_c += x_c_off; 1880 - grad_b += grad_a_off; 1881 - grad_c += grad_c_off; 1882 - y_c += width; 1883 - Oa += Va; 1884 - Ob += Vb; 1885 - Oc += Vc; 1886 - } 1887 - } 1888 - 1889 - public static void drawTexturedLine(int dest[], int texture[], int dest_off, int start_x, int end_x, int shadeValue, 1890 - int gradient, int arg7, int arg8, int arg9, int arg10, int arg11, int arg12) { 1891 - int rgb = 0; 1892 - int loops = 0; 1893 - if (start_x >= end_x) 1894 - return; 1895 - int j3; 1896 - int k3; 1897 - if (restrict_edges) { 1898 - j3 = (gradient - shadeValue) / (end_x - start_x); 1899 - if (end_x > Rasterizer.viewportRx) 1900 - end_x = Rasterizer.viewportRx; 1901 - if (start_x < 0) { 1902 - shadeValue -= start_x * j3; 1903 - start_x = 0; 1904 - } 1905 - if (start_x >= end_x) 1906 - return; 1907 - k3 = end_x - start_x >> 3; 1908 - j3 <<= 12; 1909 - shadeValue <<= 9; 1910 - } else { 1911 - if (end_x - start_x > 7) { 1912 - k3 = end_x - start_x >> 3; 1913 - j3 = (gradient - shadeValue) * shadowDecay[k3] >> 6; 1914 - } else { 1915 - k3 = 0; 1916 - j3 = 0; 1917 - } 1918 - shadeValue <<= 9; 1919 - } 1920 - dest_off += start_x; 1921 - if (lowMemory) { 1922 - int i4 = 0; 1923 - int k4 = 0; 1924 - int k6 = start_x - Rasterizer3D.center_x; 1925 - arg7 += (arg10 >> 3) * k6; 1926 - arg8 += (arg11 >> 3) * k6; 1927 - arg9 += (arg12 >> 3) * k6; 1928 - int i5 = arg9 >> 12; 1929 - if (i5 != 0) { 1930 - rgb = arg7 / i5; 1931 - loops = arg8 / i5; 1932 - if (rgb < 0) 1933 - rgb = 0; 1934 - else if (rgb > 4032) 1935 - rgb = 4032; 1936 - } 1937 - arg7 += arg10; 1938 - arg8 += arg11; 1939 - arg9 += arg12; 1940 - i5 = arg9 >> 12; 1941 - if (i5 != 0) { 1942 - i4 = arg7 / i5; 1943 - k4 = arg8 / i5; 1944 - if (i4 < 7) 1945 - i4 = 7; 1946 - else if (i4 > 4032) 1947 - i4 = 4032; 1948 - } 1949 - int i7 = i4 - rgb >> 3; 1950 - int k7 = k4 - loops >> 3; 1951 - rgb += (shadeValue & 0x600000) >> 3; 1952 - int i8 = shadeValue >> 23; 1953 - if (opaque) { 1954 - while (k3-- > 0) { 1955 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1956 - rgb += i7; 1957 - loops += k7; 1958 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1959 - rgb += i7; 1960 - loops += k7; 1961 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1962 - rgb += i7; 1963 - loops += k7; 1964 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1965 - rgb += i7; 1966 - loops += k7; 1967 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1968 - rgb += i7; 1969 - loops += k7; 1970 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1971 - rgb += i7; 1972 - loops += k7; 1973 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1974 - rgb += i7; 1975 - loops += k7; 1976 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1977 - rgb = i4; 1978 - loops = k4; 1979 - arg7 += arg10; 1980 - arg8 += arg11; 1981 - arg9 += arg12; 1982 - int j5 = arg9 >> 12; 1983 - if (j5 != 0) { 1984 - i4 = arg7 / j5; 1985 - k4 = arg8 / j5; 1986 - if (i4 < 7) 1987 - i4 = 7; 1988 - else if (i4 > 4032) 1989 - i4 = 4032; 1990 - } 1991 - i7 = i4 - rgb >> 3; 1992 - k7 = k4 - loops >> 3; 1993 - shadeValue += j3; 1994 - rgb += (shadeValue & 0x600000) >> 3; 1995 - i8 = shadeValue >> 23; 1996 - } 1997 - for (k3 = end_x - start_x & 7; k3-- > 0; ) { 1998 - dest[dest_off++] = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8; 1999 - rgb += i7; 2000 - loops += k7; 2001 - } 2002 - 2003 - return; 2004 - } 2005 - while (k3-- > 0) { 2006 - int k8; 2007 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2008 - dest[dest_off] = k8; 2009 - dest_off++; 2010 - rgb += i7; 2011 - loops += k7; 2012 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2013 - dest[dest_off] = k8; 2014 - dest_off++; 2015 - rgb += i7; 2016 - loops += k7; 2017 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2018 - dest[dest_off] = k8; 2019 - dest_off++; 2020 - rgb += i7; 2021 - loops += k7; 2022 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2023 - dest[dest_off] = k8; 2024 - dest_off++; 2025 - rgb += i7; 2026 - loops += k7; 2027 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2028 - dest[dest_off] = k8; 2029 - dest_off++; 2030 - rgb += i7; 2031 - loops += k7; 2032 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2033 - dest[dest_off] = k8; 2034 - dest_off++; 2035 - rgb += i7; 2036 - loops += k7; 2037 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2038 - dest[dest_off] = k8; 2039 - dest_off++; 2040 - rgb += i7; 2041 - loops += k7; 2042 - if ((k8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2043 - dest[dest_off] = k8; 2044 - dest_off++; 2045 - rgb = i4; 2046 - loops = k4; 2047 - arg7 += arg10; 2048 - arg8 += arg11; 2049 - arg9 += arg12; 2050 - int k5 = arg9 >> 12; 2051 - if (k5 != 0) { 2052 - i4 = arg7 / k5; 2053 - k4 = arg8 / k5; 2054 - if (i4 < 7) 2055 - i4 = 7; 2056 - else if (i4 > 4032) 2057 - i4 = 4032; 2058 - } 2059 - i7 = i4 - rgb >> 3; 2060 - k7 = k4 - loops >> 3; 2061 - shadeValue += j3; 2062 - rgb += (shadeValue & 0x600000) >> 3; 2063 - i8 = shadeValue >> 23; 2064 - } 2065 - for (k3 = end_x - start_x & 7; k3-- > 0; ) { 2066 - int l8; 2067 - if ((l8 = texture[(loops & 0xfc0) + (rgb >> 6)] >>> i8) != 0) 2068 - dest[dest_off] = l8; 2069 - dest_off++; 2070 - rgb += i7; 2071 - loops += k7; 2072 - } 2073 - 2074 - return; 2075 - } 2076 - int j4 = 0; 2077 - int l4 = 0; 2078 - int l6 = start_x - Rasterizer3D.center_x; 2079 - arg7 += (arg10 >> 3) * l6; 2080 - arg8 += (arg11 >> 3) * l6; 2081 - arg9 += (arg12 >> 3) * l6; 2082 - int l5 = arg9 >> 14; 2083 - if (l5 != 0) { 2084 - rgb = arg7 / l5; 2085 - loops = arg8 / l5; 2086 - if (rgb < 0) 2087 - rgb = 0; 2088 - else if (rgb > 16256) 2089 - rgb = 16256; 2090 - } 2091 - arg7 += arg10; 2092 - arg8 += arg11; 2093 - arg9 += arg12; 2094 - l5 = arg9 >> 14; 2095 - if (l5 != 0) { 2096 - j4 = arg7 / l5; 2097 - l4 = arg8 / l5; 2098 - if (j4 < 7) 2099 - j4 = 7; 2100 - else if (j4 > 16256) 2101 - j4 = 16256; 2102 - } 2103 - int j7 = j4 - rgb >> 3; 2104 - int l7 = l4 - loops >> 3; 2105 - rgb += shadeValue & 0x600000; 2106 - int j8 = shadeValue >> 23; 2107 - if (opaque) { 2108 - while (k3-- > 0) { 2109 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2110 - rgb += j7; 2111 - loops += l7; 2112 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2113 - rgb += j7; 2114 - loops += l7; 2115 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2116 - rgb += j7; 2117 - loops += l7; 2118 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2119 - rgb += j7; 2120 - loops += l7; 2121 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2122 - rgb += j7; 2123 - loops += l7; 2124 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2125 - rgb += j7; 2126 - loops += l7; 2127 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2128 - rgb += j7; 2129 - loops += l7; 2130 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2131 - rgb = j4; 2132 - loops = l4; 2133 - arg7 += arg10; 2134 - arg8 += arg11; 2135 - arg9 += arg12; 2136 - int i6 = arg9 >> 14; 2137 - if (i6 != 0) { 2138 - j4 = arg7 / i6; 2139 - l4 = arg8 / i6; 2140 - if (j4 < 7) 2141 - j4 = 7; 2142 - else if (j4 > 16256) 2143 - j4 = 16256; 2144 - } 2145 - j7 = j4 - rgb >> 3; 2146 - l7 = l4 - loops >> 3; 2147 - shadeValue += j3; 2148 - rgb += shadeValue & 0x600000; 2149 - j8 = shadeValue >> 23; 2150 - } 2151 - for (k3 = end_x - start_x & 7; k3-- > 0; ) { 2152 - dest[dest_off++] = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8; 2153 - rgb += j7; 2154 - loops += l7; 2155 - } 2156 - 2157 - return; 2158 - } 2159 - while (k3-- > 0) { 2160 - int i9; 2161 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2162 - dest[dest_off] = i9; 2163 - dest_off++; 2164 - rgb += j7; 2165 - loops += l7; 2166 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2167 - dest[dest_off] = i9; 2168 - dest_off++; 2169 - rgb += j7; 2170 - loops += l7; 2171 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2172 - dest[dest_off] = i9; 2173 - dest_off++; 2174 - rgb += j7; 2175 - loops += l7; 2176 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2177 - dest[dest_off] = i9; 2178 - dest_off++; 2179 - rgb += j7; 2180 - loops += l7; 2181 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2182 - dest[dest_off] = i9; 2183 - dest_off++; 2184 - rgb += j7; 2185 - loops += l7; 2186 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2187 - dest[dest_off] = i9; 2188 - dest_off++; 2189 - rgb += j7; 2190 - loops += l7; 2191 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2192 - dest[dest_off] = i9; 2193 - dest_off++; 2194 - rgb += j7; 2195 - loops += l7; 2196 - if ((i9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2197 - dest[dest_off] = i9; 2198 - dest_off++; 2199 - rgb = j4; 2200 - loops = l4; 2201 - arg7 += arg10; 2202 - arg8 += arg11; 2203 - arg9 += arg12; 2204 - int j6 = arg9 >> 14; 2205 - if (j6 != 0) { 2206 - j4 = arg7 / j6; 2207 - l4 = arg8 / j6; 2208 - if (j4 < 7) 2209 - j4 = 7; 2210 - else if (j4 > 16256) 2211 - j4 = 16256; 2212 - } 2213 - j7 = j4 - rgb >> 3; 2214 - l7 = l4 - loops >> 3; 2215 - shadeValue += j3; 2216 - rgb += shadeValue & 0x600000; 2217 - j8 = shadeValue >> 23; 2218 - } 2219 - for (int l3 = end_x - start_x & 7; l3-- > 0; ) { 2220 - int j9; 2221 - if ((j9 = texture[(loops & 0x3f80) + (rgb >> 7)] >>> j8) != 0) 2222 - dest[dest_off] = j9; 2223 - dest_off++; 2224 - rgb += j7; 2225 - loops += l7; 2226 - } 2227 - 2228 - } 2229 - 2230 - static { 2231 - for (int i = 1; i < 512; i++) 2232 - shadowDecay[i] = 32768 / i; 2233 - 2234 - for (int j = 1; j < 2048; j++) 2235 - anIntArray1469[j] = 0x10000 / j; 2236 - 2237 - for (int k = 0; k < 2048; k++) { 2238 - SINE[k] = (int) (65536D * Math.sin(k * 0.0030679614999999999D)); 2239 - COSINE[k] = (int) (65536D * Math.cos(k * 0.0030679614999999999D)); 2240 - } 2241 - 2242 - } 2243 - }
+2531
src/main/java/com/jagex/runescape/media/Rasterizer3D.kt
··· 1 + package com.jagex.runescape.media 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.cache.media.IndexedImage 5 + 6 + class Rasterizer3D : Rasterizer() { 7 + 8 + companion object { 9 + @JvmField 10 + var lowMemory: Boolean = true 11 + 12 + @JvmField 13 + var restrict_edges: Boolean = false 14 + 15 + @JvmField 16 + var opaque: Boolean = false 17 + 18 + @JvmField 19 + var notTextured: Boolean = true 20 + 21 + @JvmField 22 + var alpha: Int = 0 23 + 24 + @JvmField 25 + var center_x: Int = 0 26 + 27 + @JvmField 28 + var center_y: Int = 0 29 + 30 + @JvmField 31 + var shadowDecay: IntArray? = IntArray(512) 32 + 33 + @JvmField 34 + var reciprocal16: IntArray? = IntArray(2048) 35 + 36 + @JvmField 37 + var SINE: IntArray? = IntArray(2048) 38 + 39 + @JvmField 40 + var COSINE: IntArray? = IntArray(2048) 41 + 42 + @JvmField 43 + var lineOffsets: IntArray? = null 44 + 45 + @JvmField 46 + var loadedTextureCount: Int = 0 47 + 48 + @JvmField 49 + var textureImages: Array<IndexedImage?>? = arrayOfNulls(50) 50 + 51 + @JvmField 52 + var textureIsTransparent: BooleanArray? = BooleanArray(50) 53 + 54 + @JvmField 55 + var averageTextureColour: IntArray? = IntArray(50) 56 + 57 + @JvmField 58 + var textureTexelPoolPointer: Int = 0 59 + 60 + @JvmField 61 + var texelArrayPool: Array<IntArray?>? = null 62 + 63 + @JvmField 64 + var texelCache: Array<IntArray?>? = arrayOfNulls(50) 65 + 66 + @JvmField 67 + var textureLastUsed: IntArray? = IntArray(50) 68 + 69 + @JvmField 70 + var textureGetCount: Int = 0 71 + 72 + @JvmField 73 + var hsl2rgb: IntArray? = IntArray(0x10000) 74 + 75 + @JvmField 76 + var texturePalettes: Array<IntArray?>? = arrayOfNulls(50) 77 + 78 + private var useLatestShadeLine: Boolean = true 79 + 80 + @JvmStatic 81 + fun reset() { 82 + shadowDecay = null 83 + SINE = null 84 + COSINE = null 85 + lineOffsets = null 86 + textureImages = null 87 + textureIsTransparent = null 88 + averageTextureColour = null 89 + texelArrayPool = null 90 + texelCache = null 91 + textureLastUsed = null 92 + hsl2rgb = null 93 + texturePalettes = null 94 + } 95 + 96 + @JvmStatic 97 + fun setDefaultBounds() { 98 + lineOffsets = IntArray(Rasterizer.height) 99 + for (i in 0 until height) { 100 + lineOffsets!![i] = width * i 101 + } 102 + center_x = width / 2 103 + center_y = height / 2 104 + } 105 + 106 + @JvmStatic 107 + fun setBounds(width: Int, height: Int) { 108 + lineOffsets = IntArray(height) 109 + for (i in 0 until height) { 110 + lineOffsets!![i] = width * i 111 + } 112 + center_x = width / 2 113 + center_y = height / 2 114 + } 115 + 116 + @JvmStatic 117 + fun clearTextureCache() { 118 + texelArrayPool = null 119 + for (i in 0 until 50) { 120 + texelCache!![i] = null 121 + } 122 + } 123 + 124 + @JvmStatic 125 + fun resetTextures(texturePoolSize: Int) { 126 + if (texelArrayPool == null) { 127 + textureTexelPoolPointer = texturePoolSize //was parameter 128 + if (lowMemory) { 129 + texelArrayPool = Array(textureTexelPoolPointer) { IntArray(16384) } 130 + } else { 131 + texelArrayPool = Array(textureTexelPoolPointer) { IntArray(0x10000) } 132 + } 133 + for (k in 0 until 50) { 134 + texelCache!![k] = null 135 + } 136 + } 137 + } 138 + 139 + @JvmStatic 140 + fun unpackTextures(jagexArchive: Archive) { 141 + loadedTextureCount = 0 142 + for (i in 0 until 50) { 143 + try { 144 + textureImages!![i] = IndexedImage(jagexArchive, i.toString(), 0) 145 + if (lowMemory && textureImages!![i]!!.maxWidth == 128) { 146 + textureImages!![i]!!.resizeToHalfLibSize() 147 + } else { 148 + textureImages!![i]!!.resizeToLibSize() 149 + } 150 + loadedTextureCount++ 151 + } catch (exception: Exception) { 152 + } 153 + }/* 154 + for (int k = 0;k < textureImagesHD.length;k++) 155 + try{ 156 + textureImagesHD[k] = new RgbImage("./hddata/texture/"+k+".png"); 157 + } catch (Exception ignored){ 158 + textureImagesHD[k] = textureImagesHD[k - 1]; 159 + } 160 + */ 161 + } 162 + 163 + @JvmStatic 164 + fun getAverageRgbColorForTexture(textureId: Int): Int { 165 + if (averageTextureColour!![textureId] != 0) { 166 + return averageTextureColour!![textureId] 167 + } 168 + var red = 0 169 + var green = 0 170 + var blue = 0 171 + val colourCount = texturePalettes!![textureId]!!.size 172 + for (ptr in 0 until colourCount) { 173 + red += (texturePalettes!![textureId]!![ptr] shr 16) and 0xff 174 + green += (texturePalettes!![textureId]!![ptr] shr 8) and 0xff 175 + blue += texturePalettes!![textureId]!![ptr] and 0xff 176 + } 177 + 178 + var rgb = ((red / colourCount) shl 16) + ((green / colourCount) shl 8) + blue / colourCount 179 + rgb = adjustBrightness(rgb, 1.3999999999999999) 180 + if (rgb == 0) { 181 + rgb = 1 182 + } 183 + averageTextureColour!![textureId] = rgb 184 + return rgb 185 + } 186 + 187 + @JvmStatic 188 + fun resetTexture(textureId: Int) { 189 + if (texelCache!![textureId] == null) { 190 + return 191 + } 192 + texelArrayPool!![textureTexelPoolPointer++] = texelCache!![textureId] 193 + texelCache!![textureId] = null 194 + } 195 + 196 + @JvmStatic 197 + fun getTexturePixels(textureId: Int): IntArray { 198 + textureLastUsed!![textureId] = textureGetCount++ 199 + if (texelCache!![textureId] != null) { 200 + return texelCache!![textureId]!! 201 + } 202 + val texels: IntArray 203 + //Start of mem management code 204 + if (textureTexelPoolPointer > 0) { //Freed texture data arrays available 205 + textureTexelPoolPointer-- 206 + texels = texelArrayPool!![textureTexelPoolPointer]!! 207 + texelArrayPool!![textureTexelPoolPointer] = null 208 + } else { //No freed texture data arrays available, recycle least used texture's array 209 + var lastUsed = 0 210 + var target = -1 211 + for (i in 0 until loadedTextureCount) { 212 + if (texelCache!![i] != null && (textureLastUsed!![i] < lastUsed || target == -1)) { 213 + lastUsed = textureLastUsed!![i] 214 + target = i 215 + } 216 + } 217 + 218 + texels = texelCache!![target]!! 219 + texelCache!![target] = null 220 + } 221 + texelCache!![textureId] = texels 222 + //End of mem management code 223 + val indexedImage = textureImages!![textureId]!! 224 + val texturePalette = texturePalettes!![textureId]!! 225 + if (lowMemory) { 226 + textureIsTransparent!![textureId] = false 227 + for (texelPtr in 0 until 4096) { 228 + val texel = texturePalette[indexedImage.imgPixels[texelPtr].toInt() and 0xff] and 0xf8f8ff 229 + texels[texelPtr] = texel 230 + if (texel == 0) { 231 + textureIsTransparent!![textureId] = true 232 + } 233 + texels[4096 + texelPtr] = (texel - (texel ushr 3)) and 0xf8f8ff 234 + texels[8192 + texelPtr] = (texel - (texel ushr 2)) and 0xf8f8ff 235 + texels[12288 + texelPtr] = (texel - (texel ushr 2) - (texel ushr 3)) and 0xf8f8ff 236 + } 237 + } else { 238 + if (indexedImage.imgWidth == 64) { 239 + for (y in 0 until 128) { 240 + for (x in 0 until 128) { 241 + texels[x + (y shl 7)] = texturePalette[indexedImage.imgPixels[(x shr 1) + ((y shr 1) shl 6)].toInt() and 0xff] 242 + } 243 + } 244 + } else { 245 + for (texelPtr in 0 until 16384) { 246 + texels[texelPtr] = texturePalette[indexedImage.imgPixels[texelPtr].toInt() and 0xff] 247 + } 248 + } 249 + textureIsTransparent!![textureId] = false 250 + for (texelPtr in 0 until 16384) { 251 + texels[texelPtr] = texels[texelPtr] and 0xf8f8ff 252 + val texel = texels[texelPtr] 253 + if (texel == 0) { 254 + textureIsTransparent!![textureId] = true 255 + } 256 + texels[16384 + texelPtr] = (texel - (texel ushr 3)) and 0xf8f8ff 257 + texels[32768 + texelPtr] = (texel - (texel ushr 2)) and 0xf8f8ff 258 + texels[49152 + texelPtr] = (texel - (texel ushr 2) - (texel ushr 3)) and 0xf8f8ff 259 + } 260 + } 261 + return texels 262 + } 263 + 264 + @JvmStatic 265 + fun calculatePalette(brightness: Double) { 266 + @Suppress("NAME_SHADOWING") 267 + var brightness = brightness 268 + brightness += Math.random() * 0.029999999999999999 - 0.014999999999999999 269 + var hsl = 0 270 + for (k in 0 until 512) { 271 + val d1 = (k / 8).toDouble() / 64.0 + 0.0078125 272 + val d2 = (k and 7).toDouble() / 8.0 + 0.0625 273 + for (k1 in 0 until 128) { 274 + val d3 = k1.toDouble() / 128.0 275 + var r = d3 276 + var g = d3 277 + var b = d3 278 + if (d2 != 0.0) { 279 + val d7: Double 280 + if (d3 < 0.5) { 281 + d7 = d3 * (1.0 + d2) 282 + } else { 283 + d7 = (d3 + d2) - d3 * d2 284 + } 285 + val d8 = 2.0 * d3 - d7 286 + var d9 = d1 + 0.33333333333333331 287 + if (d9 > 1.0) { 288 + d9-- 289 + } 290 + val d10 = d1 291 + var d11 = d1 - 0.33333333333333331 292 + if (d11 < 0.0) { 293 + d11++ 294 + } 295 + if (6.0 * d9 < 1.0) { 296 + r = d8 + (d7 - d8) * 6.0 * d9 297 + } else if (2.0 * d9 < 1.0) { 298 + r = d7 299 + } else if (3.0 * d9 < 2.0) { 300 + r = d8 + (d7 - d8) * (0.66666666666666663 - d9) * 6.0 301 + } else { 302 + r = d8 303 + } 304 + if (6.0 * d10 < 1.0) { 305 + g = d8 + (d7 - d8) * 6.0 * d10 306 + } else if (2.0 * d10 < 1.0) { 307 + g = d7 308 + } else if (3.0 * d10 < 2.0) { 309 + g = d8 + (d7 - d8) * (0.66666666666666663 - d10) * 6.0 310 + } else { 311 + g = d8 312 + } 313 + if (6.0 * d11 < 1.0) { 314 + b = d8 + (d7 - d8) * 6.0 * d11 315 + } else if (2.0 * d11 < 1.0) { 316 + b = d7 317 + } else if (3.0 * d11 < 2.0) { 318 + b = d8 + (d7 - d8) * (0.66666666666666663 - d11) * 6.0 319 + } else { 320 + b = d8 321 + } 322 + } 323 + val byteR = (r * 256.0).toInt() 324 + val byteG = (g * 256.0).toInt() 325 + val byteB = (b * 256.0).toInt() 326 + var rgb = (byteR shl 16) + (byteG shl 8) + byteB 327 + rgb = adjustBrightness(rgb, brightness) 328 + if (rgb == 0) { 329 + rgb = 1 330 + } 331 + hsl2rgb!![hsl++] = rgb 332 + } 333 + } 334 + 335 + for (textureId in 0 until 50) { 336 + if (textureImages!![textureId] != null) { 337 + val palette = textureImages!![textureId]!!.palette 338 + texturePalettes!![textureId] = IntArray(palette.size) 339 + for (colourIdx in palette.indices) { 340 + texturePalettes!![textureId]!![colourIdx] = adjustBrightness(palette[colourIdx], brightness) 341 + if ((texturePalettes!![textureId]!![colourIdx] and 0xf8f8ff) == 0 && colourIdx != 0) { 342 + texturePalettes!![textureId]!![colourIdx] = 1 343 + } 344 + } 345 + } 346 + } 347 + 348 + for (textureId in 0 until 50) { 349 + resetTexture(textureId) 350 + } 351 + } 352 + 353 + @JvmStatic 354 + private fun adjustBrightness(rgb: Int, intensity: Double): Int { 355 + var r = (rgb shr 16).toDouble() / 256.0 356 + var g = ((rgb shr 8) and 0xff).toDouble() / 256.0 357 + var b = (rgb and 0xff).toDouble() / 256.0 358 + r = Math.pow(r, intensity) 359 + g = Math.pow(g, intensity) 360 + b = Math.pow(b, intensity) 361 + val r_byte = (r * 256.0).toInt() 362 + val g_byte = (g * 256.0).toInt() 363 + val b_byte = (b * 256.0).toInt() 364 + return (r_byte shl 16) + (g_byte shl 8) + b_byte 365 + } 366 + 367 + @JvmStatic 368 + fun drawShadedTriangle( 369 + y_a: Int, y_b: Int, y_c: Int, x_a: Int, x_b: Int, x_c: Int, 370 + z_a: Int, z_b: Int, z_c: Int 371 + ) { 372 + @Suppress("NAME_SHADOWING") 373 + var y_a = y_a 374 + @Suppress("NAME_SHADOWING") 375 + var y_b = y_b 376 + @Suppress("NAME_SHADOWING") 377 + var y_c = y_c 378 + @Suppress("NAME_SHADOWING") 379 + var x_a = x_a 380 + @Suppress("NAME_SHADOWING") 381 + var x_b = x_b 382 + @Suppress("NAME_SHADOWING") 383 + var x_c = x_c 384 + @Suppress("NAME_SHADOWING") 385 + var z_a = z_a 386 + @Suppress("NAME_SHADOWING") 387 + var z_b = z_b 388 + @Suppress("NAME_SHADOWING") 389 + var z_c = z_c 390 + 391 + var x_a_off = 0 392 + var z_a_off = 0 393 + if (y_b != y_a) { 394 + x_a_off = ((x_b - x_a) shl 16) / (y_b - y_a) 395 + z_a_off = ((z_b - z_a) shl 15) / (y_b - y_a) 396 + } 397 + var x_b_off = 0 398 + var z_b_off = 0 399 + if (y_c != y_b) { 400 + x_b_off = ((x_c - x_b) shl 16) / (y_c - y_b) 401 + z_b_off = ((z_c - z_b) shl 15) / (y_c - y_b) 402 + } 403 + var x_c_off = 0 404 + var z_c_off = 0 405 + if (y_c != y_a) { 406 + x_c_off = ((x_a - x_c) shl 16) / (y_a - y_c) 407 + z_c_off = ((z_a - z_c) shl 15) / (y_a - y_c) 408 + } 409 + if (y_a <= y_b && y_a <= y_c) { 410 + if (y_a >= bottomY) { 411 + return 412 + } 413 + if (y_b > bottomY) { 414 + y_b = bottomY 415 + } 416 + if (y_c > bottomY) { 417 + y_c = bottomY 418 + } 419 + if (y_b < y_c) { 420 + x_a = x_a shl 16; x_c = x_a 421 + z_a = z_a shl 15; z_c = z_a 422 + if (y_a < 0) { 423 + x_c -= x_c_off * y_a 424 + x_a -= x_a_off * y_a 425 + z_c -= z_c_off * y_a 426 + z_a -= z_a_off * y_a 427 + y_a = 0 428 + } 429 + x_b = x_b shl 16 430 + z_b = z_b shl 15 431 + if (y_b < 0) { 432 + x_b -= x_b_off * y_b 433 + z_b -= z_b_off * y_b 434 + y_b = 0 435 + } 436 + if (y_a != y_b && x_c_off < x_a_off || y_a == y_b && x_c_off > x_b_off) { 437 + y_c -= y_b 438 + y_b -= y_a 439 + y_a = lineOffsets!![y_a] 440 + while (true) { 441 + y_b-- 442 + if (y_b < 0) break 443 + drawShadedLine(pixels, y_a, x_c shr 16, x_a shr 16, z_c shr 7, z_a shr 7) 444 + x_c += x_c_off 445 + x_a += x_a_off 446 + z_c += z_c_off 447 + z_a += z_a_off 448 + y_a += width 449 + } 450 + 451 + while (true) { 452 + y_c-- 453 + if (y_c < 0) break 454 + drawShadedLine(pixels, y_a, x_c shr 16, x_b shr 16, z_c shr 7, z_b shr 7) 455 + x_c += x_c_off 456 + x_b += x_b_off 457 + z_c += z_c_off 458 + z_b += z_b_off 459 + y_a += width 460 + } 461 + return 462 + } 463 + y_c -= y_b 464 + y_b -= y_a 465 + y_a = lineOffsets!![y_a] 466 + while (true) { 467 + y_b-- 468 + if (y_b < 0) break 469 + drawShadedLine(pixels, y_a, x_a shr 16, x_c shr 16, z_a shr 7, z_c shr 7) 470 + x_c += x_c_off 471 + x_a += x_a_off 472 + z_c += z_c_off 473 + z_a += z_a_off 474 + y_a += width 475 + } 476 + 477 + while (true) { 478 + y_c-- 479 + if (y_c < 0) break 480 + drawShadedLine(pixels, y_a, x_b shr 16, x_c shr 16, z_b shr 7, z_c shr 7) 481 + x_c += x_c_off 482 + x_b += x_b_off 483 + z_c += z_c_off 484 + z_b += z_b_off 485 + y_a += width 486 + } 487 + return 488 + } 489 + x_a = x_a shl 16; x_b = x_a 490 + z_a = z_a shl 15; z_b = z_a 491 + if (y_a < 0) { 492 + x_b -= x_c_off * y_a 493 + x_a -= x_a_off * y_a 494 + z_b -= z_c_off * y_a 495 + z_a -= z_a_off * y_a 496 + y_a = 0 497 + } 498 + x_c = x_c shl 16 499 + z_c = z_c shl 15 500 + if (y_c < 0) { 501 + x_c -= x_b_off * y_c 502 + z_c -= z_b_off * y_c 503 + y_c = 0 504 + } 505 + if (y_a != y_c && x_c_off < x_a_off || y_a == y_c && x_b_off > x_a_off) { 506 + y_b -= y_c 507 + y_c -= y_a 508 + y_a = lineOffsets!![y_a] 509 + while (true) { 510 + y_c-- 511 + if (y_c < 0) break 512 + drawShadedLine(pixels, y_a, x_b shr 16, x_a shr 16, z_b shr 7, z_a shr 7) 513 + x_b += x_c_off 514 + x_a += x_a_off 515 + z_b += z_c_off 516 + z_a += z_a_off 517 + y_a += width 518 + } 519 + 520 + while (true) { 521 + y_b-- 522 + if (y_b < 0) break 523 + drawShadedLine(pixels, y_a, x_c shr 16, x_a shr 16, z_c shr 7, z_a shr 7) 524 + x_c += x_b_off 525 + x_a += x_a_off 526 + z_c += z_b_off 527 + z_a += z_a_off 528 + y_a += width 529 + } 530 + return 531 + } 532 + y_b -= y_c 533 + y_c -= y_a 534 + y_a = lineOffsets!![y_a] 535 + while (true) { 536 + y_c-- 537 + if (y_c < 0) break 538 + drawShadedLine(pixels, y_a, x_a shr 16, x_b shr 16, z_a shr 7, z_b shr 7) 539 + x_b += x_c_off 540 + x_a += x_a_off 541 + z_b += z_c_off 542 + z_a += z_a_off 543 + y_a += width 544 + } 545 + 546 + while (true) { 547 + y_b-- 548 + if (y_b < 0) break 549 + drawShadedLine(pixels, y_a, x_a shr 16, x_c shr 16, z_a shr 7, z_c shr 7) 550 + x_c += x_b_off 551 + x_a += x_a_off 552 + z_c += z_b_off 553 + z_a += z_a_off 554 + y_a += width 555 + } 556 + return 557 + } 558 + if (y_b <= y_c) { 559 + if (y_b >= bottomY) { 560 + return 561 + } 562 + if (y_c > bottomY) { 563 + y_c = bottomY 564 + } 565 + if (y_a > bottomY) { 566 + y_a = bottomY 567 + } 568 + if (y_c < y_a) { 569 + x_b = x_b shl 16; x_a = x_b 570 + z_b = z_b shl 15; z_a = z_b 571 + if (y_b < 0) { 572 + x_a -= x_a_off * y_b 573 + x_b -= x_b_off * y_b 574 + z_a -= z_a_off * y_b 575 + z_b -= z_b_off * y_b 576 + y_b = 0 577 + } 578 + x_c = x_c shl 16 579 + z_c = z_c shl 15 580 + if (y_c < 0) { 581 + x_c -= x_c_off * y_c 582 + z_c -= z_c_off * y_c 583 + y_c = 0 584 + } 585 + if (y_b != y_c && x_a_off < x_b_off || y_b == y_c && x_a_off > x_c_off) { 586 + y_a -= y_c 587 + y_c -= y_b 588 + y_b = lineOffsets!![y_b] 589 + while (true) { 590 + y_c-- 591 + if (y_c < 0) break 592 + drawShadedLine(pixels, y_b, x_a shr 16, x_b shr 16, z_a shr 7, z_b shr 7) 593 + x_a += x_a_off 594 + x_b += x_b_off 595 + z_a += z_a_off 596 + z_b += z_b_off 597 + y_b += width 598 + } 599 + 600 + while (true) { 601 + y_a-- 602 + if (y_a < 0) break 603 + drawShadedLine(pixels, y_b, x_a shr 16, x_c shr 16, z_a shr 7, z_c shr 7) 604 + x_a += x_a_off 605 + x_c += x_c_off 606 + z_a += z_a_off 607 + z_c += z_c_off 608 + y_b += width 609 + } 610 + return 611 + } 612 + y_a -= y_c 613 + y_c -= y_b 614 + y_b = lineOffsets!![y_b] 615 + while (true) { 616 + y_c-- 617 + if (y_c < 0) break 618 + drawShadedLine(pixels, y_b, x_b shr 16, x_a shr 16, z_b shr 7, z_a shr 7) 619 + x_a += x_a_off 620 + x_b += x_b_off 621 + z_a += z_a_off 622 + z_b += z_b_off 623 + y_b += width 624 + } 625 + 626 + while (true) { 627 + y_a-- 628 + if (y_a < 0) break 629 + drawShadedLine(pixels, y_b, x_c shr 16, x_a shr 16, z_c shr 7, z_a shr 7) 630 + x_a += x_a_off 631 + x_c += x_c_off 632 + z_a += z_a_off 633 + z_c += z_c_off 634 + y_b += width 635 + } 636 + return 637 + } 638 + x_b = x_b shl 16; x_c = x_b 639 + z_b = z_b shl 15; z_c = z_b 640 + if (y_b < 0) { 641 + x_c -= x_a_off * y_b 642 + x_b -= x_b_off * y_b 643 + z_c -= z_a_off * y_b 644 + z_b -= z_b_off * y_b 645 + y_b = 0 646 + } 647 + x_a = x_a shl 16 648 + z_a = z_a shl 15 649 + if (y_a < 0) { 650 + x_a -= x_c_off * y_a 651 + z_a -= z_c_off * y_a 652 + y_a = 0 653 + } 654 + if (x_a_off < x_b_off) { 655 + y_c -= y_a 656 + y_a -= y_b 657 + y_b = lineOffsets!![y_b] 658 + while (true) { 659 + y_a-- 660 + if (y_a < 0) break 661 + drawShadedLine(pixels, y_b, x_c shr 16, x_b shr 16, z_c shr 7, z_b shr 7) 662 + x_c += x_a_off 663 + x_b += x_b_off 664 + z_c += z_a_off 665 + z_b += z_b_off 666 + y_b += width 667 + } 668 + 669 + while (true) { 670 + y_c-- 671 + if (y_c < 0) break 672 + drawShadedLine(pixels, y_b, x_a shr 16, x_b shr 16, z_a shr 7, z_b shr 7) 673 + x_a += x_c_off 674 + x_b += x_b_off 675 + z_a += z_c_off 676 + z_b += z_b_off 677 + y_b += width 678 + } 679 + return 680 + } 681 + y_c -= y_a 682 + y_a -= y_b 683 + y_b = lineOffsets!![y_b] 684 + while (true) { 685 + y_a-- 686 + if (y_a < 0) break 687 + drawShadedLine(pixels, y_b, x_b shr 16, x_c shr 16, z_b shr 7, z_c shr 7) 688 + x_c += x_a_off 689 + x_b += x_b_off 690 + z_c += z_a_off 691 + z_b += z_b_off 692 + y_b += width 693 + } 694 + 695 + while (true) { 696 + y_c-- 697 + if (y_c < 0) break 698 + drawShadedLine(pixels, y_b, x_b shr 16, x_a shr 16, z_b shr 7, z_a shr 7) 699 + x_a += x_c_off 700 + x_b += x_b_off 701 + z_a += z_c_off 702 + z_b += z_b_off 703 + y_b += width 704 + } 705 + return 706 + } 707 + if (y_c >= bottomY) { 708 + return 709 + } 710 + if (y_a > bottomY) { 711 + y_a = bottomY 712 + } 713 + if (y_b > bottomY) { 714 + y_b = bottomY 715 + } 716 + if (y_a < y_b) { 717 + x_c = x_c shl 16; x_b = x_c 718 + z_c = z_c shl 15; z_b = z_c 719 + if (y_c < 0) { 720 + x_b -= x_b_off * y_c 721 + x_c -= x_c_off * y_c 722 + z_b -= z_b_off * y_c 723 + z_c -= z_c_off * y_c 724 + y_c = 0 725 + } 726 + x_a = x_a shl 16 727 + z_a = z_a shl 15 728 + if (y_a < 0) { 729 + x_a -= x_a_off * y_a 730 + z_a -= z_a_off * y_a 731 + y_a = 0 732 + } 733 + if (x_b_off < x_c_off) { 734 + y_b -= y_a 735 + y_a -= y_c 736 + y_c = lineOffsets!![y_c] 737 + while (true) { 738 + y_a-- 739 + if (y_a < 0) break 740 + drawShadedLine(pixels, y_c, x_b shr 16, x_c shr 16, z_b shr 7, z_c shr 7) 741 + x_b += x_b_off 742 + x_c += x_c_off 743 + z_b += z_b_off 744 + z_c += z_c_off 745 + y_c += width 746 + } 747 + 748 + while (true) { 749 + y_b-- 750 + if (y_b < 0) break 751 + drawShadedLine(pixels, y_c, x_b shr 16, x_a shr 16, z_b shr 7, z_a shr 7) 752 + x_b += x_b_off 753 + x_a += x_a_off 754 + z_b += z_b_off 755 + z_a += z_a_off 756 + y_c += width 757 + } 758 + return 759 + } 760 + y_b -= y_a 761 + y_a -= y_c 762 + y_c = lineOffsets!![y_c] 763 + while (true) { 764 + y_a-- 765 + if (y_a < 0) break 766 + drawShadedLine(pixels, y_c, x_c shr 16, x_b shr 16, z_c shr 7, z_b shr 7) 767 + x_b += x_b_off 768 + x_c += x_c_off 769 + z_b += z_b_off 770 + z_c += z_c_off 771 + y_c += width 772 + } 773 + 774 + while (true) { 775 + y_b-- 776 + if (y_b < 0) break 777 + drawShadedLine(pixels, y_c, x_a shr 16, x_b shr 16, z_a shr 7, z_b shr 7) 778 + x_b += x_b_off 779 + x_a += x_a_off 780 + z_b += z_b_off 781 + z_a += z_a_off 782 + y_c += width 783 + } 784 + return 785 + } 786 + x_c = x_c shl 16; x_a = x_c 787 + z_c = z_c shl 15; z_a = z_c 788 + if (y_c < 0) { 789 + x_a -= x_b_off * y_c 790 + x_c -= x_c_off * y_c 791 + z_a -= z_b_off * y_c 792 + z_c -= z_c_off * y_c 793 + y_c = 0 794 + } 795 + x_b = x_b shl 16 796 + z_b = z_b shl 15 797 + if (y_b < 0) { 798 + x_b -= x_a_off * y_b 799 + z_b -= z_a_off * y_b 800 + y_b = 0 801 + } 802 + if (x_b_off < x_c_off) { 803 + y_a -= y_b 804 + y_b -= y_c 805 + y_c = lineOffsets!![y_c] 806 + while (true) { 807 + y_b-- 808 + if (y_b < 0) break 809 + drawShadedLine(pixels, y_c, x_a shr 16, x_c shr 16, z_a shr 7, z_c shr 7) 810 + x_a += x_b_off 811 + x_c += x_c_off 812 + z_a += z_b_off 813 + z_c += z_c_off 814 + y_c += width 815 + } 816 + 817 + while (true) { 818 + y_a-- 819 + if (y_a < 0) break 820 + drawShadedLine(pixels, y_c, x_b shr 16, x_c shr 16, z_b shr 7, z_c shr 7) 821 + x_b += x_a_off 822 + x_c += x_c_off 823 + z_b += z_a_off 824 + z_c += z_c_off 825 + y_c += width 826 + } 827 + return 828 + } 829 + y_a -= y_b 830 + y_b -= y_c 831 + y_c = lineOffsets!![y_c] 832 + while (true) { 833 + y_b-- 834 + if (y_b < 0) break 835 + drawShadedLine(pixels, y_c, x_c shr 16, x_a shr 16, z_c shr 7, z_a shr 7) 836 + x_a += x_b_off 837 + x_c += x_c_off 838 + z_a += z_b_off 839 + z_c += z_c_off 840 + y_c += width 841 + } 842 + 843 + while (true) { 844 + y_a-- 845 + if (y_a < 0) break 846 + drawShadedLine(pixels, y_c, x_c shr 16, x_b shr 16, z_c shr 7, z_b shr 7) 847 + x_b += x_a_off 848 + x_c += x_c_off 849 + z_b += z_a_off 850 + z_c += z_c_off 851 + y_c += width 852 + } 853 + } 854 + 855 + //562 drawshadedline 856 + //has vertex blending :O 857 + @JvmStatic 858 + fun drawShadedLine562(dest: IntArray, dest_off: Int, startX: Int, endX: Int, colorIndex: Int, grad: Int) { 859 + @Suppress("NAME_SHADOWING") 860 + var dest_off = dest_off 861 + @Suppress("NAME_SHADOWING") 862 + var startX = startX 863 + @Suppress("NAME_SHADOWING") 864 + var endX = endX 865 + @Suppress("NAME_SHADOWING") 866 + var colorIndex = colorIndex 867 + var off = 0 868 + var color: Int 869 + var loops: Int 870 + if (restrict_edges) { 871 + if (endX > viewportRx) 872 + endX = viewportRx 873 + if (startX < 0) { 874 + //colorIndex -= startX * off;//not sure if needed 875 + startX = 0 876 + } 877 + } 878 + if (startX < endX) { 879 + dest_off += startX - 1 880 + colorIndex += off * startX 881 + if (notTextured) { 882 + loops = (endX - startX) shr 2 883 + if (loops > 0) 884 + off = ((grad - colorIndex) * shadowDecay!![loops]) shr 15 885 + else 886 + off = 0 887 + if (alpha == 0) { 888 + if (loops > 0) { 889 + do { 890 + color = hsl2rgb!![colorIndex shr 8] 891 + colorIndex += off 892 + dest_off++; dest[dest_off] = color 893 + dest_off++; dest[dest_off] = color 894 + dest_off++; dest[dest_off] = color 895 + dest_off++; dest[dest_off] = color 896 + loops-- 897 + } while (loops > 0) 898 + } 899 + loops = (endX - startX) and 0x3 900 + if (loops > 0) { 901 + color = hsl2rgb!![colorIndex shr 8] 902 + do { 903 + dest_off++; dest[dest_off] = color 904 + loops-- 905 + } while (loops > 0) 906 + } 907 + } else { 908 + val src_alpha = alpha 909 + val dest_alpha = 256 - alpha 910 + if (loops > 0) { 911 + do { 912 + color = hsl2rgb!![colorIndex shr 8] 913 + colorIndex += off 914 + color = ((((color and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((color and 0xff00) * dest_alpha) shr 8) and 0xff00) 915 + dest_off++; var i_169_ = dest[dest_off] 916 + dest[dest_off] = color + ((((i_169_ and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i_169_ and 0xff00) * src_alpha) shr 8) and 0xff00) 917 + dest_off++; i_169_ = dest[dest_off] 918 + dest[dest_off] = color + ((((i_169_ and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i_169_ and 0xff00) * src_alpha) shr 8) and 0xff00) 919 + dest_off++; i_169_ = dest[dest_off] 920 + dest[dest_off] = color + ((((i_169_ and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i_169_ and 0xff00) * src_alpha) shr 8) and 0xff00) 921 + dest_off++; i_169_ = dest[dest_off] 922 + dest[dest_off] = color + ((((i_169_ and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i_169_ and 0xff00) * src_alpha) shr 8) and 0xff00) 923 + loops-- 924 + } while (loops > 0) 925 + } 926 + loops = (endX - startX) and 0x3 927 + if (loops > 0) { 928 + color = hsl2rgb!![colorIndex shr 8] 929 + color = ((((color and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((color and 0xff00) * dest_alpha) shr 8) and 0xff00) 930 + do { 931 + dest_off++; val i_170_ = dest[dest_off] 932 + dest[dest_off] = color + ((((i_170_ and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i_170_ and 0xff00) * src_alpha) shr 8) and 0xff00) 933 + loops-- 934 + } while (loops > 0) 935 + } 936 + } 937 + } else { 938 + loops = endX - startX 939 + if (alpha == 0) { 940 + do { 941 + dest_off++; dest[dest_off] = hsl2rgb!![colorIndex shr 8] 942 + colorIndex += off 943 + loops-- 944 + } while (loops > 0) 945 + } else { 946 + val i = alpha 947 + val i_171_ = 256 - alpha 948 + do { 949 + color = hsl2rgb!![colorIndex shr 8] 950 + colorIndex += off 951 + color = ((((color and 0xff00ff) * i_171_) shr 8) and 0xff00ff) + ((((color and 0xff00) * i_171_) shr 8) and 0xff00) 952 + dest_off++; val i_ = dest[dest_off] 953 + dest[dest_off] = color + ((((i_ and 0xff00ff) * i) shr 8) and 0xff00ff) + ((((i_ and 0xff00) * i) shr 8) and 0xff00) 954 + loops-- 955 + } while (loops > 0) 956 + } 957 + } 958 + } 959 + } 960 + 961 + @JvmStatic 962 + fun drawShadedLine(dest: IntArray, dest_off: Int, start_x: Int, end_x: Int, color_index: Int, grad: Int) { 963 + if (!useLatestShadeLine) { //divert all calls to the new method as its better 964 + drawShadedLine562(dest, dest_off, start_x, end_x, color_index, grad) 965 + //drawShadedLine656(dest, dest_off, start_x, end_x, color_index, grad); 966 + return 967 + } 968 + 969 + @Suppress("NAME_SHADOWING") 970 + var dest_off = dest_off 971 + @Suppress("NAME_SHADOWING") 972 + var start_x = start_x 973 + @Suppress("NAME_SHADOWING") 974 + var end_x = end_x 975 + @Suppress("NAME_SHADOWING") 976 + var color_index = color_index 977 + var color: Int 978 + var loops: Int 979 + var off = 0 980 + if (restrict_edges) { 981 + if (end_x > viewportRx) { 982 + end_x = viewportRx 983 + } 984 + if (start_x < 0) { 985 + color_index -= start_x * off 986 + start_x = 0 987 + } 988 + } 989 + if (start_x < end_x) { 990 + dest_off += start_x 991 + color_index += off * start_x 992 + //if(1 != 1)//if the below code is dead only textured parts of models appear 993 + if (notTextured) { //ifNontexturedModel? 994 + loops = (end_x - start_x) shr 2 995 + if (loops > 0) { 996 + off = ((grad - color_index) * shadowDecay!![loops]) shr 15 997 + } else { 998 + off = 0 999 + } 1000 + if (alpha == 0) { 1001 + if (loops > 0) { 1002 + do { 1003 + color = hsl2rgb!![color_index shr 8] 1004 + color_index += off 1005 + dest[dest_off] = color; dest_off++ 1006 + dest[dest_off] = color; dest_off++ 1007 + dest[dest_off] = color; dest_off++ 1008 + dest[dest_off] = color; dest_off++ 1009 + loops-- 1010 + } while (loops > 0) 1011 + } 1012 + loops = (end_x - start_x) and 0x3 1013 + if (loops > 0) { 1014 + color = hsl2rgb!![color_index shr 8] 1015 + do { 1016 + dest[dest_off] = color; dest_off++ 1017 + loops-- 1018 + } while (loops > 0) 1019 + } 1020 + } else { 1021 + val src_alpha = alpha 1022 + val dest_alpha = 256 - alpha 1023 + if (loops > 0) { 1024 + do { 1025 + color = hsl2rgb!![color_index shr 8] 1026 + color_index += off 1027 + color = ((((color and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((color and 0xff00) * dest_alpha) shr 8) and 0xff00) 1028 + var i = dest[dest_off] 1029 + dest[dest_off] = color + ((((i and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i and 0xff00) * src_alpha) shr 8) and 0xff00); dest_off++ 1030 + i = dest[dest_off] 1031 + dest[dest_off] = color + ((((i and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i and 0xff00) * src_alpha) shr 8) and 0xff00); dest_off++ 1032 + i = dest[dest_off] 1033 + dest[dest_off] = color + ((((i and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i and 0xff00) * src_alpha) shr 8) and 0xff00); dest_off++ 1034 + i = dest[dest_off] 1035 + dest[dest_off] = color + ((((i and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i and 0xff00) * src_alpha) shr 8) and 0xff00); dest_off++ 1036 + loops-- 1037 + } while (loops > 0) 1038 + } 1039 + loops = (end_x - start_x) and 0x3 1040 + if (loops > 0) { 1041 + color = hsl2rgb!![color_index shr 8] 1042 + color = ((((color and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((color and 0xff00) * dest_alpha) shr 8) and 0xff00) 1043 + do { 1044 + val i = dest[dest_off] 1045 + dest[dest_off] = color + ((((i and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i and 0xff00) * src_alpha) shr 8) and 0xff00); dest_off++ 1046 + loops-- 1047 + } while (loops > 0) 1048 + } 1049 + } 1050 + } else { 1051 + val col_off = (grad - color_index) / (end_x - start_x) 1052 + loops = end_x - start_x 1053 + if (alpha == 0) { 1054 + do { 1055 + dest[dest_off] = hsl2rgb!![color_index shr 8]; dest_off++ 1056 + color_index += col_off 1057 + loops-- 1058 + } while (loops > 0) 1059 + } else { 1060 + val src_alpha = alpha 1061 + val dest_alpha = 256 - alpha 1062 + do { 1063 + color = hsl2rgb!![color_index shr 8] 1064 + color_index += col_off 1065 + color = ((((color and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((color and 0xff00) * dest_alpha) shr 8) and 0xff00) 1066 + val i = dest[dest_off] 1067 + dest[dest_off] = color + ((((i and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((i and 0xff00) * src_alpha) shr 8) and 0xff00); dest_off++ 1068 + loops-- 1069 + } while (loops > 0) 1070 + } 1071 + } 1072 + } 1073 + } 1074 + 1075 + @JvmStatic 1076 + fun drawFlatTriangle(y_a: Int, y_b: Int, y_c: Int, x_a: Int, x_b: Int, x_c: Int, color: Int) { 1077 + @Suppress("NAME_SHADOWING") 1078 + var y_a = y_a 1079 + @Suppress("NAME_SHADOWING") 1080 + var y_b = y_b 1081 + @Suppress("NAME_SHADOWING") 1082 + var y_c = y_c 1083 + @Suppress("NAME_SHADOWING") 1084 + var x_a = x_a 1085 + @Suppress("NAME_SHADOWING") 1086 + var x_b = x_b 1087 + @Suppress("NAME_SHADOWING") 1088 + var x_c = x_c 1089 + 1090 + var x_a_off = 0 1091 + if (y_b != y_a) { 1092 + x_a_off = ((x_b - x_a) shl 16) / (y_b - y_a) 1093 + } 1094 + var x_b_off = 0 1095 + if (y_c != y_b) { 1096 + x_b_off = ((x_c - x_b) shl 16) / (y_c - y_b) 1097 + } 1098 + var x_c_off = 0 1099 + if (y_c != y_a) { 1100 + x_c_off = ((x_a - x_c) shl 16) / (y_a - y_c) 1101 + } 1102 + if (y_a <= y_b && y_a <= y_c) { 1103 + if (y_a >= bottomY) { 1104 + return 1105 + } 1106 + if (y_b > bottomY) { 1107 + y_b = bottomY 1108 + } 1109 + if (y_c > bottomY) { 1110 + y_c = bottomY 1111 + } 1112 + if (y_b < y_c) { 1113 + x_a = x_a shl 16; x_c = x_a 1114 + if (y_a < 0) { 1115 + x_c -= x_c_off * y_a 1116 + x_a -= x_a_off * y_a 1117 + y_a = 0 1118 + } 1119 + x_b = x_b shl 16 1120 + if (y_b < 0) { 1121 + x_b -= x_b_off * y_b 1122 + y_b = 0 1123 + } 1124 + if (y_a != y_b && x_c_off < x_a_off || y_a == y_b && x_c_off > x_b_off) { 1125 + y_c -= y_b 1126 + y_b -= y_a 1127 + y_a = lineOffsets!![y_a] 1128 + while (true) { 1129 + y_b-- 1130 + if (y_b < 0) break 1131 + drawScanLine(pixels, y_a, color, x_c shr 16, x_a shr 16) 1132 + x_c += x_c_off 1133 + x_a += x_a_off 1134 + y_a += width 1135 + } 1136 + 1137 + while (true) { 1138 + y_c-- 1139 + if (y_c < 0) break 1140 + drawScanLine(pixels, y_a, color, x_c shr 16, x_b shr 16) 1141 + x_c += x_c_off 1142 + x_b += x_b_off 1143 + y_a += width 1144 + } 1145 + return 1146 + } 1147 + y_c -= y_b 1148 + y_b -= y_a 1149 + y_a = lineOffsets!![y_a] 1150 + while (true) { 1151 + y_b-- 1152 + if (y_b < 0) break 1153 + drawScanLine(pixels, y_a, color, x_a shr 16, x_c shr 16) 1154 + x_c += x_c_off 1155 + x_a += x_a_off 1156 + y_a += width 1157 + } 1158 + 1159 + while (true) { 1160 + y_c-- 1161 + if (y_c < 0) break 1162 + drawScanLine(pixels, y_a, color, x_b shr 16, x_c shr 16) 1163 + x_c += x_c_off 1164 + x_b += x_b_off 1165 + y_a += width 1166 + } 1167 + return 1168 + } 1169 + x_a = x_a shl 16; x_b = x_a 1170 + if (y_a < 0) { 1171 + x_b -= x_c_off * y_a 1172 + x_a -= x_a_off * y_a 1173 + y_a = 0 1174 + } 1175 + x_c = x_c shl 16 1176 + if (y_c < 0) { 1177 + x_c -= x_b_off * y_c 1178 + y_c = 0 1179 + } 1180 + if (y_a != y_c && x_c_off < x_a_off || y_a == y_c && x_b_off > x_a_off) { 1181 + y_b -= y_c 1182 + y_c -= y_a 1183 + y_a = lineOffsets!![y_a] 1184 + while (true) { 1185 + y_c-- 1186 + if (y_c < 0) break 1187 + drawScanLine(pixels, y_a, color, x_b shr 16, x_a shr 16) 1188 + x_b += x_c_off 1189 + x_a += x_a_off 1190 + y_a += width 1191 + } 1192 + 1193 + while (true) { 1194 + y_b-- 1195 + if (y_b < 0) break 1196 + drawScanLine(pixels, y_a, color, x_c shr 16, x_a shr 16) 1197 + x_c += x_b_off 1198 + x_a += x_a_off 1199 + y_a += width 1200 + } 1201 + return 1202 + } 1203 + y_b -= y_c 1204 + y_c -= y_a 1205 + y_a = lineOffsets!![y_a] 1206 + while (true) { 1207 + y_c-- 1208 + if (y_c < 0) break 1209 + drawScanLine(pixels, y_a, color, x_a shr 16, x_b shr 16) 1210 + x_b += x_c_off 1211 + x_a += x_a_off 1212 + y_a += width 1213 + } 1214 + 1215 + while (true) { 1216 + y_b-- 1217 + if (y_b < 0) break 1218 + drawScanLine(pixels, y_a, color, x_a shr 16, x_c shr 16) 1219 + x_c += x_b_off 1220 + x_a += x_a_off 1221 + y_a += width 1222 + } 1223 + return 1224 + } 1225 + if (y_b <= y_c) { 1226 + if (y_b >= bottomY) { 1227 + return 1228 + } 1229 + if (y_c > bottomY) { 1230 + y_c = bottomY 1231 + } 1232 + if (y_a > bottomY) { 1233 + y_a = bottomY 1234 + } 1235 + if (y_c < y_a) { 1236 + x_b = x_b shl 16; x_a = x_b 1237 + if (y_b < 0) { 1238 + x_a -= x_a_off * y_b 1239 + x_b -= x_b_off * y_b 1240 + y_b = 0 1241 + } 1242 + x_c = x_c shl 16 1243 + if (y_c < 0) { 1244 + x_c -= x_c_off * y_c 1245 + y_c = 0 1246 + } 1247 + if (y_b != y_c && x_a_off < x_b_off || y_b == y_c && x_a_off > x_c_off) { 1248 + y_a -= y_c 1249 + y_c -= y_b 1250 + y_b = lineOffsets!![y_b] 1251 + while (true) { 1252 + y_c-- 1253 + if (y_c < 0) break 1254 + drawScanLine(pixels, y_b, color, x_a shr 16, x_b shr 16) 1255 + x_a += x_a_off 1256 + x_b += x_b_off 1257 + y_b += width 1258 + } 1259 + 1260 + while (true) { 1261 + y_a-- 1262 + if (y_a < 0) break 1263 + drawScanLine(pixels, y_b, color, x_a shr 16, x_c shr 16) 1264 + x_a += x_a_off 1265 + x_c += x_c_off 1266 + y_b += width 1267 + } 1268 + return 1269 + } 1270 + y_a -= y_c 1271 + y_c -= y_b 1272 + y_b = lineOffsets!![y_b] 1273 + while (true) { 1274 + y_c-- 1275 + if (y_c < 0) break 1276 + drawScanLine(pixels, y_b, color, x_b shr 16, x_a shr 16) 1277 + x_a += x_a_off 1278 + x_b += x_b_off 1279 + y_b += width 1280 + } 1281 + 1282 + while (true) { 1283 + y_a-- 1284 + if (y_a < 0) break 1285 + drawScanLine(pixels, y_b, color, x_c shr 16, x_a shr 16) 1286 + x_a += x_a_off 1287 + x_c += x_c_off 1288 + y_b += width 1289 + } 1290 + return 1291 + } 1292 + x_b = x_b shl 16; x_c = x_b 1293 + if (y_b < 0) { 1294 + x_c -= x_a_off * y_b 1295 + x_b -= x_b_off * y_b 1296 + y_b = 0 1297 + } 1298 + x_a = x_a shl 16 1299 + if (y_a < 0) { 1300 + x_a -= x_c_off * y_a 1301 + y_a = 0 1302 + } 1303 + if (x_a_off < x_b_off) { 1304 + y_c -= y_a 1305 + y_a -= y_b 1306 + y_b = lineOffsets!![y_b] 1307 + while (true) { 1308 + y_a-- 1309 + if (y_a < 0) break 1310 + drawScanLine(pixels, y_b, color, x_c shr 16, x_b shr 16) 1311 + x_c += x_a_off 1312 + x_b += x_b_off 1313 + y_b += width 1314 + } 1315 + 1316 + while (true) { 1317 + y_c-- 1318 + if (y_c < 0) break 1319 + drawScanLine(pixels, y_b, color, x_a shr 16, x_b shr 16) 1320 + x_a += x_c_off 1321 + x_b += x_b_off 1322 + y_b += width 1323 + } 1324 + return 1325 + } 1326 + y_c -= y_a 1327 + y_a -= y_b 1328 + y_b = lineOffsets!![y_b] 1329 + while (true) { 1330 + y_a-- 1331 + if (y_a < 0) break 1332 + drawScanLine(pixels, y_b, color, x_b shr 16, x_c shr 16) 1333 + x_c += x_a_off 1334 + x_b += x_b_off 1335 + y_b += width 1336 + } 1337 + 1338 + while (true) { 1339 + y_c-- 1340 + if (y_c < 0) break 1341 + drawScanLine(pixels, y_b, color, x_b shr 16, x_a shr 16) 1342 + x_a += x_c_off 1343 + x_b += x_b_off 1344 + y_b += width 1345 + } 1346 + return 1347 + } 1348 + if (y_c >= bottomY) { 1349 + return 1350 + } 1351 + if (y_a > bottomY) { 1352 + y_a = bottomY 1353 + } 1354 + if (y_b > bottomY) { 1355 + y_b = bottomY 1356 + } 1357 + if (y_a < y_b) { 1358 + x_c = x_c shl 16; x_b = x_c 1359 + if (y_c < 0) { 1360 + x_b -= x_b_off * y_c 1361 + x_c -= x_c_off * y_c 1362 + y_c = 0 1363 + } 1364 + x_a = x_a shl 16 1365 + if (y_a < 0) { 1366 + x_a -= x_a_off * y_a 1367 + y_a = 0 1368 + } 1369 + if (x_b_off < x_c_off) { 1370 + y_b -= y_a 1371 + y_a -= y_c 1372 + y_c = lineOffsets!![y_c] 1373 + while (true) { 1374 + y_a-- 1375 + if (y_a < 0) break 1376 + drawScanLine(pixels, y_c, color, x_b shr 16, x_c shr 16) 1377 + x_b += x_b_off 1378 + x_c += x_c_off 1379 + y_c += width 1380 + } 1381 + 1382 + while (true) { 1383 + y_b-- 1384 + if (y_b < 0) break 1385 + drawScanLine(pixels, y_c, color, x_b shr 16, x_a shr 16) 1386 + x_b += x_b_off 1387 + x_a += x_a_off 1388 + y_c += width 1389 + } 1390 + return 1391 + } 1392 + y_b -= y_a 1393 + y_a -= y_c 1394 + y_c = lineOffsets!![y_c] 1395 + while (true) { 1396 + y_a-- 1397 + if (y_a < 0) break 1398 + drawScanLine(pixels, y_c, color, x_c shr 16, x_b shr 16) 1399 + x_b += x_b_off 1400 + x_c += x_c_off 1401 + y_c += width 1402 + } 1403 + 1404 + while (true) { 1405 + y_b-- 1406 + if (y_b < 0) break 1407 + drawScanLine(pixels, y_c, color, x_a shr 16, x_b shr 16) 1408 + x_b += x_b_off 1409 + x_a += x_a_off 1410 + y_c += width 1411 + } 1412 + return 1413 + } 1414 + x_c = x_c shl 16; x_a = x_c 1415 + if (y_c < 0) { 1416 + x_a -= x_b_off * y_c 1417 + x_c -= x_c_off * y_c 1418 + y_c = 0 1419 + } 1420 + x_b = x_b shl 16 1421 + if (y_b < 0) { 1422 + x_b -= x_a_off * y_b 1423 + y_b = 0 1424 + } 1425 + if (x_b_off < x_c_off) { 1426 + y_a -= y_b 1427 + y_b -= y_c 1428 + y_c = lineOffsets!![y_c] 1429 + while (true) { 1430 + y_b-- 1431 + if (y_b < 0) break 1432 + drawScanLine(pixels, y_c, color, x_a shr 16, x_c shr 16) 1433 + x_a += x_b_off 1434 + x_c += x_c_off 1435 + y_c += width 1436 + } 1437 + 1438 + while (true) { 1439 + y_a-- 1440 + if (y_a < 0) break 1441 + drawScanLine(pixels, y_c, color, x_b shr 16, x_c shr 16) 1442 + x_b += x_a_off 1443 + x_c += x_c_off 1444 + y_c += width 1445 + } 1446 + return 1447 + } 1448 + y_a -= y_b 1449 + y_b -= y_c 1450 + y_c = lineOffsets!![y_c] 1451 + while (true) { 1452 + y_b-- 1453 + if (y_b < 0) break 1454 + drawScanLine(pixels, y_c, color, x_c shr 16, x_a shr 16) 1455 + x_a += x_b_off 1456 + x_c += x_c_off 1457 + y_c += width 1458 + } 1459 + 1460 + while (true) { 1461 + y_a-- 1462 + if (y_a < 0) break 1463 + drawScanLine(pixels, y_c, color, x_c shr 16, x_b shr 16) 1464 + x_b += x_a_off 1465 + x_c += x_c_off 1466 + y_c += width 1467 + } 1468 + } 1469 + 1470 + @JvmStatic 1471 + fun drawScanLine(dest: IntArray, dest_off: Int, loops: Int, start_x: Int, end_x: Int) { 1472 + @Suppress("NAME_SHADOWING") 1473 + var dest_off = dest_off 1474 + @Suppress("NAME_SHADOWING") 1475 + var loops = loops 1476 + @Suppress("NAME_SHADOWING") 1477 + var start_x = start_x 1478 + @Suppress("NAME_SHADOWING") 1479 + var end_x = end_x 1480 + var rgb: Int //was parameter 1481 + if (restrict_edges) { 1482 + if (end_x > viewportRx) { 1483 + end_x = viewportRx 1484 + } 1485 + if (start_x < 0) { 1486 + start_x = 0 1487 + } 1488 + } 1489 + if (start_x >= end_x) { 1490 + return 1491 + } 1492 + dest_off += start_x 1493 + rgb = (end_x - start_x) shr 2 1494 + if (alpha == 0) { 1495 + while (true) { 1496 + rgb-- 1497 + if (rgb < 0) break 1498 + dest[dest_off] = loops; dest_off++ 1499 + dest[dest_off] = loops; dest_off++ 1500 + dest[dest_off] = loops; dest_off++ 1501 + dest[dest_off] = loops; dest_off++ 1502 + } 1503 + rgb = (end_x - start_x) and 3 1504 + while (true) { 1505 + rgb-- 1506 + if (rgb < 0) break 1507 + dest[dest_off] = loops; dest_off++ 1508 + } 1509 + 1510 + return 1511 + } 1512 + val dest_alpha = alpha 1513 + val src_alpha = 256 - alpha 1514 + loops = ((((loops and 0xff00ff) * src_alpha) shr 8) and 0xff00ff) + ((((loops and 0xff00) * src_alpha) shr 8) and 0xff00) 1515 + while (true) { //alpha channel fix 1516 + rgb-- 1517 + if (rgb < 0) break 1518 + dest[dest_off] = loops + ((((dest[dest_off] and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((dest[dest_off] and 0xff00) * dest_alpha) shr 8) and 0xff00) 1519 + dest_off++ 1520 + dest[dest_off] = loops + ((((dest[dest_off] and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((dest[dest_off] and 0xff00) * dest_alpha) shr 8) and 0xff00) 1521 + dest_off++ 1522 + dest[dest_off] = loops + ((((dest[dest_off] and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((dest[dest_off] and 0xff00) * dest_alpha) shr 8) and 0xff00) 1523 + dest_off++ 1524 + dest[dest_off] = loops + ((((dest[dest_off] and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((dest[dest_off] and 0xff00) * dest_alpha) shr 8) and 0xff00) 1525 + dest_off++ 1526 + } 1527 + rgb = (end_x - start_x) and 3 1528 + while (true) { 1529 + rgb-- 1530 + if (rgb < 0) break 1531 + dest[dest_off] = loops + ((((dest[dest_off] and 0xff00ff) * dest_alpha) shr 8) and 0xff00ff) + ((((dest[dest_off] and 0xff00) * dest_alpha) shr 8) and 0xff00) 1532 + dest_off++ 1533 + } 1534 + } 1535 + 1536 + @JvmStatic 1537 + fun drawTexturedTriangle( 1538 + y_a: Int, y_b: Int, y_c: Int, x_a: Int, x_b: Int, x_c: Int, 1539 + grad_a: Int, grad_b: Int, grad_c: Int, Px: Int, Mx: Int, 1540 + Nx: Int, Pz: Int, Mz: Int, Nz: Int, Py: Int, My: Int, Ny: Int, t_id: Int 1541 + ) { 1542 + @Suppress("NAME_SHADOWING") 1543 + var y_a = y_a 1544 + @Suppress("NAME_SHADOWING") 1545 + var y_b = y_b 1546 + @Suppress("NAME_SHADOWING") 1547 + var y_c = y_c 1548 + @Suppress("NAME_SHADOWING") 1549 + var x_a = x_a 1550 + @Suppress("NAME_SHADOWING") 1551 + var x_b = x_b 1552 + @Suppress("NAME_SHADOWING") 1553 + var x_c = x_c 1554 + @Suppress("NAME_SHADOWING") 1555 + var grad_a = grad_a 1556 + @Suppress("NAME_SHADOWING") 1557 + var grad_b = grad_b 1558 + @Suppress("NAME_SHADOWING") 1559 + var grad_c = grad_c 1560 + @Suppress("NAME_SHADOWING") 1561 + var Mx = Mx 1562 + @Suppress("NAME_SHADOWING") 1563 + var Mz = Mz 1564 + @Suppress("NAME_SHADOWING") 1565 + var Nx = Nx 1566 + @Suppress("NAME_SHADOWING") 1567 + var Nz = Nz 1568 + @Suppress("NAME_SHADOWING") 1569 + var My = My 1570 + @Suppress("NAME_SHADOWING") 1571 + var Ny = Ny 1572 + 1573 + val texture = getTexturePixels(t_id) 1574 + opaque = !textureIsTransparent!![t_id] 1575 + Mx = Px - Mx 1576 + Mz = Pz - Mz 1577 + My = Py - My 1578 + Nx -= Px 1579 + Nz -= Pz 1580 + Ny -= Py 1581 + var Oa = ((Nx * Pz) - (Nz * Px)) shl 14 1582 + var Ha = ((Nz * Py) - (Ny * Pz)) shl 8 1583 + var Va = ((Ny * Px) - (Nx * Py)) shl 5 1584 + var Ob = ((Mx * Pz) - (Mz * Px)) shl 14 1585 + var Hb = ((Mz * Py) - (My * Pz)) shl 8 1586 + var Vb = ((My * Px) - (Mx * Py)) shl 5 1587 + var Oc = ((Mz * Nx) - (Mx * Nz)) shl 14 1588 + var Hc = ((My * Nz) - (Mz * Ny)) shl 8 1589 + var Vc = ((Mx * Ny) - (My * Nx)) shl 5 1590 + var x_a_off = 0 1591 + var grad_a_off = 0 1592 + if (y_b != y_a) { 1593 + x_a_off = ((x_b - x_a) shl 16) / (y_b - y_a) 1594 + grad_a_off = ((grad_b - grad_a) shl 16) / (y_b - y_a) 1595 + } 1596 + var x_b_off = 0 1597 + var grad_b_off = 0 1598 + if (y_c != y_b) { 1599 + x_b_off = ((x_c - x_b) shl 16) / (y_c - y_b) 1600 + grad_b_off = ((grad_c - grad_b) shl 16) / (y_c - y_b) 1601 + } 1602 + var x_c_off = 0 1603 + var grad_c_off = 0 1604 + if (y_c != y_a) { 1605 + x_c_off = ((x_a - x_c) shl 16) / (y_a - y_c) 1606 + grad_c_off = ((grad_a - grad_c) shl 16) / (y_a - y_c) 1607 + } 1608 + if (y_a <= y_b && y_a <= y_c) { 1609 + if (y_a >= bottomY) { 1610 + return 1611 + } 1612 + if (y_b > bottomY) { 1613 + y_b = bottomY 1614 + } 1615 + if (y_c > bottomY) { 1616 + y_c = bottomY 1617 + } 1618 + if (y_b < y_c) { 1619 + x_a = x_a shl 16; x_c = x_a 1620 + grad_a = grad_a shl 16; grad_c = grad_a 1621 + if (y_a < 0) { 1622 + x_c -= x_c_off * y_a 1623 + x_a -= x_a_off * y_a 1624 + grad_c -= grad_c_off * y_a 1625 + grad_a -= grad_a_off * y_a 1626 + y_a = 0 1627 + } 1628 + x_b = x_b shl 16 1629 + grad_b = grad_b shl 16 1630 + if (y_b < 0) { 1631 + x_b -= x_b_off * y_b 1632 + grad_b -= grad_b_off * y_b 1633 + y_b = 0 1634 + } 1635 + val jA = y_a - center_y 1636 + Oa += Va * jA 1637 + Ob += Vb * jA 1638 + Oc += Vc * jA 1639 + if (y_a != y_b && x_c_off < x_a_off || y_a == y_b && x_c_off > x_b_off) { 1640 + y_c -= y_b 1641 + y_b -= y_a 1642 + y_a = lineOffsets!![y_a] 1643 + while (true) { 1644 + y_b-- 1645 + if (y_b < 0) break 1646 + drawTexturedLine(pixels, texture, y_a, x_c shr 16, x_a shr 16, grad_c shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1647 + x_c += x_c_off 1648 + x_a += x_a_off 1649 + grad_c += grad_c_off 1650 + grad_a += grad_a_off 1651 + y_a += width 1652 + Oa += Va 1653 + Ob += Vb 1654 + Oc += Vc 1655 + } 1656 + while (true) { 1657 + y_c-- 1658 + if (y_c < 0) break 1659 + drawTexturedLine(pixels, texture, y_a, x_c shr 16, x_b shr 16, grad_c shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1660 + x_c += x_c_off 1661 + x_b += x_b_off 1662 + grad_c += grad_c_off 1663 + grad_b += grad_b_off 1664 + y_a += width 1665 + Oa += Va 1666 + Ob += Vb 1667 + Oc += Vc 1668 + } 1669 + return 1670 + } 1671 + y_c -= y_b 1672 + y_b -= y_a 1673 + y_a = lineOffsets!![y_a] 1674 + while (true) { 1675 + y_b-- 1676 + if (y_b < 0) break 1677 + drawTexturedLine(pixels, texture, y_a, x_a shr 16, x_c shr 16, grad_a shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1678 + x_c += x_c_off 1679 + x_a += x_a_off 1680 + grad_c += grad_c_off 1681 + grad_a += grad_a_off 1682 + y_a += width 1683 + Oa += Va 1684 + Ob += Vb 1685 + Oc += Vc 1686 + } 1687 + while (true) { 1688 + y_c-- 1689 + if (y_c < 0) break 1690 + drawTexturedLine(pixels, texture, y_a, x_b shr 16, x_c shr 16, grad_b shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1691 + x_c += x_c_off 1692 + x_b += x_b_off 1693 + grad_c += grad_c_off 1694 + grad_b += grad_b_off 1695 + y_a += width 1696 + Oa += Va 1697 + Ob += Vb 1698 + Oc += Vc 1699 + } 1700 + return 1701 + } 1702 + x_a = x_a shl 16; x_b = x_a 1703 + grad_a = grad_a shl 16; grad_b = grad_a 1704 + if (y_a < 0) { 1705 + x_b -= x_c_off * y_a 1706 + x_a -= x_a_off * y_a 1707 + grad_b -= grad_c_off * y_a 1708 + grad_a -= grad_a_off * y_a 1709 + y_a = 0 1710 + } 1711 + x_c = x_c shl 16 1712 + grad_c = grad_c shl 16 1713 + if (y_c < 0) { 1714 + x_c -= x_b_off * y_c 1715 + grad_c -= grad_b_off * y_c 1716 + y_c = 0 1717 + } 1718 + val l8 = y_a - center_y 1719 + Oa += Va * l8 1720 + Ob += Vb * l8 1721 + Oc += Vc * l8 1722 + if (y_a != y_c && x_c_off < x_a_off || y_a == y_c && x_b_off > x_a_off) { 1723 + y_b -= y_c 1724 + y_c -= y_a 1725 + y_a = lineOffsets!![y_a] 1726 + while (true) { 1727 + y_c-- 1728 + if (y_c < 0) break 1729 + drawTexturedLine(pixels, texture, y_a, x_b shr 16, x_a shr 16, grad_b shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1730 + x_b += x_c_off 1731 + x_a += x_a_off 1732 + grad_b += grad_c_off 1733 + grad_a += grad_a_off 1734 + y_a += width 1735 + Oa += Va 1736 + Ob += Vb 1737 + Oc += Vc 1738 + } 1739 + while (true) { 1740 + y_b-- 1741 + if (y_b < 0) break 1742 + drawTexturedLine(pixels, texture, y_a, x_c shr 16, x_a shr 16, grad_c shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1743 + x_c += x_b_off 1744 + x_a += x_a_off 1745 + grad_c += grad_b_off 1746 + grad_a += grad_a_off 1747 + y_a += width 1748 + Oa += Va 1749 + Ob += Vb 1750 + Oc += Vc 1751 + } 1752 + return 1753 + } 1754 + y_b -= y_c 1755 + y_c -= y_a 1756 + y_a = lineOffsets!![y_a] 1757 + while (true) { 1758 + y_c-- 1759 + if (y_c < 0) break 1760 + drawTexturedLine(pixels, texture, y_a, x_a shr 16, x_b shr 16, grad_a shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1761 + x_b += x_c_off 1762 + x_a += x_a_off 1763 + grad_b += grad_c_off 1764 + grad_a += grad_a_off 1765 + y_a += width 1766 + Oa += Va 1767 + Ob += Vb 1768 + Oc += Vc 1769 + } 1770 + while (true) { 1771 + y_b-- 1772 + if (y_b < 0) break 1773 + drawTexturedLine(pixels, texture, y_a, x_a shr 16, x_c shr 16, grad_a shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1774 + x_c += x_b_off 1775 + x_a += x_a_off 1776 + grad_c += grad_b_off 1777 + grad_a += grad_a_off 1778 + y_a += width 1779 + Oa += Va 1780 + Ob += Vb 1781 + Oc += Vc 1782 + } 1783 + return 1784 + } 1785 + if (y_b <= y_c) { 1786 + if (y_b >= bottomY) { 1787 + return 1788 + } 1789 + if (y_c > bottomY) { 1790 + y_c = bottomY 1791 + } 1792 + if (y_a > bottomY) { 1793 + y_a = bottomY 1794 + } 1795 + if (y_c < y_a) { 1796 + x_b = x_b shl 16; x_a = x_b 1797 + grad_b = grad_b shl 16; grad_a = grad_b 1798 + if (y_b < 0) { 1799 + x_a -= x_a_off * y_b 1800 + x_b -= x_b_off * y_b 1801 + grad_a -= grad_a_off * y_b 1802 + grad_b -= grad_b_off * y_b 1803 + y_b = 0 1804 + } 1805 + x_c = x_c shl 16 1806 + grad_c = grad_c shl 16 1807 + if (y_c < 0) { 1808 + x_c -= x_c_off * y_c 1809 + grad_c -= grad_c_off * y_c 1810 + y_c = 0 1811 + } 1812 + val i9 = y_b - center_y 1813 + Oa += Va * i9 1814 + Ob += Vb * i9 1815 + Oc += Vc * i9 1816 + if (y_b != y_c && x_a_off < x_b_off || y_b == y_c && x_a_off > x_c_off) { 1817 + y_a -= y_c 1818 + y_c -= y_b 1819 + y_b = lineOffsets!![y_b] 1820 + while (true) { 1821 + y_c-- 1822 + if (y_c < 0) break 1823 + drawTexturedLine(pixels, texture, y_b, x_a shr 16, x_b shr 16, grad_a shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1824 + x_a += x_a_off 1825 + x_b += x_b_off 1826 + grad_a += grad_a_off 1827 + grad_b += grad_b_off 1828 + y_b += width 1829 + Oa += Va 1830 + Ob += Vb 1831 + Oc += Vc 1832 + } 1833 + while (true) { 1834 + y_a-- 1835 + if (y_a < 0) break 1836 + drawTexturedLine(pixels, texture, y_b, x_a shr 16, x_c shr 16, grad_a shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1837 + x_a += x_a_off 1838 + x_c += x_c_off 1839 + grad_a += grad_a_off 1840 + grad_c += grad_c_off 1841 + y_b += width 1842 + Oa += Va 1843 + Ob += Vb 1844 + Oc += Vc 1845 + } 1846 + return 1847 + } 1848 + y_a -= y_c 1849 + y_c -= y_b 1850 + y_b = lineOffsets!![y_b] 1851 + while (true) { 1852 + y_c-- 1853 + if (y_c < 0) break 1854 + drawTexturedLine(pixels, texture, y_b, x_b shr 16, x_a shr 16, grad_b shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1855 + x_a += x_a_off 1856 + x_b += x_b_off 1857 + grad_a += grad_a_off 1858 + grad_b += grad_b_off 1859 + y_b += width 1860 + Oa += Va 1861 + Ob += Vb 1862 + Oc += Vc 1863 + } 1864 + while (true) { 1865 + y_a-- 1866 + if (y_a < 0) break 1867 + drawTexturedLine(pixels, texture, y_b, x_c shr 16, x_a shr 16, grad_c shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1868 + x_a += x_a_off 1869 + x_c += x_c_off 1870 + grad_a += grad_a_off 1871 + grad_c += grad_c_off 1872 + y_b += width 1873 + Oa += Va 1874 + Ob += Vb 1875 + Oc += Vc 1876 + } 1877 + return 1878 + } 1879 + x_b = x_b shl 16; x_c = x_b 1880 + grad_b = grad_b shl 16; grad_c = grad_b 1881 + if (y_b < 0) { 1882 + x_c -= x_a_off * y_b 1883 + x_b -= x_b_off * y_b 1884 + grad_c -= grad_a_off * y_b 1885 + grad_b -= grad_b_off * y_b 1886 + y_b = 0 1887 + } 1888 + x_a = x_a shl 16 1889 + grad_a = grad_a shl 16 1890 + if (y_a < 0) { 1891 + x_a -= x_c_off * y_a 1892 + grad_a -= grad_c_off * y_a 1893 + y_a = 0 1894 + } 1895 + val j9 = y_b - center_y 1896 + Oa += Va * j9 1897 + Ob += Vb * j9 1898 + Oc += Vc * j9 1899 + if (x_a_off < x_b_off) { 1900 + y_c -= y_a 1901 + y_a -= y_b 1902 + y_b = lineOffsets!![y_b] 1903 + while (true) { 1904 + y_a-- 1905 + if (y_a < 0) break 1906 + drawTexturedLine(pixels, texture, y_b, x_c shr 16, x_b shr 16, grad_c shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1907 + x_c += x_a_off 1908 + x_b += x_b_off 1909 + grad_c += grad_a_off 1910 + grad_b += grad_b_off 1911 + y_b += width 1912 + Oa += Va 1913 + Ob += Vb 1914 + Oc += Vc 1915 + } 1916 + while (true) { 1917 + y_c-- 1918 + if (y_c < 0) break 1919 + drawTexturedLine(pixels, texture, y_b, x_a shr 16, x_b shr 16, grad_a shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1920 + x_a += x_c_off 1921 + x_b += x_b_off 1922 + grad_a += grad_c_off 1923 + grad_b += grad_b_off 1924 + y_b += width 1925 + Oa += Va 1926 + Ob += Vb 1927 + Oc += Vc 1928 + } 1929 + return 1930 + } 1931 + y_c -= y_a 1932 + y_a -= y_b 1933 + y_b = lineOffsets!![y_b] 1934 + while (true) { 1935 + y_a-- 1936 + if (y_a < 0) break 1937 + drawTexturedLine(pixels, texture, y_b, x_b shr 16, x_c shr 16, grad_b shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1938 + x_c += x_a_off 1939 + x_b += x_b_off 1940 + grad_c += grad_a_off 1941 + grad_b += grad_b_off 1942 + y_b += width 1943 + Oa += Va 1944 + Ob += Vb 1945 + Oc += Vc 1946 + } 1947 + while (true) { 1948 + y_c-- 1949 + if (y_c < 0) break 1950 + drawTexturedLine(pixels, texture, y_b, x_b shr 16, x_a shr 16, grad_b shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 1951 + x_a += x_c_off 1952 + x_b += x_b_off 1953 + grad_a += grad_c_off 1954 + grad_b += grad_b_off 1955 + y_b += width 1956 + Oa += Va 1957 + Ob += Vb 1958 + Oc += Vc 1959 + } 1960 + return 1961 + } 1962 + if (y_c >= bottomY) { 1963 + return 1964 + } 1965 + if (y_a > bottomY) { 1966 + y_a = bottomY 1967 + } 1968 + if (y_b > bottomY) { 1969 + y_b = bottomY 1970 + } 1971 + if (y_a < y_b) { 1972 + x_c = x_c shl 16; x_b = x_c 1973 + grad_c = grad_c shl 16; grad_b = grad_c 1974 + if (y_c < 0) { 1975 + x_b -= x_b_off * y_c 1976 + x_c -= x_c_off * y_c 1977 + grad_b -= grad_b_off * y_c 1978 + grad_c -= grad_c_off * y_c 1979 + y_c = 0 1980 + } 1981 + x_a = x_a shl 16 1982 + grad_a = grad_a shl 16 1983 + if (y_a < 0) { 1984 + x_a -= x_a_off * y_a 1985 + grad_a -= grad_a_off * y_a 1986 + y_a = 0 1987 + } 1988 + val k9 = y_c - center_y 1989 + Oa += Va * k9 1990 + Ob += Vb * k9 1991 + Oc += Vc * k9 1992 + if (x_b_off < x_c_off) { 1993 + y_b -= y_a 1994 + y_a -= y_c 1995 + y_c = lineOffsets!![y_c] 1996 + while (true) { 1997 + y_a-- 1998 + if (y_a < 0) break 1999 + drawTexturedLine(pixels, texture, y_c, x_b shr 16, x_c shr 16, grad_b shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2000 + x_b += x_b_off 2001 + x_c += x_c_off 2002 + grad_b += grad_b_off 2003 + grad_c += grad_c_off 2004 + y_c += width 2005 + Oa += Va 2006 + Ob += Vb 2007 + Oc += Vc 2008 + } 2009 + while (true) { 2010 + y_b-- 2011 + if (y_b < 0) break 2012 + drawTexturedLine(pixels, texture, y_c, x_b shr 16, x_a shr 16, grad_b shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2013 + x_b += x_b_off 2014 + x_a += x_a_off 2015 + grad_b += grad_b_off 2016 + grad_a += grad_a_off 2017 + y_c += width 2018 + Oa += Va 2019 + Ob += Vb 2020 + Oc += Vc 2021 + } 2022 + return 2023 + } 2024 + y_b -= y_a 2025 + y_a -= y_c 2026 + y_c = lineOffsets!![y_c] 2027 + while (true) { 2028 + y_a-- 2029 + if (y_a < 0) break 2030 + drawTexturedLine(pixels, texture, y_c, x_c shr 16, x_b shr 16, grad_c shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2031 + x_b += x_b_off 2032 + x_c += x_c_off 2033 + grad_b += grad_b_off 2034 + grad_c += grad_c_off 2035 + y_c += width 2036 + Oa += Va 2037 + Ob += Vb 2038 + Oc += Vc 2039 + } 2040 + while (true) { 2041 + y_b-- 2042 + if (y_b < 0) break 2043 + drawTexturedLine(pixels, texture, y_c, x_a shr 16, x_b shr 16, grad_a shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2044 + x_b += x_b_off 2045 + x_a += x_a_off 2046 + grad_b += grad_b_off 2047 + grad_a += grad_a_off 2048 + y_c += width 2049 + Oa += Va 2050 + Ob += Vb 2051 + Oc += Vc 2052 + } 2053 + return 2054 + } 2055 + x_c = x_c shl 16; x_a = x_c 2056 + grad_c = grad_c shl 16; grad_a = grad_c 2057 + if (y_c < 0) { 2058 + x_a -= x_b_off * y_c 2059 + x_c -= x_c_off * y_c 2060 + grad_a -= grad_b_off * y_c 2061 + grad_c -= grad_c_off * y_c 2062 + y_c = 0 2063 + } 2064 + x_b = x_b shl 16 2065 + grad_b = grad_b shl 16 2066 + if (y_b < 0) { 2067 + x_b -= x_a_off * y_b 2068 + grad_b -= grad_a_off * y_b 2069 + y_b = 0 2070 + } 2071 + val l9 = y_c - center_y 2072 + Oa += Va * l9 2073 + Ob += Vb * l9 2074 + Oc += Vc * l9 2075 + if (x_b_off < x_c_off) { 2076 + y_a -= y_b 2077 + y_b -= y_c 2078 + y_c = lineOffsets!![y_c] 2079 + while (true) { 2080 + y_b-- 2081 + if (y_b < 0) break 2082 + drawTexturedLine(pixels, texture, y_c, x_a shr 16, x_c shr 16, grad_a shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2083 + x_a += x_b_off 2084 + x_c += x_c_off 2085 + grad_a += grad_b_off 2086 + grad_c += grad_c_off 2087 + y_c += width 2088 + Oa += Va 2089 + Ob += Vb 2090 + Oc += Vc 2091 + } 2092 + while (true) { 2093 + y_a-- 2094 + if (y_a < 0) break 2095 + drawTexturedLine(pixels, texture, y_c, x_b shr 16, x_c shr 16, grad_b shr 8, grad_c shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2096 + x_b += x_a_off 2097 + x_c += x_c_off 2098 + grad_b += grad_a_off 2099 + grad_c += grad_c_off 2100 + y_c += width 2101 + Oa += Va 2102 + Ob += Vb 2103 + Oc += Vc 2104 + } 2105 + return 2106 + } 2107 + y_a -= y_b 2108 + y_b -= y_c 2109 + y_c = lineOffsets!![y_c] 2110 + while (true) { 2111 + y_b-- 2112 + if (y_b < 0) break 2113 + drawTexturedLine(pixels, texture, y_c, x_c shr 16, x_a shr 16, grad_c shr 8, grad_a shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2114 + x_a += x_b_off 2115 + x_c += x_c_off 2116 + grad_a += grad_b_off 2117 + grad_c += grad_c_off 2118 + y_c += width 2119 + Oa += Va 2120 + Ob += Vb 2121 + Oc += Vc 2122 + } 2123 + while (true) { 2124 + y_a-- 2125 + if (y_a < 0) break 2126 + drawTexturedLine(pixels, texture, y_c, x_c shr 16, x_b shr 16, grad_c shr 8, grad_b shr 8, Oa, Ob, Oc, Ha, Hb, Hc) 2127 + x_b += x_a_off 2128 + x_c += x_c_off 2129 + grad_b += grad_a_off 2130 + grad_c += grad_c_off 2131 + y_c += width 2132 + Oa += Va 2133 + Ob += Vb 2134 + Oc += Vc 2135 + } 2136 + } 2137 + 2138 + @JvmStatic 2139 + fun drawTexturedLine( 2140 + dest: IntArray, texture: IntArray, dest_off: Int, start_x: Int, end_x: Int, shadeValue: Int, 2141 + gradient: Int, arg7: Int, arg8: Int, arg9: Int, arg10: Int, arg11: Int, arg12: Int 2142 + ) { 2143 + @Suppress("NAME_SHADOWING") 2144 + var dest_off = dest_off 2145 + @Suppress("NAME_SHADOWING") 2146 + var start_x = start_x 2147 + @Suppress("NAME_SHADOWING") 2148 + var end_x = end_x 2149 + @Suppress("NAME_SHADOWING") 2150 + var shadeValue = shadeValue 2151 + @Suppress("NAME_SHADOWING") 2152 + var arg7 = arg7 2153 + @Suppress("NAME_SHADOWING") 2154 + var arg8 = arg8 2155 + @Suppress("NAME_SHADOWING") 2156 + var arg9 = arg9 2157 + 2158 + var rgb = 0 2159 + var loops = 0 2160 + if (start_x >= end_x) 2161 + return 2162 + var j3: Int 2163 + var k3: Int 2164 + if (restrict_edges) { 2165 + j3 = (gradient - shadeValue) / (end_x - start_x) 2166 + if (end_x > Rasterizer.viewportRx) 2167 + end_x = Rasterizer.viewportRx 2168 + if (start_x < 0) { 2169 + shadeValue -= start_x * j3 2170 + start_x = 0 2171 + } 2172 + if (start_x >= end_x) 2173 + return 2174 + k3 = (end_x - start_x) shr 3 2175 + j3 = j3 shl 12 2176 + shadeValue = shadeValue shl 9 2177 + } else { 2178 + if (end_x - start_x > 7) { 2179 + k3 = (end_x - start_x) shr 3 2180 + j3 = ((gradient - shadeValue) * shadowDecay!![k3]) shr 6 2181 + } else { 2182 + k3 = 0 2183 + j3 = 0 2184 + } 2185 + shadeValue = shadeValue shl 9 2186 + } 2187 + dest_off += start_x 2188 + if (lowMemory) { 2189 + var i4 = 0 2190 + var k4 = 0 2191 + val k6 = start_x - center_x 2192 + arg7 += ((arg10 shr 3) * k6) 2193 + arg8 += ((arg11 shr 3) * k6) 2194 + arg9 += ((arg12 shr 3) * k6) 2195 + var i5 = arg9 shr 12 2196 + if (i5 != 0) { 2197 + rgb = arg7 / i5 2198 + loops = arg8 / i5 2199 + if (rgb < 0) 2200 + rgb = 0 2201 + else if (rgb > 4032) 2202 + rgb = 4032 2203 + } 2204 + arg7 += arg10 2205 + arg8 += arg11 2206 + arg9 += arg12 2207 + i5 = arg9 shr 12 2208 + if (i5 != 0) { 2209 + i4 = arg7 / i5 2210 + k4 = arg8 / i5 2211 + if (i4 < 7) 2212 + i4 = 7 2213 + else if (i4 > 4032) 2214 + i4 = 4032 2215 + } 2216 + var i7 = (i4 - rgb) shr 3 2217 + var k7 = (k4 - loops) shr 3 2218 + rgb += (shadeValue and 0x600000) shr 3 2219 + var i8 = shadeValue shr 23 2220 + if (opaque) { 2221 + while (k3-- > 0) { 2222 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2223 + rgb += i7 2224 + loops += k7 2225 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2226 + rgb += i7 2227 + loops += k7 2228 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2229 + rgb += i7 2230 + loops += k7 2231 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2232 + rgb += i7 2233 + loops += k7 2234 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2235 + rgb += i7 2236 + loops += k7 2237 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2238 + rgb += i7 2239 + loops += k7 2240 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2241 + rgb += i7 2242 + loops += k7 2243 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2244 + rgb = i4 2245 + loops = k4 2246 + arg7 += arg10 2247 + arg8 += arg11 2248 + arg9 += arg12 2249 + val j5 = arg9 shr 12 2250 + if (j5 != 0) { 2251 + i4 = arg7 / j5 2252 + k4 = arg8 / j5 2253 + if (i4 < 7) 2254 + i4 = 7 2255 + else if (i4 > 4032) 2256 + i4 = 4032 2257 + } 2258 + i7 = (i4 - rgb) shr 3 2259 + k7 = (k4 - loops) shr 3 2260 + shadeValue += j3 2261 + rgb += (shadeValue and 0x600000) shr 3 2262 + i8 = shadeValue shr 23 2263 + } 2264 + k3 = (end_x - start_x) and 7 2265 + while (k3-- > 0) { 2266 + dest[dest_off] = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8; dest_off++ 2267 + rgb += i7 2268 + loops += k7 2269 + } 2270 + 2271 + return 2272 + } 2273 + while (k3-- > 0) { 2274 + var k8: Int 2275 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2276 + if (k8 != 0) 2277 + dest[dest_off] = k8 2278 + dest_off++ 2279 + rgb += i7 2280 + loops += k7 2281 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2282 + if (k8 != 0) 2283 + dest[dest_off] = k8 2284 + dest_off++ 2285 + rgb += i7 2286 + loops += k7 2287 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2288 + if (k8 != 0) 2289 + dest[dest_off] = k8 2290 + dest_off++ 2291 + rgb += i7 2292 + loops += k7 2293 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2294 + if (k8 != 0) 2295 + dest[dest_off] = k8 2296 + dest_off++ 2297 + rgb += i7 2298 + loops += k7 2299 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2300 + if (k8 != 0) 2301 + dest[dest_off] = k8 2302 + dest_off++ 2303 + rgb += i7 2304 + loops += k7 2305 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2306 + if (k8 != 0) 2307 + dest[dest_off] = k8 2308 + dest_off++ 2309 + rgb += i7 2310 + loops += k7 2311 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2312 + if (k8 != 0) 2313 + dest[dest_off] = k8 2314 + dest_off++ 2315 + rgb += i7 2316 + loops += k7 2317 + k8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2318 + if (k8 != 0) 2319 + dest[dest_off] = k8 2320 + dest_off++ 2321 + rgb = i4 2322 + loops = k4 2323 + arg7 += arg10 2324 + arg8 += arg11 2325 + arg9 += arg12 2326 + val k5 = arg9 shr 12 2327 + if (k5 != 0) { 2328 + i4 = arg7 / k5 2329 + k4 = arg8 / k5 2330 + if (i4 < 7) 2331 + i4 = 7 2332 + else if (i4 > 4032) 2333 + i4 = 4032 2334 + } 2335 + i7 = (i4 - rgb) shr 3 2336 + k7 = (k4 - loops) shr 3 2337 + shadeValue += j3 2338 + rgb += (shadeValue and 0x600000) shr 3 2339 + i8 = shadeValue shr 23 2340 + } 2341 + k3 = (end_x - start_x) and 7 2342 + while (k3-- > 0) { 2343 + val l8: Int 2344 + l8 = texture[((loops and 0xfc0) + (rgb shr 6))] ushr i8 2345 + if (l8 != 0) 2346 + dest[dest_off] = l8 2347 + dest_off++ 2348 + rgb += i7 2349 + loops += k7 2350 + } 2351 + 2352 + return 2353 + } 2354 + var j4 = 0 2355 + var l4 = 0 2356 + val l6 = start_x - center_x 2357 + arg7 += ((arg10 shr 3) * l6) 2358 + arg8 += ((arg11 shr 3) * l6) 2359 + arg9 += ((arg12 shr 3) * l6) 2360 + var l5 = arg9 shr 14 2361 + if (l5 != 0) { 2362 + rgb = arg7 / l5 2363 + loops = arg8 / l5 2364 + if (rgb < 0) 2365 + rgb = 0 2366 + else if (rgb > 16256) 2367 + rgb = 16256 2368 + } 2369 + arg7 += arg10 2370 + arg8 += arg11 2371 + arg9 += arg12 2372 + l5 = arg9 shr 14 2373 + if (l5 != 0) { 2374 + j4 = arg7 / l5 2375 + l4 = arg8 / l5 2376 + if (j4 < 7) 2377 + j4 = 7 2378 + else if (j4 > 16256) 2379 + j4 = 16256 2380 + } 2381 + var j7 = (j4 - rgb) shr 3 2382 + var l7 = (l4 - loops) shr 3 2383 + rgb += shadeValue and 0x600000 2384 + var j8 = shadeValue shr 23 2385 + if (opaque) { 2386 + while (k3-- > 0) { 2387 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2388 + rgb += j7 2389 + loops += l7 2390 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2391 + rgb += j7 2392 + loops += l7 2393 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2394 + rgb += j7 2395 + loops += l7 2396 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2397 + rgb += j7 2398 + loops += l7 2399 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2400 + rgb += j7 2401 + loops += l7 2402 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2403 + rgb += j7 2404 + loops += l7 2405 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2406 + rgb += j7 2407 + loops += l7 2408 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2409 + rgb = j4 2410 + loops = l4 2411 + arg7 += arg10 2412 + arg8 += arg11 2413 + arg9 += arg12 2414 + val i6 = arg9 shr 14 2415 + if (i6 != 0) { 2416 + j4 = arg7 / i6 2417 + l4 = arg8 / i6 2418 + if (j4 < 7) 2419 + j4 = 7 2420 + else if (j4 > 16256) 2421 + j4 = 16256 2422 + } 2423 + j7 = (j4 - rgb) shr 3 2424 + l7 = (l4 - loops) shr 3 2425 + shadeValue += j3 2426 + rgb += shadeValue and 0x600000 2427 + j8 = shadeValue shr 23 2428 + } 2429 + k3 = (end_x - start_x) and 7 2430 + while (k3-- > 0) { 2431 + dest[dest_off] = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8; dest_off++ 2432 + rgb += j7 2433 + loops += l7 2434 + } 2435 + 2436 + return 2437 + } 2438 + while (k3-- > 0) { 2439 + var i9: Int 2440 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2441 + if (i9 != 0) 2442 + dest[dest_off] = i9 2443 + dest_off++ 2444 + rgb += j7 2445 + loops += l7 2446 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2447 + if (i9 != 0) 2448 + dest[dest_off] = i9 2449 + dest_off++ 2450 + rgb += j7 2451 + loops += l7 2452 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2453 + if (i9 != 0) 2454 + dest[dest_off] = i9 2455 + dest_off++ 2456 + rgb += j7 2457 + loops += l7 2458 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2459 + if (i9 != 0) 2460 + dest[dest_off] = i9 2461 + dest_off++ 2462 + rgb += j7 2463 + loops += l7 2464 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2465 + if (i9 != 0) 2466 + dest[dest_off] = i9 2467 + dest_off++ 2468 + rgb += j7 2469 + loops += l7 2470 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2471 + if (i9 != 0) 2472 + dest[dest_off] = i9 2473 + dest_off++ 2474 + rgb += j7 2475 + loops += l7 2476 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2477 + if (i9 != 0) 2478 + dest[dest_off] = i9 2479 + dest_off++ 2480 + rgb += j7 2481 + loops += l7 2482 + i9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2483 + if (i9 != 0) 2484 + dest[dest_off] = i9 2485 + dest_off++ 2486 + rgb = j4 2487 + loops = l4 2488 + arg7 += arg10 2489 + arg8 += arg11 2490 + arg9 += arg12 2491 + val j6 = arg9 shr 14 2492 + if (j6 != 0) { 2493 + j4 = arg7 / j6 2494 + l4 = arg8 / j6 2495 + if (j4 < 7) 2496 + j4 = 7 2497 + else if (j4 > 16256) 2498 + j4 = 16256 2499 + } 2500 + j7 = (j4 - rgb) shr 3 2501 + l7 = (l4 - loops) shr 3 2502 + shadeValue += j3 2503 + rgb += shadeValue and 0x600000 2504 + j8 = shadeValue shr 23 2505 + } 2506 + var l3 = (end_x - start_x) and 7 2507 + while (l3-- > 0) { 2508 + val j9: Int 2509 + j9 = texture[((loops and 0x3f80) + (rgb shr 7))] ushr j8 2510 + if (j9 != 0) 2511 + dest[dest_off] = j9 2512 + dest_off++ 2513 + rgb += j7 2514 + loops += l7 2515 + } 2516 + } 2517 + 2518 + init { 2519 + for (i in 1 until 512) 2520 + shadowDecay!![i] = 32768 / i 2521 + 2522 + for (j in 1 until 2048) 2523 + reciprocal16!![j] = 0x10000 / j 2524 + 2525 + for (k in 0 until 2048) { 2526 + SINE!![k] = (65536.0 * Math.sin(k * 0.0030679614999999999)).toInt() 2527 + COSINE!![k] = (65536.0 * Math.cos(k * 0.0030679614999999999)).toInt() 2528 + } 2529 + } 2530 + } 2531 + }
-1969
src/main/java/com/jagex/runescape/media/renderable/Model.java
··· 1 - package com.jagex.runescape.media.renderable; 2 - 3 - import com.jagex.runescape.net.Buffer; 4 - import com.jagex.runescape.net.requester.Requester; 5 - import com.jagex.runescape.media.*; 6 - 7 - public class Model extends Renderable { 8 - 9 - 10 - public static Model EMPTY_MODEL = new Model(); 11 - private static int[] anIntArray1644 = new int[2000]; 12 - private static int[] anIntArray1645 = new int[2000]; 13 - private static int[] anIntArray1646 = new int[2000]; 14 - private static int[] anIntArray1647 = new int[2000]; 15 - public int vertexCount; 16 - public int[] verticesX; 17 - public int[] verticesY; 18 - public int[] verticesZ; 19 - public int triangleCount; 20 - public int[] trianglePointsX; 21 - public int[] trianglePointsY; 22 - public int[] trianglePointsZ; 23 - private int[] triangleHSLA; 24 - private int[] triangleHSLB; 25 - private int[] triangleHSLC; 26 - public int[] triangleDrawType; 27 - private int[] trianglePriorities; 28 - private int[] triangleAlphaValues; 29 - public int[] triangleColorValues; 30 - private int trianglePriority; 31 - private int texturedTriangleCount; 32 - private int[] texturedTrianglePointsX; 33 - private int[] texturedTrianglePointsY; 34 - private int[] texturedTrianglePointsZ; 35 - private int anInt1668; 36 - public int worldX; 37 - public int worldZ; 38 - public int diagonal2DAboveOrigin; 39 - public int maxY; 40 - private int diagonal3D; 41 - private int diagonal3DAboveOrigin; 42 - public int anInt1675; 43 - private int[] vertexSkins; 44 - private int[] triangleSkinValues; 45 - public int[][] vectorSkin; 46 - public int[][] triangleSkin; 47 - public boolean singleTile = false; 48 - public VertexNormal[] vertexNormalOffset; 49 - private static ModelHeader[] modelHeaders; 50 - public static Requester requester; 51 - private static boolean[] restrictEdges = new boolean[4096]; 52 - private static boolean[] aBooleanArray1685 = new boolean[4096]; 53 - private static int[] vertexScreenX = new int[4096]; 54 - private static int[] vertexScreenY = new int[4096]; 55 - private static int[] vertexScreenZ = new int[4096]; 56 - private static int[] vertexMovedX = new int[4096]; 57 - private static int[] vertexMovedY = new int[4096]; 58 - private static int[] vertexMovedZ = new int[4096]; 59 - private static int[] anIntArray1692 = new int[1500]; 60 - private static int[][] anIntArrayArray1693 = new int[1500][512]; 61 - private static int[] anIntArray1694 = new int[12]; 62 - private static int[][] anIntArrayArray1695 = new int[12][2000]; 63 - private static int[] anIntArray1696 = new int[2000]; 64 - private static int[] anIntArray1697 = new int[2000]; 65 - private static int[] anIntArray1698 = new int[12]; 66 - private static int[] anIntArray1699 = new int[10]; 67 - private static int[] anIntArray1700 = new int[10]; 68 - private static int[] anIntArray1701 = new int[10]; 69 - private static int vertexXModifier; 70 - private static int vertexYModifier; 71 - private static int vertexZModifier; 72 - public static boolean gameScreenClickable; 73 - public static int cursorX; 74 - public static int cursorY; 75 - public static int resourceCount; 76 - public static int[] hoveredHash = new int[1000]; 77 - public static int[] SINE; 78 - public static int[] COSINE; 79 - private static int[] HSLtoRGB; 80 - private static int[] anIntArray1713; 81 - 82 - public Model() { 83 - } 84 - 85 - 86 - public static void reset() { 87 - Model.modelHeaders = null; 88 - Model.restrictEdges = null; 89 - Model.aBooleanArray1685 = null; 90 - Model.vertexScreenX = null; 91 - Model.vertexScreenY = null; 92 - Model.vertexScreenZ = null; 93 - Model.vertexMovedX = null; 94 - Model.vertexMovedY = null; 95 - Model.vertexMovedZ = null; 96 - Model.anIntArray1692 = null; 97 - Model.anIntArrayArray1693 = null; 98 - Model.anIntArray1694 = null; 99 - Model.anIntArrayArray1695 = null; 100 - Model.anIntArray1696 = null; 101 - Model.anIntArray1697 = null; 102 - Model.anIntArray1698 = null; 103 - Model.SINE = null; 104 - Model.COSINE = null; 105 - Model.HSLtoRGB = null; 106 - Model.anIntArray1713 = null; 107 - 108 - } 109 - 110 - public static void init(int modelCount, Requester requester) { 111 - Model.modelHeaders = new ModelHeader[modelCount]; 112 - Model.requester = requester; 113 - } 114 - 115 - public static void loadModelHeader(byte[] modelData, int modelId) { 116 - if (modelData == null) { 117 - ModelHeader modelHeader = modelHeaders[modelId] = new ModelHeader(); 118 - modelHeader.vertexCount = 0; 119 - modelHeader.triangleCount = 0; 120 - modelHeader.texturedTriangleCount = 0; 121 - return; 122 - } 123 - Buffer buffer = new Buffer(modelData); 124 - buffer.currentPosition = modelData.length - 18; 125 - ModelHeader modelHeader = modelHeaders[modelId] = new ModelHeader(); 126 - modelHeader.modelData = modelData; 127 - modelHeader.vertexCount = buffer.getUnsignedShortBE(); 128 - modelHeader.triangleCount = buffer.getUnsignedShortBE(); 129 - modelHeader.texturedTriangleCount = buffer.getUnsignedByte(); 130 - int useTextures = buffer.getUnsignedByte(); 131 - int useTrianglePriority = buffer.getUnsignedByte(); 132 - int useTransparency = buffer.getUnsignedByte(); 133 - int useTriangleSkinning = buffer.getUnsignedByte(); 134 - int useVertexSkinning = buffer.getUnsignedByte(); 135 - int xDataLength = buffer.getUnsignedShortBE(); 136 - int yDataLength = buffer.getUnsignedShortBE(); 137 - int zDataLength = buffer.getUnsignedShortBE(); 138 - int triangleDataLength = buffer.getUnsignedShortBE(); 139 - int offset = 0; 140 - modelHeader.vertexDirectionOffset = offset; 141 - offset += modelHeader.vertexCount; 142 - modelHeader.triangleTypeOffset = offset; 143 - offset += modelHeader.triangleCount; 144 - modelHeader.trianglePriorityOffset = offset; 145 - if (useTrianglePriority == 255) { 146 - offset += modelHeader.triangleCount; 147 - } else { 148 - modelHeader.trianglePriorityOffset = -useTrianglePriority - 1; 149 - } 150 - modelHeader.triangleSkinOffset = offset; 151 - if (useTriangleSkinning == 1) { 152 - offset += modelHeader.triangleCount; 153 - } else { 154 - modelHeader.triangleSkinOffset = -1; 155 - } 156 - modelHeader.texturePointerOffset = offset; 157 - if (useTextures == 1) { 158 - offset += modelHeader.triangleCount; 159 - } else { 160 - modelHeader.texturePointerOffset = -1; 161 - } 162 - modelHeader.vertexSkinOffset = offset; 163 - if (useVertexSkinning == 1) { 164 - offset += modelHeader.vertexCount; 165 - } else { 166 - modelHeader.vertexSkinOffset = -1; 167 - } 168 - modelHeader.triangleAlphaOffset = offset; 169 - if (useTransparency == 1) { 170 - offset += modelHeader.triangleCount; 171 - } else { 172 - modelHeader.triangleAlphaOffset = -1; 173 - } 174 - modelHeader.triangleDataOffset = offset; 175 - offset += triangleDataLength; 176 - modelHeader.colorDataOffset = offset; 177 - offset += modelHeader.triangleCount * 2; 178 - modelHeader.uvMapTriangleOffset = offset; 179 - offset += modelHeader.texturedTriangleCount * 6; 180 - modelHeader.xDataOffset = offset; 181 - offset += xDataLength; 182 - modelHeader.yDataOffset = offset; 183 - offset += yDataLength; 184 - modelHeader.zDataOffset = offset; 185 - offset += zDataLength; 186 - } 187 - 188 - public static void resetModel(int model) { 189 - Model.modelHeaders[model] = null; 190 - } 191 - 192 - public static Model getModel(int model) { 193 - if (Model.modelHeaders == null) { 194 - return null; 195 - } 196 - ModelHeader modelHeader = Model.modelHeaders[model]; 197 - if (modelHeader == null) { 198 - Model.requester.requestModel(model); 199 - return null; 200 - } else { 201 - return new Model(model); 202 - } 203 - } 204 - 205 - public static boolean loaded(int id) { 206 - if (Model.modelHeaders == null) { 207 - return false; 208 - } 209 - ModelHeader modelHeader = Model.modelHeaders[id]; 210 - if (modelHeader == null) { 211 - Model.requester.requestModel(id); 212 - return false; 213 - } else { 214 - return true; 215 - } 216 - } 217 - 218 - 219 - public Model(int modelId) { 220 - ModelHeader modelHeader = modelHeaders[modelId]; 221 - vertexCount = modelHeader.vertexCount; 222 - triangleCount = modelHeader.triangleCount; 223 - texturedTriangleCount = modelHeader.texturedTriangleCount; 224 - verticesX = new int[vertexCount]; 225 - verticesY = new int[vertexCount]; 226 - verticesZ = new int[vertexCount]; 227 - trianglePointsX = new int[triangleCount]; 228 - trianglePointsY = new int[triangleCount]; 229 - trianglePointsZ = new int[triangleCount]; 230 - texturedTrianglePointsX = new int[texturedTriangleCount]; 231 - texturedTrianglePointsY = new int[texturedTriangleCount]; 232 - texturedTrianglePointsZ = new int[texturedTriangleCount]; 233 - if (modelHeader.vertexSkinOffset >= 0) { 234 - vertexSkins = new int[vertexCount]; 235 - } 236 - if (modelHeader.texturePointerOffset >= 0) { 237 - triangleDrawType = new int[triangleCount]; 238 - } 239 - if (modelHeader.trianglePriorityOffset >= 0) { 240 - trianglePriorities = new int[triangleCount]; 241 - } else { 242 - trianglePriority = -modelHeader.trianglePriorityOffset - 1; 243 - } 244 - if (modelHeader.triangleAlphaOffset >= 0) { 245 - triangleAlphaValues = new int[triangleCount]; 246 - } 247 - if (modelHeader.triangleSkinOffset >= 0) { 248 - triangleSkinValues = new int[triangleCount]; 249 - } 250 - triangleColorValues = new int[triangleCount]; 251 - Buffer vertexDirectionOffsetBuffer = new Buffer(modelHeader.modelData); 252 - vertexDirectionOffsetBuffer.currentPosition = modelHeader.vertexDirectionOffset; 253 - Buffer xDataOffsetBuffer = new Buffer(modelHeader.modelData); 254 - xDataOffsetBuffer.currentPosition = modelHeader.xDataOffset; 255 - Buffer yDataOffsetBuffer = new Buffer(modelHeader.modelData); 256 - yDataOffsetBuffer.currentPosition = modelHeader.yDataOffset; 257 - Buffer zDataOffsetBuffer = new Buffer(modelHeader.modelData); 258 - zDataOffsetBuffer.currentPosition = modelHeader.zDataOffset; 259 - Buffer vertexSkinOffsetBuffer = new Buffer(modelHeader.modelData); 260 - vertexSkinOffsetBuffer.currentPosition = modelHeader.vertexSkinOffset; 261 - int baseOffsetX = 0; 262 - int baseOffsetY = 0; 263 - int baseOffsetz = 0; 264 - for (int vertex = 0; vertex < vertexCount; vertex++) { 265 - int flag = vertexDirectionOffsetBuffer.getUnsignedByte(); 266 - int currentOffsetX = 0; 267 - if ((flag & 1) != 0) { 268 - currentOffsetX = xDataOffsetBuffer.getSignedSmart(); 269 - } 270 - int currentOffsetY = 0; 271 - if ((flag & 2) != 0) { 272 - currentOffsetY = yDataOffsetBuffer.getSignedSmart(); 273 - } 274 - int currentOffsetZ = 0; 275 - if ((flag & 4) != 0) { 276 - currentOffsetZ = zDataOffsetBuffer.getSignedSmart(); 277 - } 278 - verticesX[vertex] = baseOffsetX + currentOffsetX; 279 - verticesY[vertex] = baseOffsetY + currentOffsetY; 280 - verticesZ[vertex] = baseOffsetz + currentOffsetZ; 281 - baseOffsetX = verticesX[vertex]; 282 - baseOffsetY = verticesY[vertex]; 283 - baseOffsetz = verticesZ[vertex]; 284 - if (vertexSkins != null) { 285 - vertexSkins[vertex] = vertexSkinOffsetBuffer.getUnsignedByte(); 286 - } 287 - } 288 - 289 - vertexDirectionOffsetBuffer.currentPosition = modelHeader.colorDataOffset; 290 - xDataOffsetBuffer.currentPosition = modelHeader.texturePointerOffset; 291 - yDataOffsetBuffer.currentPosition = modelHeader.trianglePriorityOffset; 292 - zDataOffsetBuffer.currentPosition = modelHeader.triangleAlphaOffset; 293 - vertexSkinOffsetBuffer.currentPosition = modelHeader.triangleSkinOffset; 294 - for (int l1 = 0; l1 < triangleCount; l1++) { 295 - triangleColorValues[l1] = vertexDirectionOffsetBuffer.getUnsignedShortBE(); 296 - if (triangleDrawType != null) { 297 - triangleDrawType[l1] = xDataOffsetBuffer.getUnsignedByte(); 298 - } 299 - if (trianglePriorities != null) { 300 - trianglePriorities[l1] = yDataOffsetBuffer.getUnsignedByte(); 301 - } 302 - if (triangleAlphaValues != null) { 303 - triangleAlphaValues[l1] = zDataOffsetBuffer.getUnsignedByte(); 304 - } 305 - if (triangleSkinValues != null) { 306 - triangleSkinValues[l1] = vertexSkinOffsetBuffer.getUnsignedByte(); 307 - } 308 - } 309 - 310 - vertexDirectionOffsetBuffer.currentPosition = modelHeader.triangleDataOffset; 311 - xDataOffsetBuffer.currentPosition = modelHeader.triangleTypeOffset; 312 - int trianglePointOffsetX = 0; 313 - int trianglePointOffsetY = 0; 314 - int trianglePointOffsetZ = 0; 315 - int offset = 0; 316 - for (int triangle = 0; triangle < triangleCount; triangle++) { 317 - int type = xDataOffsetBuffer.getUnsignedByte(); 318 - if (type == 1) { 319 - trianglePointOffsetX = vertexDirectionOffsetBuffer.getSignedSmart() + offset; 320 - offset = trianglePointOffsetX; 321 - trianglePointOffsetY = vertexDirectionOffsetBuffer.getSignedSmart() + offset; 322 - offset = trianglePointOffsetY; 323 - trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset; 324 - offset = trianglePointOffsetZ; 325 - trianglePointsX[triangle] = trianglePointOffsetX; 326 - trianglePointsY[triangle] = trianglePointOffsetY; 327 - trianglePointsZ[triangle] = trianglePointOffsetZ; 328 - } 329 - if (type == 2) { 330 - trianglePointOffsetY = trianglePointOffsetZ; 331 - trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset; 332 - offset = trianglePointOffsetZ; 333 - trianglePointsX[triangle] = trianglePointOffsetX; 334 - trianglePointsY[triangle] = trianglePointOffsetY; 335 - trianglePointsZ[triangle] = trianglePointOffsetZ; 336 - } 337 - if (type == 3) { 338 - trianglePointOffsetX = trianglePointOffsetZ; 339 - trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset; 340 - offset = trianglePointOffsetZ; 341 - trianglePointsX[triangle] = trianglePointOffsetX; 342 - trianglePointsY[triangle] = trianglePointOffsetY; 343 - trianglePointsZ[triangle] = trianglePointOffsetZ; 344 - } 345 - if (type == 4) { 346 - int oldTrianglePointOffsetX = trianglePointOffsetX; 347 - trianglePointOffsetX = trianglePointOffsetY; 348 - trianglePointOffsetY = oldTrianglePointOffsetX; 349 - trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset; 350 - offset = trianglePointOffsetZ; 351 - trianglePointsX[triangle] = trianglePointOffsetX; 352 - trianglePointsY[triangle] = trianglePointOffsetY; 353 - trianglePointsZ[triangle] = trianglePointOffsetZ; 354 - } 355 - } 356 - 357 - vertexDirectionOffsetBuffer.currentPosition = modelHeader.uvMapTriangleOffset; 358 - for (int triangle = 0; triangle < texturedTriangleCount; triangle++) { 359 - texturedTrianglePointsX[triangle] = vertexDirectionOffsetBuffer.getUnsignedShortBE(); 360 - texturedTrianglePointsY[triangle] = vertexDirectionOffsetBuffer.getUnsignedShortBE(); 361 - texturedTrianglePointsZ[triangle] = vertexDirectionOffsetBuffer.getUnsignedShortBE(); 362 - } 363 - 364 - } 365 - 366 - public Model(int modelCount, Model[] subModels) { 367 - boolean setDrawType = false; 368 - boolean setPriority = false; 369 - boolean setAlpha = false; 370 - boolean setSkins = false; 371 - vertexCount = 0; 372 - triangleCount = 0; 373 - texturedTriangleCount = 0; 374 - trianglePriority = -1; 375 - for (int m = 0; m < modelCount; m++) { 376 - Model model = subModels[m]; 377 - if (model != null) { 378 - vertexCount += model.vertexCount; 379 - triangleCount += model.triangleCount; 380 - texturedTriangleCount += model.texturedTriangleCount; 381 - setDrawType |= model.triangleDrawType != null; 382 - if (model.trianglePriorities == null) { 383 - if (trianglePriority == -1) { 384 - trianglePriority = model.trianglePriority; 385 - } 386 - if (trianglePriority != model.trianglePriority) { 387 - setPriority = true; 388 - } 389 - } else { 390 - setPriority = true; 391 - } 392 - setAlpha |= model.triangleAlphaValues != null; 393 - setSkins |= model.triangleSkinValues != null; 394 - } 395 - } 396 - 397 - verticesX = new int[vertexCount]; 398 - verticesY = new int[vertexCount]; 399 - verticesZ = new int[vertexCount]; 400 - vertexSkins = new int[vertexCount]; 401 - trianglePointsX = new int[triangleCount]; 402 - trianglePointsY = new int[triangleCount]; 403 - trianglePointsZ = new int[triangleCount]; 404 - texturedTrianglePointsX = new int[texturedTriangleCount]; 405 - texturedTrianglePointsY = new int[texturedTriangleCount]; 406 - texturedTrianglePointsZ = new int[texturedTriangleCount]; 407 - if (setDrawType) { 408 - triangleDrawType = new int[triangleCount]; 409 - } 410 - if (setPriority) { 411 - trianglePriorities = new int[triangleCount]; 412 - } 413 - if (setAlpha) { 414 - triangleAlphaValues = new int[triangleCount]; 415 - } 416 - if (setSkins) { 417 - triangleSkinValues = new int[triangleCount]; 418 - } 419 - triangleColorValues = new int[triangleCount]; 420 - vertexCount = 0; 421 - triangleCount = 0; 422 - texturedTriangleCount = 0; 423 - int count = 0; 424 - for (int m = 0; m < modelCount; m++) { 425 - Model model = subModels[m]; 426 - if (model != null) { 427 - for (int triangle = 0; triangle < model.triangleCount; triangle++) { 428 - if (setDrawType) { 429 - if (model.triangleDrawType == null) { 430 - triangleDrawType[triangleCount] = 0; 431 - } else { 432 - int drawType = model.triangleDrawType[triangle]; 433 - if ((drawType & 2) == 2) { 434 - drawType += count << 2; 435 - } 436 - triangleDrawType[triangleCount] = drawType; 437 - } 438 - } 439 - if (setPriority) { 440 - if (model.trianglePriorities == null) { 441 - trianglePriorities[triangleCount] = model.trianglePriority; 442 - } else { 443 - trianglePriorities[triangleCount] = model.trianglePriorities[triangle]; 444 - } 445 - } 446 - if (setAlpha) { 447 - if (model.triangleAlphaValues == null) { 448 - triangleAlphaValues[triangleCount] = 0; 449 - } else { 450 - triangleAlphaValues[triangleCount] = model.triangleAlphaValues[triangle]; 451 - } 452 - } 453 - if (setSkins && model.triangleSkinValues != null) { 454 - triangleSkinValues[triangleCount] = model.triangleSkinValues[triangle]; 455 - } 456 - triangleColorValues[triangleCount] = model.triangleColorValues[triangle]; 457 - trianglePointsX[triangleCount] = getFirstIdenticalVertexIndex(model, 458 - model.trianglePointsX[triangle]); 459 - trianglePointsY[triangleCount] = getFirstIdenticalVertexIndex(model, 460 - model.trianglePointsY[triangle]); 461 - trianglePointsZ[triangleCount] = getFirstIdenticalVertexIndex(model, 462 - model.trianglePointsZ[triangle]); 463 - triangleCount++; 464 - } 465 - 466 - for (int triangle = 0; triangle < model.texturedTriangleCount; triangle++) { 467 - texturedTrianglePointsX[texturedTriangleCount] = getFirstIdenticalVertexIndex(model, 468 - model.texturedTrianglePointsX[triangle]); 469 - texturedTrianglePointsY[texturedTriangleCount] = getFirstIdenticalVertexIndex(model, 470 - model.texturedTrianglePointsY[triangle]); 471 - texturedTrianglePointsZ[texturedTriangleCount] = getFirstIdenticalVertexIndex(model, 472 - model.texturedTrianglePointsZ[triangle]); 473 - texturedTriangleCount++; 474 - } 475 - 476 - count += model.texturedTriangleCount; 477 - } 478 - } 479 - 480 - } 481 - 482 - public Model(Model[] models) { 483 - final int modelCount = 2;// was parameter 484 - boolean flag1 = false; 485 - boolean flag2 = false; 486 - boolean flag3 = false; 487 - boolean flag4 = false; 488 - vertexCount = 0; 489 - triangleCount = 0; 490 - texturedTriangleCount = 0; 491 - trianglePriority = -1; 492 - for (int m = 0; m < modelCount; m++) { 493 - Model model = models[m]; 494 - if (model != null) { 495 - vertexCount += model.vertexCount; 496 - triangleCount += model.triangleCount; 497 - texturedTriangleCount += model.texturedTriangleCount; 498 - flag1 |= model.triangleDrawType != null; 499 - if (model.trianglePriorities != null) { 500 - flag2 = true; 501 - } else { 502 - if (trianglePriority == -1) { 503 - trianglePriority = model.trianglePriority; 504 - } 505 - if (trianglePriority != model.trianglePriority) { 506 - flag2 = true; 507 - } 508 - } 509 - flag3 |= model.triangleAlphaValues != null; 510 - flag4 |= model.triangleColorValues != null; 511 - } 512 - } 513 - 514 - verticesX = new int[vertexCount]; 515 - verticesY = new int[vertexCount]; 516 - verticesZ = new int[vertexCount]; 517 - trianglePointsX = new int[triangleCount]; 518 - trianglePointsY = new int[triangleCount]; 519 - trianglePointsZ = new int[triangleCount]; 520 - triangleHSLA = new int[triangleCount]; 521 - triangleHSLB = new int[triangleCount]; 522 - triangleHSLC = new int[triangleCount]; 523 - texturedTrianglePointsX = new int[texturedTriangleCount]; 524 - texturedTrianglePointsY = new int[texturedTriangleCount]; 525 - texturedTrianglePointsZ = new int[texturedTriangleCount]; 526 - if (flag1) { 527 - triangleDrawType = new int[triangleCount]; 528 - } 529 - if (flag2) { 530 - trianglePriorities = new int[triangleCount]; 531 - } 532 - if (flag3) { 533 - triangleAlphaValues = new int[triangleCount]; 534 - } 535 - if (flag4) { 536 - triangleColorValues = new int[triangleCount]; 537 - } 538 - vertexCount = 0; 539 - triangleCount = 0; 540 - texturedTriangleCount = 0; 541 - int count = 0; 542 - for (int m = 0; m < modelCount; m++) { 543 - Model model = models[m]; 544 - if (model != null) { 545 - int v = vertexCount; 546 - for (int vertex = 0; vertex < model.vertexCount; vertex++) { 547 - verticesX[vertexCount] = model.verticesX[vertex]; 548 - verticesY[vertexCount] = model.verticesY[vertex]; 549 - verticesZ[vertexCount] = model.verticesZ[vertex]; 550 - vertexCount++; 551 - } 552 - 553 - for (int triangle = 0; triangle < model.triangleCount; triangle++) { 554 - trianglePointsX[triangleCount] = model.trianglePointsX[triangle] + v; 555 - trianglePointsY[triangleCount] = model.trianglePointsY[triangle] + v; 556 - trianglePointsZ[triangleCount] = model.trianglePointsZ[triangle] + v; 557 - triangleHSLA[triangleCount] = model.triangleHSLA[triangle]; 558 - triangleHSLB[triangleCount] = model.triangleHSLB[triangle]; 559 - triangleHSLC[triangleCount] = model.triangleHSLC[triangle]; 560 - if (flag1) { 561 - if (model.triangleDrawType == null) { 562 - triangleDrawType[triangleCount] = 0; 563 - } else { 564 - int drawtype = model.triangleDrawType[triangle]; 565 - if ((drawtype & 2) == 2) { 566 - drawtype += count << 2; 567 - } 568 - triangleDrawType[triangleCount] = drawtype; 569 - } 570 - } 571 - if (flag2) { 572 - if (model.trianglePriorities == null) { 573 - trianglePriorities[triangleCount] = model.trianglePriority; 574 - } else { 575 - trianglePriorities[triangleCount] = model.trianglePriorities[triangle]; 576 - } 577 - } 578 - if (flag3) { 579 - if (model.triangleAlphaValues == null) { 580 - triangleAlphaValues[triangleCount] = 0; 581 - } else { 582 - triangleAlphaValues[triangleCount] = model.triangleAlphaValues[triangle]; 583 - } 584 - } 585 - if (flag4 && model.triangleColorValues != null) { 586 - triangleColorValues[triangleCount] = model.triangleColorValues[triangle]; 587 - } 588 - triangleCount++; 589 - } 590 - 591 - for (int triangle = 0; triangle < model.texturedTriangleCount; triangle++) { 592 - texturedTrianglePointsX[texturedTriangleCount] = model.texturedTrianglePointsX[triangle] + v; 593 - texturedTrianglePointsY[texturedTriangleCount] = model.texturedTrianglePointsY[triangle] + v; 594 - texturedTrianglePointsZ[texturedTriangleCount] = model.texturedTrianglePointsZ[triangle] + v; 595 - texturedTriangleCount++; 596 - } 597 - 598 - count += model.texturedTriangleCount; 599 - } 600 - } 601 - 602 - calculateDiagonals(); 603 - } 604 - 605 - public Model(boolean flag2, 606 - Model model, boolean flag3) { 607 - vertexCount = model.vertexCount; 608 - triangleCount = model.triangleCount; 609 - texturedTriangleCount = model.texturedTriangleCount; 610 - verticesX = new int[vertexCount]; 611 - verticesY = new int[vertexCount]; 612 - verticesZ = new int[vertexCount]; 613 - for (int i = 0; i < vertexCount; i++) { 614 - verticesX[i] = model.verticesX[i]; 615 - verticesY[i] = model.verticesY[i]; 616 - verticesZ[i] = model.verticesZ[i]; 617 - } 618 - 619 - 620 - if (flag2) { 621 - triangleColorValues = model.triangleColorValues; 622 - } else { 623 - triangleColorValues = new int[triangleCount]; 624 - System.arraycopy(model.triangleColorValues, 0, triangleColorValues, 0, triangleCount); 625 - 626 - } 627 - if (flag3) { 628 - triangleAlphaValues = model.triangleAlphaValues; 629 - } else { 630 - triangleAlphaValues = new int[triangleCount]; 631 - if (model.triangleAlphaValues == null) { 632 - for (int triangle = 0; triangle < triangleCount; triangle++) { 633 - triangleAlphaValues[triangle] = 0; 634 - } 635 - 636 - } else { 637 - System.arraycopy(model.triangleAlphaValues, 0, triangleAlphaValues, 0, triangleCount); 638 - 639 - } 640 - } 641 - 642 - vertexSkins = model.vertexSkins; 643 - triangleSkinValues = model.triangleSkinValues; 644 - triangleDrawType = model.triangleDrawType; 645 - trianglePointsX = model.trianglePointsX; 646 - trianglePointsY = model.trianglePointsY; 647 - trianglePointsZ = model.trianglePointsZ; 648 - trianglePriorities = model.trianglePriorities; 649 - trianglePriority = model.trianglePriority; 650 - texturedTrianglePointsX = model.texturedTrianglePointsX; 651 - texturedTrianglePointsY = model.texturedTrianglePointsY; 652 - texturedTrianglePointsZ = model.texturedTrianglePointsZ; 653 - } 654 - 655 - public Model(boolean adjustToTerrain, boolean nonFlatShading, Model model) { 656 - vertexCount = model.vertexCount; 657 - triangleCount = model.triangleCount; 658 - texturedTriangleCount = model.texturedTriangleCount; 659 - if (adjustToTerrain) { 660 - verticesY = new int[vertexCount]; 661 - System.arraycopy(model.verticesY, 0, verticesY, 0, vertexCount); 662 - 663 - } else { 664 - verticesY = model.verticesY; 665 - } 666 - if (nonFlatShading) { 667 - triangleHSLA = new int[triangleCount]; 668 - triangleHSLB = new int[triangleCount]; 669 - triangleHSLC = new int[triangleCount]; 670 - for (int triangle = 0; triangle < triangleCount; triangle++) { 671 - triangleHSLA[triangle] = model.triangleHSLA[triangle]; 672 - triangleHSLB[triangle] = model.triangleHSLB[triangle]; 673 - triangleHSLC[triangle] = model.triangleHSLC[triangle]; 674 - } 675 - 676 - triangleDrawType = new int[triangleCount]; 677 - if (model.triangleDrawType == null) { 678 - for (int triangle = 0; triangle < triangleCount; triangle++) { 679 - triangleDrawType[triangle] = 0; 680 - } 681 - 682 - } else { 683 - System.arraycopy(model.triangleDrawType, 0, triangleDrawType, 0, triangleCount); 684 - 685 - } 686 - super.verticesNormal = new VertexNormal[vertexCount]; 687 - for (int vertex = 0; vertex < vertexCount; vertex++) { 688 - VertexNormal vertexNormalNew = super.verticesNormal[vertex] = new VertexNormal(); 689 - VertexNormal vertexNormalOld = model.verticesNormal[vertex]; 690 - vertexNormalNew.x = vertexNormalOld.x; 691 - vertexNormalNew.y = vertexNormalOld.y; 692 - vertexNormalNew.z = vertexNormalOld.z; 693 - vertexNormalNew.magnitude = vertexNormalOld.magnitude; 694 - } 695 - 696 - vertexNormalOffset = model.vertexNormalOffset; 697 - } else { 698 - triangleHSLA = model.triangleHSLA; 699 - triangleHSLB = model.triangleHSLB; 700 - triangleHSLC = model.triangleHSLC; 701 - triangleDrawType = model.triangleDrawType; 702 - } 703 - verticesX = model.verticesX; 704 - verticesZ = model.verticesZ; 705 - triangleColorValues = model.triangleColorValues; 706 - triangleAlphaValues = model.triangleAlphaValues; 707 - trianglePriorities = model.trianglePriorities; 708 - trianglePriority = model.trianglePriority; 709 - trianglePointsX = model.trianglePointsX; 710 - trianglePointsY = model.trianglePointsY; 711 - trianglePointsZ = model.trianglePointsZ; 712 - texturedTrianglePointsX = model.texturedTrianglePointsX; 713 - texturedTrianglePointsY = model.texturedTrianglePointsY; 714 - texturedTrianglePointsZ = model.texturedTrianglePointsZ; 715 - super.modelHeight = model.modelHeight; 716 - maxY = model.maxY; 717 - diagonal2DAboveOrigin = model.diagonal2DAboveOrigin; 718 - diagonal3DAboveOrigin = model.diagonal3DAboveOrigin; 719 - diagonal3D = model.diagonal3D; 720 - worldX = model.worldX; 721 - worldZ = model.worldZ; 722 - anInt1668 = model.anInt1668; 723 - } 724 - 725 - public void replaceWithModel(Model model, boolean replaceAlphaValues) { 726 - vertexCount = model.vertexCount; 727 - triangleCount = model.triangleCount; 728 - texturedTriangleCount = model.texturedTriangleCount; 729 - if (Model.anIntArray1644.length < vertexCount) { 730 - Model.anIntArray1644 = new int[vertexCount + 100]; 731 - Model.anIntArray1645 = new int[vertexCount + 100]; 732 - Model.anIntArray1646 = new int[vertexCount + 100]; 733 - } 734 - verticesX = Model.anIntArray1644; 735 - verticesY = Model.anIntArray1645; 736 - verticesZ = Model.anIntArray1646; 737 - for (int vertex = 0; vertex < vertexCount; vertex++) { 738 - verticesX[vertex] = model.verticesX[vertex]; 739 - verticesY[vertex] = model.verticesY[vertex]; 740 - verticesZ[vertex] = model.verticesZ[vertex]; 741 - } 742 - 743 - if (replaceAlphaValues) { 744 - triangleAlphaValues = model.triangleAlphaValues; 745 - } else { 746 - if (Model.anIntArray1647.length < triangleCount) { 747 - Model.anIntArray1647 = new int[triangleCount + 100]; 748 - } 749 - triangleAlphaValues = Model.anIntArray1647; 750 - if (model.triangleAlphaValues == null) { 751 - for (int triangle = 0; triangle < triangleCount; triangle++) { 752 - triangleAlphaValues[triangle] = 0; 753 - } 754 - 755 - } else { 756 - if (triangleCount >= 0) { 757 - System.arraycopy(model.triangleAlphaValues, 0, triangleAlphaValues, 0, triangleCount); 758 - } 759 - 760 - } 761 - } 762 - triangleDrawType = model.triangleDrawType; 763 - triangleColorValues = model.triangleColorValues; 764 - trianglePriorities = model.trianglePriorities; 765 - trianglePriority = model.trianglePriority; 766 - triangleSkin = model.triangleSkin; 767 - vectorSkin = model.vectorSkin; 768 - trianglePointsX = model.trianglePointsX; 769 - trianglePointsY = model.trianglePointsY; 770 - trianglePointsZ = model.trianglePointsZ; 771 - triangleHSLA = model.triangleHSLA; 772 - triangleHSLB = model.triangleHSLB; 773 - triangleHSLC = model.triangleHSLC; 774 - texturedTrianglePointsX = model.texturedTrianglePointsX; 775 - texturedTrianglePointsY = model.texturedTrianglePointsY; 776 - texturedTrianglePointsZ = model.texturedTrianglePointsZ; 777 - } 778 - 779 - private int getFirstIdenticalVertexIndex(Model model, int vertex) { 780 - int identicalVertexIndex = -1; 781 - int vertexX = model.verticesX[vertex]; 782 - int vertexY = model.verticesY[vertex]; 783 - int vertexZ = model.verticesZ[vertex]; 784 - for (int index = 0; index < vertexCount; index++) { 785 - if (vertexX != verticesX[index] || vertexY != verticesY[index] || vertexZ != verticesZ[index]) { 786 - continue; 787 - } 788 - identicalVertexIndex = index; 789 - break; 790 - } 791 - 792 - if (identicalVertexIndex == -1) { 793 - verticesX[vertexCount] = vertexX; 794 - verticesY[vertexCount] = vertexY; 795 - verticesZ[vertexCount] = vertexZ; 796 - if (model.vertexSkins != null) { 797 - vertexSkins[vertexCount] = model.vertexSkins[vertex]; 798 - } 799 - identicalVertexIndex = vertexCount++; 800 - } 801 - return identicalVertexIndex; 802 - } 803 - 804 - public void calculateDiagonals() { 805 - super.modelHeight = 0; 806 - diagonal2DAboveOrigin = 0; 807 - maxY = 0; 808 - for (int vertex = 0; vertex < vertexCount; vertex++) { 809 - int vertexX = verticesX[vertex]; 810 - int vertexY = verticesY[vertex]; 811 - int vertexZ = verticesZ[vertex]; 812 - if (-vertexY > super.modelHeight) { 813 - super.modelHeight = -vertexY; 814 - } 815 - if (vertexY > maxY) { 816 - maxY = vertexY; 817 - } 818 - int j1 = vertexX * vertexX + vertexZ * vertexZ; 819 - if (j1 > diagonal2DAboveOrigin) { 820 - diagonal2DAboveOrigin = j1; 821 - } 822 - } 823 - 824 - diagonal2DAboveOrigin = (int) (Math.sqrt(diagonal2DAboveOrigin) + 0.98999999999999999D); 825 - diagonal3DAboveOrigin = (int) (Math.sqrt(diagonal2DAboveOrigin * diagonal2DAboveOrigin + super.modelHeight * super.modelHeight) + 0.98999999999999999D); 826 - diagonal3D = diagonal3DAboveOrigin + (int) (Math.sqrt(diagonal2DAboveOrigin * diagonal2DAboveOrigin + maxY * maxY) + 0.98999999999999999D); 827 - } 828 - 829 - public void normalise() { 830 - super.modelHeight = 0; 831 - maxY = 0; 832 - for (int j = 0; j < vertexCount; j++) { 833 - int k = verticesY[j]; 834 - if (-k > super.modelHeight) { 835 - super.modelHeight = -k; 836 - } 837 - if (k > maxY) { 838 - maxY = k; 839 - } 840 - } 841 - 842 - diagonal3DAboveOrigin = (int) (Math.sqrt(diagonal2DAboveOrigin * diagonal2DAboveOrigin + super.modelHeight * super.modelHeight) + 0.98999999999999999D); 843 - diagonal3D = diagonal3DAboveOrigin + (int) (Math.sqrt(diagonal2DAboveOrigin * diagonal2DAboveOrigin + maxY * maxY) + 0.98999999999999999D); 844 - } 845 - 846 - private void calculateDiagonalsAndBounds() { 847 - super.modelHeight = 0; 848 - diagonal2DAboveOrigin = 0; 849 - maxY = 0; 850 - int minX = 32767; 851 - int maxX = -32767; 852 - int maxZ = -32767; 853 - int minZ = 32767; 854 - for (int vertex = 0; vertex < vertexCount; vertex++) { 855 - int x = verticesX[vertex]; 856 - int y = verticesY[vertex]; 857 - int z = verticesZ[vertex]; 858 - if (x < minX) { 859 - minX = x; 860 - } 861 - if (x > maxX) { 862 - maxX = x; 863 - } 864 - if (z < minZ) { 865 - minZ = z; 866 - } 867 - if (z > maxZ) { 868 - maxZ = z; 869 - } 870 - if (-y > super.modelHeight) { 871 - super.modelHeight = -y; 872 - } 873 - if (y > maxY) { 874 - maxY = y; 875 - } 876 - int bounds = x * x + z * z; 877 - if (bounds > diagonal2DAboveOrigin) { 878 - diagonal2DAboveOrigin = bounds; 879 - } 880 - } 881 - 882 - diagonal2DAboveOrigin = (int) Math.sqrt(diagonal2DAboveOrigin); 883 - diagonal3DAboveOrigin = (int) Math.sqrt(diagonal2DAboveOrigin * diagonal2DAboveOrigin + super.modelHeight * super.modelHeight); 884 - diagonal3D = diagonal3DAboveOrigin + (int) Math.sqrt(diagonal2DAboveOrigin * diagonal2DAboveOrigin + maxY * maxY); 885 - worldX = (minX << 16) + (maxX & 0xffff); 886 - worldZ = (maxZ << 16) + (minZ & 0xffff); 887 - } 888 - 889 - public void createBones() { 890 - if (vertexSkins != null) { 891 - int[] ai = new int[256]; 892 - int j = 0; 893 - for (int l = 0; l < vertexCount; l++) { 894 - int j1 = vertexSkins[l]; 895 - ai[j1]++; 896 - if (j1 > j) { 897 - j = j1; 898 - } 899 - } 900 - 901 - vectorSkin = new int[j + 1][]; 902 - for (int k1 = 0; k1 <= j; k1++) { 903 - vectorSkin[k1] = new int[ai[k1]]; 904 - ai[k1] = 0; 905 - } 906 - 907 - for (int j2 = 0; j2 < vertexCount; j2++) { 908 - int l2 = vertexSkins[j2]; 909 - vectorSkin[l2][ai[l2]++] = j2; 910 - } 911 - 912 - vertexSkins = null; 913 - } 914 - if (triangleSkinValues != null) { 915 - int[] ai1 = new int[256]; 916 - int k = 0; 917 - for (int i1 = 0; i1 < triangleCount; i1++) { 918 - int l1 = triangleSkinValues[i1]; 919 - ai1[l1]++; 920 - if (l1 > k) { 921 - k = l1; 922 - } 923 - } 924 - 925 - triangleSkin = new int[k + 1][]; 926 - for (int i2 = 0; i2 <= k; i2++) { 927 - triangleSkin[i2] = new int[ai1[i2]]; 928 - ai1[i2] = 0; 929 - } 930 - 931 - for (int k2 = 0; k2 < triangleCount; k2++) { 932 - int i3 = triangleSkinValues[k2]; 933 - triangleSkin[i3][ai1[i3]++] = k2; 934 - } 935 - 936 - triangleSkinValues = null; 937 - } 938 - } 939 - 940 - public void applyTransform(int frameId) { 941 - if (vectorSkin == null) { 942 - return; 943 - } 944 - if (frameId == -1) { 945 - return; 946 - } 947 - Animation animation = Animation.getAnimation(frameId); 948 - if (animation == null) { 949 - return; 950 - } 951 - Skins skins = animation.animationSkins; 952 - vertexXModifier = 0; 953 - vertexYModifier = 0; 954 - vertexZModifier = 0; 955 - for (int stepId = 0; stepId < animation.anInt433; stepId++) { 956 - int opcode = animation.opcodeTable[stepId]; 957 - transformStep(skins.opcodes[opcode], skins.skinList[opcode], animation.modifier1[stepId], 958 - animation.modifier2[stepId], animation.modifier3[stepId]); 959 - } 960 - 961 - } 962 - 963 - public void mixAnimationFrames(int i, int j, int k, int[] ai) { 964 - if (k == -1) { 965 - return; 966 - } 967 - if (ai == null || i == -1) { 968 - applyTransform(k); 969 - return; 970 - } 971 - Animation animation = Animation.getAnimation(k); 972 - if (animation == null) { 973 - return; 974 - } 975 - Animation animation_1 = Animation.getAnimation(i); 976 - if (animation_1 == null) { 977 - applyTransform(k); 978 - return; 979 - } 980 - Skins skins = animation.animationSkins; 981 - vertexXModifier = 0; 982 - vertexYModifier = 0; 983 - vertexZModifier = 0; 984 - int l = 0; 985 - int i1 = ai[l++]; 986 - for (int j1 = 0; j1 < animation.anInt433; j1++) { 987 - int k1; 988 - for (k1 = animation.opcodeTable[j1]; k1 > i1; i1 = ai[l++]) { 989 - ; 990 - } 991 - if (k1 != i1 || skins.opcodes[k1] == 0) { 992 - transformStep(skins.opcodes[k1], skins.skinList[k1], animation.modifier1[j1], 993 - animation.modifier2[j1], animation.modifier3[j1]); 994 - } 995 - } 996 - 997 - vertexXModifier = 0; 998 - vertexYModifier = 0; 999 - vertexZModifier = 0; 1000 - l = 0; 1001 - i1 = ai[l++]; 1002 - for (int l1 = 0; l1 < animation_1.anInt433; l1++) { 1003 - int i2; 1004 - for (i2 = animation_1.opcodeTable[l1]; i2 > i1; i1 = ai[l++]) { 1005 - ; 1006 - } 1007 - if (i2 == i1 || skins.opcodes[i2] == 0) { 1008 - transformStep(skins.opcodes[i2], skins.skinList[i2], animation_1.modifier1[l1], 1009 - animation_1.modifier2[l1], animation_1.modifier3[l1]); 1010 - } 1011 - } 1012 - 1013 - } 1014 - 1015 - private void transformStep(int i, int[] ai, int j, int k, int l) { 1016 - int i1 = ai.length; 1017 - if (i == 0) { 1018 - int j1 = 0; 1019 - vertexXModifier = 0; 1020 - vertexYModifier = 0; 1021 - vertexZModifier = 0; 1022 - for (int k2 = 0; k2 < i1; k2++) { 1023 - int l3 = ai[k2]; 1024 - if (l3 < vectorSkin.length) { 1025 - int[] ai5 = vectorSkin[l3]; 1026 - for (int i5 = 0; i5 < ai5.length; i5++) { 1027 - int j6 = ai5[i5]; 1028 - vertexXModifier += verticesX[j6]; 1029 - vertexYModifier += verticesY[j6]; 1030 - vertexZModifier += verticesZ[j6]; 1031 - j1++; 1032 - } 1033 - 1034 - } 1035 - } 1036 - 1037 - if (j1 > 0) { 1038 - vertexXModifier = vertexXModifier / j1 + j; 1039 - vertexYModifier = vertexYModifier / j1 + k; 1040 - vertexZModifier = vertexZModifier / j1 + l; 1041 - return; 1042 - } else { 1043 - vertexXModifier = j; 1044 - vertexYModifier = k; 1045 - vertexZModifier = l; 1046 - return; 1047 - } 1048 - } 1049 - if (i == 1) { 1050 - for (int k1 = 0; k1 < i1; k1++) { 1051 - int l2 = ai[k1]; 1052 - if (l2 < vectorSkin.length) { 1053 - int[] ai1 = vectorSkin[l2]; 1054 - for (int i4 = 0; i4 < ai1.length; i4++) { 1055 - int j5 = ai1[i4]; 1056 - verticesX[j5] += j; 1057 - verticesY[j5] += k; 1058 - verticesZ[j5] += l; 1059 - } 1060 - 1061 - } 1062 - } 1063 - 1064 - return; 1065 - } 1066 - if (i == 2) { 1067 - for (int l1 = 0; l1 < i1; l1++) { 1068 - int i3 = ai[l1]; 1069 - if (i3 < vectorSkin.length) { 1070 - int[] ai2 = vectorSkin[i3]; 1071 - for (int j4 = 0; j4 < ai2.length; j4++) { 1072 - int k5 = ai2[j4]; 1073 - verticesX[k5] -= vertexXModifier; 1074 - verticesY[k5] -= vertexYModifier; 1075 - verticesZ[k5] -= vertexZModifier; 1076 - int k6 = (j & 0xff) * 8; 1077 - int l6 = (k & 0xff) * 8; 1078 - int i7 = (l & 0xff) * 8; 1079 - if (i7 != 0) { 1080 - int j7 = SINE[i7]; 1081 - int i8 = COSINE[i7]; 1082 - int l8 = verticesY[k5] * j7 + verticesX[k5] * i8 >> 16; 1083 - verticesY[k5] = verticesY[k5] * i8 - verticesX[k5] * j7 >> 16; 1084 - verticesX[k5] = l8; 1085 - } 1086 - if (k6 != 0) { 1087 - int k7 = SINE[k6]; 1088 - int j8 = COSINE[k6]; 1089 - int i9 = verticesY[k5] * j8 - verticesZ[k5] * k7 >> 16; 1090 - verticesZ[k5] = verticesY[k5] * k7 + verticesZ[k5] * j8 >> 16; 1091 - verticesY[k5] = i9; 1092 - } 1093 - if (l6 != 0) { 1094 - int l7 = SINE[l6]; 1095 - int k8 = COSINE[l6]; 1096 - int j9 = verticesZ[k5] * l7 + verticesX[k5] * k8 >> 16; 1097 - verticesZ[k5] = verticesZ[k5] * k8 - verticesX[k5] * l7 >> 16; 1098 - verticesX[k5] = j9; 1099 - } 1100 - verticesX[k5] += vertexXModifier; 1101 - verticesY[k5] += vertexYModifier; 1102 - verticesZ[k5] += vertexZModifier; 1103 - } 1104 - 1105 - } 1106 - } 1107 - 1108 - return; 1109 - } 1110 - if (i == 3) { 1111 - for (int i2 = 0; i2 < i1; i2++) { 1112 - int j3 = ai[i2]; 1113 - if (j3 < vectorSkin.length) { 1114 - int[] ai3 = vectorSkin[j3]; 1115 - for (int k4 = 0; k4 < ai3.length; k4++) { 1116 - int l5 = ai3[k4]; 1117 - verticesX[l5] -= vertexXModifier; 1118 - verticesY[l5] -= vertexYModifier; 1119 - verticesZ[l5] -= vertexZModifier; 1120 - verticesX[l5] = (verticesX[l5] * j) / 128; 1121 - verticesY[l5] = (verticesY[l5] * k) / 128; 1122 - verticesZ[l5] = (verticesZ[l5] * l) / 128; 1123 - verticesX[l5] += vertexXModifier; 1124 - verticesY[l5] += vertexYModifier; 1125 - verticesZ[l5] += vertexZModifier; 1126 - } 1127 - 1128 - } 1129 - } 1130 - 1131 - return; 1132 - } 1133 - if (i == 5 && triangleSkin != null && triangleAlphaValues != null) { 1134 - for (int j2 = 0; j2 < i1; j2++) { 1135 - int k3 = ai[j2]; 1136 - if (k3 < triangleSkin.length) { 1137 - int[] ai4 = triangleSkin[k3]; 1138 - for (int l4 = 0; l4 < ai4.length; l4++) { 1139 - int i6 = ai4[l4]; 1140 - triangleAlphaValues[i6] += j * 8; 1141 - if (triangleAlphaValues[i6] < 0) { 1142 - triangleAlphaValues[i6] = 0; 1143 - } 1144 - if (triangleAlphaValues[i6] > 255) { 1145 - triangleAlphaValues[i6] = 255; 1146 - } 1147 - } 1148 - 1149 - } 1150 - } 1151 - 1152 - } 1153 - } 1154 - 1155 - public void rotate90Degrees() { 1156 - for (int i = 0; i < vertexCount; i++) { 1157 - int j = verticesX[i]; 1158 - verticesX[i] = verticesZ[i]; 1159 - verticesZ[i] = -j; 1160 - } 1161 - 1162 - } 1163 - 1164 - void rotateX(int i) { 1165 - int k = SINE[i]; 1166 - int l = COSINE[i]; 1167 - for (int i1 = 0; i1 < vertexCount; i1++) { 1168 - int j1 = verticesY[i1] * l - verticesZ[i1] * k >> 16; 1169 - verticesZ[i1] = verticesY[i1] * k + verticesZ[i1] * l >> 16; 1170 - verticesY[i1] = j1; 1171 - } 1172 - 1173 - } 1174 - 1175 - public void translate(int i, int j, int k) { 1176 - for (int l = 0; l < vertexCount; l++) { 1177 - verticesX[l] += i; 1178 - verticesY[l] += k; 1179 - verticesZ[l] += j; 1180 - } 1181 - 1182 - } 1183 - 1184 - public void replaceColor(int oldColor, int newColor) { 1185 - for (int i = 0; i < triangleCount; i++) { 1186 - if (triangleColorValues[i] == oldColor) { 1187 - triangleColorValues[i] = newColor; 1188 - } 1189 - } 1190 - 1191 - } 1192 - 1193 - public void mirror(int i) { 1194 - if (i != 0) { 1195 - for (int j = 1; j > 0; j++) { 1196 - ; 1197 - } 1198 - } 1199 - for (int k = 0; k < vertexCount; k++) { 1200 - verticesZ[k] = -verticesZ[k]; 1201 - } 1202 - 1203 - for (int l = 0; l < triangleCount; l++) { 1204 - int i1 = trianglePointsX[l]; 1205 - trianglePointsX[l] = trianglePointsZ[l]; 1206 - trianglePointsZ[l] = i1; 1207 - } 1208 - 1209 - } 1210 - 1211 - public void scaleT(int i, int j, int k, int l) { 1212 - for (int i1 = 0; i1 < vertexCount; i1++) { 1213 - verticesX[i1] = (verticesX[i1] * l) / 128; 1214 - verticesY[i1] = (verticesY[i1] * i) / 128; 1215 - verticesZ[i1] = (verticesZ[i1] * j) / 128; 1216 - } 1217 - 1218 - } 1219 - 1220 - public void applyLighting(int lightMod, int magnitudeMultiplier, int lightX, int lightY, int lightZ, boolean flatShading) { 1221 - int lightMagnitude = (int) Math.sqrt(lightX * lightX + lightY * lightY + lightZ * lightZ); 1222 - int magnitude = magnitudeMultiplier * lightMagnitude >> 8; 1223 - if (triangleHSLA == null) { 1224 - triangleHSLA = new int[triangleCount]; 1225 - triangleHSLB = new int[triangleCount]; 1226 - triangleHSLC = new int[triangleCount]; 1227 - } 1228 - if (super.verticesNormal == null) { 1229 - super.verticesNormal = new VertexNormal[vertexCount]; 1230 - for (int vertex = 0; vertex < vertexCount; vertex++) { 1231 - super.verticesNormal[vertex] = new VertexNormal(); 1232 - } 1233 - 1234 - } 1235 - for (int triangle = 0; triangle < triangleCount; triangle++) { 1236 - int _triangleX = trianglePointsX[triangle]; 1237 - int _triangleY = trianglePointsY[triangle]; 1238 - int _triangleZ = trianglePointsZ[triangle]; 1239 - int distanceXXY = verticesX[_triangleY] - verticesX[_triangleX]; 1240 - int distanceYXY = verticesY[_triangleY] - verticesY[_triangleX]; 1241 - int distanceZXY = verticesZ[_triangleY] - verticesZ[_triangleX]; 1242 - int distanceXZX = verticesX[_triangleZ] - verticesX[_triangleX]; 1243 - int distanceYZX = verticesY[_triangleZ] - verticesY[_triangleX]; 1244 - int distanceZZX = verticesZ[_triangleZ] - verticesZ[_triangleX]; 1245 - int normalX = distanceYXY * distanceZZX - distanceYZX * distanceZXY; 1246 - int normalY = distanceZXY * distanceXZX - distanceZZX * distanceXXY; 1247 - int normalZ; 1248 - for (normalZ = distanceXXY * distanceYZX - distanceXZX * distanceYXY; normalX > 8192 || normalY > 8192 || normalZ > 8192 || normalX < -8192 || normalY < -8192 || normalZ < -8192; normalZ >>= 1) { 1249 - normalX >>= 1; 1250 - normalY >>= 1; 1251 - } 1252 - 1253 - int normalLength = (int) Math.sqrt(normalX * normalX + normalY * normalY + normalZ * normalZ); 1254 - if (normalLength <= 0) { 1255 - normalLength = 1; 1256 - } 1257 - normalX = (normalX * 256) / normalLength; 1258 - normalY = (normalY * 256) / normalLength; 1259 - normalZ = (normalZ * 256) / normalLength; 1260 - if (triangleDrawType == null || (triangleDrawType[triangle] & 1) == 0) { 1261 - VertexNormal vertexNormal = super.verticesNormal[_triangleX]; 1262 - vertexNormal.x += normalX; 1263 - vertexNormal.y += normalY; 1264 - vertexNormal.z += normalZ; 1265 - vertexNormal.magnitude++; 1266 - vertexNormal = super.verticesNormal[_triangleY]; 1267 - vertexNormal.x += normalX; 1268 - vertexNormal.y += normalY; 1269 - vertexNormal.z += normalZ; 1270 - vertexNormal.magnitude++; 1271 - vertexNormal = super.verticesNormal[_triangleZ]; 1272 - vertexNormal.x += normalX; 1273 - vertexNormal.y += normalY; 1274 - vertexNormal.z += normalZ; 1275 - vertexNormal.magnitude++; 1276 - } else { 1277 - int lightness = lightMod + (lightX * normalX + lightY * normalY + lightZ * normalZ) / (magnitude + magnitude / 2); 1278 - triangleHSLA[triangle] = mixLightness(triangleColorValues[triangle], lightness, triangleDrawType[triangle]); 1279 - } 1280 - } 1281 - 1282 - if (flatShading) { 1283 - handleShading(lightMod, magnitude, lightX, lightY, lightZ); 1284 - } else { 1285 - vertexNormalOffset = new VertexNormal[vertexCount]; 1286 - for (int vertex = 0; vertex < vertexCount; vertex++) { 1287 - VertexNormal vertexNormal = super.verticesNormal[vertex]; 1288 - VertexNormal shadowVertexNormal = vertexNormalOffset[vertex] = new VertexNormal(); 1289 - shadowVertexNormal.x = vertexNormal.x; 1290 - shadowVertexNormal.y = vertexNormal.y; 1291 - shadowVertexNormal.z = vertexNormal.z; 1292 - shadowVertexNormal.magnitude = vertexNormal.magnitude; 1293 - } 1294 - 1295 - anInt1668 = (lightMod << 16) + (magnitude & 0xffff); 1296 - } 1297 - if (flatShading) { 1298 - calculateDiagonals(); 1299 - } else { 1300 - calculateDiagonalsAndBounds(); 1301 - } 1302 - } 1303 - 1304 - public void handleShading(int i, int j, int k, int l) { 1305 - int i1 = anInt1668 >> 16; 1306 - int j1 = (anInt1668 << 16) >> 16; 1307 - handleShading(i1, j1, l, i, j); 1308 - } 1309 - 1310 - private void handleShading(int i, int j, int k, int l, int i1) { 1311 - for (int j1 = 0; j1 < triangleCount; j1++) { 1312 - int k1 = trianglePointsX[j1]; 1313 - int i2 = trianglePointsY[j1]; 1314 - int j2 = trianglePointsZ[j1]; 1315 - if (triangleDrawType == null) { 1316 - int i3 = triangleColorValues[j1]; 1317 - VertexNormal class40 = super.verticesNormal[k1]; 1318 - int k2 = i + (k * class40.x + l * class40.y + i1 * class40.z) 1319 - / (j * class40.magnitude); 1320 - triangleHSLA[j1] = mixLightness(i3, k2, 0); 1321 - class40 = super.verticesNormal[i2]; 1322 - k2 = i + (k * class40.x + l * class40.y + i1 * class40.z) / (j * class40.magnitude); 1323 - triangleHSLB[j1] = mixLightness(i3, k2, 0); 1324 - class40 = super.verticesNormal[j2]; 1325 - k2 = i + (k * class40.x + l * class40.y + i1 * class40.z) / (j * class40.magnitude); 1326 - triangleHSLC[j1] = mixLightness(i3, k2, 0); 1327 - } else if ((triangleDrawType[j1] & 1) == 0) { 1328 - int j3 = triangleColorValues[j1]; 1329 - int k3 = triangleDrawType[j1]; 1330 - VertexNormal class40_1 = super.verticesNormal[k1]; 1331 - int l2 = i + (k * class40_1.x + l * class40_1.y + i1 * class40_1.z) 1332 - / (j * class40_1.magnitude); 1333 - triangleHSLA[j1] = mixLightness(j3, l2, k3); 1334 - class40_1 = super.verticesNormal[i2]; 1335 - l2 = i + (k * class40_1.x + l * class40_1.y + i1 * class40_1.z) 1336 - / (j * class40_1.magnitude); 1337 - triangleHSLB[j1] = mixLightness(j3, l2, k3); 1338 - class40_1 = super.verticesNormal[j2]; 1339 - l2 = i + (k * class40_1.x + l * class40_1.y + i1 * class40_1.z) 1340 - / (j * class40_1.magnitude); 1341 - triangleHSLC[j1] = mixLightness(j3, l2, k3); 1342 - } 1343 - } 1344 - 1345 - super.verticesNormal = null; 1346 - vertexNormalOffset = null; 1347 - vertexSkins = null; 1348 - triangleSkinValues = null; 1349 - if (triangleDrawType != null) { 1350 - for (int l1 = 0; l1 < triangleCount; l1++) { 1351 - if ((triangleDrawType[l1] & 2) == 2) { 1352 - return; 1353 - } 1354 - } 1355 - 1356 - } 1357 - triangleColorValues = null; 1358 - } 1359 - 1360 - private static int mixLightness(int i, int j, int k) { 1361 - if ((k & 2) == 2) { 1362 - if (j < 0) { 1363 - j = 0; 1364 - } else if (j > 127) { 1365 - j = 127; 1366 - } 1367 - j = 127 - j; 1368 - return j; 1369 - } 1370 - j = j * (i & 0x7f) >> 7; 1371 - if (j < 2) { 1372 - j = 2; 1373 - } else if (j > 126) { 1374 - j = 126; 1375 - } 1376 - return (i & 0xff80) + j; 1377 - } 1378 - 1379 - public void render(int i, int j, int k, int l, int i1, int j1, int k1) { 1380 - int l1 = Rasterizer3D.center_x; 1381 - int i2 = Rasterizer3D.center_y; 1382 - int j2 = SINE[i]; 1383 - int k2 = COSINE[i]; 1384 - int l2 = SINE[j]; 1385 - int i3 = COSINE[j]; 1386 - int j3 = SINE[k]; 1387 - int k3 = COSINE[k]; 1388 - int l3 = SINE[l]; 1389 - int i4 = COSINE[l]; 1390 - int j4 = j1 * l3 + k1 * i4 >> 16; 1391 - for (int k4 = 0; k4 < vertexCount; k4++) { 1392 - int l4 = verticesX[k4]; 1393 - int i5 = verticesY[k4]; 1394 - int j5 = verticesZ[k4]; 1395 - if (k != 0) { 1396 - int k5 = i5 * j3 + l4 * k3 >> 16; 1397 - i5 = i5 * k3 - l4 * j3 >> 16; 1398 - l4 = k5; 1399 - } 1400 - if (i != 0) { 1401 - int l5 = i5 * k2 - j5 * j2 >> 16; 1402 - j5 = i5 * j2 + j5 * k2 >> 16; 1403 - i5 = l5; 1404 - } 1405 - if (j != 0) { 1406 - int i6 = j5 * l2 + l4 * i3 >> 16; 1407 - j5 = j5 * i3 - l4 * l2 >> 16; 1408 - l4 = i6; 1409 - } 1410 - l4 += i1; 1411 - i5 += j1; 1412 - j5 += k1; 1413 - int j6 = i5 * i4 - j5 * l3 >> 16; 1414 - j5 = i5 * l3 + j5 * i4 >> 16; 1415 - i5 = j6; 1416 - vertexScreenZ[k4] = j5 - j4; 1417 - vertexScreenX[k4] = l1 + (l4 << 9) / j5; 1418 - vertexScreenY[k4] = i2 + (i5 << 9) / j5; 1419 - if (texturedTriangleCount > 0) { 1420 - vertexMovedX[k4] = l4; 1421 - vertexMovedY[k4] = i5; 1422 - vertexMovedZ[k4] = j5; 1423 - } 1424 - } 1425 - 1426 - try { 1427 - method599(false, false, 0); 1428 - } catch (Exception _ex) { 1429 - } 1430 - } 1431 - 1432 - @Override 1433 - public void renderAtPoint(int i, int j, int k, int l, int i1, int j1, int k1, int l1, int i2) { 1434 - int j2 = l1 * i1 - j1 * l >> 16; 1435 - int k2 = k1 * j + j2 * k >> 16; 1436 - int l2 = diagonal2DAboveOrigin * k >> 16; 1437 - int i3 = k2 + l2; 1438 - if (i3 <= 50 || k2 >= 3500) { 1439 - return; 1440 - } 1441 - int j3 = l1 * l + j1 * i1 >> 16; 1442 - int k3 = j3 - diagonal2DAboveOrigin << 9; 1443 - if (k3 / i3 >= Rasterizer.centerX) { 1444 - return; 1445 - } 1446 - int l3 = j3 + diagonal2DAboveOrigin << 9; 1447 - if (l3 / i3 <= -Rasterizer.centerX) { 1448 - return; 1449 - } 1450 - int i4 = k1 * k - j2 * j >> 16; 1451 - int j4 = diagonal2DAboveOrigin * j >> 16; 1452 - int k4 = i4 + j4 << 9; 1453 - if (k4 / i3 <= -Rasterizer.centerY) { 1454 - return; 1455 - } 1456 - int l4 = j4 + (super.modelHeight * k >> 16); 1457 - int i5 = i4 - l4 << 9; 1458 - if (i5 / i3 >= Rasterizer.centerY) { 1459 - return; 1460 - } 1461 - int j5 = l2 + (super.modelHeight * j >> 16); 1462 - boolean flag = false; 1463 - if (k2 - j5 <= 50) { 1464 - flag = true; 1465 - } 1466 - boolean flag1 = false; 1467 - if (i2 > 0 && gameScreenClickable) { 1468 - int k5 = k2 - l2; 1469 - if (k5 <= 50) { 1470 - k5 = 50; 1471 - } 1472 - if (j3 > 0) { 1473 - k3 /= i3; 1474 - l3 /= k5; 1475 - } else { 1476 - l3 /= i3; 1477 - k3 /= k5; 1478 - } 1479 - if (i4 > 0) { 1480 - i5 /= i3; 1481 - k4 /= k5; 1482 - } else { 1483 - k4 /= i3; 1484 - i5 /= k5; 1485 - } 1486 - int i6 = cursorX - Rasterizer3D.center_x; 1487 - int k6 = cursorY - Rasterizer3D.center_y; 1488 - if (i6 > k3 && i6 < l3 && k6 > i5 && k6 < k4) { 1489 - if (singleTile) { 1490 - hoveredHash[resourceCount++] = i2; 1491 - } else { 1492 - flag1 = true; 1493 - } 1494 - } 1495 - } 1496 - int l5 = Rasterizer3D.center_x; 1497 - int j6 = Rasterizer3D.center_y; 1498 - int l6 = 0; 1499 - int i7 = 0; 1500 - if (i != 0) { 1501 - l6 = SINE[i]; 1502 - i7 = COSINE[i]; 1503 - } 1504 - for (int j7 = 0; j7 < vertexCount; j7++) { 1505 - int k7 = verticesX[j7]; 1506 - int l7 = verticesY[j7]; 1507 - int i8 = verticesZ[j7]; 1508 - if (i != 0) { 1509 - int j8 = i8 * l6 + k7 * i7 >> 16; 1510 - i8 = i8 * i7 - k7 * l6 >> 16; 1511 - k7 = j8; 1512 - } 1513 - k7 += j1; 1514 - l7 += k1; 1515 - i8 += l1; 1516 - int k8 = i8 * l + k7 * i1 >> 16; 1517 - i8 = i8 * i1 - k7 * l >> 16; 1518 - k7 = k8; 1519 - k8 = l7 * k - i8 * j >> 16; 1520 - i8 = l7 * j + i8 * k >> 16; 1521 - l7 = k8; 1522 - vertexScreenZ[j7] = i8 - k2; 1523 - if (i8 >= 50) { 1524 - vertexScreenX[j7] = l5 + (k7 << 9) / i8; 1525 - vertexScreenY[j7] = j6 + (l7 << 9) / i8; 1526 - } else { 1527 - vertexScreenX[j7] = -5000; 1528 - flag = true; 1529 - } 1530 - if (flag || texturedTriangleCount > 0) { 1531 - vertexMovedX[j7] = k7; 1532 - vertexMovedY[j7] = l7; 1533 - vertexMovedZ[j7] = i8; 1534 - } 1535 - } 1536 - 1537 - try { 1538 - method599(flag, flag1, i2); 1539 - } catch (Exception _ex) { 1540 - } 1541 - } 1542 - 1543 - private void method599(boolean flag, boolean flag1, int i) { 1544 - for (int j = 0; j < diagonal3D; j++) { 1545 - anIntArray1692[j] = 0; 1546 - } 1547 - 1548 - for (int k = 0; k < triangleCount; k++) { 1549 - if (triangleDrawType == null || triangleDrawType[k] != -1) { 1550 - int l = trianglePointsX[k]; 1551 - int k1 = trianglePointsY[k]; 1552 - int j2 = trianglePointsZ[k]; 1553 - int i3 = vertexScreenX[l]; 1554 - int l3 = vertexScreenX[k1]; 1555 - int k4 = vertexScreenX[j2]; 1556 - if (flag && (i3 == -5000 || l3 == -5000 || k4 == -5000)) { 1557 - aBooleanArray1685[k] = true; 1558 - int j5 = (vertexScreenZ[l] + vertexScreenZ[k1] + vertexScreenZ[j2]) / 3 + diagonal3DAboveOrigin; 1559 - anIntArrayArray1693[j5][anIntArray1692[j5]++] = k; 1560 - } else { 1561 - if (flag1 1562 - && method602(cursorX, cursorY, vertexScreenY[l], vertexScreenY[k1], 1563 - vertexScreenY[j2], i3, l3, k4)) { 1564 - hoveredHash[resourceCount++] = i; 1565 - flag1 = false; 1566 - } 1567 - if ((i3 - l3) * (vertexScreenY[j2] - vertexScreenY[k1]) 1568 - - (vertexScreenY[l] - vertexScreenY[k1]) * (k4 - l3) > 0) { 1569 - aBooleanArray1685[k] = false; 1570 - if (i3 < 0 || l3 < 0 || k4 < 0 || i3 > Rasterizer.viewportRx 1571 - || l3 > Rasterizer.viewportRx || k4 > Rasterizer.viewportRx) { 1572 - restrictEdges[k] = true; 1573 - } else { 1574 - restrictEdges[k] = false; 1575 - } 1576 - int k5 = (vertexScreenZ[l] + vertexScreenZ[k1] + vertexScreenZ[j2]) / 3 + diagonal3DAboveOrigin; 1577 - anIntArrayArray1693[k5][anIntArray1692[k5]++] = k; 1578 - } 1579 - } 1580 - } 1581 - } 1582 - 1583 - if (trianglePriorities == null) { 1584 - for (int i1 = diagonal3D - 1; i1 >= 0; i1--) { 1585 - int l1 = anIntArray1692[i1]; 1586 - if (l1 > 0) { 1587 - int[] ai = anIntArrayArray1693[i1]; 1588 - for (int j3 = 0; j3 < l1; j3++) { 1589 - method600(ai[j3]); 1590 - } 1591 - 1592 - } 1593 - } 1594 - 1595 - return; 1596 - } 1597 - for (int j1 = 0; j1 < 12; j1++) { 1598 - anIntArray1694[j1] = 0; 1599 - anIntArray1698[j1] = 0; 1600 - } 1601 - 1602 - for (int i2 = diagonal3D - 1; i2 >= 0; i2--) { 1603 - int k2 = anIntArray1692[i2]; 1604 - if (k2 > 0) { 1605 - int[] ai1 = anIntArrayArray1693[i2]; 1606 - for (int i4 = 0; i4 < k2; i4++) { 1607 - int l4 = ai1[i4]; 1608 - int l5 = trianglePriorities[l4]; 1609 - int j6 = anIntArray1694[l5]++; 1610 - anIntArrayArray1695[l5][j6] = l4; 1611 - if (l5 < 10) { 1612 - anIntArray1698[l5] += i2; 1613 - } else if (l5 == 10) { 1614 - anIntArray1696[j6] = i2; 1615 - } else { 1616 - anIntArray1697[j6] = i2; 1617 - } 1618 - } 1619 - 1620 - } 1621 - } 1622 - 1623 - int l2 = 0; 1624 - if (anIntArray1694[1] > 0 || anIntArray1694[2] > 0) { 1625 - l2 = (anIntArray1698[1] + anIntArray1698[2]) / (anIntArray1694[1] + anIntArray1694[2]); 1626 - } 1627 - int k3 = 0; 1628 - if (anIntArray1694[3] > 0 || anIntArray1694[4] > 0) { 1629 - k3 = (anIntArray1698[3] + anIntArray1698[4]) / (anIntArray1694[3] + anIntArray1694[4]); 1630 - } 1631 - int j4 = 0; 1632 - if (anIntArray1694[6] > 0 || anIntArray1694[8] > 0) { 1633 - j4 = (anIntArray1698[6] + anIntArray1698[8]) / (anIntArray1694[6] + anIntArray1694[8]); 1634 - } 1635 - int i6 = 0; 1636 - int k6 = anIntArray1694[10]; 1637 - int[] ai2 = anIntArrayArray1695[10]; 1638 - int[] ai3 = anIntArray1696; 1639 - if (i6 == k6) { 1640 - i6 = 0; 1641 - k6 = anIntArray1694[11]; 1642 - ai2 = anIntArrayArray1695[11]; 1643 - ai3 = anIntArray1697; 1644 - } 1645 - int i5; 1646 - if (i6 < k6) { 1647 - i5 = ai3[i6]; 1648 - } else { 1649 - i5 = -1000; 1650 - } 1651 - for (int l6 = 0; l6 < 10; l6++) { 1652 - while (l6 == 0 && i5 > l2) { 1653 - method600(ai2[i6++]); 1654 - if (i6 == k6 && ai2 != anIntArrayArray1695[11]) { 1655 - i6 = 0; 1656 - k6 = anIntArray1694[11]; 1657 - ai2 = anIntArrayArray1695[11]; 1658 - ai3 = anIntArray1697; 1659 - } 1660 - if (i6 < k6) { 1661 - i5 = ai3[i6]; 1662 - } else { 1663 - i5 = -1000; 1664 - } 1665 - } 1666 - while (l6 == 3 && i5 > k3) { 1667 - method600(ai2[i6++]); 1668 - if (i6 == k6 && ai2 != anIntArrayArray1695[11]) { 1669 - i6 = 0; 1670 - k6 = anIntArray1694[11]; 1671 - ai2 = anIntArrayArray1695[11]; 1672 - ai3 = anIntArray1697; 1673 - } 1674 - if (i6 < k6) { 1675 - i5 = ai3[i6]; 1676 - } else { 1677 - i5 = -1000; 1678 - } 1679 - } 1680 - while (l6 == 5 && i5 > j4) { 1681 - method600(ai2[i6++]); 1682 - if (i6 == k6 && ai2 != anIntArrayArray1695[11]) { 1683 - i6 = 0; 1684 - k6 = anIntArray1694[11]; 1685 - ai2 = anIntArrayArray1695[11]; 1686 - ai3 = anIntArray1697; 1687 - } 1688 - if (i6 < k6) { 1689 - i5 = ai3[i6]; 1690 - } else { 1691 - i5 = -1000; 1692 - } 1693 - } 1694 - int i7 = anIntArray1694[l6]; 1695 - int[] ai4 = anIntArrayArray1695[l6]; 1696 - for (int j7 = 0; j7 < i7; j7++) { 1697 - method600(ai4[j7]); 1698 - } 1699 - 1700 - } 1701 - 1702 - while (i5 != -1000) { 1703 - method600(ai2[i6++]); 1704 - if (i6 == k6 && ai2 != anIntArrayArray1695[11]) { 1705 - i6 = 0; 1706 - ai2 = anIntArrayArray1695[11]; 1707 - k6 = anIntArray1694[11]; 1708 - ai3 = anIntArray1697; 1709 - } 1710 - if (i6 < k6) { 1711 - i5 = ai3[i6]; 1712 - } else { 1713 - i5 = -1000; 1714 - } 1715 - } 1716 - } 1717 - 1718 - private void method600(int i) { 1719 - if (aBooleanArray1685[i]) { 1720 - method601(i); 1721 - return; 1722 - } 1723 - int j = trianglePointsX[i]; 1724 - int k = trianglePointsY[i]; 1725 - int l = trianglePointsZ[i]; 1726 - Rasterizer3D.restrict_edges = restrictEdges[i]; 1727 - if (triangleAlphaValues == null) { 1728 - Rasterizer3D.alpha = 0; 1729 - } else { 1730 - Rasterizer3D.alpha = triangleAlphaValues[i]; 1731 - } 1732 - int i1; 1733 - if (triangleDrawType == null) { 1734 - i1 = 0; 1735 - } else { 1736 - i1 = triangleDrawType[i] & 3; 1737 - } 1738 - if (i1 == 0) { 1739 - Rasterizer3D.drawShadedTriangle(vertexScreenY[j], vertexScreenY[k], vertexScreenY[l], 1740 - vertexScreenX[j], vertexScreenX[k], vertexScreenX[l], triangleHSLA[i], triangleHSLB[i], 1741 - triangleHSLC[i]); 1742 - return; 1743 - } 1744 - if (i1 == 1) { 1745 - Rasterizer3D.drawFlatTriangle(vertexScreenY[j], vertexScreenY[k], vertexScreenY[l], 1746 - vertexScreenX[j], vertexScreenX[k], vertexScreenX[l], HSLtoRGB[triangleHSLA[i]]); 1747 - return; 1748 - } 1749 - if (i1 == 2) { 1750 - int j1 = triangleDrawType[i] >> 2; 1751 - int l1 = texturedTrianglePointsX[j1]; 1752 - int j2 = texturedTrianglePointsY[j1]; 1753 - int l2 = texturedTrianglePointsZ[j1]; 1754 - Rasterizer3D.drawTexturedTriangle(vertexScreenY[j], vertexScreenY[k], vertexScreenY[l], 1755 - vertexScreenX[j], vertexScreenX[k], vertexScreenX[l], triangleHSLA[i], triangleHSLB[i], 1756 - triangleHSLC[i], vertexMovedX[l1], vertexMovedX[j2], vertexMovedX[l2], vertexMovedY[l1], 1757 - vertexMovedY[j2], vertexMovedY[l2], vertexMovedZ[l1], vertexMovedZ[j2], vertexMovedZ[l2], 1758 - triangleColorValues[i]); 1759 - return; 1760 - } 1761 - int k1 = triangleDrawType[i] >> 2; 1762 - int i2 = texturedTrianglePointsX[k1]; 1763 - int k2 = texturedTrianglePointsY[k1]; 1764 - int i3 = texturedTrianglePointsZ[k1]; 1765 - Rasterizer3D.drawTexturedTriangle(vertexScreenY[j], vertexScreenY[k], vertexScreenY[l], 1766 - vertexScreenX[j], vertexScreenX[k], vertexScreenX[l], triangleHSLA[i], triangleHSLA[i], 1767 - triangleHSLA[i], vertexMovedX[i2], vertexMovedX[k2], vertexMovedX[i3], vertexMovedY[i2], 1768 - vertexMovedY[k2], vertexMovedY[i3], vertexMovedZ[i2], vertexMovedZ[k2], vertexMovedZ[i3], 1769 - triangleColorValues[i]); 1770 - } 1771 - 1772 - private void method601(int i) { 1773 - int j = Rasterizer3D.center_x; 1774 - int k = Rasterizer3D.center_y; 1775 - int l = 0; 1776 - int i1 = trianglePointsX[i]; 1777 - int j1 = trianglePointsY[i]; 1778 - int k1 = trianglePointsZ[i]; 1779 - int l1 = vertexMovedZ[i1]; 1780 - int i2 = vertexMovedZ[j1]; 1781 - int j2 = vertexMovedZ[k1]; 1782 - if (l1 >= 50) { 1783 - anIntArray1699[l] = vertexScreenX[i1]; 1784 - anIntArray1700[l] = vertexScreenY[i1]; 1785 - anIntArray1701[l++] = triangleHSLA[i]; 1786 - } else { 1787 - int k2 = vertexMovedX[i1]; 1788 - int k3 = vertexMovedY[i1]; 1789 - int k4 = triangleHSLA[i]; 1790 - if (j2 >= 50) { 1791 - int k5 = (50 - l1) * anIntArray1713[j2 - l1]; 1792 - anIntArray1699[l] = j + (k2 + ((vertexMovedX[k1] - k2) * k5 >> 16) << 9) / 50; 1793 - anIntArray1700[l] = k + (k3 + ((vertexMovedY[k1] - k3) * k5 >> 16) << 9) / 50; 1794 - anIntArray1701[l++] = k4 + ((triangleHSLC[i] - k4) * k5 >> 16); 1795 - } 1796 - if (i2 >= 50) { 1797 - int l5 = (50 - l1) * anIntArray1713[i2 - l1]; 1798 - anIntArray1699[l] = j + (k2 + ((vertexMovedX[j1] - k2) * l5 >> 16) << 9) / 50; 1799 - anIntArray1700[l] = k + (k3 + ((vertexMovedY[j1] - k3) * l5 >> 16) << 9) / 50; 1800 - anIntArray1701[l++] = k4 + ((triangleHSLB[i] - k4) * l5 >> 16); 1801 - } 1802 - } 1803 - if (i2 >= 50) { 1804 - anIntArray1699[l] = vertexScreenX[j1]; 1805 - anIntArray1700[l] = vertexScreenY[j1]; 1806 - anIntArray1701[l++] = triangleHSLB[i]; 1807 - } else { 1808 - int l2 = vertexMovedX[j1]; 1809 - int l3 = vertexMovedY[j1]; 1810 - int l4 = triangleHSLB[i]; 1811 - if (l1 >= 50) { 1812 - int i6 = (50 - i2) * anIntArray1713[l1 - i2]; 1813 - anIntArray1699[l] = j + (l2 + ((vertexMovedX[i1] - l2) * i6 >> 16) << 9) / 50; 1814 - anIntArray1700[l] = k + (l3 + ((vertexMovedY[i1] - l3) * i6 >> 16) << 9) / 50; 1815 - anIntArray1701[l++] = l4 + ((triangleHSLA[i] - l4) * i6 >> 16); 1816 - } 1817 - if (j2 >= 50) { 1818 - int j6 = (50 - i2) * anIntArray1713[j2 - i2]; 1819 - anIntArray1699[l] = j + (l2 + ((vertexMovedX[k1] - l2) * j6 >> 16) << 9) / 50; 1820 - anIntArray1700[l] = k + (l3 + ((vertexMovedY[k1] - l3) * j6 >> 16) << 9) / 50; 1821 - anIntArray1701[l++] = l4 + ((triangleHSLC[i] - l4) * j6 >> 16); 1822 - } 1823 - } 1824 - if (j2 >= 50) { 1825 - anIntArray1699[l] = vertexScreenX[k1]; 1826 - anIntArray1700[l] = vertexScreenY[k1]; 1827 - anIntArray1701[l++] = triangleHSLC[i]; 1828 - } else { 1829 - int i3 = vertexMovedX[k1]; 1830 - int i4 = vertexMovedY[k1]; 1831 - int i5 = triangleHSLC[i]; 1832 - if (i2 >= 50) { 1833 - int k6 = (50 - j2) * anIntArray1713[i2 - j2]; 1834 - anIntArray1699[l] = j + (i3 + ((vertexMovedX[j1] - i3) * k6 >> 16) << 9) / 50; 1835 - anIntArray1700[l] = k + (i4 + ((vertexMovedY[j1] - i4) * k6 >> 16) << 9) / 50; 1836 - anIntArray1701[l++] = i5 + ((triangleHSLB[i] - i5) * k6 >> 16); 1837 - } 1838 - if (l1 >= 50) { 1839 - int l6 = (50 - j2) * anIntArray1713[l1 - j2]; 1840 - anIntArray1699[l] = j + (i3 + ((vertexMovedX[i1] - i3) * l6 >> 16) << 9) / 50; 1841 - anIntArray1700[l] = k + (i4 + ((vertexMovedY[i1] - i4) * l6 >> 16) << 9) / 50; 1842 - anIntArray1701[l++] = i5 + ((triangleHSLA[i] - i5) * l6 >> 16); 1843 - } 1844 - } 1845 - int j3 = anIntArray1699[0]; 1846 - int j4 = anIntArray1699[1]; 1847 - int j5 = anIntArray1699[2]; 1848 - int i7 = anIntArray1700[0]; 1849 - int j7 = anIntArray1700[1]; 1850 - int k7 = anIntArray1700[2]; 1851 - if ((j3 - j4) * (k7 - j7) - (i7 - j7) * (j5 - j4) > 0) { 1852 - Rasterizer3D.restrict_edges = false; 1853 - if (l == 3) { 1854 - if (j3 < 0 || j4 < 0 || j5 < 0 || j3 > Rasterizer.viewportRx || j4 > Rasterizer.viewportRx 1855 - || j5 > Rasterizer.viewportRx) { 1856 - Rasterizer3D.restrict_edges = true; 1857 - } 1858 - int l7; 1859 - if (triangleDrawType == null) { 1860 - l7 = 0; 1861 - } else { 1862 - l7 = triangleDrawType[i] & 3; 1863 - } 1864 - if (l7 == 0) { 1865 - Rasterizer3D.drawShadedTriangle(i7, j7, k7, j3, j4, j5, anIntArray1701[0], anIntArray1701[1], 1866 - anIntArray1701[2]); 1867 - } else if (l7 == 1) { 1868 - Rasterizer3D.drawFlatTriangle(i7, j7, k7, j3, j4, j5, HSLtoRGB[triangleHSLA[i]]); 1869 - } else if (l7 == 2) { 1870 - int j8 = triangleDrawType[i] >> 2; 1871 - int k9 = texturedTrianglePointsX[j8]; 1872 - int k10 = texturedTrianglePointsY[j8]; 1873 - int k11 = texturedTrianglePointsZ[j8]; 1874 - Rasterizer3D.drawTexturedTriangle(i7, j7, k7, j3, j4, j5, anIntArray1701[0], anIntArray1701[1], 1875 - anIntArray1701[2], vertexMovedX[k9], vertexMovedX[k10], vertexMovedX[k11], 1876 - vertexMovedY[k9], vertexMovedY[k10], vertexMovedY[k11], vertexMovedZ[k9], 1877 - vertexMovedZ[k10], vertexMovedZ[k11], triangleColorValues[i]); 1878 - } else { 1879 - int k8 = triangleDrawType[i] >> 2; 1880 - int l9 = texturedTrianglePointsX[k8]; 1881 - int l10 = texturedTrianglePointsY[k8]; 1882 - int l11 = texturedTrianglePointsZ[k8]; 1883 - Rasterizer3D.drawTexturedTriangle(i7, j7, k7, j3, j4, j5, triangleHSLA[i], triangleHSLA[i], 1884 - triangleHSLA[i], vertexMovedX[l9], vertexMovedX[l10], vertexMovedX[l11], 1885 - vertexMovedY[l9], vertexMovedY[l10], vertexMovedY[l11], vertexMovedZ[l9], 1886 - vertexMovedZ[l10], vertexMovedZ[l11], triangleColorValues[i]); 1887 - } 1888 - } 1889 - if (l == 4) { 1890 - if (j3 < 0 || j4 < 0 || j5 < 0 || j3 > Rasterizer.viewportRx || j4 > Rasterizer.viewportRx 1891 - || j5 > Rasterizer.viewportRx || anIntArray1699[3] < 0 1892 - || anIntArray1699[3] > Rasterizer.viewportRx) { 1893 - Rasterizer3D.restrict_edges = true; 1894 - } 1895 - int i8; 1896 - if (triangleDrawType == null) { 1897 - i8 = 0; 1898 - } else { 1899 - i8 = triangleDrawType[i] & 3; 1900 - } 1901 - if (i8 == 0) { 1902 - Rasterizer3D.drawShadedTriangle(i7, j7, k7, j3, j4, j5, anIntArray1701[0], anIntArray1701[1], 1903 - anIntArray1701[2]); 1904 - Rasterizer3D.drawShadedTriangle(i7, k7, anIntArray1700[3], j3, j5, anIntArray1699[3], 1905 - anIntArray1701[0], anIntArray1701[2], anIntArray1701[3]); 1906 - return; 1907 - } 1908 - if (i8 == 1) { 1909 - int l8 = HSLtoRGB[triangleHSLA[i]]; 1910 - Rasterizer3D.drawFlatTriangle(i7, j7, k7, j3, j4, j5, l8); 1911 - Rasterizer3D.drawFlatTriangle(i7, k7, anIntArray1700[3], j3, j5, anIntArray1699[3], l8); 1912 - return; 1913 - } 1914 - if (i8 == 2) { 1915 - int i9 = triangleDrawType[i] >> 2; 1916 - int i10 = texturedTrianglePointsX[i9]; 1917 - int i11 = texturedTrianglePointsY[i9]; 1918 - int i12 = texturedTrianglePointsZ[i9]; 1919 - Rasterizer3D.drawTexturedTriangle(i7, j7, k7, j3, j4, j5, anIntArray1701[0], anIntArray1701[1], 1920 - anIntArray1701[2], vertexMovedX[i10], vertexMovedX[i11], vertexMovedX[i12], 1921 - vertexMovedY[i10], vertexMovedY[i11], vertexMovedY[i12], vertexMovedZ[i10], 1922 - vertexMovedZ[i11], vertexMovedZ[i12], triangleColorValues[i]); 1923 - Rasterizer3D.drawTexturedTriangle(i7, k7, anIntArray1700[3], j3, j5, anIntArray1699[3], 1924 - anIntArray1701[0], anIntArray1701[2], anIntArray1701[3], vertexMovedX[i10], 1925 - vertexMovedX[i11], vertexMovedX[i12], vertexMovedY[i10], vertexMovedY[i11], 1926 - vertexMovedY[i12], vertexMovedZ[i10], vertexMovedZ[i11], vertexMovedZ[i12], 1927 - triangleColorValues[i]); 1928 - return; 1929 - } 1930 - int j9 = triangleDrawType[i] >> 2; 1931 - int j10 = texturedTrianglePointsX[j9]; 1932 - int j11 = texturedTrianglePointsY[j9]; 1933 - int j12 = texturedTrianglePointsZ[j9]; 1934 - Rasterizer3D.drawTexturedTriangle(i7, j7, k7, j3, j4, j5, triangleHSLA[i], triangleHSLA[i], 1935 - triangleHSLA[i], vertexMovedX[j10], vertexMovedX[j11], vertexMovedX[j12], 1936 - vertexMovedY[j10], vertexMovedY[j11], vertexMovedY[j12], vertexMovedZ[j10], 1937 - vertexMovedZ[j11], vertexMovedZ[j12], triangleColorValues[i]); 1938 - Rasterizer3D.drawTexturedTriangle(i7, k7, anIntArray1700[3], j3, j5, anIntArray1699[3], 1939 - triangleHSLA[i], triangleHSLA[i], triangleHSLA[i], vertexMovedX[j10], 1940 - vertexMovedX[j11], vertexMovedX[j12], vertexMovedY[j10], vertexMovedY[j11], 1941 - vertexMovedY[j12], vertexMovedZ[j10], vertexMovedZ[j11], vertexMovedZ[j12], 1942 - triangleColorValues[i]); 1943 - } 1944 - } 1945 - } 1946 - 1947 - private boolean method602(int i, int j, int k, int l, int i1, int j1, int k1, int l1) { 1948 - if (j < k && j < l && j < i1) { 1949 - return false; 1950 - } 1951 - if (j > k && j > l && j > i1) { 1952 - return false; 1953 - } 1954 - if (i < j1 && i < k1 && i < l1) { 1955 - return false; 1956 - } 1957 - return i <= j1 || i <= k1 || i <= l1; 1958 - } 1959 - 1960 - 1961 - static { 1962 - SINE = Rasterizer3D.SINE; 1963 - COSINE = Rasterizer3D.COSINE; 1964 - HSLtoRGB = Rasterizer3D.hsl2rgb; 1965 - anIntArray1713 = Rasterizer3D.anIntArray1469; 1966 - } 1967 - } 1968 - 1969 - //TODO Some more missing class names
+2075
src/main/java/com/jagex/runescape/media/renderable/Model.kt
··· 1 + package com.jagex.runescape.media.renderable 2 + 3 + import com.jagex.runescape.net.Buffer 4 + import com.jagex.runescape.net.requester.Requester 5 + import com.jagex.runescape.media.* 6 + 7 + class Model : Renderable { 8 + 9 + @JvmField 10 + var vertexCount: Int = 0 11 + 12 + @JvmField 13 + var verticesX: IntArray = IntArray(0) 14 + 15 + @JvmField 16 + var verticesY: IntArray = IntArray(0) 17 + 18 + @JvmField 19 + var verticesZ: IntArray = IntArray(0) 20 + 21 + @JvmField 22 + var triangleCount: Int = 0 23 + 24 + @JvmField 25 + var trianglePointsX: IntArray = IntArray(0) 26 + 27 + @JvmField 28 + var trianglePointsY: IntArray = IntArray(0) 29 + 30 + @JvmField 31 + var trianglePointsZ: IntArray = IntArray(0) 32 + 33 + private var triangleHSLA: IntArray? = null 34 + private var triangleHSLB: IntArray? = null 35 + private var triangleHSLC: IntArray? = null 36 + 37 + @JvmField 38 + var triangleDrawType: IntArray? = null 39 + 40 + private var trianglePriorities: IntArray? = null 41 + private var triangleAlphaValues: IntArray? = null 42 + 43 + @JvmField 44 + var triangleColorValues: IntArray? = null 45 + 46 + private var trianglePriority: Int = 0 47 + private var texturedTriangleCount: Int = 0 48 + private var texturedTrianglePointsX: IntArray = IntArray(0) 49 + private var texturedTrianglePointsY: IntArray = IntArray(0) 50 + private var texturedTrianglePointsZ: IntArray = IntArray(0) 51 + private var packedLightInfo: Int = 0 52 + 53 + @JvmField 54 + var worldX: Int = 0 55 + 56 + @JvmField 57 + var worldZ: Int = 0 58 + 59 + @JvmField 60 + var diagonal2DAboveOrigin: Int = 0 61 + 62 + @JvmField 63 + var maxY: Int = 0 64 + 65 + private var diagonal3D: Int = 0 66 + private var diagonal3DAboveOrigin: Int = 0 67 + 68 + @JvmField 69 + var objectHeight: Int = 0 70 + 71 + private var vertexSkins: IntArray? = null 72 + private var triangleSkinValues: IntArray? = null 73 + 74 + @JvmField 75 + var vectorSkin: Array<IntArray>? = null 76 + 77 + @JvmField 78 + var triangleSkin: Array<IntArray>? = null 79 + 80 + @JvmField 81 + var singleTile: Boolean = false 82 + 83 + @JvmField 84 + var vertexNormalOffset: Array<VertexNormal?>? = null 85 + 86 + constructor() 87 + 88 + constructor(modelId: Int) : this() { 89 + val modelHeader = modelHeaders!![modelId]!! 90 + vertexCount = modelHeader.vertexCount 91 + triangleCount = modelHeader.triangleCount 92 + texturedTriangleCount = modelHeader.texturedTriangleCount 93 + verticesX = IntArray(vertexCount) 94 + verticesY = IntArray(vertexCount) 95 + verticesZ = IntArray(vertexCount) 96 + trianglePointsX = IntArray(triangleCount) 97 + trianglePointsY = IntArray(triangleCount) 98 + trianglePointsZ = IntArray(triangleCount) 99 + texturedTrianglePointsX = IntArray(texturedTriangleCount) 100 + texturedTrianglePointsY = IntArray(texturedTriangleCount) 101 + texturedTrianglePointsZ = IntArray(texturedTriangleCount) 102 + if (modelHeader.vertexSkinOffset >= 0) { 103 + vertexSkins = IntArray(vertexCount) 104 + } 105 + if (modelHeader.texturePointerOffset >= 0) { 106 + triangleDrawType = IntArray(triangleCount) 107 + } 108 + if (modelHeader.trianglePriorityOffset >= 0) { 109 + trianglePriorities = IntArray(triangleCount) 110 + } else { 111 + trianglePriority = -modelHeader.trianglePriorityOffset - 1 112 + } 113 + if (modelHeader.triangleAlphaOffset >= 0) { 114 + triangleAlphaValues = IntArray(triangleCount) 115 + } 116 + if (modelHeader.triangleSkinOffset >= 0) { 117 + triangleSkinValues = IntArray(triangleCount) 118 + } 119 + triangleColorValues = IntArray(triangleCount) 120 + val vertexDirectionOffsetBuffer = Buffer(modelHeader.modelData!!) 121 + vertexDirectionOffsetBuffer.currentPosition = modelHeader.vertexDirectionOffset 122 + val xDataOffsetBuffer = Buffer(modelHeader.modelData!!) 123 + xDataOffsetBuffer.currentPosition = modelHeader.xDataOffset 124 + val yDataOffsetBuffer = Buffer(modelHeader.modelData!!) 125 + yDataOffsetBuffer.currentPosition = modelHeader.yDataOffset 126 + val zDataOffsetBuffer = Buffer(modelHeader.modelData!!) 127 + zDataOffsetBuffer.currentPosition = modelHeader.zDataOffset 128 + val vertexSkinOffsetBuffer = Buffer(modelHeader.modelData!!) 129 + vertexSkinOffsetBuffer.currentPosition = modelHeader.vertexSkinOffset 130 + var baseOffsetX = 0 131 + var baseOffsetY = 0 132 + var baseOffsetz = 0 133 + for (vertex in 0 until vertexCount) { 134 + val flag = vertexDirectionOffsetBuffer.getUnsignedByte() 135 + var currentOffsetX = 0 136 + if ((flag and 1) != 0) { 137 + currentOffsetX = xDataOffsetBuffer.getSignedSmart() 138 + } 139 + var currentOffsetY = 0 140 + if ((flag and 2) != 0) { 141 + currentOffsetY = yDataOffsetBuffer.getSignedSmart() 142 + } 143 + var currentOffsetZ = 0 144 + if ((flag and 4) != 0) { 145 + currentOffsetZ = zDataOffsetBuffer.getSignedSmart() 146 + } 147 + verticesX[vertex] = baseOffsetX + currentOffsetX 148 + verticesY[vertex] = baseOffsetY + currentOffsetY 149 + verticesZ[vertex] = baseOffsetz + currentOffsetZ 150 + baseOffsetX = verticesX[vertex] 151 + baseOffsetY = verticesY[vertex] 152 + baseOffsetz = verticesZ[vertex] 153 + if (vertexSkins != null) { 154 + vertexSkins!![vertex] = vertexSkinOffsetBuffer.getUnsignedByte() 155 + } 156 + } 157 + 158 + vertexDirectionOffsetBuffer.currentPosition = modelHeader.colorDataOffset 159 + xDataOffsetBuffer.currentPosition = modelHeader.texturePointerOffset 160 + yDataOffsetBuffer.currentPosition = modelHeader.trianglePriorityOffset 161 + zDataOffsetBuffer.currentPosition = modelHeader.triangleAlphaOffset 162 + vertexSkinOffsetBuffer.currentPosition = modelHeader.triangleSkinOffset 163 + for (l1 in 0 until triangleCount) { 164 + triangleColorValues!![l1] = vertexDirectionOffsetBuffer.getUnsignedShortBE() 165 + if (triangleDrawType != null) { 166 + triangleDrawType!![l1] = xDataOffsetBuffer.getUnsignedByte() 167 + } 168 + if (trianglePriorities != null) { 169 + trianglePriorities!![l1] = yDataOffsetBuffer.getUnsignedByte() 170 + } 171 + if (triangleAlphaValues != null) { 172 + triangleAlphaValues!![l1] = zDataOffsetBuffer.getUnsignedByte() 173 + } 174 + if (triangleSkinValues != null) { 175 + triangleSkinValues!![l1] = vertexSkinOffsetBuffer.getUnsignedByte() 176 + } 177 + } 178 + 179 + vertexDirectionOffsetBuffer.currentPosition = modelHeader.triangleDataOffset 180 + xDataOffsetBuffer.currentPosition = modelHeader.triangleTypeOffset 181 + var trianglePointOffsetX = 0 182 + var trianglePointOffsetY = 0 183 + var trianglePointOffsetZ = 0 184 + var offset = 0 185 + for (triangle in 0 until triangleCount) { 186 + val type = xDataOffsetBuffer.getUnsignedByte() 187 + if (type == 1) { 188 + trianglePointOffsetX = vertexDirectionOffsetBuffer.getSignedSmart() + offset 189 + offset = trianglePointOffsetX 190 + trianglePointOffsetY = vertexDirectionOffsetBuffer.getSignedSmart() + offset 191 + offset = trianglePointOffsetY 192 + trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset 193 + offset = trianglePointOffsetZ 194 + trianglePointsX[triangle] = trianglePointOffsetX 195 + trianglePointsY[triangle] = trianglePointOffsetY 196 + trianglePointsZ[triangle] = trianglePointOffsetZ 197 + } 198 + if (type == 2) { 199 + trianglePointOffsetY = trianglePointOffsetZ 200 + trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset 201 + offset = trianglePointOffsetZ 202 + trianglePointsX[triangle] = trianglePointOffsetX 203 + trianglePointsY[triangle] = trianglePointOffsetY 204 + trianglePointsZ[triangle] = trianglePointOffsetZ 205 + } 206 + if (type == 3) { 207 + trianglePointOffsetX = trianglePointOffsetZ 208 + trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset 209 + offset = trianglePointOffsetZ 210 + trianglePointsX[triangle] = trianglePointOffsetX 211 + trianglePointsY[triangle] = trianglePointOffsetY 212 + trianglePointsZ[triangle] = trianglePointOffsetZ 213 + } 214 + if (type == 4) { 215 + val oldTrianglePointOffsetX = trianglePointOffsetX 216 + trianglePointOffsetX = trianglePointOffsetY 217 + trianglePointOffsetY = oldTrianglePointOffsetX 218 + trianglePointOffsetZ = vertexDirectionOffsetBuffer.getSignedSmart() + offset 219 + offset = trianglePointOffsetZ 220 + trianglePointsX[triangle] = trianglePointOffsetX 221 + trianglePointsY[triangle] = trianglePointOffsetY 222 + trianglePointsZ[triangle] = trianglePointOffsetZ 223 + } 224 + } 225 + 226 + vertexDirectionOffsetBuffer.currentPosition = modelHeader.uvMapTriangleOffset 227 + for (triangle in 0 until texturedTriangleCount) { 228 + texturedTrianglePointsX[triangle] = vertexDirectionOffsetBuffer.getUnsignedShortBE() 229 + texturedTrianglePointsY[triangle] = vertexDirectionOffsetBuffer.getUnsignedShortBE() 230 + texturedTrianglePointsZ[triangle] = vertexDirectionOffsetBuffer.getUnsignedShortBE() 231 + } 232 + } 233 + 234 + constructor(modelCount: Int, subModels: Array<Model?>) : this() { 235 + var setDrawType = false 236 + var setPriority = false 237 + var setAlpha = false 238 + var setSkins = false 239 + vertexCount = 0 240 + triangleCount = 0 241 + texturedTriangleCount = 0 242 + trianglePriority = -1 243 + for (m in 0 until modelCount) { 244 + val model = subModels[m] 245 + if (model != null) { 246 + vertexCount += model.vertexCount 247 + triangleCount += model.triangleCount 248 + texturedTriangleCount += model.texturedTriangleCount 249 + setDrawType = setDrawType or (model.triangleDrawType != null) 250 + if (model.trianglePriorities == null) { 251 + if (trianglePriority == -1) { 252 + trianglePriority = model.trianglePriority 253 + } 254 + if (trianglePriority != model.trianglePriority) { 255 + setPriority = true 256 + } 257 + } else { 258 + setPriority = true 259 + } 260 + setAlpha = setAlpha or (model.triangleAlphaValues != null) 261 + setSkins = setSkins or (model.triangleSkinValues != null) 262 + } 263 + } 264 + 265 + verticesX = IntArray(vertexCount) 266 + verticesY = IntArray(vertexCount) 267 + verticesZ = IntArray(vertexCount) 268 + vertexSkins = IntArray(vertexCount) 269 + trianglePointsX = IntArray(triangleCount) 270 + trianglePointsY = IntArray(triangleCount) 271 + trianglePointsZ = IntArray(triangleCount) 272 + texturedTrianglePointsX = IntArray(texturedTriangleCount) 273 + texturedTrianglePointsY = IntArray(texturedTriangleCount) 274 + texturedTrianglePointsZ = IntArray(texturedTriangleCount) 275 + if (setDrawType) { 276 + triangleDrawType = IntArray(triangleCount) 277 + } 278 + if (setPriority) { 279 + trianglePriorities = IntArray(triangleCount) 280 + } 281 + if (setAlpha) { 282 + triangleAlphaValues = IntArray(triangleCount) 283 + } 284 + if (setSkins) { 285 + triangleSkinValues = IntArray(triangleCount) 286 + } 287 + triangleColorValues = IntArray(triangleCount) 288 + vertexCount = 0 289 + triangleCount = 0 290 + texturedTriangleCount = 0 291 + var count = 0 292 + for (m in 0 until modelCount) { 293 + val model = subModels[m] 294 + if (model != null) { 295 + for (triangle in 0 until model.triangleCount) { 296 + if (setDrawType) { 297 + if (model.triangleDrawType == null) { 298 + triangleDrawType!![triangleCount] = 0 299 + } else { 300 + var drawType = model.triangleDrawType!![triangle] 301 + if ((drawType and 2) == 2) { 302 + drawType += count shl 2 303 + } 304 + triangleDrawType!![triangleCount] = drawType 305 + } 306 + } 307 + if (setPriority) { 308 + if (model.trianglePriorities == null) { 309 + trianglePriorities!![triangleCount] = model.trianglePriority 310 + } else { 311 + trianglePriorities!![triangleCount] = model.trianglePriorities!![triangle] 312 + } 313 + } 314 + if (setAlpha) { 315 + if (model.triangleAlphaValues == null) { 316 + triangleAlphaValues!![triangleCount] = 0 317 + } else { 318 + triangleAlphaValues!![triangleCount] = model.triangleAlphaValues!![triangle] 319 + } 320 + } 321 + if (setSkins && model.triangleSkinValues != null) { 322 + triangleSkinValues!![triangleCount] = model.triangleSkinValues!![triangle] 323 + } 324 + triangleColorValues!![triangleCount] = model.triangleColorValues!![triangle] 325 + trianglePointsX[triangleCount] = getFirstIdenticalVertexIndex( 326 + model, 327 + model.trianglePointsX[triangle] 328 + ) 329 + trianglePointsY[triangleCount] = getFirstIdenticalVertexIndex( 330 + model, 331 + model.trianglePointsY[triangle] 332 + ) 333 + trianglePointsZ[triangleCount] = getFirstIdenticalVertexIndex( 334 + model, 335 + model.trianglePointsZ[triangle] 336 + ) 337 + triangleCount++ 338 + } 339 + 340 + for (triangle in 0 until model.texturedTriangleCount) { 341 + texturedTrianglePointsX[texturedTriangleCount] = getFirstIdenticalVertexIndex( 342 + model, 343 + model.texturedTrianglePointsX[triangle] 344 + ) 345 + texturedTrianglePointsY[texturedTriangleCount] = getFirstIdenticalVertexIndex( 346 + model, 347 + model.texturedTrianglePointsY[triangle] 348 + ) 349 + texturedTrianglePointsZ[texturedTriangleCount] = getFirstIdenticalVertexIndex( 350 + model, 351 + model.texturedTrianglePointsZ[triangle] 352 + ) 353 + texturedTriangleCount++ 354 + } 355 + 356 + count += model.texturedTriangleCount 357 + } 358 + } 359 + } 360 + 361 + constructor(models: Array<Model?>) : this() { 362 + val modelCount = 2 // was parameter 363 + var flag1 = false 364 + var flag2 = false 365 + var flag3 = false 366 + var flag4 = false 367 + vertexCount = 0 368 + triangleCount = 0 369 + texturedTriangleCount = 0 370 + trianglePriority = -1 371 + for (m in 0 until modelCount) { 372 + val model = models[m] 373 + if (model != null) { 374 + vertexCount += model.vertexCount 375 + triangleCount += model.triangleCount 376 + texturedTriangleCount += model.texturedTriangleCount 377 + flag1 = flag1 or (model.triangleDrawType != null) 378 + if (model.trianglePriorities != null) { 379 + flag2 = true 380 + } else { 381 + if (trianglePriority == -1) { 382 + trianglePriority = model.trianglePriority 383 + } 384 + if (trianglePriority != model.trianglePriority) { 385 + flag2 = true 386 + } 387 + } 388 + flag3 = flag3 or (model.triangleAlphaValues != null) 389 + flag4 = flag4 or (model.triangleColorValues != null) 390 + } 391 + } 392 + 393 + verticesX = IntArray(vertexCount) 394 + verticesY = IntArray(vertexCount) 395 + verticesZ = IntArray(vertexCount) 396 + trianglePointsX = IntArray(triangleCount) 397 + trianglePointsY = IntArray(triangleCount) 398 + trianglePointsZ = IntArray(triangleCount) 399 + triangleHSLA = IntArray(triangleCount) 400 + triangleHSLB = IntArray(triangleCount) 401 + triangleHSLC = IntArray(triangleCount) 402 + texturedTrianglePointsX = IntArray(texturedTriangleCount) 403 + texturedTrianglePointsY = IntArray(texturedTriangleCount) 404 + texturedTrianglePointsZ = IntArray(texturedTriangleCount) 405 + if (flag1) { 406 + triangleDrawType = IntArray(triangleCount) 407 + } 408 + if (flag2) { 409 + trianglePriorities = IntArray(triangleCount) 410 + } 411 + if (flag3) { 412 + triangleAlphaValues = IntArray(triangleCount) 413 + } 414 + if (flag4) { 415 + triangleColorValues = IntArray(triangleCount) 416 + } 417 + vertexCount = 0 418 + triangleCount = 0 419 + texturedTriangleCount = 0 420 + var count = 0 421 + for (m in 0 until modelCount) { 422 + val model = models[m] 423 + if (model != null) { 424 + val v = vertexCount 425 + for (vertex in 0 until model.vertexCount) { 426 + verticesX[vertexCount] = model.verticesX[vertex] 427 + verticesY[vertexCount] = model.verticesY[vertex] 428 + verticesZ[vertexCount] = model.verticesZ[vertex] 429 + vertexCount++ 430 + } 431 + 432 + for (triangle in 0 until model.triangleCount) { 433 + trianglePointsX[triangleCount] = model.trianglePointsX[triangle] + v 434 + trianglePointsY[triangleCount] = model.trianglePointsY[triangle] + v 435 + trianglePointsZ[triangleCount] = model.trianglePointsZ[triangle] + v 436 + triangleHSLA!![triangleCount] = model.triangleHSLA!![triangle] 437 + triangleHSLB!![triangleCount] = model.triangleHSLB!![triangle] 438 + triangleHSLC!![triangleCount] = model.triangleHSLC!![triangle] 439 + if (flag1) { 440 + if (model.triangleDrawType == null) { 441 + triangleDrawType!![triangleCount] = 0 442 + } else { 443 + var drawtype = model.triangleDrawType!![triangle] 444 + if ((drawtype and 2) == 2) { 445 + drawtype += count shl 2 446 + } 447 + triangleDrawType!![triangleCount] = drawtype 448 + } 449 + } 450 + if (flag2) { 451 + if (model.trianglePriorities == null) { 452 + trianglePriorities!![triangleCount] = model.trianglePriority 453 + } else { 454 + trianglePriorities!![triangleCount] = model.trianglePriorities!![triangle] 455 + } 456 + } 457 + if (flag3) { 458 + if (model.triangleAlphaValues == null) { 459 + triangleAlphaValues!![triangleCount] = 0 460 + } else { 461 + triangleAlphaValues!![triangleCount] = model.triangleAlphaValues!![triangle] 462 + } 463 + } 464 + if (flag4 && model.triangleColorValues != null) { 465 + triangleColorValues!![triangleCount] = model.triangleColorValues!![triangle] 466 + } 467 + triangleCount++ 468 + } 469 + 470 + for (triangle in 0 until model.texturedTriangleCount) { 471 + texturedTrianglePointsX[texturedTriangleCount] = model.texturedTrianglePointsX[triangle] + v 472 + texturedTrianglePointsY[texturedTriangleCount] = model.texturedTrianglePointsY[triangle] + v 473 + texturedTrianglePointsZ[texturedTriangleCount] = model.texturedTrianglePointsZ[triangle] + v 474 + texturedTriangleCount++ 475 + } 476 + 477 + count += model.texturedTriangleCount 478 + } 479 + } 480 + 481 + calculateDiagonals() 482 + } 483 + 484 + constructor(flag2: Boolean, model: Model, flag3: Boolean) : this() { 485 + vertexCount = model.vertexCount 486 + triangleCount = model.triangleCount 487 + texturedTriangleCount = model.texturedTriangleCount 488 + verticesX = IntArray(vertexCount) 489 + verticesY = IntArray(vertexCount) 490 + verticesZ = IntArray(vertexCount) 491 + for (i in 0 until vertexCount) { 492 + verticesX[i] = model.verticesX[i] 493 + verticesY[i] = model.verticesY[i] 494 + verticesZ[i] = model.verticesZ[i] 495 + } 496 + 497 + if (flag2) { 498 + triangleColorValues = model.triangleColorValues 499 + } else { 500 + triangleColorValues = IntArray(triangleCount) 501 + System.arraycopy(model.triangleColorValues!!, 0, triangleColorValues!!, 0, triangleCount) 502 + } 503 + if (flag3) { 504 + triangleAlphaValues = model.triangleAlphaValues 505 + } else { 506 + triangleAlphaValues = IntArray(triangleCount) 507 + if (model.triangleAlphaValues == null) { 508 + for (triangle in 0 until triangleCount) { 509 + triangleAlphaValues!![triangle] = 0 510 + } 511 + } else { 512 + System.arraycopy(model.triangleAlphaValues!!, 0, triangleAlphaValues!!, 0, triangleCount) 513 + } 514 + } 515 + 516 + vertexSkins = model.vertexSkins 517 + triangleSkinValues = model.triangleSkinValues 518 + triangleDrawType = model.triangleDrawType 519 + trianglePointsX = model.trianglePointsX 520 + trianglePointsY = model.trianglePointsY 521 + trianglePointsZ = model.trianglePointsZ 522 + trianglePriorities = model.trianglePriorities 523 + trianglePriority = model.trianglePriority 524 + texturedTrianglePointsX = model.texturedTrianglePointsX 525 + texturedTrianglePointsY = model.texturedTrianglePointsY 526 + texturedTrianglePointsZ = model.texturedTrianglePointsZ 527 + } 528 + 529 + constructor(adjustToTerrain: Boolean, nonFlatShading: Boolean, model: Model) : this() { 530 + vertexCount = model.vertexCount 531 + triangleCount = model.triangleCount 532 + texturedTriangleCount = model.texturedTriangleCount 533 + if (adjustToTerrain) { 534 + verticesY = IntArray(vertexCount) 535 + System.arraycopy(model.verticesY, 0, verticesY, 0, vertexCount) 536 + } else { 537 + verticesY = model.verticesY 538 + } 539 + if (nonFlatShading) { 540 + triangleHSLA = IntArray(triangleCount) 541 + triangleHSLB = IntArray(triangleCount) 542 + triangleHSLC = IntArray(triangleCount) 543 + for (triangle in 0 until triangleCount) { 544 + triangleHSLA!![triangle] = model.triangleHSLA!![triangle] 545 + triangleHSLB!![triangle] = model.triangleHSLB!![triangle] 546 + triangleHSLC!![triangle] = model.triangleHSLC!![triangle] 547 + } 548 + 549 + triangleDrawType = IntArray(triangleCount) 550 + if (model.triangleDrawType == null) { 551 + for (triangle in 0 until triangleCount) { 552 + triangleDrawType!![triangle] = 0 553 + } 554 + } else { 555 + System.arraycopy(model.triangleDrawType!!, 0, triangleDrawType!!, 0, triangleCount) 556 + } 557 + verticesNormal = Array(vertexCount) { VertexNormal() } 558 + for (vertex in 0 until vertexCount) { 559 + val vertexNormalNew = verticesNormal!![vertex] 560 + val vertexNormalOld = model.verticesNormal!![vertex] 561 + vertexNormalNew.x = vertexNormalOld.x 562 + vertexNormalNew.y = vertexNormalOld.y 563 + vertexNormalNew.z = vertexNormalOld.z 564 + vertexNormalNew.magnitude = vertexNormalOld.magnitude 565 + } 566 + 567 + vertexNormalOffset = model.vertexNormalOffset 568 + } else { 569 + triangleHSLA = model.triangleHSLA 570 + triangleHSLB = model.triangleHSLB 571 + triangleHSLC = model.triangleHSLC 572 + triangleDrawType = model.triangleDrawType 573 + } 574 + verticesX = model.verticesX 575 + verticesZ = model.verticesZ 576 + triangleColorValues = model.triangleColorValues 577 + triangleAlphaValues = model.triangleAlphaValues 578 + trianglePriorities = model.trianglePriorities 579 + trianglePriority = model.trianglePriority 580 + trianglePointsX = model.trianglePointsX 581 + trianglePointsY = model.trianglePointsY 582 + trianglePointsZ = model.trianglePointsZ 583 + texturedTrianglePointsX = model.texturedTrianglePointsX 584 + texturedTrianglePointsY = model.texturedTrianglePointsY 585 + texturedTrianglePointsZ = model.texturedTrianglePointsZ 586 + modelHeight = model.modelHeight 587 + maxY = model.maxY 588 + diagonal2DAboveOrigin = model.diagonal2DAboveOrigin 589 + diagonal3DAboveOrigin = model.diagonal3DAboveOrigin 590 + diagonal3D = model.diagonal3D 591 + worldX = model.worldX 592 + worldZ = model.worldZ 593 + packedLightInfo = model.packedLightInfo 594 + } 595 + 596 + fun replaceWithModel(model: Model, replaceAlphaValues: Boolean) { 597 + vertexCount = model.vertexCount 598 + triangleCount = model.triangleCount 599 + texturedTriangleCount = model.texturedTriangleCount 600 + if (tmpVerticesX!!.size < vertexCount) { 601 + tmpVerticesX = IntArray(vertexCount + 100) 602 + tmpVerticesY = IntArray(vertexCount + 100) 603 + tmpVerticesZ = IntArray(vertexCount + 100) 604 + } 605 + verticesX = tmpVerticesX!! 606 + verticesY = tmpVerticesY!! 607 + verticesZ = tmpVerticesZ!! 608 + for (vertex in 0 until vertexCount) { 609 + verticesX[vertex] = model.verticesX[vertex] 610 + verticesY[vertex] = model.verticesY[vertex] 611 + verticesZ[vertex] = model.verticesZ[vertex] 612 + } 613 + 614 + if (replaceAlphaValues) { 615 + triangleAlphaValues = model.triangleAlphaValues 616 + } else { 617 + if (tmpAlphaValues!!.size < triangleCount) { 618 + tmpAlphaValues = IntArray(triangleCount + 100) 619 + } 620 + triangleAlphaValues = tmpAlphaValues 621 + if (model.triangleAlphaValues == null) { 622 + for (triangle in 0 until triangleCount) { 623 + triangleAlphaValues!![triangle] = 0 624 + } 625 + } else { 626 + if (triangleCount >= 0) { 627 + System.arraycopy(model.triangleAlphaValues!!, 0, triangleAlphaValues!!, 0, triangleCount) 628 + } 629 + } 630 + } 631 + triangleDrawType = model.triangleDrawType 632 + triangleColorValues = model.triangleColorValues 633 + trianglePriorities = model.trianglePriorities 634 + trianglePriority = model.trianglePriority 635 + triangleSkin = model.triangleSkin 636 + vectorSkin = model.vectorSkin 637 + trianglePointsX = model.trianglePointsX 638 + trianglePointsY = model.trianglePointsY 639 + trianglePointsZ = model.trianglePointsZ 640 + triangleHSLA = model.triangleHSLA 641 + triangleHSLB = model.triangleHSLB 642 + triangleHSLC = model.triangleHSLC 643 + texturedTrianglePointsX = model.texturedTrianglePointsX 644 + texturedTrianglePointsY = model.texturedTrianglePointsY 645 + texturedTrianglePointsZ = model.texturedTrianglePointsZ 646 + } 647 + 648 + private fun getFirstIdenticalVertexIndex(model: Model, vertex: Int): Int { 649 + var identicalVertexIndex = -1 650 + val vertexX = model.verticesX[vertex] 651 + val vertexY = model.verticesY[vertex] 652 + val vertexZ = model.verticesZ[vertex] 653 + for (index in 0 until vertexCount) { 654 + if (vertexX != verticesX[index] || vertexY != verticesY[index] || vertexZ != verticesZ[index]) { 655 + continue 656 + } 657 + identicalVertexIndex = index 658 + break 659 + } 660 + 661 + if (identicalVertexIndex == -1) { 662 + verticesX[vertexCount] = vertexX 663 + verticesY[vertexCount] = vertexY 664 + verticesZ[vertexCount] = vertexZ 665 + if (model.vertexSkins != null) { 666 + vertexSkins!![vertexCount] = model.vertexSkins!![vertex] 667 + } 668 + identicalVertexIndex = vertexCount++ 669 + } 670 + return identicalVertexIndex 671 + } 672 + 673 + fun calculateDiagonals() { 674 + modelHeight = 0 675 + diagonal2DAboveOrigin = 0 676 + maxY = 0 677 + for (vertex in 0 until vertexCount) { 678 + val vertexX = verticesX[vertex] 679 + val vertexY = verticesY[vertex] 680 + val vertexZ = verticesZ[vertex] 681 + if (-vertexY > modelHeight) { 682 + modelHeight = -vertexY 683 + } 684 + if (vertexY > maxY) { 685 + maxY = vertexY 686 + } 687 + val j1 = vertexX * vertexX + vertexZ * vertexZ 688 + if (j1 > diagonal2DAboveOrigin) { 689 + diagonal2DAboveOrigin = j1 690 + } 691 + } 692 + 693 + diagonal2DAboveOrigin = (Math.sqrt(diagonal2DAboveOrigin.toDouble()) + 0.99).toInt() 694 + diagonal3DAboveOrigin = 695 + (Math.sqrt((diagonal2DAboveOrigin * diagonal2DAboveOrigin + modelHeight * modelHeight).toDouble()) + 0.99).toInt() 696 + diagonal3D = diagonal3DAboveOrigin + 697 + (Math.sqrt((diagonal2DAboveOrigin * diagonal2DAboveOrigin + maxY * maxY).toDouble()) + 0.99).toInt() 698 + } 699 + 700 + fun normalise() { 701 + modelHeight = 0 702 + maxY = 0 703 + for (j in 0 until vertexCount) { 704 + val k = verticesY[j] 705 + if (-k > modelHeight) { 706 + modelHeight = -k 707 + } 708 + if (k > maxY) { 709 + maxY = k 710 + } 711 + } 712 + 713 + diagonal3DAboveOrigin = 714 + (Math.sqrt((diagonal2DAboveOrigin * diagonal2DAboveOrigin + modelHeight * modelHeight).toDouble()) + 0.99).toInt() 715 + diagonal3D = diagonal3DAboveOrigin + 716 + (Math.sqrt((diagonal2DAboveOrigin * diagonal2DAboveOrigin + maxY * maxY).toDouble()) + 0.99).toInt() 717 + } 718 + 719 + private fun calculateDiagonalsAndBounds() { 720 + modelHeight = 0 721 + diagonal2DAboveOrigin = 0 722 + maxY = 0 723 + var minX = 32767 724 + var maxX = -32767 725 + var maxZ = -32767 726 + var minZ = 32767 727 + for (vertex in 0 until vertexCount) { 728 + val x = verticesX[vertex] 729 + val y = verticesY[vertex] 730 + val z = verticesZ[vertex] 731 + if (x < minX) { 732 + minX = x 733 + } 734 + if (x > maxX) { 735 + maxX = x 736 + } 737 + if (z < minZ) { 738 + minZ = z 739 + } 740 + if (z > maxZ) { 741 + maxZ = z 742 + } 743 + if (-y > modelHeight) { 744 + modelHeight = -y 745 + } 746 + if (y > maxY) { 747 + maxY = y 748 + } 749 + val bounds = x * x + z * z 750 + if (bounds > diagonal2DAboveOrigin) { 751 + diagonal2DAboveOrigin = bounds 752 + } 753 + } 754 + 755 + diagonal2DAboveOrigin = Math.sqrt(diagonal2DAboveOrigin.toDouble()).toInt() 756 + diagonal3DAboveOrigin = 757 + Math.sqrt((diagonal2DAboveOrigin * diagonal2DAboveOrigin + modelHeight * modelHeight).toDouble()).toInt() 758 + diagonal3D = diagonal3DAboveOrigin + 759 + Math.sqrt((diagonal2DAboveOrigin * diagonal2DAboveOrigin + maxY * maxY).toDouble()).toInt() 760 + worldX = (minX shl 16) + (maxX and 0xffff) 761 + worldZ = (maxZ shl 16) + (minZ and 0xffff) 762 + } 763 + 764 + fun createBones() { 765 + if (vertexSkins != null) { 766 + val ai = IntArray(256) 767 + var j = 0 768 + for (l in 0 until vertexCount) { 769 + val j1 = vertexSkins!![l] 770 + ai[j1]++ 771 + if (j1 > j) { 772 + j = j1 773 + } 774 + } 775 + 776 + vectorSkin = Array(j + 1) { IntArray(0) } 777 + for (k1 in 0..j) { 778 + vectorSkin!![k1] = IntArray(ai[k1]) 779 + ai[k1] = 0 780 + } 781 + 782 + for (j2 in 0 until vertexCount) { 783 + val l2 = vertexSkins!![j2] 784 + vectorSkin!![l2][ai[l2]] = j2 785 + ai[l2]++ 786 + } 787 + 788 + vertexSkins = null 789 + } 790 + if (triangleSkinValues != null) { 791 + val ai1 = IntArray(256) 792 + var k = 0 793 + for (i1 in 0 until triangleCount) { 794 + val l1 = triangleSkinValues!![i1] 795 + ai1[l1]++ 796 + if (l1 > k) { 797 + k = l1 798 + } 799 + } 800 + 801 + triangleSkin = Array(k + 1) { IntArray(0) } 802 + for (i2 in 0..k) { 803 + triangleSkin!![i2] = IntArray(ai1[i2]) 804 + ai1[i2] = 0 805 + } 806 + 807 + for (k2 in 0 until triangleCount) { 808 + val i3 = triangleSkinValues!![k2] 809 + triangleSkin!![i3][ai1[i3]] = k2 810 + ai1[i3]++ 811 + } 812 + 813 + triangleSkinValues = null 814 + } 815 + } 816 + 817 + fun applyTransform(frameId: Int) { 818 + if (vectorSkin == null) { 819 + return 820 + } 821 + if (frameId == -1) { 822 + return 823 + } 824 + val animation = Animation.getAnimation(frameId) ?: return 825 + val skins = animation.animationSkins 826 + vertexXModifier = 0 827 + vertexYModifier = 0 828 + vertexZModifier = 0 829 + for (stepId in 0 until animation.transformCount) { 830 + val opcode = animation.opcodeTable[stepId] 831 + transformStep( 832 + skins.opcodes[opcode], skins.skinList[opcode], animation.modifier1[stepId], 833 + animation.modifier2[stepId], animation.modifier3[stepId] 834 + ) 835 + } 836 + } 837 + 838 + fun mixAnimationFrames(i: Int, j: Int, k: Int, ai: IntArray?) { 839 + if (k == -1) { 840 + return 841 + } 842 + if (ai == null || i == -1) { 843 + applyTransform(k) 844 + return 845 + } 846 + val animation = Animation.getAnimation(k) ?: return 847 + val animation_1 = Animation.getAnimation(i) 848 + if (animation_1 == null) { 849 + applyTransform(k) 850 + return 851 + } 852 + val skins = animation.animationSkins 853 + vertexXModifier = 0 854 + vertexYModifier = 0 855 + vertexZModifier = 0 856 + var l = 0 857 + var i1 = ai[l] 858 + l++ 859 + for (j1 in 0 until animation.transformCount) { 860 + val k1 = animation.opcodeTable[j1] 861 + while (k1 > i1) { 862 + i1 = ai[l] 863 + l++ 864 + } 865 + if (k1 != i1 || skins.opcodes[k1] == 0) { 866 + transformStep( 867 + skins.opcodes[k1], skins.skinList[k1], animation.modifier1[j1], 868 + animation.modifier2[j1], animation.modifier3[j1] 869 + ) 870 + } 871 + } 872 + 873 + vertexXModifier = 0 874 + vertexYModifier = 0 875 + vertexZModifier = 0 876 + l = 0 877 + i1 = ai[l] 878 + l++ 879 + for (l1 in 0 until animation_1.transformCount) { 880 + val i2 = animation_1.opcodeTable[l1] 881 + while (i2 > i1) { 882 + i1 = ai[l] 883 + l++ 884 + } 885 + if (i2 == i1 || skins.opcodes[i2] == 0) { 886 + transformStep( 887 + skins.opcodes[i2], skins.skinList[i2], animation_1.modifier1[l1], 888 + animation_1.modifier2[l1], animation_1.modifier3[l1] 889 + ) 890 + } 891 + } 892 + } 893 + 894 + private fun transformStep(i: Int, ai: IntArray, j: Int, k: Int, l: Int) { 895 + val i1 = ai.size 896 + if (i == 0) { 897 + var j1 = 0 898 + vertexXModifier = 0 899 + vertexYModifier = 0 900 + vertexZModifier = 0 901 + for (k2 in 0 until i1) { 902 + val l3 = ai[k2] 903 + if (l3 < vectorSkin!!.size) { 904 + val ai5 = vectorSkin!![l3] 905 + for (i5 in ai5.indices) { 906 + val j6 = ai5[i5] 907 + vertexXModifier += verticesX[j6] 908 + vertexYModifier += verticesY[j6] 909 + vertexZModifier += verticesZ[j6] 910 + j1++ 911 + } 912 + } 913 + } 914 + 915 + if (j1 > 0) { 916 + vertexXModifier = vertexXModifier / j1 + j 917 + vertexYModifier = vertexYModifier / j1 + k 918 + vertexZModifier = vertexZModifier / j1 + l 919 + return 920 + } else { 921 + vertexXModifier = j 922 + vertexYModifier = k 923 + vertexZModifier = l 924 + return 925 + } 926 + } 927 + if (i == 1) { 928 + for (k1 in 0 until i1) { 929 + val l2 = ai[k1] 930 + if (l2 < vectorSkin!!.size) { 931 + val ai1 = vectorSkin!![l2] 932 + for (i4 in ai1.indices) { 933 + val j5 = ai1[i4] 934 + verticesX[j5] += j 935 + verticesY[j5] += k 936 + verticesZ[j5] += l 937 + } 938 + } 939 + } 940 + 941 + return 942 + } 943 + if (i == 2) { 944 + for (l1 in 0 until i1) { 945 + val i3 = ai[l1] 946 + if (i3 < vectorSkin!!.size) { 947 + val ai2 = vectorSkin!![i3] 948 + for (j4 in ai2.indices) { 949 + val k5 = ai2[j4] 950 + verticesX[k5] -= vertexXModifier 951 + verticesY[k5] -= vertexYModifier 952 + verticesZ[k5] -= vertexZModifier 953 + val k6 = (j and 0xff) * 8 954 + val l6 = (k and 0xff) * 8 955 + val i7 = (l and 0xff) * 8 956 + if (i7 != 0) { 957 + val j7 = SINE!![i7] 958 + val i8 = COSINE!![i7] 959 + val l8 = ((verticesY[k5] * j7) + (verticesX[k5] * i8)) shr 16 960 + verticesY[k5] = ((verticesY[k5] * i8) - (verticesX[k5] * j7)) shr 16 961 + verticesX[k5] = l8 962 + } 963 + if (k6 != 0) { 964 + val k7 = SINE!![k6] 965 + val j8 = COSINE!![k6] 966 + val i9 = ((verticesY[k5] * j8) - (verticesZ[k5] * k7)) shr 16 967 + verticesZ[k5] = ((verticesY[k5] * k7) + (verticesZ[k5] * j8)) shr 16 968 + verticesY[k5] = i9 969 + } 970 + if (l6 != 0) { 971 + val l7 = SINE!![l6] 972 + val k8 = COSINE!![l6] 973 + val j9 = ((verticesZ[k5] * l7) + (verticesX[k5] * k8)) shr 16 974 + verticesZ[k5] = ((verticesZ[k5] * k8) - (verticesX[k5] * l7)) shr 16 975 + verticesX[k5] = j9 976 + } 977 + verticesX[k5] += vertexXModifier 978 + verticesY[k5] += vertexYModifier 979 + verticesZ[k5] += vertexZModifier 980 + } 981 + } 982 + } 983 + 984 + return 985 + } 986 + if (i == 3) { 987 + for (i2 in 0 until i1) { 988 + val j3 = ai[i2] 989 + if (j3 < vectorSkin!!.size) { 990 + val ai3 = vectorSkin!![j3] 991 + for (k4 in ai3.indices) { 992 + val l5 = ai3[k4] 993 + verticesX[l5] -= vertexXModifier 994 + verticesY[l5] -= vertexYModifier 995 + verticesZ[l5] -= vertexZModifier 996 + verticesX[l5] = (verticesX[l5] * j) / 128 997 + verticesY[l5] = (verticesY[l5] * k) / 128 998 + verticesZ[l5] = (verticesZ[l5] * l) / 128 999 + verticesX[l5] += vertexXModifier 1000 + verticesY[l5] += vertexYModifier 1001 + verticesZ[l5] += vertexZModifier 1002 + } 1003 + } 1004 + } 1005 + 1006 + return 1007 + } 1008 + if (i == 5 && triangleSkin != null && triangleAlphaValues != null) { 1009 + for (j2 in 0 until i1) { 1010 + val k3 = ai[j2] 1011 + if (k3 < triangleSkin!!.size) { 1012 + val ai4 = triangleSkin!![k3] 1013 + for (l4 in ai4.indices) { 1014 + val i6 = ai4[l4] 1015 + triangleAlphaValues!![i6] += j * 8 1016 + if (triangleAlphaValues!![i6] < 0) { 1017 + triangleAlphaValues!![i6] = 0 1018 + } 1019 + if (triangleAlphaValues!![i6] > 255) { 1020 + triangleAlphaValues!![i6] = 255 1021 + } 1022 + } 1023 + } 1024 + } 1025 + } 1026 + } 1027 + 1028 + fun rotate90Degrees() { 1029 + for (i in 0 until vertexCount) { 1030 + val j = verticesX[i] 1031 + verticesX[i] = verticesZ[i] 1032 + verticesZ[i] = -j 1033 + } 1034 + } 1035 + 1036 + fun rotateX(i: Int) { 1037 + val k = SINE!![i] 1038 + val l = COSINE!![i] 1039 + for (i1 in 0 until vertexCount) { 1040 + val j1 = ((verticesY[i1] * l) - (verticesZ[i1] * k)) shr 16 1041 + verticesZ[i1] = ((verticesY[i1] * k) + (verticesZ[i1] * l)) shr 16 1042 + verticesY[i1] = j1 1043 + } 1044 + } 1045 + 1046 + fun translate(i: Int, j: Int, k: Int) { 1047 + for (l in 0 until vertexCount) { 1048 + verticesX[l] += i 1049 + verticesY[l] += k 1050 + verticesZ[l] += j 1051 + } 1052 + } 1053 + 1054 + fun replaceColor(oldColor: Int, newColor: Int) { 1055 + for (i in 0 until triangleCount) { 1056 + if (triangleColorValues!![i] == oldColor) { 1057 + triangleColorValues!![i] = newColor 1058 + } 1059 + } 1060 + } 1061 + 1062 + fun mirror(i: Int) { 1063 + if (i != 0) { 1064 + var j = 1 1065 + while (j > 0) { 1066 + j++ 1067 + } 1068 + } 1069 + for (k in 0 until vertexCount) { 1070 + verticesZ[k] = -verticesZ[k] 1071 + } 1072 + 1073 + for (l in 0 until triangleCount) { 1074 + val i1 = trianglePointsX[l] 1075 + trianglePointsX[l] = trianglePointsZ[l] 1076 + trianglePointsZ[l] = i1 1077 + } 1078 + } 1079 + 1080 + fun scaleT(i: Int, j: Int, k: Int, l: Int) { 1081 + for (i1 in 0 until vertexCount) { 1082 + verticesX[i1] = (verticesX[i1] * l) / 128 1083 + verticesY[i1] = (verticesY[i1] * i) / 128 1084 + verticesZ[i1] = (verticesZ[i1] * j) / 128 1085 + } 1086 + } 1087 + 1088 + fun applyLighting(lightMod: Int, magnitudeMultiplier: Int, lightX: Int, lightY: Int, lightZ: Int, flatShading: Boolean) { 1089 + val lightMagnitude = Math.sqrt((lightX * lightX + lightY * lightY + lightZ * lightZ).toDouble()).toInt() 1090 + val magnitude = (magnitudeMultiplier * lightMagnitude) shr 8 1091 + if (triangleHSLA == null) { 1092 + triangleHSLA = IntArray(triangleCount) 1093 + triangleHSLB = IntArray(triangleCount) 1094 + triangleHSLC = IntArray(triangleCount) 1095 + } 1096 + if (verticesNormal == null) { 1097 + verticesNormal = Array(vertexCount) { VertexNormal() } 1098 + } 1099 + for (triangle in 0 until triangleCount) { 1100 + val _triangleX = trianglePointsX[triangle] 1101 + val _triangleY = trianglePointsY[triangle] 1102 + val _triangleZ = trianglePointsZ[triangle] 1103 + val distanceXXY = verticesX[_triangleY] - verticesX[_triangleX] 1104 + val distanceYXY = verticesY[_triangleY] - verticesY[_triangleX] 1105 + val distanceZXY = verticesZ[_triangleY] - verticesZ[_triangleX] 1106 + val distanceXZX = verticesX[_triangleZ] - verticesX[_triangleX] 1107 + val distanceYZX = verticesY[_triangleZ] - verticesY[_triangleX] 1108 + val distanceZZX = verticesZ[_triangleZ] - verticesZ[_triangleX] 1109 + var normalX = distanceYXY * distanceZZX - distanceYZX * distanceZXY 1110 + var normalY = distanceZXY * distanceXZX - distanceZZX * distanceXXY 1111 + var normalZ = distanceXXY * distanceYZX - distanceXZX * distanceYXY 1112 + while (normalX > 8192 || normalY > 8192 || normalZ > 8192 || normalX < -8192 || normalY < -8192 || normalZ < -8192) { 1113 + normalX = normalX shr 1 1114 + normalY = normalY shr 1 1115 + normalZ = normalZ shr 1 1116 + } 1117 + 1118 + var normalLength = Math.sqrt((normalX * normalX + normalY * normalY + normalZ * normalZ).toDouble()).toInt() 1119 + if (normalLength <= 0) { 1120 + normalLength = 1 1121 + } 1122 + normalX = (normalX * 256) / normalLength 1123 + normalY = (normalY * 256) / normalLength 1124 + normalZ = (normalZ * 256) / normalLength 1125 + if (triangleDrawType == null || (triangleDrawType!![triangle] and 1) == 0) { 1126 + var vertexNormal = verticesNormal!![_triangleX]!! 1127 + vertexNormal.x += normalX 1128 + vertexNormal.y += normalY 1129 + vertexNormal.z += normalZ 1130 + vertexNormal.magnitude++ 1131 + vertexNormal = verticesNormal!![_triangleY]!! 1132 + vertexNormal.x += normalX 1133 + vertexNormal.y += normalY 1134 + vertexNormal.z += normalZ 1135 + vertexNormal.magnitude++ 1136 + vertexNormal = verticesNormal!![_triangleZ]!! 1137 + vertexNormal.x += normalX 1138 + vertexNormal.y += normalY 1139 + vertexNormal.z += normalZ 1140 + vertexNormal.magnitude++ 1141 + } else { 1142 + val lightness = lightMod + (lightX * normalX + lightY * normalY + lightZ * normalZ) / (magnitude + magnitude / 2) 1143 + triangleHSLA!![triangle] = mixLightness(triangleColorValues!![triangle], lightness, triangleDrawType!![triangle]) 1144 + } 1145 + } 1146 + 1147 + if (flatShading) { 1148 + handleShading(lightMod, magnitude, lightX, lightY, lightZ) 1149 + } else { 1150 + vertexNormalOffset = arrayOfNulls(vertexCount) 1151 + for (vertex in 0 until vertexCount) { 1152 + val vertexNormal = verticesNormal!![vertex]!! 1153 + val shadowVertexNormal = VertexNormal() 1154 + vertexNormalOffset!![vertex] = shadowVertexNormal 1155 + shadowVertexNormal.x = vertexNormal.x 1156 + shadowVertexNormal.y = vertexNormal.y 1157 + shadowVertexNormal.z = vertexNormal.z 1158 + shadowVertexNormal.magnitude = vertexNormal.magnitude 1159 + } 1160 + 1161 + packedLightInfo = (lightMod shl 16) + (magnitude and 0xffff) 1162 + } 1163 + if (flatShading) { 1164 + calculateDiagonals() 1165 + } else { 1166 + calculateDiagonalsAndBounds() 1167 + } 1168 + } 1169 + 1170 + fun handleShading(i: Int, j: Int, k: Int, l: Int) { 1171 + val i1 = packedLightInfo shr 16 1172 + val j1 = (packedLightInfo shl 16) shr 16 1173 + handleShading(i1, j1, l, i, j) 1174 + } 1175 + 1176 + private fun handleShading(i: Int, j: Int, k: Int, l: Int, i1: Int) { 1177 + for (j1 in 0 until triangleCount) { 1178 + val k1 = trianglePointsX[j1] 1179 + val i2 = trianglePointsY[j1] 1180 + val j2 = trianglePointsZ[j1] 1181 + if (triangleDrawType == null) { 1182 + val i3 = triangleColorValues!![j1] 1183 + var class40 = verticesNormal!![k1]!! 1184 + var k2 = i + (k * class40.x + l * class40.y + i1 * class40.z) / (j * class40.magnitude) 1185 + triangleHSLA!![j1] = mixLightness(i3, k2, 0) 1186 + class40 = verticesNormal!![i2]!! 1187 + k2 = i + (k * class40.x + l * class40.y + i1 * class40.z) / (j * class40.magnitude) 1188 + triangleHSLB!![j1] = mixLightness(i3, k2, 0) 1189 + class40 = verticesNormal!![j2]!! 1190 + k2 = i + (k * class40.x + l * class40.y + i1 * class40.z) / (j * class40.magnitude) 1191 + triangleHSLC!![j1] = mixLightness(i3, k2, 0) 1192 + } else if ((triangleDrawType!![j1] and 1) == 0) { 1193 + val j3 = triangleColorValues!![j1] 1194 + val k3 = triangleDrawType!![j1] 1195 + var class40_1 = verticesNormal!![k1]!! 1196 + var l2 = i + (k * class40_1.x + l * class40_1.y + i1 * class40_1.z) / (j * class40_1.magnitude) 1197 + triangleHSLA!![j1] = mixLightness(j3, l2, k3) 1198 + class40_1 = verticesNormal!![i2]!! 1199 + l2 = i + (k * class40_1.x + l * class40_1.y + i1 * class40_1.z) / (j * class40_1.magnitude) 1200 + triangleHSLB!![j1] = mixLightness(j3, l2, k3) 1201 + class40_1 = verticesNormal!![j2]!! 1202 + l2 = i + (k * class40_1.x + l * class40_1.y + i1 * class40_1.z) / (j * class40_1.magnitude) 1203 + triangleHSLC!![j1] = mixLightness(j3, l2, k3) 1204 + } 1205 + } 1206 + 1207 + verticesNormal = null 1208 + vertexNormalOffset = null 1209 + vertexSkins = null 1210 + triangleSkinValues = null 1211 + if (triangleDrawType != null) { 1212 + for (l1 in 0 until triangleCount) { 1213 + if ((triangleDrawType!![l1] and 2) == 2) { 1214 + return 1215 + } 1216 + } 1217 + } 1218 + triangleColorValues = null 1219 + } 1220 + 1221 + fun render(i: Int, j: Int, k: Int, l: Int, i1: Int, j1: Int, k1: Int) { 1222 + val l1 = Rasterizer3D.center_x 1223 + val i2 = Rasterizer3D.center_y 1224 + val j2 = SINE!![i] 1225 + val k2 = COSINE!![i] 1226 + val l2 = SINE!![j] 1227 + val i3 = COSINE!![j] 1228 + val j3 = SINE!![k] 1229 + val k3 = COSINE!![k] 1230 + val l3 = SINE!![l] 1231 + val i4 = COSINE!![l] 1232 + val j4 = ((j1 * l3) + (k1 * i4)) shr 16 1233 + for (k4 in 0 until vertexCount) { 1234 + var l4 = verticesX[k4] 1235 + var i5 = verticesY[k4] 1236 + var j5 = verticesZ[k4] 1237 + if (k != 0) { 1238 + val k5 = ((i5 * j3) + (l4 * k3)) shr 16 1239 + i5 = ((i5 * k3) - (l4 * j3)) shr 16 1240 + l4 = k5 1241 + } 1242 + if (i != 0) { 1243 + val l5 = ((i5 * k2) - (j5 * j2)) shr 16 1244 + j5 = ((i5 * j2) + (j5 * k2)) shr 16 1245 + i5 = l5 1246 + } 1247 + if (j != 0) { 1248 + val i6 = ((j5 * l2) + (l4 * i3)) shr 16 1249 + j5 = ((j5 * i3) - (l4 * l2)) shr 16 1250 + l4 = i6 1251 + } 1252 + l4 += i1 1253 + i5 += j1 1254 + j5 += k1 1255 + val j6 = ((i5 * i4) - (j5 * l3)) shr 16 1256 + j5 = ((i5 * l3) + (j5 * i4)) shr 16 1257 + i5 = j6 1258 + vertexScreenZ!![k4] = j5 - j4 1259 + vertexScreenX!![k4] = l1 + ((l4 shl 9) / j5) 1260 + vertexScreenY!![k4] = i2 + ((i5 shl 9) / j5) 1261 + if (texturedTriangleCount > 0) { 1262 + vertexMovedX!![k4] = l4 1263 + vertexMovedY!![k4] = i5 1264 + vertexMovedZ!![k4] = j5 1265 + } 1266 + } 1267 + 1268 + try { 1269 + renderTriangles(false, false, 0) 1270 + } catch (_ex: Exception) { 1271 + } 1272 + } 1273 + 1274 + override fun renderAtPoint(i: Int, j: Int, k: Int, l: Int, i1: Int, j1: Int, k1: Int, l1: Int, i2: Int) { 1275 + val j2 = ((l1 * i1) - (j1 * l)) shr 16 1276 + val k2 = ((k1 * j) + (j2 * k)) shr 16 1277 + val l2 = (diagonal2DAboveOrigin * k) shr 16 1278 + val i3 = k2 + l2 1279 + if (i3 <= 50 || k2 >= 3500) { 1280 + return 1281 + } 1282 + val j3 = ((l1 * l) + (j1 * i1)) shr 16 1283 + var k3 = (j3 - diagonal2DAboveOrigin) shl 9 1284 + if (k3 / i3 >= Rasterizer.centerX) { 1285 + return 1286 + } 1287 + var l3 = (j3 + diagonal2DAboveOrigin) shl 9 1288 + if (l3 / i3 <= -Rasterizer.centerX) { 1289 + return 1290 + } 1291 + val i4 = ((k1 * k) - (j2 * j)) shr 16 1292 + val j4 = (diagonal2DAboveOrigin * j) shr 16 1293 + var k4 = (i4 + j4) shl 9 1294 + if (k4 / i3 <= -Rasterizer.centerY) { 1295 + return 1296 + } 1297 + val l4 = j4 + ((modelHeight * k) shr 16) 1298 + var i5 = (i4 - l4) shl 9 1299 + if (i5 / i3 >= Rasterizer.centerY) { 1300 + return 1301 + } 1302 + val j5 = l2 + ((modelHeight * j) shr 16) 1303 + var flag = false 1304 + if (k2 - j5 <= 50) { 1305 + flag = true 1306 + } 1307 + var flag1 = false 1308 + if (i2 > 0 && gameScreenClickable) { 1309 + val k5 = k2 - l2 1310 + @Suppress("NAME_SHADOWING") 1311 + val k5Fixed = if (k5 <= 50) 50 else k5 1312 + if (j3 > 0) { 1313 + k3 /= i3 1314 + l3 /= k5Fixed 1315 + } else { 1316 + l3 /= i3 1317 + k3 /= k5Fixed 1318 + } 1319 + if (i4 > 0) { 1320 + i5 /= i3 1321 + k4 /= k5Fixed 1322 + } else { 1323 + k4 /= i3 1324 + i5 /= k5Fixed 1325 + } 1326 + val i6 = cursorX - Rasterizer3D.center_x 1327 + val k6 = cursorY - Rasterizer3D.center_y 1328 + if (i6 > k3 && i6 < l3 && k6 > i5 && k6 < k4) { 1329 + if (singleTile) { 1330 + hoveredHash!![resourceCount] = i2 1331 + resourceCount++ 1332 + } else { 1333 + flag1 = true 1334 + } 1335 + } 1336 + } 1337 + val l5 = Rasterizer3D.center_x 1338 + val j6 = Rasterizer3D.center_y 1339 + var l6 = 0 1340 + var i7 = 0 1341 + if (i != 0) { 1342 + l6 = SINE!![i] 1343 + i7 = COSINE!![i] 1344 + } 1345 + for (j7 in 0 until vertexCount) { 1346 + var k7 = verticesX[j7] 1347 + var l7 = verticesY[j7] 1348 + var i8 = verticesZ[j7] 1349 + if (i != 0) { 1350 + val j8 = ((i8 * l6) + (k7 * i7)) shr 16 1351 + i8 = ((i8 * i7) - (k7 * l6)) shr 16 1352 + k7 = j8 1353 + } 1354 + k7 += j1 1355 + l7 += k1 1356 + i8 += l1 1357 + var k8 = ((i8 * l) + (k7 * i1)) shr 16 1358 + i8 = ((i8 * i1) - (k7 * l)) shr 16 1359 + k7 = k8 1360 + k8 = ((l7 * k) - (i8 * j)) shr 16 1361 + i8 = ((l7 * j) + (i8 * k)) shr 16 1362 + l7 = k8 1363 + vertexScreenZ!![j7] = i8 - k2 1364 + if (i8 >= 50) { 1365 + vertexScreenX!![j7] = l5 + ((k7 shl 9) / i8) 1366 + vertexScreenY!![j7] = j6 + ((l7 shl 9) / i8) 1367 + } else { 1368 + vertexScreenX!![j7] = -5000 1369 + flag = true 1370 + } 1371 + if (flag || texturedTriangleCount > 0) { 1372 + vertexMovedX!![j7] = k7 1373 + vertexMovedY!![j7] = l7 1374 + vertexMovedZ!![j7] = i8 1375 + } 1376 + } 1377 + 1378 + try { 1379 + renderTriangles(flag, flag1, i2) 1380 + } catch (_ex: Exception) { 1381 + } 1382 + } 1383 + 1384 + private fun renderTriangles(flag: Boolean, flag1: Boolean, i: Int) { 1385 + @Suppress("NAME_SHADOWING") 1386 + var flag1 = flag1 1387 + for (j in 0 until diagonal3D) { 1388 + depthBucketCount!![j] = 0 1389 + } 1390 + 1391 + for (k in 0 until triangleCount) { 1392 + if (triangleDrawType == null || triangleDrawType!![k] != -1) { 1393 + val l = trianglePointsX[k] 1394 + val k1 = trianglePointsY[k] 1395 + val j2 = trianglePointsZ[k] 1396 + val i3 = vertexScreenX!![l] 1397 + val l3 = vertexScreenX!![k1] 1398 + val k4 = vertexScreenX!![j2] 1399 + if (flag && (i3 == -5000 || l3 == -5000 || k4 == -5000)) { 1400 + triangleBehindCamera!![k] = true 1401 + val j5 = (vertexScreenZ!![l] + vertexScreenZ!![k1] + vertexScreenZ!![j2]) / 3 + diagonal3DAboveOrigin 1402 + depthBucketTriangles!![j5][depthBucketCount!![j5]] = k 1403 + depthBucketCount!![j5]++ 1404 + } else { 1405 + if (flag1 1406 + && isPointInTriangle( 1407 + cursorX, cursorY, vertexScreenY!![l], vertexScreenY!![k1], 1408 + vertexScreenY!![j2], i3, l3, k4 1409 + ) 1410 + ) { 1411 + hoveredHash!![resourceCount] = i 1412 + resourceCount++ 1413 + flag1 = false 1414 + } 1415 + if ((i3 - l3) * (vertexScreenY!![j2] - vertexScreenY!![k1]) - 1416 + (vertexScreenY!![l] - vertexScreenY!![k1]) * (k4 - l3) > 0 1417 + ) { 1418 + triangleBehindCamera!![k] = false 1419 + if (i3 < 0 || l3 < 0 || k4 < 0 || i3 > Rasterizer.viewportRx 1420 + || l3 > Rasterizer.viewportRx || k4 > Rasterizer.viewportRx 1421 + ) { 1422 + restrictEdges!![k] = true 1423 + } else { 1424 + restrictEdges!![k] = false 1425 + } 1426 + val k5 = (vertexScreenZ!![l] + vertexScreenZ!![k1] + vertexScreenZ!![j2]) / 3 + diagonal3DAboveOrigin 1427 + depthBucketTriangles!![k5][depthBucketCount!![k5]] = k 1428 + depthBucketCount!![k5]++ 1429 + } 1430 + } 1431 + } 1432 + } 1433 + 1434 + if (trianglePriorities == null) { 1435 + for (i1 in diagonal3D - 1 downTo 0) { 1436 + val l1 = depthBucketCount!![i1] 1437 + if (l1 > 0) { 1438 + val ai = depthBucketTriangles!![i1] 1439 + for (j3 in 0 until l1) { 1440 + drawTriangle(ai[j3]) 1441 + } 1442 + } 1443 + } 1444 + 1445 + return 1446 + } 1447 + for (j1 in 0 until 12) { 1448 + priorityBucketCount!![j1] = 0 1449 + priorityDepthSum!![j1] = 0 1450 + } 1451 + 1452 + for (i2 in diagonal3D - 1 downTo 0) { 1453 + val k2 = depthBucketCount!![i2] 1454 + if (k2 > 0) { 1455 + val ai1 = depthBucketTriangles!![i2] 1456 + for (i4 in 0 until k2) { 1457 + val l4 = ai1[i4] 1458 + val l5 = trianglePriorities!![l4] 1459 + val j6 = priorityBucketCount!![l5] 1460 + priorityBucketCount!![l5]++ 1461 + priorityBucketTriangles!![l5][j6] = l4 1462 + if (l5 < 10) { 1463 + priorityDepthSum!![l5] += i2 1464 + } else if (l5 == 10) { 1465 + priorityDepthA!![j6] = i2 1466 + } else { 1467 + priorityDepthB!![j6] = i2 1468 + } 1469 + } 1470 + } 1471 + } 1472 + 1473 + var l2 = 0 1474 + if (priorityBucketCount!![1] > 0 || priorityBucketCount!![2] > 0) { 1475 + l2 = (priorityDepthSum!![1] + priorityDepthSum!![2]) / (priorityBucketCount!![1] + priorityBucketCount!![2]) 1476 + } 1477 + var k3 = 0 1478 + if (priorityBucketCount!![3] > 0 || priorityBucketCount!![4] > 0) { 1479 + k3 = (priorityDepthSum!![3] + priorityDepthSum!![4]) / (priorityBucketCount!![3] + priorityBucketCount!![4]) 1480 + } 1481 + var j4 = 0 1482 + if (priorityBucketCount!![6] > 0 || priorityBucketCount!![8] > 0) { 1483 + j4 = (priorityDepthSum!![6] + priorityDepthSum!![8]) / (priorityBucketCount!![6] + priorityBucketCount!![8]) 1484 + } 1485 + var i6 = 0 1486 + var k6 = priorityBucketCount!![10] 1487 + var ai2 = priorityBucketTriangles!![10] 1488 + var ai3 = priorityDepthA!! 1489 + if (i6 == k6) { 1490 + i6 = 0 1491 + k6 = priorityBucketCount!![11] 1492 + ai2 = priorityBucketTriangles!![11] 1493 + ai3 = priorityDepthB!! 1494 + } 1495 + var i5: Int 1496 + if (i6 < k6) { 1497 + i5 = ai3[i6] 1498 + } else { 1499 + i5 = -1000 1500 + } 1501 + for (l6 in 0 until 10) { 1502 + while (l6 == 0 && i5 > l2) { 1503 + drawTriangle(ai2[i6]) 1504 + i6++ 1505 + if (i6 == k6 && ai2 !== priorityBucketTriangles!![11]) { 1506 + i6 = 0 1507 + k6 = priorityBucketCount!![11] 1508 + ai2 = priorityBucketTriangles!![11] 1509 + ai3 = priorityDepthB!! 1510 + } 1511 + if (i6 < k6) { 1512 + i5 = ai3[i6] 1513 + } else { 1514 + i5 = -1000 1515 + } 1516 + } 1517 + while (l6 == 3 && i5 > k3) { 1518 + drawTriangle(ai2[i6]) 1519 + i6++ 1520 + if (i6 == k6 && ai2 !== priorityBucketTriangles!![11]) { 1521 + i6 = 0 1522 + k6 = priorityBucketCount!![11] 1523 + ai2 = priorityBucketTriangles!![11] 1524 + ai3 = priorityDepthB!! 1525 + } 1526 + if (i6 < k6) { 1527 + i5 = ai3[i6] 1528 + } else { 1529 + i5 = -1000 1530 + } 1531 + } 1532 + while (l6 == 5 && i5 > j4) { 1533 + drawTriangle(ai2[i6]) 1534 + i6++ 1535 + if (i6 == k6 && ai2 !== priorityBucketTriangles!![11]) { 1536 + i6 = 0 1537 + k6 = priorityBucketCount!![11] 1538 + ai2 = priorityBucketTriangles!![11] 1539 + ai3 = priorityDepthB!! 1540 + } 1541 + if (i6 < k6) { 1542 + i5 = ai3[i6] 1543 + } else { 1544 + i5 = -1000 1545 + } 1546 + } 1547 + val i7 = priorityBucketCount!![l6] 1548 + val ai4 = priorityBucketTriangles!![l6] 1549 + for (j7 in 0 until i7) { 1550 + drawTriangle(ai4[j7]) 1551 + } 1552 + } 1553 + 1554 + while (i5 != -1000) { 1555 + drawTriangle(ai2[i6]) 1556 + i6++ 1557 + if (i6 == k6 && ai2 !== priorityBucketTriangles!![11]) { 1558 + i6 = 0 1559 + ai2 = priorityBucketTriangles!![11] 1560 + k6 = priorityBucketCount!![11] 1561 + ai3 = priorityDepthB!! 1562 + } 1563 + if (i6 < k6) { 1564 + i5 = ai3[i6] 1565 + } else { 1566 + i5 = -1000 1567 + } 1568 + } 1569 + } 1570 + 1571 + private fun drawTriangle(i: Int) { 1572 + if (triangleBehindCamera!![i]) { 1573 + drawClippedTriangle(i) 1574 + return 1575 + } 1576 + val j = trianglePointsX[i] 1577 + val k = trianglePointsY[i] 1578 + val l = trianglePointsZ[i] 1579 + Rasterizer3D.restrict_edges = restrictEdges!![i] 1580 + if (triangleAlphaValues == null) { 1581 + Rasterizer3D.alpha = 0 1582 + } else { 1583 + Rasterizer3D.alpha = triangleAlphaValues!![i] 1584 + } 1585 + val i1: Int 1586 + if (triangleDrawType == null) { 1587 + i1 = 0 1588 + } else { 1589 + i1 = triangleDrawType!![i] and 3 1590 + } 1591 + if (i1 == 0) { 1592 + Rasterizer3D.drawShadedTriangle( 1593 + vertexScreenY!![j], vertexScreenY!![k], vertexScreenY!![l], 1594 + vertexScreenX!![j], vertexScreenX!![k], vertexScreenX!![l], triangleHSLA!![i], triangleHSLB!![i], 1595 + triangleHSLC!![i] 1596 + ) 1597 + return 1598 + } 1599 + if (i1 == 1) { 1600 + Rasterizer3D.drawFlatTriangle( 1601 + vertexScreenY!![j], vertexScreenY!![k], vertexScreenY!![l], 1602 + vertexScreenX!![j], vertexScreenX!![k], vertexScreenX!![l], HSLtoRGB!![triangleHSLA!![i]] 1603 + ) 1604 + return 1605 + } 1606 + if (i1 == 2) { 1607 + val j1 = triangleDrawType!![i] shr 2 1608 + val l1 = texturedTrianglePointsX[j1] 1609 + val j2 = texturedTrianglePointsY[j1] 1610 + val l2 = texturedTrianglePointsZ[j1] 1611 + Rasterizer3D.drawTexturedTriangle( 1612 + vertexScreenY!![j], vertexScreenY!![k], vertexScreenY!![l], 1613 + vertexScreenX!![j], vertexScreenX!![k], vertexScreenX!![l], triangleHSLA!![i], triangleHSLB!![i], 1614 + triangleHSLC!![i], vertexMovedX!![l1], vertexMovedX!![j2], vertexMovedX!![l2], vertexMovedY!![l1], 1615 + vertexMovedY!![j2], vertexMovedY!![l2], vertexMovedZ!![l1], vertexMovedZ!![j2], vertexMovedZ!![l2], 1616 + triangleColorValues!![i] 1617 + ) 1618 + return 1619 + } 1620 + val k1 = triangleDrawType!![i] shr 2 1621 + val i2 = texturedTrianglePointsX[k1] 1622 + val k2 = texturedTrianglePointsY[k1] 1623 + val i3 = texturedTrianglePointsZ[k1] 1624 + Rasterizer3D.drawTexturedTriangle( 1625 + vertexScreenY!![j], vertexScreenY!![k], vertexScreenY!![l], 1626 + vertexScreenX!![j], vertexScreenX!![k], vertexScreenX!![l], triangleHSLA!![i], triangleHSLA!![i], 1627 + triangleHSLA!![i], vertexMovedX!![i2], vertexMovedX!![k2], vertexMovedX!![i3], vertexMovedY!![i2], 1628 + vertexMovedY!![k2], vertexMovedY!![i3], vertexMovedZ!![i2], vertexMovedZ!![k2], vertexMovedZ!![i3], 1629 + triangleColorValues!![i] 1630 + ) 1631 + } 1632 + 1633 + private fun drawClippedTriangle(i: Int) { 1634 + val j = Rasterizer3D.center_x 1635 + val k = Rasterizer3D.center_y 1636 + var l = 0 1637 + val i1 = trianglePointsX[i] 1638 + val j1 = trianglePointsY[i] 1639 + val k1 = trianglePointsZ[i] 1640 + val l1 = vertexMovedZ!![i1] 1641 + val i2 = vertexMovedZ!![j1] 1642 + val j2 = vertexMovedZ!![k1] 1643 + if (l1 >= 50) { 1644 + clippedScreenX!![l] = vertexScreenX!![i1] 1645 + clippedScreenY!![l] = vertexScreenY!![i1] 1646 + clippedHSL!![l] = triangleHSLA!![i] 1647 + l++ 1648 + } else { 1649 + val k2 = vertexMovedX!![i1] 1650 + val k3 = vertexMovedY!![i1] 1651 + val k4 = triangleHSLA!![i] 1652 + if (j2 >= 50) { 1653 + val k5 = (50 - l1) * reciprocal16!![j2 - l1] 1654 + clippedScreenX!![l] = j + ((k2 + (((vertexMovedX!![k1] - k2) * k5) shr 16)) shl 9) / 50 1655 + clippedScreenY!![l] = k + ((k3 + (((vertexMovedY!![k1] - k3) * k5) shr 16)) shl 9) / 50 1656 + clippedHSL!![l] = k4 + (((triangleHSLC!![i] - k4) * k5) shr 16) 1657 + l++ 1658 + } 1659 + if (i2 >= 50) { 1660 + val l5 = (50 - l1) * reciprocal16!![i2 - l1] 1661 + clippedScreenX!![l] = j + ((k2 + (((vertexMovedX!![j1] - k2) * l5) shr 16)) shl 9) / 50 1662 + clippedScreenY!![l] = k + ((k3 + (((vertexMovedY!![j1] - k3) * l5) shr 16)) shl 9) / 50 1663 + clippedHSL!![l] = k4 + (((triangleHSLB!![i] - k4) * l5) shr 16) 1664 + l++ 1665 + } 1666 + } 1667 + if (i2 >= 50) { 1668 + clippedScreenX!![l] = vertexScreenX!![j1] 1669 + clippedScreenY!![l] = vertexScreenY!![j1] 1670 + clippedHSL!![l] = triangleHSLB!![i] 1671 + l++ 1672 + } else { 1673 + val l2 = vertexMovedX!![j1] 1674 + val l3 = vertexMovedY!![j1] 1675 + val l4 = triangleHSLB!![i] 1676 + if (l1 >= 50) { 1677 + val i6 = (50 - i2) * reciprocal16!![l1 - i2] 1678 + clippedScreenX!![l] = j + ((l2 + (((vertexMovedX!![i1] - l2) * i6) shr 16)) shl 9) / 50 1679 + clippedScreenY!![l] = k + ((l3 + (((vertexMovedY!![i1] - l3) * i6) shr 16)) shl 9) / 50 1680 + clippedHSL!![l] = l4 + (((triangleHSLA!![i] - l4) * i6) shr 16) 1681 + l++ 1682 + } 1683 + if (j2 >= 50) { 1684 + val j6 = (50 - i2) * reciprocal16!![j2 - i2] 1685 + clippedScreenX!![l] = j + ((l2 + (((vertexMovedX!![k1] - l2) * j6) shr 16)) shl 9) / 50 1686 + clippedScreenY!![l] = k + ((l3 + (((vertexMovedY!![k1] - l3) * j6) shr 16)) shl 9) / 50 1687 + clippedHSL!![l] = l4 + (((triangleHSLC!![i] - l4) * j6) shr 16) 1688 + l++ 1689 + } 1690 + } 1691 + if (j2 >= 50) { 1692 + clippedScreenX!![l] = vertexScreenX!![k1] 1693 + clippedScreenY!![l] = vertexScreenY!![k1] 1694 + clippedHSL!![l] = triangleHSLC!![i] 1695 + l++ 1696 + } else { 1697 + val i3 = vertexMovedX!![k1] 1698 + val i4 = vertexMovedY!![k1] 1699 + val i5 = triangleHSLC!![i] 1700 + if (i2 >= 50) { 1701 + val k6 = (50 - j2) * reciprocal16!![i2 - j2] 1702 + clippedScreenX!![l] = j + ((i3 + (((vertexMovedX!![j1] - i3) * k6) shr 16)) shl 9) / 50 1703 + clippedScreenY!![l] = k + ((i4 + (((vertexMovedY!![j1] - i4) * k6) shr 16)) shl 9) / 50 1704 + clippedHSL!![l] = i5 + (((triangleHSLB!![i] - i5) * k6) shr 16) 1705 + l++ 1706 + } 1707 + if (l1 >= 50) { 1708 + val l6 = (50 - j2) * reciprocal16!![l1 - j2] 1709 + clippedScreenX!![l] = j + ((i3 + (((vertexMovedX!![i1] - i3) * l6) shr 16)) shl 9) / 50 1710 + clippedScreenY!![l] = k + ((i4 + (((vertexMovedY!![i1] - i4) * l6) shr 16)) shl 9) / 50 1711 + clippedHSL!![l] = i5 + (((triangleHSLA!![i] - i5) * l6) shr 16) 1712 + l++ 1713 + } 1714 + } 1715 + val j3 = clippedScreenX!![0] 1716 + val j4 = clippedScreenX!![1] 1717 + val j5 = clippedScreenX!![2] 1718 + val i7 = clippedScreenY!![0] 1719 + val j7 = clippedScreenY!![1] 1720 + val k7 = clippedScreenY!![2] 1721 + if ((j3 - j4) * (k7 - j7) - (i7 - j7) * (j5 - j4) > 0) { 1722 + Rasterizer3D.restrict_edges = false 1723 + if (l == 3) { 1724 + if (j3 < 0 || j4 < 0 || j5 < 0 || j3 > Rasterizer.viewportRx || j4 > Rasterizer.viewportRx 1725 + || j5 > Rasterizer.viewportRx 1726 + ) { 1727 + Rasterizer3D.restrict_edges = true 1728 + } 1729 + val l7: Int 1730 + if (triangleDrawType == null) { 1731 + l7 = 0 1732 + } else { 1733 + l7 = triangleDrawType!![i] and 3 1734 + } 1735 + if (l7 == 0) { 1736 + Rasterizer3D.drawShadedTriangle( 1737 + i7, j7, k7, j3, j4, j5, clippedHSL!![0], clippedHSL!![1], 1738 + clippedHSL!![2] 1739 + ) 1740 + } else if (l7 == 1) { 1741 + Rasterizer3D.drawFlatTriangle(i7, j7, k7, j3, j4, j5, HSLtoRGB!![triangleHSLA!![i]]) 1742 + } else if (l7 == 2) { 1743 + val j8 = triangleDrawType!![i] shr 2 1744 + val k9 = texturedTrianglePointsX[j8] 1745 + val k10 = texturedTrianglePointsY[j8] 1746 + val k11 = texturedTrianglePointsZ[j8] 1747 + Rasterizer3D.drawTexturedTriangle( 1748 + i7, j7, k7, j3, j4, j5, clippedHSL!![0], clippedHSL!![1], 1749 + clippedHSL!![2], vertexMovedX!![k9], vertexMovedX!![k10], vertexMovedX!![k11], 1750 + vertexMovedY!![k9], vertexMovedY!![k10], vertexMovedY!![k11], vertexMovedZ!![k9], 1751 + vertexMovedZ!![k10], vertexMovedZ!![k11], triangleColorValues!![i] 1752 + ) 1753 + } else { 1754 + val k8 = triangleDrawType!![i] shr 2 1755 + val l9 = texturedTrianglePointsX[k8] 1756 + val l10 = texturedTrianglePointsY[k8] 1757 + val l11 = texturedTrianglePointsZ[k8] 1758 + Rasterizer3D.drawTexturedTriangle( 1759 + i7, j7, k7, j3, j4, j5, triangleHSLA!![i], triangleHSLA!![i], 1760 + triangleHSLA!![i], vertexMovedX!![l9], vertexMovedX!![l10], vertexMovedX!![l11], 1761 + vertexMovedY!![l9], vertexMovedY!![l10], vertexMovedY!![l11], vertexMovedZ!![l9], 1762 + vertexMovedZ!![l10], vertexMovedZ!![l11], triangleColorValues!![i] 1763 + ) 1764 + } 1765 + } 1766 + if (l == 4) { 1767 + if (j3 < 0 || j4 < 0 || j5 < 0 || j3 > Rasterizer.viewportRx || j4 > Rasterizer.viewportRx 1768 + || j5 > Rasterizer.viewportRx || clippedScreenX!![3] < 0 1769 + || clippedScreenX!![3] > Rasterizer.viewportRx 1770 + ) { 1771 + Rasterizer3D.restrict_edges = true 1772 + } 1773 + val i8: Int 1774 + if (triangleDrawType == null) { 1775 + i8 = 0 1776 + } else { 1777 + i8 = triangleDrawType!![i] and 3 1778 + } 1779 + if (i8 == 0) { 1780 + Rasterizer3D.drawShadedTriangle( 1781 + i7, j7, k7, j3, j4, j5, clippedHSL!![0], clippedHSL!![1], 1782 + clippedHSL!![2] 1783 + ) 1784 + Rasterizer3D.drawShadedTriangle( 1785 + i7, k7, clippedScreenY!![3], j3, j5, clippedScreenX!![3], 1786 + clippedHSL!![0], clippedHSL!![2], clippedHSL!![3] 1787 + ) 1788 + return 1789 + } 1790 + if (i8 == 1) { 1791 + val l8 = HSLtoRGB!![triangleHSLA!![i]] 1792 + Rasterizer3D.drawFlatTriangle(i7, j7, k7, j3, j4, j5, l8) 1793 + Rasterizer3D.drawFlatTriangle(i7, k7, clippedScreenY!![3], j3, j5, clippedScreenX!![3], l8) 1794 + return 1795 + } 1796 + if (i8 == 2) { 1797 + val i9 = triangleDrawType!![i] shr 2 1798 + val i10 = texturedTrianglePointsX[i9] 1799 + val i11 = texturedTrianglePointsY[i9] 1800 + val i12 = texturedTrianglePointsZ[i9] 1801 + Rasterizer3D.drawTexturedTriangle( 1802 + i7, j7, k7, j3, j4, j5, clippedHSL!![0], clippedHSL!![1], 1803 + clippedHSL!![2], vertexMovedX!![i10], vertexMovedX!![i11], vertexMovedX!![i12], 1804 + vertexMovedY!![i10], vertexMovedY!![i11], vertexMovedY!![i12], vertexMovedZ!![i10], 1805 + vertexMovedZ!![i11], vertexMovedZ!![i12], triangleColorValues!![i] 1806 + ) 1807 + Rasterizer3D.drawTexturedTriangle( 1808 + i7, k7, clippedScreenY!![3], j3, j5, clippedScreenX!![3], 1809 + clippedHSL!![0], clippedHSL!![2], clippedHSL!![3], vertexMovedX!![i10], 1810 + vertexMovedX!![i11], vertexMovedX!![i12], vertexMovedY!![i10], vertexMovedY!![i11], 1811 + vertexMovedY!![i12], vertexMovedZ!![i10], vertexMovedZ!![i11], vertexMovedZ!![i12], 1812 + triangleColorValues!![i] 1813 + ) 1814 + return 1815 + } 1816 + val j9 = triangleDrawType!![i] shr 2 1817 + val j10 = texturedTrianglePointsX[j9] 1818 + val j11 = texturedTrianglePointsY[j9] 1819 + val j12 = texturedTrianglePointsZ[j9] 1820 + Rasterizer3D.drawTexturedTriangle( 1821 + i7, j7, k7, j3, j4, j5, triangleHSLA!![i], triangleHSLA!![i], 1822 + triangleHSLA!![i], vertexMovedX!![j10], vertexMovedX!![j11], vertexMovedX!![j12], 1823 + vertexMovedY!![j10], vertexMovedY!![j11], vertexMovedY!![j12], vertexMovedZ!![j10], 1824 + vertexMovedZ!![j11], vertexMovedZ!![j12], triangleColorValues!![i] 1825 + ) 1826 + Rasterizer3D.drawTexturedTriangle( 1827 + i7, k7, clippedScreenY!![3], j3, j5, clippedScreenX!![3], 1828 + triangleHSLA!![i], triangleHSLA!![i], triangleHSLA!![i], vertexMovedX!![j10], 1829 + vertexMovedX!![j11], vertexMovedX!![j12], vertexMovedY!![j10], vertexMovedY!![j11], 1830 + vertexMovedY!![j12], vertexMovedZ!![j10], vertexMovedZ!![j11], vertexMovedZ!![j12], 1831 + triangleColorValues!![i] 1832 + ) 1833 + } 1834 + } 1835 + } 1836 + 1837 + private fun isPointInTriangle(i: Int, j: Int, k: Int, l: Int, i1: Int, j1: Int, k1: Int, l1: Int): Boolean { 1838 + if (j < k && j < l && j < i1) { 1839 + return false 1840 + } 1841 + if (j > k && j > l && j > i1) { 1842 + return false 1843 + } 1844 + if (i < j1 && i < k1 && i < l1) { 1845 + return false 1846 + } 1847 + return i <= j1 || i <= k1 || i <= l1 1848 + } 1849 + 1850 + companion object { 1851 + @JvmField 1852 + var EMPTY_MODEL: Model = Model() 1853 + 1854 + @JvmField 1855 + var requester: Requester? = null 1856 + 1857 + @JvmField 1858 + var gameScreenClickable: Boolean = false 1859 + 1860 + @JvmField 1861 + var cursorX: Int = 0 1862 + 1863 + @JvmField 1864 + var cursorY: Int = 0 1865 + 1866 + @JvmField 1867 + var resourceCount: Int = 0 1868 + 1869 + @JvmField 1870 + var hoveredHash: IntArray? = IntArray(1000) 1871 + 1872 + @JvmField 1873 + var SINE: IntArray? = null 1874 + 1875 + @JvmField 1876 + var COSINE: IntArray? = null 1877 + 1878 + private var tmpVerticesX: IntArray? = IntArray(2000) 1879 + private var tmpVerticesY: IntArray? = IntArray(2000) 1880 + private var tmpVerticesZ: IntArray? = IntArray(2000) 1881 + private var tmpAlphaValues: IntArray? = IntArray(2000) 1882 + private var modelHeaders: Array<ModelHeader?>? = null 1883 + private var restrictEdges: BooleanArray? = BooleanArray(4096) 1884 + private var triangleBehindCamera: BooleanArray? = BooleanArray(4096) 1885 + private var vertexScreenX: IntArray? = IntArray(4096) 1886 + private var vertexScreenY: IntArray? = IntArray(4096) 1887 + private var vertexScreenZ: IntArray? = IntArray(4096) 1888 + private var vertexMovedX: IntArray? = IntArray(4096) 1889 + private var vertexMovedY: IntArray? = IntArray(4096) 1890 + private var vertexMovedZ: IntArray? = IntArray(4096) 1891 + private var depthBucketCount: IntArray? = IntArray(1500) 1892 + private var depthBucketTriangles: Array<IntArray>? = Array(1500) { IntArray(512) } 1893 + private var priorityBucketCount: IntArray? = IntArray(12) 1894 + private var priorityBucketTriangles: Array<IntArray>? = Array(12) { IntArray(2000) } 1895 + private var priorityDepthA: IntArray? = IntArray(2000) 1896 + private var priorityDepthB: IntArray? = IntArray(2000) 1897 + private var priorityDepthSum: IntArray? = IntArray(12) 1898 + private var clippedScreenX: IntArray? = IntArray(10) 1899 + private var clippedScreenY: IntArray? = IntArray(10) 1900 + private var clippedHSL: IntArray? = IntArray(10) 1901 + private var vertexXModifier: Int = 0 1902 + private var vertexYModifier: Int = 0 1903 + private var vertexZModifier: Int = 0 1904 + private var HSLtoRGB: IntArray? = null 1905 + private var reciprocal16: IntArray? = null 1906 + 1907 + init { 1908 + SINE = Rasterizer3D.SINE 1909 + COSINE = Rasterizer3D.COSINE 1910 + HSLtoRGB = Rasterizer3D.hsl2rgb 1911 + reciprocal16 = Rasterizer3D.reciprocal16 1912 + } 1913 + 1914 + @JvmStatic 1915 + fun reset() { 1916 + modelHeaders = null 1917 + restrictEdges = null 1918 + triangleBehindCamera = null 1919 + vertexScreenX = null 1920 + vertexScreenY = null 1921 + vertexScreenZ = null 1922 + vertexMovedX = null 1923 + vertexMovedY = null 1924 + vertexMovedZ = null 1925 + depthBucketCount = null 1926 + depthBucketTriangles = null 1927 + priorityBucketCount = null 1928 + priorityBucketTriangles = null 1929 + priorityDepthA = null 1930 + priorityDepthB = null 1931 + priorityDepthSum = null 1932 + SINE = null 1933 + COSINE = null 1934 + HSLtoRGB = null 1935 + reciprocal16 = null 1936 + } 1937 + 1938 + @JvmStatic 1939 + fun init(modelCount: Int, requester: Requester?) { 1940 + modelHeaders = arrayOfNulls(modelCount) 1941 + Model.requester = requester 1942 + } 1943 + 1944 + @JvmStatic 1945 + fun loadModelHeader(modelData: ByteArray?, modelId: Int) { 1946 + if (modelData == null) { 1947 + val modelHeader = ModelHeader() 1948 + modelHeaders!![modelId] = modelHeader 1949 + modelHeader.vertexCount = 0 1950 + modelHeader.triangleCount = 0 1951 + modelHeader.texturedTriangleCount = 0 1952 + return 1953 + } 1954 + val buffer = Buffer(modelData) 1955 + buffer.currentPosition = modelData.size - 18 1956 + val modelHeader = ModelHeader() 1957 + modelHeaders!![modelId] = modelHeader 1958 + modelHeader.modelData = modelData 1959 + modelHeader.vertexCount = buffer.getUnsignedShortBE() 1960 + modelHeader.triangleCount = buffer.getUnsignedShortBE() 1961 + modelHeader.texturedTriangleCount = buffer.getUnsignedByte() 1962 + val useTextures = buffer.getUnsignedByte() 1963 + val useTrianglePriority = buffer.getUnsignedByte() 1964 + val useTransparency = buffer.getUnsignedByte() 1965 + val useTriangleSkinning = buffer.getUnsignedByte() 1966 + val useVertexSkinning = buffer.getUnsignedByte() 1967 + val xDataLength = buffer.getUnsignedShortBE() 1968 + val yDataLength = buffer.getUnsignedShortBE() 1969 + val zDataLength = buffer.getUnsignedShortBE() 1970 + val triangleDataLength = buffer.getUnsignedShortBE() 1971 + var offset = 0 1972 + modelHeader.vertexDirectionOffset = offset 1973 + offset += modelHeader.vertexCount 1974 + modelHeader.triangleTypeOffset = offset 1975 + offset += modelHeader.triangleCount 1976 + modelHeader.trianglePriorityOffset = offset 1977 + if (useTrianglePriority == 255) { 1978 + offset += modelHeader.triangleCount 1979 + } else { 1980 + modelHeader.trianglePriorityOffset = -useTrianglePriority - 1 1981 + } 1982 + modelHeader.triangleSkinOffset = offset 1983 + if (useTriangleSkinning == 1) { 1984 + offset += modelHeader.triangleCount 1985 + } else { 1986 + modelHeader.triangleSkinOffset = -1 1987 + } 1988 + modelHeader.texturePointerOffset = offset 1989 + if (useTextures == 1) { 1990 + offset += modelHeader.triangleCount 1991 + } else { 1992 + modelHeader.texturePointerOffset = -1 1993 + } 1994 + modelHeader.vertexSkinOffset = offset 1995 + if (useVertexSkinning == 1) { 1996 + offset += modelHeader.vertexCount 1997 + } else { 1998 + modelHeader.vertexSkinOffset = -1 1999 + } 2000 + modelHeader.triangleAlphaOffset = offset 2001 + if (useTransparency == 1) { 2002 + offset += modelHeader.triangleCount 2003 + } else { 2004 + modelHeader.triangleAlphaOffset = -1 2005 + } 2006 + modelHeader.triangleDataOffset = offset 2007 + offset += triangleDataLength 2008 + modelHeader.colorDataOffset = offset 2009 + offset += modelHeader.triangleCount * 2 2010 + modelHeader.uvMapTriangleOffset = offset 2011 + offset += modelHeader.texturedTriangleCount * 6 2012 + modelHeader.xDataOffset = offset 2013 + offset += xDataLength 2014 + modelHeader.yDataOffset = offset 2015 + offset += yDataLength 2016 + modelHeader.zDataOffset = offset 2017 + offset += zDataLength 2018 + } 2019 + 2020 + @JvmStatic 2021 + fun resetModel(model: Int) { 2022 + modelHeaders!![model] = null 2023 + } 2024 + 2025 + @JvmStatic 2026 + fun getModel(model: Int): Model? { 2027 + if (modelHeaders == null) { 2028 + return null 2029 + } 2030 + val modelHeader = modelHeaders!![model] 2031 + if (modelHeader == null) { 2032 + requester!!.requestModel(model) 2033 + return null 2034 + } else { 2035 + return Model(model) 2036 + } 2037 + } 2038 + 2039 + @JvmStatic 2040 + fun loaded(id: Int): Boolean { 2041 + if (modelHeaders == null) { 2042 + return false 2043 + } 2044 + val modelHeader = modelHeaders!![id] 2045 + if (modelHeader == null) { 2046 + requester!!.requestModel(id) 2047 + return false 2048 + } else { 2049 + return true 2050 + } 2051 + } 2052 + 2053 + @JvmStatic 2054 + private fun mixLightness(i: Int, j: Int, k: Int): Int { 2055 + @Suppress("NAME_SHADOWING") 2056 + var j = j 2057 + if ((k and 2) == 2) { 2058 + if (j < 0) { 2059 + j = 0 2060 + } else if (j > 127) { 2061 + j = 127 2062 + } 2063 + j = 127 - j 2064 + return j 2065 + } 2066 + j = (j * (i and 0x7f)) shr 7 2067 + if (j < 2) { 2068 + j = 2 2069 + } else if (j > 126) { 2070 + j = 126 2071 + } 2072 + return (i and 0xff80) + j 2073 + } 2074 + } 2075 + }
+1 -1
src/main/java/com/jagex/runescape/scene/GroundItemTile.kt
··· 10 10 @JvmField var secondGroundItem: Renderable? = null 11 11 @JvmField var thirdGroundItem: Renderable? = null 12 12 @JvmField var uid: Int = 0 13 - @JvmField var anInt180: Int = 0 13 + @JvmField var heightOffset: Int = 0 14 14 }
+1 -1
src/main/java/com/jagex/runescape/scene/InteractiveObject.kt
··· 13 13 @JvmField var tileRight: Int = 0 14 14 @JvmField var tileTop: Int = 0 15 15 @JvmField var tileBottom: Int = 0 16 - @JvmField var anInt123: Int = 0 16 + @JvmField var renderPriority: Int = 0 17 17 @JvmField var cycle: Int = 0 18 18 @JvmField var uid: Int = 0 19 19 @JvmField var config: Byte = 0
-2287
src/main/java/com/jagex/runescape/scene/Scene.java
··· 1 - package com.jagex.runescape.scene; 2 - 3 - import com.jagex.runescape.media.Rasterizer; 4 - import com.jagex.runescape.media.Rasterizer3D; 5 - import com.jagex.runescape.media.VertexNormal; 6 - import com.jagex.runescape.media.renderable.Model; 7 - import com.jagex.runescape.media.renderable.Renderable; 8 - import com.jagex.runescape.scene.tile.*; 9 - import com.jagex.runescape.util.LinkedList; 10 - import com.jagex.runescape.world.GroundArray; 11 - 12 - public class Scene { 13 - 14 - public static boolean lowMemory = true; 15 - private int mapSizeZ; 16 - private int mapSizeX; 17 - private int mapSizeY; 18 - private int[][][] heightMap; 19 - private GroundArray<SceneTile> tileArray; 20 - private int currentPositionZ; 21 - private int sceneSpawnRequestsCacheCurrentPos; 22 - private InteractiveObject[] sceneSpawnRequestsCache; 23 - private int[][][] anIntArrayArrayArray445; 24 - private static int anInt461; 25 - private static int plane; 26 - private static int cycle; 27 - private static int currentPositionX; 28 - private static int mapBoundsX; 29 - private static int currentPositionY; 30 - private static int mapBoundsY; 31 - private static int cameraPositionTileX; 32 - private static int cameraPositionTileY; 33 - private static int cameraPosX; 34 - private static int cameraPosZ; 35 - private static int cameraPosY; 36 - private static int curveSineY; 37 - private static int curveCosineY; 38 - private static int curveSineX; 39 - private static int curveCosineX; 40 - private static InteractiveObject[] interactiveObjects = new InteractiveObject[100]; 41 - private static final int[] faceOffsetX2 = {53, -53, -53, 53}; 42 - private static final int[] faceOffsetY2 = {-53, -53, 53, 53}; 43 - private static final int[] faceOffsetX3 = {-45, 45, 45, -45}; 44 - private static final int[] faceOffsetY3 = {45, 45, -45, -45}; 45 - private static boolean clicked; 46 - private static int clickX; 47 - private static int clickY; 48 - public static int clickedTileX = -1; 49 - public static int clickedTileY = -1; 50 - private static int anInt487 = 4; 51 - private static int[] cullingClusterPointer = new int[anInt487]; 52 - private static SceneCluster[][] cullingClusters = new SceneCluster[anInt487][500]; 53 - private static int processedCullingClustersPointer; 54 - private static SceneCluster[] processedCullingClusters = new SceneCluster[500]; 55 - private static LinkedList tileList = new LinkedList(); 56 - private static final int[] anIntArray493 = {19, 55, 38, 155, 255, 110, 137, 205, 76}; 57 - private static final int[] anIntArray494 = {160, 192, 80, 96, 0, 144, 80, 48, 160}; 58 - private static final int[] TILE_WALL_DRAW_FLAGS_1 = {76, 8, 137, 4, 0, 1, 38, 2, 19}; 59 - private static final int[] WALL_UNCULL_FLAGS_0 = {0, 0, 2, 0, 0, 2, 1, 1, 0}; 60 - private static final int[] anIntArray497 = {2, 0, 0, 2, 0, 0, 0, 4, 4}; 61 - private static final int[] anIntArray498 = {0, 4, 4, 8, 0, 0, 8, 0, 0}; 62 - private static final int[] anIntArray499 = {1, 1, 0, 0, 0, 8, 0, 0, 8}; 63 - private static final int[] textureRGB = {41, 39248, 41, 4643, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 43086, 64 - 41, 41, 41, 41, 41, 41, 41, 8602, 41, 28992, 41, 41, 41, 41, 41, 5056, 41, 41, 41, 7079, 41, 41, 41, 41, 65 - 41, 41, 41, 41, 41, 41, 3131, 41, 41, 41}; 66 - private int[] anIntArray486; 67 - private int[] anIntArray487; 68 - private int anInt503; 69 - private int[][] tileShapePoints = {new int[16], {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 70 - {1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1}, {1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, 71 - {0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 72 - {1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0}, 73 - {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1}, 74 - {1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1}, 75 - {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1}}; 76 - private int[][] tileShapeIndices = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 77 - {12, 8, 4, 0, 13, 9, 5, 1, 14, 10, 6, 2, 15, 11, 7, 3}, 78 - {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, 79 - {3, 7, 11, 15, 2, 6, 10, 14, 1, 5, 9, 13, 0, 4, 8, 12}}; 80 - private static boolean[][][][] TILE_VISIBILITY_MAPS = new boolean[8][32][51][51]; 81 - private static boolean[][] TILE_VISIBILITY_MAP; 82 - private static int anInt508; 83 - private static int anInt509; 84 - private static int anInt510; 85 - private static int anInt511; 86 - private static int anInt512; 87 - private static int anInt513; 88 - 89 - public Scene(int[][][] heightMap) { 90 - final int length = 104;// was parameter 91 - final int width = 104;// was parameter 92 - final int height = 4;// was parameter 93 - sceneSpawnRequestsCache = new InteractiveObject[5000]; 94 - anIntArray486 = new int[10000]; 95 - anIntArray487 = new int[10000]; 96 - mapSizeZ = height; 97 - mapSizeX = width; 98 - mapSizeY = length; 99 - tileArray = new GroundArray<>(new SceneTile[height][width][length]); 100 - anIntArrayArrayArray445 = new int[height][width + 1][length + 1]; 101 - this.heightMap = heightMap; 102 - initToNull(); 103 - } 104 - 105 - public static void nullLoader() { 106 - interactiveObjects = null; 107 - cullingClusterPointer = null; 108 - cullingClusters = null; 109 - tileList = null; 110 - TILE_VISIBILITY_MAPS = null; 111 - TILE_VISIBILITY_MAP = null; 112 - 113 - } 114 - 115 - public void initToNull() { 116 - for (int z = 0; z < mapSizeZ; z++) { 117 - for (int x = 0; x < mapSizeX; x++) { 118 - for (int y = 0; y < mapSizeY; y++) { 119 - tileArray.clearTile(z, x, y); 120 - } 121 - 122 - } 123 - 124 - } 125 - 126 - for (int l = 0; l < anInt487; l++) { 127 - for (int j1 = 0; j1 < cullingClusterPointer[l]; j1++) { 128 - cullingClusters[l][j1] = null; 129 - } 130 - 131 - cullingClusterPointer[l] = 0; 132 - } 133 - 134 - for (int k1 = 0; k1 < sceneSpawnRequestsCacheCurrentPos; k1++) { 135 - sceneSpawnRequestsCache[k1] = null; 136 - } 137 - 138 - sceneSpawnRequestsCacheCurrentPos = 0; 139 - for (int l1 = 0; l1 < interactiveObjects.length; l1++) { 140 - interactiveObjects[l1] = null; 141 - } 142 - 143 - } 144 - 145 - public void setHeightLevel(int z) { 146 - currentPositionZ = z; 147 - for (int x = 0; x < mapSizeX; x++) { 148 - for (int y = 0; y < mapSizeY; y++) { 149 - if (tileArray.isTileEmpty(z, x, y)) { 150 - tileArray.setTile(z, x, y, new SceneTile(x, y, z)); 151 - } 152 - } 153 - 154 - } 155 - 156 - } 157 - 158 - void setBridgeMode(int x, int y) { 159 - SceneTile scenetile = tileArray.getTile(0, x, y); 160 - for (int z = 0; z < 3; z++) { 161 - SceneTile _tile = tileArray.setTile(z, x, y, tileArray.getTile(z + 1, x, y)); 162 - if (_tile != null) { 163 - _tile.z--; 164 - for (int e = 0; e < _tile.entityCount; e++) { 165 - InteractiveObject entity = _tile.interactiveObjects[e]; 166 - if ((entity.uid >> 29 & 3) == 2 && entity.tileLeft == x && entity.tileTop == y) { 167 - entity.z--; 168 - } 169 - } 170 - 171 - } 172 - } 173 - 174 - if (tileArray.isTileEmpty(0, x, y)) { 175 - tileArray.setTile(0, x, y, new SceneTile(x, y, 0)); 176 - } 177 - tileArray.getTile(0, x, y).tileBelow = scenetile; 178 - tileArray.clearTile(3, x, y); 179 - } 180 - 181 - static void createCullingCluster(final int z, int highestX, int lowestX, int highestY, int lowestY, int highestZ, int lowestZ, int searchMask) { 182 - SceneCluster scenecluster = new SceneCluster(); 183 - scenecluster.tileStartX = lowestX / 128; 184 - scenecluster.tileEndX = highestX / 128; 185 - scenecluster.tileStartY = lowestY / 128; 186 - scenecluster.tileEndY = highestY / 128; 187 - scenecluster.searchMask = searchMask; 188 - scenecluster.worldStartX = lowestX; 189 - scenecluster.worldEndX = highestX; 190 - scenecluster.worldStartY = lowestY; 191 - scenecluster.worldEndY = highestY; 192 - scenecluster.worldEndZ = highestZ; 193 - scenecluster.worldStartZ = lowestZ; 194 - cullingClusters[z][cullingClusterPointer[z]++] = scenecluster; 195 - } 196 - 197 - void setTileLogicHeight(int z, int x, int y, int logicHeight) { 198 - SceneTile sceneTile = tileArray.getTile(z, x, y); 199 - if (sceneTile != null) { 200 - sceneTile.logicHeight = logicHeight; 201 - } 202 - } 203 - 204 - void addTile(int plane, int x, int y, int shape, int clippingPathRotation, int textureId, int vertexHeightSW, int vertexHeightSE, int vertexHeightNE, int vertexHeightNW, int cA, int cB, 205 - int cD, int cC, int colourA, int colourB, int colourD, int colourC, int underlayRGB, int overlayRGB) { 206 - if (shape == 0) { 207 - GenericTile tile = new GenericTile(cA, cB, cC, cD, -1, underlayRGB, false); 208 - for (int _z = plane; _z >= 0; _z--) { 209 - if (tileArray.isTileEmpty(_z, x, y)) { 210 - tileArray.setTile(_z, x, y, new SceneTile(x, y, _z)); 211 - } 212 - } 213 - 214 - tileArray.getTile(plane, x, y).plainTile = tile; 215 - } else if (shape == 1) { 216 - GenericTile tile = new GenericTile(colourA, colourB, colourC, colourD, textureId, overlayRGB, vertexHeightSW == vertexHeightSE && vertexHeightSW == vertexHeightNE && vertexHeightSW == vertexHeightNW); 217 - for (int _z = plane; _z >= 0; _z--) { 218 - if (tileArray.isTileEmpty(_z, x, y)) { 219 - tileArray.setTile(_z, x, y, new SceneTile(x, y, _z)); 220 - } 221 - } 222 - 223 - 224 - tileArray.getTile(plane, x, y).plainTile = tile; 225 - } else { 226 - ComplexTile tile = new ComplexTile(x, vertexHeightSW, vertexHeightSE, vertexHeightNW, vertexHeightNE, y, clippingPathRotation, textureId, shape, cA, colourA, cB, colourB, cC, colourC, cD, colourD, overlayRGB, underlayRGB); 227 - for (int _z = plane; _z >= 0; _z--) { 228 - if (tileArray.isTileEmpty(_z, x, y)) { 229 - tileArray.setTile(_z, x, y, new SceneTile(x, y, _z)); 230 - } 231 - } 232 - 233 - 234 - tileArray.getTile(plane, x, y).shapedTile = tile; 235 - } 236 - } 237 - 238 - void addGroundDecoration(int x, int y, int z, int drawHeight, int uid, Renderable renderable, byte config) { 239 - if (renderable == null) { 240 - return; 241 - } 242 - FloorDecoration floorDecoration = new FloorDecoration(); 243 - floorDecoration.renderable = renderable; 244 - floorDecoration.x = x * 128 + 64; 245 - floorDecoration.y = y * 128 + 64; 246 - floorDecoration.z = drawHeight; 247 - floorDecoration.uid = uid; 248 - floorDecoration.config = config; 249 - if (tileArray.isTileEmpty(z, x, y)) { 250 - tileArray.setTile(z, x, y, new SceneTile(x, y, z)); 251 - } 252 - tileArray.getTile(z, x, y).floorDecoration = floorDecoration; 253 - } 254 - 255 - public void addGroundItemTile(int x, int y, int z, int drawHeight, int uid, Renderable firstGroundItem, Renderable secondGroundItem, 256 - Renderable thirdGroundItem) { 257 - GroundItemTile groundItemTile = new GroundItemTile(); 258 - groundItemTile.firstGroundItem = firstGroundItem; 259 - groundItemTile.x = x * 128 + 64; 260 - groundItemTile.y = y * 128 + 64; 261 - groundItemTile.z = drawHeight; 262 - groundItemTile.uid = uid; 263 - groundItemTile.secondGroundItem = secondGroundItem; 264 - groundItemTile.thirdGroundItem = thirdGroundItem; 265 - int k1 = 0; 266 - SceneTile sceneTile = tileArray.getTile(z, x, y); 267 - if (sceneTile != null) { 268 - for (int e = 0; e < sceneTile.entityCount; e++) { 269 - if (sceneTile.interactiveObjects[e].renderable instanceof Model) { 270 - int i2 = ((Model) sceneTile.interactiveObjects[e].renderable).anInt1675; 271 - if (i2 > k1) { 272 - k1 = i2; 273 - } 274 - } 275 - } 276 - 277 - } 278 - groundItemTile.anInt180 = k1; 279 - if (tileArray.isTileEmpty(z, x, y)) { 280 - tileArray.setTile(z, x, y, new SceneTile(x, y, z)); 281 - } 282 - tileArray.getTile(z, x, y).groundItemTile = groundItemTile; 283 - } 284 - 285 - void addWall(int x, int y, int z, int drawHeight, int orientation, int orientation2, int uid, Renderable primary, Renderable secondary, byte config) { 286 - if (primary != null || secondary != null) { 287 - Wall wall = new Wall(); 288 - wall.uid = uid; 289 - wall.config = config; 290 - wall.x = x * 128 + 64; 291 - wall.y = y * 128 + 64; 292 - wall.z = drawHeight; 293 - wall.primary = primary; 294 - wall.secondary = secondary; 295 - wall.orientation = orientation; 296 - wall.orientation2 = orientation2; 297 - for (int _z = z; _z >= 0; _z--) { 298 - if (tileArray.isTileEmpty(_z, x, y)) { 299 - tileArray.setTile(_z, x, y, new SceneTile(x, y, _z)); 300 - 301 - } 302 - } 303 - 304 - tileArray.getTile(z, x, y).wall = wall; 305 - } 306 - } 307 - 308 - void addWallDecoration(int x, int y, int z, int drawHeight, int offsetX, int offsetY, int face, int uid, Renderable renderable, byte config, int faceBits) { 309 - if (renderable != null) { 310 - WallDecoration wallDecoration = new WallDecoration(); 311 - wallDecoration.uid = uid; 312 - wallDecoration.config = config; 313 - wallDecoration.x = x * 128 + 64 + offsetX; 314 - wallDecoration.y = y * 128 + 64 + offsetY; 315 - wallDecoration.z = drawHeight; 316 - wallDecoration.renderable = renderable; 317 - wallDecoration.configBits = faceBits; 318 - wallDecoration.face = face; 319 - for (int planeCounter = z; planeCounter >= 0; planeCounter--) { 320 - if (tileArray.isTileEmpty(planeCounter, x, y)) { 321 - tileArray.setTile(planeCounter, x, y, new SceneTile(x, y, planeCounter)); 322 - 323 - } 324 - } 325 - 326 - tileArray.getTile(z, x, y).wallDecoration = wallDecoration; 327 - } 328 - } 329 - 330 - boolean addEntityB(int x, int y, int z, int worldZ, int rotation, int tileWidth, int tileHeight, int uid, Renderable entity, byte config) { 331 - if (entity == null) { 332 - return true; 333 - } else { 334 - int worldX = x * 128 + 64 * tileHeight; 335 - int worldY = y * 128 + 64 * tileWidth; 336 - return addRenderableC(x, y, z, worldX, worldY, worldZ, rotation, tileWidth, tileHeight, uid, entity, false, config); 337 - } 338 - } 339 - 340 - public boolean addEntity(int z, int worldX, int worldY, int worldZ, Renderable entity, int uid, int delta, boolean accountForYaw, 341 - int yaw) { 342 - if (entity == null) { 343 - return true; 344 - } 345 - int minX = worldX - delta; 346 - int minY = worldY - delta; 347 - int maxX = worldX + delta; 348 - int maxY = worldY + delta; 349 - if (accountForYaw) { 350 - if (yaw > 640 && yaw < 1408) { 351 - maxY += 128; 352 - } 353 - if (yaw > 1152 && yaw < 1920) { 354 - maxX += 128; 355 - } 356 - if (yaw > 1664 || yaw < 384) { 357 - minY -= 128; 358 - } 359 - if (yaw > 128 && yaw < 896) { 360 - minX -= 128; 361 - } 362 - } 363 - minX /= 128; 364 - minY /= 128; 365 - maxX /= 128; 366 - maxY /= 128; 367 - return addRenderableC(minX, minY, z, worldX, worldY, worldZ, yaw, (maxY - minY) + 1, (maxX - minX) + 1, uid, entity, true, (byte) 0); 368 - } 369 - 370 - public boolean addEntity(int x, int y, int z, int worldX, int worldY, int worldZ, int rotation, int tileWidth, int tileHeight, Renderable entity, 371 - int uid) { 372 - 373 - return entity == null || addRenderableC(x, y, z, worldX, worldY, worldZ, rotation, (tileWidth - y) + 1, (tileHeight - x) + 1, uid, entity, true, 374 - (byte) 0); 375 - } 376 - 377 - private boolean addRenderableC(int minX, int minY, int z, int worldX, int worldY, int worldZ, int rotation, int tileWidth, int tileHeight, 378 - int uid, Renderable renderable, boolean isDynamic, byte config) { 379 - for (int x = minX; x < minX + tileHeight; x++) { 380 - for (int y = minY; y < minY + tileWidth; y++) { 381 - if (x < 0 || y < 0 || x >= mapSizeX || y >= mapSizeY) { 382 - return false; 383 - } 384 - SceneTile tile = tileArray.getTile(z, x, y); 385 - if (tile != null && tile.entityCount >= 5) { 386 - return false; 387 - } 388 - } 389 - 390 - } 391 - 392 - InteractiveObject interactiveObject = new InteractiveObject(); 393 - interactiveObject.uid = uid; 394 - interactiveObject.config = config; 395 - interactiveObject.z = z; 396 - interactiveObject.worldX = worldX; 397 - interactiveObject.worldY = worldY; 398 - interactiveObject.worldZ = worldZ; 399 - interactiveObject.renderable = renderable; 400 - interactiveObject.rotation = rotation; 401 - interactiveObject.tileLeft = minX; 402 - interactiveObject.tileTop = minY; 403 - interactiveObject.tileRight = (minX + tileHeight) - 1; 404 - interactiveObject.tileBottom = (minY + tileWidth) - 1; 405 - for (int x = minX; x < minX + tileHeight; x++) { 406 - for (int y = minY; y < minY + tileWidth; y++) { 407 - int size = 0; 408 - if (x > minX) { 409 - size++; 410 - } 411 - if (x < (minX + tileHeight) - 1) { 412 - size += 4; 413 - } 414 - if (y > minY) { 415 - size += 8; 416 - } 417 - if (y < (minY + tileWidth) - 1) { 418 - size += 2; 419 - } 420 - for (int _z = z; _z >= 0; _z--) { 421 - if (tileArray.isTileEmpty(_z, x, y)) { 422 - tileArray.setTile(_z, x, y, new SceneTile(x, y, _z)); 423 - } 424 - } 425 - 426 - SceneTile sceneTile = tileArray.getTile(z, x, y); 427 - sceneTile.interactiveObjects[sceneTile.entityCount] = interactiveObject; 428 - sceneTile.sceneSpawnRequestsSize[sceneTile.entityCount] = size; 429 - sceneTile.interactiveObjectsSizeOR |= size; 430 - sceneTile.entityCount++; 431 - } 432 - 433 - } 434 - 435 - if (isDynamic) { 436 - sceneSpawnRequestsCache[sceneSpawnRequestsCacheCurrentPos++] = interactiveObject; 437 - } 438 - return true; 439 - } 440 - 441 - public void clearInteractiveObjectCache() { 442 - for (int j = 0; j < sceneSpawnRequestsCacheCurrentPos; j++) { 443 - InteractiveObject interactiveObject = sceneSpawnRequestsCache[j]; 444 - remove(interactiveObject); 445 - sceneSpawnRequestsCache[j] = null; 446 - } 447 - 448 - sceneSpawnRequestsCacheCurrentPos = 0; 449 - } 450 - 451 - private void remove(InteractiveObject entity) { 452 - for (int x = entity.tileLeft; x <= entity.tileRight; x++) { 453 - for (int y = entity.tileTop; y <= entity.tileBottom; y++) { 454 - SceneTile tile = tileArray.getTile(entity.z, x, y); 455 - if (tile != null) { 456 - for (int e = 0; e < tile.entityCount; e++) { 457 - if (tile.interactiveObjects[e] != entity) { 458 - continue; 459 - } 460 - tile.entityCount--; 461 - for (int e2 = e; e2 < tile.entityCount; e2++) { 462 - tile.interactiveObjects[e2] = tile.interactiveObjects[e2 + 1]; 463 - tile.sceneSpawnRequestsSize[e2] = tile.sceneSpawnRequestsSize[e2 + 1]; 464 - } 465 - 466 - tile.interactiveObjects[tile.entityCount] = null; 467 - break; 468 - } 469 - 470 - tile.interactiveObjectsSizeOR = 0; 471 - for (int j1 = 0; j1 < tile.entityCount; j1++) { 472 - tile.interactiveObjectsSizeOR |= tile.sceneSpawnRequestsSize[j1]; 473 - } 474 - 475 - } 476 - } 477 - 478 - } 479 - 480 - } 481 - 482 - void displaceWallDecoration(int x, int y, int z, int displacement) { 483 - SceneTile sceneTile = tileArray.getTile(z, x, y); 484 - if (sceneTile == null) { 485 - return; 486 - } 487 - WallDecoration wallDecoration = sceneTile.wallDecoration; 488 - if (wallDecoration == null) { 489 - return; 490 - } 491 - int absX = x * 128 + 64; 492 - int absY = y * 128 + 64; 493 - wallDecoration.x = absX + ((wallDecoration.x - absX) * displacement) / 16; 494 - wallDecoration.y = absY + ((wallDecoration.y - absY) * displacement) / 16; 495 - 496 - } 497 - 498 - public void removeWallObject(int x, int y, int z) { 499 - SceneTile tile = tileArray.getTile(z, x, y); 500 - if (tile != null) { 501 - tile.wall = null; 502 - } 503 - } 504 - 505 - public void removeWallDecoration(int x, int y, int z) { 506 - SceneTile tile = tileArray.getTile(z, x, y); 507 - if (tile != null) { 508 - tile.wallDecoration = null; 509 - } 510 - } 511 - 512 - public void removeInteractiveObject(int x, int y, int z) { 513 - SceneTile tile = tileArray.getTile(z, x, y); 514 - if (tile == null) { 515 - return; 516 - } 517 - for (int e = 0; e < tile.entityCount; e++) { 518 - InteractiveObject interactiveObject = tile.interactiveObjects[e]; 519 - if ((interactiveObject.uid >> 29 & 3) == 2 && interactiveObject.tileLeft == x && interactiveObject.tileTop == y) { 520 - remove(interactiveObject); 521 - return; 522 - } 523 - } 524 - 525 - } 526 - 527 - public void method261(int x, int y, int z) { 528 - SceneTile sceneTile = tileArray.getTile(z, x, y); 529 - if (sceneTile == null) { 530 - return; 531 - } 532 - sceneTile.floorDecoration = null; 533 - } 534 - 535 - public void clearGroundItem(int z, int x, int y) { 536 - SceneTile sceneTile = tileArray.getTile(z, x, y); 537 - if (sceneTile != null) { 538 - sceneTile.groundItemTile = null; 539 - } 540 - } 541 - 542 - public Wall getWallObject(int level, int x, int y) { 543 - SceneTile sceneTile = tileArray.getTile(level, x, y); 544 - 545 - if (sceneTile == null) { 546 - return null; 547 - } else { 548 - return sceneTile.wall; 549 - } 550 - } 551 - 552 - public WallDecoration getWallDecoration(int level, int y, int x) { 553 - SceneTile sceneTile = tileArray.getTile(level, x, y); 554 - 555 - if (sceneTile == null) { 556 - return null; 557 - } else { 558 - return sceneTile.wallDecoration; 559 - } 560 - } 561 - 562 - public InteractiveObject method265(int x, int y, int level) { 563 - SceneTile sceneTile = tileArray.getTile(level, x, y); 564 - if (sceneTile == null) { 565 - return null; 566 - } 567 - for (int i = 0; i < sceneTile.entityCount; i++) { 568 - InteractiveObject interactiveObject = sceneTile.interactiveObjects[i]; 569 - if ((interactiveObject.uid >> 29 & 3) == 2 && interactiveObject.tileLeft == x && interactiveObject.tileTop == y) { 570 - return interactiveObject; 571 - } 572 - } 573 - 574 - return null; 575 - } 576 - 577 - public FloorDecoration getFloorDecoration(int level, int x, int y) { 578 - SceneTile sceneTile = tileArray.getTile(level, x, y); 579 - if (sceneTile == null || sceneTile.floorDecoration == null) { 580 - return null; 581 - } else { 582 - return sceneTile.floorDecoration; 583 - } 584 - } 585 - 586 - public int getWallObjectHash(int x, int y, int z) { 587 - SceneTile sceneTile = tileArray.getTile(z, x, y); 588 - if (sceneTile == null || sceneTile.wall == null) { 589 - return 0; 590 - } else { 591 - return sceneTile.wall.uid; 592 - } 593 - } 594 - 595 - public int getWallDecorationHash(int x, int z, int y) { 596 - SceneTile sceneTile = tileArray.getTile(z, x, y); 597 - if (sceneTile == null || sceneTile.wallDecoration == null) { 598 - return 0; 599 - } else { 600 - return sceneTile.wallDecoration.uid; 601 - } 602 - } 603 - 604 - public int getLocationHash(int z, int x, int y) { 605 - SceneTile sceneTile = tileArray.getTile(z, x, y); 606 - if (sceneTile == null) { 607 - return 0; 608 - } 609 - for (int l = 0; l < sceneTile.entityCount; l++) { 610 - InteractiveObject interactiveObject = sceneTile.interactiveObjects[l]; 611 - if ((interactiveObject.uid >> 29 & 3) == 2 && interactiveObject.tileLeft == x && interactiveObject.tileTop == y) { 612 - return interactiveObject.uid; 613 - } 614 - } 615 - 616 - return 0; 617 - } 618 - 619 - public int getFloorDecorationHash(int z, int x, int y) { 620 - SceneTile sceneTile = tileArray.getTile(z, x, y); 621 - if (sceneTile == null || sceneTile.floorDecoration == null) { 622 - return 0; 623 - } else { 624 - return sceneTile.floorDecoration.uid; 625 - } 626 - } 627 - 628 - public int getArrangement(int z, int x, int y, int l) { 629 - SceneTile sceneTile = tileArray.getTile(z, x, y); 630 - if (sceneTile == null) { 631 - return -1; 632 - } 633 - if (sceneTile.wall != null && sceneTile.wall.uid == l) { 634 - return sceneTile.wall.config & 0xff; 635 - } 636 - if (sceneTile.wallDecoration != null && sceneTile.wallDecoration.uid == l) { 637 - return sceneTile.wallDecoration.config & 0xff; 638 - } 639 - if (sceneTile.floorDecoration != null && sceneTile.floorDecoration.uid == l) { 640 - return sceneTile.floorDecoration.config & 0xff; 641 - } 642 - for (int i1 = 0; i1 < sceneTile.entityCount; i1++) { 643 - if (sceneTile.interactiveObjects[i1].uid == l) { 644 - return sceneTile.interactiveObjects[i1].config & 0xff; 645 - } 646 - } 647 - 648 - return -1; 649 - } 650 - 651 - void shadeModels(int i, int j, int k) { 652 - for (int _z = 0; _z < mapSizeZ; _z++) { 653 - for (int _x = 0; _x < mapSizeX; _x++) { 654 - for (int _y = 0; _y < mapSizeY; _y++) { 655 - SceneTile tile = tileArray.getTile(_z, _x, _y); 656 - if (tile != null) { 657 - Wall wall = tile.wall; 658 - if (wall != null && wall.primary != null 659 - && wall.primary.verticesNormal != null) { 660 - method274(_y, _z, 0, 1, (Model) wall.primary, _x, 1); 661 - if (wall.secondary != null 662 - && wall.secondary.verticesNormal != null) { 663 - method274(_y, _z, 0, 1, (Model) wall.secondary, _x, 1); 664 - mergeNormals((Model) wall.primary, 665 - (Model) wall.secondary, 0, 0, 0, false); 666 - ((Model) wall.secondary).handleShading(i, j, 0, k); 667 - } 668 - ((Model) wall.primary).handleShading(i, j, 0, k); 669 - } 670 - for (int k1 = 0; k1 < tile.entityCount; k1++) { 671 - InteractiveObject interactiveObject = tile.interactiveObjects[k1]; 672 - if (interactiveObject != null && interactiveObject.renderable != null 673 - && interactiveObject.renderable.verticesNormal != null) { 674 - method274(_y, _z, 0, (interactiveObject.tileRight - interactiveObject.tileLeft) + 1, 675 - (Model) interactiveObject.renderable, _x, 676 - (interactiveObject.tileBottom - interactiveObject.tileTop) + 1); 677 - ((Model) interactiveObject.renderable).handleShading(i, j, 0, k); 678 - } 679 - } 680 - 681 - FloorDecoration floorDecoration = tile.floorDecoration; 682 - if (floorDecoration != null && floorDecoration.renderable.verticesNormal != null) { 683 - method273(_x, (Model) floorDecoration.renderable, _y, _z, 0); 684 - ((Model) floorDecoration.renderable).handleShading(i, j, 0, k); 685 - } 686 - } 687 - } 688 - 689 - } 690 - 691 - } 692 - 693 - } 694 - 695 - private void method273(int x, Model model, int y, int z, int l) { 696 - if (l != 0) { 697 - return; 698 - } 699 - if (x < mapSizeX) { 700 - SceneTile sceneTile = tileArray.getTile(z, x + 1, y); 701 - if (sceneTile != null && sceneTile.floorDecoration != null 702 - && sceneTile.floorDecoration.renderable.verticesNormal != null) { 703 - mergeNormals(model, 704 - (Model) sceneTile.floorDecoration.renderable, 128, 0, 0, true); 705 - } 706 - } 707 - if (y < mapSizeX) { 708 - SceneTile sceneTile = tileArray.getTile(z, x, y + 1); 709 - if (sceneTile != null && sceneTile.floorDecoration != null 710 - && sceneTile.floorDecoration.renderable.verticesNormal != null) { 711 - mergeNormals(model, 712 - (Model) sceneTile.floorDecoration.renderable, 0, 0, 128, true); 713 - } 714 - } 715 - if (x < mapSizeX && y < mapSizeY) { 716 - SceneTile sceneTile = tileArray.getTile(z, x + 1, y + 1); 717 - if (sceneTile != null && sceneTile.floorDecoration != null 718 - && sceneTile.floorDecoration.renderable.verticesNormal != null) { 719 - mergeNormals(model, 720 - (Model) sceneTile.floorDecoration.renderable, 128, 0, 128, true); 721 - } 722 - } 723 - if (x < mapSizeX && y > 0) { 724 - SceneTile sceneTile = tileArray.getTile(z, x + 1, y - 1); 725 - if (sceneTile != null && sceneTile.floorDecoration != null 726 - && sceneTile.floorDecoration.renderable.verticesNormal != null) { 727 - mergeNormals(model, 728 - (Model) sceneTile.floorDecoration.renderable, 128, 0, -128, 729 - true); 730 - } 731 - } 732 - } 733 - 734 - private void method274(int i, int j, int k, int l, Model class50_sub1_sub4_sub4, int i1, int j1) { 735 - boolean flag = true; 736 - int k1 = i1; 737 - int l1 = i1 + l; 738 - int i2 = i - 1; 739 - int j2 = i + j1; 740 - for (int z = j; z <= j + 1; z++) { 741 - if (z != mapSizeZ) { 742 - for (int x = k1; x <= l1; x++) { 743 - if (x >= 0 && x < mapSizeX) { 744 - for (int y = i2; y <= j2; y++) { 745 - if (y >= 0 && y < mapSizeY && (!flag || x >= l1 || y >= j2 || y < i && x != i1)) { 746 - SceneTile class50_sub3 = tileArray.getTile(z, x, y); 747 - if (class50_sub3 != null) { 748 - int j3 = (heightMap[z][x][y] 749 - + heightMap[z][x + 1][y] 750 - + heightMap[z][x][y + 1] + heightMap[z][x + 1][y + 1]) 751 - / 4 752 - - (heightMap[j][i1][i] 753 - + heightMap[j][i1 + 1][i] 754 - + heightMap[j][i1][i + 1] + heightMap[j][i1 + 1][i + 1]) 755 - / 4; 756 - Wall wall = class50_sub3.wall; 757 - if (wall != null && wall.primary != null 758 - && wall.primary.verticesNormal != null) { 759 - mergeNormals(class50_sub1_sub4_sub4, 760 - (Model) wall.primary, (x - i1) 761 - * 128 + (1 - l) * 64, j3, (y - i) * 128 + (1 - j1) * 64, flag); 762 - } 763 - if (wall != null && wall.secondary != null 764 - && wall.secondary.verticesNormal != null) { 765 - mergeNormals(class50_sub1_sub4_sub4, 766 - (Model) wall.secondary, (x - i1) 767 - * 128 + (1 - l) * 64, j3, (y - i) * 128 + (1 - j1) * 64, flag); 768 - } 769 - for (int k3 = 0; k3 < class50_sub3.entityCount; k3++) { 770 - InteractiveObject interactiveObject = class50_sub3.interactiveObjects[k3]; 771 - if (interactiveObject != null && interactiveObject.renderable != null 772 - && interactiveObject.renderable.verticesNormal != null) { 773 - int l3 = (interactiveObject.tileRight - interactiveObject.tileLeft) + 1; 774 - int i4 = (interactiveObject.tileBottom - interactiveObject.tileTop) + 1; 775 - mergeNormals(class50_sub1_sub4_sub4, 776 - (Model) interactiveObject.renderable, 777 - (interactiveObject.tileLeft - i1) * 128 + (l3 - l) * 64, j3, 778 - (interactiveObject.tileTop - i) * 128 + (i4 - j1) * 64, flag); 779 - } 780 - } 781 - 782 - } 783 - } 784 - } 785 - 786 - } 787 - } 788 - 789 - k1--; 790 - flag = false; 791 - } 792 - } 793 - 794 - if (k == 0) { 795 - } 796 - } 797 - 798 - private void mergeNormals(Model modelA, 799 - Model modelB, int i, int j, int k, boolean flag) { 800 - anInt503++; 801 - int count = 0; 802 - int[] vertices = modelB.verticesX; 803 - int vertexCount = modelB.vertexCount; 804 - int minX = modelB.worldX >> 16; 805 - int maxX = (modelB.worldX << 16) >> 16; 806 - int maxZ = modelB.worldZ >> 16; 807 - int minZ = (modelB.worldZ << 16) >> 16; 808 - for (int vertex = 0; vertex < modelA.vertexCount; vertex++) { 809 - VertexNormal vertexNormal = modelA.verticesNormal[vertex]; 810 - VertexNormal offsetVertexNormal = modelA.vertexNormalOffset[vertex]; 811 - if (offsetVertexNormal.magnitude != 0) { 812 - int y = modelA.verticesY[vertex] - j; 813 - if (y <= modelB.maxY) { 814 - int x = modelA.verticesX[vertex] - i; 815 - if (x >= minX && x <= maxX) { 816 - int z = modelA.verticesZ[vertex] - k; 817 - if (z >= minZ && z <= maxZ) { 818 - for (int v = 0; v < vertexCount; v++) { 819 - VertexNormal class40_2 = modelB.verticesNormal[v]; 820 - VertexNormal class40_3 = modelB.vertexNormalOffset[v]; 821 - if (x == vertices[v] && z == modelB.verticesZ[v] 822 - && y == modelB.verticesY[v] && class40_3.magnitude != 0) { 823 - vertexNormal.x += class40_3.x; 824 - vertexNormal.y += class40_3.y; 825 - vertexNormal.z += class40_3.z; 826 - vertexNormal.magnitude += class40_3.magnitude; 827 - class40_2.x += offsetVertexNormal.x; 828 - class40_2.y += offsetVertexNormal.y; 829 - class40_2.z += offsetVertexNormal.z; 830 - class40_2.magnitude += offsetVertexNormal.magnitude; 831 - count++; 832 - anIntArray486[vertex] = anInt503; 833 - anIntArray487[v] = anInt503; 834 - } 835 - } 836 - 837 - } 838 - } 839 - } 840 - } 841 - } 842 - 843 - if (count < 3 || !flag) { 844 - return; 845 - } 846 - for (int k2 = 0; k2 < modelA.triangleCount; k2++) { 847 - if (anIntArray486[modelA.trianglePointsX[k2]] == anInt503 848 - && anIntArray486[modelA.trianglePointsY[k2]] == anInt503 849 - && anIntArray486[modelA.trianglePointsZ[k2]] == anInt503) { 850 - modelA.triangleDrawType[k2] = -1; 851 - } 852 - } 853 - 854 - for (int l2 = 0; l2 < modelB.triangleCount; l2++) { 855 - if (anIntArray487[modelB.trianglePointsX[l2]] == anInt503 856 - && anIntArray487[modelB.trianglePointsY[l2]] == anInt503 857 - && anIntArray487[modelB.trianglePointsZ[l2]] == anInt503) { 858 - modelB.triangleDrawType[l2] = -1; 859 - } 860 - } 861 - 862 - } 863 - 864 - public void renderMinimapTile(int[] pixels, int pixelPointer, int j, int z, int x, int y) { 865 - SceneTile sceneTile = tileArray.getTile(z, x, y); 866 - if (sceneTile == null) { 867 - return; 868 - } 869 - GenericTile genericTile = sceneTile.plainTile; 870 - if (genericTile != null) { 871 - int tileRGB = genericTile.rgbColor; 872 - if (tileRGB == 0) { 873 - return; 874 - } 875 - // if ((tileRGB & 0xFF0000) >> 16 >= 160) { 876 - // System.out.println("FOUND RED!!!"); 877 - // System.out.println(genericTile.flat); 878 - // } 879 - for (int k1 = 0; k1 < 4; k1++) { 880 - pixels[pixelPointer] = tileRGB; 881 - pixels[pixelPointer + 1] = tileRGB; 882 - pixels[pixelPointer + 2] = tileRGB; 883 - pixels[pixelPointer + 3] = tileRGB; 884 - pixelPointer += j; 885 - } 886 - 887 - return; 888 - } 889 - ComplexTile complexTile = sceneTile.shapedTile; 890 - if (complexTile == null) { 891 - return; 892 - } 893 - int shapeA = complexTile.shape; 894 - int shapeB = complexTile.rotation; 895 - int underlayRGB = complexTile.underlayRGB; 896 - int overlayRGB = complexTile.overlayRGB; 897 - int[] shapePoints = tileShapePoints[shapeA]; 898 - int[] shapeIndices = tileShapeIndices[shapeB]; 899 - int shapePtr = 0; 900 - if (underlayRGB != 0) { 901 - for (int linePtr = 0; linePtr < 4; linePtr++) { 902 - pixels[pixelPointer] = shapePoints[shapeIndices[shapePtr++]] != 0 ? overlayRGB : underlayRGB; 903 - pixels[pixelPointer + 1] = shapePoints[shapeIndices[shapePtr++]] != 0 ? overlayRGB : underlayRGB; 904 - pixels[pixelPointer + 2] = shapePoints[shapeIndices[shapePtr++]] != 0 ? overlayRGB : underlayRGB; 905 - pixels[pixelPointer + 3] = shapePoints[shapeIndices[shapePtr++]] != 0 ? overlayRGB : underlayRGB; 906 - pixelPointer += j; 907 - } 908 - 909 - return; 910 - } 911 - for (int linePtr = 0; linePtr < 4; linePtr++) { 912 - if (shapePoints[shapeIndices[shapePtr++]] != 0) { 913 - pixels[pixelPointer] = overlayRGB; 914 - } 915 - if (shapePoints[shapeIndices[shapePtr++]] != 0) { 916 - pixels[pixelPointer + 1] = overlayRGB; 917 - } 918 - if (shapePoints[shapeIndices[shapePtr++]] != 0) { 919 - pixels[pixelPointer + 2] = overlayRGB; 920 - } 921 - if (shapePoints[shapeIndices[shapePtr++]] != 0) { 922 - pixels[pixelPointer + 3] = overlayRGB; 923 - } 924 - pixelPointer += j; 925 - } 926 - 927 - } 928 - 929 - public static void method277(int l, int k, int i1, int i, int[] ai) { 930 - anInt510 = 0; 931 - anInt511 = 0; 932 - anInt512 = i1; 933 - anInt513 = i; 934 - anInt508 = i1 / 2; 935 - anInt509 = i / 2; 936 - boolean[][][][] aflag = new boolean[9][32][53][53]; 937 - for (int j1 = 128; j1 <= 384; j1 += 32) { 938 - for (int k1 = 0; k1 < 2048; k1 += 64) { 939 - curveSineY = Model.SINE[j1]; 940 - curveCosineY = Model.COSINE[j1]; 941 - curveSineX = Model.SINE[k1]; 942 - curveCosineX = Model.COSINE[k1]; 943 - int i2 = (j1 - 128) / 32; 944 - int k2 = k1 / 64; 945 - for (int i3 = -26; i3 <= 26; i3++) { 946 - for (int k3 = -26; k3 <= 26; k3++) { 947 - int l3 = i3 * 128; 948 - int j4 = k3 * 128; 949 - boolean flag1 = false; 950 - for (int l4 = -l; l4 <= k; l4 += 128) { 951 - if (!method278(j4, l3, ai[i2] + l4)) { 952 - continue; 953 - } 954 - flag1 = true; 955 - break; 956 - } 957 - 958 - aflag[i2][k2][i3 + 25 + 1][k3 + 25 + 1] = flag1; 959 - } 960 - 961 - } 962 - 963 - } 964 - 965 - } 966 - 967 - for (int l1 = 0; l1 < 8; l1++) { 968 - for (int j2 = 0; j2 < 32; j2++) { 969 - for (int l2 = -25; l2 < 25; l2++) { 970 - for (int j3 = -25; j3 < 25; j3++) { 971 - boolean flag = false; 972 - label0: 973 - for (int i4 = -1; i4 <= 1; i4++) { 974 - for (int k4 = -1; k4 <= 1; k4++) { 975 - if (aflag[l1][j2][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 976 - flag = true; 977 - } else if (aflag[l1][(j2 + 1) % 31][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 978 - flag = true; 979 - } else if (aflag[l1 + 1][j2][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 980 - flag = true; 981 - } else { 982 - if (!aflag[l1 + 1][(j2 + 1) % 31][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 983 - continue; 984 - } 985 - flag = true; 986 - } 987 - break label0; 988 - } 989 - 990 - } 991 - 992 - TILE_VISIBILITY_MAPS[l1][j2][l2 + 25][j3 + 25] = flag; 993 - } 994 - 995 - } 996 - 997 - } 998 - 999 - } 1000 - } 1001 - 1002 - private static boolean method278(int i, int j, int l) { 1003 - int i1 = i * curveSineX + j * curveCosineX >> 16; 1004 - int j1 = i * curveCosineX - j * curveSineX >> 16; 1005 - int k1 = l * curveSineY + j1 * curveCosineY >> 16; 1006 - int l1 = l * curveCosineY - j1 * curveSineY >> 16; 1007 - if (k1 < 50 || k1 > 3500) { 1008 - return false; 1009 - } 1010 - int i2 = anInt508 + (i1 << 9) / k1; 1011 - int j2 = anInt509 + (l1 << 9) / k1; 1012 - return i2 >= anInt510 && i2 <= anInt512 && j2 >= anInt511 && j2 <= anInt513; 1013 - } 1014 - 1015 - public void method279(int i, int j, int k) { 1016 - clicked = true; 1017 - clickX = j; 1018 - clickY = k; 1019 - clickedTileX = -1; 1020 - if (i != 0) { 1021 - } else { 1022 - clickedTileY = -1; 1023 - } 1024 - } 1025 - 1026 - public void render(int cameraPosX, int j, int k, int l, int cameraPosY, int curveX, int curveY) { 1027 - if (cameraPosX < 0) { 1028 - cameraPosX = 0; 1029 - } else if (cameraPosX >= mapSizeX * 128) { 1030 - cameraPosX = mapSizeX * 128 - 1; 1031 - } 1032 - if (cameraPosY < 0) { 1033 - cameraPosY = 0; 1034 - } else if (cameraPosY >= mapSizeY * 128) { 1035 - cameraPosY = mapSizeY * 128 - 1; 1036 - } 1037 - cycle++; 1038 - curveSineY = Model.SINE[curveY]; 1039 - curveCosineY = Model.COSINE[curveY]; 1040 - curveSineX = Model.SINE[curveX]; 1041 - curveCosineX = Model.COSINE[curveX]; 1042 - TILE_VISIBILITY_MAP = TILE_VISIBILITY_MAPS[(curveY - 128) / 32][curveX / 64]; 1043 - Scene.cameraPosX = cameraPosX; 1044 - cameraPosZ = l; 1045 - Scene.cameraPosY = cameraPosY; 1046 - cameraPositionTileX = cameraPosX / 128; 1047 - cameraPositionTileY = cameraPosY / 128; 1048 - plane = j; 1049 - currentPositionX = cameraPositionTileX - 25; 1050 - if (k != 0) { 1051 - return; 1052 - } 1053 - if (currentPositionX < 0) { 1054 - currentPositionX = 0; 1055 - } 1056 - currentPositionY = cameraPositionTileY - 25; 1057 - if (currentPositionY < 0) { 1058 - currentPositionY = 0; 1059 - } 1060 - mapBoundsX = cameraPositionTileX + 25; 1061 - if (mapBoundsX > mapSizeX) { 1062 - mapBoundsX = mapSizeX; 1063 - } 1064 - mapBoundsY = cameraPositionTileY + 25; 1065 - if (mapBoundsY > mapSizeY) { 1066 - mapBoundsY = mapSizeY; 1067 - } 1068 - processCulling(); 1069 - anInt461 = 0; 1070 - for (int z = currentPositionZ; z < mapSizeZ; z++) { 1071 - for (int x = currentPositionX; x < mapBoundsX; x++) { 1072 - for (int y = currentPositionY; y < mapBoundsY; y++) { 1073 - SceneTile tile = tileArray.getTile(z, x, y); 1074 - if (tile != null) { 1075 - if (tile.logicHeight > j 1076 - || !TILE_VISIBILITY_MAP[(x - cameraPositionTileX) + 25][(y - cameraPositionTileY) + 25] 1077 - && heightMap[z][x][y] - l < 2000) { 1078 - tile.draw = false; 1079 - tile.visible = false; 1080 - tile.wallCullDirection = 0; 1081 - } else { 1082 - tile.draw = true; 1083 - tile.visible = true; 1084 - tile.drawEntities = tile.entityCount > 0; 1085 - anInt461++; 1086 - } 1087 - } 1088 - } 1089 - 1090 - } 1091 - 1092 - } 1093 - 1094 - for (int z = currentPositionZ; z < mapSizeZ; z++) { 1095 - for (int offsetX = -25; offsetX <= 0; offsetX++) { 1096 - int x = cameraPositionTileX + offsetX; 1097 - int x2 = cameraPositionTileX - offsetX; 1098 - if (x >= currentPositionX || x2 < mapBoundsX) { 1099 - for (int offsetY = -25; offsetY <= 0; offsetY++) { 1100 - int y = cameraPositionTileY + offsetY; 1101 - int y2 = cameraPositionTileY - offsetY; 1102 - if (x >= currentPositionX) { 1103 - if (y >= currentPositionY) { 1104 - SceneTile sceneTile = tileArray.getTile(z, x, y); 1105 - if (sceneTile != null && sceneTile.draw) { 1106 - renderTile(sceneTile, true); 1107 - } 1108 - } 1109 - if (y2 < mapBoundsY) { 1110 - SceneTile sceneTile = tileArray.getTile(z, x, y2); 1111 - if (sceneTile != null && sceneTile.draw) { 1112 - renderTile(sceneTile, true); 1113 - } 1114 - } 1115 - } 1116 - if (x2 < mapBoundsX) { 1117 - if (y >= currentPositionY) { 1118 - SceneTile sceneTile = tileArray.getTile(z, x2, y); 1119 - if (sceneTile != null && sceneTile.draw) { 1120 - renderTile(sceneTile, true); 1121 - } 1122 - } 1123 - if (y2 < mapBoundsY) { 1124 - SceneTile sceneTile = tileArray.getTile(z, x2, y2); 1125 - if (sceneTile != null && sceneTile.draw) { 1126 - renderTile(sceneTile, true); 1127 - } 1128 - } 1129 - } 1130 - if (anInt461 == 0) { 1131 - clicked = false; 1132 - return; 1133 - } 1134 - } 1135 - 1136 - } 1137 - } 1138 - 1139 - } 1140 - 1141 - for (int z = currentPositionZ; z < mapSizeZ; z++) { 1142 - for (int offsetX = -25; offsetX <= 0; offsetX++) { 1143 - int x = cameraPositionTileX + offsetX; 1144 - int x2 = cameraPositionTileX - offsetX; 1145 - if (x >= currentPositionX || x2 < mapBoundsX) { 1146 - for (int offsetY = -25; offsetY <= 0; offsetY++) { 1147 - int y = cameraPositionTileY + offsetY; 1148 - int y2 = cameraPositionTileY - offsetY; 1149 - if (x >= currentPositionX) { 1150 - if (y >= currentPositionY) { 1151 - SceneTile tile = tileArray.getTile(z, x, y); 1152 - if (tile != null && tile.draw) { 1153 - renderTile(tile, false); 1154 - } 1155 - } 1156 - if (y2 < mapBoundsY) { 1157 - SceneTile tile = tileArray.getTile(z, x, y2); 1158 - if (tile != null && tile.draw) { 1159 - renderTile(tile, false); 1160 - } 1161 - } 1162 - } 1163 - if (x2 < mapBoundsX) { 1164 - if (y >= currentPositionY) { 1165 - SceneTile tile = tileArray.getTile(z, x2, y); 1166 - if (tile != null && tile.draw) { 1167 - renderTile(tile, false); 1168 - } 1169 - } 1170 - if (y2 < mapBoundsY) { 1171 - SceneTile tile = tileArray.getTile(z, x2, y2); 1172 - if (tile != null && tile.draw) { 1173 - renderTile(tile, false); 1174 - } 1175 - } 1176 - } 1177 - if (anInt461 == 0) { 1178 - clicked = false; 1179 - return; 1180 - } 1181 - } 1182 - 1183 - } 1184 - } 1185 - 1186 - } 1187 - 1188 - clicked = false; 1189 - } 1190 - 1191 - private void renderTile(SceneTile _tile, boolean flag) { 1192 - tileList.pushBack(_tile); 1193 - do { 1194 - SceneTile groundTile; 1195 - do { 1196 - groundTile = (SceneTile) tileList.pop(); 1197 - if (groundTile == null) { 1198 - return; 1199 - } 1200 - } while (!groundTile.visible); 1201 - int x = groundTile.x; 1202 - int y = groundTile.y; 1203 - int z = groundTile.z; 1204 - int level = groundTile.renderLevel; 1205 - if (groundTile.draw) { 1206 - if (flag) { 1207 - if (z > 0) { 1208 - SceneTile tile = tileArray.getTile(z - 1, x, y); 1209 - if (tile != null && tile.visible) { 1210 - continue; 1211 - } 1212 - } 1213 - if (x <= cameraPositionTileX && x > currentPositionX) { 1214 - SceneTile tile = tileArray.getTile(z, x - 1, y); 1215 - if (tile != null && tile.visible 1216 - && (tile.draw || (groundTile.interactiveObjectsSizeOR & 1) == 0)) { 1217 - continue; 1218 - } 1219 - } 1220 - if (x >= cameraPositionTileX && x < mapBoundsX - 1) { 1221 - SceneTile tile = tileArray.getTile(z, x + 1, y); 1222 - if (tile != null && tile.visible 1223 - && (tile.draw || (groundTile.interactiveObjectsSizeOR & 4) == 0)) { 1224 - continue; 1225 - } 1226 - } 1227 - if (y <= cameraPositionTileY && y > currentPositionY) { 1228 - SceneTile tile = tileArray.getTile(z, x, y - 1); 1229 - if (tile != null && tile.visible 1230 - && (tile.draw || (groundTile.interactiveObjectsSizeOR & 8) == 0)) { 1231 - continue; 1232 - } 1233 - } 1234 - if (y >= cameraPositionTileY && y < mapBoundsY - 1) { 1235 - SceneTile tile = tileArray.getTile(z, x, y + 1); 1236 - if (tile != null && tile.visible 1237 - && (tile.draw || (groundTile.interactiveObjectsSizeOR & 2) == 0)) { 1238 - continue; 1239 - } 1240 - } 1241 - } else { 1242 - flag = true; 1243 - } 1244 - groundTile.draw = false; 1245 - if (groundTile.tileBelow != null) { 1246 - SceneTile tile = groundTile.tileBelow; 1247 - if (tile.plainTile != null) { 1248 - if (!isTileOccluded(x, y, 0)) { 1249 - renderPlainTile(tile.plainTile, x, y, 0, curveSineX, curveCosineX, curveSineY, curveCosineY); 1250 - } 1251 - } else if (tile.shapedTile != null && !isTileOccluded(x, y, 0)) { 1252 - renderShapedTile(tile.shapedTile, x, y, curveSineX, curveCosineX, curveSineY, curveCosineY); 1253 - } 1254 - Wall wall = tile.wall; 1255 - if (wall != null) { 1256 - wall.primary.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1257 - wall.x - cameraPosX, wall.z - cameraPosZ, wall.y - cameraPosY, 1258 - wall.uid); 1259 - } 1260 - for (int i2 = 0; i2 < tile.entityCount; i2++) { 1261 - InteractiveObject interactiveObject = tile.interactiveObjects[i2]; 1262 - if (interactiveObject != null) { 1263 - interactiveObject.renderable.renderAtPoint(interactiveObject.rotation, curveSineY, curveCosineY, curveSineX, 1264 - curveCosineX, interactiveObject.worldX - cameraPosX, interactiveObject.worldZ - cameraPosZ, interactiveObject.worldY 1265 - - cameraPosY, interactiveObject.uid); 1266 - } 1267 - } 1268 - 1269 - } 1270 - boolean flag1 = false; 1271 - if (groundTile.plainTile != null) { 1272 - if (!isTileOccluded(x, y, level)) { 1273 - flag1 = true; 1274 - renderPlainTile(groundTile.plainTile, x, y, level, curveSineX, curveCosineX, curveSineY, curveCosineY); 1275 - } 1276 - } else if (groundTile.shapedTile != null && !isTileOccluded(x, y, level)) { 1277 - flag1 = true; 1278 - renderShapedTile(groundTile.shapedTile, x, y, curveSineX, curveCosineX, curveSineY, curveCosineY); 1279 - } 1280 - int j1 = 0; 1281 - int j2 = 0; 1282 - Wall wallObject = groundTile.wall; 1283 - WallDecoration wallDecoration = groundTile.wallDecoration; 1284 - if (wallObject != null || wallDecoration != null) { 1285 - if (cameraPositionTileX == x) { 1286 - j1++; 1287 - } else if (cameraPositionTileX < x) { 1288 - j1 += 2; 1289 - } 1290 - if (cameraPositionTileY == y) { 1291 - j1 += 3; 1292 - } else if (cameraPositionTileY > y) { 1293 - j1 += 6; 1294 - } 1295 - j2 = anIntArray493[j1]; 1296 - groundTile.wallDrawFlags = TILE_WALL_DRAW_FLAGS_1[j1]; 1297 - } 1298 - if (wallObject != null) { 1299 - if ((wallObject.orientation & anIntArray494[j1]) != 0) { 1300 - if (wallObject.orientation == 16) { 1301 - groundTile.wallCullDirection = 3; 1302 - groundTile.wallUncullDirection = WALL_UNCULL_FLAGS_0[j1]; 1303 - groundTile.wallCullOppositeDirection = 3 - groundTile.wallUncullDirection; 1304 - } else if (wallObject.orientation == 32) { 1305 - groundTile.wallCullDirection = 6; 1306 - groundTile.wallUncullDirection = anIntArray497[j1]; 1307 - groundTile.wallCullOppositeDirection = 6 - groundTile.wallUncullDirection; 1308 - } else if (wallObject.orientation == 64) { 1309 - groundTile.wallCullDirection = 12; 1310 - groundTile.wallUncullDirection = anIntArray498[j1]; 1311 - groundTile.wallCullOppositeDirection = 12 - groundTile.wallUncullDirection; 1312 - } else { 1313 - groundTile.wallCullDirection = 9; 1314 - groundTile.wallUncullDirection = anIntArray499[j1]; 1315 - groundTile.wallCullOppositeDirection = 9 - groundTile.wallUncullDirection; 1316 - } 1317 - } else { 1318 - groundTile.wallCullDirection = 0; 1319 - } 1320 - if ((wallObject.orientation & j2) != 0 && !isWallOccluded(x, y, level, wallObject.orientation)) { 1321 - wallObject.primary.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1322 - wallObject.x - cameraPosX, wallObject.z - cameraPosZ, wallObject.y 1323 - - cameraPosY, wallObject.uid); 1324 - } 1325 - if ((wallObject.orientation2 & j2) != 0 && !isWallOccluded(x, y, level, wallObject.orientation2)) { 1326 - wallObject.secondary.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1327 - wallObject.x - cameraPosX, wallObject.z - cameraPosZ, wallObject.y 1328 - - cameraPosY, wallObject.uid); 1329 - } 1330 - } 1331 - if (wallDecoration != null && !isOccluded(level, x, y, wallDecoration.renderable.modelHeight)) { 1332 - if ((wallDecoration.configBits & j2) != 0) { 1333 - wallDecoration.renderable.renderAtPoint(wallDecoration.face, curveSineY, curveCosineY, curveSineX, 1334 - curveCosineX, wallDecoration.x - cameraPosX, wallDecoration.z - cameraPosZ, 1335 - wallDecoration.y - cameraPosY, wallDecoration.uid); 1336 - } else if ((wallDecoration.configBits & 0x300) != 0) { 1337 - int j4 = wallDecoration.x - cameraPosX; 1338 - int l5 = wallDecoration.z - cameraPosZ; 1339 - int k6 = wallDecoration.y - cameraPosY; 1340 - int i8 = wallDecoration.face; 1341 - int k9; 1342 - if (i8 == 1 || i8 == 2) { 1343 - k9 = -j4; 1344 - } else { 1345 - k9 = j4; 1346 - } 1347 - int k10; 1348 - if (i8 == 2 || i8 == 3) { 1349 - k10 = -k6; 1350 - } else { 1351 - k10 = k6; 1352 - } 1353 - if ((wallDecoration.configBits & 0x100) != 0 && k10 < k9) { 1354 - int i11 = j4 + faceOffsetX2[i8]; 1355 - int k11 = k6 + faceOffsetY2[i8]; 1356 - wallDecoration.renderable.renderAtPoint(i8 * 512 + 256, curveSineY, curveCosineY, curveSineX, 1357 - curveCosineX, i11, l5, k11, wallDecoration.uid); 1358 - } 1359 - if ((wallDecoration.configBits & 0x200) != 0 && k10 > k9) { 1360 - int j11 = j4 + faceOffsetX3[i8]; 1361 - int l11 = k6 + faceOffsetY3[i8]; 1362 - wallDecoration.renderable.renderAtPoint(i8 * 512 + 1280 & 0x7ff, curveSineY, curveCosineY, 1363 - curveSineX, curveCosineX, j11, l5, l11, wallDecoration.uid); 1364 - } 1365 - } 1366 - } 1367 - if (flag1) { 1368 - FloorDecoration floorDecoration = groundTile.floorDecoration; 1369 - if (floorDecoration != null) { 1370 - floorDecoration.renderable.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1371 - floorDecoration.x - cameraPosX, floorDecoration.z - cameraPosZ, floorDecoration.y - cameraPosY, 1372 - floorDecoration.uid); 1373 - } 1374 - GroundItemTile groundItemTile_1 = groundTile.groundItemTile; 1375 - if (groundItemTile_1 != null && groundItemTile_1.anInt180 == 0) { 1376 - if (groundItemTile_1.secondGroundItem != null) { 1377 - groundItemTile_1.secondGroundItem.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1378 - groundItemTile_1.x - cameraPosX, groundItemTile_1.z - cameraPosZ, groundItemTile_1.y 1379 - - cameraPosY, groundItemTile_1.uid); 1380 - } 1381 - if (groundItemTile_1.thirdGroundItem != null) { 1382 - groundItemTile_1.thirdGroundItem.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1383 - groundItemTile_1.x - cameraPosX, groundItemTile_1.z - cameraPosZ, groundItemTile_1.y 1384 - - cameraPosY, groundItemTile_1.uid); 1385 - } 1386 - if (groundItemTile_1.firstGroundItem != null) { 1387 - groundItemTile_1.firstGroundItem.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1388 - groundItemTile_1.x - cameraPosX, groundItemTile_1.z - cameraPosZ, groundItemTile_1.y 1389 - - cameraPosY, groundItemTile_1.uid); 1390 - } 1391 - } 1392 - } 1393 - int k4 = groundTile.interactiveObjectsSizeOR; 1394 - if (k4 != 0) { 1395 - if (x < cameraPositionTileX && (k4 & 4) != 0) { 1396 - SceneTile tile = tileArray.getTile(z, x + 1, y); 1397 - if (tile != null && tile.visible) { 1398 - tileList.pushBack(tile); 1399 - } 1400 - } 1401 - if (y < cameraPositionTileY && (k4 & 2) != 0) { 1402 - SceneTile tile = tileArray.getTile(z, x, y + 1); 1403 - if (tile != null && tile.visible) { 1404 - tileList.pushBack(tile); 1405 - } 1406 - } 1407 - if (x > cameraPositionTileX && (k4 & 1) != 0) { 1408 - SceneTile tile = tileArray.getTile(z, x - 1, y); 1409 - if (tile != null && tile.visible) { 1410 - tileList.pushBack(tile); 1411 - } 1412 - } 1413 - if (y > cameraPositionTileY && (k4 & 8) != 0) { 1414 - SceneTile tile = tileArray.getTile(z, x, y - 1); 1415 - if (tile != null && tile.visible) { 1416 - tileList.pushBack(tile); 1417 - } 1418 - } 1419 - } 1420 - } 1421 - if (groundTile.wallCullDirection != 0) { 1422 - boolean flag2 = true; 1423 - for (int e = 0; e < groundTile.entityCount; e++) { 1424 - if (groundTile.interactiveObjects[e].cycle == cycle 1425 - || (groundTile.sceneSpawnRequestsSize[e] & groundTile.wallCullDirection) != groundTile.wallUncullDirection) { 1426 - continue; 1427 - } 1428 - flag2 = false; 1429 - break; 1430 - } 1431 - 1432 - if (flag2) { 1433 - Wall wall_1 = groundTile.wall; 1434 - if (!isWallOccluded(x, y, level, wall_1.orientation)) { 1435 - wall_1.primary.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1436 - wall_1.x - cameraPosX, wall_1.z - cameraPosZ, wall_1.y 1437 - - cameraPosY, wall_1.uid); 1438 - } 1439 - groundTile.wallCullDirection = 0; 1440 - } 1441 - } 1442 - if (groundTile.drawEntities) { 1443 - try { 1444 - int entityCount = groundTile.entityCount; 1445 - groundTile.drawEntities = false; 1446 - int l1 = 0; 1447 - label0: 1448 - for (int e = 0; e < entityCount; e++) { 1449 - InteractiveObject entity = groundTile.interactiveObjects[e]; 1450 - if (entity.cycle == cycle) { 1451 - continue; 1452 - } 1453 - for (int _x = entity.tileLeft; _x <= entity.tileRight; _x++) { 1454 - for (int _y = entity.tileTop; _y <= entity.tileBottom; _y++) { 1455 - SceneTile tile = tileArray.getTile(z, _x, _y); 1456 - if (tile.draw) { 1457 - groundTile.drawEntities = true; 1458 - } else { 1459 - if (tile.wallCullDirection == 0) { 1460 - continue; 1461 - } 1462 - int l6 = 0; 1463 - if (_x > entity.tileLeft) { 1464 - l6++; 1465 - } 1466 - if (_x < entity.tileRight) { 1467 - l6 += 4; 1468 - } 1469 - if (_y > entity.tileTop) { 1470 - l6 += 8; 1471 - } 1472 - if (_y < entity.tileBottom) { 1473 - l6 += 2; 1474 - } 1475 - if ((l6 & tile.wallCullDirection) != groundTile.wallCullOppositeDirection) { 1476 - continue; 1477 - } 1478 - groundTile.drawEntities = true; 1479 - } 1480 - continue label0; 1481 - } 1482 - 1483 - } 1484 - 1485 - interactiveObjects[l1++] = entity; 1486 - int i5 = cameraPositionTileX - entity.tileLeft; 1487 - int i6 = entity.tileRight - cameraPositionTileX; 1488 - if (i6 > i5) { 1489 - i5 = i6; 1490 - } 1491 - int i7 = cameraPositionTileY - entity.tileTop; 1492 - int j8 = entity.tileBottom - cameraPositionTileY; 1493 - if (j8 > i7) { 1494 - entity.anInt123 = i5 + j8; 1495 - } else { 1496 - entity.anInt123 = i5 + i7; 1497 - } 1498 - } 1499 - 1500 - while (l1 > 0) { 1501 - int i3 = -50; 1502 - int l3 = -1; 1503 - for (int j5 = 0; j5 < l1; j5++) { 1504 - InteractiveObject entity = interactiveObjects[j5]; 1505 - if (entity.cycle != cycle) { 1506 - if (entity.anInt123 > i3) { 1507 - i3 = entity.anInt123; 1508 - l3 = j5; 1509 - } else if (entity.anInt123 == i3) { 1510 - int j7 = entity.worldX - cameraPosX; 1511 - int k8 = entity.worldY - cameraPosY; 1512 - int l9 = interactiveObjects[l3].worldX - cameraPosX; 1513 - int l10 = interactiveObjects[l3].worldY - cameraPosY; 1514 - if (j7 * j7 + k8 * k8 > l9 * l9 + l10 * l10) { 1515 - l3 = j5; 1516 - } 1517 - } 1518 - } 1519 - } 1520 - 1521 - if (l3 == -1) { 1522 - break; 1523 - } 1524 - InteractiveObject entity = interactiveObjects[l3]; 1525 - entity.cycle = cycle; 1526 - if (!isAreaOccluded(entity.tileLeft, entity.tileRight, entity.tileTop, entity.tileBottom, level, 1527 - entity.renderable.modelHeight)) { 1528 - entity.renderable.renderAtPoint(entity.rotation, curveSineY, curveCosineY, curveSineX, 1529 - curveCosineX, entity.worldX - cameraPosX, entity.worldZ - cameraPosZ, 1530 - entity.worldY - cameraPosY, entity.uid); 1531 - } 1532 - for (int _x = entity.tileLeft; _x <= entity.tileRight; _x++) { 1533 - for (int _y = entity.tileTop; _y <= entity.tileBottom; _y++) { 1534 - SceneTile tile = tileArray.getTile(z, _x, _y); 1535 - if (tile.wallCullDirection != 0) { 1536 - tileList.pushBack(tile); 1537 - } else if ((_x != x || _y != y) && tile.visible) { 1538 - tileList.pushBack(tile); 1539 - } 1540 - } 1541 - 1542 - } 1543 - 1544 - } 1545 - if (groundTile.drawEntities) { 1546 - continue; 1547 - } 1548 - } catch (Exception _ex) { 1549 - groundTile.drawEntities = false; 1550 - } 1551 - } 1552 - if (!groundTile.visible || groundTile.wallCullDirection != 0) { 1553 - continue; 1554 - } 1555 - if (x <= cameraPositionTileX && x > currentPositionX) { 1556 - SceneTile tile = tileArray.getTile(z, x - 1, y); 1557 - if (tile != null && tile.visible) { 1558 - continue; 1559 - } 1560 - } 1561 - if (x >= cameraPositionTileX && x < mapBoundsX - 1) { 1562 - SceneTile tile = tileArray.getTile(z, x + 1, y); 1563 - if (tile != null && tile.visible) { 1564 - continue; 1565 - } 1566 - } 1567 - if (y <= cameraPositionTileY && y > currentPositionY) { 1568 - SceneTile tile = tileArray.getTile(z, x, y - 1); 1569 - if (tile != null && tile.visible) { 1570 - continue; 1571 - } 1572 - } 1573 - if (y >= cameraPositionTileY && y < mapBoundsY - 1) { 1574 - SceneTile tile = tileArray.getTile(z, x, y + 1); 1575 - if (tile != null && tile.visible) { 1576 - continue; 1577 - } 1578 - } 1579 - groundTile.visible = false; 1580 - anInt461--; 1581 - GroundItemTile groundItemTile = groundTile.groundItemTile; 1582 - if (groundItemTile != null && groundItemTile.anInt180 != 0) { 1583 - if (groundItemTile.secondGroundItem != null) { 1584 - groundItemTile.secondGroundItem.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1585 - groundItemTile.x - cameraPosX, groundItemTile.z - cameraPosZ - groundItemTile.anInt180, 1586 - groundItemTile.y - cameraPosY, groundItemTile.uid); 1587 - } 1588 - if (groundItemTile.thirdGroundItem != null) { 1589 - groundItemTile.thirdGroundItem.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1590 - groundItemTile.x - cameraPosX, groundItemTile.z - cameraPosZ - groundItemTile.anInt180, 1591 - groundItemTile.y - cameraPosY, groundItemTile.uid); 1592 - } 1593 - if (groundItemTile.firstGroundItem != null) { 1594 - groundItemTile.firstGroundItem.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1595 - groundItemTile.x - cameraPosX, groundItemTile.z - cameraPosZ - groundItemTile.anInt180, 1596 - groundItemTile.y - cameraPosY, groundItemTile.uid); 1597 - } 1598 - } 1599 - if (groundTile.wallDrawFlags != 0) { 1600 - WallDecoration wallDecoration = groundTile.wallDecoration; 1601 - if (wallDecoration != null && !isOccluded(level, x, y, wallDecoration.renderable.modelHeight)) { 1602 - if ((wallDecoration.configBits & groundTile.wallDrawFlags) != 0) { 1603 - wallDecoration.renderable.renderAtPoint(wallDecoration.face, curveSineY, curveCosineY, curveSineX, 1604 - curveCosineX, wallDecoration.x - cameraPosX, wallDecoration.z - cameraPosZ, wallDecoration.y 1605 - - cameraPosY, wallDecoration.uid); 1606 - } else if ((wallDecoration.configBits & 0x300) != 0) { 1607 - int l2 = wallDecoration.x - cameraPosX; 1608 - int j3 = wallDecoration.z - cameraPosZ; 1609 - int i4 = wallDecoration.y - cameraPosY; 1610 - int k5 = wallDecoration.face; 1611 - int j6; 1612 - if (k5 == 1 || k5 == 2) { 1613 - j6 = -l2; 1614 - } else { 1615 - j6 = l2; 1616 - } 1617 - int l7; 1618 - if (k5 == 2 || k5 == 3) { 1619 - l7 = -i4; 1620 - } else { 1621 - l7 = i4; 1622 - } 1623 - if ((wallDecoration.configBits & 0x100) != 0 && l7 >= j6) { 1624 - int i9 = l2 + faceOffsetX2[k5]; 1625 - int i10 = i4 + faceOffsetY2[k5]; 1626 - wallDecoration.renderable.renderAtPoint(k5 * 512 + 256, curveSineY, curveCosineY, curveSineX, 1627 - curveCosineX, i9, j3, i10, wallDecoration.uid); 1628 - } 1629 - if ((wallDecoration.configBits & 0x200) != 0 && l7 <= j6) { 1630 - int j9 = l2 + faceOffsetX3[k5]; 1631 - int j10 = i4 + faceOffsetY3[k5]; 1632 - wallDecoration.renderable.renderAtPoint(k5 * 512 + 1280 & 0x7ff, curveSineY, curveCosineY, 1633 - curveSineX, curveCosineX, j9, j3, j10, wallDecoration.uid); 1634 - } 1635 - } 1636 - } 1637 - Wall wallObject = groundTile.wall; 1638 - if (wallObject != null) { 1639 - if ((wallObject.orientation2 & groundTile.wallDrawFlags) != 0 && !isWallOccluded(x, y, level, wallObject.orientation2)) { 1640 - wallObject.secondary.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1641 - wallObject.x - cameraPosX, wallObject.z - cameraPosZ, wallObject.y 1642 - - cameraPosY, wallObject.uid); 1643 - } 1644 - if ((wallObject.orientation & groundTile.wallDrawFlags) != 0 && !isWallOccluded(x, y, level, wallObject.orientation)) { 1645 - wallObject.primary.renderAtPoint(0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1646 - wallObject.x - cameraPosX, wallObject.z - cameraPosZ, wallObject.y 1647 - - cameraPosY, wallObject.uid); 1648 - } 1649 - } 1650 - } 1651 - if (z < mapSizeZ - 1) { 1652 - SceneTile tile = tileArray.getTile(z + 1, x, y); 1653 - if (tile != null && tile.visible) { 1654 - tileList.pushBack(tile); 1655 - } 1656 - } 1657 - if (x < cameraPositionTileX) { 1658 - SceneTile tile = tileArray.getTile(z, x + 1, y); 1659 - if (tile != null && tile.visible) { 1660 - tileList.pushBack(tile); 1661 - } 1662 - } 1663 - if (y < cameraPositionTileY) { 1664 - SceneTile tile = tileArray.getTile(z, x, y + 1); 1665 - if (tile != null && tile.visible) { 1666 - tileList.pushBack(tile); 1667 - } 1668 - } 1669 - if (x > cameraPositionTileX) { 1670 - SceneTile tile = tileArray.getTile(z, x - 1, y); 1671 - if (tile != null && tile.visible) { 1672 - tileList.pushBack(tile); 1673 - } 1674 - } 1675 - if (y > cameraPositionTileY) { 1676 - SceneTile tile = tileArray.getTile(z, x, y - 1); 1677 - if (tile != null && tile.visible) { 1678 - tileList.pushBack(tile); 1679 - } 1680 - } 1681 - } while (true); 1682 - } 1683 - 1684 - private void renderPlainTile(GenericTile plainTile, int tileX, int tileY, int tileZ, int sinX, int cosineX, int sinY, int cosineY) { 1685 - int xC; 1686 - int xA = xC = (tileX << 7) - cameraPosX; 1687 - int yB; 1688 - int yA = yB = (tileY << 7) - cameraPosY; 1689 - int xD; 1690 - int xB = xD = xA + 128; 1691 - int yC; 1692 - int yD = yC = yA + 128; 1693 - int zA = heightMap[tileZ][tileX][tileY] - cameraPosZ; 1694 - int zB = heightMap[tileZ][tileX + 1][tileY] - cameraPosZ; 1695 - int zC = heightMap[tileZ][tileX + 1][tileY + 1] - cameraPosZ; 1696 - int zD = heightMap[tileZ][tileX][tileY + 1] - cameraPosZ; 1697 - int temp = yA * sinX + xA * cosineX >> 16; 1698 - yA = yA * cosineX - xA * sinX >> 16; 1699 - xA = temp; 1700 - temp = zA * cosineY - yA * sinY >> 16; 1701 - yA = zA * sinY + yA * cosineY >> 16; 1702 - zA = temp; 1703 - if (yA < 50) { 1704 - return; 1705 - } 1706 - temp = yB * sinX + xB * cosineX >> 16; 1707 - yB = yB * cosineX - xB * sinX >> 16; 1708 - xB = temp; 1709 - temp = zB * cosineY - yB * sinY >> 16; 1710 - yB = zB * sinY + yB * cosineY >> 16; 1711 - zB = temp; 1712 - if (yB < 50) { 1713 - return; 1714 - } 1715 - temp = yD * sinX + xD * cosineX >> 16; 1716 - yD = yD * cosineX - xD * sinX >> 16; 1717 - xD = temp; 1718 - temp = zC * cosineY - yD * sinY >> 16; 1719 - yD = zC * sinY + yD * cosineY >> 16; 1720 - zC = temp; 1721 - if (yD < 50) { 1722 - return; 1723 - } 1724 - temp = yC * sinX + xC * cosineX >> 16; 1725 - yC = yC * cosineX - xC * sinX >> 16; 1726 - xC = temp; 1727 - temp = zD * cosineY - yC * sinY >> 16; 1728 - yC = zD * sinY + yC * cosineY >> 16; 1729 - zD = temp; 1730 - if (yC < 50) { 1731 - return; 1732 - } 1733 - int screenXA = Rasterizer3D.center_x + (xA << 9) / yA; 1734 - int screenYA = Rasterizer3D.center_y + (zA << 9) / yA; 1735 - int screenXB = Rasterizer3D.center_x + (xB << 9) / yB; 1736 - int screenYB = Rasterizer3D.center_y + (zB << 9) / yB; 1737 - int screenXD = Rasterizer3D.center_x + (xD << 9) / yD; 1738 - int screenYD = Rasterizer3D.center_y + (zC << 9) / yD; 1739 - int screenXC = Rasterizer3D.center_x + (xC << 9) / yC; 1740 - int screenYC = Rasterizer3D.center_y + (zD << 9) / yC; 1741 - Rasterizer3D.alpha = 0; 1742 - if ((screenXD - screenXC) * (screenYB - screenYC) - (screenYD - screenYC) * (screenXB - screenXC) > 0) { 1743 - Rasterizer3D.restrict_edges = screenXD < 0 || screenXC < 0 || screenXB < 0 || 1744 - screenXD > Rasterizer.viewportRx || 1745 - screenXC > Rasterizer.viewportRx || 1746 - screenXB > Rasterizer.viewportRx; 1747 - if (clicked && isMouseWithinTriangle(clickX, clickY, screenYD, screenYC, screenYB, screenXD, screenXC, screenXB)) { 1748 - clickedTileX = tileX; 1749 - clickedTileY = tileY; 1750 - } 1751 - if (plainTile.texture == -1) { 1752 - if (plainTile.colourD != 0xbc614e) { 1753 - Rasterizer3D.drawShadedTriangle(screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, plainTile.colourD, plainTile.colourC, 1754 - plainTile.colourB); 1755 - } 1756 - } else if (!lowMemory) { 1757 - if (plainTile.flat) { 1758 - Rasterizer3D.drawTexturedTriangle(screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, plainTile.colourD, plainTile.colourC, 1759 - plainTile.colourB, xA, xB, xC, zA, zB, zD, yA, yB, yC, plainTile.texture); 1760 - } else { 1761 - Rasterizer3D.drawTexturedTriangle(screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, plainTile.colourD, plainTile.colourC, 1762 - plainTile.colourB, xD, xC, xB, zC, zD, zB, yD, yC, yB, plainTile.texture); 1763 - } 1764 - } else { 1765 - int rgb = textureRGB[plainTile.texture]; 1766 - Rasterizer3D.drawShadedTriangle(screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, mixColours(rgb, plainTile.colourD), mixColours( 1767 - rgb, plainTile.colourC), mixColours(rgb, plainTile.colourB)); 1768 - } 1769 - } 1770 - if ((screenXA - screenXB) * (screenYC - screenYB) - (screenYA - screenYB) * (screenXC - screenXB) > 0) { 1771 - Rasterizer3D.restrict_edges = screenXA < 0 || screenXB < 0 || screenXC < 0 || screenXA > Rasterizer.viewportRx || screenXB > Rasterizer.viewportRx 1772 - || screenXC > Rasterizer.viewportRx; 1773 - if (clicked && isMouseWithinTriangle(clickX, clickY, screenYA, screenYB, screenYC, screenXA, screenXB, screenXC)) { 1774 - clickedTileX = tileX; 1775 - clickedTileY = tileY; 1776 - } 1777 - if (plainTile.texture == -1) { 1778 - if (plainTile.colourA != 0xbc614e) { 1779 - Rasterizer3D.drawShadedTriangle(screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, plainTile.colourA, plainTile.colourB, 1780 - plainTile.colourC); 1781 - } 1782 - } else { 1783 - if (!lowMemory) { 1784 - Rasterizer3D.drawTexturedTriangle(screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, plainTile.colourA, plainTile.colourB, 1785 - plainTile.colourC, xA, xB, xC, zA, zB, zD, yA, yB, yC, plainTile.texture); 1786 - return; 1787 - } 1788 - int rgb = textureRGB[plainTile.texture]; 1789 - Rasterizer3D.drawShadedTriangle(screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, mixColours(rgb, plainTile.colourA), mixColours( 1790 - rgb, plainTile.colourB), mixColours(rgb, plainTile.colourC)); 1791 - } 1792 - } 1793 - } 1794 - 1795 - private void renderShapedTile(ComplexTile shapedTile, int tileX, int tileY, int sineX, int cosineX, int sineY, int cosineY) { 1796 - int triangleCount = shapedTile.originalVertexX.length; 1797 - for (int triangle = 0; triangle < triangleCount; triangle++) { 1798 - int viewspaceX = shapedTile.originalVertexX[triangle] - cameraPosX; 1799 - int viewspaceY = shapedTile.originalVertexY[triangle] - cameraPosZ; 1800 - int viewspaceZ = shapedTile.originalVertexZ[triangle] - cameraPosY; 1801 - int temp = viewspaceZ * sineX + viewspaceX * cosineX >> 16; 1802 - viewspaceZ = viewspaceZ * cosineX - viewspaceX * sineX >> 16; 1803 - viewspaceX = temp; 1804 - temp = viewspaceY * cosineY - viewspaceZ * sineY >> 16; 1805 - viewspaceZ = viewspaceY * sineY + viewspaceZ * cosineY >> 16; 1806 - viewspaceY = temp; 1807 - if (viewspaceZ < 50) { 1808 - return; 1809 - } 1810 - if (shapedTile.triangleTexture != null) { 1811 - ComplexTile.viewspaceX[triangle] = viewspaceX; 1812 - ComplexTile.viewspaceY[triangle] = viewspaceY; 1813 - ComplexTile.viewspaceZ[triangle] = viewspaceZ; 1814 - } 1815 - ComplexTile.screenX[triangle] = Rasterizer3D.center_x + (viewspaceX << 9) / viewspaceZ; 1816 - ComplexTile.screenY[triangle] = Rasterizer3D.center_y + (viewspaceY << 9) / viewspaceZ; 1817 - } 1818 - 1819 - Rasterizer3D.alpha = 0; 1820 - triangleCount = shapedTile.triangleA.length; 1821 - for (int tirangle = 0; tirangle < triangleCount; tirangle++) { 1822 - int a = shapedTile.triangleA[tirangle]; 1823 - int b = shapedTile.triangleB[tirangle]; 1824 - int c = shapedTile.triangleC[tirangle]; 1825 - int screenXA = ComplexTile.screenX[a]; 1826 - int screenXB = ComplexTile.screenX[b]; 1827 - int screenXC = ComplexTile.screenX[c]; 1828 - int screenYA = ComplexTile.screenY[a]; 1829 - int screenYB = ComplexTile.screenY[b]; 1830 - int screenYC = ComplexTile.screenY[c]; 1831 - if ((screenXA - screenXB) * (screenYC - screenYB) - (screenYA - screenYB) * (screenXC - screenXB) > 0) { 1832 - Rasterizer3D.restrict_edges = screenXA < 0 || screenXB < 0 || screenXC < 0 || screenXA > Rasterizer.viewportRx || screenXB > Rasterizer.viewportRx 1833 - || screenXC > Rasterizer.viewportRx; 1834 - if (clicked && isMouseWithinTriangle(clickX, clickY, screenYA, screenYB, screenYC, screenXA, screenXB, screenXC)) { 1835 - clickedTileX = tileX; 1836 - clickedTileY = tileY; 1837 - } 1838 - if (shapedTile.triangleTexture == null || shapedTile.triangleTexture[tirangle] == -1) { 1839 - if (shapedTile.triangleHSLA[tirangle] != 0xbc614e) { 1840 - Rasterizer3D.drawShadedTriangle(screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, shapedTile.triangleHSLA[tirangle], 1841 - shapedTile.triangleHSLB[tirangle], shapedTile.triangleHSLC[tirangle]); 1842 - } 1843 - } else if (!lowMemory) { 1844 - if (shapedTile.flat) { 1845 - Rasterizer3D.drawTexturedTriangle(screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, shapedTile.triangleHSLA[tirangle], 1846 - shapedTile.triangleHSLB[tirangle], shapedTile.triangleHSLC[tirangle], ComplexTile.viewspaceX[0], 1847 - ComplexTile.viewspaceX[1], ComplexTile.viewspaceX[3], ComplexTile.viewspaceY[0], 1848 - ComplexTile.viewspaceY[1], ComplexTile.viewspaceY[3], ComplexTile.viewspaceZ[0], 1849 - ComplexTile.viewspaceZ[1], ComplexTile.viewspaceZ[3], shapedTile.triangleTexture[tirangle]); 1850 - } else { 1851 - Rasterizer3D.drawTexturedTriangle(screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, shapedTile.triangleHSLA[tirangle], 1852 - shapedTile.triangleHSLB[tirangle], shapedTile.triangleHSLC[tirangle], ComplexTile.viewspaceX[a], 1853 - ComplexTile.viewspaceX[b], ComplexTile.viewspaceX[c], ComplexTile.viewspaceY[a], 1854 - ComplexTile.viewspaceY[b], ComplexTile.viewspaceY[c], ComplexTile.viewspaceZ[a], 1855 - ComplexTile.viewspaceZ[b], ComplexTile.viewspaceZ[c], shapedTile.triangleTexture[tirangle]); 1856 - } 1857 - } else { 1858 - int k5 = textureRGB[shapedTile.triangleTexture[tirangle]]; 1859 - Rasterizer3D.drawShadedTriangle(screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1860 - mixColours(k5, shapedTile.triangleHSLA[tirangle]), mixColours(k5, shapedTile.triangleHSLB[tirangle]), 1861 - mixColours(k5, shapedTile.triangleHSLC[tirangle])); 1862 - } 1863 - } 1864 - } 1865 - 1866 - } 1867 - 1868 - private int mixColours(int colourA, int colourB) { 1869 - colourB = 127 - colourB; 1870 - colourB = (colourB * (colourA & 0x7f)) / 160; 1871 - if (colourB < 2) { 1872 - colourB = 2; 1873 - } else if (colourB > 126) { 1874 - colourB = 126; 1875 - } 1876 - return (colourA & 0xff80) + colourB; 1877 - } 1878 - 1879 - private boolean isMouseWithinTriangle(int mouseX, int mouseY, int pointAY, int pointBY, int pointCY, int pointAX, int pointBX, int pointCX) { 1880 - if (mouseY < pointAY && mouseY < pointBY && mouseY < pointCY) { 1881 - return false; 1882 - } 1883 - if (mouseY > pointAY && mouseY > pointBY && mouseY > pointCY) { 1884 - return false; 1885 - } 1886 - if (mouseX < pointAX && mouseX < pointBX && mouseX < pointCX) { 1887 - return false; 1888 - } 1889 - if (mouseX > pointAX && mouseX > pointBX && mouseX > pointCX) { 1890 - return false; 1891 - } 1892 - int b1 = (mouseY - pointAY) * (pointBX - pointAX) - (mouseX - pointAX) * (pointBY - pointAY); 1893 - int b2 = (mouseY - pointCY) * (pointAX - pointCX) - (mouseX - pointCX) * (pointAY - pointCY); 1894 - int b3 = (mouseY - pointBY) * (pointCX - pointBX) - (mouseX - pointBX) * (pointCY - pointBY); 1895 - return b1 * b3 > 0 && b3 * b2 > 0; 1896 - } 1897 - 1898 - private void processCulling() { 1899 - int clusterCount = cullingClusterPointer[plane]; 1900 - SceneCluster[] clusters = cullingClusters[plane]; 1901 - processedCullingClustersPointer = 0; 1902 - for (int c = 0; c < clusterCount; c++) { 1903 - SceneCluster cluster = clusters[c]; 1904 - if (cluster.searchMask == 1) { 1905 - int distanceFromCameraStartX = (cluster.tileStartX - cameraPositionTileX) + 25; 1906 - if (distanceFromCameraStartX < 0 || distanceFromCameraStartX > 50) { 1907 - continue; 1908 - } 1909 - int distanceFromCameraStartY = (cluster.tileStartY - cameraPositionTileY) + 25; 1910 - if (distanceFromCameraStartY < 0) { 1911 - distanceFromCameraStartY = 0; 1912 - } 1913 - int cameraPositionTileY = (cluster.tileEndY - Scene.cameraPositionTileY) + 25; 1914 - if (cameraPositionTileY > 50) { 1915 - cameraPositionTileY = 50; 1916 - } 1917 - boolean visible = false; 1918 - while (distanceFromCameraStartY <= cameraPositionTileY) { 1919 - if (TILE_VISIBILITY_MAP[distanceFromCameraStartX][distanceFromCameraStartY++]) { 1920 - visible = true; 1921 - break; 1922 - } 1923 - } 1924 - if (!visible) { 1925 - continue; 1926 - } 1927 - int realDistanceFromCameraStartX = cameraPosX - cluster.worldStartX; 1928 - if (realDistanceFromCameraStartX > 32) { 1929 - cluster.tileDistanceEnum = 1; 1930 - } else { 1931 - if (realDistanceFromCameraStartX >= -32) { 1932 - continue; 1933 - } 1934 - cluster.tileDistanceEnum = 2; 1935 - realDistanceFromCameraStartX = -realDistanceFromCameraStartX; 1936 - } 1937 - cluster.worldDistanceFromCameraStartY = (cluster.worldStartY - cameraPosY << 8) / realDistanceFromCameraStartX; 1938 - cluster.worldDistanceFromCameraEndY = (cluster.worldEndY - cameraPosY << 8) / realDistanceFromCameraStartX; 1939 - cluster.worldDistanceFromCameraStartZ = (cluster.worldEndZ - cameraPosZ << 8) / realDistanceFromCameraStartX; 1940 - cluster.worldDistanceFromCameraEndZ = (cluster.worldStartZ - cameraPosZ << 8) / realDistanceFromCameraStartX; 1941 - processedCullingClusters[processedCullingClustersPointer++] = cluster; 1942 - continue; 1943 - } 1944 - if (cluster.searchMask == 2) { 1945 - int distanceFromCameraStartY = (cluster.tileStartY - cameraPositionTileY) + 25; 1946 - if (distanceFromCameraStartY < 0 || distanceFromCameraStartY > 50) { 1947 - continue; 1948 - } 1949 - int distanceFromCameraStartX = (cluster.tileStartX - cameraPositionTileX) + 25; 1950 - if (distanceFromCameraStartX < 0) { 1951 - distanceFromCameraStartX = 0; 1952 - } 1953 - int distanceFromCameraEndX = (cluster.tileEndX - cameraPositionTileX) + 25; 1954 - if (distanceFromCameraEndX > 50) { 1955 - distanceFromCameraEndX = 50; 1956 - } 1957 - boolean visible = false; 1958 - while (distanceFromCameraStartX <= distanceFromCameraEndX) { 1959 - if (TILE_VISIBILITY_MAP[distanceFromCameraStartX++][distanceFromCameraStartY]) { 1960 - visible = true; 1961 - break; 1962 - } 1963 - } 1964 - if (!visible) { 1965 - continue; 1966 - } 1967 - int realDistanceFromCameraStartY = cameraPosY - cluster.worldStartY; 1968 - if (realDistanceFromCameraStartY > 32) { 1969 - cluster.tileDistanceEnum = 3; 1970 - } else { 1971 - if (realDistanceFromCameraStartY >= -32) { 1972 - continue; 1973 - } 1974 - cluster.tileDistanceEnum = 4; 1975 - realDistanceFromCameraStartY = -realDistanceFromCameraStartY; 1976 - } 1977 - cluster.worldDistanceFromCameraStartX = (cluster.worldStartX - cameraPosX << 8) / realDistanceFromCameraStartY; 1978 - cluster.worldDistanceFromCameraEndX = (cluster.worldEndX - cameraPosX << 8) / realDistanceFromCameraStartY; 1979 - cluster.worldDistanceFromCameraStartZ = (cluster.worldEndZ - cameraPosZ << 8) / realDistanceFromCameraStartY; 1980 - cluster.worldDistanceFromCameraEndZ = (cluster.worldStartZ - cameraPosZ << 8) / realDistanceFromCameraStartY; 1981 - processedCullingClusters[processedCullingClustersPointer++] = cluster; 1982 - } else if (cluster.searchMask == 4) { 1983 - int realDistanceFromCameraStartZ = cluster.worldEndZ - cameraPosZ; 1984 - if (realDistanceFromCameraStartZ > 128) { 1985 - int distanceFromCameraStartY = (cluster.tileStartY - cameraPositionTileY) + 25; 1986 - if (distanceFromCameraStartY < 0) { 1987 - distanceFromCameraStartY = 0; 1988 - } 1989 - int distanceFromCameraEndY = (cluster.tileEndY - cameraPositionTileY) + 25; 1990 - if (distanceFromCameraEndY > 50) { 1991 - distanceFromCameraEndY = 50; 1992 - } 1993 - if (distanceFromCameraStartY <= distanceFromCameraEndY) { 1994 - int distanceFromCameraStartX = (cluster.tileStartX - cameraPositionTileX) + 25; 1995 - if (distanceFromCameraStartX < 0) { 1996 - distanceFromCameraStartX = 0; 1997 - } 1998 - int distanceFromCameraEndX = (cluster.tileEndX - cameraPositionTileX) + 25; 1999 - if (distanceFromCameraEndX > 50) { 2000 - distanceFromCameraEndX = 50; 2001 - } 2002 - boolean visible = false; 2003 - label0: 2004 - for (int x = distanceFromCameraStartX; x <= distanceFromCameraEndX; x++) { 2005 - for (int y = distanceFromCameraStartY; y <= distanceFromCameraEndY; y++) { 2006 - if (!TILE_VISIBILITY_MAP[x][y]) { 2007 - continue; 2008 - } 2009 - visible = true; 2010 - break label0; 2011 - } 2012 - 2013 - } 2014 - 2015 - if (visible) { 2016 - cluster.tileDistanceEnum = 5; 2017 - cluster.worldDistanceFromCameraStartX = (cluster.worldStartX - cameraPosX << 8) / realDistanceFromCameraStartZ; 2018 - cluster.worldDistanceFromCameraEndX = (cluster.worldEndX - cameraPosX << 8) / realDistanceFromCameraStartZ; 2019 - cluster.worldDistanceFromCameraStartY = (cluster.worldStartY - cameraPosY << 8) / realDistanceFromCameraStartZ; 2020 - cluster.worldDistanceFromCameraEndY = (cluster.worldEndY - cameraPosY << 8) / realDistanceFromCameraStartZ; 2021 - processedCullingClusters[processedCullingClustersPointer++] = cluster; 2022 - } 2023 - } 2024 - } 2025 - } 2026 - } 2027 - 2028 - } 2029 - 2030 - private boolean isTileOccluded(int x, int y, int z) { 2031 - int l = anIntArrayArrayArray445[z][x][y]; 2032 - if (l == -cycle) { 2033 - return false; 2034 - } 2035 - if (l == cycle) { 2036 - return true; 2037 - } 2038 - int worldX = x << 7; 2039 - int worldY = y << 7; 2040 - if (method291(worldX + 1, worldY + 1, heightMap[z][x][y]) 2041 - && method291((worldX + 128) - 1, worldY + 1, heightMap[z][x + 1][y]) 2042 - && method291((worldX + 128) - 1, (worldY + 128) - 1, heightMap[z][x + 1][y + 1]) 2043 - && method291(worldX + 1, (worldY + 128) - 1, heightMap[z][x][y + 1])) { 2044 - anIntArrayArrayArray445[z][x][y] = cycle; 2045 - return true; 2046 - } else { 2047 - anIntArrayArrayArray445[z][x][y] = -cycle; 2048 - return false; 2049 - } 2050 - } 2051 - 2052 - private boolean isWallOccluded(int x, int y, int level, int wallType) { 2053 - if (!isTileOccluded(x, y, level)) { 2054 - return false; 2055 - } 2056 - int posX = x << 7; 2057 - int posY = y << 7; 2058 - int posZ = heightMap[level][x][y] - 1; 2059 - int z1 = posZ - 120; 2060 - int z2 = posZ - 230; 2061 - int z3 = posZ - 238; 2062 - if (wallType < 16) { 2063 - if (wallType == 1) { 2064 - if (posX > cameraPosX) { 2065 - if (!method291(posX, posY, posZ)) { 2066 - return false; 2067 - } 2068 - if (!method291(posX, posY + 128, posZ)) { 2069 - return false; 2070 - } 2071 - } 2072 - if (level > 0) { 2073 - if (!method291(posX, posY, z1)) { 2074 - return false; 2075 - } 2076 - if (!method291(posX, posY + 128, z1)) { 2077 - return false; 2078 - } 2079 - } 2080 - if (!method291(posX, posY, z2)) { 2081 - return false; 2082 - } 2083 - return method291(posX, posY + 128, z2); 2084 - } 2085 - if (wallType == 2) { 2086 - if (posY < cameraPosY) { 2087 - if (!method291(posX, posY + 128, posZ)) { 2088 - return false; 2089 - } 2090 - if (!method291(posX + 128, posY + 128, posZ)) { 2091 - return false; 2092 - } 2093 - } 2094 - if (level > 0) { 2095 - if (!method291(posX, posY + 128, z1)) { 2096 - return false; 2097 - } 2098 - if (!method291(posX + 128, posY + 128, z1)) { 2099 - return false; 2100 - } 2101 - } 2102 - if (!method291(posX, posY + 128, z2)) { 2103 - return false; 2104 - } 2105 - return method291(posX + 128, posY + 128, z2); 2106 - } 2107 - if (wallType == 4) { 2108 - if (posX < cameraPosX) { 2109 - if (!method291(posX + 128, posY, posZ)) { 2110 - return false; 2111 - } 2112 - if (!method291(posX + 128, posY + 128, posZ)) { 2113 - return false; 2114 - } 2115 - } 2116 - if (level > 0) { 2117 - if (!method291(posX + 128, posY, z1)) { 2118 - return false; 2119 - } 2120 - if (!method291(posX + 128, posY + 128, z1)) { 2121 - return false; 2122 - } 2123 - } 2124 - if (!method291(posX + 128, posY, z2)) { 2125 - return false; 2126 - } 2127 - return method291(posX + 128, posY + 128, z2); 2128 - } 2129 - if (wallType == 8) { 2130 - if (posY > cameraPosY) { 2131 - if (!method291(posX, posY, posZ)) { 2132 - return false; 2133 - } 2134 - if (!method291(posX + 128, posY, posZ)) { 2135 - return false; 2136 - } 2137 - } 2138 - if (level > 0) { 2139 - if (!method291(posX, posY, z1)) { 2140 - return false; 2141 - } 2142 - if (!method291(posX + 128, posY, z1)) { 2143 - return false; 2144 - } 2145 - } 2146 - if (!method291(posX, posY, z2)) { 2147 - return false; 2148 - } 2149 - return method291(posX + 128, posY, z2); 2150 - } 2151 - } 2152 - if (!method291(posX + 64, posY + 64, z3)) { 2153 - return false; 2154 - } 2155 - if (wallType == 16) { 2156 - return method291(posX, posY + 128, z2); 2157 - } 2158 - if (wallType == 32) { 2159 - return method291(posX + 128, posY + 128, z2); 2160 - } 2161 - if (wallType == 64) { 2162 - return method291(posX + 128, posY, z2); 2163 - } 2164 - if (wallType == 128) { 2165 - return method291(posX, posY, z2); 2166 - } else { 2167 - System.out.println("Warning unsupported wall type"); 2168 - return true; 2169 - } 2170 - } 2171 - 2172 - private boolean isOccluded(int i, int j, int k, int l) { 2173 - if (!isTileOccluded(j, k, i)) { 2174 - return false; 2175 - } 2176 - int i1 = j << 7; 2177 - int j1 = k << 7; 2178 - return method291(i1 + 1, j1 + 1, heightMap[i][j][k] - l) 2179 - && method291((i1 + 128) - 1, j1 + 1, heightMap[i][j + 1][k] - l) 2180 - && method291((i1 + 128) - 1, (j1 + 128) - 1, heightMap[i][j + 1][k + 1] - l) 2181 - && method291(i1 + 1, (j1 + 128) - 1, heightMap[i][j][k + 1] - l); 2182 - } 2183 - 2184 - private boolean isAreaOccluded(int minimumX, int maximumX, int minimumY, int maximumY, int z, int offsetZ) { 2185 - if (minimumX == maximumX && minimumY == maximumY) { 2186 - if (!isTileOccluded(minimumX, minimumY, z)) { 2187 - return false; 2188 - } 2189 - int _x = minimumX << 7; 2190 - int _y = minimumY << 7; 2191 - return method291(_x + 1, _y + 1, heightMap[z][minimumX][minimumY] - offsetZ) 2192 - && method291((_x + 128) - 1, _y + 1, heightMap[z][minimumX + 1][minimumY] - offsetZ) 2193 - && method291((_x + 128) - 1, (_y + 128) - 1, heightMap[z][minimumX + 1][minimumY + 1] - offsetZ) 2194 - && method291(_x + 1, (_y + 128) - 1, heightMap[z][minimumX][minimumY + 1] - offsetZ); 2195 - } 2196 - for (int x = minimumX; x <= maximumX; x++) { 2197 - for (int y = minimumY; y <= maximumY; y++) { 2198 - if (anIntArrayArrayArray445[z][x][y] == -cycle) { 2199 - return false; 2200 - } 2201 - } 2202 - 2203 - } 2204 - 2205 - int _x = (minimumX << 7) + 1; 2206 - int _y = (minimumY << 7) + 2; 2207 - int _z = heightMap[z][minimumX][minimumY] - offsetZ; 2208 - if (!method291(_x, _y, _z)) { 2209 - return false; 2210 - } 2211 - int j3 = (maximumX << 7) - 1; 2212 - if (!method291(j3, _y, _z)) { 2213 - return false; 2214 - } 2215 - int k3 = (maximumY << 7) - 1; 2216 - if (!method291(_x, k3, _z)) { 2217 - return false; 2218 - } 2219 - return method291(j3, k3, _z); 2220 - } 2221 - 2222 - private boolean method291(int posX, int posY, int posZ) { 2223 - for (int c = 0; c < processedCullingClustersPointer; c++) { 2224 - SceneCluster cluster = processedCullingClusters[c]; 2225 - if (cluster.tileDistanceEnum == 1) { 2226 - int i1 = cluster.worldStartX - posX; 2227 - if (i1 > 0) { 2228 - int j2 = cluster.worldStartY + (cluster.worldDistanceFromCameraStartY * i1 >> 8); 2229 - int k3 = cluster.worldEndY + (cluster.worldDistanceFromCameraEndY * i1 >> 8); 2230 - int l4 = cluster.worldEndZ + (cluster.worldDistanceFromCameraStartZ * i1 >> 8); 2231 - int i6 = cluster.worldStartZ + (cluster.worldDistanceFromCameraEndZ * i1 >> 8); 2232 - if (posY >= j2 && posY <= k3 && posZ >= l4 && posZ <= i6) { 2233 - return true; 2234 - } 2235 - } 2236 - } else if (cluster.tileDistanceEnum == 2) { 2237 - int j1 = posX - cluster.worldStartX; 2238 - if (j1 > 0) { 2239 - int k2 = cluster.worldStartY + (cluster.worldDistanceFromCameraStartY * j1 >> 8); 2240 - int l3 = cluster.worldEndY + (cluster.worldDistanceFromCameraEndY * j1 >> 8); 2241 - int i5 = cluster.worldEndZ + (cluster.worldDistanceFromCameraStartZ * j1 >> 8); 2242 - int j6 = cluster.worldStartZ + (cluster.worldDistanceFromCameraEndZ * j1 >> 8); 2243 - if (posY >= k2 && posY <= l3 && posZ >= i5 && posZ <= j6) { 2244 - return true; 2245 - } 2246 - } 2247 - } else if (cluster.tileDistanceEnum == 3) { 2248 - int k1 = cluster.worldStartY - posY; 2249 - if (k1 > 0) { 2250 - int l2 = cluster.worldStartX + (cluster.worldDistanceFromCameraStartX * k1 >> 8); 2251 - int i4 = cluster.worldEndX + (cluster.worldDistanceFromCameraEndX * k1 >> 8); 2252 - int j5 = cluster.worldEndZ + (cluster.worldDistanceFromCameraStartZ * k1 >> 8); 2253 - int k6 = cluster.worldStartZ + (cluster.worldDistanceFromCameraEndZ * k1 >> 8); 2254 - if (posX >= l2 && posX <= i4 && posZ >= j5 && posZ <= k6) { 2255 - return true; 2256 - } 2257 - } 2258 - } else if (cluster.tileDistanceEnum == 4) { 2259 - int l1 = posY - cluster.worldStartY; 2260 - if (l1 > 0) { 2261 - int i3 = cluster.worldStartX + (cluster.worldDistanceFromCameraStartX * l1 >> 8); 2262 - int j4 = cluster.worldEndX + (cluster.worldDistanceFromCameraEndX * l1 >> 8); 2263 - int k5 = cluster.worldEndZ + (cluster.worldDistanceFromCameraStartZ * l1 >> 8); 2264 - int l6 = cluster.worldStartZ + (cluster.worldDistanceFromCameraEndZ * l1 >> 8); 2265 - if (posX >= i3 && posX <= j4 && posZ >= k5 && posZ <= l6) { 2266 - return true; 2267 - } 2268 - } 2269 - } else if (cluster.tileDistanceEnum == 5) { 2270 - int i2 = posZ - cluster.worldEndZ; 2271 - if (i2 > 0) { 2272 - int j3 = cluster.worldStartX + (cluster.worldDistanceFromCameraStartX * i2 >> 8); 2273 - int k4 = cluster.worldEndX + (cluster.worldDistanceFromCameraEndX * i2 >> 8); 2274 - int l5 = cluster.worldStartY + (cluster.worldDistanceFromCameraStartY * i2 >> 8); 2275 - int i7 = cluster.worldEndY + (cluster.worldDistanceFromCameraEndY * i2 >> 8); 2276 - if (posX >= j3 && posX <= k4 && posY >= l5 && posY <= i7) { 2277 - return true; 2278 - } 2279 - } 2280 - } 2281 - } 2282 - 2283 - return false; 2284 - } 2285 - 2286 - } 2287 - //TODO:Needs more refactoring
+2348
src/main/java/com/jagex/runescape/scene/Scene.kt
··· 1 + package com.jagex.runescape.scene 2 + 3 + import com.jagex.runescape.media.Rasterizer 4 + import com.jagex.runescape.media.Rasterizer3D 5 + import com.jagex.runescape.media.VertexNormal 6 + import com.jagex.runescape.media.renderable.Model 7 + import com.jagex.runescape.media.renderable.Renderable 8 + import com.jagex.runescape.scene.tile.* 9 + import com.jagex.runescape.util.LinkedList 10 + import com.jagex.runescape.world.GroundArray 11 + 12 + class Scene(heightMap: Array<Array<IntArray>>) { 13 + 14 + @JvmField var mapSizeZ: Int 15 + @JvmField var mapSizeX: Int 16 + @JvmField var mapSizeY: Int 17 + @JvmField var heightMap: Array<Array<IntArray>> 18 + @JvmField var tileArray: GroundArray<SceneTile> 19 + @JvmField var currentPositionZ: Int = 0 20 + @JvmField var sceneSpawnRequestsCacheCurrentPos: Int = 0 21 + @JvmField var sceneSpawnRequestsCache: Array<InteractiveObject?> 22 + @JvmField var tileRenderCycle: Array<Array<IntArray>> 23 + @JvmField var vertexTagsA: IntArray 24 + @JvmField var vertexTagsB: IntArray 25 + @JvmField var occlusionCycle: Int = 0 26 + @JvmField var tileShapePoints: Array<IntArray> = arrayOf( 27 + IntArray(16), 28 + intArrayOf(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 29 + intArrayOf(1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1), 30 + intArrayOf(1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0), 31 + intArrayOf(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1), 32 + intArrayOf(0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 33 + intArrayOf(1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1), 34 + intArrayOf(1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0), 35 + intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0), 36 + intArrayOf(1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1), 37 + intArrayOf(1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0), 38 + intArrayOf(0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1), 39 + intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1) 40 + ) 41 + @JvmField var tileShapeIndices: Array<IntArray> = arrayOf( 42 + intArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), 43 + intArrayOf(12, 8, 4, 0, 13, 9, 5, 1, 14, 10, 6, 2, 15, 11, 7, 3), 44 + intArrayOf(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), 45 + intArrayOf(3, 7, 11, 15, 2, 6, 10, 14, 1, 5, 9, 13, 0, 4, 8, 12) 46 + ) 47 + 48 + init { 49 + val length = 104 50 + val width = 104 51 + val height = 4 52 + sceneSpawnRequestsCache = arrayOfNulls(5000) 53 + vertexTagsA = IntArray(10000) 54 + vertexTagsB = IntArray(10000) 55 + mapSizeZ = height 56 + mapSizeX = width 57 + mapSizeY = length 58 + tileArray = GroundArray(Array(height) { Array(width) { arrayOfNulls<SceneTile>(length) } }) 59 + tileRenderCycle = Array(height) { Array(width + 1) { IntArray(length + 1) } } 60 + this.heightMap = heightMap 61 + initToNull() 62 + } 63 + 64 + fun initToNull() { 65 + for (z in 0 until mapSizeZ) { 66 + for (x in 0 until mapSizeX) { 67 + for (y in 0 until mapSizeY) { 68 + tileArray.clearTile(z, x, y) 69 + } 70 + } 71 + } 72 + 73 + for (l in 0 until CULLING_PLANES) { 74 + for (j1 in 0 until cullingClusterPointer!![l]) { 75 + cullingClusters!![l][j1] = null 76 + } 77 + cullingClusterPointer!![l] = 0 78 + } 79 + 80 + for (k1 in 0 until sceneSpawnRequestsCacheCurrentPos) { 81 + sceneSpawnRequestsCache[k1] = null 82 + } 83 + 84 + sceneSpawnRequestsCacheCurrentPos = 0 85 + for (l1 in interactiveObjects!!.indices) { 86 + interactiveObjects!![l1] = null 87 + } 88 + } 89 + 90 + fun setHeightLevel(z: Int) { 91 + currentPositionZ = z 92 + for (x in 0 until mapSizeX) { 93 + for (y in 0 until mapSizeY) { 94 + if (tileArray.isTileEmpty(z, x, y)) { 95 + tileArray.setTile(z, x, y, SceneTile(x, y, z)) 96 + } 97 + } 98 + } 99 + } 100 + 101 + fun setBridgeMode(x: Int, y: Int) { 102 + val scenetile = tileArray.getTile(0, x, y) 103 + for (z in 0 until 3) { 104 + val _tile = tileArray.setTile(z, x, y, tileArray.getTile(z + 1, x, y)) 105 + if (_tile != null) { 106 + _tile.z-- 107 + for (e in 0 until _tile.entityCount) { 108 + val entity = _tile.interactiveObjects[e] ?: continue 109 + if ((entity.uid ushr 29 and 3) == 2 && entity.tileLeft == x && entity.tileTop == y) { 110 + entity.z-- 111 + } 112 + } 113 + } 114 + } 115 + 116 + if (tileArray.isTileEmpty(0, x, y)) { 117 + tileArray.setTile(0, x, y, SceneTile(x, y, 0)) 118 + } 119 + tileArray.getTile(0, x, y)!!.tileBelow = scenetile 120 + tileArray.clearTile(3, x, y) 121 + } 122 + 123 + fun setTileLogicHeight(z: Int, x: Int, y: Int, logicHeight: Int) { 124 + val sceneTile = tileArray.getTile(z, x, y) 125 + if (sceneTile != null) { 126 + sceneTile.logicHeight = logicHeight 127 + } 128 + } 129 + 130 + fun addTile( 131 + plane: Int, x: Int, y: Int, shape: Int, clippingPathRotation: Int, textureId: Int, 132 + vertexHeightSW: Int, vertexHeightSE: Int, vertexHeightNE: Int, vertexHeightNW: Int, 133 + cA: Int, cB: Int, cD: Int, cC: Int, colourA: Int, colourB: Int, colourD: Int, colourC: Int, 134 + underlayRGB: Int, overlayRGB: Int 135 + ) { 136 + if (shape == 0) { 137 + val tile = GenericTile(cA, cB, cC, cD, -1, underlayRGB, false) 138 + for (_z in plane downTo 0) { 139 + if (tileArray.isTileEmpty(_z, x, y)) { 140 + tileArray.setTile(_z, x, y, SceneTile(x, y, _z)) 141 + } 142 + } 143 + tileArray.getTile(plane, x, y)!!.plainTile = tile 144 + } else if (shape == 1) { 145 + val tile = GenericTile( 146 + colourA, colourB, colourC, colourD, textureId, overlayRGB, 147 + vertexHeightSW == vertexHeightSE && vertexHeightSW == vertexHeightNE && vertexHeightSW == vertexHeightNW 148 + ) 149 + for (_z in plane downTo 0) { 150 + if (tileArray.isTileEmpty(_z, x, y)) { 151 + tileArray.setTile(_z, x, y, SceneTile(x, y, _z)) 152 + } 153 + } 154 + tileArray.getTile(plane, x, y)!!.plainTile = tile 155 + } else { 156 + val tile = ComplexTile( 157 + x, vertexHeightSW, vertexHeightSE, vertexHeightNW, vertexHeightNE, y, 158 + clippingPathRotation, textureId, shape, cA, colourA, cB, colourB, cC, colourC, cD, colourD, 159 + overlayRGB, underlayRGB 160 + ) 161 + for (_z in plane downTo 0) { 162 + if (tileArray.isTileEmpty(_z, x, y)) { 163 + tileArray.setTile(_z, x, y, SceneTile(x, y, _z)) 164 + } 165 + } 166 + tileArray.getTile(plane, x, y)!!.shapedTile = tile 167 + } 168 + } 169 + 170 + fun addGroundDecoration(x: Int, y: Int, z: Int, drawHeight: Int, uid: Int, renderable: Renderable?, config: Byte) { 171 + if (renderable == null) { 172 + return 173 + } 174 + val floorDecoration = FloorDecoration() 175 + floorDecoration.renderable = renderable 176 + floorDecoration.x = x * 128 + 64 177 + floorDecoration.y = y * 128 + 64 178 + floorDecoration.z = drawHeight 179 + floorDecoration.uid = uid 180 + floorDecoration.config = config 181 + if (tileArray.isTileEmpty(z, x, y)) { 182 + tileArray.setTile(z, x, y, SceneTile(x, y, z)) 183 + } 184 + tileArray.getTile(z, x, y)!!.floorDecoration = floorDecoration 185 + } 186 + 187 + fun addGroundItemTile( 188 + x: Int, y: Int, z: Int, drawHeight: Int, uid: Int, 189 + firstGroundItem: Renderable?, secondGroundItem: Renderable?, thirdGroundItem: Renderable? 190 + ) { 191 + val groundItemTile = GroundItemTile() 192 + groundItemTile.firstGroundItem = firstGroundItem 193 + groundItemTile.x = x * 128 + 64 194 + groundItemTile.y = y * 128 + 64 195 + groundItemTile.z = drawHeight 196 + groundItemTile.uid = uid 197 + groundItemTile.secondGroundItem = secondGroundItem 198 + groundItemTile.thirdGroundItem = thirdGroundItem 199 + var k1 = 0 200 + val sceneTile = tileArray.getTile(z, x, y) 201 + if (sceneTile != null) { 202 + for (e in 0 until sceneTile.entityCount) { 203 + val obj = sceneTile.interactiveObjects[e] 204 + if (obj != null && obj.renderable is Model) { 205 + val i2 = (obj.renderable as Model).objectHeight 206 + if (i2 > k1) { 207 + k1 = i2 208 + } 209 + } 210 + } 211 + } 212 + groundItemTile.heightOffset = k1 213 + if (tileArray.isTileEmpty(z, x, y)) { 214 + tileArray.setTile(z, x, y, SceneTile(x, y, z)) 215 + } 216 + tileArray.getTile(z, x, y)!!.groundItemTile = groundItemTile 217 + } 218 + 219 + fun addWall( 220 + x: Int, y: Int, z: Int, drawHeight: Int, orientation: Int, orientation2: Int, 221 + uid: Int, primary: Renderable?, secondary: Renderable?, config: Byte 222 + ) { 223 + if (primary != null || secondary != null) { 224 + val wall = Wall() 225 + wall.uid = uid 226 + wall.config = config 227 + wall.x = x * 128 + 64 228 + wall.y = y * 128 + 64 229 + wall.z = drawHeight 230 + wall.primary = primary 231 + wall.secondary = secondary 232 + wall.orientation = orientation 233 + wall.orientation2 = orientation2 234 + for (_z in z downTo 0) { 235 + if (tileArray.isTileEmpty(_z, x, y)) { 236 + tileArray.setTile(_z, x, y, SceneTile(x, y, _z)) 237 + } 238 + } 239 + tileArray.getTile(z, x, y)!!.wall = wall 240 + } 241 + } 242 + 243 + fun addWallDecoration( 244 + x: Int, y: Int, z: Int, drawHeight: Int, offsetX: Int, offsetY: Int, 245 + face: Int, uid: Int, renderable: Renderable?, config: Byte, faceBits: Int 246 + ) { 247 + if (renderable != null) { 248 + val wallDecoration = WallDecoration() 249 + wallDecoration.uid = uid 250 + wallDecoration.config = config 251 + wallDecoration.x = x * 128 + 64 + offsetX 252 + wallDecoration.y = y * 128 + 64 + offsetY 253 + wallDecoration.z = drawHeight 254 + wallDecoration.renderable = renderable 255 + wallDecoration.configBits = faceBits 256 + wallDecoration.face = face 257 + for (planeCounter in z downTo 0) { 258 + if (tileArray.isTileEmpty(planeCounter, x, y)) { 259 + tileArray.setTile(planeCounter, x, y, SceneTile(x, y, planeCounter)) 260 + } 261 + } 262 + tileArray.getTile(z, x, y)!!.wallDecoration = wallDecoration 263 + } 264 + } 265 + 266 + fun addEntityB( 267 + x: Int, y: Int, z: Int, worldZ: Int, rotation: Int, 268 + tileWidth: Int, tileHeight: Int, uid: Int, entity: Renderable?, config: Byte 269 + ): Boolean { 270 + if (entity == null) { 271 + return true 272 + } else { 273 + val worldX = x * 128 + 64 * tileHeight 274 + val worldY = y * 128 + 64 * tileWidth 275 + return addRenderableC(x, y, z, worldX, worldY, worldZ, rotation, tileWidth, tileHeight, uid, entity, false, config) 276 + } 277 + } 278 + 279 + fun addEntity( 280 + z: Int, worldX: Int, worldY: Int, worldZ: Int, entity: Renderable?, 281 + uid: Int, delta: Int, accountForYaw: Boolean, yaw: Int 282 + ): Boolean { 283 + if (entity == null) { 284 + return true 285 + } 286 + var minX = worldX - delta 287 + var minY = worldY - delta 288 + var maxX = worldX + delta 289 + var maxY = worldY + delta 290 + if (accountForYaw) { 291 + if (yaw > 640 && yaw < 1408) { 292 + maxY += 128 293 + } 294 + if (yaw > 1152 && yaw < 1920) { 295 + maxX += 128 296 + } 297 + if (yaw > 1664 || yaw < 384) { 298 + minY -= 128 299 + } 300 + if (yaw > 128 && yaw < 896) { 301 + minX -= 128 302 + } 303 + } 304 + minX /= 128 305 + minY /= 128 306 + maxX /= 128 307 + maxY /= 128 308 + return addRenderableC(minX, minY, z, worldX, worldY, worldZ, yaw, (maxY - minY) + 1, (maxX - minX) + 1, uid, entity, true, 0.toByte()) 309 + } 310 + 311 + fun addEntity( 312 + x: Int, y: Int, z: Int, worldX: Int, worldY: Int, worldZ: Int, 313 + rotation: Int, tileWidth: Int, tileHeight: Int, entity: Renderable?, uid: Int 314 + ): Boolean { 315 + return entity == null || addRenderableC( 316 + x, y, z, worldX, worldY, worldZ, rotation, (tileWidth - y) + 1, 317 + (tileHeight - x) + 1, uid, entity, true, 0.toByte() 318 + ) 319 + } 320 + 321 + private fun addRenderableC( 322 + minX: Int, minY: Int, z: Int, worldX: Int, worldY: Int, worldZ: Int, 323 + rotation: Int, tileWidth: Int, tileHeight: Int, uid: Int, renderable: Renderable, 324 + isDynamic: Boolean, config: Byte 325 + ): Boolean { 326 + for (x in minX until minX + tileHeight) { 327 + for (y in minY until minY + tileWidth) { 328 + if (x < 0 || y < 0 || x >= mapSizeX || y >= mapSizeY) { 329 + return false 330 + } 331 + val tile = tileArray.getTile(z, x, y) 332 + if (tile != null && tile.entityCount >= 5) { 333 + return false 334 + } 335 + } 336 + } 337 + 338 + val interactiveObject = InteractiveObject() 339 + interactiveObject.uid = uid 340 + interactiveObject.config = config 341 + interactiveObject.z = z 342 + interactiveObject.worldX = worldX 343 + interactiveObject.worldY = worldY 344 + interactiveObject.worldZ = worldZ 345 + interactiveObject.renderable = renderable 346 + interactiveObject.rotation = rotation 347 + interactiveObject.tileLeft = minX 348 + interactiveObject.tileTop = minY 349 + interactiveObject.tileRight = (minX + tileHeight) - 1 350 + interactiveObject.tileBottom = (minY + tileWidth) - 1 351 + for (x in minX until minX + tileHeight) { 352 + for (y in minY until minY + tileWidth) { 353 + var size = 0 354 + if (x > minX) { 355 + size++ 356 + } 357 + if (x < (minX + tileHeight) - 1) { 358 + size += 4 359 + } 360 + if (y > minY) { 361 + size += 8 362 + } 363 + if (y < (minY + tileWidth) - 1) { 364 + size += 2 365 + } 366 + for (_z in z downTo 0) { 367 + if (tileArray.isTileEmpty(_z, x, y)) { 368 + tileArray.setTile(_z, x, y, SceneTile(x, y, _z)) 369 + } 370 + } 371 + 372 + val sceneTile = tileArray.getTile(z, x, y)!! 373 + sceneTile.interactiveObjects[sceneTile.entityCount] = interactiveObject 374 + sceneTile.sceneSpawnRequestsSize[sceneTile.entityCount] = size 375 + sceneTile.interactiveObjectsSizeOR = sceneTile.interactiveObjectsSizeOR or size 376 + sceneTile.entityCount++ 377 + } 378 + } 379 + 380 + if (isDynamic) { 381 + sceneSpawnRequestsCache[sceneSpawnRequestsCacheCurrentPos] = interactiveObject 382 + sceneSpawnRequestsCacheCurrentPos++ 383 + } 384 + return true 385 + } 386 + 387 + fun clearInteractiveObjectCache() { 388 + for (j in 0 until sceneSpawnRequestsCacheCurrentPos) { 389 + val interactiveObject = sceneSpawnRequestsCache[j] 390 + remove(interactiveObject!!) 391 + sceneSpawnRequestsCache[j] = null 392 + } 393 + sceneSpawnRequestsCacheCurrentPos = 0 394 + } 395 + 396 + private fun remove(entity: InteractiveObject) { 397 + for (x in entity.tileLeft..entity.tileRight) { 398 + for (y in entity.tileTop..entity.tileBottom) { 399 + val tile = tileArray.getTile(entity.z, x, y) 400 + if (tile != null) { 401 + for (e in 0 until tile.entityCount) { 402 + if (tile.interactiveObjects[e] != entity) { 403 + continue 404 + } 405 + tile.entityCount-- 406 + for (e2 in e until tile.entityCount) { 407 + tile.interactiveObjects[e2] = tile.interactiveObjects[e2 + 1] 408 + tile.sceneSpawnRequestsSize[e2] = tile.sceneSpawnRequestsSize[e2 + 1] 409 + } 410 + tile.interactiveObjects[tile.entityCount] = null 411 + break 412 + } 413 + 414 + tile.interactiveObjectsSizeOR = 0 415 + for (j1 in 0 until tile.entityCount) { 416 + tile.interactiveObjectsSizeOR = tile.interactiveObjectsSizeOR or tile.sceneSpawnRequestsSize[j1] 417 + } 418 + } 419 + } 420 + } 421 + } 422 + 423 + fun displaceWallDecoration(x: Int, y: Int, z: Int, displacement: Int) { 424 + val sceneTile = tileArray.getTile(z, x, y) ?: return 425 + val wallDecoration = sceneTile.wallDecoration ?: return 426 + val absX = x * 128 + 64 427 + val absY = y * 128 + 64 428 + wallDecoration.x = absX + ((wallDecoration.x - absX) * displacement) / 16 429 + wallDecoration.y = absY + ((wallDecoration.y - absY) * displacement) / 16 430 + } 431 + 432 + fun removeWallObject(x: Int, y: Int, z: Int) { 433 + val tile = tileArray.getTile(z, x, y) 434 + if (tile != null) { 435 + tile.wall = null 436 + } 437 + } 438 + 439 + fun removeWallDecoration(x: Int, y: Int, z: Int) { 440 + val tile = tileArray.getTile(z, x, y) 441 + if (tile != null) { 442 + tile.wallDecoration = null 443 + } 444 + } 445 + 446 + fun removeInteractiveObject(x: Int, y: Int, z: Int) { 447 + val tile = tileArray.getTile(z, x, y) ?: return 448 + for (e in 0 until tile.entityCount) { 449 + val interactiveObject = tile.interactiveObjects[e] ?: continue 450 + if ((interactiveObject.uid ushr 29 and 3) == 2 && interactiveObject.tileLeft == x && interactiveObject.tileTop == y) { 451 + remove(interactiveObject) 452 + return 453 + } 454 + } 455 + } 456 + 457 + fun method261(x: Int, y: Int, z: Int) { 458 + val sceneTile = tileArray.getTile(z, x, y) ?: return 459 + sceneTile.floorDecoration = null 460 + } 461 + 462 + fun clearGroundItem(z: Int, x: Int, y: Int) { 463 + val sceneTile = tileArray.getTile(z, x, y) 464 + if (sceneTile != null) { 465 + sceneTile.groundItemTile = null 466 + } 467 + } 468 + 469 + fun getWallObject(level: Int, x: Int, y: Int): Wall? { 470 + val sceneTile = tileArray.getTile(level, x, y) 471 + return if (sceneTile == null) { 472 + null 473 + } else { 474 + sceneTile.wall 475 + } 476 + } 477 + 478 + fun getWallDecoration(level: Int, y: Int, x: Int): WallDecoration? { 479 + val sceneTile = tileArray.getTile(level, x, y) 480 + return if (sceneTile == null) { 481 + null 482 + } else { 483 + sceneTile.wallDecoration 484 + } 485 + } 486 + 487 + fun method265(x: Int, y: Int, level: Int): InteractiveObject? { 488 + val sceneTile = tileArray.getTile(level, x, y) ?: return null 489 + for (i in 0 until sceneTile.entityCount) { 490 + val interactiveObject = sceneTile.interactiveObjects[i] ?: continue 491 + if ((interactiveObject.uid ushr 29 and 3) == 2 && interactiveObject.tileLeft == x && interactiveObject.tileTop == y) { 492 + return interactiveObject 493 + } 494 + } 495 + return null 496 + } 497 + 498 + fun getFloorDecoration(level: Int, x: Int, y: Int): FloorDecoration? { 499 + val sceneTile = tileArray.getTile(level, x, y) 500 + return if (sceneTile == null || sceneTile.floorDecoration == null) { 501 + null 502 + } else { 503 + sceneTile.floorDecoration 504 + } 505 + } 506 + 507 + fun getWallObjectHash(x: Int, y: Int, z: Int): Int { 508 + val sceneTile = tileArray.getTile(z, x, y) 509 + val wall = sceneTile?.wall 510 + return if (wall == null) { 511 + 0 512 + } else { 513 + wall.uid 514 + } 515 + } 516 + 517 + fun getWallDecorationHash(x: Int, z: Int, y: Int): Int { 518 + val sceneTile = tileArray.getTile(z, x, y) 519 + val wallDecoration = sceneTile?.wallDecoration 520 + return if (wallDecoration == null) { 521 + 0 522 + } else { 523 + wallDecoration.uid 524 + } 525 + } 526 + 527 + fun getLocationHash(z: Int, x: Int, y: Int): Int { 528 + val sceneTile = tileArray.getTile(z, x, y) ?: return 0 529 + for (l in 0 until sceneTile.entityCount) { 530 + val interactiveObject = sceneTile.interactiveObjects[l] ?: continue 531 + if ((interactiveObject.uid ushr 29 and 3) == 2 && interactiveObject.tileLeft == x && interactiveObject.tileTop == y) { 532 + return interactiveObject.uid 533 + } 534 + } 535 + return 0 536 + } 537 + 538 + fun getFloorDecorationHash(z: Int, x: Int, y: Int): Int { 539 + val sceneTile = tileArray.getTile(z, x, y) 540 + val floorDecoration = sceneTile?.floorDecoration 541 + return if (floorDecoration == null) { 542 + 0 543 + } else { 544 + floorDecoration.uid 545 + } 546 + } 547 + 548 + fun getArrangement(z: Int, x: Int, y: Int, l: Int): Int { 549 + val sceneTile = tileArray.getTile(z, x, y) ?: return -1 550 + val wall = sceneTile.wall 551 + if (wall != null && wall.uid == l) { 552 + return wall.config.toInt() and 0xff 553 + } 554 + val wallDecoration = sceneTile.wallDecoration 555 + if (wallDecoration != null && wallDecoration.uid == l) { 556 + return wallDecoration.config.toInt() and 0xff 557 + } 558 + val floorDecoration = sceneTile.floorDecoration 559 + if (floorDecoration != null && floorDecoration.uid == l) { 560 + return floorDecoration.config.toInt() and 0xff 561 + } 562 + for (i1 in 0 until sceneTile.entityCount) { 563 + val interactiveObject = sceneTile.interactiveObjects[i1] ?: continue 564 + if (interactiveObject.uid == l) { 565 + return interactiveObject.config.toInt() and 0xff 566 + } 567 + } 568 + return -1 569 + } 570 + 571 + fun shadeModels(i: Int, j: Int, k: Int) { 572 + for (_z in 0 until mapSizeZ) { 573 + for (_x in 0 until mapSizeX) { 574 + for (_y in 0 until mapSizeY) { 575 + val tile = tileArray.getTile(_z, _x, _y) 576 + if (tile != null) { 577 + val wall = tile.wall 578 + val wallPrimary = wall?.primary 579 + if (wall != null && wallPrimary != null && wallPrimary.verticesNormal != null) { 580 + method274(_y, _z, 0, 1, wallPrimary as Model, _x, 1) 581 + val wallSecondary = wall.secondary 582 + if (wallSecondary != null && wallSecondary.verticesNormal != null) { 583 + method274(_y, _z, 0, 1, wallSecondary as Model, _x, 1) 584 + mergeNormals( 585 + wallPrimary, 586 + wallSecondary, 0, 0, 0, false 587 + ) 588 + (wallSecondary as Model).handleShading(i, j, 0, k) 589 + } 590 + (wallPrimary as Model).handleShading(i, j, 0, k) 591 + } 592 + for (k1 in 0 until tile.entityCount) { 593 + val interactiveObject = tile.interactiveObjects[k1] 594 + val renderable = interactiveObject?.renderable 595 + if (interactiveObject != null && renderable != null && renderable.verticesNormal != null) { 596 + method274( 597 + _y, _z, 0, (interactiveObject.tileRight - interactiveObject.tileLeft) + 1, 598 + renderable as Model, _x, 599 + (interactiveObject.tileBottom - interactiveObject.tileTop) + 1 600 + ) 601 + (renderable as Model).handleShading(i, j, 0, k) 602 + } 603 + } 604 + 605 + val floorDecoration = tile.floorDecoration 606 + val floorRenderable = floorDecoration?.renderable 607 + if (floorDecoration != null && floorRenderable != null && floorRenderable.verticesNormal != null) { 608 + method273(_x, floorRenderable as Model, _y, _z, 0) 609 + (floorRenderable as Model).handleShading(i, j, 0, k) 610 + } 611 + } 612 + } 613 + } 614 + } 615 + } 616 + 617 + private fun method273(x: Int, model: Model, y: Int, z: Int, l: Int) { 618 + if (l != 0) { 619 + return 620 + } 621 + if (x < mapSizeX) { 622 + val sceneTile = tileArray.getTile(z, x + 1, y) 623 + val fd = sceneTile?.floorDecoration 624 + val r = fd?.renderable 625 + if (fd != null && r != null && r.verticesNormal != null) { 626 + mergeNormals(model, r as Model, 128, 0, 0, true) 627 + } 628 + } 629 + if (y < mapSizeX) { 630 + val sceneTile = tileArray.getTile(z, x, y + 1) 631 + val fd = sceneTile?.floorDecoration 632 + val r = fd?.renderable 633 + if (fd != null && r != null && r.verticesNormal != null) { 634 + mergeNormals(model, r as Model, 0, 0, 128, true) 635 + } 636 + } 637 + if (x < mapSizeX && y < mapSizeY) { 638 + val sceneTile = tileArray.getTile(z, x + 1, y + 1) 639 + val fd = sceneTile?.floorDecoration 640 + val r = fd?.renderable 641 + if (fd != null && r != null && r.verticesNormal != null) { 642 + mergeNormals(model, r as Model, 128, 0, 128, true) 643 + } 644 + } 645 + if (x < mapSizeX && y > 0) { 646 + val sceneTile = tileArray.getTile(z, x + 1, y - 1) 647 + val fd = sceneTile?.floorDecoration 648 + val r = fd?.renderable 649 + if (fd != null && r != null && r.verticesNormal != null) { 650 + mergeNormals(model, r as Model, 128, 0, -128, true) 651 + } 652 + } 653 + } 654 + 655 + private fun method274(i: Int, j: Int, k: Int, l: Int, class50_sub1_sub4_sub4: Model, i1: Int, j1: Int) { 656 + var flag = true 657 + val k1 = i1 658 + val l1 = i1 + l 659 + val i2 = i - 1 660 + val j2 = i + j1 661 + for (z in j..j + 1) { 662 + if (z != mapSizeZ) { 663 + for (x in k1..l1) { 664 + if (x in 0 until mapSizeX) { 665 + for (y in i2..j2) { 666 + if (y in 0 until mapSizeY && (!flag || x >= l1 || y >= j2 || y < i && x != i1)) { 667 + val class50_sub3 = tileArray.getTile(z, x, y) 668 + if (class50_sub3 != null) { 669 + val j3 = (heightMap[z][x][y] + heightMap[z][x + 1][y] + heightMap[z][x][y + 1] + heightMap[z][x + 1][y + 1]) / 4 - 670 + (heightMap[j][i1][i] + heightMap[j][i1 + 1][i] + heightMap[j][i1][i + 1] + heightMap[j][i1 + 1][i + 1]) / 4 671 + val wall = class50_sub3.wall 672 + val wallPrimary = wall?.primary 673 + if (wall != null && wallPrimary != null && wallPrimary.verticesNormal != null) { 674 + mergeNormals( 675 + class50_sub1_sub4_sub4, 676 + wallPrimary as Model, 677 + (x - i1) * 128 + (1 - l) * 64, j3, (y - i) * 128 + (1 - j1) * 64, flag 678 + ) 679 + } 680 + val wallSecondary = wall?.secondary 681 + if (wall != null && wallSecondary != null && wallSecondary.verticesNormal != null) { 682 + mergeNormals( 683 + class50_sub1_sub4_sub4, 684 + wallSecondary as Model, 685 + (x - i1) * 128 + (1 - l) * 64, j3, (y - i) * 128 + (1 - j1) * 64, flag 686 + ) 687 + } 688 + for (k3 in 0 until class50_sub3.entityCount) { 689 + val interactiveObject = class50_sub3.interactiveObjects[k3] 690 + val objRenderable = interactiveObject?.renderable 691 + if (interactiveObject != null && objRenderable != null && objRenderable.verticesNormal != null) { 692 + val l3 = (interactiveObject.tileRight - interactiveObject.tileLeft) + 1 693 + val i4 = (interactiveObject.tileBottom - interactiveObject.tileTop) + 1 694 + mergeNormals( 695 + class50_sub1_sub4_sub4, 696 + objRenderable as Model, 697 + (interactiveObject.tileLeft - i1) * 128 + (l3 - l) * 64, j3, 698 + (interactiveObject.tileTop - i) * 128 + (i4 - j1) * 64, flag 699 + ) 700 + } 701 + } 702 + } 703 + } 704 + } 705 + } 706 + } 707 + flag = false 708 + } 709 + } 710 + 711 + if (k == 0) { 712 + } 713 + } 714 + 715 + private fun mergeNormals(modelA: Model, modelB: Model, i: Int, j: Int, k: Int, flag: Boolean) { 716 + occlusionCycle++ 717 + var count = 0 718 + val vertices = modelB.verticesX 719 + val vertexCount = modelB.vertexCount 720 + val minX = modelB.worldX shr 16 721 + val maxX = (modelB.worldX shl 16) shr 16 722 + val maxZ = modelB.worldZ shr 16 723 + val minZ = (modelB.worldZ shl 16) shr 16 724 + for (vertex in 0 until modelA.vertexCount) { 725 + val vertexNormal = modelA.verticesNormal!![vertex]!! 726 + val offsetVertexNormal = modelA.vertexNormalOffset!![vertex]!! 727 + if (offsetVertexNormal.magnitude != 0) { 728 + val y = modelA.verticesY[vertex] - j 729 + if (y <= modelB.maxY) { 730 + val x = modelA.verticesX[vertex] - i 731 + if (x >= minX && x <= maxX) { 732 + val z = modelA.verticesZ[vertex] - k 733 + if (z >= minZ && z <= maxZ) { 734 + for (v in 0 until vertexCount) { 735 + val class40_2 = modelB.verticesNormal!![v]!! 736 + val class40_3 = modelB.vertexNormalOffset!![v]!! 737 + if (x == vertices[v] && z == modelB.verticesZ[v] && y == modelB.verticesY[v] && class40_3.magnitude != 0) { 738 + vertexNormal.x += class40_3.x 739 + vertexNormal.y += class40_3.y 740 + vertexNormal.z += class40_3.z 741 + vertexNormal.magnitude += class40_3.magnitude 742 + class40_2.x += offsetVertexNormal.x 743 + class40_2.y += offsetVertexNormal.y 744 + class40_2.z += offsetVertexNormal.z 745 + class40_2.magnitude += offsetVertexNormal.magnitude 746 + count++ 747 + vertexTagsA[vertex] = occlusionCycle 748 + vertexTagsB[v] = occlusionCycle 749 + } 750 + } 751 + } 752 + } 753 + } 754 + } 755 + } 756 + 757 + if (count < 3 || !flag) { 758 + return 759 + } 760 + for (k2 in 0 until modelA.triangleCount) { 761 + if (vertexTagsA[modelA.trianglePointsX[k2]] == occlusionCycle && 762 + vertexTagsA[modelA.trianglePointsY[k2]] == occlusionCycle && 763 + vertexTagsA[modelA.trianglePointsZ[k2]] == occlusionCycle 764 + ) { 765 + modelA.triangleDrawType!![k2] = -1 766 + } 767 + } 768 + 769 + for (l2 in 0 until modelB.triangleCount) { 770 + if (vertexTagsB[modelB.trianglePointsX[l2]] == occlusionCycle && 771 + vertexTagsB[modelB.trianglePointsY[l2]] == occlusionCycle && 772 + vertexTagsB[modelB.trianglePointsZ[l2]] == occlusionCycle 773 + ) { 774 + modelB.triangleDrawType!![l2] = -1 775 + } 776 + } 777 + } 778 + 779 + fun renderMinimapTile(pixels: IntArray, pixelPointer: Int, j: Int, z: Int, x: Int, y: Int) { 780 + @Suppress("NAME_SHADOWING") 781 + var pixelPointer = pixelPointer 782 + val sceneTile = tileArray.getTile(z, x, y) ?: return 783 + val genericTile = sceneTile.plainTile 784 + if (genericTile != null) { 785 + val tileRGB = genericTile.rgbColor 786 + if (tileRGB == 0) { 787 + return 788 + } 789 + for (k1 in 0 until 4) { 790 + pixels[pixelPointer] = tileRGB 791 + pixels[pixelPointer + 1] = tileRGB 792 + pixels[pixelPointer + 2] = tileRGB 793 + pixels[pixelPointer + 3] = tileRGB 794 + pixelPointer += j 795 + } 796 + return 797 + } 798 + val complexTile = sceneTile.shapedTile ?: return 799 + val shapeA = complexTile.shape 800 + val shapeB = complexTile.rotation 801 + val underlayRGB = complexTile.underlayRGB 802 + val overlayRGB = complexTile.overlayRGB 803 + val shapePoints = tileShapePoints[shapeA] 804 + val shapeIndices = tileShapeIndices[shapeB] 805 + var shapePtr = 0 806 + if (underlayRGB != 0) { 807 + for (linePtr in 0 until 4) { 808 + pixels[pixelPointer] = if (shapePoints[shapeIndices[shapePtr++]] != 0) overlayRGB else underlayRGB 809 + pixels[pixelPointer + 1] = if (shapePoints[shapeIndices[shapePtr++]] != 0) overlayRGB else underlayRGB 810 + pixels[pixelPointer + 2] = if (shapePoints[shapeIndices[shapePtr++]] != 0) overlayRGB else underlayRGB 811 + pixels[pixelPointer + 3] = if (shapePoints[shapeIndices[shapePtr++]] != 0) overlayRGB else underlayRGB 812 + pixelPointer += j 813 + } 814 + return 815 + } 816 + for (linePtr in 0 until 4) { 817 + if (shapePoints[shapeIndices[shapePtr++]] != 0) { 818 + pixels[pixelPointer] = overlayRGB 819 + } 820 + if (shapePoints[shapeIndices[shapePtr++]] != 0) { 821 + pixels[pixelPointer + 1] = overlayRGB 822 + } 823 + if (shapePoints[shapeIndices[shapePtr++]] != 0) { 824 + pixels[pixelPointer + 2] = overlayRGB 825 + } 826 + if (shapePoints[shapeIndices[shapePtr++]] != 0) { 827 + pixels[pixelPointer + 3] = overlayRGB 828 + } 829 + pixelPointer += j 830 + } 831 + } 832 + 833 + fun method279(i: Int, j: Int, k: Int) { 834 + clicked = true 835 + clickX = j 836 + clickY = k 837 + clickedTileX = -1 838 + if (i != 0) { 839 + } else { 840 + clickedTileY = -1 841 + } 842 + } 843 + 844 + @Suppress("NAME_SHADOWING") 845 + fun render(cameraPosX: Int, j: Int, k: Int, l: Int, cameraPosY: Int, curveX: Int, curveY: Int) { 846 + var cameraPosX = cameraPosX 847 + var cameraPosY = cameraPosY 848 + if (cameraPosX < 0) { 849 + cameraPosX = 0 850 + } else if (cameraPosX >= mapSizeX * 128) { 851 + cameraPosX = mapSizeX * 128 - 1 852 + } 853 + if (cameraPosY < 0) { 854 + cameraPosY = 0 855 + } else if (cameraPosY >= mapSizeY * 128) { 856 + cameraPosY = mapSizeY * 128 - 1 857 + } 858 + cycle++ 859 + curveSineY = Model.SINE!![curveY] 860 + curveCosineY = Model.COSINE!![curveY] 861 + curveSineX = Model.SINE!![curveX] 862 + curveCosineX = Model.COSINE!![curveX] 863 + TILE_VISIBILITY_MAP = TILE_VISIBILITY_MAPS!![(curveY - 128) / 32][curveX / 64] 864 + Scene.cameraPosX = cameraPosX 865 + cameraPosZ = l 866 + Scene.cameraPosY = cameraPosY 867 + cameraPositionTileX = cameraPosX / 128 868 + cameraPositionTileY = cameraPosY / 128 869 + plane = j 870 + currentPositionX = cameraPositionTileX - 25 871 + if (k != 0) { 872 + return 873 + } 874 + if (currentPositionX < 0) { 875 + currentPositionX = 0 876 + } 877 + currentPositionY = cameraPositionTileY - 25 878 + if (currentPositionY < 0) { 879 + currentPositionY = 0 880 + } 881 + mapBoundsX = cameraPositionTileX + 25 882 + if (mapBoundsX > mapSizeX) { 883 + mapBoundsX = mapSizeX 884 + } 885 + mapBoundsY = cameraPositionTileY + 25 886 + if (mapBoundsY > mapSizeY) { 887 + mapBoundsY = mapSizeY 888 + } 889 + processCulling() 890 + deferredObjectCount = 0 891 + for (z in currentPositionZ until mapSizeZ) { 892 + for (x in currentPositionX until mapBoundsX) { 893 + for (y in currentPositionY until mapBoundsY) { 894 + val tile = tileArray.getTile(z, x, y) 895 + if (tile != null) { 896 + if (tile.logicHeight > j || 897 + !TILE_VISIBILITY_MAP!![(x - cameraPositionTileX) + 25][(y - cameraPositionTileY) + 25] && 898 + heightMap[z][x][y] - l < 2000 899 + ) { 900 + tile.draw = false 901 + tile.visible = false 902 + tile.wallCullDirection = 0 903 + } else { 904 + tile.draw = true 905 + tile.visible = true 906 + tile.drawEntities = tile.entityCount > 0 907 + deferredObjectCount++ 908 + } 909 + } 910 + } 911 + } 912 + } 913 + 914 + for (z in currentPositionZ until mapSizeZ) { 915 + for (offsetX in -25..0) { 916 + val x = cameraPositionTileX + offsetX 917 + val x2 = cameraPositionTileX - offsetX 918 + if (x >= currentPositionX || x2 < mapBoundsX) { 919 + for (offsetY in -25..0) { 920 + val y = cameraPositionTileY + offsetY 921 + val y2 = cameraPositionTileY - offsetY 922 + if (x >= currentPositionX) { 923 + if (y >= currentPositionY) { 924 + val sceneTile = tileArray.getTile(z, x, y) 925 + if (sceneTile != null && sceneTile.draw) { 926 + renderTile(sceneTile, true) 927 + } 928 + } 929 + if (y2 < mapBoundsY) { 930 + val sceneTile = tileArray.getTile(z, x, y2) 931 + if (sceneTile != null && sceneTile.draw) { 932 + renderTile(sceneTile, true) 933 + } 934 + } 935 + } 936 + if (x2 < mapBoundsX) { 937 + if (y >= currentPositionY) { 938 + val sceneTile = tileArray.getTile(z, x2, y) 939 + if (sceneTile != null && sceneTile.draw) { 940 + renderTile(sceneTile, true) 941 + } 942 + } 943 + if (y2 < mapBoundsY) { 944 + val sceneTile = tileArray.getTile(z, x2, y2) 945 + if (sceneTile != null && sceneTile.draw) { 946 + renderTile(sceneTile, true) 947 + } 948 + } 949 + } 950 + if (deferredObjectCount == 0) { 951 + clicked = false 952 + return 953 + } 954 + } 955 + } 956 + } 957 + } 958 + 959 + for (z in currentPositionZ until mapSizeZ) { 960 + for (offsetX in -25..0) { 961 + val x = cameraPositionTileX + offsetX 962 + val x2 = cameraPositionTileX - offsetX 963 + if (x >= currentPositionX || x2 < mapBoundsX) { 964 + for (offsetY in -25..0) { 965 + val y = cameraPositionTileY + offsetY 966 + val y2 = cameraPositionTileY - offsetY 967 + if (x >= currentPositionX) { 968 + if (y >= currentPositionY) { 969 + val tile = tileArray.getTile(z, x, y) 970 + if (tile != null && tile.draw) { 971 + renderTile(tile, false) 972 + } 973 + } 974 + if (y2 < mapBoundsY) { 975 + val tile = tileArray.getTile(z, x, y2) 976 + if (tile != null && tile.draw) { 977 + renderTile(tile, false) 978 + } 979 + } 980 + } 981 + if (x2 < mapBoundsX) { 982 + if (y >= currentPositionY) { 983 + val tile = tileArray.getTile(z, x2, y) 984 + if (tile != null && tile.draw) { 985 + renderTile(tile, false) 986 + } 987 + } 988 + if (y2 < mapBoundsY) { 989 + val tile = tileArray.getTile(z, x2, y2) 990 + if (tile != null && tile.draw) { 991 + renderTile(tile, false) 992 + } 993 + } 994 + } 995 + if (deferredObjectCount == 0) { 996 + clicked = false 997 + return 998 + } 999 + } 1000 + } 1001 + } 1002 + } 1003 + 1004 + clicked = false 1005 + } 1006 + 1007 + private fun renderTile(_tile: SceneTile, flag: Boolean) { 1008 + @Suppress("NAME_SHADOWING") 1009 + var flag = flag 1010 + tileList!!.pushBack(_tile) 1011 + do { 1012 + var groundTile: SceneTile 1013 + do { 1014 + groundTile = tileList!!.pop() as SceneTile? ?: return 1015 + } while (!groundTile.visible) 1016 + val x = groundTile.x 1017 + val y = groundTile.y 1018 + val z = groundTile.z 1019 + val level = groundTile.renderLevel 1020 + if (groundTile.draw) { 1021 + if (flag) { 1022 + if (z > 0) { 1023 + val tile = tileArray.getTile(z - 1, x, y) 1024 + if (tile != null && tile.visible) { 1025 + continue 1026 + } 1027 + } 1028 + if (x <= cameraPositionTileX && x > currentPositionX) { 1029 + val tile = tileArray.getTile(z, x - 1, y) 1030 + if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR and 1) == 0)) { 1031 + continue 1032 + } 1033 + } 1034 + if (x >= cameraPositionTileX && x < mapBoundsX - 1) { 1035 + val tile = tileArray.getTile(z, x + 1, y) 1036 + if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR and 4) == 0)) { 1037 + continue 1038 + } 1039 + } 1040 + if (y <= cameraPositionTileY && y > currentPositionY) { 1041 + val tile = tileArray.getTile(z, x, y - 1) 1042 + if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR and 8) == 0)) { 1043 + continue 1044 + } 1045 + } 1046 + if (y >= cameraPositionTileY && y < mapBoundsY - 1) { 1047 + val tile = tileArray.getTile(z, x, y + 1) 1048 + if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR and 2) == 0)) { 1049 + continue 1050 + } 1051 + } 1052 + } else { 1053 + flag = true 1054 + } 1055 + groundTile.draw = false 1056 + val tileBelow = groundTile.tileBelow 1057 + if (tileBelow != null) { 1058 + val plainTile = tileBelow.plainTile 1059 + val shapedTile = tileBelow.shapedTile 1060 + if (plainTile != null) { 1061 + if (!isTileOccluded(x, y, 0)) { 1062 + renderPlainTile(plainTile, x, y, 0, curveSineX, curveCosineX, curveSineY, curveCosineY) 1063 + } 1064 + } else if (shapedTile != null && !isTileOccluded(x, y, 0)) { 1065 + renderShapedTile(shapedTile, x, y, curveSineX, curveCosineX, curveSineY, curveCosineY) 1066 + } 1067 + val wall = tileBelow.wall 1068 + if (wall != null) { 1069 + wall.primary!!.renderAtPoint( 1070 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1071 + wall.x - cameraPosX, wall.z - cameraPosZ, wall.y - cameraPosY, 1072 + wall.uid 1073 + ) 1074 + } 1075 + for (i2 in 0 until tileBelow.entityCount) { 1076 + val interactiveObject = tileBelow.interactiveObjects[i2] 1077 + if (interactiveObject != null) { 1078 + interactiveObject.renderable?.renderAtPoint( 1079 + interactiveObject.rotation, curveSineY, curveCosineY, curveSineX, 1080 + curveCosineX, interactiveObject.worldX - cameraPosX, interactiveObject.worldZ - cameraPosZ, 1081 + interactiveObject.worldY - cameraPosY, interactiveObject.uid 1082 + ) 1083 + } 1084 + } 1085 + } 1086 + var flag1 = false 1087 + val groundPlainTile = groundTile.plainTile 1088 + val groundShapedTile = groundTile.shapedTile 1089 + if (groundPlainTile != null) { 1090 + if (!isTileOccluded(x, y, level)) { 1091 + flag1 = true 1092 + renderPlainTile(groundPlainTile, x, y, level, curveSineX, curveCosineX, curveSineY, curveCosineY) 1093 + } 1094 + } else if (groundShapedTile != null && !isTileOccluded(x, y, level)) { 1095 + flag1 = true 1096 + renderShapedTile(groundShapedTile, x, y, curveSineX, curveCosineX, curveSineY, curveCosineY) 1097 + } 1098 + var j1 = 0 1099 + var j2 = 0 1100 + val wallObject = groundTile.wall 1101 + val wallDecoration = groundTile.wallDecoration 1102 + if (wallObject != null || wallDecoration != null) { 1103 + if (cameraPositionTileX == x) { 1104 + j1++ 1105 + } else if (cameraPositionTileX < x) { 1106 + j1 += 2 1107 + } 1108 + if (cameraPositionTileY == y) { 1109 + j1 += 3 1110 + } else if (cameraPositionTileY > y) { 1111 + j1 += 6 1112 + } 1113 + j2 = WALL_DRAW_FLAGS_0[j1] 1114 + groundTile.wallDrawFlags = TILE_WALL_DRAW_FLAGS_1[j1] 1115 + } 1116 + if (wallObject != null) { 1117 + if ((wallObject.orientation and WALL_ORIENTATION_FLAGS[j1]) != 0) { 1118 + if (wallObject.orientation == 16) { 1119 + groundTile.wallCullDirection = 3 1120 + groundTile.wallUncullDirection = WALL_UNCULL_FLAGS_0[j1] 1121 + groundTile.wallCullOppositeDirection = 3 - groundTile.wallUncullDirection 1122 + } else if (wallObject.orientation == 32) { 1123 + groundTile.wallCullDirection = 6 1124 + groundTile.wallUncullDirection = WALL_UNCULL_FLAGS_1[j1] 1125 + groundTile.wallCullOppositeDirection = 6 - groundTile.wallUncullDirection 1126 + } else if (wallObject.orientation == 64) { 1127 + groundTile.wallCullDirection = 12 1128 + groundTile.wallUncullDirection = WALL_UNCULL_FLAGS_2[j1] 1129 + groundTile.wallCullOppositeDirection = 12 - groundTile.wallUncullDirection 1130 + } else { 1131 + groundTile.wallCullDirection = 9 1132 + groundTile.wallUncullDirection = WALL_UNCULL_FLAGS_3[j1] 1133 + groundTile.wallCullOppositeDirection = 9 - groundTile.wallUncullDirection 1134 + } 1135 + } else { 1136 + groundTile.wallCullDirection = 0 1137 + } 1138 + if ((wallObject.orientation and j2) != 0 && !isWallOccluded(x, y, level, wallObject.orientation)) { 1139 + wallObject.primary!!.renderAtPoint( 1140 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1141 + wallObject.x - cameraPosX, wallObject.z - cameraPosZ, 1142 + wallObject.y - cameraPosY, wallObject.uid 1143 + ) 1144 + } 1145 + if ((wallObject.orientation2 and j2) != 0 && !isWallOccluded(x, y, level, wallObject.orientation2)) { 1146 + wallObject.secondary!!.renderAtPoint( 1147 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1148 + wallObject.x - cameraPosX, wallObject.z - cameraPosZ, 1149 + wallObject.y - cameraPosY, wallObject.uid 1150 + ) 1151 + } 1152 + } 1153 + if (wallDecoration != null && !isOccluded(level, x, y, wallDecoration.renderable!!.modelHeight)) { 1154 + if ((wallDecoration.configBits and j2) != 0) { 1155 + wallDecoration.renderable!!.renderAtPoint( 1156 + wallDecoration.face, curveSineY, curveCosineY, curveSineX, 1157 + curveCosineX, wallDecoration.x - cameraPosX, wallDecoration.z - cameraPosZ, 1158 + wallDecoration.y - cameraPosY, wallDecoration.uid 1159 + ) 1160 + } else if ((wallDecoration.configBits and 0x300) != 0) { 1161 + val j4 = wallDecoration.x - cameraPosX 1162 + val l5 = wallDecoration.z - cameraPosZ 1163 + val k6 = wallDecoration.y - cameraPosY 1164 + val i8 = wallDecoration.face 1165 + val k9: Int 1166 + if (i8 == 1 || i8 == 2) { 1167 + k9 = -j4 1168 + } else { 1169 + k9 = j4 1170 + } 1171 + val k10: Int 1172 + if (i8 == 2 || i8 == 3) { 1173 + k10 = -k6 1174 + } else { 1175 + k10 = k6 1176 + } 1177 + if ((wallDecoration.configBits and 0x100) != 0 && k10 < k9) { 1178 + val i11 = j4 + faceOffsetX2[i8] 1179 + val k11 = k6 + faceOffsetY2[i8] 1180 + wallDecoration.renderable!!.renderAtPoint( 1181 + i8 * 512 + 256, curveSineY, curveCosineY, curveSineX, 1182 + curveCosineX, i11, l5, k11, wallDecoration.uid 1183 + ) 1184 + } 1185 + if ((wallDecoration.configBits and 0x200) != 0 && k10 > k9) { 1186 + val j11 = j4 + faceOffsetX3[i8] 1187 + val l11 = k6 + faceOffsetY3[i8] 1188 + wallDecoration.renderable!!.renderAtPoint( 1189 + (i8 * 512 + 1280) and 0x7ff, curveSineY, curveCosineY, 1190 + curveSineX, curveCosineX, j11, l5, l11, wallDecoration.uid 1191 + ) 1192 + } 1193 + } 1194 + } 1195 + if (flag1) { 1196 + val floorDecoration = groundTile.floorDecoration 1197 + if (floorDecoration != null) { 1198 + floorDecoration.renderable!!.renderAtPoint( 1199 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1200 + floorDecoration.x - cameraPosX, floorDecoration.z - cameraPosZ, floorDecoration.y - cameraPosY, 1201 + floorDecoration.uid 1202 + ) 1203 + } 1204 + val groundItemTile_1 = groundTile.groundItemTile 1205 + if (groundItemTile_1 != null && groundItemTile_1.heightOffset == 0) { 1206 + groundItemTile_1.secondGroundItem?.renderAtPoint( 1207 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1208 + groundItemTile_1.x - cameraPosX, groundItemTile_1.z - cameraPosZ, 1209 + groundItemTile_1.y - cameraPosY, groundItemTile_1.uid 1210 + ) 1211 + groundItemTile_1.thirdGroundItem?.renderAtPoint( 1212 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1213 + groundItemTile_1.x - cameraPosX, groundItemTile_1.z - cameraPosZ, 1214 + groundItemTile_1.y - cameraPosY, groundItemTile_1.uid 1215 + ) 1216 + groundItemTile_1.firstGroundItem?.renderAtPoint( 1217 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1218 + groundItemTile_1.x - cameraPosX, groundItemTile_1.z - cameraPosZ, 1219 + groundItemTile_1.y - cameraPosY, groundItemTile_1.uid 1220 + ) 1221 + } 1222 + } 1223 + val k4 = groundTile.interactiveObjectsSizeOR 1224 + if (k4 != 0) { 1225 + if (x < cameraPositionTileX && (k4 and 4) != 0) { 1226 + val tile = tileArray.getTile(z, x + 1, y) 1227 + if (tile != null && tile.visible) { 1228 + tileList!!.pushBack(tile) 1229 + } 1230 + } 1231 + if (y < cameraPositionTileY && (k4 and 2) != 0) { 1232 + val tile = tileArray.getTile(z, x, y + 1) 1233 + if (tile != null && tile.visible) { 1234 + tileList!!.pushBack(tile) 1235 + } 1236 + } 1237 + if (x > cameraPositionTileX && (k4 and 1) != 0) { 1238 + val tile = tileArray.getTile(z, x - 1, y) 1239 + if (tile != null && tile.visible) { 1240 + tileList!!.pushBack(tile) 1241 + } 1242 + } 1243 + if (y > cameraPositionTileY && (k4 and 8) != 0) { 1244 + val tile = tileArray.getTile(z, x, y - 1) 1245 + if (tile != null && tile.visible) { 1246 + tileList!!.pushBack(tile) 1247 + } 1248 + } 1249 + } 1250 + } 1251 + if (groundTile.wallCullDirection != 0) { 1252 + var flag2 = true 1253 + for (e in 0 until groundTile.entityCount) { 1254 + val obj = groundTile.interactiveObjects[e] 1255 + if (obj == null || obj.cycle == cycle || 1256 + (groundTile.sceneSpawnRequestsSize[e] and groundTile.wallCullDirection) != groundTile.wallUncullDirection 1257 + ) { 1258 + continue 1259 + } 1260 + flag2 = false 1261 + break 1262 + } 1263 + 1264 + if (flag2) { 1265 + val wall_1 = groundTile.wall!! 1266 + if (!isWallOccluded(x, y, level, wall_1.orientation)) { 1267 + wall_1.primary!!.renderAtPoint( 1268 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1269 + wall_1.x - cameraPosX, wall_1.z - cameraPosZ, 1270 + wall_1.y - cameraPosY, wall_1.uid 1271 + ) 1272 + } 1273 + groundTile.wallCullDirection = 0 1274 + } 1275 + } 1276 + if (groundTile.drawEntities) { 1277 + try { 1278 + val entityCount = groundTile.entityCount 1279 + groundTile.drawEntities = false 1280 + var l1 = 0 1281 + label0@ for (e in 0 until entityCount) { 1282 + val entity = groundTile.interactiveObjects[e] ?: continue 1283 + if (entity.cycle == cycle) { 1284 + continue 1285 + } 1286 + for (_x in entity.tileLeft..entity.tileRight) { 1287 + for (_y in entity.tileTop..entity.tileBottom) { 1288 + val tile = tileArray.getTile(z, _x, _y)!! 1289 + if (tile.draw) { 1290 + groundTile.drawEntities = true 1291 + } else { 1292 + if (tile.wallCullDirection == 0) { 1293 + continue 1294 + } 1295 + var l6 = 0 1296 + if (_x > entity.tileLeft) { 1297 + l6++ 1298 + } 1299 + if (_x < entity.tileRight) { 1300 + l6 += 4 1301 + } 1302 + if (_y > entity.tileTop) { 1303 + l6 += 8 1304 + } 1305 + if (_y < entity.tileBottom) { 1306 + l6 += 2 1307 + } 1308 + if ((l6 and tile.wallCullDirection) != groundTile.wallCullOppositeDirection) { 1309 + continue 1310 + } 1311 + groundTile.drawEntities = true 1312 + } 1313 + continue@label0 1314 + } 1315 + } 1316 + 1317 + interactiveObjects!![l1] = entity 1318 + l1++ 1319 + var i5 = cameraPositionTileX - entity.tileLeft 1320 + val i6 = entity.tileRight - cameraPositionTileX 1321 + if (i6 > i5) { 1322 + i5 = i6 1323 + } 1324 + val i7 = cameraPositionTileY - entity.tileTop 1325 + val j8 = entity.tileBottom - cameraPositionTileY 1326 + if (j8 > i7) { 1327 + entity.renderPriority = i5 + j8 1328 + } else { 1329 + entity.renderPriority = i5 + i7 1330 + } 1331 + } 1332 + 1333 + while (l1 > 0) { 1334 + var i3 = -50 1335 + var l3 = -1 1336 + for (j5 in 0 until l1) { 1337 + val entity = interactiveObjects!![j5]!! 1338 + if (entity.cycle != cycle) { 1339 + if (entity.renderPriority > i3) { 1340 + i3 = entity.renderPriority 1341 + l3 = j5 1342 + } else if (entity.renderPriority == i3) { 1343 + val j7 = entity.worldX - cameraPosX 1344 + val k8 = entity.worldY - cameraPosY 1345 + val l9 = interactiveObjects!![l3]!!.worldX - cameraPosX 1346 + val l10 = interactiveObjects!![l3]!!.worldY - cameraPosY 1347 + if (j7 * j7 + k8 * k8 > l9 * l9 + l10 * l10) { 1348 + l3 = j5 1349 + } 1350 + } 1351 + } 1352 + } 1353 + 1354 + if (l3 == -1) { 1355 + break 1356 + } 1357 + val entity = interactiveObjects!![l3]!! 1358 + entity.cycle = cycle 1359 + if (!isAreaOccluded( 1360 + entity.tileLeft, entity.tileRight, entity.tileTop, entity.tileBottom, level, 1361 + entity.renderable!!.modelHeight 1362 + ) 1363 + ) { 1364 + entity.renderable!!.renderAtPoint( 1365 + entity.rotation, curveSineY, curveCosineY, curveSineX, 1366 + curveCosineX, entity.worldX - cameraPosX, entity.worldZ - cameraPosZ, 1367 + entity.worldY - cameraPosY, entity.uid 1368 + ) 1369 + } 1370 + for (_x in entity.tileLeft..entity.tileRight) { 1371 + for (_y in entity.tileTop..entity.tileBottom) { 1372 + val tile = tileArray.getTile(z, _x, _y)!! 1373 + if (tile.wallCullDirection != 0) { 1374 + tileList!!.pushBack(tile) 1375 + } else if ((_x != x || _y != y) && tile.visible) { 1376 + tileList!!.pushBack(tile) 1377 + } 1378 + } 1379 + } 1380 + } 1381 + if (groundTile.drawEntities) { 1382 + continue 1383 + } 1384 + } catch (_ex: Exception) { 1385 + groundTile.drawEntities = false 1386 + } 1387 + } 1388 + if (!groundTile.visible || groundTile.wallCullDirection != 0) { 1389 + continue 1390 + } 1391 + if (x <= cameraPositionTileX && x > currentPositionX) { 1392 + val tile = tileArray.getTile(z, x - 1, y) 1393 + if (tile != null && tile.visible) { 1394 + continue 1395 + } 1396 + } 1397 + if (x >= cameraPositionTileX && x < mapBoundsX - 1) { 1398 + val tile = tileArray.getTile(z, x + 1, y) 1399 + if (tile != null && tile.visible) { 1400 + continue 1401 + } 1402 + } 1403 + if (y <= cameraPositionTileY && y > currentPositionY) { 1404 + val tile = tileArray.getTile(z, x, y - 1) 1405 + if (tile != null && tile.visible) { 1406 + continue 1407 + } 1408 + } 1409 + if (y >= cameraPositionTileY && y < mapBoundsY - 1) { 1410 + val tile = tileArray.getTile(z, x, y + 1) 1411 + if (tile != null && tile.visible) { 1412 + continue 1413 + } 1414 + } 1415 + groundTile.visible = false 1416 + deferredObjectCount-- 1417 + val groundItemTile = groundTile.groundItemTile 1418 + if (groundItemTile != null && groundItemTile.heightOffset != 0) { 1419 + groundItemTile.secondGroundItem?.renderAtPoint( 1420 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1421 + groundItemTile.x - cameraPosX, groundItemTile.z - cameraPosZ - groundItemTile.heightOffset, 1422 + groundItemTile.y - cameraPosY, groundItemTile.uid 1423 + ) 1424 + groundItemTile.thirdGroundItem?.renderAtPoint( 1425 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1426 + groundItemTile.x - cameraPosX, groundItemTile.z - cameraPosZ - groundItemTile.heightOffset, 1427 + groundItemTile.y - cameraPosY, groundItemTile.uid 1428 + ) 1429 + groundItemTile.firstGroundItem?.renderAtPoint( 1430 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1431 + groundItemTile.x - cameraPosX, groundItemTile.z - cameraPosZ - groundItemTile.heightOffset, 1432 + groundItemTile.y - cameraPosY, groundItemTile.uid 1433 + ) 1434 + } 1435 + if (groundTile.wallDrawFlags != 0) { 1436 + val wallDecoration = groundTile.wallDecoration 1437 + if (wallDecoration != null && !isOccluded(level, x, y, wallDecoration.renderable!!.modelHeight)) { 1438 + if ((wallDecoration.configBits and groundTile.wallDrawFlags) != 0) { 1439 + wallDecoration.renderable!!.renderAtPoint( 1440 + wallDecoration.face, curveSineY, curveCosineY, curveSineX, 1441 + curveCosineX, wallDecoration.x - cameraPosX, wallDecoration.z - cameraPosZ, 1442 + wallDecoration.y - cameraPosY, wallDecoration.uid 1443 + ) 1444 + } else if ((wallDecoration.configBits and 0x300) != 0) { 1445 + val l2 = wallDecoration.x - cameraPosX 1446 + val j3 = wallDecoration.z - cameraPosZ 1447 + val i4 = wallDecoration.y - cameraPosY 1448 + val k5 = wallDecoration.face 1449 + val j6: Int 1450 + if (k5 == 1 || k5 == 2) { 1451 + j6 = -l2 1452 + } else { 1453 + j6 = l2 1454 + } 1455 + val l7: Int 1456 + if (k5 == 2 || k5 == 3) { 1457 + l7 = -i4 1458 + } else { 1459 + l7 = i4 1460 + } 1461 + if ((wallDecoration.configBits and 0x100) != 0 && l7 >= j6) { 1462 + val i9 = l2 + faceOffsetX2[k5] 1463 + val i10 = i4 + faceOffsetY2[k5] 1464 + wallDecoration.renderable!!.renderAtPoint( 1465 + k5 * 512 + 256, curveSineY, curveCosineY, curveSineX, 1466 + curveCosineX, i9, j3, i10, wallDecoration.uid 1467 + ) 1468 + } 1469 + if ((wallDecoration.configBits and 0x200) != 0 && l7 <= j6) { 1470 + val j9 = l2 + faceOffsetX3[k5] 1471 + val j10 = i4 + faceOffsetY3[k5] 1472 + wallDecoration.renderable!!.renderAtPoint( 1473 + (k5 * 512 + 1280) and 0x7ff, curveSineY, curveCosineY, 1474 + curveSineX, curveCosineX, j9, j3, j10, wallDecoration.uid 1475 + ) 1476 + } 1477 + } 1478 + } 1479 + val wallObject = groundTile.wall 1480 + if (wallObject != null) { 1481 + if ((wallObject.orientation2 and groundTile.wallDrawFlags) != 0 && !isWallOccluded(x, y, level, wallObject.orientation2)) { 1482 + wallObject.secondary!!.renderAtPoint( 1483 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1484 + wallObject.x - cameraPosX, wallObject.z - cameraPosZ, 1485 + wallObject.y - cameraPosY, wallObject.uid 1486 + ) 1487 + } 1488 + if ((wallObject.orientation and groundTile.wallDrawFlags) != 0 && !isWallOccluded(x, y, level, wallObject.orientation)) { 1489 + wallObject.primary!!.renderAtPoint( 1490 + 0, curveSineY, curveCosineY, curveSineX, curveCosineX, 1491 + wallObject.x - cameraPosX, wallObject.z - cameraPosZ, 1492 + wallObject.y - cameraPosY, wallObject.uid 1493 + ) 1494 + } 1495 + } 1496 + } 1497 + if (z < mapSizeZ - 1) { 1498 + val tile = tileArray.getTile(z + 1, x, y) 1499 + if (tile != null && tile.visible) { 1500 + tileList!!.pushBack(tile) 1501 + } 1502 + } 1503 + if (x < cameraPositionTileX) { 1504 + val tile = tileArray.getTile(z, x + 1, y) 1505 + if (tile != null && tile.visible) { 1506 + tileList!!.pushBack(tile) 1507 + } 1508 + } 1509 + if (y < cameraPositionTileY) { 1510 + val tile = tileArray.getTile(z, x, y + 1) 1511 + if (tile != null && tile.visible) { 1512 + tileList!!.pushBack(tile) 1513 + } 1514 + } 1515 + if (x > cameraPositionTileX) { 1516 + val tile = tileArray.getTile(z, x - 1, y) 1517 + if (tile != null && tile.visible) { 1518 + tileList!!.pushBack(tile) 1519 + } 1520 + } 1521 + if (y > cameraPositionTileY) { 1522 + val tile = tileArray.getTile(z, x, y - 1) 1523 + if (tile != null && tile.visible) { 1524 + tileList!!.pushBack(tile) 1525 + } 1526 + } 1527 + } while (true) 1528 + } 1529 + 1530 + private fun renderPlainTile( 1531 + plainTile: GenericTile, tileX: Int, tileY: Int, tileZ: Int, 1532 + sinX: Int, cosineX: Int, sinY: Int, cosineY: Int 1533 + ) { 1534 + var xA = (tileX shl 7) - cameraPosX 1535 + var xC = xA 1536 + var yA = (tileY shl 7) - cameraPosY 1537 + var yB = yA 1538 + var xB = xA + 128 1539 + var xD = xB 1540 + var yD = yA + 128 1541 + var yC = yD 1542 + var zA = heightMap[tileZ][tileX][tileY] - cameraPosZ 1543 + var zB = heightMap[tileZ][tileX + 1][tileY] - cameraPosZ 1544 + var zC = heightMap[tileZ][tileX + 1][tileY + 1] - cameraPosZ 1545 + var zD = heightMap[tileZ][tileX][tileY + 1] - cameraPosZ 1546 + 1547 + var temp = (yA * sinX + xA * cosineX) shr 16 1548 + yA = (yA * cosineX - xA * sinX) shr 16 1549 + xA = temp 1550 + temp = (zA * cosineY - yA * sinY) shr 16 1551 + yA = (zA * sinY + yA * cosineY) shr 16 1552 + zA = temp 1553 + if (yA < 50) { 1554 + return 1555 + } 1556 + temp = (yB * sinX + xB * cosineX) shr 16 1557 + yB = (yB * cosineX - xB * sinX) shr 16 1558 + xB = temp 1559 + temp = (zB * cosineY - yB * sinY) shr 16 1560 + yB = (zB * sinY + yB * cosineY) shr 16 1561 + zB = temp 1562 + if (yB < 50) { 1563 + return 1564 + } 1565 + temp = (yD * sinX + xD * cosineX) shr 16 1566 + yD = (yD * cosineX - xD * sinX) shr 16 1567 + xD = temp 1568 + temp = (zC * cosineY - yD * sinY) shr 16 1569 + yD = (zC * sinY + yD * cosineY) shr 16 1570 + zC = temp 1571 + if (yD < 50) { 1572 + return 1573 + } 1574 + temp = (yC * sinX + xC * cosineX) shr 16 1575 + yC = (yC * cosineX - xC * sinX) shr 16 1576 + xC = temp 1577 + temp = (zD * cosineY - yC * sinY) shr 16 1578 + yC = (zD * sinY + yC * cosineY) shr 16 1579 + zD = temp 1580 + if (yC < 50) { 1581 + return 1582 + } 1583 + val screenXA = Rasterizer3D.center_x + ((xA shl 9) / yA) 1584 + val screenYA = Rasterizer3D.center_y + ((zA shl 9) / yA) 1585 + val screenXB = Rasterizer3D.center_x + ((xB shl 9) / yB) 1586 + val screenYB = Rasterizer3D.center_y + ((zB shl 9) / yB) 1587 + val screenXD = Rasterizer3D.center_x + ((xD shl 9) / yD) 1588 + val screenYD = Rasterizer3D.center_y + ((zC shl 9) / yD) 1589 + val screenXC = Rasterizer3D.center_x + ((xC shl 9) / yC) 1590 + val screenYC = Rasterizer3D.center_y + ((zD shl 9) / yC) 1591 + Rasterizer3D.alpha = 0 1592 + if ((screenXD - screenXC) * (screenYB - screenYC) - (screenYD - screenYC) * (screenXB - screenXC) > 0) { 1593 + Rasterizer3D.restrict_edges = screenXD < 0 || screenXC < 0 || screenXB < 0 || 1594 + screenXD > Rasterizer.viewportRx || 1595 + screenXC > Rasterizer.viewportRx || 1596 + screenXB > Rasterizer.viewportRx 1597 + if (clicked && isMouseWithinTriangle(clickX, clickY, screenYD, screenYC, screenYB, screenXD, screenXC, screenXB)) { 1598 + clickedTileX = tileX 1599 + clickedTileY = tileY 1600 + } 1601 + if (plainTile.texture == -1) { 1602 + if (plainTile.colourD != 0xbc614e) { 1603 + Rasterizer3D.drawShadedTriangle( 1604 + screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, 1605 + plainTile.colourD, plainTile.colourC, plainTile.colourB 1606 + ) 1607 + } 1608 + } else if (!lowMemory) { 1609 + if (plainTile.flat) { 1610 + Rasterizer3D.drawTexturedTriangle( 1611 + screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, 1612 + plainTile.colourD, plainTile.colourC, plainTile.colourB, 1613 + xA, xB, xC, zA, zB, zD, yA, yB, yC, plainTile.texture 1614 + ) 1615 + } else { 1616 + Rasterizer3D.drawTexturedTriangle( 1617 + screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, 1618 + plainTile.colourD, plainTile.colourC, plainTile.colourB, 1619 + xD, xC, xB, zC, zD, zB, yD, yC, yB, plainTile.texture 1620 + ) 1621 + } 1622 + } else { 1623 + val rgb = textureRGB[plainTile.texture] 1624 + Rasterizer3D.drawShadedTriangle( 1625 + screenYD, screenYC, screenYB, screenXD, screenXC, screenXB, 1626 + mixColours(rgb, plainTile.colourD), mixColours(rgb, plainTile.colourC), 1627 + mixColours(rgb, plainTile.colourB) 1628 + ) 1629 + } 1630 + } 1631 + if ((screenXA - screenXB) * (screenYC - screenYB) - (screenYA - screenYB) * (screenXC - screenXB) > 0) { 1632 + Rasterizer3D.restrict_edges = screenXA < 0 || screenXB < 0 || screenXC < 0 || 1633 + screenXA > Rasterizer.viewportRx || screenXB > Rasterizer.viewportRx || 1634 + screenXC > Rasterizer.viewportRx 1635 + if (clicked && isMouseWithinTriangle(clickX, clickY, screenYA, screenYB, screenYC, screenXA, screenXB, screenXC)) { 1636 + clickedTileX = tileX 1637 + clickedTileY = tileY 1638 + } 1639 + if (plainTile.texture == -1) { 1640 + if (plainTile.colourA != 0xbc614e) { 1641 + Rasterizer3D.drawShadedTriangle( 1642 + screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1643 + plainTile.colourA, plainTile.colourB, plainTile.colourC 1644 + ) 1645 + } 1646 + } else { 1647 + if (!lowMemory) { 1648 + Rasterizer3D.drawTexturedTriangle( 1649 + screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1650 + plainTile.colourA, plainTile.colourB, plainTile.colourC, 1651 + xA, xB, xC, zA, zB, zD, yA, yB, yC, plainTile.texture 1652 + ) 1653 + return 1654 + } 1655 + val rgb = textureRGB[plainTile.texture] 1656 + Rasterizer3D.drawShadedTriangle( 1657 + screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1658 + mixColours(rgb, plainTile.colourA), mixColours(rgb, plainTile.colourB), 1659 + mixColours(rgb, plainTile.colourC) 1660 + ) 1661 + } 1662 + } 1663 + } 1664 + 1665 + private fun renderShapedTile( 1666 + shapedTile: ComplexTile, tileX: Int, tileY: Int, 1667 + sineX: Int, cosineX: Int, sineY: Int, cosineY: Int 1668 + ) { 1669 + var triangleCount = shapedTile.originalVertexX.size 1670 + for (triangle in 0 until triangleCount) { 1671 + var viewspaceX = shapedTile.originalVertexX[triangle] - cameraPosX 1672 + var viewspaceY = shapedTile.originalVertexY[triangle] - cameraPosZ 1673 + var viewspaceZ = shapedTile.originalVertexZ[triangle] - cameraPosY 1674 + var temp = (viewspaceZ * sineX + viewspaceX * cosineX) shr 16 1675 + viewspaceZ = (viewspaceZ * cosineX - viewspaceX * sineX) shr 16 1676 + viewspaceX = temp 1677 + temp = (viewspaceY * cosineY - viewspaceZ * sineY) shr 16 1678 + viewspaceZ = (viewspaceY * sineY + viewspaceZ * cosineY) shr 16 1679 + viewspaceY = temp 1680 + if (viewspaceZ < 50) { 1681 + return 1682 + } 1683 + if (shapedTile.triangleTexture != null) { 1684 + ComplexTile.viewspaceX[triangle] = viewspaceX 1685 + ComplexTile.viewspaceY[triangle] = viewspaceY 1686 + ComplexTile.viewspaceZ[triangle] = viewspaceZ 1687 + } 1688 + ComplexTile.screenX[triangle] = Rasterizer3D.center_x + ((viewspaceX shl 9) / viewspaceZ) 1689 + ComplexTile.screenY[triangle] = Rasterizer3D.center_y + ((viewspaceY shl 9) / viewspaceZ) 1690 + } 1691 + 1692 + Rasterizer3D.alpha = 0 1693 + triangleCount = shapedTile.triangleA.size 1694 + for (tirangle in 0 until triangleCount) { 1695 + val a = shapedTile.triangleA[tirangle] 1696 + val b = shapedTile.triangleB[tirangle] 1697 + val c = shapedTile.triangleC[tirangle] 1698 + val screenXA = ComplexTile.screenX[a] 1699 + val screenXB = ComplexTile.screenX[b] 1700 + val screenXC = ComplexTile.screenX[c] 1701 + val screenYA = ComplexTile.screenY[a] 1702 + val screenYB = ComplexTile.screenY[b] 1703 + val screenYC = ComplexTile.screenY[c] 1704 + if ((screenXA - screenXB) * (screenYC - screenYB) - (screenYA - screenYB) * (screenXC - screenXB) > 0) { 1705 + Rasterizer3D.restrict_edges = screenXA < 0 || screenXB < 0 || screenXC < 0 || 1706 + screenXA > Rasterizer.viewportRx || screenXB > Rasterizer.viewportRx || 1707 + screenXC > Rasterizer.viewportRx 1708 + if (clicked && isMouseWithinTriangle(clickX, clickY, screenYA, screenYB, screenYC, screenXA, screenXB, screenXC)) { 1709 + clickedTileX = tileX 1710 + clickedTileY = tileY 1711 + } 1712 + val triTexture = shapedTile.triangleTexture 1713 + if (triTexture == null || triTexture[tirangle] == -1) { 1714 + if (shapedTile.triangleHSLA[tirangle] != 0xbc614e) { 1715 + Rasterizer3D.drawShadedTriangle( 1716 + screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1717 + shapedTile.triangleHSLA[tirangle], shapedTile.triangleHSLB[tirangle], 1718 + shapedTile.triangleHSLC[tirangle] 1719 + ) 1720 + } 1721 + } else if (!lowMemory) { 1722 + if (shapedTile.flat) { 1723 + Rasterizer3D.drawTexturedTriangle( 1724 + screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1725 + shapedTile.triangleHSLA[tirangle], shapedTile.triangleHSLB[tirangle], 1726 + shapedTile.triangleHSLC[tirangle], 1727 + ComplexTile.viewspaceX[0], ComplexTile.viewspaceX[1], ComplexTile.viewspaceX[3], 1728 + ComplexTile.viewspaceY[0], ComplexTile.viewspaceY[1], ComplexTile.viewspaceY[3], 1729 + ComplexTile.viewspaceZ[0], ComplexTile.viewspaceZ[1], ComplexTile.viewspaceZ[3], 1730 + triTexture[tirangle] 1731 + ) 1732 + } else { 1733 + Rasterizer3D.drawTexturedTriangle( 1734 + screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1735 + shapedTile.triangleHSLA[tirangle], shapedTile.triangleHSLB[tirangle], 1736 + shapedTile.triangleHSLC[tirangle], 1737 + ComplexTile.viewspaceX[a], ComplexTile.viewspaceX[b], ComplexTile.viewspaceX[c], 1738 + ComplexTile.viewspaceY[a], ComplexTile.viewspaceY[b], ComplexTile.viewspaceY[c], 1739 + ComplexTile.viewspaceZ[a], ComplexTile.viewspaceZ[b], ComplexTile.viewspaceZ[c], 1740 + triTexture[tirangle] 1741 + ) 1742 + } 1743 + } else { 1744 + val k5 = textureRGB[triTexture[tirangle]] 1745 + Rasterizer3D.drawShadedTriangle( 1746 + screenYA, screenYB, screenYC, screenXA, screenXB, screenXC, 1747 + mixColours(k5, shapedTile.triangleHSLA[tirangle]), 1748 + mixColours(k5, shapedTile.triangleHSLB[tirangle]), 1749 + mixColours(k5, shapedTile.triangleHSLC[tirangle]) 1750 + ) 1751 + } 1752 + } 1753 + } 1754 + } 1755 + 1756 + private fun mixColours(colourA: Int, colourB: Int): Int { 1757 + @Suppress("NAME_SHADOWING") 1758 + var colourB = colourB 1759 + colourB = 127 - colourB 1760 + colourB = (colourB * (colourA and 0x7f)) / 160 1761 + if (colourB < 2) { 1762 + colourB = 2 1763 + } else if (colourB > 126) { 1764 + colourB = 126 1765 + } 1766 + return (colourA and 0xff80.toInt()) + colourB 1767 + } 1768 + 1769 + private fun isMouseWithinTriangle( 1770 + mouseX: Int, mouseY: Int, pointAY: Int, pointBY: Int, pointCY: Int, 1771 + pointAX: Int, pointBX: Int, pointCX: Int 1772 + ): Boolean { 1773 + if (mouseY < pointAY && mouseY < pointBY && mouseY < pointCY) { 1774 + return false 1775 + } 1776 + if (mouseY > pointAY && mouseY > pointBY && mouseY > pointCY) { 1777 + return false 1778 + } 1779 + if (mouseX < pointAX && mouseX < pointBX && mouseX < pointCX) { 1780 + return false 1781 + } 1782 + if (mouseX > pointAX && mouseX > pointBX && mouseX > pointCX) { 1783 + return false 1784 + } 1785 + val b1 = (mouseY - pointAY) * (pointBX - pointAX) - (mouseX - pointAX) * (pointBY - pointAY) 1786 + val b2 = (mouseY - pointCY) * (pointAX - pointCX) - (mouseX - pointCX) * (pointAY - pointCY) 1787 + val b3 = (mouseY - pointBY) * (pointCX - pointBX) - (mouseX - pointBX) * (pointCY - pointBY) 1788 + return b1 * b3 > 0 && b3 * b2 > 0 1789 + } 1790 + 1791 + private fun processCulling() { 1792 + val clusterCount = cullingClusterPointer!![plane] 1793 + val clusters = cullingClusters!![plane] 1794 + processedCullingClustersPointer = 0 1795 + for (c in 0 until clusterCount) { 1796 + val cluster = clusters[c]!! 1797 + if (cluster.searchMask == 1) { 1798 + val distanceFromCameraStartX = (cluster.tileStartX - cameraPositionTileX) + 25 1799 + if (distanceFromCameraStartX < 0 || distanceFromCameraStartX > 50) { 1800 + continue 1801 + } 1802 + var distanceFromCameraStartY = (cluster.tileStartY - cameraPositionTileY) + 25 1803 + if (distanceFromCameraStartY < 0) { 1804 + distanceFromCameraStartY = 0 1805 + } 1806 + var localCameraPositionTileY = (cluster.tileEndY - cameraPositionTileY) + 25 1807 + if (localCameraPositionTileY > 50) { 1808 + localCameraPositionTileY = 50 1809 + } 1810 + var visible = false 1811 + while (distanceFromCameraStartY <= localCameraPositionTileY) { 1812 + if (TILE_VISIBILITY_MAP!![distanceFromCameraStartX][distanceFromCameraStartY]) { 1813 + visible = true 1814 + break 1815 + } 1816 + distanceFromCameraStartY++ 1817 + } 1818 + if (!visible) { 1819 + continue 1820 + } 1821 + var realDistanceFromCameraStartX = cameraPosX - cluster.worldStartX 1822 + if (realDistanceFromCameraStartX > 32) { 1823 + cluster.tileDistanceEnum = 1 1824 + } else { 1825 + if (realDistanceFromCameraStartX >= -32) { 1826 + continue 1827 + } 1828 + cluster.tileDistanceEnum = 2 1829 + realDistanceFromCameraStartX = -realDistanceFromCameraStartX 1830 + } 1831 + cluster.worldDistanceFromCameraStartY = ((cluster.worldStartY - cameraPosY) shl 8) / realDistanceFromCameraStartX 1832 + cluster.worldDistanceFromCameraEndY = ((cluster.worldEndY - cameraPosY) shl 8) / realDistanceFromCameraStartX 1833 + cluster.worldDistanceFromCameraStartZ = ((cluster.worldEndZ - cameraPosZ) shl 8) / realDistanceFromCameraStartX 1834 + cluster.worldDistanceFromCameraEndZ = ((cluster.worldStartZ - cameraPosZ) shl 8) / realDistanceFromCameraStartX 1835 + processedCullingClusters!![processedCullingClustersPointer++] = cluster 1836 + continue 1837 + } 1838 + if (cluster.searchMask == 2) { 1839 + val distanceFromCameraStartY = (cluster.tileStartY - cameraPositionTileY) + 25 1840 + if (distanceFromCameraStartY < 0 || distanceFromCameraStartY > 50) { 1841 + continue 1842 + } 1843 + var distanceFromCameraStartX = (cluster.tileStartX - cameraPositionTileX) + 25 1844 + if (distanceFromCameraStartX < 0) { 1845 + distanceFromCameraStartX = 0 1846 + } 1847 + var distanceFromCameraEndX = (cluster.tileEndX - cameraPositionTileX) + 25 1848 + if (distanceFromCameraEndX > 50) { 1849 + distanceFromCameraEndX = 50 1850 + } 1851 + var visible = false 1852 + while (distanceFromCameraStartX <= distanceFromCameraEndX) { 1853 + if (TILE_VISIBILITY_MAP!![distanceFromCameraStartX][distanceFromCameraStartY]) { 1854 + visible = true 1855 + break 1856 + } 1857 + distanceFromCameraStartX++ 1858 + } 1859 + if (!visible) { 1860 + continue 1861 + } 1862 + var realDistanceFromCameraStartY = cameraPosY - cluster.worldStartY 1863 + if (realDistanceFromCameraStartY > 32) { 1864 + cluster.tileDistanceEnum = 3 1865 + } else { 1866 + if (realDistanceFromCameraStartY >= -32) { 1867 + continue 1868 + } 1869 + cluster.tileDistanceEnum = 4 1870 + realDistanceFromCameraStartY = -realDistanceFromCameraStartY 1871 + } 1872 + cluster.worldDistanceFromCameraStartX = ((cluster.worldStartX - cameraPosX) shl 8) / realDistanceFromCameraStartY 1873 + cluster.worldDistanceFromCameraEndX = ((cluster.worldEndX - cameraPosX) shl 8) / realDistanceFromCameraStartY 1874 + cluster.worldDistanceFromCameraStartZ = ((cluster.worldEndZ - cameraPosZ) shl 8) / realDistanceFromCameraStartY 1875 + cluster.worldDistanceFromCameraEndZ = ((cluster.worldStartZ - cameraPosZ) shl 8) / realDistanceFromCameraStartY 1876 + processedCullingClusters!![processedCullingClustersPointer++] = cluster 1877 + } else if (cluster.searchMask == 4) { 1878 + val realDistanceFromCameraStartZ = cluster.worldEndZ - cameraPosZ 1879 + if (realDistanceFromCameraStartZ > 128) { 1880 + var distanceFromCameraStartY = (cluster.tileStartY - cameraPositionTileY) + 25 1881 + if (distanceFromCameraStartY < 0) { 1882 + distanceFromCameraStartY = 0 1883 + } 1884 + var distanceFromCameraEndY = (cluster.tileEndY - cameraPositionTileY) + 25 1885 + if (distanceFromCameraEndY > 50) { 1886 + distanceFromCameraEndY = 50 1887 + } 1888 + if (distanceFromCameraStartY <= distanceFromCameraEndY) { 1889 + var distanceFromCameraStartX = (cluster.tileStartX - cameraPositionTileX) + 25 1890 + if (distanceFromCameraStartX < 0) { 1891 + distanceFromCameraStartX = 0 1892 + } 1893 + var distanceFromCameraEndX = (cluster.tileEndX - cameraPositionTileX) + 25 1894 + if (distanceFromCameraEndX > 50) { 1895 + distanceFromCameraEndX = 50 1896 + } 1897 + var visible = false 1898 + label0@ for (x in distanceFromCameraStartX..distanceFromCameraEndX) { 1899 + for (y in distanceFromCameraStartY..distanceFromCameraEndY) { 1900 + if (!TILE_VISIBILITY_MAP!![x][y]) { 1901 + continue 1902 + } 1903 + visible = true 1904 + break@label0 1905 + } 1906 + } 1907 + 1908 + if (visible) { 1909 + cluster.tileDistanceEnum = 5 1910 + cluster.worldDistanceFromCameraStartX = ((cluster.worldStartX - cameraPosX) shl 8) / realDistanceFromCameraStartZ 1911 + cluster.worldDistanceFromCameraEndX = ((cluster.worldEndX - cameraPosX) shl 8) / realDistanceFromCameraStartZ 1912 + cluster.worldDistanceFromCameraStartY = ((cluster.worldStartY - cameraPosY) shl 8) / realDistanceFromCameraStartZ 1913 + cluster.worldDistanceFromCameraEndY = ((cluster.worldEndY - cameraPosY) shl 8) / realDistanceFromCameraStartZ 1914 + processedCullingClusters!![processedCullingClustersPointer++] = cluster 1915 + } 1916 + } 1917 + } 1918 + } 1919 + } 1920 + } 1921 + 1922 + private fun isTileOccluded(x: Int, y: Int, z: Int): Boolean { 1923 + val l = tileRenderCycle[z][x][y] 1924 + if (l == -cycle) { 1925 + return false 1926 + } 1927 + if (l == cycle) { 1928 + return true 1929 + } 1930 + val worldX = x shl 7 1931 + val worldY = y shl 7 1932 + if (method291(worldX + 1, worldY + 1, heightMap[z][x][y]) && 1933 + method291((worldX + 128) - 1, worldY + 1, heightMap[z][x + 1][y]) && 1934 + method291((worldX + 128) - 1, (worldY + 128) - 1, heightMap[z][x + 1][y + 1]) && 1935 + method291(worldX + 1, (worldY + 128) - 1, heightMap[z][x][y + 1]) 1936 + ) { 1937 + tileRenderCycle[z][x][y] = cycle 1938 + return true 1939 + } else { 1940 + tileRenderCycle[z][x][y] = -cycle 1941 + return false 1942 + } 1943 + } 1944 + 1945 + private fun isWallOccluded(x: Int, y: Int, level: Int, wallType: Int): Boolean { 1946 + if (!isTileOccluded(x, y, level)) { 1947 + return false 1948 + } 1949 + val posX = x shl 7 1950 + val posY = y shl 7 1951 + val posZ = heightMap[level][x][y] - 1 1952 + val z1 = posZ - 120 1953 + val z2 = posZ - 230 1954 + val z3 = posZ - 238 1955 + if (wallType < 16) { 1956 + if (wallType == 1) { 1957 + if (posX > cameraPosX) { 1958 + if (!method291(posX, posY, posZ)) { 1959 + return false 1960 + } 1961 + if (!method291(posX, posY + 128, posZ)) { 1962 + return false 1963 + } 1964 + } 1965 + if (level > 0) { 1966 + if (!method291(posX, posY, z1)) { 1967 + return false 1968 + } 1969 + if (!method291(posX, posY + 128, z1)) { 1970 + return false 1971 + } 1972 + } 1973 + if (!method291(posX, posY, z2)) { 1974 + return false 1975 + } 1976 + return method291(posX, posY + 128, z2) 1977 + } 1978 + if (wallType == 2) { 1979 + if (posY < cameraPosY) { 1980 + if (!method291(posX, posY + 128, posZ)) { 1981 + return false 1982 + } 1983 + if (!method291(posX + 128, posY + 128, posZ)) { 1984 + return false 1985 + } 1986 + } 1987 + if (level > 0) { 1988 + if (!method291(posX, posY + 128, z1)) { 1989 + return false 1990 + } 1991 + if (!method291(posX + 128, posY + 128, z1)) { 1992 + return false 1993 + } 1994 + } 1995 + if (!method291(posX, posY + 128, z2)) { 1996 + return false 1997 + } 1998 + return method291(posX + 128, posY + 128, z2) 1999 + } 2000 + if (wallType == 4) { 2001 + if (posX < cameraPosX) { 2002 + if (!method291(posX + 128, posY, posZ)) { 2003 + return false 2004 + } 2005 + if (!method291(posX + 128, posY + 128, posZ)) { 2006 + return false 2007 + } 2008 + } 2009 + if (level > 0) { 2010 + if (!method291(posX + 128, posY, z1)) { 2011 + return false 2012 + } 2013 + if (!method291(posX + 128, posY + 128, z1)) { 2014 + return false 2015 + } 2016 + } 2017 + if (!method291(posX + 128, posY, z2)) { 2018 + return false 2019 + } 2020 + return method291(posX + 128, posY + 128, z2) 2021 + } 2022 + if (wallType == 8) { 2023 + if (posY > cameraPosY) { 2024 + if (!method291(posX, posY, posZ)) { 2025 + return false 2026 + } 2027 + if (!method291(posX + 128, posY, posZ)) { 2028 + return false 2029 + } 2030 + } 2031 + if (level > 0) { 2032 + if (!method291(posX, posY, z1)) { 2033 + return false 2034 + } 2035 + if (!method291(posX + 128, posY, z1)) { 2036 + return false 2037 + } 2038 + } 2039 + if (!method291(posX, posY, z2)) { 2040 + return false 2041 + } 2042 + return method291(posX + 128, posY, z2) 2043 + } 2044 + } 2045 + if (!method291(posX + 64, posY + 64, z3)) { 2046 + return false 2047 + } 2048 + if (wallType == 16) { 2049 + return method291(posX, posY + 128, z2) 2050 + } 2051 + if (wallType == 32) { 2052 + return method291(posX + 128, posY + 128, z2) 2053 + } 2054 + if (wallType == 64) { 2055 + return method291(posX + 128, posY, z2) 2056 + } 2057 + if (wallType == 128) { 2058 + return method291(posX, posY, z2) 2059 + } else { 2060 + println("Warning unsupported wall type") 2061 + return true 2062 + } 2063 + } 2064 + 2065 + private fun isOccluded(i: Int, j: Int, k: Int, l: Int): Boolean { 2066 + if (!isTileOccluded(j, k, i)) { 2067 + return false 2068 + } 2069 + val i1 = j shl 7 2070 + val j1 = k shl 7 2071 + return method291(i1 + 1, j1 + 1, heightMap[i][j][k] - l) && 2072 + method291((i1 + 128) - 1, j1 + 1, heightMap[i][j + 1][k] - l) && 2073 + method291((i1 + 128) - 1, (j1 + 128) - 1, heightMap[i][j + 1][k + 1] - l) && 2074 + method291(i1 + 1, (j1 + 128) - 1, heightMap[i][j][k + 1] - l) 2075 + } 2076 + 2077 + private fun isAreaOccluded(minimumX: Int, maximumX: Int, minimumY: Int, maximumY: Int, z: Int, offsetZ: Int): Boolean { 2078 + if (minimumX == maximumX && minimumY == maximumY) { 2079 + if (!isTileOccluded(minimumX, minimumY, z)) { 2080 + return false 2081 + } 2082 + val _x = minimumX shl 7 2083 + val _y = minimumY shl 7 2084 + return method291(_x + 1, _y + 1, heightMap[z][minimumX][minimumY] - offsetZ) && 2085 + method291((_x + 128) - 1, _y + 1, heightMap[z][minimumX + 1][minimumY] - offsetZ) && 2086 + method291((_x + 128) - 1, (_y + 128) - 1, heightMap[z][minimumX + 1][minimumY + 1] - offsetZ) && 2087 + method291(_x + 1, (_y + 128) - 1, heightMap[z][minimumX][minimumY + 1] - offsetZ) 2088 + } 2089 + for (x in minimumX..maximumX) { 2090 + for (y in minimumY..maximumY) { 2091 + if (tileRenderCycle[z][x][y] == -cycle) { 2092 + return false 2093 + } 2094 + } 2095 + } 2096 + 2097 + val _x = (minimumX shl 7) + 1 2098 + val _y = (minimumY shl 7) + 2 2099 + val _z = heightMap[z][minimumX][minimumY] - offsetZ 2100 + if (!method291(_x, _y, _z)) { 2101 + return false 2102 + } 2103 + val j3 = (maximumX shl 7) - 1 2104 + if (!method291(j3, _y, _z)) { 2105 + return false 2106 + } 2107 + val k3 = (maximumY shl 7) - 1 2108 + if (!method291(_x, k3, _z)) { 2109 + return false 2110 + } 2111 + return method291(j3, k3, _z) 2112 + } 2113 + 2114 + private fun method291(posX: Int, posY: Int, posZ: Int): Boolean { 2115 + for (c in 0 until processedCullingClustersPointer) { 2116 + val cluster = processedCullingClusters!![c]!! 2117 + if (cluster.tileDistanceEnum == 1) { 2118 + val i1 = cluster.worldStartX - posX 2119 + if (i1 > 0) { 2120 + val j2 = cluster.worldStartY + ((cluster.worldDistanceFromCameraStartY * i1) shr 8) 2121 + val k3 = cluster.worldEndY + ((cluster.worldDistanceFromCameraEndY * i1) shr 8) 2122 + val l4 = cluster.worldEndZ + ((cluster.worldDistanceFromCameraStartZ * i1) shr 8) 2123 + val i6 = cluster.worldStartZ + ((cluster.worldDistanceFromCameraEndZ * i1) shr 8) 2124 + if (posY >= j2 && posY <= k3 && posZ >= l4 && posZ <= i6) { 2125 + return true 2126 + } 2127 + } 2128 + } else if (cluster.tileDistanceEnum == 2) { 2129 + val j1 = posX - cluster.worldStartX 2130 + if (j1 > 0) { 2131 + val k2 = cluster.worldStartY + ((cluster.worldDistanceFromCameraStartY * j1) shr 8) 2132 + val l3 = cluster.worldEndY + ((cluster.worldDistanceFromCameraEndY * j1) shr 8) 2133 + val i5 = cluster.worldEndZ + ((cluster.worldDistanceFromCameraStartZ * j1) shr 8) 2134 + val j6 = cluster.worldStartZ + ((cluster.worldDistanceFromCameraEndZ * j1) shr 8) 2135 + if (posY >= k2 && posY <= l3 && posZ >= i5 && posZ <= j6) { 2136 + return true 2137 + } 2138 + } 2139 + } else if (cluster.tileDistanceEnum == 3) { 2140 + val k1 = cluster.worldStartY - posY 2141 + if (k1 > 0) { 2142 + val l2 = cluster.worldStartX + ((cluster.worldDistanceFromCameraStartX * k1) shr 8) 2143 + val i4 = cluster.worldEndX + ((cluster.worldDistanceFromCameraEndX * k1) shr 8) 2144 + val j5 = cluster.worldEndZ + ((cluster.worldDistanceFromCameraStartZ * k1) shr 8) 2145 + val k6 = cluster.worldStartZ + ((cluster.worldDistanceFromCameraEndZ * k1) shr 8) 2146 + if (posX >= l2 && posX <= i4 && posZ >= j5 && posZ <= k6) { 2147 + return true 2148 + } 2149 + } 2150 + } else if (cluster.tileDistanceEnum == 4) { 2151 + val l1 = posY - cluster.worldStartY 2152 + if (l1 > 0) { 2153 + val i3 = cluster.worldStartX + ((cluster.worldDistanceFromCameraStartX * l1) shr 8) 2154 + val j4 = cluster.worldEndX + ((cluster.worldDistanceFromCameraEndX * l1) shr 8) 2155 + val k5 = cluster.worldEndZ + ((cluster.worldDistanceFromCameraStartZ * l1) shr 8) 2156 + val l6 = cluster.worldStartZ + ((cluster.worldDistanceFromCameraEndZ * l1) shr 8) 2157 + if (posX >= i3 && posX <= j4 && posZ >= k5 && posZ <= l6) { 2158 + return true 2159 + } 2160 + } 2161 + } else if (cluster.tileDistanceEnum == 5) { 2162 + val i2 = posZ - cluster.worldEndZ 2163 + if (i2 > 0) { 2164 + val j3 = cluster.worldStartX + ((cluster.worldDistanceFromCameraStartX * i2) shr 8) 2165 + val k4 = cluster.worldEndX + ((cluster.worldDistanceFromCameraEndX * i2) shr 8) 2166 + val l5 = cluster.worldStartY + ((cluster.worldDistanceFromCameraStartY * i2) shr 8) 2167 + val i7 = cluster.worldEndY + ((cluster.worldDistanceFromCameraEndY * i2) shr 8) 2168 + if (posX >= j3 && posX <= k4 && posY >= l5 && posY <= i7) { 2169 + return true 2170 + } 2171 + } 2172 + } 2173 + } 2174 + return false 2175 + } 2176 + 2177 + companion object { 2178 + @JvmField var lowMemory: Boolean = true 2179 + 2180 + @JvmStatic var deferredObjectCount: Int = 0 2181 + @JvmStatic var plane: Int = 0 2182 + @JvmStatic var cycle: Int = 0 2183 + @JvmStatic var currentPositionX: Int = 0 2184 + @JvmStatic var mapBoundsX: Int = 0 2185 + @JvmStatic var currentPositionY: Int = 0 2186 + @JvmStatic var mapBoundsY: Int = 0 2187 + @JvmStatic var cameraPositionTileX: Int = 0 2188 + @JvmStatic var cameraPositionTileY: Int = 0 2189 + @JvmStatic var cameraPosX: Int = 0 2190 + @JvmStatic var cameraPosZ: Int = 0 2191 + @JvmStatic var cameraPosY: Int = 0 2192 + @JvmStatic var curveSineY: Int = 0 2193 + @JvmStatic var curveCosineY: Int = 0 2194 + @JvmStatic var curveSineX: Int = 0 2195 + @JvmStatic var curveCosineX: Int = 0 2196 + @JvmField var interactiveObjects: Array<InteractiveObject?>? = arrayOfNulls(100) 2197 + @JvmField val faceOffsetX2: IntArray = intArrayOf(53, -53, -53, 53) 2198 + @JvmField val faceOffsetY2: IntArray = intArrayOf(-53, -53, 53, 53) 2199 + @JvmField val faceOffsetX3: IntArray = intArrayOf(-45, 45, 45, -45) 2200 + @JvmField val faceOffsetY3: IntArray = intArrayOf(45, 45, -45, -45) 2201 + @JvmStatic var clicked: Boolean = false 2202 + @JvmStatic var clickX: Int = 0 2203 + @JvmStatic var clickY: Int = 0 2204 + @JvmField var clickedTileX: Int = -1 2205 + @JvmField var clickedTileY: Int = -1 2206 + @JvmStatic var CULLING_PLANES: Int = 4 2207 + @JvmField var cullingClusterPointer: IntArray? = IntArray(CULLING_PLANES) 2208 + @JvmField var cullingClusters: Array<Array<SceneCluster?>>? = Array(CULLING_PLANES) { arrayOfNulls(500) } 2209 + @JvmStatic var processedCullingClustersPointer: Int = 0 2210 + @JvmField var processedCullingClusters: Array<SceneCluster?>? = arrayOfNulls(500) 2211 + @JvmField var tileList: LinkedList? = LinkedList() 2212 + @JvmField val WALL_DRAW_FLAGS_0: IntArray = intArrayOf(19, 55, 38, 155, 255, 110, 137, 205, 76) 2213 + @JvmField val WALL_ORIENTATION_FLAGS: IntArray = intArrayOf(160, 192, 80, 96, 0, 144, 80, 48, 160) 2214 + @JvmField val TILE_WALL_DRAW_FLAGS_1: IntArray = intArrayOf(76, 8, 137, 4, 0, 1, 38, 2, 19) 2215 + @JvmField val WALL_UNCULL_FLAGS_0: IntArray = intArrayOf(0, 0, 2, 0, 0, 2, 1, 1, 0) 2216 + @JvmField val WALL_UNCULL_FLAGS_1: IntArray = intArrayOf(2, 0, 0, 2, 0, 0, 0, 4, 4) 2217 + @JvmField val WALL_UNCULL_FLAGS_2: IntArray = intArrayOf(0, 4, 4, 8, 0, 0, 8, 0, 0) 2218 + @JvmField val WALL_UNCULL_FLAGS_3: IntArray = intArrayOf(1, 1, 0, 0, 0, 8, 0, 0, 8) 2219 + @JvmField val textureRGB: IntArray = intArrayOf( 2220 + 41, 39248, 41, 4643, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 43086, 2221 + 41, 41, 41, 41, 41, 41, 41, 8602, 41, 28992, 41, 41, 41, 41, 41, 5056, 2222 + 41, 41, 41, 7079, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 3131, 41, 41, 41 2223 + ) 2224 + @JvmField var TILE_VISIBILITY_MAPS: Array<Array<Array<BooleanArray>>>? = Array(8) { Array(32) { Array(51) { BooleanArray(51) } } } 2225 + @JvmField var TILE_VISIBILITY_MAP: Array<BooleanArray>? = null 2226 + @JvmStatic var screenCenterX: Int = 0 2227 + @JvmStatic var screenCenterY: Int = 0 2228 + @JvmStatic var screenMinX: Int = 0 2229 + @JvmStatic var screenMinY: Int = 0 2230 + @JvmStatic var screenMaxX: Int = 0 2231 + @JvmStatic var screenMaxY: Int = 0 2232 + 2233 + @JvmStatic 2234 + fun nullLoader() { 2235 + interactiveObjects = null 2236 + cullingClusterPointer = null 2237 + cullingClusters = null 2238 + tileList = null 2239 + TILE_VISIBILITY_MAPS = null 2240 + TILE_VISIBILITY_MAP = null 2241 + } 2242 + 2243 + @JvmStatic 2244 + fun createCullingCluster( 2245 + z: Int, highestX: Int, lowestX: Int, highestY: Int, lowestY: Int, 2246 + highestZ: Int, lowestZ: Int, searchMask: Int 2247 + ) { 2248 + val scenecluster = SceneCluster() 2249 + scenecluster.tileStartX = lowestX / 128 2250 + scenecluster.tileEndX = highestX / 128 2251 + scenecluster.tileStartY = lowestY / 128 2252 + scenecluster.tileEndY = highestY / 128 2253 + scenecluster.searchMask = searchMask 2254 + scenecluster.worldStartX = lowestX 2255 + scenecluster.worldEndX = highestX 2256 + scenecluster.worldStartY = lowestY 2257 + scenecluster.worldEndY = highestY 2258 + scenecluster.worldEndZ = highestZ 2259 + scenecluster.worldStartZ = lowestZ 2260 + cullingClusters!![z][cullingClusterPointer!![z]] = scenecluster 2261 + cullingClusterPointer!![z]++ 2262 + } 2263 + 2264 + @JvmStatic 2265 + fun method277(l: Int, k: Int, i1: Int, i: Int, ai: IntArray) { 2266 + screenMinX = 0 2267 + screenMinY = 0 2268 + screenMaxX = i1 2269 + screenMaxY = i 2270 + screenCenterX = i1 / 2 2271 + screenCenterY = i / 2 2272 + val aflag = Array(9) { Array(32) { Array(53) { BooleanArray(53) } } } 2273 + var j1 = 128 2274 + while (j1 <= 384) { 2275 + var k1 = 0 2276 + while (k1 < 2048) { 2277 + curveSineY = Model.SINE!![j1] 2278 + curveCosineY = Model.COSINE!![j1] 2279 + curveSineX = Model.SINE!![k1] 2280 + curveCosineX = Model.COSINE!![k1] 2281 + val i2 = (j1 - 128) / 32 2282 + val k2 = k1 / 64 2283 + for (i3 in -26..26) { 2284 + for (k3 in -26..26) { 2285 + val l3 = i3 * 128 2286 + val j4 = k3 * 128 2287 + var flag1 = false 2288 + var l4 = -l 2289 + while (l4 <= k) { 2290 + if (!method278(j4, l3, ai[i2] + l4)) { 2291 + l4 += 128 2292 + continue 2293 + } 2294 + flag1 = true 2295 + break 2296 + } 2297 + aflag[i2][k2][i3 + 25 + 1][k3 + 25 + 1] = flag1 2298 + } 2299 + } 2300 + k1 += 64 2301 + } 2302 + j1 += 32 2303 + } 2304 + 2305 + for (l1 in 0 until 8) { 2306 + for (j2 in 0 until 32) { 2307 + for (l2 in -25 until 25) { 2308 + for (j3 in -25 until 25) { 2309 + var flag = false 2310 + label0@ for (i4 in -1..1) { 2311 + for (k4 in -1..1) { 2312 + if (aflag[l1][j2][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 2313 + flag = true 2314 + } else if (aflag[l1][(j2 + 1) % 31][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 2315 + flag = true 2316 + } else if (aflag[l1 + 1][j2][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 2317 + flag = true 2318 + } else { 2319 + if (!aflag[l1 + 1][(j2 + 1) % 31][l2 + i4 + 25 + 1][j3 + k4 + 25 + 1]) { 2320 + continue 2321 + } 2322 + flag = true 2323 + } 2324 + break@label0 2325 + } 2326 + } 2327 + TILE_VISIBILITY_MAPS!![l1][j2][l2 + 25][j3 + 25] = flag 2328 + } 2329 + } 2330 + } 2331 + } 2332 + } 2333 + 2334 + @JvmStatic 2335 + private fun method278(i: Int, j: Int, l: Int): Boolean { 2336 + val i1 = (i * curveSineX + j * curveCosineX) shr 16 2337 + val j1 = (i * curveCosineX - j * curveSineX) shr 16 2338 + val k1 = (l * curveSineY + j1 * curveCosineY) shr 16 2339 + val l1 = (l * curveCosineY - j1 * curveSineY) shr 16 2340 + if (k1 < 50 || k1 > 3500) { 2341 + return false 2342 + } 2343 + val i2 = screenCenterX + ((i1 shl 9) / k1) 2344 + val j2 = screenCenterY + ((l1 shl 9) / k1) 2345 + return i2 >= screenMinX && i2 <= screenMaxX && j2 >= screenMinY && j2 <= screenMaxY 2346 + } 2347 + } 2348 + }