From a1500a7cb116c626fd72830e1655132534017ece Mon Sep 17 00:00:00 2001 From: thedaneeffect Date: Thu, 5 Jan 2023 17:15:18 -0500 Subject: [PATCH] Scene --- src/main/java/Game.java | 109 ++-- src/main/java/LocType.java | 12 +- src/main/java/MapUtil.java | 67 ++ src/main/java/PathingEntity.java | 2 +- src/main/java/Scene.java | 726 +++++++++++---------- src/main/java/SceneBuilder.java | 844 +++++++++++++------------ src/main/java/SceneTile.java | 30 +- src/main/java/SceneWallDecoration.java | 4 +- src/main/java/SeqType.java | 2 +- src/main/java/ZoneUtil.java | 67 -- 10 files changed, 995 insertions(+), 868 deletions(-) create mode 100644 src/main/java/MapUtil.java delete mode 100644 src/main/java/ZoneUtil.java diff --git a/src/main/java/Game.java b/src/main/java/Game.java index e5cc5e1..3489a5d 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -650,6 +650,8 @@ public class Game extends GameShell { public String loginMessage1 = ""; public int baseX; public int baseZ; + public int bytesIn; + public int bytesOut; public BitmapFont fontPlain11; public BitmapFont fontPlain12; public BitmapFont fontBold12; @@ -1709,7 +1711,7 @@ public class Game extends GameShell { Draw3D.clearTexels(); clearCaches(); - scene.clear(); + scene.reset(); for (int i = 0; i < 4; i++) { levelCollisionMap[i].reset(); @@ -1805,8 +1807,8 @@ public class Game extends GameShell { if (chunk == -1) { continue; } - int i9 = (chunk >> 24) & 3; - int l9 = (chunk >> 1) & 3; + int mapLevel = (chunk >> 24) & 3; + int chunkRotation = (chunk >> 1) & 3; int mapX = (chunk >> 14) & 0x3ff; int mapZ = (chunk >> 3) & 0x7ff; int mapID = ((mapX / 8) << 8) + (mapZ / 8); @@ -1814,7 +1816,7 @@ public class Game extends GameShell { if ((sceneMapIndex[i] != mapID) || (sceneMapLandData[i] == null)) { continue; } - builder.method179(i9, l9, levelCollisionMap, x * 8, (mapX & 7) * 8, sceneMapLandData[i], (mapZ & 7) * 8, level, z * 8); + builder.readChunkTiles(levelCollisionMap, sceneMapLandData[i], (mapX & 7) * 8, (mapZ & 7) * 8, mapLevel, chunkRotation, x * 8, z * 8, level); break; } } @@ -1825,7 +1827,7 @@ public class Game extends GameShell { for (int chunkZ = 0; chunkZ < 13; chunkZ++) { int bitset = levelChunkBitset[0][chunkX][chunkZ]; if (bitset == -1) { - builder.method174(chunkZ * 8, 8, 8, chunkX * 8); + builder.stitchHeightmap(chunkX * 8, chunkZ * 8, 8, 8); } } } @@ -1835,20 +1837,20 @@ public class Game extends GameShell { for (int level = 0; level < 4; level++) { for (int chunkX = 0; chunkX < 13; chunkX++) { for (int chunkZ = 0; chunkZ < 13; chunkZ++) { - int bitset = levelChunkBitset[level][chunkX][chunkZ]; - if (bitset == -1) { + int chunkBitset = levelChunkBitset[level][chunkX][chunkZ]; + if (chunkBitset == -1) { continue; } - int k10 = (bitset >> 24) & 3; - int i11 = (bitset >> 1) & 3; - int mapX = (bitset >> 14) & 0x3ff; - int mapZ = (bitset >> 3) & 0x7ff; + int mapLevel = (chunkBitset >> 24) & 3; + int mapRotation = (chunkBitset >> 1) & 3; + int mapX = (chunkBitset >> 14) & 0x3ff; + int mapZ = (chunkBitset >> 3) & 0x7ff; int mapID = ((mapX / 8) << 8) + (mapZ / 8); - for (int k12 = 0; k12 < sceneMapIndex.length; k12++) { - if ((sceneMapIndex[k12] != mapID) || (sceneMapLocData[k12] == null)) { + for (int i = 0; i < sceneMapIndex.length; i++) { + if ((sceneMapIndex[i] != mapID) || (sceneMapLocData[i] == null)) { continue; } - builder.method183(levelCollisionMap, scene, k10, chunkX * 8, (mapZ & 7) * 8, level, sceneMapLocData[k12], (mapX & 7) * 8, i11, chunkZ * 8); + builder.readChunkLocs(levelCollisionMap, scene, mapLevel, mapRotation, (mapX & 7) * 8, (mapZ & 7) * 8, chunkX * 8, chunkZ * 8, sceneMapLocData[i], level); break; } } @@ -1865,7 +1867,7 @@ public class Game extends GameShell { if (data != null) { int originX = ((sceneMapIndex[i] >> 8) * 64) - sceneBaseTileX; int originZ = ((sceneMapIndex[i] & 0xff) * 64) - sceneBaseTileZ; - builder.method180(data, originZ, originX, (sceneCenterZoneX - 6) * 8, (sceneCenterZoneZ - 6) * 8, levelCollisionMap); + builder.readTiles(data, originZ, originX, (sceneCenterZoneX - 6) * 8, (sceneCenterZoneZ - 6) * 8, levelCollisionMap); } } @@ -1874,7 +1876,7 @@ public class Game extends GameShell { if ((data == null) && (sceneCenterZoneZ < 800)) { int originX = ((sceneMapIndex[i] >> 8) * 64) - sceneBaseTileX; int originZ = ((sceneMapIndex[i] & 0xff) * 64) - sceneBaseTileZ; - builder.method174(originZ, 64, 64, originX); + builder.stitchHeightmap(originX, originZ, 64, 64); } } @@ -1885,7 +1887,7 @@ public class Game extends GameShell { if (data != null) { int originX = ((sceneMapIndex[i] >> 8) * 64) - sceneBaseTileX; int originZ = ((sceneMapIndex[i] & 0xff) * 64) - sceneBaseTileZ; - builder.method190(originX, levelCollisionMap, originZ, scene, data); + builder.readLocs(levelCollisionMap, scene, originX, originZ, data); } } } @@ -2068,7 +2070,7 @@ public class Game extends GameShell { bitset += 0x80000000; } - scene.addTemporary(npc, currentLevel, npc.x, npc.z, getHeightmapY(currentLevel, npc.x, npc.z), npc.yaw, bitset, npc.needsForwardDrawPadding, ((npc.size - 1) * 64) + 60); + scene.pushTemporary(npc, currentLevel, npc.x, npc.z, getHeightmapY(currentLevel, npc.x, npc.z), npc.yaw, bitset, npc.needsForwardDrawPadding, ((npc.size - 1) * 64) + 60); } } @@ -3111,7 +3113,7 @@ public class Game extends GameShell { username = ""; password = ""; clearCaches(); - scene.clear(); + scene.reset(); for (int i = 0; i < 4; i++) { levelCollisionMap[i].reset(); } @@ -3220,7 +3222,7 @@ public class Game extends GameShell { if ((player.locModel != null) && (loopCycle >= player.locStartCycle) && (loopCycle < player.locStopCycle)) { player.lowmem = false; player.y = getHeightmapY(currentLevel, player.x, player.z); - scene.addTemporary(player, currentLevel, player.minSceneTileX, player.minSceneTileZ, player.maxSceneTileX, player.maxSceneTileZ, player.x, player.z, player.y, player.yaw, index); + scene.pushTemporary(player, currentLevel, player.minSceneTileX, player.minSceneTileZ, player.maxSceneTileX, player.maxSceneTileZ, player.x, player.z, player.y, player.yaw, index); continue; } @@ -3232,7 +3234,7 @@ public class Game extends GameShell { } player.y = getHeightmapY(currentLevel, player.x, player.z); - scene.addTemporary(player, currentLevel, player.x, player.z, player.y, player.yaw, index, player.needsForwardDrawPadding, 60); + scene.pushTemporary(player, currentLevel, player.x, player.z, player.y, player.yaw, index, player.needsForwardDrawPadding, 60); } } @@ -3585,9 +3587,9 @@ public class Game extends GameShell { if (type.mapsceneIcon != -1) { Image8 icon = imageMapscene[type.mapsceneIcon]; if (icon != null) { - int offsetX = ((type.width * 4) - icon.width) / 2; - int offsetY = ((type.length * 4) - icon.height) / 2; - icon.blit(48 + (tileX * 4) + offsetX, 48 + ((104 - tileZ - type.length) * 4) + offsetY); + int offsetX = ((type.sizeX * 4) - icon.width) / 2; + int offsetY = ((type.sizeZ * 4) - icon.height) / 2; + icon.blit(48 + (tileX * 4) + offsetX, 48 + ((104 - tileZ - type.sizeZ) * 4) + offsetY); } } else { if ((kind == 0) || (kind == 2)) { @@ -3663,9 +3665,9 @@ public class Game extends GameShell { Image8 icon = imageMapscene[type.mapsceneIcon]; if (icon != null) { - int offsetX = ((type.width * 4) - icon.width) / 2; - int offsetY = ((type.length * 4) - icon.height) / 2; - icon.blit(48 + (tileX * 4) + offsetX, 48 + ((104 - tileZ - type.length) * 4) + offsetY); + int offsetX = ((type.sizeX * 4) - icon.width) / 2; + int offsetY = ((type.sizeZ * 4) - icon.height) / 2; + icon.blit(48 + (tileX * 4) + offsetX, 48 + ((104 - tileZ - type.sizeZ) * 4) + offsetY); } } else if (kind == 9) { int rgb = 0xEEEEEE; @@ -3701,9 +3703,9 @@ public class Game extends GameShell { Image8 icon = imageMapscene[type.mapsceneIcon]; if (icon != null) { - int offsetX = ((type.width * 4) - icon.width) / 2; - int offsetY = ((type.length * 4) - icon.height) / 2; - icon.blit(48 + (tileX * 4) + offsetX, 48 + ((104 - tileZ - type.length) * 4) + offsetY); + int offsetX = ((type.sizeX * 4) - icon.width) / 2; + int offsetY = ((type.sizeZ * 4) - icon.height) / 2; + icon.blit(48 + (tileX * 4) + offsetX, 48 + ((104 - tileZ - type.sizeZ) * 4) + offsetY); } } } @@ -3889,7 +3891,7 @@ public class Game extends GameShell { } } proj.update(delta); - scene.addTemporary(proj, currentLevel, (int) proj.x, (int) proj.z, (int) proj.y, proj.yaw, -1, false, 60); + scene.pushTemporary(proj, currentLevel, (int) proj.x, (int) proj.z, (int) proj.y, proj.yaw, -1, false, 60); } } } @@ -4238,6 +4240,8 @@ public class Game extends GameShell { } try { + bytesOut+=out.position; + if ((connection != null) && (out.position > 0)) { connection.write(out.data, 0, out.position); out.position = 0; @@ -4579,11 +4583,11 @@ public class Game extends GameShell { int width; int length; if ((angle == 0) || (angle == 2)) { - width = loc.width; - length = loc.length; + width = loc.sizeX; + length = loc.sizeZ; } else { - width = loc.length; - length = loc.width; + width = loc.sizeZ; + length = loc.sizeX; } int interactionFlags = loc.interactionSideFlags; if (angle != 0) { @@ -8774,7 +8778,7 @@ public class Game extends GameShell { if (anim.seqComplete) { anim.unlink(); } else { - scene.addTemporary(anim, anim.level, anim.x, anim.z, anim.y, 0, -1, false, 60); + scene.pushTemporary(anim, anim.level, anim.x, anim.z, anim.y, 0, -1, false, 60); } } } @@ -9374,7 +9378,7 @@ public class Game extends GameShell { color = 0xff0000; } - fontPlain11.drawStringRight(String.format("Fps: %d", super.fps), x, y, color); + fontPlain11.drawStringRight(String.format("%d fps", super.fps), x, y, color); y += 13; double ft = 0; @@ -9383,23 +9387,27 @@ public class Game extends GameShell { } ft /= super.frameTime.length; - fontPlain11.drawStringRight(String.format("%04.4fms", ft), x, y, color); + fontPlain11.drawStringRight(String.format("%04.4f ms", ft), x, y, color); y += 13; Runtime runtime = Runtime.getRuntime(); int mem = (int) ((runtime.totalMemory() - runtime.freeMemory()) / 1024L); - fontPlain11.drawStringRight("Mem: " + mem + "k", x, y, 0xffff00); + fontPlain11.drawStringRight(mem + " kB", x, y, 0xffff00); y += 13; - fontPlain11.drawStringRight("Occluders: " + Scene.levelOccluderCount[Scene.topLevel] + ", active: " + Scene.activeOccluderCount, x, y, 0xFFFF00); + fontPlain11.drawStringRight(bytesIn + " bytes in", x, y, 0xffff00); y += 13; - fontPlain11.drawStringRight("Active wall occluders: " + Scene.activeWallOccluderCount, x, y, 0xFFFF00); + fontPlain11.drawStringRight(bytesOut + " bytes out", x, y, 0xffff00); y += 13; - fontPlain11.drawStringRight("Active ground occluders: " + Scene.activeGroundOccluderCount, x, y, 0xFFFF00); + if ((loopCycle % 50) == 0) { + bytesIn = 0; + bytesOut = 0; + } + + fontPlain11.drawStringRight(String.format("%d/%d occluders",Scene.activeOccluderCount,Scene.levelOccluderCount[Scene.topLevel]), x, y, 0xFFFF00); y += 13; - fontPlain11.drawStringRight("Tiles culled: " + Scene.tilesCulled, x, y, 0xFFFF00); } } @@ -10771,12 +10779,12 @@ public class Game extends GameShell { player.locStartCycle = delay + loopCycle; player.locStopCycle = duration + loopCycle; player.locModel = model; - int sizeX = type.width; - int sizeZ = type.length; + int sizeX = type.sizeX; + int sizeZ = type.sizeZ; if ((rotation == 1) || (rotation == 3)) { - sizeX = type.length; - sizeZ = type.width; + sizeX = type.sizeZ; + sizeZ = type.sizeX; } player.locOffsetX = (x * 128) + (sizeX * 64); @@ -11100,12 +11108,12 @@ public class Game extends GameShell { scene.removeLoc(level, x, z); LocType type = LocType.get(otherID); - if (((x + type.width) > 103) || ((z + type.width) > 103) || ((x + type.length) > 103) || ((z + type.length) > 103)) { + if (((x + type.sizeX) > 103) || ((z + type.sizeX) > 103) || ((x + type.sizeZ) > 103) || ((z + type.sizeZ) > 103)) { return; } if (type.solid) { - levelCollisionMap[level].remove(otherRotation, type.width, x, z, type.length, type.blocksProjectiles); + levelCollisionMap[level].remove(otherRotation, type.sizeX, x, z, type.sizeZ, type.blocksProjectiles); } } @@ -11206,6 +11214,7 @@ public class Game extends GameShell { packetType = (packetType - randomIn.nextInt()) & 0xff; } packetSize = PacketIn.SIZE[packetType]; + bytesIn++; available--; } @@ -11224,6 +11233,7 @@ public class Game extends GameShell { connection.read(in.data, 0, 2); in.position = 0; packetSize = in.read16U(); + bytesIn += 2; available -= 2; } else { return false; @@ -11241,6 +11251,7 @@ public class Game extends GameShell { lastPacketType2 = lastPacketType1; lastPacketType1 = lastPacketType0; lastPacketType0 = packetType; + bytesIn += packetSize; switch (packetType) { case PacketIn.SYNC_PLAYERS: diff --git a/src/main/java/LocType.java b/src/main/java/LocType.java index fafb2bb..33b54e6 100644 --- a/src/main/java/LocType.java +++ b/src/main/java/LocType.java @@ -73,7 +73,7 @@ public class LocType { public String name; public int scaleY; public byte lightAttenuation; - public int width; + public int sizeX; public int translateY; public int mapfunctionIcon; public int[] dstColor; @@ -85,7 +85,7 @@ public class LocType { public int mapsceneIcon; public int[] overrideTypeIDs; public int supportsObj; - public int length; + public int sizeZ; public boolean adjustToTerrain; public boolean occludes; public boolean decorative; @@ -121,8 +121,8 @@ public class LocType { description = null; srcColor = null; dstColor = null; - width = 1; - length = 1; + sizeX = 1; + sizeZ = 1; solid = true; blocksProjectiles = true; interactable = false; @@ -421,9 +421,9 @@ public class LocType { } } } else if (j == 14) { - width = buffer.read8U(); + sizeX = buffer.read8U(); } else if (j == 15) { - length = buffer.read8U(); + sizeZ = buffer.read8U(); } else if (j == 17) { solid = false; } else if (j == 18) { diff --git a/src/main/java/MapUtil.java b/src/main/java/MapUtil.java new file mode 100644 index 0000000..eded028 --- /dev/null +++ b/src/main/java/MapUtil.java @@ -0,0 +1,67 @@ +// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov. +// Jad home page: http://www.kpdus.com/jad.html +// Decompiler options: packimports(3) + +public class MapUtil { + + public static int rotateX(int x, int z, int rotation) { + rotation &= 3; + if (rotation == 0) { + return x; + } + if (rotation == 1) { + return z; + } + if (rotation == 2) { + return 7 - x; + } else { + return 7 - z; + } + } + + public static int rotateZ(int x, int z, int rotation) { + rotation &= 3; + if (rotation == 0) { + return z; + } + if (rotation == 1) { + return 7 - x; + } + if (rotation == 2) { + return 7 - z; + } else { + return x; + } + } + + public static int rotateLocX(int x, int z, int sizeX, int sizeZ, int rotation) { + rotation &= 3; + if (rotation == 0) { + return x; + } + if (rotation == 1) { + return z; + } + if (rotation == 2) { + return 7 - x - (sizeX - 1); + } else { + return 7 - z - (sizeZ - 1); + } + } + + public static int rotateLocZ(int x, int z, int sizeX, int sizeZ, int rotation) { + rotation &= 3; + if (rotation == 0) { + return z; + } + if (rotation == 1) { + return 7 - x - (sizeX - 1); + } + if (rotation == 2) { + return 7 - z - (sizeZ - 1); + } else { + return x; + } + } + +} diff --git a/src/main/java/PathingEntity.java b/src/main/java/PathingEntity.java index a5d97b5..8136a12 100644 --- a/src/main/java/PathingEntity.java +++ b/src/main/java/PathingEntity.java @@ -44,7 +44,7 @@ public class PathingEntity extends Entity { public int targetTileZ; public int size = 1; /** - * Passed to {@link Scene#addTemporary(Entity, int, int, int, int, int, int, boolean, int)} to provide an additional + * Passed to {@link Scene#pushTemporary(Entity, int, int, int, int, int, int, boolean, int)} to provide an additional * tile worth of draw padding ahead of this entity for things like animations that extend past the normal boundary. */ public boolean needsForwardDrawPadding = false; diff --git a/src/main/java/Scene.java b/src/main/java/Scene.java index 5ca851b..92c9fbf 100644 --- a/src/main/java/Scene.java +++ b/src/main/java/Scene.java @@ -6,30 +6,40 @@ import java.util.Arrays; public class Scene { - public static final int[] anIntArray463 = {53, -53, -53, 53}; - public static final int[] anIntArray464 = {-53, -53, 53, 53}; + public static final int[] DIAGONAL_WALL_DECORATION_ROTATION_OFFSET_X = {53, -53, -53, 53}; + public static final int[] DIAGONAL_WALL_DECORATION_ROTATION_OFFSET_Z = {-53, -53, 53, 53}; public static final int[] anIntArray465 = {-45, 45, 45, -45}; public static final int[] anIntArray466 = {45, 45, -45, -45}; /** * Occlusion flags for walls of kind 0, 2 and decorations 4, 5, */ - public static final int[] ROTATION_WALL_TYPE = {1, 2, 4, 8}; + public static final int[] ROTATION_WALL_TYPE = { + 1 << 0, + 1 << 1, + 1 << 2, + 1 << 3, + }; /** * Occlusion flags for walls of type 1 and 3. */ - public static final int[] ROTATION_WALL_CORNER_TYPE = {16, 32, 64, 128}; - public static final int[] anIntArray478 = { + public static final int[] ROTATION_WALL_CORNER_TYPE = { + 1 << 4, + 1 << 5, + 1 << 6, + 1 << 7, + }; + public static final int[] DIRECTION_ALLOW_WALL_TYPE_PRIMARY = { 0b00010011, // eyeTileX > tileX && eyeTileZ < tileZ 0b00110111, // eyeTileX == tileX && eyeTileZ < tileZ 0b00100110, // eyeTileX < tileX && eyeTileZ < tileZ 0b10011011, // eyeTileX > tileX && eyeTileZ == tileZ - 0b11111111, // eyeTileX = tileX && eyeTileZ == tileZ + 0b11111111, // eyeTileX == tileX && eyeTileZ == tileZ 0b01101110, // eyeTileX < tileX && eyeTileZ == tileZ 0b10001001, // eyeTileX > tileX && eyeTileZ > tileZ 0b11001101, // eyeTileX = tileX && eyeTileZ > tileZ 0b01001100, // eyeTileX < tileX && eyeTileZ > tileZ }; - public static final int[] anIntArray479 = { + public static final int[] DIRECTION_ALLOW_WALL_CORNER_TYPE = { 0b10100000, // eyeTileX > tileX && eyeTileZ < tileZ 0b11000000, // eyeTileX == tileX && eyeTileZ < tileZ 0b01010000, // eyeTileX < tileX && eyeTileZ < tileZ @@ -40,7 +50,7 @@ public class Scene { 0b00110000, // eyeTileX = tileX && eyeTileZ > tileZ 0b10100000, // eyeTileX < tileX && eyeTileZ > tileZ }; - public static final int[] anIntArray480 = { + public static final int[] DIRECTION_ALLOW_WALL_TYPE_SECONDARY = { 0b01001100, // eyeTileX > tileX && eyeTileZ < tileZ 0b00001000, // eyeTileX == tileX && eyeTileZ < tileZ 0b10001001, // eyeTileX < tileX && eyeTileZ < tileZ @@ -51,35 +61,55 @@ public class Scene { 0b00000010, // eyeTileX = tileX && eyeTileZ > tileZ 0b00010011, // eyeTileX < tileX && eyeTileZ > tileZ }; - public static final int[] anIntArray481 = { - 0b000, // eyeTileX > tileX && eyeTileZ < tileZ - 0b000, // eyeTileX == tileX && eyeTileZ < tileZ - 0b010, // eyeTileX < tileX && eyeTileZ < tileZ - 0b000, // eyeTileX > tileX && eyeTileZ == tileZ - 0b000, // eyeTileX = tileX && eyeTileZ == tileZ - 0b010, // eyeTileX < tileX && eyeTileZ == tileZ - 0b001, // eyeTileX > tileX && eyeTileZ > tileZ - 0b001, // eyeTileX = tileX && eyeTileZ > tileZ - 0b000, // eyeTileX < tileX && eyeTileZ > tileZ + public static final int[] WALL_CORNER_TYPE_16_BLOCK_LOC_SPANS = { + 0b0000, // eyeTileX > tileX && eyeTileZ < tileZ + 0b0000, // eyeTileX == tileX && eyeTileZ < tileZ + 0b0010, // eyeTileX < tileX && eyeTileZ < tileZ + 0b0000, // eyeTileX > tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX = tileX && eyeTileZ == tileZ + 0b0010, // eyeTileX < tileX && eyeTileZ == tileZ + 0b0001, // eyeTileX > tileX && eyeTileZ > tileZ + 0b0001, // eyeTileX = tileX && eyeTileZ > tileZ + 0b0000, // eyeTileX < tileX && eyeTileZ > tileZ }; - public static final int[] anIntArray482 = { - 0b010, // eyeTileX > tileX && eyeTileZ < tileZ - 0b000, // eyeTileX == tileX && eyeTileZ < tileZ - 0b000, // eyeTileX < tileX && eyeTileZ < tileZ - 0b010, // eyeTileX > tileX && eyeTileZ == tileZ - 0b000, // eyeTileX = tileX && eyeTileZ == tileZ - 0b000, // eyeTileX < tileX && eyeTileZ == tileZ - 0b000, // eyeTileX > tileX && eyeTileZ > tileZ - 0b100, // eyeTileX = tileX && eyeTileZ > tileZ - 0b100, // eyeTileX < tileX && eyeTileZ > tileZ + public static final int[] WALL_CORNER_TYPE_32_BLOCK_LOC_SPANS = { + 0b0010, // eyeTileX > tileX && eyeTileZ < tileZ + 0b0000, // eyeTileX == tileX && eyeTileZ < tileZ + 0b0000, // eyeTileX < tileX && eyeTileZ < tileZ + 0b0010, // eyeTileX > tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX = tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX < tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX > tileX && eyeTileZ > tileZ + 0b0100, // eyeTileX = tileX && eyeTileZ > tileZ + 0b0100, // eyeTileX < tileX && eyeTileZ > tileZ + }; + public static final int[] WALL_CORNER_TYPE_64_BLOCK_LOC_SPANS = { + 0b0000, // eyeTileX > tileX && eyeTileZ < tileZ + 0b0100, // eyeTileX == tileX && eyeTileZ < tileZ + 0b0100, // eyeTileX < tileX && eyeTileZ < tileZ + 0b1000, // eyeTileX > tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX = tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX < tileX && eyeTileZ == tileZ + 0b1000, // eyeTileX > tileX && eyeTileZ > tileZ + 0b0000, // eyeTileX = tileX && eyeTileZ > tileZ + 0b0000, // eyeTileX < tileX && eyeTileZ > tileZ + }; + public static final int[] WALL_CORNER_TYPE_128_BLOCK_LOC_SPANS = { + 0b0001, // eyeTileX > tileX && eyeTileZ < tileZ + 0b0001, // eyeTileX == tileX && eyeTileZ < tileZ + 0b0000, // eyeTileX < tileX && eyeTileZ < tileZ + 0b0000, // eyeTileX > tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX = tileX && eyeTileZ == tileZ + 0b1000, // eyeTileX < tileX && eyeTileZ == tileZ + 0b0000, // eyeTileX > tileX && eyeTileZ > tileZ + 0b0000, // eyeTileX = tileX && eyeTileZ > tileZ + 0b1000, // eyeTileX < tileX && eyeTileZ > tileZ }; - public static final int[] anIntArray483 = {0, 4, 4, 8, 0, 0, 8, 0, 0}; - public static final int[] anIntArray484 = {1, 1, 0, 0, 0, 8, 0, 0, 8}; public static final int[] TEXTURE_HSL = {41, 39248, 41, 4643, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 43086, 41, 41, 41, 41, 41, 41, 41, 8602, 41, 28992, 41, 41, 41, 41, 41, 5056, 41, 41, 41, 7079, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 3131, 41, 41, 41}; public static final int LEVEL_COUNT = 4; public static final SceneOccluder[] activeOccluders = new SceneOccluder[500]; public static boolean lowmem = true; - public static int anInt446; + public static int tilesRemaining; public static int topLevel; public static int cycle; public static int minDrawTileX; @@ -95,6 +125,9 @@ public class Scene { public static int cosEyePitch; public static int sinEyeYaw; public static int cosEyeYaw; + /** + * Used to track locs being sorted for drawing on a per-tile basis. + */ public static SceneLoc[] locBuffer = new SceneLoc[100]; public static boolean takingInput; public static int mouseX; @@ -261,10 +294,10 @@ public class Scene { levelTiles = new SceneTile[maxLevel][maxTileX][maxTileZ]; levelTileOcclusionCycles = new int[maxLevel][maxTileX + 1][maxTileZ + 1]; this.levelHeightmaps = levelHeightmaps; - clear(); + reset(); } - public void clear() { + public void reset() { for (int level = 0; level < maxLevel; level++) { for (int stx = 0; stx < maxTileX; stx++) { for (int stz = 0; stz < maxTileZ; stz++) { @@ -309,7 +342,7 @@ public class Scene { continue; } - above.dataLevel--; + above.level--; for (int i = 0; i < above.locCount; i++) { SceneLoc loc = above.locs[i]; @@ -436,7 +469,7 @@ public class Scene { levelTiles[level][tileX][tileZ].wall = wall; } - public void setWallDecoration(int occlude, Entity entity, int level, int tileX, int tileZ, int y, int yaw, int offsetX, int offsetZ, int bitset, byte info) { + public void setWallDecoration(int type, Entity entity, int level, int tileX, int tileZ, int y, int yaw, int offsetX, int offsetZ, int bitset, byte info) { if (entity == null) { return; } @@ -447,8 +480,8 @@ public class Scene { deco.z = (tileZ * 128) + 64 + offsetZ; deco.y = y; deco.entity = entity; - deco.occlude = occlude; - deco.yaw = yaw; + deco.type = type; + deco.rotation = yaw; for (int p = level; p >= 0; p--) { if (levelTiles[p][tileX][tileZ] == null) { levelTiles[p][tileX][tileZ] = new SceneTile(p, tileX, tileZ); @@ -457,17 +490,17 @@ public class Scene { levelTiles[level][tileX][tileZ].wallDecoration = deco; } - public boolean add(Entity entity, int level, int tileX, int tileZ, int y, int width, int length, int yaw, int bitset, byte info) { + public boolean push(Entity entity, int level, int tileX, int tileZ, int y, int width, int length, int yaw, int bitset, byte info) { if (entity == null) { return true; } else { int sceneX = (tileX * 128) + (64 * width); int sceneZ = (tileZ * 128) + (64 * length); - return add(entity, level, tileX, tileZ, width, length, sceneX, sceneZ, y, yaw, bitset, info, false); + return push(entity, level, tileX, tileZ, width, length, sceneX, sceneZ, y, yaw, bitset, info, false); } } - public boolean addTemporary(Entity entity, int level, int x, int z, int y, int yaw, int bitset, boolean forwardPadding, int padding) { + public boolean pushTemporary(Entity entity, int level, int x, int z, int y, int yaw, int bitset, boolean forwardPadding, int padding) { if (entity == null) { return true; } @@ -496,18 +529,18 @@ public class Scene { z0 /= 128; x1 /= 128; z1 /= 128; - return add(entity, level, x0, z0, (x1 - x0) + 1, (z1 - z0) + 1, x, z, y, yaw, bitset, (byte) 0, true); + return push(entity, level, x0, z0, (x1 - x0) + 1, (z1 - z0) + 1, x, z, y, yaw, bitset, (byte) 0, true); } - public boolean addTemporary(Entity entity, int level, int minTileX, int minTileZ, int maxTileX, int maxTileZ, int x, int z, int y, int yaw, int bitset) { + public boolean pushTemporary(Entity entity, int level, int minTileX, int minTileZ, int maxTileX, int maxTileZ, int x, int z, int y, int yaw, int bitset) { if (entity == null) { return true; } else { - return add(entity, level, minTileX, minTileZ, (maxTileX - minTileX) + 1, (maxTileZ - minTileZ) + 1, x, z, y, yaw, bitset, (byte) 0, true); + return push(entity, level, minTileX, minTileZ, (maxTileX - minTileX) + 1, (maxTileZ - minTileZ) + 1, x, z, y, yaw, bitset, (byte) 0, true); } } - public boolean add(Entity entity, int level, int tileX, int tileZ, int tileSizeX, int tileSizeZ, int x, int z, int y, int yaw, int bitset, byte info, boolean temporary) { + public boolean push(Entity entity, int level, int tileX, int tileZ, int tileSizeX, int tileSizeZ, int x, int z, int y, int yaw, int bitset, byte info, boolean temporary) { for (int tx = tileX; tx < (tileX + tileSizeX); tx++) { for (int tz = tileZ; tz < (tileZ + tileSizeZ); tz++) { if ((tx < 0) || (tz < 0) || (tx >= maxTileX) || (tz >= maxTileZ)) { @@ -538,19 +571,19 @@ public class Scene { int spans = 0; if (tx > tileX) { - spans++; + spans |= 0b0001; } if (tx < ((tileX + tileSizeX) - 1)) { - spans += 4; + spans |= 0b0100; } if (tz > tileZ) { - spans += 8; + spans |= 0b1000; } if (tz < ((tileZ + tileSizeZ) - 1)) { - spans += 2; + spans |= 0b0010; } for (int p = level; p >= 0; p--) { @@ -562,7 +595,7 @@ public class Scene { SceneTile tile = levelTiles[level][tx][tz]; tile.locs[tile.locCount] = loc; tile.locSpan[tile.locCount] = spans; - tile.spans |= spans; + tile.locSpans |= spans; tile.locCount++; } } @@ -577,13 +610,13 @@ public class Scene { public void clearTemporaryLocs() { for (int i = 0; i < temporaryLocCount; i++) { SceneLoc loc = temporaryLocs[i]; - remove(loc); + removeLoc(loc); temporaryLocs[i] = null; } temporaryLocCount = 0; } - public void remove(SceneLoc loc) { + public void removeLoc(SceneLoc loc) { for (int tx = loc.minSceneTileX; tx <= loc.maxSceneTileX; tx++) { for (int tz = loc.minSceneTileZ; tz <= loc.maxSceneTileZ; tz++) { SceneTile tile = levelTiles[loc.level][tx][tz]; @@ -607,10 +640,10 @@ public class Scene { break; } - tile.spans = 0; + tile.locSpans = 0; for (int j1 = 0; j1 < tile.locCount; j1++) { - tile.spans |= tile.locSpan[j1]; + tile.locSpans |= tile.locSpan[j1]; } } } @@ -652,7 +685,7 @@ public class Scene { for (int j1 = 0; j1 < tile.locCount; j1++) { SceneLoc loc = tile.locs[j1]; if ((((loc.bitset >> 29) & 3) == 2) && (loc.minSceneTileX == x) && (loc.minSceneTileZ == z)) { - remove(loc); + removeLoc(loc); return; } } @@ -842,18 +875,21 @@ public class Scene { mergeNormals(model, (Model) tile.groundDecoration.entity, 128, 0, 0, true); } } + if (tileZ < maxTileX) { SceneTile tile = levelTiles[level][tileX][tileZ + 1]; if ((tile != null) && (tile.groundDecoration != null) && (tile.groundDecoration.entity.vertexNormal != null)) { mergeNormals(model, (Model) tile.groundDecoration.entity, 0, 0, 128, true); } } + if ((tileX < maxTileX) && (tileZ < maxTileZ)) { SceneTile tile = levelTiles[level][tileX + 1][tileZ + 1]; if ((tile != null) && (tile.groundDecoration != null) && (tile.groundDecoration.entity.vertexNormal != null)) { mergeNormals(model, (Model) tile.groundDecoration.entity, 128, 0, 128, true); } } + if ((tileX < maxTileX) && (tileZ > 0)) { SceneTile tile = levelTiles[level][tileX + 1][tileZ - 1]; if ((tile != null) && (tile.groundDecoration != null) && (tile.groundDecoration.entity.vertexNormal != null)) { @@ -1120,7 +1156,7 @@ public class Scene { updateActiveOccluders(); - anInt446 = 0; + tilesRemaining = 0; for (int level = minLevel; level < maxLevel; level++) { SceneTile[][] tiles = levelTiles[level]; for (int x = minDrawTileX; x < maxDrawTileX; x++) { @@ -1132,14 +1168,14 @@ public class Scene { } if ((tile.drawLevel > topLevel) || (!visibilityMap[(x - eyeTileX) + 25][(z - eyeTileZ) + 25] && ((levelHeightmaps[level][x][z] - eyeY) < 2000))) { - tile.drawable = false; + tile.visible = false; tile.update = false; - tile.anInt1325 = 0; + tile.checkLocSpans = 0; } else { - tile.drawable = true; + tile.visible = true; tile.update = true; tile.containsLocs = tile.locCount > 0; - anInt446++; + tilesRemaining++; } } } @@ -1163,14 +1199,14 @@ public class Scene { if (rightTileX >= minDrawTileX) { if (forwardTileZ >= minDrawTileZ) { SceneTile tile = tiles[rightTileX][forwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, true); } } if (backwardTileZ < maxDrawTileZ) { SceneTile tile = tiles[rightTileX][backwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, true); } } @@ -1179,20 +1215,20 @@ public class Scene { if (leftTileX < maxDrawTileX) { if (forwardTileZ >= minDrawTileZ) { SceneTile tile = tiles[leftTileX][forwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, true); } } if (backwardTileZ < maxDrawTileZ) { SceneTile tile = tiles[leftTileX][backwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, true); } } } - if (anInt446 == 0) { + if (tilesRemaining == 0) { takingInput = false; return; } @@ -1218,14 +1254,14 @@ public class Scene { if (rightTileX >= minDrawTileX) { if (forwardTileZ >= minDrawTileZ) { SceneTile tile = tiles[rightTileX][forwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, false); } } if (backwardTileZ < maxDrawTileZ) { SceneTile tile = tiles[rightTileX][backwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, false); } } @@ -1233,20 +1269,20 @@ public class Scene { if (leftTileX < maxDrawTileX) { if (forwardTileZ >= minDrawTileZ) { SceneTile tile = tiles[leftTileX][forwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, false); } } if (backwardTileZ < maxDrawTileZ) { SceneTile tile = tiles[leftTileX][backwardTileZ]; - if ((tile != null) && tile.drawable) { + if ((tile != null) && tile.visible) { drawTile(tile, false); } } } - if (anInt446 == 0) { + if (tilesRemaining == 0) { takingInput = false; return; } @@ -1256,10 +1292,10 @@ public class Scene { takingInput = false; } - public void drawTile(SceneTile next, boolean flag) { + public void drawTile(SceneTile next, boolean checkAdjacent) { drawTileQueue.pushBack(next); - do { + while (true) { SceneTile tile; do { @@ -1272,14 +1308,14 @@ public class Scene { int tileX = tile.x; int tileZ = tile.z; - int dataLevel = tile.dataLevel; int level = tile.level; - SceneTile[][] tiles = levelTiles[dataLevel]; + int occludeLevel = tile.occludeLevel; + SceneTile[][] tiles = levelTiles[level]; - if (tile.drawable) { - if (flag) { - if (dataLevel > 0) { - SceneTile other = levelTiles[dataLevel - 1][tileX][tileZ]; + if (tile.visible) { + if (checkAdjacent) { + if (level > 0) { + SceneTile other = levelTiles[level - 1][tileX][tileZ]; if ((other != null) && other.update) { continue; @@ -1288,42 +1324,49 @@ public class Scene { if ((tileX <= eyeTileX) && (tileX > minDrawTileX)) { SceneTile other = tiles[tileX - 1][tileZ]; - if ((other != null) && other.update && (other.drawable || ((tile.spans & 1) == 0))) { + + if ((other != null) && other.update && (other.visible || ((tile.locSpans & 1) == 0))) { continue; } } + if ((tileX >= eyeTileX) && (tileX < (maxDrawTileX - 1))) { SceneTile other = tiles[tileX + 1][tileZ]; - if ((other != null) && other.update && (other.drawable || ((tile.spans & 4) == 0))) { + + if ((other != null) && other.update && (other.visible || ((tile.locSpans & 4) == 0))) { continue; } } + if ((tileZ <= eyeTileZ) && (tileZ > minDrawTileZ)) { SceneTile other = tiles[tileX][tileZ - 1]; - if ((other != null) && other.update && (other.drawable || ((tile.spans & 8) == 0))) { + + if ((other != null) && other.update && (other.visible || ((tile.locSpans & 8) == 0))) { continue; } } + if ((tileZ >= eyeTileZ) && (tileZ < (maxDrawTileZ - 1))) { SceneTile other = tiles[tileX][tileZ + 1]; - if ((other != null) && other.update && (other.drawable || ((tile.spans & 2) == 0))) { + + if ((other != null) && other.update && (other.visible || ((tile.locSpans & 2) == 0))) { continue; } } } else { - flag = true; + checkAdjacent = true; } - tile.drawable = false; + tile.visible = false; if (tile.bridge != null) { drawBridgeTile(tileX, tileZ, tile.bridge); } - boolean tileDrawn = drawTileUnderlayOrOverlay(tile, tileX, tileZ, level); + boolean tileDrawn = drawTileUnderlayOrOverlay(tile, tileX, tileZ, occludeLevel); int direction = 0; - int drawWallTypes = 0; + int allowWallTypes = 0; SceneWall wall = tile.wall; SceneWallDecoration wallDecoration = tile.wallDecoration; @@ -1340,77 +1383,58 @@ public class Scene { } else if (eyeTileZ > tileZ) { direction += 6; } - drawWallTypes = anIntArray478[direction]; - tile.anInt1328 = anIntArray480[direction]; + + // Essentially what's happening here is when there are multiple wall types on the same tile, we have + // to decide which ones to draw in which order. allowWallTypes determines the first walls that draw, + // and then tile.allowWallTypes determines the second walls to draw. This order is dependent on the + // direction the camera is relative to the tile. + allowWallTypes = DIRECTION_ALLOW_WALL_TYPE_PRIMARY[direction]; + tile.allowWallTypes = DIRECTION_ALLOW_WALL_TYPE_SECONDARY[direction]; } if (wall != null) { - if ((wall.typeA & anIntArray479[direction]) != 0) { + if ((wall.typeA & DIRECTION_ALLOW_WALL_CORNER_TYPE[direction]) != 0) { switch (wall.typeA) { + /** + * @see SceneTile#locSpans + */ case 16: - tile.anInt1325 = 0b0011; - tile.anInt1326 = anIntArray481[direction]; - tile.anInt1327 = 0b0011 - tile.anInt1326; + tile.checkLocSpans = 0b0011; + tile.blockLocSpans = WALL_CORNER_TYPE_16_BLOCK_LOC_SPANS[direction]; + tile.inverseBlockLocSpans = 0b0011 - tile.blockLocSpans; break; case 32: - tile.anInt1325 = 0b0110; - tile.anInt1326 = anIntArray482[direction]; - tile.anInt1327 = 0b0110 - tile.anInt1326; + tile.checkLocSpans = 0b0110; + tile.blockLocSpans = WALL_CORNER_TYPE_32_BLOCK_LOC_SPANS[direction]; + tile.inverseBlockLocSpans = 0b0110 - tile.blockLocSpans; break; case 64: - tile.anInt1325 = 0b1100; - tile.anInt1326 = anIntArray483[direction]; - tile.anInt1327 = 0b1100 - tile.anInt1326; + tile.checkLocSpans = 0b1100; + tile.blockLocSpans = WALL_CORNER_TYPE_64_BLOCK_LOC_SPANS[direction]; + tile.inverseBlockLocSpans = 0b1100 - tile.blockLocSpans; break; - default: - tile.anInt1325 = 0b1001; - tile.anInt1326 = anIntArray484[direction]; - tile.anInt1327 = 0b1001 - tile.anInt1326; + case 128: + tile.checkLocSpans = 0b1001; + tile.blockLocSpans = WALL_CORNER_TYPE_128_BLOCK_LOC_SPANS[direction]; + tile.inverseBlockLocSpans = 0b1001 - tile.blockLocSpans; break; } } else { - tile.anInt1325 = 0; + tile.checkLocSpans = 0; } - if (((wall.typeA & drawWallTypes) != 0) && !wallOccluded(level, tileX, tileZ, wall.typeA)) { + if (((wall.typeA & allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeA)) { wall.entityA.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wall.x - eyeX, wall.y - eyeY, wall.z - eyeZ, wall.bitset); } - if (((wall.typeB & drawWallTypes) != 0) && !wallOccluded(level, tileX, tileZ, wall.typeB)) { + if (((wall.typeB & allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeB)) { wall.entityB.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wall.x - eyeX, wall.y - eyeY, wall.z - eyeZ, wall.bitset); } } - if ((wallDecoration != null) && !occluded(level, tileX, tileZ, wallDecoration.entity.minY)) { - if ((wallDecoration.occlude & drawWallTypes) != 0) { - wallDecoration.entity.draw(wallDecoration.yaw, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wallDecoration.x - eyeX, wallDecoration.y - eyeY, wallDecoration.z - eyeZ, wallDecoration.bitset); - } else if ((wallDecoration.occlude & 0x300) != 0) { - int j4 = wallDecoration.x - eyeX; - int l5 = wallDecoration.y - eyeY; - int k6 = wallDecoration.z - eyeZ; - int i8 = wallDecoration.yaw; - int k9; - if ((i8 == 1) || (i8 == 2)) { - k9 = -j4; - } else { - k9 = j4; - } - int k10; - if ((i8 == 2) || (i8 == 3)) { - k10 = -k6; - } else { - k10 = k6; - } - if (((wallDecoration.occlude & 0x100) != 0) && (k10 < k9)) { - int i11 = j4 + anIntArray463[i8]; - int k11 = k6 + anIntArray464[i8]; - wallDecoration.entity.draw((i8 * 512) + 256, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, i11, l5, k11, wallDecoration.bitset); - } - if (((wallDecoration.occlude & 0x200) != 0) && (k10 > k9)) { - int j11 = j4 + anIntArray465[i8]; - int l11 = k6 + anIntArray466[i8]; - wallDecoration.entity.draw(((i8 * 512) + 1280) & 0x7ff, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, j11, l5, l11, wallDecoration.bitset); - } + if (wallDecoration != null) { + if (!occluded(occludeLevel, tileX, tileZ, wallDecoration.entity.minY)) { + drawWallDecoration(allowWallTypes, wallDecoration); } } @@ -1421,70 +1445,63 @@ public class Scene { groundDecoration.entity.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, groundDecoration.x - eyeX, groundDecoration.y - eyeY, groundDecoration.z - eyeZ, groundDecoration.bitset); } - SceneObjStack objStack = tile.objStack; + SceneObjStack stack = tile.objStack; - if ((objStack != null) && (objStack.offset == 0)) { - if (objStack.obj1 != null) { - objStack.obj1.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, objStack.x - eyeX, objStack.y - eyeY, objStack.z - eyeZ, objStack.bitset); - } - - if (objStack.obj2 != null) { - objStack.obj2.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, objStack.x - eyeX, objStack.y - eyeY, objStack.z - eyeZ, objStack.bitset); - } - - if (objStack.obj0 != null) { - objStack.obj0.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, objStack.x - eyeX, objStack.y - eyeY, objStack.z - eyeZ, objStack.bitset); - } + if ((stack != null) && (stack.offset == 0)) { + drawObjStack(stack, 0); } } - int k4 = tile.spans; - if (k4 != 0) { - if ((tileX < eyeTileX) && ((k4 & 4) != 0)) { - SceneTile tile_17 = tiles[tileX + 1][tileZ]; - if ((tile_17 != null) && tile_17.update) { - drawTileQueue.pushBack(tile_17); + int spans = tile.locSpans; + + if (spans != 0) { + if ((tileX < eyeTileX) && ((spans & 4) != 0)) { + SceneTile adjacent = tiles[tileX + 1][tileZ]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } - if ((tileZ < eyeTileZ) && ((k4 & 2) != 0)) { - SceneTile tile_18 = tiles[tileX][tileZ + 1]; - if ((tile_18 != null) && tile_18.update) { - drawTileQueue.pushBack(tile_18); + + if ((tileZ < eyeTileZ) && ((spans & 2) != 0)) { + SceneTile adjacent = tiles[tileX][tileZ + 1]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } - if ((tileX > eyeTileX) && ((k4 & 1) != 0)) { - SceneTile tile_19 = tiles[tileX - 1][tileZ]; - if ((tile_19 != null) && tile_19.update) { - drawTileQueue.pushBack(tile_19); + + if ((tileX > eyeTileX) && ((spans & 1) != 0)) { + SceneTile adjacent = tiles[tileX - 1][tileZ]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } - if ((tileZ > eyeTileZ) && ((k4 & 8) != 0)) { - SceneTile tile_20 = tiles[tileX][tileZ - 1]; - if ((tile_20 != null) && tile_20.update) { - drawTileQueue.pushBack(tile_20); + + if ((tileZ > eyeTileZ) && ((spans & 8) != 0)) { + SceneTile adjacent = tiles[tileX][tileZ - 1]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } } } - if (tile.anInt1325 != 0) { + if (tile.checkLocSpans != 0) { boolean draw = true; for (int i = 0; i < tile.locCount; i++) { - if (tile.locs[i].drawn() || (tile.locSpan[i] & tile.anInt1325) != tile.anInt1326) { - continue; + if (!tile.locs[i].drawn() && (tile.locSpan[i] & tile.checkLocSpans) == tile.blockLocSpans) { + draw = false; + break; } - draw = false; - break; } if (draw) { SceneWall wall = tile.wall; - if (!wallOccluded(level, tileX, tileZ, wall.typeA)) { + if (!wallOccluded(occludeLevel, tileX, tileZ, wall.typeA)) { wall.entityA.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wall.x - eyeX, wall.y - eyeY, wall.z - eyeZ, wall.bitset); } - tile.anInt1325 = 0; + tile.checkLocSpans = 0; } } @@ -1494,7 +1511,7 @@ public class Scene { tile.containsLocs = false; int locBufferSize = 0; - label0: + iterate_locs: for (int i = 0; i < locCount; i++) { SceneLoc loc = tile.locs[i]; @@ -1504,38 +1521,38 @@ public class Scene { for (int x = loc.minSceneTileX; x <= loc.maxSceneTileX; x++) { for (int z = loc.minSceneTileZ; z <= loc.maxSceneTileZ; z++) { - SceneTile ground = tiles[x][z]; + SceneTile other = tiles[x][z]; - if (!ground.drawable) { - if (ground.anInt1325 == 0) { + if (!other.visible) { + if (other.checkLocSpans == 0) { continue; } - - int flags = 0; - + + int spans = 0; + if (x > loc.minSceneTileX) { - flags++; + spans |= 0b0001; } - + if (x < loc.maxSceneTileX) { - flags += 4; + spans |= 0b0100; } - + if (z > loc.minSceneTileZ) { - flags += 8; + spans |= 0b1000; } - + if (z < loc.maxSceneTileZ) { - flags += 2; + spans |= 0b0010; } - - if ((flags & ground.anInt1325) != tile.anInt1327) { + + if ((spans & other.checkLocSpans) != tile.inverseBlockLocSpans) { continue; } } tile.containsLocs = true; - continue label0; + continue iterate_locs; } } @@ -1575,7 +1592,6 @@ public class Scene { int dx1 = locBuffer[farthestIndex].x - eyeX; int dz1 = locBuffer[farthestIndex].z - eyeZ; - // dot if (((dx0 * dx0) + (dz0 * dz0)) > ((dx1 * dx1) + (dz1 * dz1))) { farthestIndex = index; } @@ -1590,18 +1606,18 @@ public class Scene { SceneLoc farthest = locBuffer[farthestIndex]; farthest.cycle = cycle; - if (!occluded(level, farthest.minSceneTileX, farthest.maxSceneTileX, farthest.minSceneTileZ, farthest.maxSceneTileZ, farthest.entity.minY)) { + if (!occluded(occludeLevel, farthest.minSceneTileX, farthest.maxSceneTileX, farthest.minSceneTileZ, farthest.maxSceneTileZ, farthest.entity.minY)) { farthest.entity.draw(farthest.yaw, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, farthest.x - eyeX, farthest.y - eyeY, farthest.z - eyeZ, farthest.bitset); } for (int x = farthest.minSceneTileX; x <= farthest.maxSceneTileX; x++) { for (int z = farthest.minSceneTileZ; z <= farthest.maxSceneTileZ; z++) { - SceneTile tile1 = tiles[x][z]; + SceneTile occupied = tiles[x][z]; - if (tile1.anInt1325 != 0) { - drawTileQueue.pushBack(tile1); - } else if (((x != tileX) || (z != tileZ)) && tile1.update) { - drawTileQueue.pushBack(tile1); + if (occupied.checkLocSpans != 0) { + drawTileQueue.pushBack(occupied); + } else if (((x != tileX) || (z != tileZ)) && occupied.update) { + drawTileQueue.pushBack(occupied); } } } @@ -1615,74 +1631,84 @@ public class Scene { } } - if (!tile.update || (tile.anInt1325 != 0)) { + if (!tile.update || (tile.checkLocSpans != 0)) { continue; } + if ((tileX <= eyeTileX) && (tileX > minDrawTileX)) { - SceneTile tile_8 = tiles[tileX - 1][tileZ]; - if ((tile_8 != null) && tile_8.update) { + SceneTile adjacent = tiles[tileX - 1][tileZ]; + if ((adjacent != null) && adjacent.update) { continue; } } + if ((tileX >= eyeTileX) && (tileX < (maxDrawTileX - 1))) { - SceneTile tile_9 = tiles[tileX + 1][tileZ]; - if ((tile_9 != null) && tile_9.update) { + SceneTile adjacent = tiles[tileX + 1][tileZ]; + if ((adjacent != null) && adjacent.update) { continue; } } + if ((tileZ <= eyeTileZ) && (tileZ > minDrawTileZ)) { - SceneTile tile_10 = tiles[tileX][tileZ - 1]; - if ((tile_10 != null) && tile_10.update) { + SceneTile adjacent = tiles[tileX][tileZ - 1]; + if ((adjacent != null) && adjacent.update) { continue; } } + if ((tileZ >= eyeTileZ) && (tileZ < (maxDrawTileZ - 1))) { - SceneTile tile_11 = tiles[tileX][tileZ + 1]; - if ((tile_11 != null) && tile_11.update) { + SceneTile adjacent = tiles[tileX][tileZ + 1]; + if ((adjacent != null) && adjacent.update) { continue; } } + tile.update = false; - anInt446--; + tilesRemaining--; SceneObjStack stack = tile.objStack; if (stack != null && stack.offset != 0) { - drawObjStack(stack); + drawObjStack(stack, stack.offset); } - if (tile.anInt1328 != 0) { - SceneWallDecoration deco = tile.wallDecoration; + if (tile.allowWallTypes != 0) { + SceneWallDecoration wallDecoration = tile.wallDecoration; + + if ((wallDecoration != null) && !occluded(occludeLevel, tileX, tileZ, wallDecoration.entity.minY)) { + if ((wallDecoration.type & tile.allowWallTypes) != 0) { + wallDecoration.entity.draw(wallDecoration.rotation, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wallDecoration.x - eyeX, wallDecoration.y - eyeY, wallDecoration.z - eyeZ, wallDecoration.bitset); + } else if ((wallDecoration.type & 0x300) != 0) { + int dx = wallDecoration.x - eyeX; + int dy = wallDecoration.y - eyeY; + int dz = wallDecoration.z - eyeZ; + + int rotation = wallDecoration.rotation; + int nearestX; + int nearestZ; - if ((deco != null) && !occluded(level, tileX, tileZ, deco.entity.minY)) { - if ((deco.occlude & tile.anInt1328) != 0) { - deco.entity.draw(deco.yaw, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, deco.x - eyeX, deco.y - eyeY, deco.z - eyeZ, deco.bitset); - } else if ((deco.occlude & 0x300) != 0) { - int dx = deco.x - eyeX; - int dy = deco.y - eyeY; - int dz = deco.z - eyeZ; - int rotation = deco.yaw; - int j6; if ((rotation == 1) || (rotation == 2)) { - j6 = -dx; + nearestX = -dx; } else { - j6 = dx; + nearestX = dx; } - int l7; + if ((rotation == 2) || (rotation == 3)) { - l7 = -dz; + nearestZ = -dz; } else { - l7 = dz; + nearestZ = dz; } - if (((deco.occlude & 0x100) != 0) && (l7 >= j6)) { - int i9 = dx + anIntArray463[rotation]; - int i10 = dz + anIntArray464[rotation]; - deco.entity.draw((rotation * 512) + 256, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, i9, dy, i10, deco.bitset); + + if (((wallDecoration.type & 0x100) != 0) && (nearestZ >= nearestX)) { + int x = dx + DIAGONAL_WALL_DECORATION_ROTATION_OFFSET_X[rotation]; + int z = dz + DIAGONAL_WALL_DECORATION_ROTATION_OFFSET_Z[rotation]; + wallDecoration.entity.draw((rotation * 512) + 256, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, dy, z, wallDecoration.bitset); } - if (((deco.occlude & 0x200) != 0) && (l7 <= j6)) { - int j9 = dx + anIntArray465[rotation]; - int j10 = dz + anIntArray466[rotation]; - deco.entity.draw(((rotation * 512) + 1280) & 0x7ff, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, j9, dy, j10, deco.bitset); + + if (((wallDecoration.type & 0x200) != 0) && (nearestZ <= nearestX)) { + int x = dx + anIntArray465[rotation]; + int z = dz + anIntArray466[rotation]; + wallDecoration.entity.draw(((rotation * 512) + 1280) & 0x7ff, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, dy, z, wallDecoration.bitset); } } } @@ -1690,68 +1716,109 @@ public class Scene { SceneWall wall = tile.wall; if (wall != null) { - if (((wall.typeB & tile.anInt1328) != 0) && !wallOccluded(level, tileX, tileZ, wall.typeB)) { + if (((wall.typeB & tile.allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeB)) { wall.entityB.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wall.x - eyeX, wall.y - eyeY, wall.z - eyeZ, wall.bitset); } - if (((wall.typeA & tile.anInt1328) != 0) && !wallOccluded(level, tileX, tileZ, wall.typeA)) { + if (((wall.typeA & tile.allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeA)) { wall.entityA.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wall.x - eyeX, wall.y - eyeY, wall.z - eyeZ, wall.bitset); } } } - if (dataLevel < (maxLevel - 1)) { - SceneTile tile_12 = levelTiles[dataLevel + 1][tileX][tileZ]; - if ((tile_12 != null) && tile_12.update) { - drawTileQueue.pushBack(tile_12); + if (level < (maxLevel - 1)) { + SceneTile above = levelTiles[level + 1][tileX][tileZ]; + if ((above != null) && above.update) { + drawTileQueue.pushBack(above); } } + if (tileX < eyeTileX) { - SceneTile tile_13 = tiles[tileX + 1][tileZ]; - if ((tile_13 != null) && tile_13.update) { - drawTileQueue.pushBack(tile_13); + SceneTile adjacent = tiles[tileX + 1][tileZ]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } + if (tileZ < eyeTileZ) { - SceneTile tile_14 = tiles[tileX][tileZ + 1]; - if ((tile_14 != null) && tile_14.update) { - drawTileQueue.pushBack(tile_14); + SceneTile adjacent = tiles[tileX][tileZ + 1]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } + if (tileX > eyeTileX) { - SceneTile tile_15 = tiles[tileX - 1][tileZ]; - if ((tile_15 != null) && tile_15.update) { - drawTileQueue.pushBack(tile_15); + SceneTile adjacent = tiles[tileX - 1][tileZ]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } + if (tileZ > eyeTileZ) { - SceneTile tile_16 = tiles[tileX][tileZ - 1]; - if ((tile_16 != null) && tile_16.update) { - drawTileQueue.pushBack(tile_16); + SceneTile adjacent = tiles[tileX][tileZ - 1]; + if ((adjacent != null) && adjacent.update) { + drawTileQueue.pushBack(adjacent); } } - } while (true); + } } - private static void drawObjStack(SceneObjStack stack) { + private static void drawObjStack(SceneObjStack stack, int offset) { if (stack.obj1 != null) { - stack.obj1.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, stack.x - eyeX, stack.y - eyeY - stack.offset, stack.z - eyeZ, stack.bitset); + stack.obj1.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, stack.x - eyeX, stack.y - eyeY - offset, stack.z - eyeZ, stack.bitset); } if (stack.obj2 != null) { - stack.obj2.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, stack.x - eyeX, stack.y - eyeY - stack.offset, stack.z - eyeZ, stack.bitset); + stack.obj2.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, stack.x - eyeX, stack.y - eyeY - offset, stack.z - eyeZ, stack.bitset); } if (stack.obj0 != null) { - stack.obj0.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, stack.x - eyeX, stack.y - eyeY - stack.offset, stack.z - eyeZ, stack.bitset); + stack.obj0.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, stack.x - eyeX, stack.y - eyeY - offset, stack.z - eyeZ, stack.bitset); } } - private boolean drawTileUnderlayOrOverlay(SceneTile tile, int tileX, int tileZ, int level) { + private static void drawWallDecoration(int occlusions, SceneWallDecoration wallDecoration) { + if ((wallDecoration.type & occlusions) != 0) { + wallDecoration.entity.draw(wallDecoration.rotation, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, wallDecoration.x - eyeX, wallDecoration.y - eyeY, wallDecoration.z - eyeZ, wallDecoration.bitset); + } else if ((wallDecoration.type & 0x300) != 0) { + int dx = wallDecoration.x - eyeX; + int y = wallDecoration.y - eyeY; + int dz = wallDecoration.z - eyeZ; + int rotation = wallDecoration.rotation; + + int nearestX; + int nearestZ; + + if ((rotation == 1) || (rotation == 2)) { + nearestX = -dx; + } else { + nearestX = dx; + } + if ((rotation == 2) || (rotation == 3)) { + nearestZ = -dz; + } else { + nearestZ = dz; + } + + if (((wallDecoration.type & 0x100) != 0) && (nearestZ < nearestX)) { + int x = dx + DIAGONAL_WALL_DECORATION_ROTATION_OFFSET_X[rotation]; + int z = dz + DIAGONAL_WALL_DECORATION_ROTATION_OFFSET_Z[rotation]; + wallDecoration.entity.draw((rotation * 512) + 256, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, y, z, wallDecoration.bitset); + } + + if (((wallDecoration.type & 0x200) != 0) && (nearestZ > nearestX)) { + int x = dx + anIntArray465[rotation]; + int z = dz + anIntArray466[rotation]; + wallDecoration.entity.draw(((rotation * 512) + 1280) & 0x7ff, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, y, z, wallDecoration.bitset); + } + } + } + + private boolean drawTileUnderlayOrOverlay(SceneTile tile, int x, int z, int level) { if (tile.underlay != null) { - if (!tileOccluded(level, tileX, tileZ)) { - drawTileUnderlay(tile.underlay, level, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, tileX, tileZ); + if (!tileOccluded(level, x, z)) { + drawTileUnderlay(tile.underlay, level, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, z); return true; } - } else if ((tile.overlay != null) && !tileOccluded(level, tileX, tileZ)) { - drawTileOverlay(tileX, sinEyePitch, sinEyeYaw, tile.overlay, cosEyePitch, tileZ, cosEyeYaw); + } else if ((tile.overlay != null) && !tileOccluded(level, x, z)) { + drawTileOverlay(x, sinEyePitch, sinEyeYaw, tile.overlay, cosEyePitch, z, cosEyeYaw); return true; } return false; @@ -2000,7 +2067,7 @@ public class Scene { activeOccluderCount = 0; activeGroundOccluderCount = 0; activeWallOccluderCount = 0; - tilesCulled=0; + tilesCulled = 0; if (disableOccluders) { return; @@ -2199,175 +2266,166 @@ public class Scene { } } - public boolean wallOccluded(int level, int stx, int stz, int type) { - if (!tileOccluded(level, stx, stz)) { + public boolean wallOccluded(int level, int tileX, int tileZ, int type) { + if (!tileOccluded(level, tileX, tileZ)) { return false; } - int x = stx << 7; - int z = stz << 7; - int y = levelHeightmaps[level][stx][stz] - 1; - int y0 = y - 120; - int y1 = y - 230; - int y2 = y - 238; + int sceneX = tileX << 7; + int sceneZ = tileZ << 7; + int sceneY = levelHeightmaps[level][tileX][tileZ] - 1; + int y0 = sceneY - 120; + int y1 = sceneY - 230; + int y2 = sceneY - 238; if (type < 16) { if (type == 1) { - if (x > eyeX) { - if (!occluded(x, y, z)) { + if (sceneX > eyeX) { + if (!occluded(sceneX, sceneY, sceneZ)) { return false; } - if (!occluded(x, y, z + 128)) { + if (!occluded(sceneX, sceneY, sceneZ + 128)) { return false; } } if (level > 0) { - if (!occluded(x, y0, z)) { + if (!occluded(sceneX, y0, sceneZ)) { return false; } - if (!occluded(x, y0, z + 128)) { + if (!occluded(sceneX, y0, sceneZ + 128)) { return false; } } - if (!occluded(x, y1, z)) { + if (!occluded(sceneX, y1, sceneZ)) { return false; } - return occluded(x, y1, z + 128); - } - if (type == 2) { - if (z < eyeZ) { - if (!occluded(x, y, z + 128)) { + return occluded(sceneX, y1, sceneZ + 128); + } else if (type == 2) { + if (sceneZ < eyeZ) { + if (!occluded(sceneX, sceneY, sceneZ + 128)) { return false; } - if (!occluded(x + 128, y, z + 128)) { + if (!occluded(sceneX + 128, sceneY, sceneZ + 128)) { return false; } } if (level > 0) { - if (!occluded(x, y0, z + 128)) { + if (!occluded(sceneX, y0, sceneZ + 128)) { return false; } - if (!occluded(x + 128, y0, z + 128)) { + if (!occluded(sceneX + 128, y0, sceneZ + 128)) { return false; } } - if (!occluded(x, y1, z + 128)) { + if (!occluded(sceneX, y1, sceneZ + 128)) { return false; } - return occluded(x + 128, y1, z + 128); - } - if (type == 4) { - if (x < eyeX) { - if (!occluded(x + 128, y, z)) { + return occluded(sceneX + 128, y1, sceneZ + 128); + } else if (type == 4) { + if (sceneX < eyeX) { + if (!occluded(sceneX + 128, sceneY, sceneZ)) { return false; } - if (!occluded(x + 128, y, z + 128)) { + if (!occluded(sceneX + 128, sceneY, sceneZ + 128)) { return false; } } if (level > 0) { - if (!occluded(x + 128, y0, z)) { + if (!occluded(sceneX + 128, y0, sceneZ)) { return false; } - if (!occluded(x + 128, y0, z + 128)) { + if (!occluded(sceneX + 128, y0, sceneZ + 128)) { return false; } } - if (!occluded(x + 128, y1, z)) { + if (!occluded(sceneX + 128, y1, sceneZ)) { return false; } - return occluded(x + 128, y1, z + 128); - } - if (type == 8) { - if (z > eyeZ) { - if (!occluded(x, y, z)) { + return occluded(sceneX + 128, y1, sceneZ + 128); + } else if (type == 8) { + if (sceneZ > eyeZ) { + if (!occluded(sceneX, sceneY, sceneZ)) { return false; } - if (!occluded(x + 128, y, z)) { + if (!occluded(sceneX + 128, sceneY, sceneZ)) { return false; } } if (level > 0) { - if (!occluded(x, y0, z)) { + if (!occluded(sceneX, y0, sceneZ)) { return false; } - if (!occluded(x + 128, y0, z)) { + if (!occluded(sceneX + 128, y0, sceneZ)) { return false; } } - if (!occluded(x, y1, z)) { + if (!occluded(sceneX, y1, sceneZ)) { return false; } - return occluded(x + 128, y1, z); + return occluded(sceneX + 128, y1, sceneZ); } } - if (!occluded(x + 64, y2, z + 64)) { + if (!occluded(sceneX + 64, y2, sceneZ + 64)) { return false; } if (type == 16) { - return occluded(x, y1, z + 128); - } - - if (type == 32) { - return occluded(x + 128, y1, z + 128); - } - - if (type == 64) { - return occluded(x + 128, y1, z); - } - - if (type == 128) { - return occluded(x, y1, z); + return occluded(sceneX, y1, sceneZ + 128); + } else if (type == 32) { + return occluded(sceneX + 128, y1, sceneZ + 128); + } else if (type == 64) { + return occluded(sceneX + 128, y1, sceneZ); + } else if (type == 128) { + return occluded(sceneX, y1, sceneZ); } else { System.out.println("Warning unsupported wall type"); return true; } } - public boolean occluded(int level, int tx, int tz, int y) { - if (!tileOccluded(level, tx, tz)) { + public boolean occluded(int level, int tileX, int tileZ, int y) { + if (!tileOccluded(level, tileX, tileZ)) { return false; } - int x = tx << 7; - int z = tz << 7; - return occluded(x + 1, levelHeightmaps[level][tx][tz] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][tx + 1][tz] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][tx + 1][tz + 1] - y, (z + 128) - 1) && occluded(x + 1, levelHeightmaps[level][tx][tz + 1] - y, (z + 128) - 1); + int x = tileX << 7; + int z = tileZ << 7; + return occluded(x + 1, levelHeightmaps[level][tileX][tileZ] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][tileX + 1][tileZ] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][tileX + 1][tileZ + 1] - y, (z + 128) - 1) && occluded(x + 1, levelHeightmaps[level][tileX][tileZ + 1] - y, (z + 128) - 1); } - public boolean occluded(int level, int tx0, int tx1, int tz0, int tz1, int y) { - if ((tx0 == tx1) && (tz0 == tz1)) { - if (!tileOccluded(level, tx0, tz0)) { + public boolean occluded(int level, int minTileX, int maxTileX, int minTileZ, int maxTileZ, int y) { + if ((minTileX == maxTileX) && (minTileZ == maxTileZ)) { + if (!tileOccluded(level, minTileX, minTileZ)) { return false; } - int x = tx0 << 7; - int z = tz0 << 7; - return occluded(x + 1, levelHeightmaps[level][tx0][tz0] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][tx0 + 1][tz0] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][tx0 + 1][tz0 + 1] - y, (z + 128) - 1) && occluded(x + 1, levelHeightmaps[level][tx0][tz0 + 1] - y, (z + 128) - 1); + int x = minTileX << 7; + int z = minTileZ << 7; + return occluded(x + 1, levelHeightmaps[level][minTileX][minTileZ] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][minTileX + 1][minTileZ] - y, z + 1) && occluded((x + 128) - 1, levelHeightmaps[level][minTileX + 1][minTileZ + 1] - y, (z + 128) - 1) && occluded(x + 1, levelHeightmaps[level][minTileX][minTileZ + 1] - y, (z + 128) - 1); } - for (int stx = tx0; stx <= tx1; stx++) { - for (int stz = tz0; stz <= tz1; stz++) { + for (int stx = minTileX; stx <= maxTileX; stx++) { + for (int stz = minTileZ; stz <= maxTileZ; stz++) { if (levelTileOcclusionCycles[level][stx][stz] == -cycle) { return false; } } } - int x0 = (tx0 << 7) + 1; - int z0 = (tz0 << 7) + 2; - int y0 = levelHeightmaps[level][tx0][tz0] - y; + int x0 = (minTileX << 7) + 1; + int z0 = (minTileZ << 7) + 2; + int y0 = levelHeightmaps[level][minTileX][minTileZ] - y; if (!occluded(x0, y0, z0)) { return false; } - int x1 = (tx1 << 7) - 1; + int x1 = (maxTileX << 7) - 1; if (!occluded(x1, y0, z0)) { return false; } - int z1 = (tz1 << 7) - 1; + int z1 = (maxTileZ << 7) - 1; if (!occluded(x0, y0, z1)) { return false; diff --git a/src/main/java/SceneBuilder.java b/src/main/java/SceneBuilder.java index 2ade670..e1ac02d 100644 --- a/src/main/java/SceneBuilder.java +++ b/src/main/java/SceneBuilder.java @@ -4,30 +4,31 @@ public class SceneBuilder { - public static final int[] anIntArray137 = {1, 0, -1, 0}; - public static final int[] anIntArray144 = {0, -1, 0, 1}; + public static final int[] WALL_DECORATION_FORWARD_X = {1, 0, -1, 0}; + public static final int[] WALL_DECORATION_FORWARD_Z = {0, -1, 0, 1}; public static int randomHueOffset = (int) (Math.random() * 17.0) - 8; public static int level; public static int randomLightnessOffset = (int) (Math.random() * 33.0) - 16; public static int minLevel = 99; public static boolean lowmem = true; - public static int method170(int i, int i_3_) { - int i_4_ = i + (i_3_ * 57); - i_4_ = (i_4_ << 13) ^ i_4_; - int i_5_ = ((i_4_ * ((i_4_ * i_4_ * 15731) + 789221)) + 1376312589) & 0x7fffffff; - return (i_5_ >> 19) & 0xff; + public static int noise(int x, int y) { + int n = x + (y * 57); + n = (n << 13) ^ n; + return ((((n * ((n * n * 15731) + 789221)) + 1376312589) & 0x7fffffff) >> 19) & 0xff; } - public static int method172(int i, int i_108_) { - int i_109_ = (method176(i + 45365, i_108_ + 91923, 4) - 128) + ((method176(i + 10294, i_108_ + 37821, 2) - 128) >> 1) + ((method176(i, i_108_, 1) - 128) >> 2); - i_109_ = (int) ((double) i_109_ * 0.3) + 35; - if (i_109_ < 10) { - i_109_ = 10; - } else if (i_109_ > 60) { - i_109_ = 60; + public static int perlin(int x, int z) { + int value = (perlin(x + 45365, z + 91923, 4) - 128) + ((perlin(x + 10294, z + 37821, 2) - 128) >> 1) + ((perlin(x, z, 1) - 128) >> 2); + value = (int) ((double) value * 0.3) + 35; + + if (value < 10) { + value = 10; + } else if (value > 60) { + value = 60; } - return i_109_; + + return value; } public static void method173(Buffer buffer, OnDemand onDemand) { @@ -50,18 +51,18 @@ public class SceneBuilder { } } - public static int method176(int i, int i_144_, int i_145_) { - int i_146_ = i / i_145_; - int i_147_ = i & (i_145_ - 1); - int i_148_ = i_144_ / i_145_; - int i_149_ = i_144_ & (i_145_ - 1); - int i_150_ = method186(i_146_, i_148_); - int i_151_ = method186(i_146_ + 1, i_148_); - int i_152_ = method186(i_146_, i_148_ + 1); - int i_153_ = method186(i_146_ + 1, i_148_ + 1); - int i_154_ = method184(i_150_, i_151_, i_147_, i_145_); - int i_155_ = method184(i_152_, i_153_, i_147_, i_145_); - return method184(i_154_, i_155_, i_149_, i_145_); + public static int perlin(int x, int z, int scale) { + int intX = x / scale; + int intZ = z / scale; + int fracX = x & (scale - 1); + int fracZ = z & (scale - 1); + int v1 = smoothNoise(intX, intZ); + int v2 = smoothNoise(intX + 1, intZ); + int v3 = smoothNoise(intX, intZ + 1); + int v4 = smoothNoise(intX + 1, intZ + 1); + int i1 = interpolate(v1, v2, fracX, scale); + int i2 = interpolate(v3, v4, fracX, scale); + return interpolate(i1, i2, fracZ, scale); } /** @@ -82,16 +83,16 @@ public class SceneBuilder { return type.validate(kind); } - public static int method184(int i, int i_216_, int i_217_, int i_218_) { - int i_219_ = (65536 - Draw3D.cos[(i_217_ * 1024) / i_218_]) >> 1; - return ((i * (65536 - i_219_)) >> 16) + ((i_216_ * i_219_) >> 16); + public static int interpolate(int a, int b, int x, int scale) { + int f = (65536 - Draw3D.cos[(x * 1024) / scale]) >> 1; + return ((a * (65536 - f)) >> 16) + ((b * f) >> 16); } - public static int method186(int i, int i_221_) { - int i_222_ = method170(i - 1, i_221_ - 1) + method170(i + 1, i_221_ - 1) + method170(i - 1, i_221_ + 1) + method170(i + 1, i_221_ + 1); - int i_223_ = method170(i - 1, i_221_) + method170(i + 1, i_221_) + method170(i, i_221_ - 1) + method170(i, i_221_ + 1); - int i_224_ = method170(i, i_221_); - return (i_222_ / 16) + (i_223_ / 8) + (i_224_ / 4); + public static int smoothNoise(int x, int y) { + int corners = noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1); + int sides = noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1); + int center = noise(x, y); + return (corners / 16) + (sides / 8) + (center / 4); } public static int mulHSL(int hsl, int lightness) { @@ -108,7 +109,7 @@ public class SceneBuilder { return (hsl & 0xff80) + lightness; } - public static void addLoc(Scene scene, int rotation, int z, int kind, int tileLevel, SceneCollisionMap collision, int[][][] levelHeightmap, int x, int locID, int dataLevel) { + public static void addLoc(Scene scene, int rotation, int z, int kind, int tileLevel, SceneCollisionMap collision, int[][][] levelHeightmap, int x, int locID, int level) { int heightSW = levelHeightmap[tileLevel][x][z]; int heightSE = levelHeightmap[tileLevel][x + 1][z]; int heightNE = levelHeightmap[tileLevel][x + 1][z + 1]; @@ -116,7 +117,7 @@ public class SceneBuilder { int y = (heightSW + heightSE + heightNE + heightNW) >> 2; LocType loc = LocType.get(locID); - int bitset = x + (z << 7) + (locID << 14) + 1073741824; + int bitset = x + (z << 7) + (locID << 14) + 0x40000000; if (!loc.interactable) { bitset += 0x80000000; @@ -125,138 +126,21 @@ public class SceneBuilder { byte info = (byte) ((rotation << 6) + kind); if (kind == 22) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(22, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, 22, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.addGroundDecoration(entity, dataLevel, x, z, y, bitset, info); - - if (loc.solid && loc.interactable) { - collision.addSolid(z, x); - } + addGroundDecoration(scene, rotation, z, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if ((kind == 10) || (kind == 11)) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(10, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, 10, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - if (entity != null) { - int angle = 0; - - if (kind == 11) { - angle += 256; - } - - int width; - int length; - - if ((rotation == 1) || (rotation == 3)) { - width = loc.length; - length = loc.width; - } else { - width = loc.width; - length = loc.length; - } - - scene.add(entity, dataLevel, x, z, y, width, length, angle, bitset, info); - } - if (loc.solid) { - collision.add(loc.blocksProjectiles, loc.width, loc.length, x, z, rotation); - } + addLoc(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind >= 12) { - Entity entity; - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(kind, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, kind, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.add(entity, dataLevel, x, z, y, 1, 1, 0, bitset, info); - - if (loc.solid) { - collision.add(loc.blocksProjectiles, loc.width, loc.length, x, z, rotation); - } + addDiagonalWall(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 0) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(0, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, 0, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], entity, 0, null, dataLevel, x, z, y, bitset, info); - - if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); - } + addWall(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 1) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(1, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, 1, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, dataLevel, x, z, y, bitset, info); - - if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); - } + addDiagonalWallCorner(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 2) { - int nextRotation = (rotation + 1) & 0x3; - Entity locA; - Entity locB; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - locA = loc.getModel(2, 4 + rotation, heightSW, heightSE, heightNE, heightNW, -1); - locB = loc.getModel(2, nextRotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - locA = new LocEntity(locID, 4 + rotation, 2, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - locB = new LocEntity(locID, nextRotation, 2, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], locA, Scene.ROTATION_WALL_TYPE[nextRotation], locB, dataLevel, x, z, y, bitset, info); - - if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); - } + addFullWallCorner(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 3) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(3, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, 3, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, dataLevel, x, z, y, bitset, info); - - if (loc.solid) { - collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); - } + addWallCorner(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 9) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(kind, rotation, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, rotation, kind, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.add(entity, dataLevel, x, z, y, 1, 1, 0, bitset, info); - - if (loc.solid) { - collision.add(loc.blocksProjectiles, loc.width, loc.length, x, z, rotation); - } + addDiagonalWall(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else { if (loc.adjustToTerrain) { if (rotation == 1) { @@ -282,66 +166,184 @@ public class SceneBuilder { } if (kind == 4) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(4, 0, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, dataLevel, x, z, y, rotation * 512, 0, 0, bitset, info); + addWallDecoration(scene, rotation, z, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 5) { - int padding = 16; - int wallBitset = scene.getWallBitset(dataLevel, x, z); - - if (wallBitset > 0) { - padding = LocType.get((wallBitset >> 14) & 0x7fff).decorationPadding; - } - - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(4, 0, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, dataLevel, x, z, y, rotation * 512, anIntArray137[rotation] * padding, anIntArray144[rotation] * padding, bitset, info); + addWallDecorationOutside(scene, rotation, z, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 6) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(4, 0, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWallDecoration(256, entity, dataLevel, x, z, y, rotation, 0, 0, bitset, info); + addDiagonalWallDecorationInside(z, scene, level, x, locID, rotation, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 7) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(4, 0, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWallDecoration(512, entity, dataLevel, x, z, y, rotation, 0, 0, bitset, info); + addDiagonalWallDecorationOutside(z, scene, level, x, locID, rotation, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else if (kind == 8) { - Entity entity; - - if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { - entity = loc.getModel(4, 0, heightSW, heightSE, heightNE, heightNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); - } - - scene.setWallDecoration(768, entity, dataLevel, x, z, y, rotation, 0, 0, bitset, info); + addDiagonalWallDecorationBoth(z, scene, level, x, locID, rotation, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } } } + private static void addGroundDecoration(Scene scene, int rotation, int z, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(22, rotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, rotation, 22, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.addGroundDecoration(entity, level, x, z, y, bitset, info); + + if (loc.solid && loc.interactable) { + collision.addSolid(z, x); + } + } + + private static void addLoc(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(10, rotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, rotation, 10, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + if (entity != null) { + int angle = 0; + + if (kind == 11) { + angle += 256; + } + + int width; + int length; + + if ((rotation == 1) || (rotation == 3)) { + width = loc.sizeZ; + length = loc.sizeX; + } else { + width = loc.sizeX; + length = loc.sizeZ; + } + + scene.push(entity, level, x, z, y, width, length, angle, bitset, info); + } + if (loc.solid) { + collision.add(loc.blocksProjectiles, loc.sizeX, loc.sizeZ, x, z, rotation); + } + } + + private static void addWall(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(0, rotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, rotation, 0, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], entity, 0, null, level, x, z, y, bitset, info); + + if (loc.solid) { + collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); + } + } + + private static void addDiagonalWallCorner(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(1, rotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, rotation, 1, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, y, bitset, info); + + if (loc.solid) { + collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); + } + } + + private static void addFullWallCorner(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + int nextRotation = (rotation + 1) & 0x3; + Entity locA; + Entity locB; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + locA = loc.getModel(2, 4 + rotation, heightSW, heightSE, heightNE, heightNW, -1); + locB = loc.getModel(2, nextRotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + locA = new LocEntity(locID, 4 + rotation, 2, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + locB = new LocEntity(locID, nextRotation, 2, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_TYPE[rotation], locA, Scene.ROTATION_WALL_TYPE[nextRotation], locB, level, x, z, y, bitset, info); + + if (loc.solid) { + collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); + } + } + + private static void addWallCorner(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(3, rotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, rotation, 3, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.setWall(Scene.ROTATION_WALL_CORNER_TYPE[rotation], entity, 0, null, level, x, z, y, bitset, info); + + if (loc.solid) { + collision.addWall(z, rotation, x, kind, loc.blocksProjectiles); + } + } + + private static void addDiagonalWall(Scene scene, int rotation, int z, int kind, SceneCollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(kind, rotation, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, rotation, kind, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.push(entity, level, x, z, y, 1, 1, 0, bitset, info); + + if (loc.solid) { + collision.add(loc.blocksProjectiles, loc.sizeX, loc.sizeZ, x, z, rotation); + } + } + + private static void addWallDecoration(Scene scene, int rotation, int z, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(4, 0, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, 0, 4, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, level, x, z, y, rotation * 512, 0, 0, bitset, info); + } + + private static void addWallDecorationOutside(Scene scene, int rotation, int z, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + int padding = 16; + int wallBitset = scene.getWallBitset(level, x, z); + + if (wallBitset > 0) { + padding = LocType.get((wallBitset >> 14) & 0x7fff).decorationPadding; + } + + Entity entity; + + if ((loc.seqID == -1) && (loc.overrideTypeIDs == null)) { + entity = loc.getModel(4, 0, heightSW, heightSE, heightNE, heightNW, -1); + } else { + entity = new LocEntity(locID, 0, 4, heightSE, heightNE, heightSW, heightNW, loc.seqID, true); + } + + scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, level, x, z, y, rotation * 512, WALL_DECORATION_FORWARD_X[rotation] * padding, WALL_DECORATION_FORWARD_Z[rotation] * padding, bitset, info); + } + /** * Reads the Locs from the provided data and determines if their models are available. The origin coordinate is used * to determine if a loc would be excluded from the scene, therefor not required to be validated. The chain of calls @@ -896,29 +898,42 @@ public class SceneBuilder { } } - public void method174(int i, int i_113_, int i_115_, int i_116_) { - for (int i_117_ = i; i_117_ <= (i + i_113_); i_117_++) { - for (int i_118_ = i_116_; i_118_ <= (i_116_ + i_115_); i_118_++) { - if ((i_118_ >= 0) && (i_118_ < maxTileX) && (i_117_ >= 0) && (i_117_ < maxTileZ)) { - levelShademap[0][i_118_][i_117_] = (byte) 127; - if ((i_118_ == i_116_) && (i_118_ > 0)) { - levelHeightmap[0][i_118_][i_117_] = levelHeightmap[0][i_118_ - 1][i_117_]; - } - if ((i_118_ == (i_116_ + i_115_)) && (i_118_ < (maxTileX - 1))) { - levelHeightmap[0][i_118_][i_117_] = levelHeightmap[0][i_118_ + 1][i_117_]; - } - if ((i_117_ == i) && (i_117_ > 0)) { - levelHeightmap[0][i_118_][i_117_] = levelHeightmap[0][i_118_][i_117_ - 1]; - } - if ((i_117_ == (i + i_113_)) && (i_117_ < (maxTileZ - 1))) { - levelHeightmap[0][i_118_][i_117_] = levelHeightmap[0][i_118_][i_117_ + 1]; - } + /** + * Flattens the perimeter of the provided area. + * @param tileX the area x. + * @param tileZ the area z. + * @param tileSizeX the area size x. + * @param tileSizeZ the area size z. + */ + public void stitchHeightmap(int tileX, int tileZ, int tileSizeX, int tileSizeZ) { + for (int z = tileZ; z <= (tileZ + tileSizeZ); z++) { + for (int x = tileX; x <= (tileX + tileSizeX); x++) { + if ((x < 0) || (x >= maxTileX) || (z < 0) || (z >= maxTileZ)) { + continue; + } + + levelShademap[0][x][z] = (byte) 127; + + if ((x == tileX) && (x > 0)) { + levelHeightmap[0][x][z] = levelHeightmap[0][x - 1][z]; + } + + if ((x == (tileX + tileSizeX)) && (x < (maxTileX - 1))) { + levelHeightmap[0][x][z] = levelHeightmap[0][x + 1][z]; + } + + if ((z == tileZ) && (z > 0)) { + levelHeightmap[0][x][z] = levelHeightmap[0][x][z - 1]; + } + + if ((z == (tileZ + tileSizeZ)) && (z < (maxTileZ - 1))) { + levelHeightmap[0][x][z] = levelHeightmap[0][x][z + 1]; } } } } - public void method175(int z, Scene scene, SceneCollisionMap collision, int kind, int level, int x, int locID, int rotation) { + public void addLoc(Scene scene, SceneCollisionMap collision, int locID, int kind, int rotation, int level, int x, int z) { if (lowmem && ((levelTileFlags[0][x][z] & 0x2) == 0) && (((levelTileFlags[level][x][z] & 0x10) != 0) || (getDrawLevel(level, x, z) != SceneBuilder.level))) { return; } @@ -975,14 +990,14 @@ public class SceneBuilder { int height; if ((rotation == 1) || (rotation == 3)) { - width = type.length; - height = type.width; + width = type.sizeZ; + height = type.sizeX; } else { - width = type.width; - height = type.length; + width = type.sizeX; + height = type.sizeZ; } - if (scene.add(entity, level, x, z, heightmapAverage, width, height, yaw, bitset, info) && type.castShadow) { + if (scene.push(entity, level, x, z, heightmapAverage, width, height, yaw, bitset, info) && type.castShadow) { Model model; if (entity instanceof Model) { @@ -1010,7 +1025,7 @@ public class SceneBuilder { } if (type.solid && (collision != null)) { - collision.add(type.blocksProjectiles, type.width, type.length, x, z, rotation); + collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); } } else if (kind >= 12) { Entity entity; @@ -1021,14 +1036,14 @@ public class SceneBuilder { entity = new LocEntity(locID, rotation, kind, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); } - scene.add(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); + scene.push(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); if ((kind >= 12) && (kind <= 17) && (kind != 13) && (level > 0)) { levelOccludemap[level][x][z] |= 0b100_100_100_100; } if (type.solid && (collision != null)) { - collision.add(type.blocksProjectiles, type.width, type.length, x, z, rotation); + collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); } } else if (kind == 0) { Entity entity; @@ -1171,82 +1186,78 @@ public class SceneBuilder { } else { entity = new LocEntity(locID, rotation, kind, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); } - scene.add(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); + scene.push(entity, level, x, z, heightmapAverage, 1, 1, 0, bitset, info); if (type.solid && (collision != null)) { - collision.add(type.blocksProjectiles, type.width, type.length, x, z, rotation); + collision.add(type.blocksProjectiles, type.sizeX, type.sizeZ, x, z, rotation); } } else { if (type.adjustToTerrain) { if (rotation == 1) { - int i_139_ = heightmapNW; + int tmp = heightmapNW; heightmapNW = heightmapNE; heightmapNE = heightmapSE; heightmapSE = heightmapSW; - heightmapSW = i_139_; + heightmapSW = tmp; } else if (rotation == 2) { - int i_140_ = heightmapNW; + int tmp = heightmapNW; heightmapNW = heightmapSE; - heightmapSE = i_140_; - i_140_ = heightmapNE; + heightmapSE = tmp; + tmp = heightmapNE; heightmapNE = heightmapSW; - heightmapSW = i_140_; + heightmapSW = tmp; } else if (rotation == 3) { - int i_141_ = heightmapNW; + int tmp = heightmapNW; heightmapNW = heightmapSW; heightmapSW = heightmapSE; heightmapSE = heightmapNE; - heightmapNE = i_141_; + heightmapNE = tmp; } } + if (kind == 4) { - Entity entity; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, level, x, z, heightmapAverage, rotation * 512, 0, 0, bitset, info); + addWallDecoration(scene, rotation, z, x, locID, level, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 5) { - int i_142_ = 16; - int i_143_ = scene.getWallBitset(level, x, z); - if (i_143_ > 0) { - i_142_ = LocType.get((i_143_ >> 14) & 0x7fff).decorationPadding; - } - Entity entity; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, level, x, z, heightmapAverage, rotation * 512, anIntArray137[rotation] * i_142_, anIntArray144[rotation] * i_142_, bitset, info); + addWallDecorationOutside(scene, rotation, z, x, locID, level, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 6) { - Entity entity; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.setWallDecoration(256, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + addDiagonalWallDecorationInside(z, scene, level, x, locID, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 7) { - Entity entity; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.setWallDecoration(512, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + addDiagonalWallDecorationOutside(z, scene, level, x, locID, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 8) { - Entity entity; - if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { - entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); - } else { - entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); - } - scene.setWallDecoration(768, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + addDiagonalWallDecorationBoth(z, scene, level, x, locID, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } } } + private static void addDiagonalWallDecorationBoth(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + scene.setWallDecoration(0x300, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + } + + private static void addDiagonalWallDecorationOutside(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + scene.setWallDecoration(0x200, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + } + + private static void addDiagonalWallDecorationInside(int z, Scene scene, int level, int x, int locID, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + Entity entity; + if ((type.seqID == -1) && (type.overrideTypeIDs == null)) { + entity = type.getModel(4, 0, heightmapSW, heightmapSE, heightmapNE, heightmapNW, -1); + } else { + entity = new LocEntity(locID, 0, 4, heightmapSE, heightmapNE, heightmapSW, heightmapNW, type.seqID, true); + } + scene.setWallDecoration(0x100, entity, level, x, z, heightmapAverage, rotation, 0, 0, bitset, info); + } + public int decimateHSL(int hue, int saturation, int lightness) { if (lightness > 179) { saturation /= 2; @@ -1263,97 +1274,104 @@ public class SceneBuilder { return ((hue / 4) << 10) + ((saturation / 32) << 7) + (lightness / 2); } - public void method179(int i, int i_162_, SceneCollisionMap[] collisionMaps, int i_164_, int i_165_, byte[] is, int i_166_, int i_167_, int i_168_) { - for (int i_169_ = 0; i_169_ < 8; i_169_++) { - for (int i_170_ = 0; i_170_ < 8; i_170_++) { - if (((i_164_ + i_169_) > 0) && ((i_164_ + i_169_) < 103) && ((i_168_ + i_170_) > 0) && ((i_168_ + i_170_) < 103)) { - collisionMaps[i_167_].flags[i_164_ + i_169_][i_168_ + i_170_] &= ~0x1000000; + public void readChunkTiles(SceneCollisionMap[] collisionMaps, byte[] data, int chunkX, int chunkZ, int mapLevel, int chunkRotation, int originX, int originZ, int level) { + for (int dx = 0; dx < 8; dx++) { + for (int dz = 0; dz < 8; dz++) { + if (((originX + dx) > 0) && ((originX + dx) < 103) && ((originZ + dz) > 0) && ((originZ + dz) < 103)) { + collisionMaps[level].flags[originX + dx][originZ + dz] &= ~0x1000000; } } } - Buffer buffer = new Buffer(is); - for (int i_172_ = 0; i_172_ < 4; i_172_++) { - for (int i_173_ = 0; i_173_ < 64; i_173_++) { - for (int i_174_ = 0; i_174_ < 64; i_174_++) { - if ((i_172_ == i) && (i_173_ >= i_165_) && (i_173_ < (i_165_ + 8)) && (i_174_ >= i_166_) && (i_174_ < (i_166_ + 8))) { - method181(i_168_ + ZoneUtil.method156(i_174_ & 0x7, i_162_, i_173_ & 0x7), 0, buffer, i_164_ + ZoneUtil.method155(i_162_, i_174_ & 0x7, i_173_ & 0x7), i_167_, i_162_, 0); + Buffer in = new Buffer(data); + for (int l = 0; l < 4; l++) { + for (int x = 0; x < 64; x++) { + for (int z = 0; z < 64; z++) { + if ((l == mapLevel) && (x >= chunkX) && (x < (chunkX + 8)) && (z >= chunkZ) && (z < (chunkZ + 8))) { + readTiles(in, 0, 0, level, originX + MapUtil.rotateX(x & 0x7, z & 0x7, chunkRotation), originZ + MapUtil.rotateZ(x & 0x7, z & 0x7, chunkRotation), chunkRotation); } else { - method181(-1, 0, buffer, -1, 0, 0, 0); + readTiles(in, 0, 0, 0, -1, -1, 0); } } } } } - public void method180(byte[] is, int i, int i_175_, int i_176_, int i_177_, SceneCollisionMap[] collisionMaps) { - for (int i_179_ = 0; i_179_ < 4; i_179_++) { - for (int i_180_ = 0; i_180_ < 64; i_180_++) { - for (int i_181_ = 0; i_181_ < 64; i_181_++) { - if (((i_175_ + i_180_) > 0) && ((i_175_ + i_180_) < 103) && ((i + i_181_) > 0) && ((i + i_181_) < 103)) { - collisionMaps[i_179_].flags[i_175_ + i_180_][i + i_181_] &= ~0x1000000; + public void readTiles(byte[] data, int offsetZ, int offsetX, int originX, int originZ, SceneCollisionMap[] collisionMaps) { + for (int level = 0; level < 4; level++) { + for (int x = 0; x < 64; x++) { + for (int z = 0; z < 64; z++) { + if (((offsetX + x) > 0) && ((offsetX + x) < 103) && ((offsetZ + z) > 0) && ((offsetZ + z) < 103)) { + collisionMaps[level].flags[offsetX + x][offsetZ + z] &= ~0x1000000; } } } } - Buffer buffer = new Buffer(is); - for (int i_182_ = 0; i_182_ < 4; i_182_++) { - for (int i_183_ = 0; i_183_ < 64; i_183_++) { - for (int i_184_ = 0; i_184_ < 64; i_184_++) { - method181(i_184_ + i, i_177_, buffer, i_183_ + i_175_, i_182_, 0, i_176_); + + Buffer in = new Buffer(data); + for (int level = 0; level < 4; level++) { + for (int x = 0; x < 64; x++) { + for (int z = 0; z < 64; z++) { + readTiles(in, originX, originZ, level, x + offsetX, z + offsetZ, 0); } } } } - public void method181(int i, int i_185_, Buffer buffer, int i_186_, int i_187_, int i_188_, int i_190_) { - if ((i_186_ >= 0) && (i_186_ < 104) && (i >= 0) && (i < 104)) { - levelTileFlags[i_187_][i_186_][i] = (byte) 0; + public void readTiles(Buffer in, int originX, int originZ, int level, int x, int z, int mapRotation) { + if ((x >= 0) && (x < 104) && (z >= 0) && (z < 104)) { + levelTileFlags[level][x][z] = (byte) 0; + for (; ; ) { - int i_191_ = buffer.read8U(); - if (i_191_ == 0) { - if (i_187_ == 0) { - levelHeightmap[0][i_186_][i] = -method172(932731 + i_186_ + i_190_, 556238 + i + i_185_) * 8; + int type = in.read8U(); + + if (type == 0) { + if (level == 0) { + levelHeightmap[0][x][z] = -perlin(932731 + x + originX, 556238 + z + originZ) * 8; } else { - levelHeightmap[i_187_][i_186_][i] = levelHeightmap[i_187_ - 1][i_186_][i] - 240; + levelHeightmap[level][x][z] = levelHeightmap[level - 1][x][z] - 240; break; } break; } - if (i_191_ == 1) { - int i_192_ = buffer.read8U(); - if (i_192_ == 1) { - i_192_ = 0; + + if (type == 1) { + int height = in.read8U(); + + if (height == 1) { + height = 0; } - if (i_187_ == 0) { - levelHeightmap[0][i_186_][i] = -i_192_ * 8; + + if (level == 0) { + levelHeightmap[0][x][z] = -height * 8; } else { - levelHeightmap[i_187_][i_186_][i] = levelHeightmap[i_187_ - 1][i_186_][i] - (i_192_ * 8); + levelHeightmap[level][x][z] = levelHeightmap[level - 1][x][z] - (height * 8); break; } break; } - if (i_191_ <= 49) { - levelTileOverlayIDs[i_187_][i_186_][i] = buffer.read(); - levelTileOverlayShape[i_187_][i_186_][i] = (byte) ((i_191_ - 2) / 4); - levelTileOverlayRotation[i_187_][i_186_][i] = (byte) (((i_191_ - 2) + i_188_) & 0x3); - } else if (i_191_ <= 81) { - levelTileFlags[i_187_][i_186_][i] = (byte) (i_191_ - 49); + + if (type <= 49) { + levelTileOverlayIDs[level][x][z] = in.read(); + levelTileOverlayShape[level][x][z] = (byte) ((type - 2) / 4); + levelTileOverlayRotation[level][x][z] = (byte) (((type - 2) + mapRotation) & 0x3); + } else if (type <= 81) { + levelTileFlags[level][x][z] = (byte) (type - 49); } else { - levelTileUnderlayIDs[i_187_][i_186_][i] = (byte) (i_191_ - 81); + levelTileUnderlayIDs[level][x][z] = (byte) (type - 81); } } } else { for (; ; ) { - int i_193_ = buffer.read8U(); - if (i_193_ == 0) { + int type = in.read8U(); + if (type == 0) { break; } - if (i_193_ == 1) { - buffer.read8U(); + if (type == 1) { + in.read8U(); break; } - if (i_193_ <= 49) { - buffer.read8U(); + if (type <= 49) { + in.read8U(); } } } @@ -1369,44 +1387,62 @@ public class SceneBuilder { return level; } - public void method183(SceneCollisionMap[] collisionMaps, Scene scene, int i, int i_197_, int i_198_, int i_199_, byte[] is, int i_200_, int i_201_, int i_202_) { - Buffer buffer = new Buffer(is); - int i_203_ = -1; - for (; ; ) { - int i_204_ = buffer.readSmartU(); - if (i_204_ == 0) { + public void readChunkLocs(SceneCollisionMap[] collisionMaps, Scene scene, int mapLevel, int mapRotation, int mapChunkX, int mapChunkZ, int originX, int originZ, byte[] data, int level) { + Buffer in = new Buffer(data); + int locID = -1; + + while (true) { + int deltaID = in.readSmartU(); + + if (deltaID == 0) { break; } - i_203_ += i_204_; - int i_205_ = 0; - for (; ; ) { - int i_206_ = buffer.readSmartU(); - if (i_206_ == 0) { + + locID += deltaID; + + int locData = 0; + + while (true) { + int deltaData = in.readSmartU(); + + if (deltaData == 0) { break; } - i_205_ += i_206_ - 1; - int i_207_ = i_205_ & 0x3f; - int i_208_ = (i_205_ >> 6) & 0x3f; - int i_209_ = i_205_ >> 12; - int i_210_ = buffer.read8U(); - int i_211_ = i_210_ >> 2; - int i_212_ = i_210_ & 0x3; - if ((i_209_ == i) && (i_208_ >= i_200_) && (i_208_ < (i_200_ + 8)) && (i_207_ >= i_198_) && (i_207_ < (i_198_ + 8))) { - LocType type = LocType.get(i_203_); - int i_213_ = i_197_ + ZoneUtil.method157(i_201_, type.length, i_208_ & 0x7, i_207_ & 0x7, type.width); - int i_214_ = i_202_ + ZoneUtil.method158(i_207_ & 0x7, type.length, i_201_, type.width, i_208_ & 0x7); - if ((i_213_ > 0) && (i_214_ > 0) && (i_213_ < 103) && (i_214_ < 103)) { - int i_215_ = i_209_; - if ((levelTileFlags[1][i_213_][i_214_] & 0x2) == 2) { - i_215_--; - } - SceneCollisionMap collisionMap = null; - if (i_215_ >= 0) { - collisionMap = collisionMaps[i_215_]; - } - method175(i_214_, scene, collisionMap, i_211_, i_199_, i_213_, i_203_, (i_212_ + i_201_) & 0x3); - } + + locData += deltaData - 1; + + int locZ = locData & 0x3f; + int locX = (locData >> 6) & 0x3f; + int locLevel = locData >> 12; + int locInfo = in.read8U(); + int locKind = locInfo >> 2; + int locRotation = locInfo & 0x3; + + if ((locLevel != mapLevel) || (locX < mapChunkX) || (locX >= (mapChunkX + 8)) || (locZ < mapChunkZ) || (locZ >= (mapChunkZ + 8))) { + continue; } + + LocType loc = LocType.get(locID); + int x = originX + MapUtil.rotateLocX(locX & 0x7, locZ & 0x7, loc.sizeX, loc.sizeZ, mapRotation); + int z = originZ + MapUtil.rotateLocZ(locX & 0x7, locZ & 0x7, loc.sizeX, loc.sizeZ, mapRotation); + + if ((x <= 0) || (z <= 0) || (x >= 103) || (z >= 103)) { + continue; + } + + int collisionLevel = locLevel; + + if ((levelTileFlags[1][x][z] & 0x2) == 2) { + collisionLevel--; + } + + SceneCollisionMap collisionMap = null; + + if (collisionLevel >= 0) { + collisionMap = collisionMaps[collisionLevel]; + } + + addLoc(scene, collisionMap, locID, locKind, (locRotation + mapRotation) & 0x3, level, x, z); } } } @@ -1437,40 +1473,50 @@ public class SceneBuilder { return (hsl & 0xff80) + scalar; } - public void method190(int i, SceneCollisionMap[] collisionMaps, int i_263_, Scene scene, byte[] is) { - Buffer buffer = new Buffer(is); - int i_265_ = -1; + public void readLocs(SceneCollisionMap[] collisionMaps, Scene scene, int originX, int originZ, byte[] data) { + Buffer in = new Buffer(data); + int locID = -1; for (; ; ) { - int i_266_ = buffer.readSmartU(); - if (i_266_ == 0) { + int deltaID = in.readSmartU(); + + if (deltaID == 0) { break; } - i_265_ += i_266_; - int i_267_ = 0; + + locID += deltaID; + int locData = 0; + for (; ; ) { - int i_268_ = buffer.readSmartU(); - if (i_268_ == 0) { + int deltaData = in.readSmartU(); + + if (deltaData == 0) { break; } - i_267_ += i_268_ - 1; - int i_269_ = i_267_ & 0x3f; - int i_270_ = (i_267_ >> 6) & 0x3f; - int i_271_ = i_267_ >> 12; - int i_272_ = buffer.read8U(); - int i_273_ = i_272_ >> 2; - int i_274_ = i_272_ & 0x3; - int i_275_ = i_270_ + i; - int i_276_ = i_269_ + i_263_; - if ((i_275_ > 0) && (i_276_ > 0) && (i_275_ < 103) && (i_276_ < 103)) { - int i_277_ = i_271_; - if ((levelTileFlags[1][i_275_][i_276_] & 0x2) == 2) { - i_277_--; + + locData += deltaData - 1; + int locZ = locData & 0x3f; + int locX = (locData >> 6) & 0x3f; + int locLevel = locData >> 12; + int locInfo = in.read8U(); + int locKind = locInfo >> 2; + int locRotation = locInfo & 0x3; + int x = locX + originX; + int z = locZ + originZ; + + if ((x > 0) && (z > 0) && (x < 103) && (z < 103)) { + int collisionLevel = locLevel; + + if ((levelTileFlags[1][x][z] & 0x2) == 2) { + collisionLevel--; } + SceneCollisionMap collisionMap = null; - if (i_277_ >= 0) { - collisionMap = collisionMaps[i_277_]; + + if (collisionLevel >= 0) { + collisionMap = collisionMaps[collisionLevel]; } - method175(i_276_, scene, collisionMap, i_273_, i_271_, i_275_, i_265_, i_274_); + + addLoc(scene, collisionMap, locID, locKind, locRotation, locLevel, x, z); } } } diff --git a/src/main/java/SceneTile.java b/src/main/java/SceneTile.java index 1d4c898..e4c42af 100644 --- a/src/main/java/SceneTile.java +++ b/src/main/java/SceneTile.java @@ -6,10 +6,13 @@ public class SceneTile extends DoublyLinkedList.Node { public final int x; public final int z; - public final int level; + /** + * Which level to sample when testing against this tile for occlusion. + */ + public final int occludeLevel; public final SceneLoc[] locs = new SceneLoc[5]; public final int[] locSpan = new int[5]; - public int dataLevel; + public int level; public SceneTileUnderlay underlay; public SceneTileOverlay overlay; public SceneWall wall; @@ -17,23 +20,32 @@ public class SceneTile extends DoublyLinkedList.Node { public SceneGroundDecoration groundDecoration; public SceneObjStack objStack; public int locCount; - public int spans; + /** + * When larger than 1x1 locs reside on a tile, we have to know which part of it might be on this tile to properly + * cull it. + *

+ * 0b0001 = x > loc.minSceneTileX + * 0b0010 = z < loc.maxSceneTileZ + * 0b0100 = x < loc.maxSceneTileX + * 0b1000 = z > loc.minSceneTileZ + */ + public int locSpans; /** * Used as a short circuit to prevent drawing tiles above the top level. Mostly applies to lowmem. * @see Scene#draw(int, int, int, int, int, int) */ public int drawLevel; - public boolean drawable; + public boolean visible; public boolean update; public boolean containsLocs; - public int anInt1325; - public int anInt1326; - public int anInt1327; - public int anInt1328; + public int checkLocSpans; + public int blockLocSpans; + public int inverseBlockLocSpans; + public int allowWallTypes; public SceneTile bridge; public SceneTile(int level, int x, int z) { - this.level = dataLevel = level; + this.occludeLevel = this.level = level; this.x = x; this.z = z; } diff --git a/src/main/java/SceneWallDecoration.java b/src/main/java/SceneWallDecoration.java index 55395be..140c382 100644 --- a/src/main/java/SceneWallDecoration.java +++ b/src/main/java/SceneWallDecoration.java @@ -3,8 +3,8 @@ public class SceneWallDecoration { public int y; public int x; public int z; - public int occlude; - public int yaw; + public int type; + public int rotation; public Entity entity; public int bitset; public byte info; diff --git a/src/main/java/SeqType.java b/src/main/java/SeqType.java index 6fd8a9d..b200a23 100644 --- a/src/main/java/SeqType.java +++ b/src/main/java/SeqType.java @@ -58,7 +58,7 @@ public class SeqType { /** * Adds additional space to the render bounds. - * @see Scene#addTemporary(Entity, int, int, int, int, int, int, boolean, int) + * @see Scene#pushTemporary(Entity, int, int, int, int, int, int, boolean, int) */ public boolean forwardRenderPadding = false; diff --git a/src/main/java/ZoneUtil.java b/src/main/java/ZoneUtil.java deleted file mode 100644 index 594aabd..0000000 --- a/src/main/java/ZoneUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov. -// Jad home page: http://www.kpdus.com/jad.html -// Decompiler options: packimports(3) - -public class ZoneUtil { - - public static int method155(int i, int j, int k) { - i &= 3; - if (i == 0) { - return k; - } - if (i == 1) { - return j; - } - if (i == 2) { - return 7 - k; - } else { - return 7 - j; - } - } - - public static int method156(int i, int j, int l) { - j &= 3; - if (j == 0) { - return i; - } - if (j == 1) { - return 7 - l; - } - if (j == 2) { - return 7 - i; - } else { - return l; - } - } - - public static int method157(int i, int j, int k, int l, int i1) { - i &= 3; - if (i == 0) { - return k; - } - if (i == 1) { - return l; - } - if (i == 2) { - return 7 - k - (i1 - 1); - } else { - return 7 - l - (j - 1); - } - } - - public static int method158(int j, int k, int l, int i1, int j1) { - l &= 3; - if (l == 0) { - return j; - } - if (l == 1) { - return 7 - j1 - (i1 - 1); - } - if (l == 2) { - return 7 - j - (k - 1); - } else { - return j1; - } - } - -}