From eb802eccd374f7808f6ac76fcc0f41fc49ad6e32 Mon Sep 17 00:00:00 2001 From: thedaneeffect Date: Fri, 6 Jan 2023 17:21:55 -0500 Subject: [PATCH] Reverted: Occluder Threshold Constants: LocType Type --- src/main/java/LocType.java | 932 ++++++++++++++++---------------- src/main/java/Scene.java | 192 +++---- src/main/java/SceneBuilder.java | 148 ++--- src/main/java/SceneTile.java | 2 +- 4 files changed, 624 insertions(+), 650 deletions(-) diff --git a/src/main/java/LocType.java b/src/main/java/LocType.java index 20ea881..85e639d 100644 --- a/src/main/java/LocType.java +++ b/src/main/java/LocType.java @@ -8,528 +8,552 @@ import java.io.IOException; public class LocType { - public static final Model[] TMP_MODELS = new Model[4]; - public static boolean lowmem; - public static Buffer dat; - public static int[] offsets; - public static int count; - public static Game game; - public static int anInt771; - /** - * This is where dynamically generated models go. - */ - public static LRUMap modelCacheDynamic = new LRUMap(30); - public static LocType[] cache; - /** - * This is where basic models go. - */ - public static LRUMap modelCacheStatic = new LRUMap(500); + public static final int TYPE_WALL_STRAIGHT = 0; + public static final int TYPE_WALL_CORNER_DIAGONAL = 1; + public static final int TYPE_WALL_L = 2; + public static final int TYPE_WALL_SQUARE_CORNER = 3; + public static final int TYPE_WALLDECOR_STRAIGHT = 4; + public static final int TYPE_WALLDECOR_STRAIGHT_OFFSET = 5; + public static final int TYPE_WALLDECOR_DIAGONAL_NOOFFSET = 6; + public static final int TYPE_WALLDECOR_DIAGONAL_OFFSET = 7; + public static final int TYPE_WALLDECOR_DIAGONAL_BOTH = 8; + public static final int TYPE_WALL_DIAGONAL = 9; + public static final int TYPE_CENTREPIECE = 10; + public static final int TYPE_CENTREPIECE_DIAGONAL = 11; + public static final int TYPE_ROOF_STRAIGHT = 12; + public static final int TYPE_ROOF_DIAGONAL = 13; + public static final int TYPE_ROOF_DIAGONAL_WITH_ROOFEDGE = 14; + public static final int TYPE_ROOF_L_CONCAVE = 15; + public static final int TYPE_ROOF_L_CONVEX = 16; + public static final int TYPE_ROOF_FLAT = 17; + public static final int TYPE_ROOFEDGE_STRAIGHT = 18; + public static final int TYPE_ROOFEDGE_DIAGONALCORNER = 19; + public static final int TYPE_ROOFEDGE_L = 20; + public static final int TYPE_ROOFEDGE_SQUARECORNER = 21; + public static final int TYPE_GROUND_DECOR = 22; - public static LocType get(int i) { - if (i >= count) { - i = 0; + public static final Model[] TMP_MODELS = new Model[4]; + public static boolean lowmem; + public static Buffer dat; + public static int[] offsets; + public static int count; + public static Game game; + public static int cachePos; + /** + * This is where dynamically generated models go. + */ + public static LRUMap modelCacheDynamic = new LRUMap(30); + public static LocType[] cache; + /** + * This is where basic models go. + */ + public static LRUMap modelCacheStatic = new LRUMap(500); + + public static LocType get(int locID) { + if (locID >= count) { + locID = 0; + } + for (int i = 0; i < 20; i++) { + if (cache[i].index == locID) { + return cache[i]; + } + } + cachePos = (cachePos + 1) % 20; + LocType type = cache[cachePos]; + dat.position = offsets[locID]; + type.index = locID; + type.reset(); + type.method582(dat); + return type; } - for (int j = 0; j < 20; j++) { - if (cache[j].index == i) { - return cache[j]; + + public static void unload() { + modelCacheStatic = null; + modelCacheDynamic = null; + offsets = null; + cache = null; + dat = null; + } + + public static void unpack(FileArchive archive) throws IOException { + dat = new Buffer(archive.read("loc.dat")); + Buffer buffer = new Buffer(archive.read("loc.idx")); + count = buffer.read16U(); + offsets = new int[count]; + int offset = 2; + for (int j = 0; j < count; j++) { + offsets[j] = offset; + offset += buffer.read16U(); + } + cache = new LocType[20]; + for (int i = 0; i < 20; i++) { + cache[i] = new LocType(); } } - anInt771 = (anInt771 + 1) % 20; - LocType type = cache[anInt771]; - dat.position = offsets[i]; - type.index = i; - type.reset(); - type.method582(dat); - return type; - } - public static void unload() { - modelCacheStatic = null; - modelCacheDynamic = null; - offsets = null; - cache = null; - dat = null; - } + public boolean important; + public byte lightAmbient; + public int translateX; + public String name; + public int scaleY; + public byte lightAttenuation; + public int sizeX; + public int translateY; + public int mapfunctionIcon; + public int[] dstColor; + public int scaleX; + public int varp; + public boolean invert; + public int index = -1; + public boolean blocksProjectiles; + public int mapsceneIcon; + public int[] overrideTypeIDs; + public int supportsObj; + public int sizeZ; + public boolean adjustToTerrain; + public boolean occludes; + public boolean decorative; + public boolean solid; + public int interactionSideFlags; + /** + * Models flagged as dynamic will always copy their models face information by making copyFaces + * equal true. + * + * @see Model#Model(boolean, boolean, Model) + */ + public boolean dynamic; + public int scaleZ; + public int[] modelIDs; + public int varbit; + public int decorOffset; + public int[] modelKinds; + public String description; + public boolean interactable; + public boolean castShadow; + public int seqID; + public int translateZ; + public int[] srcColor; + public String[] actions; - public static void unpack(FileArchive archive) throws IOException { - dat = new Buffer(archive.read("loc.dat")); - Buffer buffer = new Buffer(archive.read("loc.idx")); - count = buffer.read16U(); - offsets = new int[count]; - int i = 2; - for (int j = 0; j < count; j++) { - offsets[j] = i; - i += buffer.read16U(); + public LocType() { } - cache = new LocType[20]; - for (int k = 0; k < 20; k++) { - cache[k] = new LocType(); + + public void reset() { + modelIDs = null; + modelKinds = null; + name = null; + description = null; + srcColor = null; + dstColor = null; + sizeX = 1; + sizeZ = 1; + solid = true; + blocksProjectiles = true; + interactable = false; + adjustToTerrain = false; + dynamic = false; + occludes = false; + seqID = -1; + decorOffset = 16; + lightAmbient = 0; + lightAttenuation = 0; + actions = null; + mapfunctionIcon = -1; + mapsceneIcon = -1; + invert = false; + castShadow = true; + scaleX = 128; + scaleZ = 128; + scaleY = 128; + interactionSideFlags = 0; + translateX = 0; + translateY = 0; + translateZ = 0; + important = false; + decorative = false; + supportsObj = -1; + varbit = -1; + varp = -1; + overrideTypeIDs = null; } - } - public boolean important; - public byte lightAmbient; - public int translateX; - public String name; - public int scaleY; - public byte lightAttenuation; - public int sizeX; - public int translateY; - public int mapfunctionIcon; - public int[] dstColor; - public int scaleX; - public int varp; - public boolean invert; - public int index = -1; - public boolean blocksProjectiles; - public int mapsceneIcon; - public int[] overrideTypeIDs; - public int supportsObj; - public int sizeZ; - public boolean adjustToTerrain; - public boolean occludes; - public boolean decorative; - public boolean solid; - public int interactionSideFlags; - /** - * Models flagged as dynamic will always copy their models face information by making copyFaces - * equal true. - * - * @see Model#Model(boolean, boolean, Model) - */ - public boolean dynamic; - public int scaleZ; - public int[] modelIDs; - public int varbit; - public int decorationPadding; - public int[] modelKinds; - public String description; - public boolean interactable; - public boolean castShadow; - public int seqID; - public int translateZ; - public int[] srcColor; - public String[] actions; - - public LocType() { - } - - public void reset() { - modelIDs = null; - modelKinds = null; - name = null; - description = null; - srcColor = null; - dstColor = null; - sizeX = 1; - sizeZ = 1; - solid = true; - blocksProjectiles = true; - interactable = false; - adjustToTerrain = false; - dynamic = false; - occludes = false; - seqID = -1; - decorationPadding = 16; - lightAmbient = 0; - lightAttenuation = 0; - actions = null; - mapfunctionIcon = -1; - mapsceneIcon = -1; - invert = false; - castShadow = true; - scaleX = 128; - scaleZ = 128; - scaleY = 128; - interactionSideFlags = 0; - translateX = 0; - translateY = 0; - translateZ = 0; - important = false; - decorative = false; - supportsObj = -1; - varbit = -1; - varp = -1; - overrideTypeIDs = null; - } - - public void prefetch(OnDemand onDemand) { - if (modelIDs == null) { - return; - } - for (int modelID : modelIDs) { - onDemand.prefetch(modelID & 0xffff, 0); - } - } - - public boolean validate(int kind) { - if (modelKinds == null) { + public void prefetch(OnDemand onDemand) { if (modelIDs == null) { - return true; + return; } - if (kind != 10) { - return true; - } - boolean valid = true; for (int modelID : modelIDs) { - valid &= Model.validate(modelID & 0xffff); - } - return valid; - } - for (int i = 0; i < modelKinds.length; i++) { - if (modelKinds[i] == kind) { - return Model.validate(modelIDs[i] & 0xffff); + onDemand.prefetch(modelID & 0xffff, 0); } } - return true; - } - public Model getModel(int kind, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int transformID) { - Model model = getModel(kind, transformID, rotation); - - if (model == null) { - return null; - } - - if (adjustToTerrain || dynamic) { - model = new Model(adjustToTerrain, dynamic, model); - } - - if (adjustToTerrain) { - int groundY = (heightmapSW + heightmapSE + heightmapNE + heightmapNW) / 4; - for (int i = 0; i < model.vertexCount; i++) { - int x = model.vertexX[i]; - int z = model.vertexZ[i]; - int heightS = heightmapSW + (((heightmapSE - heightmapSW) * (x + 64)) / 128); - int heightN = heightmapNW + (((heightmapNE - heightmapNW) * (x + 64)) / 128); - int y = heightS + (((heightN - heightS) * (z + 64)) / 128); - model.vertexY[i] += y - groundY; + public boolean validate(int kind) { + if (modelKinds == null) { + if (modelIDs == null) { + return true; + } + if (kind != 10) { + return true; + } + boolean valid = true; + for (int modelID : modelIDs) { + valid &= Model.validate(modelID & 0xffff); + } + return valid; + } + for (int i = 0; i < modelKinds.length; i++) { + if (modelKinds[i] == kind) { + return Model.validate(modelIDs[i] & 0xffff); + } } - model.calculateBoundsY(); - } - return model; - } - - public boolean validate() { - if (modelIDs == null) { return true; } - boolean ok = true; - for (int modelID : modelIDs) { - ok &= Model.validate(modelID & 0xffff); - } - return ok; - } - public LocType getOverrideType() { - int value = -1; + public Model getModel(int kind, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int transformID) { + Model model = getModel(kind, transformID, rotation); - if (varbit != -1) { - VarbitType varbit = VarbitType.instances[this.varbit]; - int varp = varbit.varp; - int low = varbit.lsb; - int high = varbit.msb; - int mask = Game.BITMASK[high - low]; - value = (game.varps[varp] >> low) & mask; - } else if (varp != -1) { - value = game.varps[varp]; - } - - if ((value < 0) || (value >= overrideTypeIDs.length) || (overrideTypeIDs[value] == -1)) { - return null; - } else { - return get(overrideTypeIDs[value]); - } - } - - public Model getModel(int kind, int transformID, int rotation) { - Model model = null; - long bitset; - - if (modelKinds == null) { - if (kind != 10) { + if (model == null) { return null; } - bitset = ((long) index << 6) + rotation + ((long) (transformID + 1) << 32); - Model cached = modelCacheDynamic.get(bitset); - - if (cached != null) { - return cached; + if (adjustToTerrain || dynamic) { + model = new Model(adjustToTerrain, dynamic, model); } + if (adjustToTerrain) { + int groundY = (heightmapSW + heightmapSE + heightmapNE + heightmapNW) / 4; + for (int i = 0; i < model.vertexCount; i++) { + int x = model.vertexX[i]; + int z = model.vertexZ[i]; + int heightS = heightmapSW + (((heightmapSE - heightmapSW) * (x + 64)) / 128); + int heightN = heightmapNW + (((heightmapNE - heightmapNW) * (x + 64)) / 128); + int y = heightS + (((heightN - heightS) * (z + 64)) / 128); + model.vertexY[i] += y - groundY; + } + model.calculateBoundsY(); + } + return model; + } + + public boolean validate() { if (modelIDs == null) { - return null; + return true; + } + boolean ok = true; + for (int modelID : modelIDs) { + ok &= Model.validate(modelID & 0xffff); + } + return ok; + } + + public LocType getOverrideType() { + int value = -1; + + if (varbit != -1) { + VarbitType varbit = VarbitType.instances[this.varbit]; + int varp = varbit.varp; + int low = varbit.lsb; + int high = varbit.msb; + int mask = Game.BITMASK[high - low]; + value = (game.varps[varp] >> low) & mask; + } else if (varp != -1) { + value = game.varps[varp]; } - boolean flip = invert ^ (rotation > 3); - int modelCount = modelIDs.length; + if ((value < 0) || (value >= overrideTypeIDs.length) || (overrideTypeIDs[value] == -1)) { + return null; + } else { + return get(overrideTypeIDs[value]); + } + } - for (int i = 0; i < modelCount; i++) { - int modelID = modelIDs[i]; + public Model getModel(int kind, int transformID, int rotation) { + Model model = null; + long bitset; + + if (modelKinds == null) { + if (kind != 10) { + return null; + } + + bitset = ((long) index << 6) + rotation + ((long) (transformID + 1) << 32); + Model cached = modelCacheDynamic.get(bitset); + + if (cached != null) { + return cached; + } + + if (modelIDs == null) { + return null; + } + + boolean flip = invert ^ (rotation > 3); + int modelCount = modelIDs.length; + + for (int i = 0; i < modelCount; i++) { + int modelID = modelIDs[i]; + + if (flip) { + modelID += 0x10000; + } + + model = modelCacheStatic.get(modelID); + if (model == null) { + model = Model.tryGet(modelID & 0xffff); + if (model == null) { + return null; + } + if (flip) { + model.rotateY180(); + } + modelCacheStatic.put((long) modelID, model); + } + + if (modelCount > 1) { + TMP_MODELS[i] = model; + } + } + + if (modelCount > 1) { + model = new Model(modelCount, TMP_MODELS); + } + } else { + int kindIndex = -1; + + for (int i = 0; i < modelKinds.length; i++) { + if (modelKinds[i] != kind) { + continue; + } + kindIndex = i; + break; + } + + if (kindIndex == -1) { + return null; + } + + bitset = ((long) this.index << 6) + ((long) kindIndex << 3) + rotation + ((long) (transformID + 1) << 32); + + Model cached = modelCacheDynamic.get(bitset); + + if (cached != null) { + return cached; + } + + int modelID = modelIDs[kindIndex]; + boolean flip = invert ^ (rotation > 3); if (flip) { modelID += 0x10000; } model = modelCacheStatic.get(modelID); + if (model == null) { model = Model.tryGet(modelID & 0xffff); + if (model == null) { return null; } + if (flip) { model.rotateY180(); } + modelCacheStatic.put((long) modelID, model); } + } - if (modelCount > 1) { - TMP_MODELS[i] = model; + boolean scaled = (scaleX != 128) || (scaleZ != 128) || (scaleY != 128); + boolean translated = (translateX != 0) || (translateY != 0) || (translateZ != 0); + + Model modified = new Model(srcColor == null, SeqTransform.isNull(transformID), (rotation == 0) && (transformID == -1) && !scaled && !translated, model); + + if (transformID != -1) { + modified.createLabelReferences(); + modified.applyTransform(transformID); + modified.labelFaces = null; + modified.labelVertices = null; + } + + while (rotation-- > 0) { + modified.rotateY90(); + } + + if (srcColor != null) { + for (int k2 = 0; k2 < srcColor.length; k2++) { + modified.recolor(srcColor[k2], dstColor[k2]); } } - if (modelCount > 1) { - model = new Model(modelCount, TMP_MODELS); - } - } else { - int kindIndex = -1; - - for (int i = 0; i < modelKinds.length; i++) { - if (modelKinds[i] != kind) { - continue; - } - kindIndex = i; - break; + if (scaled) { + modified.scale(scaleX, scaleY, scaleZ); } - if (kindIndex == -1) { - return null; + if (translated) { + modified.translate(translateX, translateY, translateZ); } - bitset = ((long) this.index << 6) + ((long) kindIndex << 3) + rotation + ((long) (transformID + 1) << 32); + modified.calculateNormals(64 + lightAmbient, 768 + (lightAttenuation * 5), -50, -10, -50, !dynamic); - Model cached = modelCacheDynamic.get(bitset); - - if (cached != null) { - return cached; + if (supportsObj == 1) { + modified.objRaise = modified.minY; } - int modelID = modelIDs[kindIndex]; - boolean flip = invert ^ (rotation > 3); - - if (flip) { - modelID += 0x10000; - } - - model = modelCacheStatic.get(modelID); - - if (model == null) { - model = Model.tryGet(modelID & 0xffff); - - if (model == null) { - return null; - } - - if (flip) { - model.rotateY180(); - } - - modelCacheStatic.put((long) modelID, model); - } + modelCacheDynamic.put(bitset, modified); + return modified; } - boolean scaled = (scaleX != 128) || (scaleZ != 128) || (scaleY != 128); - boolean translated = (translateX != 0) || (translateY != 0) || (translateZ != 0); - - Model modified = new Model(srcColor == null, SeqTransform.isNull(transformID), (rotation == 0) && (transformID == -1) && !scaled && !translated, model); - - if (transformID != -1) { - modified.createLabelReferences(); - modified.applyTransform(transformID); - modified.labelFaces = null; - modified.labelVertices = null; - } - - while (rotation-- > 0) { - modified.rotateY90(); - } - - if (srcColor != null) { - for (int k2 = 0; k2 < srcColor.length; k2++) { - modified.recolor(srcColor[k2], dstColor[k2]); - } - } - - if (scaled) { - modified.scale(scaleX, scaleY, scaleZ); - } - - if (translated) { - modified.translate(translateX, translateY, translateZ); - } - - modified.calculateNormals(64 + lightAmbient, 768 + (lightAttenuation * 5), -50, -10, -50, !dynamic); - - if (supportsObj == 1) { - modified.objRaise = modified.minY; - } - - modelCacheDynamic.put(bitset, modified); - return modified; - } - - public void method582(Buffer buffer) { - int i = -1; - label0: - do { - int j; + public void method582(Buffer buffer) { + int i = -1; + label0: do { - j = buffer.read8U(); - if (j == 0) { - break label0; - } - if (j == 1) { - int k = buffer.read8U(); - if (k > 0) { - if ((modelIDs == null) || lowmem) { - modelKinds = new int[k]; - modelIDs = new int[k]; - for (int k1 = 0; k1 < k; k1++) { - modelIDs[k1] = buffer.read16U(); - modelKinds[k1] = buffer.read8U(); + int j; + do { + j = buffer.read8U(); + if (j == 0) { + break label0; + } + if (j == 1) { + int k = buffer.read8U(); + if (k > 0) { + if ((modelIDs == null) || lowmem) { + modelKinds = new int[k]; + modelIDs = new int[k]; + for (int k1 = 0; k1 < k; k1++) { + modelIDs[k1] = buffer.read16U(); + modelKinds[k1] = buffer.read8U(); + } + } else { + buffer.position += k * 3; } - } else { - buffer.position += k * 3; } - } - } else if (j == 2) { - name = buffer.readString(); - } else if (j == 3) { - description = buffer.readString(); - } else if (j == 5) { - int l = buffer.read8U(); - if (l > 0) { - if ((modelIDs == null) || lowmem) { - modelKinds = null; - modelIDs = new int[l]; - for (int l1 = 0; l1 < l; l1++) { - modelIDs[l1] = buffer.read16U(); + } else if (j == 2) { + name = buffer.readString(); + } else if (j == 3) { + description = buffer.readString(); + } else if (j == 5) { + int l = buffer.read8U(); + if (l > 0) { + if ((modelIDs == null) || lowmem) { + modelKinds = null; + modelIDs = new int[l]; + for (int l1 = 0; l1 < l; l1++) { + modelIDs[l1] = buffer.read16U(); + } + } else { + buffer.position += l * 2; } - } else { - buffer.position += l * 2; } + } else if (j == 14) { + sizeX = buffer.read8U(); + } else if (j == 15) { + sizeZ = buffer.read8U(); + } else if (j == 17) { + solid = false; + } else if (j == 18) { + blocksProjectiles = false; + } else if (j == 19) { + i = buffer.read8U(); + if (i == 1) { + interactable = true; + } + } else if (j == 21) { + adjustToTerrain = true; + } else if (j == 22) { + dynamic = true; + } else if (j == 23) { + occludes = true; + } else if (j == 24) { + seqID = buffer.read16U(); + if (seqID == 65535) { + seqID = -1; + } + } else if (j == 28) { + decorOffset = buffer.read8U(); + } else if (j == 29) { + lightAmbient = buffer.read(); + } else if (j == 39) { + lightAttenuation = buffer.read(); + } else if ((j >= 30) && (j < 39)) { + if (actions == null) { + actions = new String[5]; + } + actions[j - 30] = buffer.readString(); + if (actions[j - 30].equalsIgnoreCase("hidden")) { + actions[j - 30] = null; + } + } else if (j == 40) { + int i1 = buffer.read8U(); + srcColor = new int[i1]; + dstColor = new int[i1]; + for (int i2 = 0; i2 < i1; i2++) { + srcColor[i2] = buffer.read16U(); + dstColor[i2] = buffer.read16U(); + } + } else if (j == 60) { + mapfunctionIcon = buffer.read16U(); + } else if (j == 62) { + invert = true; + } else if (j == 64) { + castShadow = false; + } else if (j == 65) { + scaleX = buffer.read16U(); + } else if (j == 66) { + scaleZ = buffer.read16U(); + } else if (j == 67) { + scaleY = buffer.read16U(); + } else if (j == 68) { + mapsceneIcon = buffer.read16U(); + } else if (j == 69) { + interactionSideFlags = buffer.read8U(); + } else if (j == 70) { + translateX = buffer.read16(); + } else if (j == 71) { + translateY = buffer.read16(); + } else if (j == 72) { + translateZ = buffer.read16(); + } else if (j == 73) { + important = true; + } else if (j == 74) { + decorative = true; + } else { + if (j != 75) { + continue; + } + supportsObj = buffer.read8U(); } - } else if (j == 14) { - sizeX = buffer.read8U(); - } else if (j == 15) { - sizeZ = buffer.read8U(); - } else if (j == 17) { - solid = false; - } else if (j == 18) { - blocksProjectiles = false; - } else if (j == 19) { - i = buffer.read8U(); - if (i == 1) { - interactable = true; - } - } else if (j == 21) { - adjustToTerrain = true; - } else if (j == 22) { - dynamic = true; - } else if (j == 23) { - occludes = true; - } else if (j == 24) { - seqID = buffer.read16U(); - if (seqID == 65535) { - seqID = -1; - } - } else if (j == 28) { - decorationPadding = buffer.read8U(); - } else if (j == 29) { - lightAmbient = buffer.read(); - } else if (j == 39) { - lightAttenuation = buffer.read(); - } else if ((j >= 30) && (j < 39)) { - if (actions == null) { - actions = new String[5]; - } - actions[j - 30] = buffer.readString(); - if (actions[j - 30].equalsIgnoreCase("hidden")) { - actions[j - 30] = null; - } - } else if (j == 40) { - int i1 = buffer.read8U(); - srcColor = new int[i1]; - dstColor = new int[i1]; - for (int i2 = 0; i2 < i1; i2++) { - srcColor[i2] = buffer.read16U(); - dstColor[i2] = buffer.read16U(); - } - } else if (j == 60) { - mapfunctionIcon = buffer.read16U(); - } else if (j == 62) { - invert = true; - } else if (j == 64) { - castShadow = false; - } else if (j == 65) { - scaleX = buffer.read16U(); - } else if (j == 66) { - scaleZ = buffer.read16U(); - } else if (j == 67) { - scaleY = buffer.read16U(); - } else if (j == 68) { - mapsceneIcon = buffer.read16U(); - } else if (j == 69) { - interactionSideFlags = buffer.read8U(); - } else if (j == 70) { - translateX = buffer.read16(); - } else if (j == 71) { - translateY = buffer.read16(); - } else if (j == 72) { - translateZ = buffer.read16(); - } else if (j == 73) { - important = true; - } else if (j == 74) { - decorative = true; - } else { - if (j != 75) { - continue; - } - supportsObj = buffer.read8U(); + continue label0; + } while (j != 77); + varbit = buffer.read16U(); + if (varbit == 65535) { + varbit = -1; } - continue label0; - } while (j != 77); - varbit = buffer.read16U(); - if (varbit == 65535) { - varbit = -1; - } - varp = buffer.read16U(); - if (varp == 65535) { - varp = -1; - } - int j1 = buffer.read8U(); - overrideTypeIDs = new int[j1 + 1]; - for (int j2 = 0; j2 <= j1; j2++) { - overrideTypeIDs[j2] = buffer.read16U(); - if (overrideTypeIDs[j2] == 65535) { - overrideTypeIDs[j2] = -1; + varp = buffer.read16U(); + if (varp == 65535) { + varp = -1; + } + int j1 = buffer.read8U(); + overrideTypeIDs = new int[j1 + 1]; + for (int j2 = 0; j2 <= j1; j2++) { + overrideTypeIDs[j2] = buffer.read16U(); + if (overrideTypeIDs[j2] == 65535) { + overrideTypeIDs[j2] = -1; + } + } + } while (true); + if (i == -1) { + interactable = (modelIDs != null) && ((modelKinds == null) || (modelKinds[0] == 10)); + if (actions != null) { + interactable = true; } } - } while (true); - if (i == -1) { - interactable = (modelIDs != null) && ((modelKinds == null) || (modelKinds[0] == 10)); - if (actions != null) { - interactable = true; + if (decorative) { + solid = false; + blocksProjectiles = false; + } + if (supportsObj == -1) { + supportsObj = solid ? 1 : 0; } } - if (decorative) { - solid = false; - blocksProjectiles = false; - } - if (supportsObj == -1) { - supportsObj = solid ? 1 : 0; - } - } } diff --git a/src/main/java/Scene.java b/src/main/java/Scene.java index d68d47d..34b0cd0 100644 --- a/src/main/java/Scene.java +++ b/src/main/java/Scene.java @@ -6,10 +6,10 @@ import java.util.Arrays; public class Scene { - public static final int[] DIAGONAL_WALL_DECORATION0_ROTATION_OFFSET_X = {53, -53, -53, 53}; - public static final int[] DIAGONAL_WALL_DECORATION0_ROTATION_OFFSET_Z = {-53, -53, 53, 53}; - public static final int[] DIAGONAL_WALL_DECORATION1_ROTATION_OFFSET_X = {-45, 45, 45, -45}; - public static final int[] DIAGONAL_WALL_DECORATION1_ROTATION_OFFSET_Z = {45, 45, -45, -45}; + public static final int[] WALL_DECORATION_INSET_X = {53, -53, -53, 53}; + public static final int[] WALL_DECORATION_INSET_Z = {-53, -53, 53, 53}; + public static final int[] WALL_DECORATION_OUTSET_X = {-45, 45, 45, -45}; + public static final int[] WALL_DECORATION_OUTSET_Z = {45, 45, -45, -45}; /** * Occlusion flags for walls of kind 0, 2 and decorations 4, 5, */ @@ -28,7 +28,7 @@ public class Scene { 1 << 6, 1 << 7, }; - public static final int[] DIRECTION_ALLOW_WALL_TYPE_PRIMARY = { + public static final int[] FRONT_WALL_TYPES = { 0b00010011, // eyeTileX > tileX && eyeTileZ < tileZ 0b00110111, // eyeTileX == tileX && eyeTileZ < tileZ 0b00100110, // eyeTileX < tileX && eyeTileZ < tileZ @@ -50,7 +50,7 @@ public class Scene { 0b00110000, // eyeTileX = tileX && eyeTileZ > tileZ 0b10100000, // eyeTileX < tileX && eyeTileZ > tileZ }; - public static final int[] DIRECTION_ALLOW_WALL_TYPE_SECONDARY = { + public static final int[] BACK_WALL_TYPES = { 0b01001100, // eyeTileX > tileX && eyeTileZ < tileZ 0b00001000, // eyeTileX == tileX && eyeTileZ < tileZ 0b10001001, // eyeTileX < tileX && eyeTileZ < tileZ @@ -469,25 +469,25 @@ public class Scene { levelTiles[level][tileX][tileZ].wall = wall; } - 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) { + public void setWallDecoration(int type, Entity entity, int level, int tileX, int tileZ, int y, int rotation, int offsetX, int offsetZ, int bitset, byte info) { if (entity == null) { return; } - SceneWallDecoration deco = new SceneWallDecoration(); - deco.bitset = bitset; - deco.info = info; - deco.x = (tileX * 128) + 64 + offsetX; - deco.z = (tileZ * 128) + 64 + offsetZ; - deco.y = y; - deco.entity = entity; - deco.type = type; - deco.rotation = yaw; + SceneWallDecoration decor = new SceneWallDecoration(); + decor.bitset = bitset; + decor.info = info; + decor.x = (tileX * 128) + 64 + offsetX; + decor.z = (tileZ * 128) + 64 + offsetZ; + decor.y = y; + decor.entity = entity; + decor.type = type; + decor.rotation = rotation; for (int p = level; p >= 0; p--) { if (levelTiles[p][tileX][tileZ] == null) { levelTiles[p][tileX][tileZ] = new SceneTile(p, tileX, tileZ); } } - levelTiles[level][tileX][tileZ].wallDecoration = deco; + levelTiles[level][tileX][tileZ].wallDecoration = decor; } public boolean add(Entity entity, int level, int tileX, int tileZ, int y, int width, int length, int yaw, int bitset, byte info) { @@ -654,12 +654,12 @@ public class Scene { if (tile == null) { return; } - SceneWallDecoration decoration = tile.wallDecoration; - if (decoration != null) { + SceneWallDecoration decor = tile.wallDecoration; + if (decor != null) { int sx = (stx * 128) + 64; int sz = (stz * 128) + 64; - decoration.x = sx + (((decoration.x - sx) * offset) / 16); - decoration.z = sz + (((decoration.z - sz) * offset) / 16); + decor.x = sx + (((decor.x - sx) * offset) / 16); + decor.z = sz + (((decor.z - sz) * offset) / 16); } } @@ -1366,12 +1366,12 @@ public class Scene { boolean tileDrawn = drawTileUnderlayOrOverlay(tile, tileX, tileZ, occludeLevel); int direction = 0; - int allowWallTypes = 0; + int frontWallTypes = 0; SceneWall wall = tile.wall; - SceneWallDecoration wallDecoration = tile.wallDecoration; + SceneWallDecoration decor = tile.wallDecoration; - if ((wall != null) || (wallDecoration != null)) { + if ((wall != null) || (decor != null)) { if (eyeTileX == tileX) { direction++; } else if (eyeTileX < tileX) { @@ -1384,12 +1384,8 @@ public class Scene { direction += 6; } - // 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]; + frontWallTypes = FRONT_WALL_TYPES[direction]; + tile.backWallTypes = BACK_WALL_TYPES[direction]; } if (wall != null) { @@ -1423,26 +1419,24 @@ public class Scene { tile.checkLocSpans = 0; } - if (((wall.typeA & allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeA)) { + if (((wall.typeA & frontWallTypes) != 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 & allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeB)) { + if (((wall.typeB & frontWallTypes) != 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) { - if (!occluded(occludeLevel, tileX, tileZ, wallDecoration.entity.minY)) { - drawWallDecoration(allowWallTypes, wallDecoration); - } + if (decor != null && !occluded(occludeLevel, tileX, tileZ, decor.entity.minY)) { + drawWallDecor(frontWallTypes, decor, true); } if (tileDrawn) { - SceneGroundDecoration groundDecoration = tile.groundDecoration; + SceneGroundDecoration groundDecor = tile.groundDecoration; - if (groundDecoration != null) { - groundDecoration.entity.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, groundDecoration.x - eyeX, groundDecoration.y - eyeY, groundDecoration.z - eyeZ, groundDecoration.bitset); + if (groundDecor != null) { + groundDecor.entity.draw(0, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, groundDecor.x - eyeX, groundDecor.y - eyeY, groundDecor.z - eyeZ, groundDecor.bitset); } SceneObjStack stack = tile.objStack; @@ -1455,28 +1449,28 @@ public class Scene { int spans = tile.locSpans; if (spans != 0) { - if ((tileX < eyeTileX) && ((spans & 4) != 0)) { + if ((tileX < eyeTileX) && ((spans & 0x4) != 0)) { SceneTile adjacent = tiles[tileX + 1][tileZ]; if ((adjacent != null) && adjacent.update) { drawTileQueue.pushBack(adjacent); } } - if ((tileZ < eyeTileZ) && ((spans & 2) != 0)) { + if ((tileZ < eyeTileZ) && ((spans & 0x2) != 0)) { SceneTile adjacent = tiles[tileX][tileZ + 1]; if ((adjacent != null) && adjacent.update) { drawTileQueue.pushBack(adjacent); } } - if ((tileX > eyeTileX) && ((spans & 1) != 0)) { + if ((tileX > eyeTileX) && ((spans & 0x1) != 0)) { SceneTile adjacent = tiles[tileX - 1][tileZ]; if ((adjacent != null) && adjacent.update) { drawTileQueue.pushBack(adjacent); } } - if ((tileZ > eyeTileZ) && ((spans & 8) != 0)) { + if ((tileZ > eyeTileZ) && ((spans & 0x8) != 0)) { SceneTile adjacent = tiles[tileX][tileZ - 1]; if ((adjacent != null) && adjacent.update) { drawTileQueue.pushBack(adjacent); @@ -1606,8 +1600,8 @@ public class Scene { SceneLoc farthest = locBuffer[farthestIndex]; farthest.cycle = cycle; - 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); + 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++) { @@ -1672,54 +1666,21 @@ public class Scene { drawObjStack(stack, stack.offset); } - if (tile.allowWallTypes != 0) { - SceneWallDecoration wallDecoration = tile.wallDecoration; + if (tile.backWallTypes != 0) { + SceneWallDecoration decor = 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 ((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_DECORATION0_ROTATION_OFFSET_X[rotation]; - int z = dz + DIAGONAL_WALL_DECORATION0_ROTATION_OFFSET_Z[rotation]; - wallDecoration.entity.draw((rotation * 512) + 256, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, dy, z, wallDecoration.bitset); - } - - if (((wallDecoration.type & 0x200) != 0) && (nearestZ <= nearestX)) { - int x = dx + DIAGONAL_WALL_DECORATION1_ROTATION_OFFSET_X[rotation]; - int z = dz + DIAGONAL_WALL_DECORATION1_ROTATION_OFFSET_Z[rotation]; - wallDecoration.entity.draw(((rotation * 512) + 1280) & 0x7ff, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, dy, z, wallDecoration.bitset); - } - } + if (decor != null && !occluded(occludeLevel, tileX, tileZ, decor.entity.minY)) { + drawWallDecor(tile.backWallTypes, decor, false); } SceneWall wall = tile.wall; if (wall != null) { - if (((wall.typeB & tile.allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeB)) { + if (((wall.typeB & tile.backWallTypes) != 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.allowWallTypes) != 0) && !wallOccluded(occludeLevel, tileX, tileZ, wall.typeA)) { + + if (((wall.typeA & tile.backWallTypes) != 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); } } @@ -1774,39 +1735,60 @@ public class Scene { } } - 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; + private static void drawWallDecor(int allowWallTypes, SceneWallDecoration decor, boolean front) { + if ((decor.type & allowWallTypes) != 0) { + decor.entity.draw(decor.rotation, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, decor.x - eyeX, decor.y - eyeY, decor.z - eyeZ, decor.bitset); + } else if ((decor.type & 0x300) != 0) { + int x = decor.x - eyeX; + int y = decor.y - eyeY; + int z = decor.z - eyeZ; + int rotation = decor.rotation; int nearestX; int nearestZ; if ((rotation == 1) || (rotation == 2)) { - nearestX = -dx; + nearestX = -x; } else { - nearestX = dx; + nearestX = x; } + if ((rotation == 2) || (rotation == 3)) { - nearestZ = -dz; + nearestZ = -z; } else { - nearestZ = dz; + nearestZ = z; } - if (((wallDecoration.type & 0x100) != 0) && (nearestZ < nearestX)) { - int x = dx + DIAGONAL_WALL_DECORATION0_ROTATION_OFFSET_X[rotation]; - int z = dz + DIAGONAL_WALL_DECORATION0_ROTATION_OFFSET_Z[rotation]; - wallDecoration.entity.draw((rotation * 512) + 256, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, y, z, wallDecoration.bitset); + if ((decor.type & 0x100) != 0) { + boolean draw = false; + + if (front && nearestZ < nearestX) { + draw = true; + } else if (!front && nearestZ >= nearestX) { + draw = true; + } + + if (draw) { + int drawX = x + WALL_DECORATION_INSET_X[rotation]; + int drawZ = z + WALL_DECORATION_INSET_Z[rotation]; + decor.entity.draw((rotation * 512) + 256, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, drawX, y, drawZ, decor.bitset); + } } - if (((wallDecoration.type & 0x200) != 0) && (nearestZ > nearestX)) { - int x = dx + DIAGONAL_WALL_DECORATION1_ROTATION_OFFSET_X[rotation]; - int z = dz + DIAGONAL_WALL_DECORATION1_ROTATION_OFFSET_Z[rotation]; - wallDecoration.entity.draw(((rotation * 512) + 1280) & 0x7ff, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, x, y, z, wallDecoration.bitset); + if ((decor.type & 0x200) != 0) { + boolean draw = false; + + if (front && nearestZ > nearestX) { + draw = true; + } else if (!front && nearestZ <= nearestX) { + draw = true; + } + + if (draw) { + int drawX = x + WALL_DECORATION_OUTSET_X[rotation]; + int drawZ = z + WALL_DECORATION_OUTSET_Z[rotation]; + decor.entity.draw(((rotation * 512) + 1280) & 0x7ff, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, drawX, y, drawZ, decor.bitset); + } } } } diff --git a/src/main/java/SceneBuilder.java b/src/main/java/SceneBuilder.java index 8c090ee..e4c7e6d 100644 --- a/src/main/java/SceneBuilder.java +++ b/src/main/java/SceneBuilder.java @@ -4,8 +4,8 @@ public class SceneBuilder { - 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 final int[] WALL_DECORATION_ROTATION_FORWARD_X = {1, 0, -1, 0}; + public static final int[] WALL_DECORATION_ROTATION_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; @@ -114,7 +114,7 @@ public class SceneBuilder { return (hsl & 0xff80) + lightness; } - public static void addLoc(Scene scene, int rotation, int z, int kind, int tileLevel, CollisionMap collision, int[][][] levelHeightmap, int x, int locID, int level) { + public static void addLoc(Scene scene, int rotation, int z, int type, int tileLevel, CollisionMap 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]; @@ -128,24 +128,24 @@ public class SceneBuilder { bitset += 0x80000000; } - byte info = (byte) ((rotation << 6) + kind); + byte info = (byte) ((rotation << 6) + type); - if (kind == 22) { + if (type == LocType.TYPE_GROUND_DECOR) { addGroundDecoration(scene, rotation, z, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if ((kind == 10) || (kind == 11)) { - addLoc(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind >= 12) { - addDiagonalWall(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 0) { - addWall(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 1) { - addDiagonalWallCorner(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 2) { - addFullWallCorner(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 3) { - addWallCorner(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 9) { - addDiagonalWall(scene, rotation, z, kind, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if ((type == LocType.TYPE_CENTREPIECE) || (type == LocType.TYPE_CENTREPIECE_DIAGONAL)) { + addLoc(scene, rotation, z, type, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if (type >= LocType.TYPE_ROOF_STRAIGHT) { + addRoofOrDiagonalWall(scene, rotation, z, type, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if (type == LocType.TYPE_WALL_STRAIGHT) { + addWallStraight(scene, rotation, z, type, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if (type == LocType.TYPE_WALL_CORNER_DIAGONAL) { + addWallCornerDiagonal(scene, rotation, z, type, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if (type == LocType.TYPE_WALL_L) { + addWallL(scene, rotation, z, type, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if (type == LocType.TYPE_WALL_SQUARE_CORNER) { + addWallSquareCorner(scene, rotation, z, type, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if (type == LocType.TYPE_WALL_DIAGONAL) { + addRoofOrDiagonalWall(scene, rotation, z, type, collision, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); } else { if (loc.adjustToTerrain) { if (rotation == 1) { @@ -170,16 +170,16 @@ public class SceneBuilder { } } - if (kind == 4) { - addWallDecoration(scene, rotation, z, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 5) { - addWallDecorationOutside(scene, rotation, z, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 6) { - addDiagonalWallDecorationInside(z, scene, level, x, locID, rotation, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 7) { - addDiagonalWallDecorationOutside(z, scene, level, x, locID, rotation, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); - } else if (kind == 8) { - addDiagonalWallDecorationBoth(z, scene, level, x, locID, rotation, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + if (type == LocType.TYPE_WALLDECOR_STRAIGHT) { + addWallDecor(scene, Scene.ROTATION_WALL_TYPE[rotation], loc, locID, bitset, info, level, x, z, rotation * 512, heightSW, heightSE, heightNE, heightNW, y); + } else if (type == LocType.TYPE_WALLDECOR_STRAIGHT_OFFSET) { + addWallDecorOffset(scene, rotation, z, x, locID, level, heightSW, heightSE, heightNE, heightNW, y, loc, bitset, info); + } else if (type == LocType.TYPE_WALLDECOR_DIAGONAL_NOOFFSET) { + addWallDecor(scene, 0x100, loc, locID, bitset, info, level, x, z, rotation, heightSW, heightSE, heightNE, heightNW, y); + } else if (type == LocType.TYPE_WALLDECOR_DIAGONAL_OFFSET) { + addWallDecor(scene, 0x200, loc, locID, bitset, info, level, x, z, rotation, heightSW, heightSE, heightNE, heightNW, y); + } else if (type == LocType.TYPE_WALLDECOR_DIAGONAL_BOTH) { + addWallDecor(scene, 0x300, loc, locID, bitset, info, level, x, z, rotation, heightSW, heightSE, heightNE, heightNW, y); } } } @@ -234,7 +234,7 @@ public class SceneBuilder { } } - private static void addWall(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addWallStraight(Scene scene, int rotation, int z, int kind, CollisionMap 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)) { @@ -250,7 +250,7 @@ public class SceneBuilder { } } - private static void addDiagonalWallCorner(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addWallCornerDiagonal(Scene scene, int rotation, int z, int kind, CollisionMap 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)) { @@ -266,7 +266,7 @@ public class SceneBuilder { } } - private static void addFullWallCorner(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addWallL(Scene scene, int rotation, int z, int kind, CollisionMap 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; @@ -286,7 +286,7 @@ public class SceneBuilder { } } - private static void addWallCorner(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addWallSquareCorner(Scene scene, int rotation, int z, int kind, CollisionMap 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)) { @@ -302,19 +302,7 @@ public class SceneBuilder { } } - 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 addDiagonalWall(Scene scene, int rotation, int z, int kind, CollisionMap collision, int x, int locID, int level, int heightSW, int heightSE, int heightNE, int heightNW, int y, LocType loc, int bitset, byte info) { + private static void addRoofOrDiagonalWall(Scene scene, int rotation, int z, int kind, CollisionMap 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)) { @@ -330,12 +318,12 @@ public class SceneBuilder { } } - 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; + private static void addWallDecorOffset(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 offset = 16; int wallBitset = scene.getWallBitset(level, x, z); if (wallBitset > 0) { - padding = LocType.get((wallBitset >> 14) & 0x7fff).decorationPadding; + offset = LocType.get((wallBitset >> 14) & 0x7fff).decorOffset; } Entity entity; @@ -346,7 +334,7 @@ public class SceneBuilder { 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); + scene.setWallDecoration(Scene.ROTATION_WALL_TYPE[rotation], entity, level, x, z, y, rotation * 512, WALL_DECORATION_ROTATION_FORWARD_X[rotation] * offset, WALL_DECORATION_ROTATION_FORWARD_Z[rotation] * offset, bitset, info); } /** @@ -782,7 +770,7 @@ public class SceneBuilder { int area = ((maxLevel + 1) - minLevel) * ((maxTileZ - minTileZ) + 1); - if (area >= 2) { + if (area >= 8) { int minY = levelHeightmap[maxLevel][tileX][minTileZ] - 240; int maxY = levelHeightmap[minLevel][tileX][minTileZ]; @@ -835,7 +823,7 @@ public class SceneBuilder { int area = ((maxLevel + 1) - minLevel) * ((maxTileX - minTileX) + 1); - if (area >= 2) { + if (area >= 8) { int minY = levelHeightmap[maxLevel][minTileX][tileZ] - 240; int maxY = levelHeightmap[minLevel][minTileX][tileZ]; @@ -886,7 +874,7 @@ public class SceneBuilder { } } - if ((((maxTileX - minTileX) + 1) * ((maxTileZ - minTileZ) + 1)) >= 4) { + if ((((maxTileX - minTileX) + 1) * ((maxTileZ - minTileZ) + 1)) >= 8) { int y = levelHeightmap[level][minTileX][minTileZ]; Scene.addOccluder(topLevel, minTileX * 128, y, minTileZ * 128, (maxTileX * 128) + 128, y, (maxTileZ * 128) + 128, SceneOccluder.TYPE_GROUND); @@ -968,13 +956,13 @@ public class SceneBuilder { } else if (kind == 0) { addWall(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 1) { - addDiagonalWallCorner(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addWallCornerDiagonal(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 2) { addFullWall(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 3) { - addWallCorner(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addWallSquareCorner(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 9) { - addDiagonalWall(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addRoofOrDiagonalWall(scene, collision, locID, kind, rotation, level, x, z, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else { if (type.adjustToTerrain) { if (rotation == 1) { @@ -1000,15 +988,15 @@ public class SceneBuilder { } if (kind == 4) { - addWallDecoration(scene, rotation, z, x, locID, level, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addWallDecor(scene, Scene.ROTATION_WALL_TYPE[rotation], type, locID, bitset, info, level, x, z, rotation * 512, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage); } else if (kind == 5) { - addWallDecorationOutside(scene, rotation, z, x, locID, level, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addWallDecorOffset(scene, rotation, z, x, locID, level, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); } else if (kind == 6) { - addDiagonalWallDecorationInside(z, scene, level, x, locID, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addWallDecor(scene, 0x100, type, locID, bitset, info, level, x, z, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage); } else if (kind == 7) { - addDiagonalWallDecorationOutside(z, scene, level, x, locID, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addWallDecor(scene, 0x200, type, locID, bitset, info, level, x, z, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage); } else if (kind == 8) { - addDiagonalWallDecorationBoth(z, scene, level, x, locID, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage, type, bitset, info); + addWallDecor(scene, 0x300, type, locID, bitset, info, level, x, z, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, heightmapAverage); } } } @@ -1159,12 +1147,12 @@ public class SceneBuilder { collision.addWall(x, z, kind, rotation, type.blocksProjectiles); } - if (type.decorationPadding != 16) { - scene.setWallDecorationOffset(level, x, z, type.decorationPadding); + if (type.decorOffset != 16) { + scene.setWallDecorationOffset(level, x, z, type.decorOffset); } } - private void addDiagonalWallCorner(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + private void addWallCornerDiagonal(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, 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)) { @@ -1227,12 +1215,12 @@ public class SceneBuilder { collision.addWall(x, z, kind, rotation, type.blocksProjectiles); } - if (type.decorationPadding != 16) { - scene.setWallDecorationOffset(level, x, z, type.decorationPadding); + if (type.decorOffset != 16) { + scene.setWallDecorationOffset(level, x, z, type.decorOffset); } } - private void addWallCorner(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + private void addWallSquareCorner(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, 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)) { @@ -1260,7 +1248,7 @@ public class SceneBuilder { } } - private static void addDiagonalWall(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage, LocType type, int bitset, byte info) { + private static void addRoofOrDiagonalWall(Scene scene, CollisionMap collision, int locID, int kind, int rotation, int level, int x, int z, 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)) { @@ -1275,34 +1263,14 @@ public class SceneBuilder { } } - 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) { + private static void addWallDecor(Scene scene, int decorType, LocType type, int locID, int locBitset, byte locInfo, int level, int x, int z, int rotation, int heightmapSW, int heightmapSE, int heightmapNE, int heightmapNW, int heightmapAverage) { 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); - } - - 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 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); + scene.setWallDecoration(decorType, entity, level, x, z, heightmapAverage, rotation, 0, 0, locBitset, locInfo); } public int decimateHSL(int hue, int saturation, int lightness) { diff --git a/src/main/java/SceneTile.java b/src/main/java/SceneTile.java index e4c42af..c2540c1 100644 --- a/src/main/java/SceneTile.java +++ b/src/main/java/SceneTile.java @@ -41,7 +41,7 @@ public class SceneTile extends DoublyLinkedList.Node { public int checkLocSpans; public int blockLocSpans; public int inverseBlockLocSpans; - public int allowWallTypes; + public int backWallTypes; public SceneTile bridge; public SceneTile(int level, int x, int z) {