null to create a new one.
- * @throws IOException if the stream content is malformed or an I/O error occurs.
- */
- public static byte[] decompress(byte[] src, int off, int len, byte[] dst) throws IOException {
- ByteArrayOutputStream tmp = null;
+ /**
+ * Decompresses the source.
+ *
+ * @param src the source data.
+ * @param off the source offset.
+ * @param len the source length.
+ * @param dst the destination or null to create a new one.
+ * @throws IOException if the stream content is malformed or an I/O error occurs.
+ */
+ public static byte[] decompress(byte[] src, int off, int len, byte[] dst) throws IOException {
+ ByteArrayOutputStream tmp = null;
- if (dst == null) {
- tmp = new ByteArrayOutputStream();
- }
+ if (dst == null) {
+ tmp = new ByteArrayOutputStream();
+ }
- try (BZip2CompressorInputStream in = new BZip2CompressorInputStream(new BZip2(src, off, len))) {
- if (tmp != null) {
- IOUtils.copy(in, tmp);
- } else {
- IOUtils.readFully(in, dst);
- }
- }
+ try (BZip2CompressorInputStream in = new BZip2CompressorInputStream(new BZip2(src, off, len))) {
+ if (tmp != null) {
+ IOUtils.copy(in, tmp);
+ } else {
+ IOUtils.readFully(in, dst);
+ }
+ }
- if (tmp != null) {
- return tmp.toByteArray();
- }
+ if (tmp != null) {
+ return tmp.toByteArray();
+ }
- return dst;
- }
+ return dst;
+ }
- /**
- * The input.
- */
- private final ByteArrayInputStream in;
- /**
- * The position.
- */
- private int position;
+ /**
+ * The input.
+ */
+ private final ByteArrayInputStream in;
+ /**
+ * The position.
+ */
+ private int position;
- /**
- * Constructs a new helper class to fool that silly compressor.
- *
- * @param src the source.
- * @param off the source offset.
- * @param len the source length.
- */
- private BZip2(byte[] src, int off, int len) {
- this.in = new ByteArrayInputStream(src, off, len);
- }
+ /**
+ * Constructs a new helper class to fool that silly compressor.
+ *
+ * @param src the source.
+ * @param off the source offset.
+ * @param len the source length.
+ */
+ private BZip2(byte[] src, int off, int len) {
+ this.in = new ByteArrayInputStream(src, off, len);
+ }
- @Override
- public int read() throws IOException {
- if (position < 4) {
- return MAGIC[position++];
- }
- return in.read();
- }
+ @Override
+ public int read() throws IOException {
+ if (position < 4) {
+ return MAGIC[position++];
+ }
+ return in.read();
+ }
}
diff --git a/src/main/java/BitmapFont.java b/src/main/java/BitmapFont.java
index 8b6234a..7fcfd3e 100644
--- a/src/main/java/BitmapFont.java
+++ b/src/main/java/BitmapFont.java
@@ -3,531 +3,531 @@ import java.util.Random;
public class BitmapFont {
- public final byte[][] charMask = new byte[256][];
- public final int[] charMaskWidth = new int[256];
- public final int[] charMaskHeight = new int[256];
- public final int[] charOffsetX = new int[256];
- public final int[] charOffsetY = new int[256];
- public final int[] charAdvance = new int[256];
- public final Random random = new Random();
- public int height;
- public boolean strikethrough = false;
+ public final byte[][] charMask = new byte[256][];
+ public final int[] charMaskWidth = new int[256];
+ public final int[] charMaskHeight = new int[256];
+ public final int[] charOffsetX = new int[256];
+ public final int[] charOffsetY = new int[256];
+ public final int[] charAdvance = new int[256];
+ public final Random random = new Random();
+ public int height;
+ public boolean strikethrough = false;
- public BitmapFont(FileArchive archive, String name, boolean quill) throws IOException {
- Buffer dat = new Buffer(archive.read(name + ".dat"));
- Buffer idx = new Buffer(archive.read("index.dat"));
- idx.position = dat.read16U() + 4;
+ public BitmapFont(FileArchive archive, String name, boolean quill) throws IOException {
+ Buffer dat = new Buffer(archive.read(name + ".dat"));
+ Buffer idx = new Buffer(archive.read("index.dat"));
+ idx.position = dat.read16U() + 4;
- int k = idx.read8U();
+ int k = idx.read8U();
- if (k > 0) {
- idx.position += 3 * (k - 1);
- }
+ if (k > 0) {
+ idx.position += 3 * (k - 1);
+ }
- for (int c = 0; c < 256; c++) {
- charOffsetX[c] = idx.read8U();
- charOffsetY[c] = idx.read8U();
+ for (int c = 0; c < 256; c++) {
+ charOffsetX[c] = idx.read8U();
+ charOffsetY[c] = idx.read8U();
- int w = charMaskWidth[c] = idx.read16U();
- int h = charMaskHeight[c] = idx.read16U();
- int storeOrder = idx.read8U();
+ int w = charMaskWidth[c] = idx.read16U();
+ int h = charMaskHeight[c] = idx.read16U();
+ int storeOrder = idx.read8U();
- int len = w * h;
- charMask[c] = new byte[len];
+ int len = w * h;
+ charMask[c] = new byte[len];
- if (storeOrder == 0) {
- for (int i = 0; i < len; i++) {
- charMask[c][i] = dat.read();
- }
- } else if (storeOrder == 1) {
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- charMask[c][x + (y * w)] = dat.read();
- }
- }
- }
+ if (storeOrder == 0) {
+ for (int i = 0; i < len; i++) {
+ charMask[c][i] = dat.read();
+ }
+ } else if (storeOrder == 1) {
+ for (int x = 0; x < w; x++) {
+ for (int y = 0; y < h; y++) {
+ charMask[c][x + (y * w)] = dat.read();
+ }
+ }
+ }
- if ((h > height) && (c < 128)) {
- height = h;
- }
+ if ((h > height) && (c < 128)) {
+ height = h;
+ }
- // some simple kerning
- // https://en.wikipedia.org/wiki/Kerning
+ // some simple kerning
+ // https://en.wikipedia.org/wiki/Kerning
- charOffsetX[c] = 1;
- charAdvance[c] = w + 2;
+ charOffsetX[c] = 1;
+ charAdvance[c] = w + 2;
- int acc = 0;
+ int acc = 0;
- for (int y = h / 7; y < h; y++) {
- acc += charMask[c][y * w];
- }
+ for (int y = h / 7; y < h; y++) {
+ acc += charMask[c][y * w];
+ }
- if (acc <= (h / 7)) {
- charAdvance[c]--;
- charOffsetX[c] = 0;
- }
+ if (acc <= (h / 7)) {
+ charAdvance[c]--;
+ charOffsetX[c] = 0;
+ }
- acc = 0;
+ acc = 0;
- for (int y = h / 7; y < h; y++) {
- acc += charMask[c][(w - 1) + (y * w)];
- }
+ for (int y = h / 7; y < h; y++) {
+ acc += charMask[c][(w - 1) + (y * w)];
+ }
- if (acc <= (h / 7)) {
- charAdvance[c]--;
- }
- }
+ if (acc <= (h / 7)) {
+ charAdvance[c]--;
+ }
+ }
- // only q8_full uses this flag.
- if (quill) {
- charAdvance[' '] = charAdvance['I'];
- } else {
- charAdvance[' '] = charAdvance['i'];
- }
- }
+ // only q8_full uses this flag.
+ if (quill) {
+ charAdvance[' '] = charAdvance['I'];
+ } else {
+ charAdvance[' '] = charAdvance['i'];
+ }
+ }
- /**
- * Draws a right aligned string. Note: This method is not taggable.
- *
- * @param s the string.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- */
- public void drawStringRight(String s, int x, int y, int rgb) {
- drawString(s, x - stringWidth(s), y, rgb);
- }
+ /**
+ * Draws a right aligned string. Note: This method is not taggable.
+ *
+ * @param s the string.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ */
+ public void drawStringRight(String s, int x, int y, int rgb) {
+ drawString(s, x - stringWidth(s), y, rgb);
+ }
- /**
- * Draws a centered string. Note: This method is not taggable.
- *
- * @param s the string.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- */
- public void drawStringCenter(String s, int x, int y, int rgb) {
- drawString(s, x - (stringWidth(s) / 2), y, rgb);
- }
+ /**
+ * Draws a centered string. Note: This method is not taggable.
+ *
+ * @param s the string.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ */
+ public void drawStringCenter(String s, int x, int y, int rgb) {
+ drawString(s, x - (stringWidth(s) / 2), y, rgb);
+ }
- /**
- * Draws a centered and taggable string.
- *
- * @param s the string.
- * @param x the center x.
- * @param y the y.
- * @param rgb the rgb.
- * @param shadow true to draw with a shadow.
- */
- public void drawStringTaggableCenter(String s, int x, int y, int rgb, boolean shadow) {
- drawStringTaggable(s, x - (stringWidthTaggable(s) / 2), y, rgb, shadow);
- }
+ /**
+ * Draws a centered and taggable string.
+ *
+ * @param s the string.
+ * @param x the center x.
+ * @param y the y.
+ * @param rgb the rgb.
+ * @param shadow true to draw with a shadow.
+ */
+ public void drawStringTaggableCenter(String s, int x, int y, int rgb, boolean shadow) {
+ drawStringTaggable(s, x - (stringWidthTaggable(s) / 2), y, rgb, shadow);
+ }
- /**
- * Calculates the string width.
- *
- * @param s the string.
- * @return the string width.
- */
- public int stringWidthTaggable(String s) {
- if (s == null) {
- return 0;
- }
- int w = 0;
- for (int k = 0; k < s.length(); k++) {
- if ((s.charAt(k) == '@') && ((k + 4) < s.length()) && (s.charAt(k + 4) == '@')) {
- k += 4;
- } else {
- w += charAdvance[s.charAt(k)];
- }
- }
- return w;
- }
+ /**
+ * Calculates the string width.
+ *
+ * @param s the string.
+ * @return the string width.
+ */
+ public int stringWidthTaggable(String s) {
+ if (s == null) {
+ return 0;
+ }
+ int w = 0;
+ for (int k = 0; k < s.length(); k++) {
+ if ((s.charAt(k) == '@') && ((k + 4) < s.length()) && (s.charAt(k + 4) == '@')) {
+ k += 4;
+ } else {
+ w += charAdvance[s.charAt(k)];
+ }
+ }
+ return w;
+ }
- /**
- * Calculates the string width. Note: This method is not taggable.
- *
- * @param s the string.
- * @return the string width.
- */
- public int stringWidth(String s) {
- if (s == null) {
- return 0;
- }
- int w = 0;
- for (int k = 0; k < s.length(); k++) {
- w += charAdvance[s.charAt(k)];
- }
- return w;
- }
+ /**
+ * Calculates the string width. Note: This method is not taggable.
+ *
+ * @param s the string.
+ * @return the string width.
+ */
+ public int stringWidth(String s) {
+ if (s == null) {
+ return 0;
+ }
+ int w = 0;
+ for (int k = 0; k < s.length(); k++) {
+ w += charAdvance[s.charAt(k)];
+ }
+ return w;
+ }
- /**
- * Standard draw string method. Note: This method is not taggable.
- *
- * @param s the s.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- */
- public void drawString(String s, int x, int y, int rgb) {
- if (s == null) {
- return;
- }
- y -= height;
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c != ' ') {
- fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c], charMaskWidth[c], charMaskHeight[c], rgb);
- }
- x += charAdvance[c];
- }
- }
+ /**
+ * Standard draw string method. Note: This method is not taggable.
+ *
+ * @param s the s.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ */
+ public void drawString(String s, int x, int y, int rgb) {
+ if (s == null) {
+ return;
+ }
+ y -= height;
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (c != ' ') {
+ fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c], charMaskWidth[c], charMaskHeight[c], rgb);
+ }
+ x += charAdvance[c];
+ }
+ }
- /**
- * Draws a string with the wave effect. Note: This method is not taggable.
- *
- * @param s the string.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- * @param cycle the cycle.
- */
- public void drawStringWave(String s, int x, int y, int rgb, int cycle) {
- if (s == null) {
- return;
- }
- x -= stringWidth(s) / 2;
- y -= height;
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c != ' ') {
- fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c] + (int) (Math.sin(((double) i / 2D) + ((double) cycle / 5D)) * 5D), charMaskWidth[c], charMaskHeight[c], rgb);
- }
- x += charAdvance[c];
- }
- }
+ /**
+ * Draws a string with the wave effect. Note: This method is not taggable.
+ *
+ * @param s the string.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ * @param cycle the cycle.
+ */
+ public void drawStringWave(String s, int x, int y, int rgb, int cycle) {
+ if (s == null) {
+ return;
+ }
+ x -= stringWidth(s) / 2;
+ y -= height;
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (c != ' ') {
+ fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c] + (int) (Math.sin(((double) i / 2D) + ((double) cycle / 5D)) * 5D), charMaskWidth[c], charMaskHeight[c], rgb);
+ }
+ x += charAdvance[c];
+ }
+ }
- /**
- * Draws a string with the wave2 effect. Note: This method is not taggable.
- *
- * @param s the string.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- * @param cycle the wave cycle.
- */
- public void drawStringWave2(String s, int x, int y, int rgb, int cycle) {
- if (s == null) {
- return;
- }
- x -= stringWidth(s) / 2;
- y -= height;
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c != ' ') {
- fillMaskedRect(charMask[c], x + charOffsetX[c] + (int) (Math.sin(((double) i / 5D) + ((double) cycle / 5D)) * 5D), y + charOffsetY[c] + (int) (Math.sin(((double) i / 3D) + ((double) cycle / 5D)) * 5D), charMaskWidth[c], charMaskHeight[c], rgb);
- }
- x += charAdvance[c];
- }
- }
+ /**
+ * Draws a string with the wave2 effect. Note: This method is not taggable.
+ *
+ * @param s the string.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ * @param cycle the wave cycle.
+ */
+ public void drawStringWave2(String s, int x, int y, int rgb, int cycle) {
+ if (s == null) {
+ return;
+ }
+ x -= stringWidth(s) / 2;
+ y -= height;
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (c != ' ') {
+ fillMaskedRect(charMask[c], x + charOffsetX[c] + (int) (Math.sin(((double) i / 5D) + ((double) cycle / 5D)) * 5D), y + charOffsetY[c] + (int) (Math.sin(((double) i / 3D) + ((double) cycle / 5D)) * 5D), charMaskWidth[c], charMaskHeight[c], rgb);
+ }
+ x += charAdvance[c];
+ }
+ }
- /**
- * Draws a string with the shake effect. Note: This method is not taggable.
- *
- * @param s the string.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- * @param cycle the shake cycle.
- * @param phase the shake phase.
- */
- public void drawStringShake(String s, int x, int y, int rgb, int cycle, int phase) {
- if (s == null) {
- return;
- }
+ /**
+ * Draws a string with the shake effect. Note: This method is not taggable.
+ *
+ * @param s the string.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ * @param cycle the shake cycle.
+ * @param phase the shake phase.
+ */
+ public void drawStringShake(String s, int x, int y, int rgb, int cycle, int phase) {
+ if (s == null) {
+ return;
+ }
- double amplitude = 7D - ((double) phase / 8D);
+ double amplitude = 7D - ((double) phase / 8D);
- if (amplitude < 0.0D) {
- amplitude = 0.0D;
- }
+ if (amplitude < 0.0D) {
+ amplitude = 0.0D;
+ }
- x -= stringWidth(s) / 2;
- y -= height;
+ x -= stringWidth(s) / 2;
+ y -= height;
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
- if (c != ' ') {
- fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c] + (int) (Math.sin(((double) i / 1.5D) + (double) cycle) * amplitude), charMaskWidth[c], charMaskHeight[c], rgb);
- }
+ if (c != ' ') {
+ fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c] + (int) (Math.sin(((double) i / 1.5D) + (double) cycle) * amplitude), charMaskWidth[c], charMaskHeight[c], rgb);
+ }
- x += charAdvance[c];
- }
- }
+ x += charAdvance[c];
+ }
+ }
- /**
- * Draws a taggable string.
- *
- * @param s the string.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- * @param shadowed true to draw with a shadow.
- * @see #evaluateTag(String)
- */
- public void drawStringTaggable(String s, int x, int y, int rgb, boolean shadowed) {
- strikethrough = false;
+ /**
+ * Draws a taggable string.
+ *
+ * @param s the string.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ * @param shadowed true to draw with a shadow.
+ * @see #evaluateTag(String)
+ */
+ public void drawStringTaggable(String s, int x, int y, int rgb, boolean shadowed) {
+ strikethrough = false;
- int leftX = x;
+ int leftX = x;
- if (s == null) {
- return;
- }
+ if (s == null) {
+ return;
+ }
- y -= height;
+ y -= height;
- for (int i = 0; i < s.length(); i++) {
- if ((s.charAt(i) == '@') && ((i + 4) < s.length()) && (s.charAt(i + 4) == '@')) {
- int value = evaluateTag(s.substring(i + 1, i + 4));
+ for (int i = 0; i < s.length(); i++) {
+ if ((s.charAt(i) == '@') && ((i + 4) < s.length()) && (s.charAt(i + 4) == '@')) {
+ int value = evaluateTag(s.substring(i + 1, i + 4));
- if (value != -1) {
- rgb = value;
- }
+ if (value != -1) {
+ rgb = value;
+ }
- i += 4;
- } else {
- char c = s.charAt(i);
+ i += 4;
+ } else {
+ char c = s.charAt(i);
- if (c != ' ') {
- if (shadowed) {
- fillMaskedRect(charMask[c], x + charOffsetX[c] + 1, y + charOffsetY[c] + 1, charMaskWidth[c], charMaskHeight[c], 0);
- }
- fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c], charMaskWidth[c], charMaskHeight[c], rgb);
- }
+ if (c != ' ') {
+ if (shadowed) {
+ fillMaskedRect(charMask[c], x + charOffsetX[c] + 1, y + charOffsetY[c] + 1, charMaskWidth[c], charMaskHeight[c], 0);
+ }
+ fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c], charMaskWidth[c], charMaskHeight[c], rgb);
+ }
- x += charAdvance[c];
- }
- }
+ x += charAdvance[c];
+ }
+ }
- if (strikethrough) {
- Draw2D.drawLineX(leftX, y + (int) ((double) height * 0.7), x - leftX, 0x800000);
- }
- }
+ if (strikethrough) {
+ Draw2D.drawLineX(leftX, y + (int) ((double) height * 0.7), x - leftX, 0x800000);
+ }
+ }
- /**
- * Identical to {@link #drawStringTaggable(String, int, int, int, boolean)} with the exception of a random chance to
- * advance a character by an additional pixel to prevent macro clients from detecting tooltip text easily.
- *
- * @param s the string.
- * @param x the x.
- * @param y the y.
- * @param rgb the rgb.
- * @param shadowed true to draw with a shadow.
- * @param seed the seed.
- * @see #evaluateTag(String)
- */
- public void drawStringTooltip(String s, int x, int y, int rgb, boolean shadowed, int seed) {
- if (s == null) {
- return;
- }
- random.setSeed(seed);
- int alpha = 192 + (random.nextInt() & 0x1f);
- y -= height;
- for (int i = 0; i < s.length(); i++) {
- if ((s.charAt(i) == '@') && ((i + 4) < s.length()) && (s.charAt(i + 4) == '@')) {
- int value = evaluateTag(s.substring(i + 1, i + 4));
- if (value != -1) {
- rgb = value;
- }
- i += 4;
- } else {
- char c = s.charAt(i);
- if (c != ' ') {
- if (shadowed) {
- fillMaskedRect(charMask[c], x + charOffsetX[c] + 1, y + charOffsetY[c] + 1, charMaskWidth[c], charMaskHeight[c], 0, 192);
- }
- fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c], charMaskWidth[c], charMaskHeight[c], rgb, alpha);
- }
- x += charAdvance[c];
- if ((random.nextInt() & 3) == 0) {
- x++;
- }
- }
- }
- }
+ /**
+ * Identical to {@link #drawStringTaggable(String, int, int, int, boolean)} with the exception of a random chance to
+ * advance a character by an additional pixel to prevent macro clients from detecting tooltip text easily.
+ *
+ * @param s the string.
+ * @param x the x.
+ * @param y the y.
+ * @param rgb the rgb.
+ * @param shadowed true to draw with a shadow.
+ * @param seed the seed.
+ * @see #evaluateTag(String)
+ */
+ public void drawStringTooltip(String s, int x, int y, int rgb, boolean shadowed, int seed) {
+ if (s == null) {
+ return;
+ }
+ random.setSeed(seed);
+ int alpha = 192 + (random.nextInt() & 0x1f);
+ y -= height;
+ for (int i = 0; i < s.length(); i++) {
+ if ((s.charAt(i) == '@') && ((i + 4) < s.length()) && (s.charAt(i + 4) == '@')) {
+ int value = evaluateTag(s.substring(i + 1, i + 4));
+ if (value != -1) {
+ rgb = value;
+ }
+ i += 4;
+ } else {
+ char c = s.charAt(i);
+ if (c != ' ') {
+ if (shadowed) {
+ fillMaskedRect(charMask[c], x + charOffsetX[c] + 1, y + charOffsetY[c] + 1, charMaskWidth[c], charMaskHeight[c], 0, 192);
+ }
+ fillMaskedRect(charMask[c], x + charOffsetX[c], y + charOffsetY[c], charMaskWidth[c], charMaskHeight[c], rgb, alpha);
+ }
+ x += charAdvance[c];
+ if ((random.nextInt() & 3) == 0) {
+ x++;
+ }
+ }
+ }
+ }
- public int evaluateTag(String s) {
- switch (s) {
- case "red":
- return 0xff0000;
- case "gre":
- return 0xff00;
- case "blu":
- return 0xff;
- case "yel":
- return 0xffff00;
- case "cya":
- return 0xffff;
- case "mag":
- return 0xff00ff;
- case "whi":
- return 0xffffff;
- case "bla":
- return 0;
- case "lre":
- return 0xff9040;
- case "dre":
- return 0x800000;
- case "dbl":
- return 0x80;
- case "or1":
- return 0xffb000;
- case "or2":
- return 0xff7000;
- case "or3":
- return 0xff3000;
- case "gr1":
- return 0xc0ff00;
- case "gr2":
- return 0x80ff00;
- case "gr3":
- return 0x40ff00;
- case "str":
- strikethrough = true;
- break;
- case "end":
- strikethrough = false;
- break;
- }
- return -1;
- }
+ public int evaluateTag(String s) {
+ switch (s) {
+ case "red":
+ return 0xff0000;
+ case "gre":
+ return 0xff00;
+ case "blu":
+ return 0xff;
+ case "yel":
+ return 0xffff00;
+ case "cya":
+ return 0xffff;
+ case "mag":
+ return 0xff00ff;
+ case "whi":
+ return 0xffffff;
+ case "bla":
+ return 0;
+ case "lre":
+ return 0xff9040;
+ case "dre":
+ return 0x800000;
+ case "dbl":
+ return 0x80;
+ case "or1":
+ return 0xffb000;
+ case "or2":
+ return 0xff7000;
+ case "or3":
+ return 0xff3000;
+ case "gr1":
+ return 0xc0ff00;
+ case "gr2":
+ return 0x80ff00;
+ case "gr3":
+ return 0x40ff00;
+ case "str":
+ strikethrough = true;
+ break;
+ case "end":
+ strikethrough = false;
+ break;
+ }
+ return -1;
+ }
- public void fillMaskedRect(byte[] mask, int x, int y, int w, int h, int rgb) {
- int dstOff = x + (y * Draw2D.width);
- int dstStep = Draw2D.width - w;
- int maskStep = 0;
- int maskOff = 0;
- if (y < Draw2D.top) {
- int trim = Draw2D.top - y;
- h -= trim;
- y = Draw2D.top;
- maskOff += trim * w;
- dstOff += trim * Draw2D.width;
- }
- if ((y + h) >= Draw2D.bottom) {
- h -= ((y + h) - Draw2D.bottom) + 1;
- }
- if (x < Draw2D.left) {
- int trim = Draw2D.left - x;
- w -= trim;
- x = Draw2D.left;
- maskOff += trim;
- dstOff += trim;
- maskStep += trim;
- dstStep += trim;
- }
- if ((x + w) >= Draw2D.right) {
- int trim = ((x + w) - Draw2D.right) + 1;
- w -= trim;
- maskStep += trim;
- dstStep += trim;
- }
- if ((w > 0) && (h > 0)) {
- fillMaskedRect(mask, maskOff, maskStep, Draw2D.pixels, dstOff, dstStep, w, h, rgb);
- }
- }
+ public void fillMaskedRect(byte[] mask, int x, int y, int w, int h, int rgb) {
+ int dstOff = x + (y * Draw2D.width);
+ int dstStep = Draw2D.width - w;
+ int maskStep = 0;
+ int maskOff = 0;
+ if (y < Draw2D.top) {
+ int trim = Draw2D.top - y;
+ h -= trim;
+ y = Draw2D.top;
+ maskOff += trim * w;
+ dstOff += trim * Draw2D.width;
+ }
+ if ((y + h) >= Draw2D.bottom) {
+ h -= ((y + h) - Draw2D.bottom) + 1;
+ }
+ if (x < Draw2D.left) {
+ int trim = Draw2D.left - x;
+ w -= trim;
+ x = Draw2D.left;
+ maskOff += trim;
+ dstOff += trim;
+ maskStep += trim;
+ dstStep += trim;
+ }
+ if ((x + w) >= Draw2D.right) {
+ int trim = ((x + w) - Draw2D.right) + 1;
+ w -= trim;
+ maskStep += trim;
+ dstStep += trim;
+ }
+ if ((w > 0) && (h > 0)) {
+ fillMaskedRect(mask, maskOff, maskStep, Draw2D.pixels, dstOff, dstStep, w, h, rgb);
+ }
+ }
- public void fillMaskedRect(byte[] mask, int x, int y, int w, int h, int rgb, int alpha) {
- int dstOff = x + (y * Draw2D.width);
- int dstStep = Draw2D.width - w;
- int maskStep = 0;
- int maskOff = 0;
- if (y < Draw2D.top) {
- int trim = Draw2D.top - y;
- h -= trim;
- y = Draw2D.top;
- maskOff += trim * w;
- dstOff += trim * Draw2D.width;
- }
- if ((y + h) >= Draw2D.bottom) {
- h -= ((y + h) - Draw2D.bottom) + 1;
- }
- if (x < Draw2D.left) {
- int trim = Draw2D.left - x;
- w -= trim;
- x = Draw2D.left;
- maskOff += trim;
- dstOff += trim;
- maskStep += trim;
- dstStep += trim;
- }
- if ((x + w) >= Draw2D.right) {
- int trim = ((x + w) - Draw2D.right) + 1;
- w -= trim;
- maskStep += trim;
- dstStep += trim;
- }
- if ((w <= 0) || (h <= 0)) {
- return;
- }
- fillMaskedRect(mask, maskOff, maskStep, Draw2D.pixels, dstOff, dstStep, w, h, rgb, alpha);
- }
+ public void fillMaskedRect(byte[] mask, int x, int y, int w, int h, int rgb, int alpha) {
+ int dstOff = x + (y * Draw2D.width);
+ int dstStep = Draw2D.width - w;
+ int maskStep = 0;
+ int maskOff = 0;
+ if (y < Draw2D.top) {
+ int trim = Draw2D.top - y;
+ h -= trim;
+ y = Draw2D.top;
+ maskOff += trim * w;
+ dstOff += trim * Draw2D.width;
+ }
+ if ((y + h) >= Draw2D.bottom) {
+ h -= ((y + h) - Draw2D.bottom) + 1;
+ }
+ if (x < Draw2D.left) {
+ int trim = Draw2D.left - x;
+ w -= trim;
+ x = Draw2D.left;
+ maskOff += trim;
+ dstOff += trim;
+ maskStep += trim;
+ dstStep += trim;
+ }
+ if ((x + w) >= Draw2D.right) {
+ int trim = ((x + w) - Draw2D.right) + 1;
+ w -= trim;
+ maskStep += trim;
+ dstStep += trim;
+ }
+ if ((w <= 0) || (h <= 0)) {
+ return;
+ }
+ fillMaskedRect(mask, maskOff, maskStep, Draw2D.pixels, dstOff, dstStep, w, h, rgb, alpha);
+ }
- public void fillMaskedRect(byte[] mask, int maskOff, int maskStep, int[] dst, int dstOff, int dstStep, int w, int h, int rgb) {
- int halfW = -(w >> 2);
- w = -(w & 3);
- for (int y = -h; y < 0; y++) {
- for (int x = halfW; x < 0; x++) {
- if (mask[maskOff++] != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- if (mask[maskOff++] != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- if (mask[maskOff++] != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- if (mask[maskOff++] != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- }
- for (int x = w; x < 0; x++) {
- if (mask[maskOff++] != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- }
- dstOff += dstStep;
- maskOff += maskStep;
- }
- }
+ public void fillMaskedRect(byte[] mask, int maskOff, int maskStep, int[] dst, int dstOff, int dstStep, int w, int h, int rgb) {
+ int halfW = -(w >> 2);
+ w = -(w & 3);
+ for (int y = -h; y < 0; y++) {
+ for (int x = halfW; x < 0; x++) {
+ if (mask[maskOff++] != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ if (mask[maskOff++] != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ if (mask[maskOff++] != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ if (mask[maskOff++] != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ }
+ for (int x = w; x < 0; x++) {
+ if (mask[maskOff++] != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ }
+ dstOff += dstStep;
+ maskOff += maskStep;
+ }
+ }
- public void fillMaskedRect(byte[] mask, int maskOff, int maskStep, int[] dst, int dstOff, int dstStep, int w, int h, int rgb, int alpha) {
- rgb = ((((rgb & 0xff00ff) * alpha) & 0xff00ff00) + (((rgb & 0xff00) * alpha) & 0xff0000)) >> 8;
- alpha = 256 - alpha;
- for (int y = -h; y < 0; y++) {
- for (int x = -w; x < 0; x++) {
- if (mask[maskOff++] != 0) {
- int dstRGB = dst[dstOff];
- dst[dstOff++] = (((((dstRGB & 0xff00ff) * alpha) & 0xff00ff00) + (((dstRGB & 0xff00) * alpha) & 0xff0000)) >> 8) + rgb;
- } else {
- dstOff++;
- }
- }
- dstOff += dstStep;
- maskOff += maskStep;
- }
- }
+ public void fillMaskedRect(byte[] mask, int maskOff, int maskStep, int[] dst, int dstOff, int dstStep, int w, int h, int rgb, int alpha) {
+ rgb = ((((rgb & 0xff00ff) * alpha) & 0xff00ff00) + (((rgb & 0xff00) * alpha) & 0xff0000)) >> 8;
+ alpha = 256 - alpha;
+ for (int y = -h; y < 0; y++) {
+ for (int x = -w; x < 0; x++) {
+ if (mask[maskOff++] != 0) {
+ int dstRGB = dst[dstOff];
+ dst[dstOff++] = (((((dstRGB & 0xff00ff) * alpha) & 0xff00ff00) + (((dstRGB & 0xff00) * alpha) & 0xff0000)) >> 8) + rgb;
+ } else {
+ dstOff++;
+ }
+ }
+ dstOff += dstStep;
+ maskOff += maskStep;
+ }
+ }
}
diff --git a/src/main/java/Buffer.java b/src/main/java/Buffer.java
index 5c0a92d..6643dff 100644
--- a/src/main/java/Buffer.java
+++ b/src/main/java/Buffer.java
@@ -28,323 +28,323 @@ import java.nio.charset.StandardCharsets;
*/
public class Buffer extends DoublyLinkedList.Node {
- private static final int[] BITMASK = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1};
+ private static final int[] BITMASK = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1};
- public static Buffer create(int sizeType) {
- Buffer buffer = new Buffer();
- buffer.position = 0;
+ public static Buffer create(int sizeType) {
+ Buffer buffer = new Buffer();
+ buffer.position = 0;
- if (sizeType == 0) {
- buffer.data = new byte[100];
- } else if (sizeType == 1) {
- buffer.data = new byte[5000];
- } else {
- buffer.data = new byte[30000];
- }
+ if (sizeType == 0) {
+ buffer.data = new byte[100];
+ } else if (sizeType == 1) {
+ buffer.data = new byte[5000];
+ } else {
+ buffer.data = new byte[30000];
+ }
- return buffer;
- }
+ return buffer;
+ }
- public byte[] data;
- public int position;
- public int bitPosition;
- public ISAACRandom random;
+ public byte[] data;
+ public int position;
+ public int bitPosition;
+ public ISAACRandom random;
- public Buffer() {
- }
+ public Buffer() {
+ }
- public Buffer(byte[] src) {
- data = src;
- position = 0;
- }
+ public Buffer(byte[] src) {
+ data = src;
+ position = 0;
+ }
- public void writeOp(int i) {
- data[position++] = (byte) (i + random.nextInt());
- }
+ public void writeOp(int i) {
+ data[position++] = (byte) (i + random.nextInt());
+ }
- public void writeSize(int i) {
- data[position - i - 1] = (byte) i;
- }
+ public void writeSize(int i) {
+ data[position - i - 1] = (byte) i;
+ }
- public void write8(int i) {
- data[position++] = (byte) i;
- }
+ public void write8(int i) {
+ data[position++] = (byte) i;
+ }
- public void write8C(int i) {
- data[position++] = (byte) -i;
- }
+ public void write8C(int i) {
+ data[position++] = (byte) -i;
+ }
- public void write8S(int j) {
- data[position++] = (byte) (128 - j);
- }
+ public void write8S(int j) {
+ data[position++] = (byte) (128 - j);
+ }
- public void write16(int i) {
- data[position++] = (byte) (i >> 8);
- data[position++] = (byte) i;
- }
+ public void write16(int i) {
+ data[position++] = (byte) (i >> 8);
+ data[position++] = (byte) i;
+ }
- public void write16A(int j) {
- data[position++] = (byte) (j >> 8);
- data[position++] = (byte) (j + 128);
- }
+ public void write16A(int j) {
+ data[position++] = (byte) (j >> 8);
+ data[position++] = (byte) (j + 128);
+ }
- public void write16LE(int i) {
- data[position++] = (byte) i;
- data[position++] = (byte) (i >> 8);
- }
+ public void write16LE(int i) {
+ data[position++] = (byte) i;
+ data[position++] = (byte) (i >> 8);
+ }
- public void write16LEA(int j) {
- data[position++] = (byte) (j + 128);
- data[position++] = (byte) (j >> 8);
- }
+ public void write16LEA(int j) {
+ data[position++] = (byte) (j + 128);
+ data[position++] = (byte) (j >> 8);
+ }
- public void write24(int i) {
- data[position++] = (byte) (i >> 16);
- data[position++] = (byte) (i >> 8);
- data[position++] = (byte) i;
- }
+ public void write24(int i) {
+ data[position++] = (byte) (i >> 16);
+ data[position++] = (byte) (i >> 8);
+ data[position++] = (byte) i;
+ }
- public void write32(int i) {
- data[position++] = (byte) (i >> 24);
- data[position++] = (byte) (i >> 16);
- data[position++] = (byte) (i >> 8);
- data[position++] = (byte) i;
- }
+ public void write32(int i) {
+ data[position++] = (byte) (i >> 24);
+ data[position++] = (byte) (i >> 16);
+ data[position++] = (byte) (i >> 8);
+ data[position++] = (byte) i;
+ }
- public void write32LE(int j) {
- data[position++] = (byte) j;
- data[position++] = (byte) (j >> 8);
- data[position++] = (byte) (j >> 16);
- data[position++] = (byte) (j >> 24);
- }
+ public void write32LE(int j) {
+ data[position++] = (byte) j;
+ data[position++] = (byte) (j >> 8);
+ data[position++] = (byte) (j >> 16);
+ data[position++] = (byte) (j >> 24);
+ }
- public void write64(long l) {
- data[position++] = (byte) (int) (l >> 56);
- data[position++] = (byte) (int) (l >> 48);
- data[position++] = (byte) (int) (l >> 40);
- data[position++] = (byte) (int) (l >> 32);
- data[position++] = (byte) (int) (l >> 24);
- data[position++] = (byte) (int) (l >> 16);
- data[position++] = (byte) (int) (l >> 8);
- data[position++] = (byte) (int) l;
- }
+ public void write64(long l) {
+ data[position++] = (byte) (int) (l >> 56);
+ data[position++] = (byte) (int) (l >> 48);
+ data[position++] = (byte) (int) (l >> 40);
+ data[position++] = (byte) (int) (l >> 32);
+ data[position++] = (byte) (int) (l >> 24);
+ data[position++] = (byte) (int) (l >> 16);
+ data[position++] = (byte) (int) (l >> 8);
+ data[position++] = (byte) (int) l;
+ }
- public void writeString(String s) {
- write(s.getBytes(StandardCharsets.ISO_8859_1));
- write8('\n');
- }
+ public void writeString(String s) {
+ write(s.getBytes(StandardCharsets.ISO_8859_1));
+ write8('\n');
+ }
- public void write(byte[] src, int off, int len) {
- System.arraycopy(src, off, data, position, len);
- position += len;
- }
+ public void write(byte[] src, int off, int len) {
+ System.arraycopy(src, off, data, position, len);
+ position += len;
+ }
- public void write(byte[] src) {
- write(src, 0, src.length);
- }
+ public void write(byte[] src) {
+ write(src, 0, src.length);
+ }
- public void writeA(byte[] src, int off, int len) {
- for (int i = (off + len) - 1; i >= off; i--) {
- data[position++] = (byte) (src[i] + 128);
- }
- }
+ public void writeA(byte[] src, int off, int len) {
+ for (int i = (off + len) - 1; i >= off; i--) {
+ data[position++] = (byte) (src[i] + 128);
+ }
+ }
- public byte read() {
- return data[position++];
- }
+ public byte read() {
+ return data[position++];
+ }
- public byte read8C() {
- return (byte) -data[position++];
- }
+ public byte read8C() {
+ return (byte) -data[position++];
+ }
- public byte read8S() {
- return (byte) (128 - data[position++]);
- }
+ public byte read8S() {
+ return (byte) (128 - data[position++]);
+ }
- public int read8U() {
- return data[position++] & 0xff;
- }
+ public int read8U() {
+ return data[position++] & 0xff;
+ }
- public int read8UA() {
- return (data[position++] - 128) & 0xff;
- }
+ public int read8UA() {
+ return (data[position++] - 128) & 0xff;
+ }
- public int read8UC() {
- return -data[position++] & 0xff;
- }
+ public int read8UC() {
+ return -data[position++] & 0xff;
+ }
- public int read8US() {
- return (128 - data[position++]) & 0xff;
- }
+ public int read8US() {
+ return (128 - data[position++]) & 0xff;
+ }
- /**
- * Gets a 1 or 2 byte varint which has the range [-16384...16383].
- *
- * @return the value.
- */
- public int readSmart() {
- int i = data[position] & 0xff;
- if (i < 128) {
- return read8U() - 64;
- } else {
- return read16U() - 49152;
- }
- }
+ /**
+ * Gets a 1 or 2 byte varint which has the range [-16384...16383].
+ *
+ * @return the value.
+ */
+ public int readSmart() {
+ int i = data[position] & 0xff;
+ if (i < 128) {
+ return read8U() - 64;
+ } else {
+ return read16U() - 49152;
+ }
+ }
- /**
- * Gets a 1 or 2 byte varint which has the range [0...32768].
- *
- * @return the value.
- */
- public int readSmartU() {
- int i = data[position] & 0xff;
- if (i < 128) {
- return read8U();
- } else {
- return read16U() - 32768;
- }
- }
+ /**
+ * Gets a 1 or 2 byte varint which has the range [0...32768].
+ *
+ * @return the value.
+ */
+ public int readSmartU() {
+ int i = data[position] & 0xff;
+ if (i < 128) {
+ return read8U();
+ } else {
+ return read16U() - 32768;
+ }
+ }
- public int read16U() {
- position += 2;
- return ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
- }
+ public int read16U() {
+ position += 2;
+ return ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
+ }
- public int read16UA() {
- position += 2;
- return ((data[position - 2] & 0xff) << 8) + ((data[position - 1] - 128) & 0xff);
- }
+ public int read16UA() {
+ position += 2;
+ return ((data[position - 2] & 0xff) << 8) + ((data[position - 1] - 128) & 0xff);
+ }
- public int read16ULE() {
- position += 2;
- return ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
- }
+ public int read16ULE() {
+ position += 2;
+ return ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
+ }
- public int read16ULEA() {
- position += 2;
- return ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
- }
+ public int read16ULEA() {
+ position += 2;
+ return ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
+ }
- public int read16() {
- position += 2;
- int i = ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
- if (i > 32767) {
- i -= 0x10000;
- }
- return i;
- }
+ public int read16() {
+ position += 2;
+ int i = ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
+ if (i > 32767) {
+ i -= 0x10000;
+ }
+ return i;
+ }
- public int read16LE() {
- position += 2;
- int j = ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
- if (j > 0x7fff) {
- j -= 0x10000;
- }
- return j;
- }
+ public int read16LE() {
+ position += 2;
+ int j = ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
+ if (j > 0x7fff) {
+ j -= 0x10000;
+ }
+ return j;
+ }
- public int read16LEA() {
- position += 2;
- int j = ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
- if (j > 0x7fff) {
- j -= 0x10000;
- }
- return j;
- }
+ public int read16LEA() {
+ position += 2;
+ int j = ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
+ if (j > 0x7fff) {
+ j -= 0x10000;
+ }
+ return j;
+ }
- public int read24() {
- position += 3;
- return ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
- }
+ public int read24() {
+ position += 3;
+ return ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
+ }
- public int read32() {
- position += 4;
- return ((data[position - 4] & 0xff) << 24) + ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
- }
+ public int read32() {
+ position += 4;
+ return ((data[position - 4] & 0xff) << 24) + ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
+ }
- public int read32ME() {
- position += 4;
- return ((data[position - 3] & 0xff) << 24) + ((data[position - 4] & 0xff) << 16) + ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
- }
+ public int read32ME() {
+ position += 4;
+ return ((data[position - 3] & 0xff) << 24) + ((data[position - 4] & 0xff) << 16) + ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
+ }
- public int read32RME() {
- position += 4;
- return ((data[position - 2] & 0xff) << 24) + ((data[position - 1] & 0xff) << 16) + ((data[position - 4] & 0xff) << 8) + (data[position - 3] & 0xff);
- }
+ public int read32RME() {
+ position += 4;
+ return ((data[position - 2] & 0xff) << 24) + ((data[position - 1] & 0xff) << 16) + ((data[position - 4] & 0xff) << 8) + (data[position - 3] & 0xff);
+ }
- public long read64() {
- long l = (long) read32() & 0xffffffffL;
- long l1 = (long) read32() & 0xffffffffL;
- return (l << 32) + l1;
- }
+ public long read64() {
+ long l = (long) read32() & 0xffffffffL;
+ long l1 = (long) read32() & 0xffffffffL;
+ return (l << 32) + l1;
+ }
- public String readString() {
- int start = position;
- while (data[position++] != '\n') {
- }
- return new String(data, start, position - start - 1);
- }
+ public String readString() {
+ int start = position;
+ while (data[position++] != '\n') {
+ }
+ return new String(data, start, position - start - 1);
+ }
- public byte[] readStringRaw() {
- int start = position;
- while (data[position++] != '\n') {
- }
- byte[] raw = new byte[position - start - 1];
- for (int j = start; j < (position - 1); j++) {
- raw[j - start] = data[j];
- }
- return raw;
- }
+ public byte[] readStringRaw() {
+ int start = position;
+ while (data[position++] != '\n') {
+ }
+ byte[] raw = new byte[position - start - 1];
+ for (int j = start; j < (position - 1); j++) {
+ raw[j - start] = data[j];
+ }
+ return raw;
+ }
- public void read(byte[] dst, int off, int len) {
- System.arraycopy(data, position, dst, off, len);
- position += len;
- }
+ public void read(byte[] dst, int off, int len) {
+ System.arraycopy(data, position, dst, off, len);
+ position += len;
+ }
- public void read(byte[] dst) {
- read(dst,0,dst.length);
- }
+ public void read(byte[] dst) {
+ read(dst, 0, dst.length);
+ }
- public void readReversed(byte[] dst, int off, int len) {
- for (int i = (off + len) - 1; i >= off; i--) {
- dst[i] = data[position++];
- }
- }
+ public void readReversed(byte[] dst, int off, int len) {
+ for (int i = (off + len) - 1; i >= off; i--) {
+ dst[i] = data[position++];
+ }
+ }
- public void accessBits() {
- bitPosition = position * 8;
- }
+ public void accessBits() {
+ bitPosition = position * 8;
+ }
- public int readN(int n) {
- int bytePos = bitPosition >> 3;
- int remaining = 8 - (bitPosition & 7);
- int value = 0;
- bitPosition += n;
- for (; n > remaining; remaining = 8) {
- value += (data[bytePos++] & BITMASK[remaining]) << (n - remaining);
- n -= remaining;
- }
- if (n == remaining) {
- value += data[bytePos] & BITMASK[remaining];
- } else {
- value += (data[bytePos] >> (remaining - n)) & BITMASK[n];
- }
- return value;
- }
+ public int readN(int n) {
+ int bytePos = bitPosition >> 3;
+ int remaining = 8 - (bitPosition & 7);
+ int value = 0;
+ bitPosition += n;
+ for (; n > remaining; remaining = 8) {
+ value += (data[bytePos++] & BITMASK[remaining]) << (n - remaining);
+ n -= remaining;
+ }
+ if (n == remaining) {
+ value += data[bytePos] & BITMASK[remaining];
+ } else {
+ value += (data[bytePos] >> (remaining - n)) & BITMASK[n];
+ }
+ return value;
+ }
- public void accessBytes() {
- position = (bitPosition + 7) / 8;
- }
+ public void accessBytes() {
+ position = (bitPosition + 7) / 8;
+ }
- public void encrypt(BigInteger exponent, BigInteger modulus) {
- int length = position;
- position = 0;
- byte[] raw = new byte[length];
- read(raw, 0, length);
- byte[] encrypted = new BigInteger(raw).modPow(exponent, modulus).toByteArray();
- position = 0;
- write8(encrypted.length);
- write(encrypted, 0, encrypted.length);
- }
+ public void encrypt(BigInteger exponent, BigInteger modulus) {
+ int length = position;
+ position = 0;
+ byte[] raw = new byte[length];
+ read(raw, 0, length);
+ byte[] encrypted = new BigInteger(raw).modPow(exponent, modulus).toByteArray();
+ position = 0;
+ write8(encrypted.length);
+ write(encrypted, 0, encrypted.length);
+ }
}
diff --git a/src/main/java/Censor.java b/src/main/java/Censor.java
index a2808ae..024a2fa 100644
--- a/src/main/java/Censor.java
+++ b/src/main/java/Censor.java
@@ -6,933 +6,933 @@ import java.io.IOException;
public class Censor {
- public static final String[] aStringArray626 = {"cook", "cook's", "cooks", "seeks", "sheet", "woop", "woops", "faq", "noob", "noobs"};
- public static int[] anIntArray620;
- public static char[][] aCharArrayArray621;
- public static byte[][][] aByteArrayArrayArray622;
- public static char[][] aCharArrayArray623;
- public static char[][] aCharArrayArray624;
- public static int[] anIntArray625;
+ public static final String[] aStringArray626 = {"cook", "cook's", "cooks", "seeks", "sheet", "woop", "woops", "faq", "noob", "noobs"};
+ public static int[] anIntArray620;
+ public static char[][] aCharArrayArray621;
+ public static byte[][][] aByteArrayArrayArray622;
+ public static char[][] aCharArrayArray623;
+ public static char[][] aCharArrayArray624;
+ public static int[] anIntArray625;
- public static void method487(FileArchive archive) throws IOException {
- Buffer buffer = new Buffer(archive.read("fragmentsenc.txt"));
- Buffer buffer_1 = new Buffer(archive.read("badenc.txt"));
- Buffer class30_sub2_sub2_2 = new Buffer(archive.read("domainenc.txt"));
- Buffer buffer_3 = new Buffer(archive.read("tldlist.txt"));
- method488(buffer, buffer_1, class30_sub2_sub2_2, buffer_3);
- }
+ public static void method487(FileArchive archive) throws IOException {
+ Buffer buffer = new Buffer(archive.read("fragmentsenc.txt"));
+ Buffer buffer_1 = new Buffer(archive.read("badenc.txt"));
+ Buffer class30_sub2_sub2_2 = new Buffer(archive.read("domainenc.txt"));
+ Buffer buffer_3 = new Buffer(archive.read("tldlist.txt"));
+ method488(buffer, buffer_1, class30_sub2_sub2_2, buffer_3);
+ }
- public static void method488(Buffer buffer, Buffer buffer_1, Buffer class30_sub2_sub2_2, Buffer buffer_3) {
- method490(buffer_1);
- method491(class30_sub2_sub2_2);
- method492(buffer);
- method489(buffer_3);
- }
+ public static void method488(Buffer buffer, Buffer buffer_1, Buffer class30_sub2_sub2_2, Buffer buffer_3) {
+ method490(buffer_1);
+ method491(class30_sub2_sub2_2);
+ method492(buffer);
+ method489(buffer_3);
+ }
- public static void method489(Buffer buffer) {
- int i = buffer.read32();
- aCharArrayArray624 = new char[i][];
- anIntArray625 = new int[i];
- for (int j = 0; j < i; j++) {
- anIntArray625[j] = buffer.read8U();
- char[] ac = new char[buffer.read8U()];
- for (int k = 0; k < ac.length; k++) {
- ac[k] = (char) buffer.read8U();
- }
- aCharArrayArray624[j] = ac;
- }
- }
+ public static void method489(Buffer buffer) {
+ int i = buffer.read32();
+ aCharArrayArray624 = new char[i][];
+ anIntArray625 = new int[i];
+ for (int j = 0; j < i; j++) {
+ anIntArray625[j] = buffer.read8U();
+ char[] ac = new char[buffer.read8U()];
+ for (int k = 0; k < ac.length; k++) {
+ ac[k] = (char) buffer.read8U();
+ }
+ aCharArrayArray624[j] = ac;
+ }
+ }
- public static void method490(Buffer buffer) {
- int j = buffer.read32();
- aCharArrayArray621 = new char[j][];
- aByteArrayArrayArray622 = new byte[j][][];
- method493(buffer, aCharArrayArray621, aByteArrayArrayArray622);
- }
+ public static void method490(Buffer buffer) {
+ int j = buffer.read32();
+ aCharArrayArray621 = new char[j][];
+ aByteArrayArrayArray622 = new byte[j][][];
+ method493(buffer, aCharArrayArray621, aByteArrayArrayArray622);
+ }
- public static void method491(Buffer buffer) {
- int i = buffer.read32();
- aCharArrayArray623 = new char[i][];
- method494(aCharArrayArray623, buffer, -490);
- }
+ public static void method491(Buffer buffer) {
+ int i = buffer.read32();
+ aCharArrayArray623 = new char[i][];
+ method494(aCharArrayArray623, buffer, -490);
+ }
- public static void method492(Buffer buffer) {
- anIntArray620 = new int[buffer.read32()];
- for (int i = 0; i < anIntArray620.length; i++) {
- anIntArray620[i] = buffer.read16U();
- }
- }
+ public static void method492(Buffer buffer) {
+ anIntArray620 = new int[buffer.read32()];
+ for (int i = 0; i < anIntArray620.length; i++) {
+ anIntArray620[i] = buffer.read16U();
+ }
+ }
- public static void method493(Buffer buffer, char[][] ac, byte[][][] abyte0) {
- for (int j = 0; j < ac.length; j++) {
- char[] ac1 = new char[buffer.read8U()];
- for (int k = 0; k < ac1.length; k++) {
- ac1[k] = (char) buffer.read8U();
- }
- ac[j] = ac1;
- byte[][] abyte1 = new byte[buffer.read8U()][2];
- for (int l = 0; l < abyte1.length; l++) {
- abyte1[l][0] = (byte) buffer.read8U();
- abyte1[l][1] = (byte) buffer.read8U();
- }
- if (abyte1.length > 0) {
- abyte0[j] = abyte1;
- }
- }
- }
+ public static void method493(Buffer buffer, char[][] ac, byte[][][] abyte0) {
+ for (int j = 0; j < ac.length; j++) {
+ char[] ac1 = new char[buffer.read8U()];
+ for (int k = 0; k < ac1.length; k++) {
+ ac1[k] = (char) buffer.read8U();
+ }
+ ac[j] = ac1;
+ byte[][] abyte1 = new byte[buffer.read8U()][2];
+ for (int l = 0; l < abyte1.length; l++) {
+ abyte1[l][0] = (byte) buffer.read8U();
+ abyte1[l][1] = (byte) buffer.read8U();
+ }
+ if (abyte1.length > 0) {
+ abyte0[j] = abyte1;
+ }
+ }
+ }
- public static void method494(char[][] ac, Buffer buffer, int i) {
- if (i >= 0) {
- return;
- }
- for (int j = 0; j < ac.length; j++) {
- char[] ac1 = new char[buffer.read8U()];
- for (int k = 0; k < ac1.length; k++) {
- ac1[k] = (char) buffer.read8U();
- }
- ac[j] = ac1;
- }
- }
+ public static void method494(char[][] ac, Buffer buffer, int i) {
+ if (i >= 0) {
+ return;
+ }
+ for (int j = 0; j < ac.length; j++) {
+ char[] ac1 = new char[buffer.read8U()];
+ for (int k = 0; k < ac1.length; k++) {
+ ac1[k] = (char) buffer.read8U();
+ }
+ ac[j] = ac1;
+ }
+ }
- public static void method495(char[] ac) {
- int i = 0;
- for (int j = 0; j < ac.length; j++) {
- if (method496(ac[j])) {
- ac[i] = ac[j];
- } else {
- ac[i] = ' ';
- }
- if ((i == 0) || (ac[i] != ' ') || (ac[i - 1] != ' ')) {
- i++;
- }
- }
- for (int k = i; k < ac.length; k++) {
- ac[k] = ' ';
- }
- }
+ public static void method495(char[] ac) {
+ int i = 0;
+ for (int j = 0; j < ac.length; j++) {
+ if (method496(ac[j])) {
+ ac[i] = ac[j];
+ } else {
+ ac[i] = ' ';
+ }
+ if ((i == 0) || (ac[i] != ' ') || (ac[i - 1] != ' ')) {
+ i++;
+ }
+ }
+ for (int k = i; k < ac.length; k++) {
+ ac[k] = ' ';
+ }
+ }
- public static boolean method496(char c) {
- return ((c >= ' ') && (c <= '\177')) || (c == ' ') || (c == '\n') || (c == '\t') || (c == '\243') || (c == '\u20AC');
- }
+ public static boolean method496(char c) {
+ return ((c >= ' ') && (c <= '\177')) || (c == ' ') || (c == '\n') || (c == '\t') || (c == '\243') || (c == '\u20AC');
+ }
- public static String apply(String s) {
- char[] ac = s.toCharArray();
- method495(ac);
- String s1 = new String(ac).trim();
- ac = s1.toLowerCase().toCharArray();
- String s2 = s1.toLowerCase();
- method505(ac);
- method500(ac);
- method501(ac);
- method514(ac);
- for (String value : aStringArray626) {
- for (int k = -1; (k = s2.indexOf(value, k + 1)) != -1; ) {
- char[] ac1 = value.toCharArray();
- for (int i1 = 0; i1 < ac1.length; i1++) {
- ac[i1 + k] = ac1[i1];
- }
- }
- }
- method498(s1.toCharArray(), 2, ac);
- method499(0, ac);
- return new String(ac).trim();
- }
+ public static String apply(String s) {
+ char[] ac = s.toCharArray();
+ method495(ac);
+ String s1 = new String(ac).trim();
+ ac = s1.toLowerCase().toCharArray();
+ String s2 = s1.toLowerCase();
+ method505(ac);
+ method500(ac);
+ method501(ac);
+ method514(ac);
+ for (String value : aStringArray626) {
+ for (int k = -1; (k = s2.indexOf(value, k + 1)) != -1; ) {
+ char[] ac1 = value.toCharArray();
+ for (int i1 = 0; i1 < ac1.length; i1++) {
+ ac[i1 + k] = ac1[i1];
+ }
+ }
+ }
+ method498(s1.toCharArray(), 2, ac);
+ method499(0, ac);
+ return new String(ac).trim();
+ }
- public static void method498(char[] ac, int i, char[] ac1) {
- for (int j = 0; j < ac.length; j++) {
- if ((ac1[j] != '*') && method522(ac[j])) {
- ac1[j] = ac[j];
- }
- }
- if (i == 2) {
- }
- }
+ public static void method498(char[] ac, int i, char[] ac1) {
+ for (int j = 0; j < ac.length; j++) {
+ if ((ac1[j] != '*') && method522(ac[j])) {
+ ac1[j] = ac[j];
+ }
+ }
+ if (i == 2) {
+ }
+ }
- public static void method499(int i, char[] ac) {
- boolean flag = true;
- for (int j = 0; j < ac.length; j++) {
- char c = ac[j];
- if (method519(c)) {
- if (flag) {
- if (method521(c)) {
- flag = false;
- }
- } else if (method522(c)) {
- ac[j] = (char) ((c + 97) - 65);
- }
- } else {
- flag = true;
- }
- }
- if (i == 0) {
- }
- }
+ public static void method499(int i, char[] ac) {
+ boolean flag = true;
+ for (int j = 0; j < ac.length; j++) {
+ char c = ac[j];
+ if (method519(c)) {
+ if (flag) {
+ if (method521(c)) {
+ flag = false;
+ }
+ } else if (method522(c)) {
+ ac[j] = (char) ((c + 97) - 65);
+ }
+ } else {
+ flag = true;
+ }
+ }
+ if (i == 0) {
+ }
+ }
- public static void method500(char[] ac) {
- for (int i = 0; i < 2; i++) {
- for (int j = aCharArrayArray621.length - 1; j >= 0; j--) {
- method509(aByteArrayArrayArray622[j], ac, aCharArrayArray621[j]);
- }
- }
- }
+ public static void method500(char[] ac) {
+ for (int i = 0; i < 2; i++) {
+ for (int j = aCharArrayArray621.length - 1; j >= 0; j--) {
+ method509(aByteArrayArrayArray622[j], ac, aCharArrayArray621[j]);
+ }
+ }
+ }
- public static void method501(char[] ac) {
- char[] ac1 = ac.clone();
- char[] ac2 = {'(', 'a', ')'};
- method509(null, ac1, ac2);
- char[] ac3 = ac.clone();
- char[] ac4 = {'d', 'o', 't'};
- method509(null, ac3, ac4);
- for (int i = aCharArrayArray623.length - 1; i >= 0; i--) {
- method502(ac, aCharArrayArray623[i], ac3, ac1);
- }
- }
+ public static void method501(char[] ac) {
+ char[] ac1 = ac.clone();
+ char[] ac2 = {'(', 'a', ')'};
+ method509(null, ac1, ac2);
+ char[] ac3 = ac.clone();
+ char[] ac4 = {'d', 'o', 't'};
+ method509(null, ac3, ac4);
+ for (int i = aCharArrayArray623.length - 1; i >= 0; i--) {
+ method502(ac, aCharArrayArray623[i], ac3, ac1);
+ }
+ }
- public static void method502(char[] ac, char[] ac1, char[] ac2, char[] ac3) {
- if (ac1.length > ac.length) {
- return;
- }
- int j;
- for (int k = 0; k <= (ac.length - ac1.length); k += j) {
- int l = k;
- int i1 = 0;
- j = 1;
- while (l < ac.length) {
- int j1;
- char c = ac[l];
- char c1 = '\0';
- if ((l + 1) < ac.length) {
- c1 = ac[l + 1];
- }
- if ((i1 < ac1.length) && (((j1 = method511(c, ac1[i1], c1))) > 0)) {
- l += j1;
- i1++;
- continue;
- }
- if (i1 == 0) {
- break;
- }
- if ((j1 = method511(c, ac1[i1 - 1], c1)) > 0) {
- l += j1;
- if (i1 == 1) {
- j++;
- }
- continue;
- }
- if ((i1 >= ac1.length) || !method517(c)) {
- break;
- }
- l++;
- }
- if (i1 >= ac1.length) {
- boolean flag1 = false;
- int k1 = method503(ac, ac3, k);
- int l1 = method504(ac2, l - 1, ac);
- if ((k1 > 2) || (l1 > 2)) {
- flag1 = true;
- }
- if (flag1) {
- for (int i2 = k; i2 < l; i2++) {
- ac[i2] = '*';
- }
- }
- }
- }
- }
+ public static void method502(char[] ac, char[] ac1, char[] ac2, char[] ac3) {
+ if (ac1.length > ac.length) {
+ return;
+ }
+ int j;
+ for (int k = 0; k <= (ac.length - ac1.length); k += j) {
+ int l = k;
+ int i1 = 0;
+ j = 1;
+ while (l < ac.length) {
+ int j1;
+ char c = ac[l];
+ char c1 = '\0';
+ if ((l + 1) < ac.length) {
+ c1 = ac[l + 1];
+ }
+ if ((i1 < ac1.length) && (((j1 = method511(c, ac1[i1], c1))) > 0)) {
+ l += j1;
+ i1++;
+ continue;
+ }
+ if (i1 == 0) {
+ break;
+ }
+ if ((j1 = method511(c, ac1[i1 - 1], c1)) > 0) {
+ l += j1;
+ if (i1 == 1) {
+ j++;
+ }
+ continue;
+ }
+ if ((i1 >= ac1.length) || !method517(c)) {
+ break;
+ }
+ l++;
+ }
+ if (i1 >= ac1.length) {
+ boolean flag1 = false;
+ int k1 = method503(ac, ac3, k);
+ int l1 = method504(ac2, l - 1, ac);
+ if ((k1 > 2) || (l1 > 2)) {
+ flag1 = true;
+ }
+ if (flag1) {
+ for (int i2 = k; i2 < l; i2++) {
+ ac[i2] = '*';
+ }
+ }
+ }
+ }
+ }
- public static int method503(char[] ac, char[] ac1, int j) {
- if (j == 0) {
- return 2;
- }
- for (int k = j - 1; k >= 0; k--) {
- if (!method517(ac[k])) {
- break;
- }
- if (ac[k] == '@') {
- return 3;
- }
- }
- int l = 0;
- for (int i1 = j - 1; i1 >= 0; i1--) {
- if (!method517(ac1[i1])) {
- break;
- }
- if (ac1[i1] == '*') {
- l++;
- }
- }
- if (l >= 3) {
- return 4;
- }
- return !method517(ac[j - 1]) ? 0 : 1;
- }
+ public static int method503(char[] ac, char[] ac1, int j) {
+ if (j == 0) {
+ return 2;
+ }
+ for (int k = j - 1; k >= 0; k--) {
+ if (!method517(ac[k])) {
+ break;
+ }
+ if (ac[k] == '@') {
+ return 3;
+ }
+ }
+ int l = 0;
+ for (int i1 = j - 1; i1 >= 0; i1--) {
+ if (!method517(ac1[i1])) {
+ break;
+ }
+ if (ac1[i1] == '*') {
+ l++;
+ }
+ }
+ if (l >= 3) {
+ return 4;
+ }
+ return !method517(ac[j - 1]) ? 0 : 1;
+ }
- public static int method504(char[] ac, int i, char[] ac1) {
- if ((i + 1) == ac1.length) {
- return 2;
- }
- for (int j = i + 1; j < ac1.length; j++) {
- if (!method517(ac1[j])) {
- break;
- }
- if ((ac1[j] == '.') || (ac1[j] == ',')) {
- return 3;
- }
- }
- int k = 0;
- for (int l = i + 1; l < ac1.length; l++) {
- if (!method517(ac[l])) {
- break;
- }
- if (ac[l] == '*') {
- k++;
- }
- }
- if (k >= 3) {
- return 4;
- }
- return !method517(ac1[i + 1]) ? 0 : 1;
- }
+ public static int method504(char[] ac, int i, char[] ac1) {
+ if ((i + 1) == ac1.length) {
+ return 2;
+ }
+ for (int j = i + 1; j < ac1.length; j++) {
+ if (!method517(ac1[j])) {
+ break;
+ }
+ if ((ac1[j] == '.') || (ac1[j] == ',')) {
+ return 3;
+ }
+ }
+ int k = 0;
+ for (int l = i + 1; l < ac1.length; l++) {
+ if (!method517(ac[l])) {
+ break;
+ }
+ if (ac[l] == '*') {
+ k++;
+ }
+ }
+ if (k >= 3) {
+ return 4;
+ }
+ return !method517(ac1[i + 1]) ? 0 : 1;
+ }
- public static void method505(char[] ac) {
- char[] ac1 = ac.clone();
- char[] ac2 = {'d', 'o', 't'};
- method509(null, ac1, ac2);
- char[] ac3 = ac.clone();
- char[] ac4 = {'s', 'l', 'a', 's', 'h'};
- method509(null, ac3, ac4);
- for (int i = 0; i < aCharArrayArray624.length; i++) {
- method506(ac3, aCharArrayArray624[i], anIntArray625[i], ac1, ac);
- }
- }
+ public static void method505(char[] ac) {
+ char[] ac1 = ac.clone();
+ char[] ac2 = {'d', 'o', 't'};
+ method509(null, ac1, ac2);
+ char[] ac3 = ac.clone();
+ char[] ac4 = {'s', 'l', 'a', 's', 'h'};
+ method509(null, ac3, ac4);
+ for (int i = 0; i < aCharArrayArray624.length; i++) {
+ method506(ac3, aCharArrayArray624[i], anIntArray625[i], ac1, ac);
+ }
+ }
- public static void method506(char[] ac, char[] ac1, int i, char[] ac2, char[] ac3) {
- if (ac1.length > ac3.length) {
- return;
- }
- int j;
- for (int k = 0; k <= (ac3.length - ac1.length); k += j) {
- int l = k;
- int i1 = 0;
- j = 1;
- while (l < ac3.length) {
- int j1;
- char c = ac3[l];
- char c1 = '\0';
- if ((l + 1) < ac3.length) {
- c1 = ac3[l + 1];
- }
- if ((i1 < ac1.length) && (((j1 = method511(c, ac1[i1], c1))) > 0)) {
- l += j1;
- i1++;
- continue;
- }
- if (i1 == 0) {
- break;
- }
- if ((j1 = method511(c, ac1[i1 - 1], c1)) > 0) {
- l += j1;
- if (i1 == 1) {
- j++;
- }
- continue;
- }
- if ((i1 >= ac1.length) || !method517(c)) {
- break;
- }
- l++;
- }
- if (i1 >= ac1.length) {
- boolean flag1 = false;
- int k1 = method507(ac3, k, ac2);
- int l1 = method508(ac3, ac, l - 1);
- if ((i == 1) && (k1 > 0) && (l1 > 0)) {
- flag1 = true;
- }
- if ((i == 2) && (((k1 > 2) && (l1 > 0)) || ((k1 > 0) && (l1 > 2)))) {
- flag1 = true;
- }
- if ((i == 3) && (k1 > 0) && (l1 > 2)) {
- flag1 = true;
- }
- if (flag1) {
- int i2 = k;
- int j2 = l - 1;
- if (k1 > 2) {
- if (k1 == 4) {
- boolean flag2 = false;
- for (int l2 = i2 - 1; l2 >= 0; l2--) {
- if (flag2) {
- if (ac2[l2] != '*') {
- break;
- }
- i2 = l2;
- } else if (ac2[l2] == '*') {
- i2 = l2;
- flag2 = true;
- }
- }
- }
- boolean flag3 = false;
- for (int i3 = i2 - 1; i3 >= 0; i3--) {
- if (flag3) {
- if (method517(ac3[i3])) {
- break;
- }
- i2 = i3;
- } else if (!method517(ac3[i3])) {
- flag3 = true;
- i2 = i3;
- }
- }
- }
- if (l1 > 2) {
- if (l1 == 4) {
- boolean flag4 = false;
- for (int j3 = j2 + 1; j3 < ac3.length; j3++) {
- if (flag4) {
- if (ac[j3] != '*') {
- break;
- }
- j2 = j3;
- } else if (ac[j3] == '*') {
- j2 = j3;
- flag4 = true;
- }
- }
- }
- boolean flag5 = false;
- for (int k3 = j2 + 1; k3 < ac3.length; k3++) {
- if (flag5) {
- if (method517(ac3[k3])) {
- break;
- }
- j2 = k3;
- } else if (!method517(ac3[k3])) {
- flag5 = true;
- j2 = k3;
- }
- }
- }
- for (int k2 = i2; k2 <= j2; k2++) {
- ac3[k2] = '*';
- }
- }
- }
- }
- }
+ public static void method506(char[] ac, char[] ac1, int i, char[] ac2, char[] ac3) {
+ if (ac1.length > ac3.length) {
+ return;
+ }
+ int j;
+ for (int k = 0; k <= (ac3.length - ac1.length); k += j) {
+ int l = k;
+ int i1 = 0;
+ j = 1;
+ while (l < ac3.length) {
+ int j1;
+ char c = ac3[l];
+ char c1 = '\0';
+ if ((l + 1) < ac3.length) {
+ c1 = ac3[l + 1];
+ }
+ if ((i1 < ac1.length) && (((j1 = method511(c, ac1[i1], c1))) > 0)) {
+ l += j1;
+ i1++;
+ continue;
+ }
+ if (i1 == 0) {
+ break;
+ }
+ if ((j1 = method511(c, ac1[i1 - 1], c1)) > 0) {
+ l += j1;
+ if (i1 == 1) {
+ j++;
+ }
+ continue;
+ }
+ if ((i1 >= ac1.length) || !method517(c)) {
+ break;
+ }
+ l++;
+ }
+ if (i1 >= ac1.length) {
+ boolean flag1 = false;
+ int k1 = method507(ac3, k, ac2);
+ int l1 = method508(ac3, ac, l - 1);
+ if ((i == 1) && (k1 > 0) && (l1 > 0)) {
+ flag1 = true;
+ }
+ if ((i == 2) && (((k1 > 2) && (l1 > 0)) || ((k1 > 0) && (l1 > 2)))) {
+ flag1 = true;
+ }
+ if ((i == 3) && (k1 > 0) && (l1 > 2)) {
+ flag1 = true;
+ }
+ if (flag1) {
+ int i2 = k;
+ int j2 = l - 1;
+ if (k1 > 2) {
+ if (k1 == 4) {
+ boolean flag2 = false;
+ for (int l2 = i2 - 1; l2 >= 0; l2--) {
+ if (flag2) {
+ if (ac2[l2] != '*') {
+ break;
+ }
+ i2 = l2;
+ } else if (ac2[l2] == '*') {
+ i2 = l2;
+ flag2 = true;
+ }
+ }
+ }
+ boolean flag3 = false;
+ for (int i3 = i2 - 1; i3 >= 0; i3--) {
+ if (flag3) {
+ if (method517(ac3[i3])) {
+ break;
+ }
+ i2 = i3;
+ } else if (!method517(ac3[i3])) {
+ flag3 = true;
+ i2 = i3;
+ }
+ }
+ }
+ if (l1 > 2) {
+ if (l1 == 4) {
+ boolean flag4 = false;
+ for (int j3 = j2 + 1; j3 < ac3.length; j3++) {
+ if (flag4) {
+ if (ac[j3] != '*') {
+ break;
+ }
+ j2 = j3;
+ } else if (ac[j3] == '*') {
+ j2 = j3;
+ flag4 = true;
+ }
+ }
+ }
+ boolean flag5 = false;
+ for (int k3 = j2 + 1; k3 < ac3.length; k3++) {
+ if (flag5) {
+ if (method517(ac3[k3])) {
+ break;
+ }
+ j2 = k3;
+ } else if (!method517(ac3[k3])) {
+ flag5 = true;
+ j2 = k3;
+ }
+ }
+ }
+ for (int k2 = i2; k2 <= j2; k2++) {
+ ac3[k2] = '*';
+ }
+ }
+ }
+ }
+ }
- public static int method507(char[] ac, int j, char[] ac1) {
- if (j == 0) {
- return 2;
- }
- for (int k = j - 1; k >= 0; k--) {
- if (!method517(ac[k])) {
- break;
- }
- if ((ac[k] == ',') || (ac[k] == '.')) {
- return 3;
- }
- }
- int l = 0;
- for (int i1 = j - 1; i1 >= 0; i1--) {
- if (!method517(ac1[i1])) {
- break;
- }
- if (ac1[i1] == '*') {
- l++;
- }
- }
- if (l >= 3) {
- return 4;
- }
- return !method517(ac[j - 1]) ? 0 : 1;
- }
+ public static int method507(char[] ac, int j, char[] ac1) {
+ if (j == 0) {
+ return 2;
+ }
+ for (int k = j - 1; k >= 0; k--) {
+ if (!method517(ac[k])) {
+ break;
+ }
+ if ((ac[k] == ',') || (ac[k] == '.')) {
+ return 3;
+ }
+ }
+ int l = 0;
+ for (int i1 = j - 1; i1 >= 0; i1--) {
+ if (!method517(ac1[i1])) {
+ break;
+ }
+ if (ac1[i1] == '*') {
+ l++;
+ }
+ }
+ if (l >= 3) {
+ return 4;
+ }
+ return !method517(ac[j - 1]) ? 0 : 1;
+ }
- public static int method508(char[] ac, char[] ac1, int i) {
- if ((i + 1) == ac.length) {
- return 2;
- }
- for (int j = i + 1; j < ac.length; j++) {
- if (!method517(ac[j])) {
- break;
- }
- if ((ac[j] == '\\') || (ac[j] == '/')) {
- return 3;
- }
- }
- int k = 0;
- for (int l = i + 1; l < ac.length; l++) {
- if (!method517(ac1[l])) {
- break;
- }
- if (ac1[l] == '*') {
- k++;
- }
- }
- if (k >= 5) {
- return 4;
- }
- return !method517(ac[i + 1]) ? 0 : 1;
- }
+ public static int method508(char[] ac, char[] ac1, int i) {
+ if ((i + 1) == ac.length) {
+ return 2;
+ }
+ for (int j = i + 1; j < ac.length; j++) {
+ if (!method517(ac[j])) {
+ break;
+ }
+ if ((ac[j] == '\\') || (ac[j] == '/')) {
+ return 3;
+ }
+ }
+ int k = 0;
+ for (int l = i + 1; l < ac.length; l++) {
+ if (!method517(ac1[l])) {
+ break;
+ }
+ if (ac1[l] == '*') {
+ k++;
+ }
+ }
+ if (k >= 5) {
+ return 4;
+ }
+ return !method517(ac[i + 1]) ? 0 : 1;
+ }
- public static void method509(byte[][] abyte0, char[] ac, char[] ac1) {
- if (ac1.length > ac.length) {
- return;
- }
- int j;
- for (int k = 0; k <= (ac.length - ac1.length); k += j) {
- int l = k;
- int i1 = 0;
- int j1 = 0;
- j = 1;
- boolean flag1 = false;
- boolean flag2 = false;
- boolean flag3 = false;
- while ((l < ac.length) && (!flag2 || !flag3)) {
- int k1;
- char c = ac[l];
- char c2 = '\0';
- if ((l + 1) < ac.length) {
- c2 = ac[l + 1];
- }
- if ((i1 < ac1.length) && (((k1 = method512(c2, c, ac1[i1]))) > 0)) {
- if ((k1 == 1) && method520(c)) {
- flag2 = true;
- }
- if ((k1 == 2) && (method520(c) || method520(c2))) {
- flag2 = true;
- }
- l += k1;
- i1++;
- continue;
- }
- if (i1 == 0) {
- break;
- }
- if ((k1 = method512(c2, c, ac1[i1 - 1])) > 0) {
- l += k1;
- if (i1 == 1) {
- j++;
- }
- continue;
- }
- if ((i1 >= ac1.length) || !method518(c)) {
- break;
- }
- if (method517(c) && (c != '\'')) {
- flag1 = true;
- }
- if (method520(c)) {
- flag3 = true;
- }
- l++;
- if (((++j1 * 100) / (l - k)) > 90) {
- break;
- }
- }
- if ((i1 >= ac1.length) && (!flag2 || !flag3)) {
- boolean flag4 = true;
- if (!flag1) {
- char c1 = ' ';
- if ((k - 1) >= 0) {
- c1 = ac[k - 1];
- }
- char c3 = ' ';
- if (l < ac.length) {
- c3 = ac[l];
- }
- byte byte0 = method513(c1);
- byte byte1 = method513(c3);
- if ((abyte0 != null) && method510(byte0, abyte0, byte1)) {
- flag4 = false;
- }
- } else {
- boolean flag5 = false;
- boolean flag6 = false;
- if (((k - 1) < 0) || (method517(ac[k - 1]) && (ac[k - 1] != '\''))) {
- flag5 = true;
- }
- if ((l >= ac.length) || (method517(ac[l]) && (ac[l] != '\''))) {
- flag6 = true;
- }
- if (!flag5 || !flag6) {
- boolean flag7 = false;
- int k2 = k - 2;
- if (flag5) {
- k2 = k;
- }
- for (; !flag7 && (k2 < l); k2++) {
- if ((k2 >= 0) && (!method517(ac[k2]) || (ac[k2] == '\''))) {
- char[] ac2 = new char[3];
- int j3;
- for (j3 = 0; j3 < 3; j3++) {
- if (((k2 + j3) >= ac.length) || (method517(ac[k2 + j3]) && (ac[k2 + j3] != '\''))) {
- break;
- }
- ac2[j3] = ac[k2 + j3];
- }
- boolean flag8 = true;
- if (j3 == 0) {
- flag8 = false;
- }
- if ((j3 < 3) && ((k2 - 1) >= 0) && (!method517(ac[k2 - 1]) || (ac[k2 - 1] == '\''))) {
- flag8 = false;
- }
- if (flag8 && !method523(ac2)) {
- flag7 = true;
- }
- }
- }
- if (!flag7) {
- flag4 = false;
- }
- }
- }
- if (flag4) {
- int l1 = 0;
- int i2 = 0;
- int j2 = -1;
- for (int l2 = k; l2 < l; l2++) {
- if (method520(ac[l2])) {
- l1++;
- } else if (method519(ac[l2])) {
- i2++;
- j2 = l2;
- }
- }
- if (j2 > -1) {
- l1 -= l - 1 - j2;
- }
- if (l1 <= i2) {
- for (int i3 = k; i3 < l; i3++) {
- ac[i3] = '*';
- }
- } else {
- j = 1;
- }
- }
- }
- }
- }
+ public static void method509(byte[][] abyte0, char[] ac, char[] ac1) {
+ if (ac1.length > ac.length) {
+ return;
+ }
+ int j;
+ for (int k = 0; k <= (ac.length - ac1.length); k += j) {
+ int l = k;
+ int i1 = 0;
+ int j1 = 0;
+ j = 1;
+ boolean flag1 = false;
+ boolean flag2 = false;
+ boolean flag3 = false;
+ while ((l < ac.length) && (!flag2 || !flag3)) {
+ int k1;
+ char c = ac[l];
+ char c2 = '\0';
+ if ((l + 1) < ac.length) {
+ c2 = ac[l + 1];
+ }
+ if ((i1 < ac1.length) && (((k1 = method512(c2, c, ac1[i1]))) > 0)) {
+ if ((k1 == 1) && method520(c)) {
+ flag2 = true;
+ }
+ if ((k1 == 2) && (method520(c) || method520(c2))) {
+ flag2 = true;
+ }
+ l += k1;
+ i1++;
+ continue;
+ }
+ if (i1 == 0) {
+ break;
+ }
+ if ((k1 = method512(c2, c, ac1[i1 - 1])) > 0) {
+ l += k1;
+ if (i1 == 1) {
+ j++;
+ }
+ continue;
+ }
+ if ((i1 >= ac1.length) || !method518(c)) {
+ break;
+ }
+ if (method517(c) && (c != '\'')) {
+ flag1 = true;
+ }
+ if (method520(c)) {
+ flag3 = true;
+ }
+ l++;
+ if (((++j1 * 100) / (l - k)) > 90) {
+ break;
+ }
+ }
+ if ((i1 >= ac1.length) && (!flag2 || !flag3)) {
+ boolean flag4 = true;
+ if (!flag1) {
+ char c1 = ' ';
+ if ((k - 1) >= 0) {
+ c1 = ac[k - 1];
+ }
+ char c3 = ' ';
+ if (l < ac.length) {
+ c3 = ac[l];
+ }
+ byte byte0 = method513(c1);
+ byte byte1 = method513(c3);
+ if ((abyte0 != null) && method510(byte0, abyte0, byte1)) {
+ flag4 = false;
+ }
+ } else {
+ boolean flag5 = false;
+ boolean flag6 = false;
+ if (((k - 1) < 0) || (method517(ac[k - 1]) && (ac[k - 1] != '\''))) {
+ flag5 = true;
+ }
+ if ((l >= ac.length) || (method517(ac[l]) && (ac[l] != '\''))) {
+ flag6 = true;
+ }
+ if (!flag5 || !flag6) {
+ boolean flag7 = false;
+ int k2 = k - 2;
+ if (flag5) {
+ k2 = k;
+ }
+ for (; !flag7 && (k2 < l); k2++) {
+ if ((k2 >= 0) && (!method517(ac[k2]) || (ac[k2] == '\''))) {
+ char[] ac2 = new char[3];
+ int j3;
+ for (j3 = 0; j3 < 3; j3++) {
+ if (((k2 + j3) >= ac.length) || (method517(ac[k2 + j3]) && (ac[k2 + j3] != '\''))) {
+ break;
+ }
+ ac2[j3] = ac[k2 + j3];
+ }
+ boolean flag8 = true;
+ if (j3 == 0) {
+ flag8 = false;
+ }
+ if ((j3 < 3) && ((k2 - 1) >= 0) && (!method517(ac[k2 - 1]) || (ac[k2 - 1] == '\''))) {
+ flag8 = false;
+ }
+ if (flag8 && !method523(ac2)) {
+ flag7 = true;
+ }
+ }
+ }
+ if (!flag7) {
+ flag4 = false;
+ }
+ }
+ }
+ if (flag4) {
+ int l1 = 0;
+ int i2 = 0;
+ int j2 = -1;
+ for (int l2 = k; l2 < l; l2++) {
+ if (method520(ac[l2])) {
+ l1++;
+ } else if (method519(ac[l2])) {
+ i2++;
+ j2 = l2;
+ }
+ }
+ if (j2 > -1) {
+ l1 -= l - 1 - j2;
+ }
+ if (l1 <= i2) {
+ for (int i3 = k; i3 < l; i3++) {
+ ac[i3] = '*';
+ }
+ } else {
+ j = 1;
+ }
+ }
+ }
+ }
+ }
- public static boolean method510(byte byte0, byte[][] abyte0, byte byte2) {
- int i = 0;
- if ((abyte0[i][0] == byte0) && (abyte0[i][1] == byte2)) {
- return true;
- }
- int j = abyte0.length - 1;
- if ((abyte0[j][0] == byte0) && (abyte0[j][1] == byte2)) {
- return true;
- }
- do {
- int k = (i + j) / 2;
- if ((abyte0[k][0] == byte0) && (abyte0[k][1] == byte2)) {
- return true;
- }
- if ((byte0 < abyte0[k][0]) || ((byte0 == abyte0[k][0]) && (byte2 < abyte0[k][1]))) {
- j = k;
- } else {
- i = k;
- }
- } while ((i != j) && ((i + 1) != j));
- return false;
- }
+ public static boolean method510(byte byte0, byte[][] abyte0, byte byte2) {
+ int i = 0;
+ if ((abyte0[i][0] == byte0) && (abyte0[i][1] == byte2)) {
+ return true;
+ }
+ int j = abyte0.length - 1;
+ if ((abyte0[j][0] == byte0) && (abyte0[j][1] == byte2)) {
+ return true;
+ }
+ do {
+ int k = (i + j) / 2;
+ if ((abyte0[k][0] == byte0) && (abyte0[k][1] == byte2)) {
+ return true;
+ }
+ if ((byte0 < abyte0[k][0]) || ((byte0 == abyte0[k][0]) && (byte2 < abyte0[k][1]))) {
+ j = k;
+ } else {
+ i = k;
+ }
+ } while ((i != j) && ((i + 1) != j));
+ return false;
+ }
- public static int method511(char c, char c1, char c2) {
- if (c1 == c) {
- return 1;
- }
- if ((c1 == 'o') && (c == '0')) {
- return 1;
- }
- if ((c1 == 'o') && (c == '(') && (c2 == ')')) {
- return 2;
- }
- if ((c1 == 'c') && ((c == '(') || (c == '<') || (c == '['))) {
- return 1;
- }
- if ((c1 == 'e') && (c == '\u20AC')) {
- return 1;
- }
- if ((c1 == 's') && (c == '$')) {
- return 1;
- }
- return ((c1 != 'l') || (c != 'i')) ? 0 : 1;
- }
+ public static int method511(char c, char c1, char c2) {
+ if (c1 == c) {
+ return 1;
+ }
+ if ((c1 == 'o') && (c == '0')) {
+ return 1;
+ }
+ if ((c1 == 'o') && (c == '(') && (c2 == ')')) {
+ return 2;
+ }
+ if ((c1 == 'c') && ((c == '(') || (c == '<') || (c == '['))) {
+ return 1;
+ }
+ if ((c1 == 'e') && (c == '\u20AC')) {
+ return 1;
+ }
+ if ((c1 == 's') && (c == '$')) {
+ return 1;
+ }
+ return ((c1 != 'l') || (c != 'i')) ? 0 : 1;
+ }
- public static int method512(char c, char c1, char c2) {
- if (c2 == c1) {
- return 1;
- }
- if ((c2 >= 'a') && (c2 <= 'm')) {
- if (c2 == 'a') {
- if ((c1 == '4') || (c1 == '@') || (c1 == '^')) {
- return 1;
- }
- return ((c1 != '/') || (c != '\\')) ? 0 : 2;
- }
- if (c2 == 'b') {
- if ((c1 == '6') || (c1 == '8')) {
- return 1;
- }
- return (((c1 != '1') || (c != '3')) && ((c1 != 'i') || (c != '3'))) ? 0 : 2;
- }
- if (c2 == 'c') {
- return ((c1 != '(') && (c1 != '<') && (c1 != '{') && (c1 != '[')) ? 0 : 1;
- }
- if (c2 == 'd') {
- return (((c1 != '[') || (c != ')')) && ((c1 != 'i') || (c != ')'))) ? 0 : 2;
- }
- if (c2 == 'e') {
- return ((c1 != '3') && (c1 != '\u20AC')) ? 0 : 1;
- }
- if (c2 == 'f') {
- if ((c1 == 'p') && (c == 'h')) {
- return 2;
- }
- return (c1 != '\243') ? 0 : 1;
- }
- if (c2 == 'g') {
- return ((c1 != '9') && (c1 != '6') && (c1 != 'q')) ? 0 : 1;
- }
- if (c2 == 'h') {
- return (c1 != '#') ? 0 : 1;
- }
- if (c2 == 'i') {
- return ((c1 != 'y') && (c1 != 'l') && (c1 != 'j') && (c1 != '1') && (c1 != '!') && (c1 != ':') && (c1 != ';') && (c1 != '|')) ? 0 : 1;
- }
- if (c2 == 'j') {
- return 0;
- }
- if (c2 == 'k') {
- return 0;
- }
- if (c2 == 'l') {
- return ((c1 != '1') && (c1 != '|') && (c1 != 'i')) ? 0 : 1;
- }
- if (c2 == 'm') {
- return 0;
- }
- }
- if ((c2 >= 'n') && (c2 <= 'z')) {
- if (c2 == 'n') {
- return 0;
- }
- if (c2 == 'o') {
- if ((c1 == '0') || (c1 == '*')) {
- return 1;
- }
- return (((c1 != '(') || (c != ')')) && ((c1 != '[') || (c != ']')) && ((c1 != '{') || (c != '}')) && ((c1 != '<') || (c != '>'))) ? 0 : 2;
- }
- if (c2 == 'p') {
- return 0;
- }
- if (c2 == 'q') {
- return 0;
- }
- if (c2 == 'r') {
- return 0;
- }
- if (c2 == 's') {
- return ((c1 != '5') && (c1 != 'z') && (c1 != '$') && (c1 != '2')) ? 0 : 1;
- }
- if (c2 == 't') {
- return ((c1 != '7') && (c1 != '+')) ? 0 : 1;
- }
- if (c2 == 'u') {
- if (c1 == 'v') {
- return 1;
- }
- return (((c1 != '\\') || (c != '/')) && ((c1 != '\\') || (c != '|')) && ((c1 != '|') || (c != '/'))) ? 0 : 2;
- }
- if (c2 == 'v') {
- return (((c1 != '\\') || (c != '/')) && ((c1 != '\\') || (c != '|')) && ((c1 != '|') || (c != '/'))) ? 0 : 2;
- }
- if (c2 == 'w') {
- return ((c1 != 'v') || (c != 'v')) ? 0 : 2;
- }
- if (c2 == 'x') {
- return (((c1 != ')') || (c != '(')) && ((c1 != '}') || (c != '{')) && ((c1 != ']') || (c != '[')) && ((c1 != '>') || (c != '<'))) ? 0 : 2;
- }
- if (c2 == 'y') {
- return 0;
- }
- if (c2 == 'z') {
- return 0;
- }
- }
- if ((c2 >= '0') && (c2 <= '9')) {
- if (c2 == '0') {
- if ((c1 == 'o') || (c1 == 'O')) {
- return 1;
- }
- return (((c1 != '(') || (c != ')')) && ((c1 != '{') || (c != '}')) && ((c1 != '[') || (c != ']'))) ? 0 : 2;
- }
- if (c2 == '1') {
- return (c1 != 'l') ? 0 : 1;
- } else {
- return 0;
- }
- }
- if (c2 == ',') {
- return (c1 != '.') ? 0 : 1;
- }
- if (c2 == '.') {
- return (c1 != ',') ? 0 : 1;
- }
- if (c2 == '!') {
- return (c1 != 'i') ? 0 : 1;
- } else {
- return 0;
- }
- }
+ public static int method512(char c, char c1, char c2) {
+ if (c2 == c1) {
+ return 1;
+ }
+ if ((c2 >= 'a') && (c2 <= 'm')) {
+ if (c2 == 'a') {
+ if ((c1 == '4') || (c1 == '@') || (c1 == '^')) {
+ return 1;
+ }
+ return ((c1 != '/') || (c != '\\')) ? 0 : 2;
+ }
+ if (c2 == 'b') {
+ if ((c1 == '6') || (c1 == '8')) {
+ return 1;
+ }
+ return (((c1 != '1') || (c != '3')) && ((c1 != 'i') || (c != '3'))) ? 0 : 2;
+ }
+ if (c2 == 'c') {
+ return ((c1 != '(') && (c1 != '<') && (c1 != '{') && (c1 != '[')) ? 0 : 1;
+ }
+ if (c2 == 'd') {
+ return (((c1 != '[') || (c != ')')) && ((c1 != 'i') || (c != ')'))) ? 0 : 2;
+ }
+ if (c2 == 'e') {
+ return ((c1 != '3') && (c1 != '\u20AC')) ? 0 : 1;
+ }
+ if (c2 == 'f') {
+ if ((c1 == 'p') && (c == 'h')) {
+ return 2;
+ }
+ return (c1 != '\243') ? 0 : 1;
+ }
+ if (c2 == 'g') {
+ return ((c1 != '9') && (c1 != '6') && (c1 != 'q')) ? 0 : 1;
+ }
+ if (c2 == 'h') {
+ return (c1 != '#') ? 0 : 1;
+ }
+ if (c2 == 'i') {
+ return ((c1 != 'y') && (c1 != 'l') && (c1 != 'j') && (c1 != '1') && (c1 != '!') && (c1 != ':') && (c1 != ';') && (c1 != '|')) ? 0 : 1;
+ }
+ if (c2 == 'j') {
+ return 0;
+ }
+ if (c2 == 'k') {
+ return 0;
+ }
+ if (c2 == 'l') {
+ return ((c1 != '1') && (c1 != '|') && (c1 != 'i')) ? 0 : 1;
+ }
+ if (c2 == 'm') {
+ return 0;
+ }
+ }
+ if ((c2 >= 'n') && (c2 <= 'z')) {
+ if (c2 == 'n') {
+ return 0;
+ }
+ if (c2 == 'o') {
+ if ((c1 == '0') || (c1 == '*')) {
+ return 1;
+ }
+ return (((c1 != '(') || (c != ')')) && ((c1 != '[') || (c != ']')) && ((c1 != '{') || (c != '}')) && ((c1 != '<') || (c != '>'))) ? 0 : 2;
+ }
+ if (c2 == 'p') {
+ return 0;
+ }
+ if (c2 == 'q') {
+ return 0;
+ }
+ if (c2 == 'r') {
+ return 0;
+ }
+ if (c2 == 's') {
+ return ((c1 != '5') && (c1 != 'z') && (c1 != '$') && (c1 != '2')) ? 0 : 1;
+ }
+ if (c2 == 't') {
+ return ((c1 != '7') && (c1 != '+')) ? 0 : 1;
+ }
+ if (c2 == 'u') {
+ if (c1 == 'v') {
+ return 1;
+ }
+ return (((c1 != '\\') || (c != '/')) && ((c1 != '\\') || (c != '|')) && ((c1 != '|') || (c != '/'))) ? 0 : 2;
+ }
+ if (c2 == 'v') {
+ return (((c1 != '\\') || (c != '/')) && ((c1 != '\\') || (c != '|')) && ((c1 != '|') || (c != '/'))) ? 0 : 2;
+ }
+ if (c2 == 'w') {
+ return ((c1 != 'v') || (c != 'v')) ? 0 : 2;
+ }
+ if (c2 == 'x') {
+ return (((c1 != ')') || (c != '(')) && ((c1 != '}') || (c != '{')) && ((c1 != ']') || (c != '[')) && ((c1 != '>') || (c != '<'))) ? 0 : 2;
+ }
+ if (c2 == 'y') {
+ return 0;
+ }
+ if (c2 == 'z') {
+ return 0;
+ }
+ }
+ if ((c2 >= '0') && (c2 <= '9')) {
+ if (c2 == '0') {
+ if ((c1 == 'o') || (c1 == 'O')) {
+ return 1;
+ }
+ return (((c1 != '(') || (c != ')')) && ((c1 != '{') || (c != '}')) && ((c1 != '[') || (c != ']'))) ? 0 : 2;
+ }
+ if (c2 == '1') {
+ return (c1 != 'l') ? 0 : 1;
+ } else {
+ return 0;
+ }
+ }
+ if (c2 == ',') {
+ return (c1 != '.') ? 0 : 1;
+ }
+ if (c2 == '.') {
+ return (c1 != ',') ? 0 : 1;
+ }
+ if (c2 == '!') {
+ return (c1 != 'i') ? 0 : 1;
+ } else {
+ return 0;
+ }
+ }
- public static byte method513(char c) {
- if ((c >= 'a') && (c <= 'z')) {
- return (byte) ((c - 97) + 1);
- }
- if (c == '\'') {
- return 28;
- }
- if ((c >= '0') && (c <= '9')) {
- return (byte) ((c - 48) + 29);
- } else {
- return 27;
- }
- }
+ public static byte method513(char c) {
+ if ((c >= 'a') && (c <= 'z')) {
+ return (byte) ((c - 97) + 1);
+ }
+ if (c == '\'') {
+ return 28;
+ }
+ if ((c >= '0') && (c <= '9')) {
+ return (byte) ((c - 48) + 29);
+ } else {
+ return 27;
+ }
+ }
- public static void method514(char[] ac) {
- int j;
- int k = 0;
- int l = 0;
- int i1 = 0;
- while ((j = method515(ac, k)) != -1) {
- boolean flag = false;
- for (int j1 = k; (j1 >= 0) && (j1 < j) && !flag; j1++) {
- if (!method517(ac[j1]) && !method518(ac[j1])) {
- flag = true;
- }
- }
- if (flag) {
- l = 0;
- }
- if (l == 0) {
- i1 = j;
- }
- k = method516(ac, j);
- int k1 = 0;
- for (int l1 = j; l1 < k; l1++) {
- k1 = ((k1 * 10) + ac[l1]) - 48;
- }
- if ((k1 > 255) || ((k - j) > 8)) {
- l = 0;
- } else {
- l++;
- }
- if (l == 4) {
- for (int i2 = i1; i2 < k; i2++) {
- ac[i2] = '*';
- }
- l = 0;
- }
- }
- }
+ public static void method514(char[] ac) {
+ int j;
+ int k = 0;
+ int l = 0;
+ int i1 = 0;
+ while ((j = method515(ac, k)) != -1) {
+ boolean flag = false;
+ for (int j1 = k; (j1 >= 0) && (j1 < j) && !flag; j1++) {
+ if (!method517(ac[j1]) && !method518(ac[j1])) {
+ flag = true;
+ }
+ }
+ if (flag) {
+ l = 0;
+ }
+ if (l == 0) {
+ i1 = j;
+ }
+ k = method516(ac, j);
+ int k1 = 0;
+ for (int l1 = j; l1 < k; l1++) {
+ k1 = ((k1 * 10) + ac[l1]) - 48;
+ }
+ if ((k1 > 255) || ((k - j) > 8)) {
+ l = 0;
+ } else {
+ l++;
+ }
+ if (l == 4) {
+ for (int i2 = i1; i2 < k; i2++) {
+ ac[i2] = '*';
+ }
+ l = 0;
+ }
+ }
+ }
- public static int method515(char[] ac, int i) {
- for (int k = i; (k < ac.length) && (k >= 0); k++) {
- if ((ac[k] >= '0') && (ac[k] <= '9')) {
- return k;
- }
- }
- return -1;
- }
+ public static int method515(char[] ac, int i) {
+ for (int k = i; (k < ac.length) && (k >= 0); k++) {
+ if ((ac[k] >= '0') && (ac[k] <= '9')) {
+ return k;
+ }
+ }
+ return -1;
+ }
- public static int method516(char[] ac, int j) {
- for (int k = j; (k < ac.length) && (k >= 0); k++) {
- if ((ac[k] < '0') || (ac[k] > '9')) {
- return k;
- }
- }
- return ac.length;
- }
+ public static int method516(char[] ac, int j) {
+ for (int k = j; (k < ac.length) && (k >= 0); k++) {
+ if ((ac[k] < '0') || (ac[k] > '9')) {
+ return k;
+ }
+ }
+ return ac.length;
+ }
- public static boolean method517(char c) {
- return !method519(c) && !method520(c);
- }
+ public static boolean method517(char c) {
+ return !method519(c) && !method520(c);
+ }
- public static boolean method518(char c) {
- if ((c < 'a') || (c > 'z')) {
- return true;
- }
- return (c == 'v') || (c == 'x') || (c == 'j') || (c == 'q') || (c == 'z');
- }
+ public static boolean method518(char c) {
+ if ((c < 'a') || (c > 'z')) {
+ return true;
+ }
+ return (c == 'v') || (c == 'x') || (c == 'j') || (c == 'q') || (c == 'z');
+ }
- public static boolean method519(char c) {
- return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
- }
+ public static boolean method519(char c) {
+ return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
+ }
- public static boolean method520(char c) {
- return (c >= '0') && (c <= '9');
- }
+ public static boolean method520(char c) {
+ return (c >= '0') && (c <= '9');
+ }
- public static boolean method521(char c) {
- return (c >= 'a') && (c <= 'z');
- }
+ public static boolean method521(char c) {
+ return (c >= 'a') && (c <= 'z');
+ }
- public static boolean method522(char c) {
- return (c >= 'A') && (c <= 'Z');
- }
+ public static boolean method522(char c) {
+ return (c >= 'A') && (c <= 'Z');
+ }
- public static boolean method523(char[] ac) {
- boolean flag = true;
- for (char c : ac) {
- if (!method520(c) && (c != 0)) {
- flag = false;
- break;
- }
- }
- if (flag) {
- return true;
- }
- int j = method524(ac);
- int k = 0;
- int l = anIntArray620.length - 1;
- if ((j == anIntArray620[k]) || (j == anIntArray620[l])) {
- return true;
- }
- do {
- int i1 = (k + l) / 2;
- if (j == anIntArray620[i1]) {
- return true;
- }
- if (j < anIntArray620[i1]) {
- l = i1;
- } else {
- k = i1;
- }
- } while ((k != l) && ((k + 1) != l));
- return false;
- }
+ public static boolean method523(char[] ac) {
+ boolean flag = true;
+ for (char c : ac) {
+ if (!method520(c) && (c != 0)) {
+ flag = false;
+ break;
+ }
+ }
+ if (flag) {
+ return true;
+ }
+ int j = method524(ac);
+ int k = 0;
+ int l = anIntArray620.length - 1;
+ if ((j == anIntArray620[k]) || (j == anIntArray620[l])) {
+ return true;
+ }
+ do {
+ int i1 = (k + l) / 2;
+ if (j == anIntArray620[i1]) {
+ return true;
+ }
+ if (j < anIntArray620[i1]) {
+ l = i1;
+ } else {
+ k = i1;
+ }
+ } while ((k != l) && ((k + 1) != l));
+ return false;
+ }
- public static int method524(char[] ac) {
- if (ac.length > 6) {
- return 0;
- }
- int k = 0;
- for (int l = 0; l < ac.length; l++) {
- char c = ac[ac.length - l - 1];
- if ((c >= 'a') && (c <= 'z')) {
- k = (((k * 38) + c) - 97) + 1;
- } else if (c == '\'') {
- k = (k * 38) + 27;
- } else if ((c >= '0') && (c <= '9')) {
- k = (((k * 38) + c) - 48) + 28;
- } else if (c != 0) {
- return 0;
- }
- }
- return k;
- }
+ public static int method524(char[] ac) {
+ if (ac.length > 6) {
+ return 0;
+ }
+ int k = 0;
+ for (int l = 0; l < ac.length; l++) {
+ char c = ac[ac.length - l - 1];
+ if ((c >= 'a') && (c <= 'z')) {
+ k = (((k * 38) + c) - 97) + 1;
+ } else if (c == '\'') {
+ k = (k * 38) + 27;
+ } else if ((c >= '0') && (c <= '9')) {
+ k = (((k * 38) + c) - 48) + 28;
+ } else if (c != 0) {
+ return 0;
+ }
+ }
+ return k;
+ }
}
diff --git a/src/main/java/CollisionMap.java b/src/main/java/CollisionMap.java
index db18c15..89674b1 100644
--- a/src/main/java/CollisionMap.java
+++ b/src/main/java/CollisionMap.java
@@ -79,19 +79,19 @@ public class CollisionMap {
}
} else if (type == 2) {
if (rotation == 0) {
- add(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_N);
+ add(x, z, FLAG_BLOCK_ENTITY_W | FLAG_BLOCK_ENTITY_N);
add(x - 1, z, FLAG_BLOCK_ENTITY_E);
add(x, z + 1, FLAG_BLOCK_ENTITY_S);
} else if (rotation == 1) {
- add(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_N);
+ add(x, z, FLAG_BLOCK_ENTITY_E | FLAG_BLOCK_ENTITY_N);
add(x, z + 1, FLAG_BLOCK_ENTITY_S);
add(x + 1, z, FLAG_BLOCK_ENTITY_W);
} else if (rotation == 2) {
- add(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_S);
+ add(x, z, FLAG_BLOCK_ENTITY_E | FLAG_BLOCK_ENTITY_S);
add(x + 1, z, FLAG_BLOCK_ENTITY_W);
add(x, z - 1, FLAG_BLOCK_ENTITY_N);
} else if (rotation == 3) {
- add(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_S);
+ add(x, z, FLAG_BLOCK_ENTITY_W | FLAG_BLOCK_ENTITY_S);
add(x, z - 1, FLAG_BLOCK_ENTITY_N);
add(x - 1, z, FLAG_BLOCK_ENTITY_E);
}
@@ -128,19 +128,19 @@ public class CollisionMap {
}
} else if (type == 2) {
if (rotation == 0) {
- add(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_N);
+ add(x, z, FLAG_BLOCK_PROJECTILE_W | FLAG_BLOCK_PROJECTILE_N);
add(x - 1, z, FLAG_BLOCK_PROJECTILE_E);
add(x, z + 1, FLAG_BLOCK_PROJECTILE_S);
} else if (rotation == 1) {
- add(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_N);
+ add(x, z, FLAG_BLOCK_PROJECTILE_E | FLAG_BLOCK_PROJECTILE_N);
add(x, z + 1, FLAG_BLOCK_PROJECTILE_S);
add(x + 1, z, FLAG_BLOCK_PROJECTILE_W);
} else if (rotation == 2) {
- add(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_S);
+ add(x, z, FLAG_BLOCK_PROJECTILE_E | FLAG_BLOCK_PROJECTILE_S);
add(x + 1, z, FLAG_BLOCK_PROJECTILE_W);
add(x, z - 1, FLAG_BLOCK_PROJECTILE_N);
} else if (rotation == 3) {
- add(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_S);
+ add(x, z, FLAG_BLOCK_PROJECTILE_W | FLAG_BLOCK_PROJECTILE_S);
add(x, z - 1, FLAG_BLOCK_PROJECTILE_N);
add(x - 1, z, FLAG_BLOCK_PROJECTILE_E);
}
@@ -211,19 +211,19 @@ public class CollisionMap {
}
} else if (type == 2) {
if (rotation == 0) {
- remove(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_N);
+ remove(x, z, FLAG_BLOCK_ENTITY_W | FLAG_BLOCK_ENTITY_N);
remove(x - 1, z, FLAG_BLOCK_ENTITY_E);
remove(x, z + 1, FLAG_BLOCK_ENTITY_S);
} else if (rotation == 1) {
- remove(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_N);
+ remove(x, z, FLAG_BLOCK_ENTITY_E | FLAG_BLOCK_ENTITY_N);
remove(x, z + 1, FLAG_BLOCK_ENTITY_S);
remove(x + 1, z, FLAG_BLOCK_ENTITY_W);
} else if (rotation == 2) {
- remove(x, z, FLAG_BLOCK_ENTITY_E|FLAG_BLOCK_ENTITY_S);
+ remove(x, z, FLAG_BLOCK_ENTITY_E | FLAG_BLOCK_ENTITY_S);
remove(x + 1, z, FLAG_BLOCK_ENTITY_W);
remove(x, z - 1, FLAG_BLOCK_ENTITY_N);
} else if (rotation == 3) {
- remove(x, z, FLAG_BLOCK_ENTITY_W|FLAG_BLOCK_ENTITY_S);
+ remove(x, z, FLAG_BLOCK_ENTITY_W | FLAG_BLOCK_ENTITY_S);
remove(x, z - 1, FLAG_BLOCK_ENTITY_N);
remove(x - 1, z, FLAG_BLOCK_ENTITY_E);
}
@@ -259,19 +259,19 @@ public class CollisionMap {
}
} else if (type == 2) {
if (rotation == 0) {
- remove(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_N);
+ remove(x, z, FLAG_BLOCK_PROJECTILE_W | FLAG_BLOCK_PROJECTILE_N);
remove(x - 1, z, FLAG_BLOCK_PROJECTILE_E);
remove(x, z + 1, FLAG_BLOCK_PROJECTILE_S);
} else if (rotation == 1) {
- remove(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_N);
+ remove(x, z, FLAG_BLOCK_PROJECTILE_E | FLAG_BLOCK_PROJECTILE_N);
remove(x, z + 1, FLAG_BLOCK_PROJECTILE_S);
remove(x + 1, z, FLAG_BLOCK_PROJECTILE_W);
} else if (rotation == 2) {
- remove(x, z, FLAG_BLOCK_PROJECTILE_E|FLAG_BLOCK_PROJECTILE_S);
+ remove(x, z, FLAG_BLOCK_PROJECTILE_E | FLAG_BLOCK_PROJECTILE_S);
remove(x + 1, z, FLAG_BLOCK_PROJECTILE_W);
remove(x, z - 1, FLAG_BLOCK_PROJECTILE_N);
} else if (rotation == 3) {
- remove(x, z, FLAG_BLOCK_PROJECTILE_W|FLAG_BLOCK_PROJECTILE_S);
+ remove(x, z, FLAG_BLOCK_PROJECTILE_W | FLAG_BLOCK_PROJECTILE_S);
remove(x, z - 1, FLAG_BLOCK_PROJECTILE_N);
remove(x - 1, z, FLAG_BLOCK_PROJECTILE_E);
}
diff --git a/src/main/java/Connection.java b/src/main/java/Connection.java
index 5667965..eee7f20 100644
--- a/src/main/java/Connection.java
+++ b/src/main/java/Connection.java
@@ -9,155 +9,155 @@ import java.net.Socket;
public class Connection implements Runnable {
- public final Socket socket;
- public final GameShell shell;
- public InputStream in;
- public OutputStream out;
- public boolean closed = false;
- public byte[] buf;
- public int tcycl;
- public int tnum;
- public boolean writer = false;
- public boolean ioerror = false;
+ public final Socket socket;
+ public final GameShell shell;
+ public InputStream in;
+ public OutputStream out;
+ public boolean closed = false;
+ public byte[] buf;
+ public int tcycl;
+ public int tnum;
+ public boolean writer = false;
+ public boolean ioerror = false;
- public Connection(GameShell shell, Socket socket) throws IOException {
- this.shell = shell;
- this.socket = socket;
- this.socket.setSoTimeout(30000);
- this.socket.setTcpNoDelay(true);
- in = this.socket.getInputStream();
- out = this.socket.getOutputStream();
- }
+ public Connection(GameShell shell, Socket socket) throws IOException {
+ this.shell = shell;
+ this.socket = socket;
+ this.socket.setSoTimeout(30000);
+ this.socket.setTcpNoDelay(true);
+ in = this.socket.getInputStream();
+ out = this.socket.getOutputStream();
+ }
- public void close() {
- closed = true;
- try {
- if (in != null) {
- in.close();
- }
- if (out != null) {
- out.close();
- }
- if (socket != null) {
- socket.close();
- }
- } catch (IOException _ex) {
- System.out.println("Error closing stream");
- }
- writer = false;
- synchronized (this) {
- notify();
- }
- buf = null;
- }
+ public void close() {
+ closed = true;
+ try {
+ if (in != null) {
+ in.close();
+ }
+ if (out != null) {
+ out.close();
+ }
+ if (socket != null) {
+ socket.close();
+ }
+ } catch (IOException _ex) {
+ System.out.println("Error closing stream");
+ }
+ writer = false;
+ synchronized (this) {
+ notify();
+ }
+ buf = null;
+ }
- public int read() throws IOException {
- if (closed) {
- return 0;
- } else {
- return in.read();
- }
- }
+ public int read() throws IOException {
+ if (closed) {
+ return 0;
+ } else {
+ return in.read();
+ }
+ }
- public int available() throws IOException {
- if (closed) {
- return 0;
- } else {
- return in.available();
- }
- }
+ public int available() throws IOException {
+ if (closed) {
+ return 0;
+ } else {
+ return in.available();
+ }
+ }
- public void read(byte[] dst, int off, int len) throws IOException {
- if (closed) {
- return;
- }
- int k;
- for (; len > 0; len -= k) {
- k = in.read(dst, off, len);
- if (k <= 0) {
- throw new IOException("EOF");
- }
- off += k;
- }
- }
+ public void read(byte[] dst, int off, int len) throws IOException {
+ if (closed) {
+ return;
+ }
+ int k;
+ for (; len > 0; len -= k) {
+ k = in.read(dst, off, len);
+ if (k <= 0) {
+ throw new IOException("EOF");
+ }
+ off += k;
+ }
+ }
- public void write(byte[] src, int off, int len) throws IOException {
- if (closed) {
- return;
- }
- if (ioerror) {
- ioerror = false;
- throw new IOException("Error in writer thread");
- }
- if (buf == null) {
- buf = new byte[5000];
- }
- synchronized (this) {
- for (int i = 0; i < len; i++) {
- buf[tnum] = src[i + off];
- tnum = (tnum + 1) % 5000;
- if (tnum == ((tcycl + 4900) % 5000)) {
- throw new IOException("buffer overflow");
- }
- }
- if (!writer) {
- writer = true;
- shell.startThread(this, 3);
- }
- notify();
- }
- }
+ public void write(byte[] src, int off, int len) throws IOException {
+ if (closed) {
+ return;
+ }
+ if (ioerror) {
+ ioerror = false;
+ throw new IOException("Error in writer thread");
+ }
+ if (buf == null) {
+ buf = new byte[5000];
+ }
+ synchronized (this) {
+ for (int i = 0; i < len; i++) {
+ buf[tnum] = src[i + off];
+ tnum = (tnum + 1) % 5000;
+ if (tnum == ((tcycl + 4900) % 5000)) {
+ throw new IOException("buffer overflow");
+ }
+ }
+ if (!writer) {
+ writer = true;
+ shell.startThread(this, 3);
+ }
+ notify();
+ }
+ }
- @Override
- public void run() {
- while (writer) {
- int i;
- int j;
- synchronized (this) {
- if (tnum == tcycl) {
- try {
- wait();
- } catch (InterruptedException ignored) {
- }
- }
- if (!writer) {
- return;
- }
- j = tcycl;
- if (tnum >= tcycl) {
- i = tnum - tcycl;
- } else {
- i = 5000 - tcycl;
- }
- }
- if (i > 0) {
- try {
- out.write(buf, j, i);
- } catch (IOException _ex) {
- ioerror = true;
- }
- tcycl = (tcycl + i) % 5000;
- try {
- if (tnum == tcycl) {
- out.flush();
- }
- } catch (IOException _ex) {
- ioerror = true;
- }
- }
- }
- }
+ @Override
+ public void run() {
+ while (writer) {
+ int i;
+ int j;
+ synchronized (this) {
+ if (tnum == tcycl) {
+ try {
+ wait();
+ } catch (InterruptedException ignored) {
+ }
+ }
+ if (!writer) {
+ return;
+ }
+ j = tcycl;
+ if (tnum >= tcycl) {
+ i = tnum - tcycl;
+ } else {
+ i = 5000 - tcycl;
+ }
+ }
+ if (i > 0) {
+ try {
+ out.write(buf, j, i);
+ } catch (IOException _ex) {
+ ioerror = true;
+ }
+ tcycl = (tcycl + i) % 5000;
+ try {
+ if (tnum == tcycl) {
+ out.flush();
+ }
+ } catch (IOException _ex) {
+ ioerror = true;
+ }
+ }
+ }
+ }
- public void debug() {
- System.out.println("closed:" + closed);
- System.out.println("tcycl:" + tcycl);
- System.out.println("tnum:" + tnum);
- System.out.println("writer:" + writer);
- System.out.println("ioerror:" + ioerror);
- try {
- System.out.println("available:" + available());
- } catch (IOException ignored) {
- }
- }
+ public void debug() {
+ System.out.println("closed:" + closed);
+ System.out.println("tcycl:" + tcycl);
+ System.out.println("tnum:" + tnum);
+ System.out.println("writer:" + writer);
+ System.out.println("ioerror:" + ioerror);
+ try {
+ System.out.println("available:" + available());
+ } catch (IOException ignored) {
+ }
+ }
}
diff --git a/src/main/java/DoublyLinkedList.java b/src/main/java/DoublyLinkedList.java
index 6df4e96..6f7556e 100644
--- a/src/main/java/DoublyLinkedList.java
+++ b/src/main/java/DoublyLinkedList.java
@@ -1,114 +1,114 @@
public class DoublyLinkedList {
- public static class Node {
+ public static class Node {
- public Node prev;
- public Node next;
+ public Node prev;
+ public Node next;
- public void unlink() {
- if (next != null) {
- next.prev = prev;
- prev.next = next;
- prev = null;
- next = null;
- }
- }
+ public void unlink() {
+ if (next != null) {
+ next.prev = prev;
+ prev.next = next;
+ prev = null;
+ next = null;
+ }
+ }
- }
+ }
- public final Node head;
- public Node peeked;
+ public final Node head;
+ public Node peeked;
- public DoublyLinkedList() {
- head = new Node();
- head.prev = head;
- head.next = head;
- }
+ public DoublyLinkedList() {
+ head = new Node();
+ head.prev = head;
+ head.next = head;
+ }
- public void pushBack(Node node) {
- if (node.next != null) {
- node.unlink();
- }
- node.next = head.next;
- node.prev = head;
- node.next.prev = node;
- node.prev.next = node;
- }
+ public void pushBack(Node node) {
+ if (node.next != null) {
+ node.unlink();
+ }
+ node.next = head.next;
+ node.prev = head;
+ node.next.prev = node;
+ node.prev.next = node;
+ }
- public void pushFront(Node node) {
- if (node.next != null) {
- node.unlink();
- }
- node.next = head;
- node.prev = head.prev;
- node.next.prev = node;
- node.prev.next = node;
- }
+ public void pushFront(Node node) {
+ if (node.next != null) {
+ node.unlink();
+ }
+ node.next = head;
+ node.prev = head.prev;
+ node.next.prev = node;
+ node.prev.next = node;
+ }
- public Node pollFront() {
- Node node = head.prev;
- if (node == head) {
- return null;
- } else {
- node.unlink();
- return node;
- }
- }
+ public Node pollFront() {
+ Node node = head.prev;
+ if (node == head) {
+ return null;
+ } else {
+ node.unlink();
+ return node;
+ }
+ }
- public Node peekFront() {
- Node node = head.prev;
- if (node == head) {
- peeked = null;
- return null;
- } else {
- peeked = node.prev;
- return node;
- }
- }
+ public Node peekFront() {
+ Node node = head.prev;
+ if (node == head) {
+ peeked = null;
+ return null;
+ } else {
+ peeked = node.prev;
+ return node;
+ }
+ }
- public Node peekBack() {
- Node node = head.next;
- if (node == head) {
- peeked = null;
- return null;
- } else {
- peeked = node.next;
- return node;
- }
- }
+ public Node peekBack() {
+ Node node = head.next;
+ if (node == head) {
+ peeked = null;
+ return null;
+ } else {
+ peeked = node.next;
+ return node;
+ }
+ }
- public Node prev() {
- Node node = peeked;
- if (node == head) {
- peeked = null;
- return null;
- } else {
- peeked = node.prev;
- return node;
- }
- }
+ public Node prev() {
+ Node node = peeked;
+ if (node == head) {
+ peeked = null;
+ return null;
+ } else {
+ peeked = node.prev;
+ return node;
+ }
+ }
- public Node next() {
- Node node = peeked;
- if (node == head) {
- peeked = null;
- return null;
- }
- peeked = node.next;
- return node;
- }
+ public Node next() {
+ Node node = peeked;
+ if (node == head) {
+ peeked = null;
+ return null;
+ }
+ peeked = node.next;
+ return node;
+ }
- public void clear() {
- if (head.prev == head) {
- return;
- }
- do {
- Node node = head.prev;
- if (node == head) {
- return;
- }
- node.unlink();
- } while (true);
- }
+ public void clear() {
+ if (head.prev == head) {
+ return;
+ }
+ do {
+ Node node = head.prev;
+ if (node == head) {
+ return;
+ }
+ node.unlink();
+ } while (true);
+ }
}
diff --git a/src/main/java/Draw2D.java b/src/main/java/Draw2D.java
index 5a1e23f..cd0e60b 100644
--- a/src/main/java/Draw2D.java
+++ b/src/main/java/Draw2D.java
@@ -2,286 +2,287 @@ import java.util.Arrays;
public class Draw2D {
- public static int[] pixels;
- public static int width;
- public static int height;
- public static int top;
- public static int bottom;
- public static int left;
- public static int right;
- public static int boundX;
- public static int centerX;
- public static int centerY;
+ public static int[] pixels;
+ public static int width;
+ public static int height;
+ public static int top;
+ public static int bottom;
+ public static int left;
+ public static int right;
+ public static int boundX;
+ public static int centerX;
+ public static int centerY;
- public static void bind(int[] pixels, int width, int height) {
- Draw2D.pixels = pixels;
- Draw2D.width = width;
- Draw2D.height = height;
- setBounds(0, 0, width, height);
- }
+ public static void bind(int[] pixels, int width, int height) {
+ Draw2D.pixels = pixels;
+ Draw2D.width = width;
+ Draw2D.height = height;
+ setBounds(0, 0, width, height);
+ }
- public static void resetBounds() {
- left = 0;
- top = 0;
- right = width;
- bottom = height;
- boundX = right - 1;
- centerX = right / 2;
- }
+ public static void resetBounds() {
+ left = 0;
+ top = 0;
+ right = width;
+ bottom = height;
+ boundX = right - 1;
+ centerX = right / 2;
+ }
- public static void setBounds(int left, int top, int right, int bottom) {
- if (left < 0) {
- left = 0;
- }
- if (top < 0) {
- top = 0;
- }
- if (right > width) {
- right = width;
- }
- if (bottom > height) {
- bottom = height;
- }
- Draw2D.left = left;
- Draw2D.top = top;
- Draw2D.right = right;
- Draw2D.bottom = bottom;
- boundX = Draw2D.right - 1;
- centerX = Draw2D.right / 2;
- centerY = Draw2D.bottom / 2;
- }
+ public static void setBounds(int left, int top, int right, int bottom) {
+ if (left < 0) {
+ left = 0;
+ }
+ if (top < 0) {
+ top = 0;
+ }
+ if (right > width) {
+ right = width;
+ }
+ if (bottom > height) {
+ bottom = height;
+ }
+ Draw2D.left = left;
+ Draw2D.top = top;
+ Draw2D.right = right;
+ Draw2D.bottom = bottom;
+ boundX = Draw2D.right - 1;
+ centerX = Draw2D.right / 2;
+ centerY = Draw2D.bottom / 2;
+ }
- public static void clear() {
- Arrays.fill(pixels, 0);
- }
+ public static void clear() {
+ Arrays.fill(pixels, 0);
+ }
- /**
- * Bresenham's line algorithm.
- * @param x1 the first x coordinate.
- * @param y1 the first y coordinate.
- * @param x2 the second x coordinate.
- * @param y2 the second y coordinate.
- * @param rgb the color.
- */
- public static void drawLine(int x1, int y1, int x2, int y2, int rgb) {
- int dx = Math.abs(x2 - x1);
- int dy = Math.abs(y2 - y1);
+ /**
+ * Bresenham's line algorithm.
+ *
+ * @param x1 the first x coordinate.
+ * @param y1 the first y coordinate.
+ * @param x2 the second x coordinate.
+ * @param y2 the second y coordinate.
+ * @param rgb the color.
+ */
+ public static void drawLine(int x1, int y1, int x2, int y2, int rgb) {
+ int dx = Math.abs(x2 - x1);
+ int dy = Math.abs(y2 - y1);
- int sx = (x1 < x2) ? 1 : -1;
- int sy = (y1 < y2) ? 1 : -1;
+ int sx = (x1 < x2) ? 1 : -1;
+ int sy = (y1 < y2) ? 1 : -1;
- int err = dx - dy;
+ int err = dx - dy;
- while (true) {
- if ((x1 >= left) && (x1 < right) && (y1 >= top) && (y1 < bottom)) {
- pixels[x1 + (y1 * width)] = rgb;
- }
+ while (true) {
+ if ((x1 >= left) && (x1 < right) && (y1 >= top) && (y1 < bottom)) {
+ pixels[x1 + (y1 * width)] = rgb;
+ }
- if ((x1 == x2) && (y1 == y2)) {
- break;
- }
+ if ((x1 == x2) && (y1 == y2)) {
+ break;
+ }
- int e2 = 2 * err;
+ int e2 = 2 * err;
- if (e2 > -dy) {
- err = err - dy;
- x1 = x1 + sx;
- }
+ if (e2 > -dy) {
+ err = err - dy;
+ x1 = x1 + sx;
+ }
- if (e2 < dx) {
- err = err + dx;
- y1 = y1 + sy;
- }
- }
+ if (e2 < dx) {
+ err = err + dx;
+ y1 = y1 + sy;
+ }
+ }
- }
+ }
- public static void fillRect(int x, int y, int width, int height, int rgb, int alpha) {
- if (x < left) {
- width -= left - x;
- x = left;
- }
+ public static void fillRect(int x, int y, int width, int height, int rgb, int alpha) {
+ if (x < left) {
+ width -= left - x;
+ x = left;
+ }
- if (y < top) {
- height -= top - y;
- y = top;
- }
+ if (y < top) {
+ height -= top - y;
+ y = top;
+ }
- if ((x + width) > right) {
- width = right - x;
- }
+ if ((x + width) > right) {
+ width = right - x;
+ }
- if ((y + height) > bottom) {
- height = bottom - y;
- }
+ if ((y + height) > bottom) {
+ height = bottom - y;
+ }
- int invAlpha = 256 - alpha;
- int r0 = ((rgb >> 16) & 0xff) * alpha;
- int g0 = ((rgb >> 8) & 0xff) * alpha;
- int b0 = (rgb & 0xff) * alpha;
+ int invAlpha = 256 - alpha;
+ int r0 = ((rgb >> 16) & 0xff) * alpha;
+ int g0 = ((rgb >> 8) & 0xff) * alpha;
+ int b0 = (rgb & 0xff) * alpha;
- int step = Draw2D.width - width;
- int offset = x + (y * Draw2D.width);
+ int step = Draw2D.width - width;
+ int offset = x + (y * Draw2D.width);
- for (int i = 0; i < height; i++) {
- for (int j = -width; j < 0; j++) {
- int r1 = ((pixels[offset] >> 16) & 0xff) * invAlpha;
- int g1 = ((pixels[offset] >> 8) & 0xff) * invAlpha;
- int b1 = (pixels[offset] & 0xff) * invAlpha;
- pixels[offset++] = (((r0 + r1) >> 8) << 16) + (((g0 + g1) >> 8) << 8) + ((b0 + b1) >> 8);
- }
- offset += step;
- }
- }
+ for (int i = 0; i < height; i++) {
+ for (int j = -width; j < 0; j++) {
+ int r1 = ((pixels[offset] >> 16) & 0xff) * invAlpha;
+ int g1 = ((pixels[offset] >> 8) & 0xff) * invAlpha;
+ int b1 = (pixels[offset] & 0xff) * invAlpha;
+ pixels[offset++] = (((r0 + r1) >> 8) << 16) + (((g0 + g1) >> 8) << 8) + ((b0 + b1) >> 8);
+ }
+ offset += step;
+ }
+ }
- public static void fillRect(int x, int y, int width, int height, int rgb) {
- if (x < left) {
- width -= left - x;
- x = left;
- }
+ public static void fillRect(int x, int y, int width, int height, int rgb) {
+ if (x < left) {
+ width -= left - x;
+ x = left;
+ }
- if (y < top) {
- height -= top - y;
- y = top;
- }
+ if (y < top) {
+ height -= top - y;
+ y = top;
+ }
- if ((x + width) > right) {
- width = right - x;
- }
+ if ((x + width) > right) {
+ width = right - x;
+ }
- if ((y + height) > bottom) {
- height = bottom - y;
- }
+ if ((y + height) > bottom) {
+ height = bottom - y;
+ }
- int step = Draw2D.width - width;
- int offset = x + (y * Draw2D.width);
+ int step = Draw2D.width - width;
+ int offset = x + (y * Draw2D.width);
- for (int i = -height; i < 0; i++) {
- for (int j = -width; j < 0; j++) {
- pixels[offset++] = rgb;
- }
- offset += step;
- }
- }
+ for (int i = -height; i < 0; i++) {
+ for (int j = -width; j < 0; j++) {
+ pixels[offset++] = rgb;
+ }
+ offset += step;
+ }
+ }
- public static void drawRect(int x, int y, int width, int height, int rgb) {
- drawLineX(x, y, width, rgb);
- drawLineX(x, (y + height) - 1, width, rgb);
- drawLineY(x, y, height, rgb);
- drawLineY((x + width) - 1, y, height, rgb);
- }
+ public static void drawRect(int x, int y, int width, int height, int rgb) {
+ drawLineX(x, y, width, rgb);
+ drawLineX(x, (y + height) - 1, width, rgb);
+ drawLineY(x, y, height, rgb);
+ drawLineY((x + width) - 1, y, height, rgb);
+ }
- public static void drawRect(int x, int y, int width, int height, int rgb, int alpha) {
- drawLineX(x, y, width, rgb, alpha);
- drawLineX(x, (y + height) - 1, width, rgb, alpha);
- if (height >= 3) {
- drawLineY(rgb, x, alpha, y + 1, height - 2);
- drawLineY(rgb, (x + width) - 1, alpha, y + 1, height - 2);
- }
- }
+ public static void drawRect(int x, int y, int width, int height, int rgb, int alpha) {
+ drawLineX(x, y, width, rgb, alpha);
+ drawLineX(x, (y + height) - 1, width, rgb, alpha);
+ if (height >= 3) {
+ drawLineY(rgb, x, alpha, y + 1, height - 2);
+ drawLineY(rgb, (x + width) - 1, alpha, y + 1, height - 2);
+ }
+ }
- public static void drawLineX(int x, int y, int length, int rgb) {
- if ((y < top) || (y >= bottom)) {
- return;
- }
+ public static void drawLineX(int x, int y, int length, int rgb) {
+ if ((y < top) || (y >= bottom)) {
+ return;
+ }
- if (x < left) {
- length -= left - x;
- x = left;
- }
+ if (x < left) {
+ length -= left - x;
+ x = left;
+ }
- if ((x + length) > right) {
- length = right - x;
- }
+ if ((x + length) > right) {
+ length = right - x;
+ }
- int offset = x + (y * width);
+ int offset = x + (y * width);
- for (int i = 0; i < length; i++) {
- pixels[offset + i] = rgb;
- }
- }
+ for (int i = 0; i < length; i++) {
+ pixels[offset + i] = rgb;
+ }
+ }
- public static void drawLineX(int x, int y, int length, int rgb, int alpha) {
- if ((y < top) || (y >= bottom)) {
- return;
- }
+ public static void drawLineX(int x, int y, int length, int rgb, int alpha) {
+ if ((y < top) || (y >= bottom)) {
+ return;
+ }
- if (x < left) {
- length -= left - x;
- x = left;
- }
+ if (x < left) {
+ length -= left - x;
+ x = left;
+ }
- if ((x + length) > right) {
- length = right - x;
- }
+ if ((x + length) > right) {
+ length = right - x;
+ }
- int invAlpha = 256 - alpha;
- int r0 = ((rgb >> 16) & 0xff) * alpha;
- int g0 = ((rgb >> 8) & 0xff) * alpha;
- int b0 = (rgb & 0xff) * alpha;
+ int invAlpha = 256 - alpha;
+ int r0 = ((rgb >> 16) & 0xff) * alpha;
+ int g0 = ((rgb >> 8) & 0xff) * alpha;
+ int b0 = (rgb & 0xff) * alpha;
- int offset = x + (y * width);
+ int offset = x + (y * width);
- for (int i = 0; i < length; i++) {
- int r1 = ((pixels[offset] >> 16) & 0xff) * invAlpha;
- int g1 = ((pixels[offset] >> 8) & 0xff) * invAlpha;
- int b1 = (pixels[offset] & 0xff) * invAlpha;
- pixels[offset++] = (((r0 + r1) >> 8) << 16) + (((g0 + g1) >> 8) << 8) + ((b0 + b1) >> 8);
- }
- }
+ for (int i = 0; i < length; i++) {
+ int r1 = ((pixels[offset] >> 16) & 0xff) * invAlpha;
+ int g1 = ((pixels[offset] >> 8) & 0xff) * invAlpha;
+ int b1 = (pixels[offset] & 0xff) * invAlpha;
+ pixels[offset++] = (((r0 + r1) >> 8) << 16) + (((g0 + g1) >> 8) << 8) + ((b0 + b1) >> 8);
+ }
+ }
- public static void drawLineY(int x, int y, int length, int rgb) {
- if ((x < left) || (x >= right)) {
- return;
- }
+ public static void drawLineY(int x, int y, int length, int rgb) {
+ if ((x < left) || (x >= right)) {
+ return;
+ }
- if (y < top) {
- length -= top - y;
- y = top;
- }
+ if (y < top) {
+ length -= top - y;
+ y = top;
+ }
- if ((y + length) > bottom) {
- length = bottom - y;
- }
+ if ((y + length) > bottom) {
+ length = bottom - y;
+ }
- int offset = x + (y * width);
+ int offset = x + (y * width);
- for (int i = 0; i < length; i++) {
- pixels[offset + (i * width)] = rgb;
- }
- }
+ for (int i = 0; i < length; i++) {
+ pixels[offset + (i * width)] = rgb;
+ }
+ }
- public static void drawLineY(int rgb, int x, int alpha, int y, int length) {
- if ((x < left) || (x >= right)) {
- return;
- }
+ public static void drawLineY(int rgb, int x, int alpha, int y, int length) {
+ if ((x < left) || (x >= right)) {
+ return;
+ }
- if (y < top) {
- length -= top - y;
- y = top;
- }
+ if (y < top) {
+ length -= top - y;
+ y = top;
+ }
- if ((y + length) > bottom) {
- length = bottom - y;
- }
+ if ((y + length) > bottom) {
+ length = bottom - y;
+ }
- int invAlpha = 256 - alpha;
- int r0 = ((rgb >> 16) & 0xff) * alpha;
- int g0 = ((rgb >> 8) & 0xff) * alpha;
- int b0 = (rgb & 0xff) * alpha;
+ int invAlpha = 256 - alpha;
+ int r0 = ((rgb >> 16) & 0xff) * alpha;
+ int g0 = ((rgb >> 8) & 0xff) * alpha;
+ int b0 = (rgb & 0xff) * alpha;
- int offset = x + (y * width);
+ int offset = x + (y * width);
- for (int i = 0; i < length; i++) {
- int r1 = ((pixels[offset] >> 16) & 0xff) * invAlpha;
- int g1 = ((pixels[offset] >> 8) & 0xff) * invAlpha;
- int b1 = (pixels[offset] & 0xff) * invAlpha;
- pixels[offset] = (((r0 + r1) >> 8) << 16) + (((g0 + g1) >> 8) << 8) + ((b0 + b1) >> 8);
- offset += width;
- }
- }
+ for (int i = 0; i < length; i++) {
+ int r1 = ((pixels[offset] >> 16) & 0xff) * invAlpha;
+ int g1 = ((pixels[offset] >> 8) & 0xff) * invAlpha;
+ int b1 = (pixels[offset] & 0xff) * invAlpha;
+ pixels[offset] = (((r0 + r1) >> 8) << 16) + (((g0 + g1) >> 8) << 8) + ((b0 + b1) >> 8);
+ offset += width;
+ }
+ }
- public Draw2D() {
- }
+ public Draw2D() {
+ }
}
diff --git a/src/main/java/Draw3D.java b/src/main/java/Draw3D.java
index 65177ed..b1b37b9 100644
--- a/src/main/java/Draw3D.java
+++ b/src/main/java/Draw3D.java
@@ -405,7 +405,7 @@ public class Draw3D {
/**
* Returns the rgb with each component raised to the power of gamma
*
- * @param rgb the input rgb.
+ * @param rgb the input rgb.
* @param gamma the gamma.
* @return the result.
*/
diff --git a/src/main/java/DrawArea.java b/src/main/java/DrawArea.java
index 8e9cb6d..65a2780 100644
--- a/src/main/java/DrawArea.java
+++ b/src/main/java/DrawArea.java
@@ -8,30 +8,30 @@ import java.awt.image.DataBufferInt;
public class DrawArea {
- public final int[] pixels;
- public final int width;
- public final int height;
- public final BufferedImage image;
+ public final int[] pixels;
+ public final int width;
+ public final int height;
+ public final BufferedImage image;
- public DrawArea(int width, int height) {
- this.width = width;
- this.height = height;
- this.image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB);
- this.pixels = ((DataBufferInt) this.image.getRaster().getDataBuffer()).getData();
- bind();
- }
+ public DrawArea(int width, int height) {
+ this.width = width;
+ this.height = height;
+ this.image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB);
+ this.pixels = ((DataBufferInt) this.image.getRaster().getDataBuffer()).getData();
+ bind();
+ }
- public DrawArea(Image24 image) {
- this(image.width, image.height);
- image.blitOpaque(0, 0);
- }
+ public DrawArea(Image24 image) {
+ this(image.width, image.height);
+ image.blitOpaque(0, 0);
+ }
- public void bind() {
- Draw2D.bind(pixels, width, height);
- }
+ public void bind() {
+ Draw2D.bind(pixels, width, height);
+ }
- public void draw(Graphics g, int x, int y) {
- g.drawImage(image, x, y, null);
- }
+ public void draw(Graphics g, int x, int y) {
+ g.drawImage(image, x, y, null);
+ }
}
diff --git a/src/main/java/Entity.java b/src/main/java/Entity.java
index 6fef21d..bce36ff 100644
--- a/src/main/java/Entity.java
+++ b/src/main/java/Entity.java
@@ -1,22 +1,22 @@
public class Entity extends DoublyLinkedList.Node {
- public VertexNormal[] vertexNormal;
- public int minY = 1000;
+ public VertexNormal[] vertexNormal;
+ public int minY = 1000;
- public Entity() {
- }
+ public Entity() {
+ }
- public void draw(int yaw, int sinEyePitch, int cosEyePitch, int sinEyeYaw, int cosEyeYaw, int relativeX, int relativeY, int relativeZ, int bitset) {
- Model model = getModel();
+ public void draw(int yaw, int sinEyePitch, int cosEyePitch, int sinEyeYaw, int cosEyeYaw, int relativeX, int relativeY, int relativeZ, int bitset) {
+ Model model = getModel();
- if (model != null) {
- minY = model.minY;
- model.draw(yaw, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, relativeX, relativeY, relativeZ, bitset);
- }
- }
+ if (model != null) {
+ minY = model.minY;
+ model.draw(yaw, sinEyePitch, cosEyePitch, sinEyeYaw, cosEyeYaw, relativeX, relativeY, relativeZ, bitset);
+ }
+ }
- public Model getModel() {
- return null;
- }
+ public Model getModel() {
+ return null;
+ }
}
diff --git a/src/main/java/FileArchive.java b/src/main/java/FileArchive.java
index 11d0cd2..3ebb584 100644
--- a/src/main/java/FileArchive.java
+++ b/src/main/java/FileArchive.java
@@ -9,83 +9,83 @@ import java.nio.file.Path;
*/
public class FileArchive {
- public byte[] data;
- public int fileCount;
- public int[] fileHash;
- public int[] fileSizeInflated;
- public int[] fileSizeDeflated;
- public int[] fileOffset;
- public boolean unpacked;
+ public byte[] data;
+ public int fileCount;
+ public int[] fileHash;
+ public int[] fileSizeInflated;
+ public int[] fileSizeDeflated;
+ public int[] fileOffset;
+ public boolean unpacked;
- public FileArchive(byte[] src) throws IOException {
- load(src);
- }
+ public FileArchive(byte[] src) throws IOException {
+ load(src);
+ }
- public void load(byte[] src) throws IOException {
- Buffer buffer = new Buffer(src);
+ public void load(byte[] src) throws IOException {
+ Buffer buffer = new Buffer(src);
- int unpackedSize = buffer.read24();
- int packedSize = buffer.read24();
+ int unpackedSize = buffer.read24();
+ int packedSize = buffer.read24();
- if (packedSize != unpackedSize) {
- data = new byte[unpackedSize];
- BZip2.decompress(src, 6, packedSize, data);
- buffer = new Buffer(data);
- unpacked = true;
- } else {
- data = src;
- unpacked = false;
- }
+ if (packedSize != unpackedSize) {
+ data = new byte[unpackedSize];
+ BZip2.decompress(src, 6, packedSize, data);
+ buffer = new Buffer(data);
+ unpacked = true;
+ } else {
+ data = src;
+ unpacked = false;
+ }
- fileCount = buffer.read16U();
- fileHash = new int[fileCount];
- fileSizeInflated = new int[fileCount];
- fileSizeDeflated = new int[fileCount];
- fileOffset = new int[fileCount];
+ fileCount = buffer.read16U();
+ fileHash = new int[fileCount];
+ fileSizeInflated = new int[fileCount];
+ fileSizeDeflated = new int[fileCount];
+ fileOffset = new int[fileCount];
- int offset = buffer.position + (fileCount * 10);
+ int offset = buffer.position + (fileCount * 10);
- for (int file = 0; file < fileCount; file++) {
- fileHash[file] = buffer.read32();
- fileSizeInflated[file] = buffer.read24();
- fileSizeDeflated[file] = buffer.read24();
- fileOffset[file] = offset;
- offset += fileSizeDeflated[file];
- }
- }
+ for (int file = 0; file < fileCount; file++) {
+ fileHash[file] = buffer.read32();
+ fileSizeInflated[file] = buffer.read24();
+ fileSizeDeflated[file] = buffer.read24();
+ fileOffset[file] = offset;
+ offset += fileSizeDeflated[file];
+ }
+ }
- public void export(String s, Path dst) throws IOException {
- byte[] data = read(s);
- if (data == null) {
- throw new FileNotFoundException(s);
- }
- try (OutputStream out = Files.newOutputStream(dst)) {
- out.write(data);
- }
- }
+ public void export(String s, Path dst) throws IOException {
+ byte[] data = read(s);
+ if (data == null) {
+ throw new FileNotFoundException(s);
+ }
+ try (OutputStream out = Files.newOutputStream(dst)) {
+ out.write(data);
+ }
+ }
- public byte[] read(String s) throws IOException {
- int hash = 0;
- s = s.toUpperCase();
- for (int j = 0; j < s.length(); j++) {
- hash = ((hash * 61) + s.charAt(j)) - 32;
- }
+ public byte[] read(String s) throws IOException {
+ int hash = 0;
+ s = s.toUpperCase();
+ for (int j = 0; j < s.length(); j++) {
+ hash = ((hash * 61) + s.charAt(j)) - 32;
+ }
- for (int file = 0; file < fileCount; file++) {
- if (fileHash[file] != hash) {
- continue;
- }
+ for (int file = 0; file < fileCount; file++) {
+ if (fileHash[file] != hash) {
+ continue;
+ }
- byte[] dst = new byte[fileSizeInflated[file]];
+ byte[] dst = new byte[fileSizeInflated[file]];
- if (!unpacked) {
- BZip2.decompress(data, fileOffset[file], fileSizeDeflated[file], dst);
- } else {
- System.arraycopy(data, fileOffset[file], dst, 0, fileSizeInflated[file]);
- }
- return dst;
- }
- return null;
- }
+ if (!unpacked) {
+ BZip2.decompress(data, fileOffset[file], fileSizeDeflated[file], dst);
+ } else {
+ System.arraycopy(data, fileOffset[file], dst, 0, fileSizeInflated[file]);
+ }
+ return dst;
+ }
+ return null;
+ }
}
diff --git a/src/main/java/FileStore.java b/src/main/java/FileStore.java
index 8b252cf..597eca8 100644
--- a/src/main/java/FileStore.java
+++ b/src/main/java/FileStore.java
@@ -7,186 +7,186 @@ import java.io.RandomAccessFile;
public class FileStore {
- public static final byte[] buf = new byte[520];
- public final RandomAccessFile dat;
- public final RandomAccessFile idx;
- public final int store;
- public int maxFileSize;
+ public static final byte[] buf = new byte[520];
+ public final RandomAccessFile dat;
+ public final RandomAccessFile idx;
+ public final int store;
+ public int maxFileSize;
- public FileStore(int maxFileSize, RandomAccessFile dat, RandomAccessFile idx, int store) {
- this.maxFileSize = 65000;
- this.store = store;
- this.dat = dat;
- this.idx = idx;
- this.maxFileSize = maxFileSize;
- }
+ public FileStore(int maxFileSize, RandomAccessFile dat, RandomAccessFile idx, int store) {
+ this.maxFileSize = 65000;
+ this.store = store;
+ this.dat = dat;
+ this.idx = idx;
+ this.maxFileSize = maxFileSize;
+ }
- public synchronized long getFileCount() throws IOException {
- return idx.length() / 6L;
- }
+ public synchronized long getFileCount() throws IOException {
+ return idx.length() / 6L;
+ }
- public synchronized byte[] read(int file) {
- try {
- idx.seek(file * 6L);
+ public synchronized byte[] read(int file) {
+ try {
+ idx.seek(file * 6L);
- idx.read(buf, 0, 6);
+ idx.read(buf, 0, 6);
- int size = ((buf[0] & 0xff) << 16) + ((buf[1] & 0xff) << 8) + (buf[2] & 0xff);
- int sector = ((buf[3] & 0xff) << 16) + ((buf[4] & 0xff) << 8) + (buf[5] & 0xff);
+ int size = ((buf[0] & 0xff) << 16) + ((buf[1] & 0xff) << 8) + (buf[2] & 0xff);
+ int sector = ((buf[3] & 0xff) << 16) + ((buf[4] & 0xff) << 8) + (buf[5] & 0xff);
- if (size > maxFileSize) {
- return null;
- }
+ if (size > maxFileSize) {
+ return null;
+ }
- if ((sector <= 0) || ((long) sector > (dat.length() / 520L))) {
- return null;
- }
+ if ((sector <= 0) || ((long) sector > (dat.length() / 520L))) {
+ return null;
+ }
- byte[] data = new byte[size];
- int position = 0;
+ byte[] data = new byte[size];
+ int position = 0;
- for (int part = 0; position < size; part++) {
- if (sector == 0) {
- return null;
- }
+ for (int part = 0; position < size; part++) {
+ if (sector == 0) {
+ return null;
+ }
- dat.seek(sector * 520L);
+ dat.seek(sector * 520L);
- int available = size - position;
+ int available = size - position;
- if (available > 512) {
- available = 512;
- }
+ if (available > 512) {
+ available = 512;
+ }
- dat.read(buf, 0, available + 8);
+ dat.read(buf, 0, available + 8);
- int sectorFile = ((buf[0] & 0xff) << 8) + (buf[1] & 0xff);
- int sectorPart = ((buf[2] & 0xff) << 8) + (buf[3] & 0xff);
- int nextSector = ((buf[4] & 0xff) << 16) + ((buf[5] & 0xff) << 8) + (buf[6] & 0xff);
- int sectorStore = buf[7] & 0xff;
+ int sectorFile = ((buf[0] & 0xff) << 8) + (buf[1] & 0xff);
+ int sectorPart = ((buf[2] & 0xff) << 8) + (buf[3] & 0xff);
+ int nextSector = ((buf[4] & 0xff) << 16) + ((buf[5] & 0xff) << 8) + (buf[6] & 0xff);
+ int sectorStore = buf[7] & 0xff;
- if ((sectorFile != file) || (sectorPart != part) || (sectorStore != store)) {
- return null;
- }
+ if ((sectorFile != file) || (sectorPart != part) || (sectorStore != store)) {
+ return null;
+ }
- if ((nextSector < 0) || ((long) nextSector > (dat.length() / 520L))) {
- return null;
- }
+ if ((nextSector < 0) || ((long) nextSector > (dat.length() / 520L))) {
+ return null;
+ }
- for (int i = 0; i < available; i++) {
- data[position++] = buf[i + 8];
- }
+ for (int i = 0; i < available; i++) {
+ data[position++] = buf[i + 8];
+ }
- sector = nextSector;
- }
- return data;
- } catch (IOException e) {
- return null;
- }
- }
+ sector = nextSector;
+ }
+ return data;
+ } catch (IOException e) {
+ return null;
+ }
+ }
- public synchronized void write(byte[] src, int file, int size) {
- boolean written = write(src, file, size, true);
- if (!written) {
- write(src, file, size, false);
- }
- }
+ public synchronized void write(byte[] src, int file, int size) {
+ boolean written = write(src, file, size, true);
+ if (!written) {
+ write(src, file, size, false);
+ }
+ }
- public synchronized boolean write(byte[] data, int file, int size, boolean overwrite) {
- try {
- int sector;
+ public synchronized boolean write(byte[] data, int file, int size, boolean overwrite) {
+ try {
+ int sector;
- if (overwrite) {
- idx.seek(file * 6L);
- idx.read(buf, 0, 6);
+ if (overwrite) {
+ idx.seek(file * 6L);
+ idx.read(buf, 0, 6);
- sector = ((buf[3] & 0xff) << 16) + ((buf[4] & 0xff) << 8) + (buf[5] & 0xff);
+ sector = ((buf[3] & 0xff) << 16) + ((buf[4] & 0xff) << 8) + (buf[5] & 0xff);
- if ((sector <= 0) || ((long) sector > (dat.length() / 520L))) {
- return false;
- }
- } else {
- sector = (int) ((dat.length() + 519L) / 520L);
+ if ((sector <= 0) || ((long) sector > (dat.length() / 520L))) {
+ return false;
+ }
+ } else {
+ sector = (int) ((dat.length() + 519L) / 520L);
- if (sector == 0) {
- sector = 1;
- }
- }
+ if (sector == 0) {
+ sector = 1;
+ }
+ }
- buf[0] = (byte) (size >> 16);
- buf[1] = (byte) (size >> 8);
- buf[2] = (byte) size;
- buf[3] = (byte) (sector >> 16);
- buf[4] = (byte) (sector >> 8);
- buf[5] = (byte) sector;
+ buf[0] = (byte) (size >> 16);
+ buf[1] = (byte) (size >> 8);
+ buf[2] = (byte) size;
+ buf[3] = (byte) (sector >> 16);
+ buf[4] = (byte) (sector >> 8);
+ buf[5] = (byte) sector;
- idx.seek(file * 6L);
- idx.write(buf, 0, 6);
+ idx.seek(file * 6L);
+ idx.write(buf, 0, 6);
- int written = 0;
- for (int part = 0; written < size; part++) {
- int nextSector = 0;
+ int written = 0;
+ for (int part = 0; written < size; part++) {
+ int nextSector = 0;
- if (overwrite) {
- dat.seek(sector * 520L);
+ if (overwrite) {
+ dat.seek(sector * 520L);
- if (dat.read(buf, 0, 8) == 8) {
- int sectorFile = ((buf[0] & 0xff) << 8) + (buf[1] & 0xff);
- int sectorPart = ((buf[2] & 0xff) << 8) + (buf[3] & 0xff);
- nextSector = ((buf[4] & 0xff) << 16) + ((buf[5] & 0xff) << 8) + (buf[6] & 0xff);
- int sectorStore = buf[7] & 0xff;
- if ((sectorFile != file) || (sectorPart != part) || (sectorStore != store)) {
- return false;
- }
- if ((nextSector < 0) || ((long) nextSector > (dat.length() / 520L))) {
- return false;
- }
- }
- }
+ if (dat.read(buf, 0, 8) == 8) {
+ int sectorFile = ((buf[0] & 0xff) << 8) + (buf[1] & 0xff);
+ int sectorPart = ((buf[2] & 0xff) << 8) + (buf[3] & 0xff);
+ nextSector = ((buf[4] & 0xff) << 16) + ((buf[5] & 0xff) << 8) + (buf[6] & 0xff);
+ int sectorStore = buf[7] & 0xff;
+ if ((sectorFile != file) || (sectorPart != part) || (sectorStore != store)) {
+ return false;
+ }
+ if ((nextSector < 0) || ((long) nextSector > (dat.length() / 520L))) {
+ return false;
+ }
+ }
+ }
- if (nextSector == 0) {
- overwrite = false;
- nextSector = (int) ((dat.length() + 519L) / 520L);
+ if (nextSector == 0) {
+ overwrite = false;
+ nextSector = (int) ((dat.length() + 519L) / 520L);
- if (nextSector == 0) {
- nextSector++;
- }
+ if (nextSector == 0) {
+ nextSector++;
+ }
- if (nextSector == sector) {
- nextSector++;
- }
- }
+ if (nextSector == sector) {
+ nextSector++;
+ }
+ }
- if ((size - written) <= 512) {
- nextSector = 0;
- }
+ if ((size - written) <= 512) {
+ nextSector = 0;
+ }
- buf[0] = (byte) (file >> 8);
- buf[1] = (byte) file;
- buf[2] = (byte) (part >> 8);
- buf[3] = (byte) part;
- buf[4] = (byte) (nextSector >> 16);
- buf[5] = (byte) (nextSector >> 8);
- buf[6] = (byte) nextSector;
- buf[7] = (byte) store;
+ buf[0] = (byte) (file >> 8);
+ buf[1] = (byte) file;
+ buf[2] = (byte) (part >> 8);
+ buf[3] = (byte) part;
+ buf[4] = (byte) (nextSector >> 16);
+ buf[5] = (byte) (nextSector >> 8);
+ buf[6] = (byte) nextSector;
+ buf[7] = (byte) store;
- dat.seek(sector * 520L);
- dat.write(buf, 0, 8);
+ dat.seek(sector * 520L);
+ dat.write(buf, 0, 8);
- int available = size - written;
+ int available = size - written;
- if (available > 512) {
- available = 512;
- }
+ if (available > 512) {
+ available = 512;
+ }
- dat.write(data, written, available);
- written += available;
- sector = nextSector;
- }
- return true;
- } catch (IOException e) {
- return false;
- }
- }
+ dat.write(data, written, available);
+ written += available;
+ sector = nextSector;
+ }
+ return true;
+ } catch (IOException e) {
+ return false;
+ }
+ }
}
diff --git a/src/main/java/GameFrame.java b/src/main/java/GameFrame.java
index dc368b0..85a1259 100644
--- a/src/main/java/GameFrame.java
+++ b/src/main/java/GameFrame.java
@@ -7,18 +7,18 @@ import java.awt.*;
public class GameFrame extends JFrame {
- public final GameShell shell;
+ public final GameShell shell;
- public GameFrame(GameShell shell) {
- this.shell = shell;
- setTitle("Jagex");
- setResizable(false);
- setLayout(new BorderLayout());
- add(shell, BorderLayout.CENTER);
- pack();
- setLocationRelativeTo(null);
- setVisible(true);
- transferFocus();
- }
+ public GameFrame(GameShell shell) {
+ this.shell = shell;
+ setTitle("Jagex");
+ setResizable(false);
+ setLayout(new BorderLayout());
+ add(shell, BorderLayout.CENTER);
+ pack();
+ setLocationRelativeTo(null);
+ setVisible(true);
+ transferFocus();
+ }
}
diff --git a/src/main/java/GameShell.java b/src/main/java/GameShell.java
index aae4b51..a7bd61b 100644
--- a/src/main/java/GameShell.java
+++ b/src/main/java/GameShell.java
@@ -9,507 +9,507 @@ import java.io.IOException;
public abstract class GameShell extends JComponent implements Runnable, MouseListener, MouseMotionListener, KeyListener, FocusListener, WindowListener {
- public final long[] otim = new long[10];
- public final double[] frameTime = new double[100];
- public final int[] actionKey = new int[128];
- public final int[] keyQueue = new int[128];
- public int state;
- public int deltime = 20;
- public int mindel = 1;
- public int fps;
- public boolean debug = false;
- public int screenWidth;
- public int screenHeight;
- public Graphics graphics;
- public GameFrame frame;
- public boolean refresh = true;
- public boolean focused = true;
- public int idleCycles;
- public int mouseButton;
- public int mouseX;
- public int mouseY;
- public int lastMouseClickButton;
- public int lastMouseClickX;
- public int lastMouseClickY;
- public long lastMouseClickTime;
- public int mouseClickButton;
- public int mouseClickX;
- public int mouseClickY;
- public long mouseClickTime;
- public int keyQueueReadPos;
- public int keyQueueWritePos;
-
- public void init(int width, int height) {
- screenWidth = width;
- screenHeight = height;
- setSize(width, height);
- setPreferredSize(getSize());
- frame = new GameFrame(this);
- graphics = this.getGraphics();
- startThread(this, 1);
- requestFocus();
- }
-
- public void initApplet(int width, int height) {
- screenWidth = width;
- screenHeight = height;
- graphics = this.getGraphics();
- startThread(this, 1);
- }
-
- @Override
- public void run() {
- try {
- this.addMouseListener(this);
- this.addMouseMotionListener(this);
- this.addKeyListener(this);
- this.addFocusListener(this);
-
- if (frame != null) {
- frame.addWindowListener(this);
- }
-
- drawProgress(0, "Loading...");
- load();
-
- int opos = 0;
- int fpos = 0;
- int ratio = 256;
- int delta = 1;
- int count = 0;
- int intex = 0; // interrupt exceptions
-
- for (int k1 = 0; k1 < 10; k1++) {
- otim[k1] = System.currentTimeMillis();
- }
-
- while (state >= 0) {
- if (state > 0) {
- state--;
- if (state == 0) {
- shutdown();
- return;
- }
- }
-
- int lastRatio = ratio;
- int lastDelta = delta;
-
- ratio = 300;
- delta = 1;
-
- long ntime = System.currentTimeMillis();
-
- if (otim[opos] == 0L) {
- ratio = lastRatio;
- delta = lastDelta;
- } else if (ntime > otim[opos]) {
- ratio = (int) ((2560L * deltime) / (ntime - otim[opos]));
- }
-
- if (ratio < 25) {
- ratio = 25;
- }
-
- if (ratio > 256) {
- ratio = 256;
- delta = (int) ((long) deltime - ((ntime - otim[opos]) / 10L));
- }
-
- if (delta > deltime) {
- delta = deltime;
- }
-
- otim[opos] = ntime;
- opos = (opos + 1) % 10;
-
- if (delta > 1) {
- for (int k2 = 0; k2 < 10; k2++) {
- if (otim[k2] != 0L) {
- otim[k2] += delta;
- }
- }
- }
-
- if (delta < mindel) {
- delta = mindel;
- }
-
- try {
- Thread.sleep(delta);
- } catch (InterruptedException e) {
- intex++;
- }
-
- long time = System.nanoTime();
-
- for (; count < 256; count += ratio) {
- mouseClickButton = lastMouseClickButton;
- mouseClickX = lastMouseClickX;
- mouseClickY = lastMouseClickY;
- mouseClickTime = lastMouseClickTime;
- lastMouseClickButton = 0;
- update();
- keyQueueReadPos = keyQueueWritePos;
- }
-
- count &= 0xff;
-
- if (deltime > 0) {
- fps = (1000 * ratio) / (deltime * 256);
- }
-
- draw();
-
- frameTime[fpos] = (double)(System.nanoTime() - time) / 1_000_000.0;
- fpos = (fpos + 1) % frameTime.length;
-
- if (debug) {
- System.out.println("ntime:" + ntime);
- for (int i = 0; i < 10; i++) {
- int o = ((opos - i - 1) + 20) % 10;
- System.out.println("otim" + o + ":" + otim[o]);
- }
- System.out.println("fps:" + fps + " ratio:" + ratio + " count:" + count);
- System.out.println("del:" + delta + " deltime:" + deltime + " mindel:" + mindel);
- System.out.println("intex:" + intex + " opos:" + opos);
- debug = false;
- intex = 0;
- }
- }
- } catch (Exception e) {
- state = -1;
- e.printStackTrace();
- }
-
- if (state == -1) {
- shutdown();
- }
- }
-
- public void shutdown() {
- state = -2;
- unload();
-
- if (frame != null) {
- try {
- Thread.sleep(1000L);
- } catch (Exception ignored) {
- }
- try {
- System.exit(0);
- } catch (Throwable ignored) {
- }
- }
- }
-
- public void setFramerate(int fps) {
- deltime = 1000 / fps;
- }
-
- public void destroy() {
- state = -1;
-
- try {
- Thread.sleep(5000L);
- } catch (Exception ignored) {
- }
-
- if (state == -1) {
- shutdown();
- }
- }
-
- @Override
- public void update(Graphics g) {
- if (graphics == null) {
- graphics = g;
- }
- refresh = true;
- refresh();
- }
-
- @Override
- public void paint(Graphics g) {
- if (graphics == null) {
- graphics = g;
- }
- refresh = true;
- refresh();
- }
-
- @Override
- public void mousePressed(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
-
- idleCycles = 0;
- lastMouseClickX = x;
- lastMouseClickY = y;
- lastMouseClickTime = System.currentTimeMillis();
-
- if (SwingUtilities.isRightMouseButton(e)) {
- lastMouseClickButton = 2;
- mouseButton = 2;
- } else {
- lastMouseClickButton = 1;
- mouseButton = 1;
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- idleCycles = 0;
- mouseButton = 0;
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- }
-
- @Override
- public void mouseEntered(MouseEvent e) {
- }
-
- @Override
- public void mouseExited(MouseEvent e) {
- idleCycles = 0;
- mouseX = -1;
- mouseY = -1;
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
- idleCycles = 0;
- mouseX = x;
- mouseY = y;
- }
-
- @Override
- public void mouseMoved(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
- idleCycles = 0;
- mouseX = x;
- mouseY = y;
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- idleCycles = 0;
- int code = e.getKeyCode();
- int value = e.getKeyChar();
-
- if (value < 30) {
- value = 0;
- }
-
- if (code == KeyEvent.VK_LEFT) {
- value = 1;
- } else if (code == KeyEvent.VK_RIGHT) {
- value = 2;
- } else if (code == KeyEvent.VK_UP) {
- value = 3;
- } else if (code == KeyEvent.VK_DOWN) {
- value = 4;
- } else if (code == KeyEvent.VK_CONTROL) {
- value = 5;
- } else if (code == KeyEvent.VK_BACK_SPACE) {
- value = 8;
- } else if (code == KeyEvent.VK_DELETE) {
- value = 8;
- } else if (code == KeyEvent.VK_TAB) {
- value = 9;
- } else if (code == KeyEvent.VK_ENTER) {
- value = 10;
- } else if ((code >= KeyEvent.VK_F1) && (code <= KeyEvent.VK_F12)) {
- value = (1008 + code) - KeyEvent.VK_F1;
- } else if (code == KeyEvent.VK_HOME) {
- value = 1000;
- } else if (code == KeyEvent.VK_END) {
- value = 1001;
- } else if (code == KeyEvent.VK_PAGE_UP) {
- value = 1002;
- } else if (code == KeyEvent.VK_PAGE_DOWN) {
- value = 1003;
- }
-
- if ((value > 0) && (value < 128)) {
- actionKey[value] = 1;
- }
-
- if (value > 4) {
- keyQueue[keyQueueWritePos] = value;
- keyQueueWritePos = (keyQueueWritePos + 1) & 0x7f;
- }
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- idleCycles = 0;
-
- int code = e.getKeyCode();
- char action = e.getKeyChar();
-
- if (action < 30) {
- action = 0;
- }
-
- if (code == KeyEvent.VK_LEFT) {
- action = 1;
- } else if (code == KeyEvent.VK_RIGHT) {
- action = 2;
- } else if (code == KeyEvent.VK_UP) {
- action = 3;
- } else if (code == KeyEvent.VK_DOWN) {
- action = 4;
- } else if (code == KeyEvent.VK_CONTROL) {
- action = 5;
- } else if (code == KeyEvent.VK_BACK_SPACE) {
- action = 8;
- } else if (code == KeyEvent.VK_DELETE) {
- action = 8;
- } else if (code == KeyEvent.VK_TAB) {
- action = 9;
- } else if (code == KeyEvent.VK_ENTER) {
- action = 10;
- }
-
- if ((action > 0) && (action < 128)) {
- actionKey[action] = 0;
- }
- }
-
- @Override
- public void keyTyped(KeyEvent e) {
- }
-
- public int pollKey() {
- int key = -1;
- if (keyQueueWritePos != keyQueueReadPos) {
- key = keyQueue[keyQueueReadPos];
- keyQueueReadPos = (keyQueueReadPos + 1) & 0x7f;
- }
- return key;
- }
-
- @Override
- public void focusGained(FocusEvent e) {
- focused = true;
- refresh = true;
- refresh();
- }
-
- @Override
- public void focusLost(FocusEvent e) {
- focused = false;
- for (int i = 0; i < 128; i++) {
- actionKey[i] = 0;
- }
- }
-
- @Override
- public void windowActivated(WindowEvent e) {
- }
-
- @Override
- public void windowClosed(WindowEvent e) {
- }
-
- @Override
- public void windowClosing(WindowEvent e) {
- destroy();
- }
-
- @Override
- public void windowDeactivated(WindowEvent e) {
- }
-
- @Override
- public void windowDeiconified(WindowEvent e) {
- }
-
- @Override
- public void windowIconified(WindowEvent e) {
- }
-
- @Override
- public void windowOpened(WindowEvent e) {
- }
-
- /**
- * Called when the {@link GameShell} thread starts.
- *
- * @see #run()
- */
- public abstract void load() throws IOException;
-
- /**
- * @see #run()
- */
- public abstract void update() throws IOException;
-
- /**
- * @see #run()
- */
- public abstract void unload();
-
- /**
- * @see #run()
- */
- public abstract void draw() throws IOException;
-
- /**
- * Refresh is invoked whenever the shell is expected to potentially lost its display image.
- *
- * @see #update(Graphics)
- * @see #paint(Graphics)
- * @see #focusGained(FocusEvent)
- */
- public abstract void refresh();
-
- public void startThread(Runnable runnable, int priority) {
- Thread thread = new Thread(runnable);
- thread.start();
- thread.setPriority(priority);
- }
-
- public void drawProgress(int percent, String message) throws IOException {
- while (graphics == null) {
- graphics = this.getGraphics();
- try {
- this.repaint();
- } catch (Exception ignored) {
- }
- try {
- Thread.sleep(1000L);
- } catch (Exception ignored) {
- }
- }
-
- java.awt.Font helvetica = new java.awt.Font("Helvetica", java.awt.Font.BOLD, 13);
- FontMetrics metrics = this.getFontMetrics(helvetica);
-
- if (refresh) {
- graphics.setColor(Color.black);
- graphics.fillRect(0, 0, screenWidth, screenHeight);
- refresh = false;
- }
-
- int y = (screenHeight / 2) - 18;
-
- graphics.setColor(new Color(140, 17, 17));
- graphics.drawRect((screenWidth / 2) - 152, y, 304, 34);
- graphics.fillRect((screenWidth / 2) - 150, y + 2, percent * 3, 30);
-
- graphics.setColor(Color.black);
- graphics.fillRect(((screenWidth / 2) - 150) + (percent * 3), y + 2, 300 - (percent * 3), 30);
-
- graphics.setFont(helvetica);
- graphics.setColor(Color.white);
- graphics.drawString(message, (screenWidth - metrics.stringWidth(message)) / 2, y + 22);
- }
+ public final long[] otim = new long[10];
+ public final double[] frameTime = new double[100];
+ public final int[] actionKey = new int[128];
+ public final int[] keyQueue = new int[128];
+ public int state;
+ public int deltime = 20;
+ public int mindel = 1;
+ public int fps;
+ public boolean debug = false;
+ public int screenWidth;
+ public int screenHeight;
+ public Graphics graphics;
+ public GameFrame frame;
+ public boolean refresh = true;
+ public boolean focused = true;
+ public int idleCycles;
+ public int mouseButton;
+ public int mouseX;
+ public int mouseY;
+ public int lastMouseClickButton;
+ public int lastMouseClickX;
+ public int lastMouseClickY;
+ public long lastMouseClickTime;
+ public int mouseClickButton;
+ public int mouseClickX;
+ public int mouseClickY;
+ public long mouseClickTime;
+ public int keyQueueReadPos;
+ public int keyQueueWritePos;
+
+ public void init(int width, int height) {
+ screenWidth = width;
+ screenHeight = height;
+ setSize(width, height);
+ setPreferredSize(getSize());
+ frame = new GameFrame(this);
+ graphics = this.getGraphics();
+ startThread(this, 1);
+ requestFocus();
+ }
+
+ public void initApplet(int width, int height) {
+ screenWidth = width;
+ screenHeight = height;
+ graphics = this.getGraphics();
+ startThread(this, 1);
+ }
+
+ @Override
+ public void run() {
+ try {
+ this.addMouseListener(this);
+ this.addMouseMotionListener(this);
+ this.addKeyListener(this);
+ this.addFocusListener(this);
+
+ if (frame != null) {
+ frame.addWindowListener(this);
+ }
+
+ drawProgress(0, "Loading...");
+ load();
+
+ int opos = 0;
+ int fpos = 0;
+ int ratio = 256;
+ int delta = 1;
+ int count = 0;
+ int intex = 0; // interrupt exceptions
+
+ for (int k1 = 0; k1 < 10; k1++) {
+ otim[k1] = System.currentTimeMillis();
+ }
+
+ while (state >= 0) {
+ if (state > 0) {
+ state--;
+ if (state == 0) {
+ shutdown();
+ return;
+ }
+ }
+
+ int lastRatio = ratio;
+ int lastDelta = delta;
+
+ ratio = 300;
+ delta = 1;
+
+ long ntime = System.currentTimeMillis();
+
+ if (otim[opos] == 0L) {
+ ratio = lastRatio;
+ delta = lastDelta;
+ } else if (ntime > otim[opos]) {
+ ratio = (int) ((2560L * deltime) / (ntime - otim[opos]));
+ }
+
+ if (ratio < 25) {
+ ratio = 25;
+ }
+
+ if (ratio > 256) {
+ ratio = 256;
+ delta = (int) ((long) deltime - ((ntime - otim[opos]) / 10L));
+ }
+
+ if (delta > deltime) {
+ delta = deltime;
+ }
+
+ otim[opos] = ntime;
+ opos = (opos + 1) % 10;
+
+ if (delta > 1) {
+ for (int k2 = 0; k2 < 10; k2++) {
+ if (otim[k2] != 0L) {
+ otim[k2] += delta;
+ }
+ }
+ }
+
+ if (delta < mindel) {
+ delta = mindel;
+ }
+
+ try {
+ Thread.sleep(delta);
+ } catch (InterruptedException e) {
+ intex++;
+ }
+
+ long time = System.nanoTime();
+
+ for (; count < 256; count += ratio) {
+ mouseClickButton = lastMouseClickButton;
+ mouseClickX = lastMouseClickX;
+ mouseClickY = lastMouseClickY;
+ mouseClickTime = lastMouseClickTime;
+ lastMouseClickButton = 0;
+ update();
+ keyQueueReadPos = keyQueueWritePos;
+ }
+
+ count &= 0xff;
+
+ if (deltime > 0) {
+ fps = (1000 * ratio) / (deltime * 256);
+ }
+
+ draw();
+
+ frameTime[fpos] = (double) (System.nanoTime() - time) / 1_000_000.0;
+ fpos = (fpos + 1) % frameTime.length;
+
+ if (debug) {
+ System.out.println("ntime:" + ntime);
+ for (int i = 0; i < 10; i++) {
+ int o = ((opos - i - 1) + 20) % 10;
+ System.out.println("otim" + o + ":" + otim[o]);
+ }
+ System.out.println("fps:" + fps + " ratio:" + ratio + " count:" + count);
+ System.out.println("del:" + delta + " deltime:" + deltime + " mindel:" + mindel);
+ System.out.println("intex:" + intex + " opos:" + opos);
+ debug = false;
+ intex = 0;
+ }
+ }
+ } catch (Exception e) {
+ state = -1;
+ e.printStackTrace();
+ }
+
+ if (state == -1) {
+ shutdown();
+ }
+ }
+
+ public void shutdown() {
+ state = -2;
+ unload();
+
+ if (frame != null) {
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception ignored) {
+ }
+ try {
+ System.exit(0);
+ } catch (Throwable ignored) {
+ }
+ }
+ }
+
+ public void setFramerate(int fps) {
+ deltime = 1000 / fps;
+ }
+
+ public void destroy() {
+ state = -1;
+
+ try {
+ Thread.sleep(5000L);
+ } catch (Exception ignored) {
+ }
+
+ if (state == -1) {
+ shutdown();
+ }
+ }
+
+ @Override
+ public void update(Graphics g) {
+ if (graphics == null) {
+ graphics = g;
+ }
+ refresh = true;
+ refresh();
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ if (graphics == null) {
+ graphics = g;
+ }
+ refresh = true;
+ refresh();
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+
+ idleCycles = 0;
+ lastMouseClickX = x;
+ lastMouseClickY = y;
+ lastMouseClickTime = System.currentTimeMillis();
+
+ if (SwingUtilities.isRightMouseButton(e)) {
+ lastMouseClickButton = 2;
+ mouseButton = 2;
+ } else {
+ lastMouseClickButton = 1;
+ mouseButton = 1;
+ }
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ idleCycles = 0;
+ mouseButton = 0;
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ idleCycles = 0;
+ mouseX = -1;
+ mouseY = -1;
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+ idleCycles = 0;
+ mouseX = x;
+ mouseY = y;
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+ idleCycles = 0;
+ mouseX = x;
+ mouseY = y;
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ idleCycles = 0;
+ int code = e.getKeyCode();
+ int value = e.getKeyChar();
+
+ if (value < 30) {
+ value = 0;
+ }
+
+ if (code == KeyEvent.VK_LEFT) {
+ value = 1;
+ } else if (code == KeyEvent.VK_RIGHT) {
+ value = 2;
+ } else if (code == KeyEvent.VK_UP) {
+ value = 3;
+ } else if (code == KeyEvent.VK_DOWN) {
+ value = 4;
+ } else if (code == KeyEvent.VK_CONTROL) {
+ value = 5;
+ } else if (code == KeyEvent.VK_BACK_SPACE) {
+ value = 8;
+ } else if (code == KeyEvent.VK_DELETE) {
+ value = 8;
+ } else if (code == KeyEvent.VK_TAB) {
+ value = 9;
+ } else if (code == KeyEvent.VK_ENTER) {
+ value = 10;
+ } else if ((code >= KeyEvent.VK_F1) && (code <= KeyEvent.VK_F12)) {
+ value = (1008 + code) - KeyEvent.VK_F1;
+ } else if (code == KeyEvent.VK_HOME) {
+ value = 1000;
+ } else if (code == KeyEvent.VK_END) {
+ value = 1001;
+ } else if (code == KeyEvent.VK_PAGE_UP) {
+ value = 1002;
+ } else if (code == KeyEvent.VK_PAGE_DOWN) {
+ value = 1003;
+ }
+
+ if ((value > 0) && (value < 128)) {
+ actionKey[value] = 1;
+ }
+
+ if (value > 4) {
+ keyQueue[keyQueueWritePos] = value;
+ keyQueueWritePos = (keyQueueWritePos + 1) & 0x7f;
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ idleCycles = 0;
+
+ int code = e.getKeyCode();
+ char action = e.getKeyChar();
+
+ if (action < 30) {
+ action = 0;
+ }
+
+ if (code == KeyEvent.VK_LEFT) {
+ action = 1;
+ } else if (code == KeyEvent.VK_RIGHT) {
+ action = 2;
+ } else if (code == KeyEvent.VK_UP) {
+ action = 3;
+ } else if (code == KeyEvent.VK_DOWN) {
+ action = 4;
+ } else if (code == KeyEvent.VK_CONTROL) {
+ action = 5;
+ } else if (code == KeyEvent.VK_BACK_SPACE) {
+ action = 8;
+ } else if (code == KeyEvent.VK_DELETE) {
+ action = 8;
+ } else if (code == KeyEvent.VK_TAB) {
+ action = 9;
+ } else if (code == KeyEvent.VK_ENTER) {
+ action = 10;
+ }
+
+ if ((action > 0) && (action < 128)) {
+ actionKey[action] = 0;
+ }
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ public int pollKey() {
+ int key = -1;
+ if (keyQueueWritePos != keyQueueReadPos) {
+ key = keyQueue[keyQueueReadPos];
+ keyQueueReadPos = (keyQueueReadPos + 1) & 0x7f;
+ }
+ return key;
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ focused = true;
+ refresh = true;
+ refresh();
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ focused = false;
+ for (int i = 0; i < 128; i++) {
+ actionKey[i] = 0;
+ }
+ }
+
+ @Override
+ public void windowActivated(WindowEvent e) {
+ }
+
+ @Override
+ public void windowClosed(WindowEvent e) {
+ }
+
+ @Override
+ public void windowClosing(WindowEvent e) {
+ destroy();
+ }
+
+ @Override
+ public void windowDeactivated(WindowEvent e) {
+ }
+
+ @Override
+ public void windowDeiconified(WindowEvent e) {
+ }
+
+ @Override
+ public void windowIconified(WindowEvent e) {
+ }
+
+ @Override
+ public void windowOpened(WindowEvent e) {
+ }
+
+ /**
+ * Called when the {@link GameShell} thread starts.
+ *
+ * @see #run()
+ */
+ public abstract void load() throws IOException;
+
+ /**
+ * @see #run()
+ */
+ public abstract void update() throws IOException;
+
+ /**
+ * @see #run()
+ */
+ public abstract void unload();
+
+ /**
+ * @see #run()
+ */
+ public abstract void draw() throws IOException;
+
+ /**
+ * Refresh is invoked whenever the shell is expected to potentially lost its display image.
+ *
+ * @see #update(Graphics)
+ * @see #paint(Graphics)
+ * @see #focusGained(FocusEvent)
+ */
+ public abstract void refresh();
+
+ public void startThread(Runnable runnable, int priority) {
+ Thread thread = new Thread(runnable);
+ thread.start();
+ thread.setPriority(priority);
+ }
+
+ public void drawProgress(int percent, String message) throws IOException {
+ while (graphics == null) {
+ graphics = this.getGraphics();
+ try {
+ this.repaint();
+ } catch (Exception ignored) {
+ }
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception ignored) {
+ }
+ }
+
+ java.awt.Font helvetica = new java.awt.Font("Helvetica", java.awt.Font.BOLD, 13);
+ FontMetrics metrics = this.getFontMetrics(helvetica);
+
+ if (refresh) {
+ graphics.setColor(Color.black);
+ graphics.fillRect(0, 0, screenWidth, screenHeight);
+ refresh = false;
+ }
+
+ int y = (screenHeight / 2) - 18;
+
+ graphics.setColor(new Color(140, 17, 17));
+ graphics.drawRect((screenWidth / 2) - 152, y, 304, 34);
+ graphics.fillRect((screenWidth / 2) - 150, y + 2, percent * 3, 30);
+
+ graphics.setColor(Color.black);
+ graphics.fillRect(((screenWidth / 2) - 150) + (percent * 3), y + 2, 300 - (percent * 3), 30);
+
+ graphics.setFont(helvetica);
+ graphics.setColor(Color.white);
+ graphics.drawString(message, (screenWidth - metrics.stringWidth(message)) / 2, y + 22);
+ }
}
diff --git a/src/main/java/Image24.java b/src/main/java/Image24.java
index 9b491cd..d76d10c 100644
--- a/src/main/java/Image24.java
+++ b/src/main/java/Image24.java
@@ -4,469 +4,469 @@ import java.io.IOException;
public class Image24 extends DoublyLinkedList.Node {
- public int[] pixels;
- public int width;
- public int height;
- public int cropX;
- public int cropY;
- public int cropW;
- public int cropH;
+ public int[] pixels;
+ public int width;
+ public int height;
+ public int cropX;
+ public int cropY;
+ public int cropW;
+ public int cropH;
- public Image24(int i, int j) {
- pixels = new int[i * j];
- width = cropW = i;
- height = cropH = j;
- cropX = cropY = 0;
- }
+ public Image24(int i, int j) {
+ pixels = new int[i * j];
+ width = cropW = i;
+ height = cropH = j;
+ cropX = cropY = 0;
+ }
- public Image24(byte[] src, java.awt.Component component) {
- try {
- java.awt.Image image = Toolkit.getDefaultToolkit().createImage(src);
- MediaTracker tracker = new MediaTracker(component);
- tracker.addImage(image, 0);
- tracker.waitForAll();
- width = image.getWidth(component);
- height = image.getHeight(component);
- cropW = width;
- cropH = height;
- cropX = 0;
- cropY = 0;
- pixels = new int[width * height];
- PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
- pixelgrabber.grabPixels();
- } catch (Exception _ex) {
- System.out.println("Error converting jpg");
- }
- }
+ public Image24(byte[] src, java.awt.Component component) {
+ try {
+ java.awt.Image image = Toolkit.getDefaultToolkit().createImage(src);
+ MediaTracker tracker = new MediaTracker(component);
+ tracker.addImage(image, 0);
+ tracker.waitForAll();
+ width = image.getWidth(component);
+ height = image.getHeight(component);
+ cropW = width;
+ cropH = height;
+ cropX = 0;
+ cropY = 0;
+ pixels = new int[width * height];
+ PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
+ pixelgrabber.grabPixels();
+ } catch (Exception _ex) {
+ System.out.println("Error converting jpg");
+ }
+ }
- public Image24(FileArchive archive, String file, int index) throws IOException {
- Buffer dat = new Buffer(archive.read(file + ".dat"));
- Buffer idx = new Buffer(archive.read("index.dat"));
- idx.position = dat.read16U();
- cropW = idx.read16U();
- cropH = idx.read16U();
- int paletteSize = idx.read8U();
- int[] palette = new int[paletteSize];
- for (int k = 0; k < (paletteSize - 1); k++) {
- palette[k + 1] = idx.read24();
- if (palette[k + 1] == 0) {
- palette[k + 1] = 1;
- }
- }
- for (int i = 0; i < index; i++) {
- idx.position += 2;
- dat.position += idx.read16U() * idx.read16U();
- idx.position++;
- }
- cropX = idx.read8U();
- cropY = idx.read8U();
- width = idx.read16U();
- height = idx.read16U();
- int layout = idx.read8U();
- int pixelLen = width * height;
- pixels = new int[pixelLen];
- if (layout == 0) {
- for (int i = 0; i < pixelLen; i++) {
- pixels[i] = palette[dat.read8U()];
- }
- return;
- }
- if (layout == 1) {
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- pixels[x + (y * width)] = palette[dat.read8U()];
- }
- }
- }
- }
+ public Image24(FileArchive archive, String file, int index) throws IOException {
+ Buffer dat = new Buffer(archive.read(file + ".dat"));
+ Buffer idx = new Buffer(archive.read("index.dat"));
+ idx.position = dat.read16U();
+ cropW = idx.read16U();
+ cropH = idx.read16U();
+ int paletteSize = idx.read8U();
+ int[] palette = new int[paletteSize];
+ for (int k = 0; k < (paletteSize - 1); k++) {
+ palette[k + 1] = idx.read24();
+ if (palette[k + 1] == 0) {
+ palette[k + 1] = 1;
+ }
+ }
+ for (int i = 0; i < index; i++) {
+ idx.position += 2;
+ dat.position += idx.read16U() * idx.read16U();
+ idx.position++;
+ }
+ cropX = idx.read8U();
+ cropY = idx.read8U();
+ width = idx.read16U();
+ height = idx.read16U();
+ int layout = idx.read8U();
+ int pixelLen = width * height;
+ pixels = new int[pixelLen];
+ if (layout == 0) {
+ for (int i = 0; i < pixelLen; i++) {
+ pixels[i] = palette[dat.read8U()];
+ }
+ return;
+ }
+ if (layout == 1) {
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ pixels[x + (y * width)] = palette[dat.read8U()];
+ }
+ }
+ }
+ }
- public void bind() {
- Draw2D.bind(pixels, width, height);
- }
+ public void bind() {
+ Draw2D.bind(pixels, width, height);
+ }
- public void translate(int r, int g, int b) {
- for (int i = 0; i < pixels.length; i++) {
- int rgb = pixels[i];
- if (rgb != 0) {
- int red = (rgb >> 16) & 0xff;
- red += r;
- if (red < 1) {
- red = 1;
- } else if (red > 255) {
- red = 255;
- }
- int green = (rgb >> 8) & 0xff;
- green += g;
- if (green < 1) {
- green = 1;
- } else if (green > 255) {
- green = 255;
- }
- int blue = rgb & 0xff;
- blue += b;
- if (blue < 1) {
- blue = 1;
- } else if (blue > 255) {
- blue = 255;
- }
- pixels[i] = (red << 16) + (green << 8) + blue;
- }
- }
- }
+ public void translate(int r, int g, int b) {
+ for (int i = 0; i < pixels.length; i++) {
+ int rgb = pixels[i];
+ if (rgb != 0) {
+ int red = (rgb >> 16) & 0xff;
+ red += r;
+ if (red < 1) {
+ red = 1;
+ } else if (red > 255) {
+ red = 255;
+ }
+ int green = (rgb >> 8) & 0xff;
+ green += g;
+ if (green < 1) {
+ green = 1;
+ } else if (green > 255) {
+ green = 255;
+ }
+ int blue = rgb & 0xff;
+ blue += b;
+ if (blue < 1) {
+ blue = 1;
+ } else if (blue > 255) {
+ blue = 255;
+ }
+ pixels[i] = (red << 16) + (green << 8) + blue;
+ }
+ }
+ }
- public void crop() {
- int[] pixels = new int[cropW * cropH];
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- pixels[((y + cropY) * cropW) + x + cropX] = this.pixels[(y * width) + x];
- }
- }
- this.pixels = pixels;
- width = cropW;
- height = cropH;
- cropX = 0;
- cropY = 0;
- }
+ public void crop() {
+ int[] pixels = new int[cropW * cropH];
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ pixels[((y + cropY) * cropW) + x + cropX] = this.pixels[(y * width) + x];
+ }
+ }
+ this.pixels = pixels;
+ width = cropW;
+ height = cropH;
+ cropX = 0;
+ cropY = 0;
+ }
- public void blitOpaque(int x, int y) {
- x += cropX;
- y += cropY;
- int dstOff = x + (y * Draw2D.width);
- int srcOff = 0;
- int h = height;
- int w = width;
- int dstStep = Draw2D.width - w;
- int srcStep = 0;
- if (y < Draw2D.top) {
- int trim = Draw2D.top - y;
- h -= trim;
- y = Draw2D.top;
- srcOff += trim * w;
- dstOff += trim * Draw2D.width;
- }
- if ((y + h) > Draw2D.bottom) {
- h -= (y + h) - Draw2D.bottom;
- }
- if (x < Draw2D.left) {
- int trim = Draw2D.left - x;
- w -= trim;
- x = Draw2D.left;
- srcOff += trim;
- dstOff += trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((x + w) > Draw2D.right) {
- int trim = (x + w) - Draw2D.right;
- w -= trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((w > 0) && (h > 0)) {
- copyPixels(dstOff, w, h, srcStep, srcOff, dstStep, pixels, Draw2D.pixels);
- }
- }
+ public void blitOpaque(int x, int y) {
+ x += cropX;
+ y += cropY;
+ int dstOff = x + (y * Draw2D.width);
+ int srcOff = 0;
+ int h = height;
+ int w = width;
+ int dstStep = Draw2D.width - w;
+ int srcStep = 0;
+ if (y < Draw2D.top) {
+ int trim = Draw2D.top - y;
+ h -= trim;
+ y = Draw2D.top;
+ srcOff += trim * w;
+ dstOff += trim * Draw2D.width;
+ }
+ if ((y + h) > Draw2D.bottom) {
+ h -= (y + h) - Draw2D.bottom;
+ }
+ if (x < Draw2D.left) {
+ int trim = Draw2D.left - x;
+ w -= trim;
+ x = Draw2D.left;
+ srcOff += trim;
+ dstOff += trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((x + w) > Draw2D.right) {
+ int trim = (x + w) - Draw2D.right;
+ w -= trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((w > 0) && (h > 0)) {
+ copyPixels(dstOff, w, h, srcStep, srcOff, dstStep, pixels, Draw2D.pixels);
+ }
+ }
- public void copyPixels(int dstOff, int w, int h, int srcStep, int srcOff, int dstStep, int[] src, int[] dst) {
- int quarterWidth = -(w >> 2);
- w = -(w & 3);
- for (int y = -h; y < 0; y++) {
- for (int i = quarterWidth; i < 0; i++) {
- dst[dstOff++] = src[srcOff++];
- dst[dstOff++] = src[srcOff++];
- dst[dstOff++] = src[srcOff++];
- dst[dstOff++] = src[srcOff++];
- }
- for (int i = w; i < 0; i++) {
- dst[dstOff++] = src[srcOff++];
- }
- dstOff += dstStep;
- srcOff += srcStep;
- }
- }
+ public void copyPixels(int dstOff, int w, int h, int srcStep, int srcOff, int dstStep, int[] src, int[] dst) {
+ int quarterWidth = -(w >> 2);
+ w = -(w & 3);
+ for (int y = -h; y < 0; y++) {
+ for (int i = quarterWidth; i < 0; i++) {
+ dst[dstOff++] = src[srcOff++];
+ dst[dstOff++] = src[srcOff++];
+ dst[dstOff++] = src[srcOff++];
+ dst[dstOff++] = src[srcOff++];
+ }
+ for (int i = w; i < 0; i++) {
+ dst[dstOff++] = src[srcOff++];
+ }
+ dstOff += dstStep;
+ srcOff += srcStep;
+ }
+ }
- public void draw(int x, int y) {
- x += cropX;
- y += cropY;
- int dstOff = x + (y * Draw2D.width);
- int srcOff = 0;
- int h = height;
- int w = width;
- int dstStep = Draw2D.width - w;
- int srcStep = 0;
- if (y < Draw2D.top) {
- int trim = Draw2D.top - y;
- h -= trim;
- y = Draw2D.top;
- srcOff += trim * w;
- dstOff += trim * Draw2D.width;
- }
- if ((y + h) > Draw2D.bottom) {
- h -= (y + h) - Draw2D.bottom;
- }
- if (x < Draw2D.left) {
- int trim = Draw2D.left - x;
- w -= trim;
- x = Draw2D.left;
- srcOff += trim;
- dstOff += trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((x + w) > Draw2D.right) {
- int trim = (x + w) - Draw2D.right;
- w -= trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((w > 0) && (h > 0)) {
- copyPixels(Draw2D.pixels, pixels, srcOff, dstOff, w, h, dstStep, srcStep);
- }
- }
+ public void draw(int x, int y) {
+ x += cropX;
+ y += cropY;
+ int dstOff = x + (y * Draw2D.width);
+ int srcOff = 0;
+ int h = height;
+ int w = width;
+ int dstStep = Draw2D.width - w;
+ int srcStep = 0;
+ if (y < Draw2D.top) {
+ int trim = Draw2D.top - y;
+ h -= trim;
+ y = Draw2D.top;
+ srcOff += trim * w;
+ dstOff += trim * Draw2D.width;
+ }
+ if ((y + h) > Draw2D.bottom) {
+ h -= (y + h) - Draw2D.bottom;
+ }
+ if (x < Draw2D.left) {
+ int trim = Draw2D.left - x;
+ w -= trim;
+ x = Draw2D.left;
+ srcOff += trim;
+ dstOff += trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((x + w) > Draw2D.right) {
+ int trim = (x + w) - Draw2D.right;
+ w -= trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((w > 0) && (h > 0)) {
+ copyPixels(Draw2D.pixels, pixels, srcOff, dstOff, w, h, dstStep, srcStep);
+ }
+ }
- public void copyPixels(int[] dst, int[] src, int srcOff, int dstOff, int w, int h, int dstStep, int srcstep) {
- int quarterW = -(w >> 2);
- w = -(w & 3);
- for (int y = -h; y < 0; y++) {
- int rgb;
- for (int x = quarterW; x < 0; x++) {
- rgb = src[srcOff++];
- if (rgb != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- rgb = src[srcOff++];
- if (rgb != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- rgb = src[srcOff++];
- if (rgb != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- rgb = src[srcOff++];
- if (rgb != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- }
- for (int k2 = w; k2 < 0; k2++) {
- rgb = src[srcOff++];
- if (rgb != 0) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- }
- dstOff += dstStep;
- srcOff += srcstep;
- }
- }
+ public void copyPixels(int[] dst, int[] src, int srcOff, int dstOff, int w, int h, int dstStep, int srcstep) {
+ int quarterW = -(w >> 2);
+ w = -(w & 3);
+ for (int y = -h; y < 0; y++) {
+ int rgb;
+ for (int x = quarterW; x < 0; x++) {
+ rgb = src[srcOff++];
+ if (rgb != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ rgb = src[srcOff++];
+ if (rgb != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ rgb = src[srcOff++];
+ if (rgb != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ rgb = src[srcOff++];
+ if (rgb != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ }
+ for (int k2 = w; k2 < 0; k2++) {
+ rgb = src[srcOff++];
+ if (rgb != 0) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ }
+ dstOff += dstStep;
+ srcOff += srcstep;
+ }
+ }
- public void draw(int x, int y, int alpha) {
- x += cropX;
- y += cropY;
- int dstOff = x + (y * Draw2D.width);
- int srcOff = 0;
- int h = height;
- int w = width;
- int dstStep = Draw2D.width - w;
- int srcStep = 0;
- if (y < Draw2D.top) {
- int trim = Draw2D.top - y;
- h -= trim;
- y = Draw2D.top;
- srcOff += trim * w;
- dstOff += trim * Draw2D.width;
- }
- if ((y + h) > Draw2D.bottom) {
- h -= (y + h) - Draw2D.bottom;
- }
- if (x < Draw2D.left) {
- int trim = Draw2D.left - x;
- w -= trim;
- x = Draw2D.left;
- srcOff += trim;
- dstOff += trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((x + w) > Draw2D.right) {
- int trim = (x + w) - Draw2D.right;
- w -= trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((w > 0) && (h > 0)) {
- copyPixelsAlpha(srcOff, w, Draw2D.pixels, pixels, srcStep, h, dstStep, alpha, dstOff);
- }
- }
+ public void draw(int x, int y, int alpha) {
+ x += cropX;
+ y += cropY;
+ int dstOff = x + (y * Draw2D.width);
+ int srcOff = 0;
+ int h = height;
+ int w = width;
+ int dstStep = Draw2D.width - w;
+ int srcStep = 0;
+ if (y < Draw2D.top) {
+ int trim = Draw2D.top - y;
+ h -= trim;
+ y = Draw2D.top;
+ srcOff += trim * w;
+ dstOff += trim * Draw2D.width;
+ }
+ if ((y + h) > Draw2D.bottom) {
+ h -= (y + h) - Draw2D.bottom;
+ }
+ if (x < Draw2D.left) {
+ int trim = Draw2D.left - x;
+ w -= trim;
+ x = Draw2D.left;
+ srcOff += trim;
+ dstOff += trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((x + w) > Draw2D.right) {
+ int trim = (x + w) - Draw2D.right;
+ w -= trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((w > 0) && (h > 0)) {
+ copyPixelsAlpha(srcOff, w, Draw2D.pixels, pixels, srcStep, h, dstStep, alpha, dstOff);
+ }
+ }
- public void copyPixelsAlpha(int srcOff, int w, int[] dst, int[] src, int srcStep, int h, int dstStep, int alpha, int dstOff) {
- int invAlpha = 256 - alpha;
- for (int k2 = -h; k2 < 0; k2++) {
- for (int l2 = -w; l2 < 0; l2++) {
- int srcRGB = src[srcOff++];
- if (srcRGB != 0) {
- int dstRGB = dst[dstOff];
- dst[dstOff++] = (((((srcRGB & 0xff00ff) * alpha) + ((dstRGB & 0xff00ff) * invAlpha)) & 0xff00ff00) + ((((srcRGB & 0xff00) * alpha) + ((dstRGB & 0xff00) * invAlpha)) & 0xff0000)) >> 8;
- } else {
- dstOff++;
- }
- }
- dstOff += dstStep;
- srcOff += srcStep;
- }
- }
+ public void copyPixelsAlpha(int srcOff, int w, int[] dst, int[] src, int srcStep, int h, int dstStep, int alpha, int dstOff) {
+ int invAlpha = 256 - alpha;
+ for (int k2 = -h; k2 < 0; k2++) {
+ for (int l2 = -w; l2 < 0; l2++) {
+ int srcRGB = src[srcOff++];
+ if (srcRGB != 0) {
+ int dstRGB = dst[dstOff];
+ dst[dstOff++] = (((((srcRGB & 0xff00ff) * alpha) + ((dstRGB & 0xff00ff) * invAlpha)) & 0xff00ff00) + ((((srcRGB & 0xff00) * alpha) + ((dstRGB & 0xff00) * invAlpha)) & 0xff0000)) >> 8;
+ } else {
+ dstOff++;
+ }
+ }
+ dstOff += dstStep;
+ srcOff += srcStep;
+ }
+ }
- public void drawRotatedMasked(int x, int y, int width, int height, int anchorX, int anchorY, int zoom, int angle, int[] lineLengths, int[] lineOffsets) {
- try {
- int midX = -width / 2;
- int midY = -height / 2;
- int sin = (int) (Math.sin((double) angle / 326.11000000000001D) * 65536D);
- int cos = (int) (Math.cos((double) angle / 326.11000000000001D) * 65536D);
- sin = (sin * zoom) >> 8;
- cos = (cos * zoom) >> 8;
- int leftX = (anchorX << 16) + (midY * sin) + (midX * cos);
- int lefty = ((anchorY << 16) + (midY * cos)) - (midX * sin);
- int leftOff = x + (y * Draw2D.width);
- for (y = 0; y < height; y++) {
- int lineOffset = lineOffsets[y];
- int dstOff = leftOff + lineOffset;
- int srcX = leftX + (cos * lineOffset);
- int srcY = lefty - (sin * lineOffset);
- for (x = -lineLengths[y]; x < 0; x++) {
- Draw2D.pixels[dstOff++] = pixels[(srcX >> 16) + ((srcY >> 16) * this.width)];
- srcX += cos;
- srcY -= sin;
- }
- leftX += sin;
- lefty += cos;
- leftOff += Draw2D.width;
- }
- } catch (Exception ignored) {
- }
- }
+ public void drawRotatedMasked(int x, int y, int width, int height, int anchorX, int anchorY, int zoom, int angle, int[] lineLengths, int[] lineOffsets) {
+ try {
+ int midX = -width / 2;
+ int midY = -height / 2;
+ int sin = (int) (Math.sin((double) angle / 326.11000000000001D) * 65536D);
+ int cos = (int) (Math.cos((double) angle / 326.11000000000001D) * 65536D);
+ sin = (sin * zoom) >> 8;
+ cos = (cos * zoom) >> 8;
+ int leftX = (anchorX << 16) + (midY * sin) + (midX * cos);
+ int lefty = ((anchorY << 16) + (midY * cos)) - (midX * sin);
+ int leftOff = x + (y * Draw2D.width);
+ for (y = 0; y < height; y++) {
+ int lineOffset = lineOffsets[y];
+ int dstOff = leftOff + lineOffset;
+ int srcX = leftX + (cos * lineOffset);
+ int srcY = lefty - (sin * lineOffset);
+ for (x = -lineLengths[y]; x < 0; x++) {
+ Draw2D.pixels[dstOff++] = pixels[(srcX >> 16) + ((srcY >> 16) * this.width)];
+ srcX += cos;
+ srcY -= sin;
+ }
+ leftX += sin;
+ lefty += cos;
+ leftOff += Draw2D.width;
+ }
+ } catch (Exception ignored) {
+ }
+ }
- public void drawRotated(int x, int y, int width, int height, int anchorX, int anchorY, double radians, int zoom) {
- try {
- int centerX = -width / 2;
- int centerY = -height / 2;
- int sin = (int) (Math.sin(radians) * 65536D);
- int cos = (int) (Math.cos(radians) * 65536D);
- sin = (sin * zoom) >> 8;
- cos = (cos * zoom) >> 8;
- int leftX = (anchorX << 16) + (centerY * sin) + (centerX * cos);
- int leftY = ((anchorY << 16) + (centerY * cos)) - (centerX * sin);
- int leftOff = x + (y * Draw2D.width);
+ public void drawRotated(int x, int y, int width, int height, int anchorX, int anchorY, double radians, int zoom) {
+ try {
+ int centerX = -width / 2;
+ int centerY = -height / 2;
+ int sin = (int) (Math.sin(radians) * 65536D);
+ int cos = (int) (Math.cos(radians) * 65536D);
+ sin = (sin * zoom) >> 8;
+ cos = (cos * zoom) >> 8;
+ int leftX = (anchorX << 16) + (centerY * sin) + (centerX * cos);
+ int leftY = ((anchorY << 16) + (centerY * cos)) - (centerX * sin);
+ int leftOff = x + (y * Draw2D.width);
- for (y = 0; y < height; y++) {
- int dstOff = leftOff;
- int dstX = leftX;
- int dstY = leftY;
- for (x = -width; x < 0; x++) {
- int rgb = pixels[(dstX >> 16) + ((dstY >> 16) * this.width)];
- if (rgb != 0) {
- Draw2D.pixels[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- dstX += cos;
- dstY -= sin;
- }
- leftX += sin;
- leftY += cos;
- leftOff += Draw2D.width;
- }
- } catch (Exception ignored) {
- }
- }
+ for (y = 0; y < height; y++) {
+ int dstOff = leftOff;
+ int dstX = leftX;
+ int dstY = leftY;
+ for (x = -width; x < 0; x++) {
+ int rgb = pixels[(dstX >> 16) + ((dstY >> 16) * this.width)];
+ if (rgb != 0) {
+ Draw2D.pixels[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ dstX += cos;
+ dstY -= sin;
+ }
+ leftX += sin;
+ leftY += cos;
+ leftOff += Draw2D.width;
+ }
+ } catch (Exception ignored) {
+ }
+ }
- public void drawMasked(Image8 mask, int y, int x) {
- x += cropX;
- y += cropY;
- int dstOff = x + (y * Draw2D.width);
- int srcOff = 0;
- int h = height;
- int w = width;
- int dstStep = Draw2D.width - w;
- int srcStep = 0;
- if (y < Draw2D.top) {
- int trim = Draw2D.top - y;
- h -= trim;
- y = Draw2D.top;
- srcOff += trim * w;
- dstOff += trim * Draw2D.width;
- }
- if ((y + h) > Draw2D.bottom) {
- h -= (y + h) - Draw2D.bottom;
- }
- if (x < Draw2D.left) {
- int trim = Draw2D.left - x;
- w -= trim;
- x = Draw2D.left;
- srcOff += trim;
- dstOff += trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((x + w) > Draw2D.right) {
- int trim = (x + w) - Draw2D.right;
- w -= trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((w > 0) && (h > 0)) {
- copyPixelsMasked(pixels, srcOff, srcStep, mask.pixels, w, h, Draw2D.pixels, dstOff, dstStep);
- }
- }
+ public void drawMasked(Image8 mask, int y, int x) {
+ x += cropX;
+ y += cropY;
+ int dstOff = x + (y * Draw2D.width);
+ int srcOff = 0;
+ int h = height;
+ int w = width;
+ int dstStep = Draw2D.width - w;
+ int srcStep = 0;
+ if (y < Draw2D.top) {
+ int trim = Draw2D.top - y;
+ h -= trim;
+ y = Draw2D.top;
+ srcOff += trim * w;
+ dstOff += trim * Draw2D.width;
+ }
+ if ((y + h) > Draw2D.bottom) {
+ h -= (y + h) - Draw2D.bottom;
+ }
+ if (x < Draw2D.left) {
+ int trim = Draw2D.left - x;
+ w -= trim;
+ x = Draw2D.left;
+ srcOff += trim;
+ dstOff += trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((x + w) > Draw2D.right) {
+ int trim = (x + w) - Draw2D.right;
+ w -= trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((w > 0) && (h > 0)) {
+ copyPixelsMasked(pixels, srcOff, srcStep, mask.pixels, w, h, Draw2D.pixels, dstOff, dstStep);
+ }
+ }
- public void copyPixelsMasked(int[] src, int srcOff, int srcStep, byte[] mask, int w, int h, int[] dst, int dstOff, int dstStep) {
- int quarterW = -(w >> 2);
- w = -(w & 3);
- for (int y = -h; y < 0; y++) {
- int rgb;
- for (int i = quarterW; i < 0; i++) {
- rgb = src[srcOff++];
- if ((rgb != 0) && (mask[dstOff] == 0)) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- rgb = src[srcOff++];
- if ((rgb != 0) && (mask[dstOff] == 0)) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- rgb = src[srcOff++];
- if ((rgb != 0) && (mask[dstOff] == 0)) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- rgb = src[srcOff++];
- if ((rgb != 0) && (mask[dstOff] == 0)) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- }
- for (int i = w; i < 0; i++) {
- rgb = src[srcOff++];
- if ((rgb != 0) && (mask[dstOff] == 0)) {
- dst[dstOff++] = rgb;
- } else {
- dstOff++;
- }
- }
- dstOff += dstStep;
- srcOff += srcStep;
- }
- }
+ public void copyPixelsMasked(int[] src, int srcOff, int srcStep, byte[] mask, int w, int h, int[] dst, int dstOff, int dstStep) {
+ int quarterW = -(w >> 2);
+ w = -(w & 3);
+ for (int y = -h; y < 0; y++) {
+ int rgb;
+ for (int i = quarterW; i < 0; i++) {
+ rgb = src[srcOff++];
+ if ((rgb != 0) && (mask[dstOff] == 0)) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ rgb = src[srcOff++];
+ if ((rgb != 0) && (mask[dstOff] == 0)) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ rgb = src[srcOff++];
+ if ((rgb != 0) && (mask[dstOff] == 0)) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ rgb = src[srcOff++];
+ if ((rgb != 0) && (mask[dstOff] == 0)) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ }
+ for (int i = w; i < 0; i++) {
+ rgb = src[srcOff++];
+ if ((rgb != 0) && (mask[dstOff] == 0)) {
+ dst[dstOff++] = rgb;
+ } else {
+ dstOff++;
+ }
+ }
+ dstOff += dstStep;
+ srcOff += srcStep;
+ }
+ }
}
diff --git a/src/main/java/Image8.java b/src/main/java/Image8.java
index 382ec9c..a17ec8a 100644
--- a/src/main/java/Image8.java
+++ b/src/main/java/Image8.java
@@ -2,223 +2,223 @@ import java.io.IOException;
public class Image8 {
- public final int[] palette;
- public byte[] pixels;
- public int width;
- public int height;
- public int cropX;
- public int cropY;
- public int cropW;
- public int cropH;
+ public final int[] palette;
+ public byte[] pixels;
+ public int width;
+ public int height;
+ public int cropX;
+ public int cropY;
+ public int cropW;
+ public int cropH;
- public Image8(FileArchive archive, String name, int index) throws IOException {
- Buffer dat = new Buffer(archive.read(name + ".dat"));
- Buffer idx = new Buffer(archive.read("index.dat"));
- idx.position = dat.read16U();
- cropW = idx.read16U();
- cropH = idx.read16U();
- int paletteSize = idx.read8U();
- palette = new int[paletteSize];
- for (int i = 0; i < (paletteSize - 1); i++) {
- palette[i + 1] = idx.read24();
- }
- for (int i = 0; i < index; i++) {
- idx.position += 2;
- dat.position += idx.read16U() * idx.read16U();
- idx.position++;
- }
- cropX = idx.read8U();
- cropY = idx.read8U();
- width = idx.read16U();
- height = idx.read16U();
- int pixelOrder = idx.read8U();
- int pixelCount = width * height;
- pixels = new byte[pixelCount];
+ public Image8(FileArchive archive, String name, int index) throws IOException {
+ Buffer dat = new Buffer(archive.read(name + ".dat"));
+ Buffer idx = new Buffer(archive.read("index.dat"));
+ idx.position = dat.read16U();
+ cropW = idx.read16U();
+ cropH = idx.read16U();
+ int paletteSize = idx.read8U();
+ palette = new int[paletteSize];
+ for (int i = 0; i < (paletteSize - 1); i++) {
+ palette[i + 1] = idx.read24();
+ }
+ for (int i = 0; i < index; i++) {
+ idx.position += 2;
+ dat.position += idx.read16U() * idx.read16U();
+ idx.position++;
+ }
+ cropX = idx.read8U();
+ cropY = idx.read8U();
+ width = idx.read16U();
+ height = idx.read16U();
+ int pixelOrder = idx.read8U();
+ int pixelCount = width * height;
+ pixels = new byte[pixelCount];
- if (pixelOrder == 0) {
- for (int i = 0; i < pixelCount; i++) {
- pixels[i] = dat.read();
- }
- return;
- }
+ if (pixelOrder == 0) {
+ for (int i = 0; i < pixelCount; i++) {
+ pixels[i] = dat.read();
+ }
+ return;
+ }
- if (pixelOrder == 1) {
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- pixels[x + (y * width)] = dat.read();
- }
- }
- }
- }
+ if (pixelOrder == 1) {
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ pixels[x + (y * width)] = dat.read();
+ }
+ }
+ }
+ }
- public void shrink() {
- cropW /= 2;
- cropH /= 2;
- byte[] pixels = new byte[cropW * cropH];
- int off = 0;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- pixels[((x + cropX) >> 1) + (((y + cropY) >> 1) * cropW)] = this.pixels[off++];
- }
- }
- this.pixels = pixels;
- width = cropW;
- height = cropH;
- cropX = 0;
- cropY = 0;
- }
+ public void shrink() {
+ cropW /= 2;
+ cropH /= 2;
+ byte[] pixels = new byte[cropW * cropH];
+ int off = 0;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ pixels[((x + cropX) >> 1) + (((y + cropY) >> 1) * cropW)] = this.pixels[off++];
+ }
+ }
+ this.pixels = pixels;
+ width = cropW;
+ height = cropH;
+ cropX = 0;
+ cropY = 0;
+ }
- public void crop() {
- if ((width == cropW) && (height == cropH)) {
- return;
- }
- byte[] pixels = new byte[cropW * cropH];
- int off = 0;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- pixels[x + cropX + ((y + cropY) * cropW)] = this.pixels[off++];
- }
- }
- this.pixels = pixels;
- width = cropW;
- height = cropH;
- cropX = 0;
- cropY = 0;
- }
+ public void crop() {
+ if ((width == cropW) && (height == cropH)) {
+ return;
+ }
+ byte[] pixels = new byte[cropW * cropH];
+ int off = 0;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ pixels[x + cropX + ((y + cropY) * cropW)] = this.pixels[off++];
+ }
+ }
+ this.pixels = pixels;
+ width = cropW;
+ height = cropH;
+ cropX = 0;
+ cropY = 0;
+ }
- public void flipHorizontally() {
- byte[] pixels = new byte[width * height];
- int off = 0;
- for (int y = 0; y < height; y++) {
- for (int x = width - 1; x >= 0; x--) {
- pixels[off++] = this.pixels[x + (y * width)];
- }
- }
- this.pixels = pixels;
- cropX = cropW - width - cropX;
- }
+ public void flipHorizontally() {
+ byte[] pixels = new byte[width * height];
+ int off = 0;
+ for (int y = 0; y < height; y++) {
+ for (int x = width - 1; x >= 0; x--) {
+ pixels[off++] = this.pixels[x + (y * width)];
+ }
+ }
+ this.pixels = pixels;
+ cropX = cropW - width - cropX;
+ }
- public void flipVertically() {
- byte[] pixels = new byte[width * height];
- int i = 0;
- for (int y = height - 1; y >= 0; y--) {
- for (int x = 0; x < width; x++) {
- pixels[i++] = this.pixels[x + (y * width)];
- }
- }
- this.pixels = pixels;
- cropY = cropH - height - cropY;
- }
+ public void flipVertically() {
+ byte[] pixels = new byte[width * height];
+ int i = 0;
+ for (int y = height - 1; y >= 0; y--) {
+ for (int x = 0; x < width; x++) {
+ pixels[i++] = this.pixels[x + (y * width)];
+ }
+ }
+ this.pixels = pixels;
+ cropY = cropH - height - cropY;
+ }
- public void translate(int r, int g, int b) {
- for (int i = 0; i < palette.length; i++) {
- int red = (palette[i] >> 16) & 0xff;
- red += r;
- if (red < 0) {
- red = 0;
- } else if (red > 255) {
- red = 255;
- }
- int green = (palette[i] >> 8) & 0xff;
- green += g;
- if (green < 0) {
- green = 0;
- } else if (green > 255) {
- green = 255;
- }
- int blue = palette[i] & 0xff;
- blue += b;
- if (blue < 0) {
- blue = 0;
- } else if (blue > 255) {
- blue = 255;
- }
- palette[i] = (red << 16) + (green << 8) + blue;
- }
- }
+ public void translate(int r, int g, int b) {
+ for (int i = 0; i < palette.length; i++) {
+ int red = (palette[i] >> 16) & 0xff;
+ red += r;
+ if (red < 0) {
+ red = 0;
+ } else if (red > 255) {
+ red = 255;
+ }
+ int green = (palette[i] >> 8) & 0xff;
+ green += g;
+ if (green < 0) {
+ green = 0;
+ } else if (green > 255) {
+ green = 255;
+ }
+ int blue = palette[i] & 0xff;
+ blue += b;
+ if (blue < 0) {
+ blue = 0;
+ } else if (blue > 255) {
+ blue = 255;
+ }
+ palette[i] = (red << 16) + (green << 8) + blue;
+ }
+ }
- public void blit(int x, int y) {
- x += cropX;
- y += cropY;
- int dstOff = x + (y * Draw2D.width);
- int srcOff = 0;
- int height = this.height;
- int width = this.width;
- int dstStep = Draw2D.width - width;
- int srcStep = 0;
- if (y < Draw2D.top) {
- int trim = Draw2D.top - y;
- height -= trim;
- y = Draw2D.top;
- srcOff += trim * width;
- dstOff += trim * Draw2D.width;
- }
- if ((y + height) > Draw2D.bottom) {
- height -= (y + height) - Draw2D.bottom;
- }
- if (x < Draw2D.left) {
- int trim = Draw2D.left - x;
- width -= trim;
- x = Draw2D.left;
- srcOff += trim;
- dstOff += trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((x + width) > Draw2D.right) {
- int trim = (x + width) - Draw2D.right;
- width -= trim;
- srcStep += trim;
- dstStep += trim;
- }
- if ((width > 0) && (height > 0)) {
- blit(height, Draw2D.pixels, pixels, dstStep, dstOff, width, srcOff, palette, srcStep);
- }
- }
+ public void blit(int x, int y) {
+ x += cropX;
+ y += cropY;
+ int dstOff = x + (y * Draw2D.width);
+ int srcOff = 0;
+ int height = this.height;
+ int width = this.width;
+ int dstStep = Draw2D.width - width;
+ int srcStep = 0;
+ if (y < Draw2D.top) {
+ int trim = Draw2D.top - y;
+ height -= trim;
+ y = Draw2D.top;
+ srcOff += trim * width;
+ dstOff += trim * Draw2D.width;
+ }
+ if ((y + height) > Draw2D.bottom) {
+ height -= (y + height) - Draw2D.bottom;
+ }
+ if (x < Draw2D.left) {
+ int trim = Draw2D.left - x;
+ width -= trim;
+ x = Draw2D.left;
+ srcOff += trim;
+ dstOff += trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((x + width) > Draw2D.right) {
+ int trim = (x + width) - Draw2D.right;
+ width -= trim;
+ srcStep += trim;
+ dstStep += trim;
+ }
+ if ((width > 0) && (height > 0)) {
+ blit(height, Draw2D.pixels, pixels, dstStep, dstOff, width, srcOff, palette, srcStep);
+ }
+ }
- public void blit(int height, int[] dst, byte[] src, int dstStep, int dstOff, int width, int srcOff, int[] palette, int srcStep) {
- int quarterWidth = -(width >> 2);
- width = -(width & 3);
- for (int y = -height; y < 0; y++) {
- for (int w = quarterWidth; w < 0; w++) {
- byte paletteIndex = src[srcOff++];
+ public void blit(int height, int[] dst, byte[] src, int dstStep, int dstOff, int width, int srcOff, int[] palette, int srcStep) {
+ int quarterWidth = -(width >> 2);
+ width = -(width & 3);
+ for (int y = -height; y < 0; y++) {
+ for (int w = quarterWidth; w < 0; w++) {
+ byte paletteIndex = src[srcOff++];
- if (paletteIndex != 0) {
- dst[dstOff++] = palette[paletteIndex & 0xff];
- } else {
- dstOff++;
- }
+ if (paletteIndex != 0) {
+ dst[dstOff++] = palette[paletteIndex & 0xff];
+ } else {
+ dstOff++;
+ }
- paletteIndex = src[srcOff++];
- if (paletteIndex != 0) {
- dst[dstOff++] = palette[paletteIndex & 0xff];
- } else {
- dstOff++;
- }
- paletteIndex = src[srcOff++];
- if (paletteIndex != 0) {
- dst[dstOff++] = palette[paletteIndex & 0xff];
- } else {
- dstOff++;
- }
- paletteIndex = src[srcOff++];
- if (paletteIndex != 0) {
- dst[dstOff++] = palette[paletteIndex & 0xff];
- } else {
- dstOff++;
- }
- }
- for (int i = width; i < 0; i++) {
- byte paletteIndex = src[srcOff++];
- if (paletteIndex != 0) {
- dst[dstOff++] = palette[paletteIndex & 0xff];
- } else {
- dstOff++;
- }
- }
- dstOff += dstStep;
- srcOff += srcStep;
- }
- }
+ paletteIndex = src[srcOff++];
+ if (paletteIndex != 0) {
+ dst[dstOff++] = palette[paletteIndex & 0xff];
+ } else {
+ dstOff++;
+ }
+ paletteIndex = src[srcOff++];
+ if (paletteIndex != 0) {
+ dst[dstOff++] = palette[paletteIndex & 0xff];
+ } else {
+ dstOff++;
+ }
+ paletteIndex = src[srcOff++];
+ if (paletteIndex != 0) {
+ dst[dstOff++] = palette[paletteIndex & 0xff];
+ } else {
+ dstOff++;
+ }
+ }
+ for (int i = width; i < 0; i++) {
+ byte paletteIndex = src[srcOff++];
+ if (paletteIndex != 0) {
+ dst[dstOff++] = palette[paletteIndex & 0xff];
+ } else {
+ dstOff++;
+ }
+ }
+ dstOff += dstStep;
+ srcOff += srcStep;
+ }
+ }
}
diff --git a/src/main/java/LocEntity.java b/src/main/java/LocEntity.java
index 9cfb74c..3ca42ff 100644
--- a/src/main/java/LocEntity.java
+++ b/src/main/java/LocEntity.java
@@ -4,115 +4,115 @@
public class LocEntity extends Entity {
- public static Game game;
- public final int[] overrideTypeIDs;
- public final int varbit;
- public final int varp;
- public final int heightmapSW;
- public final int heightmapSE;
- public final int heightmapNE;
- public final int heightmapNW;
- public final int id;
- public final int kind;
- public final int rotation;
- public int seqFrame;
- public SeqType seq;
- public int seqCycle;
+ public static Game game;
+ public final int[] overrideTypeIDs;
+ public final int varbit;
+ public final int varp;
+ public final int heightmapSW;
+ public final int heightmapSE;
+ public final int heightmapNE;
+ public final int heightmapNW;
+ public final int id;
+ public final int kind;
+ public final int rotation;
+ public int seqFrame;
+ public SeqType seq;
+ public int seqCycle;
- public LocEntity(int id, int rotation, int kind, int heightmapSE, int heightmapNE, int heightmapSW, int heightmapNW, int seqID, boolean randomFrame) {
- this.id = id;
- this.kind = kind;
- this.rotation = rotation;
- this.heightmapSW = heightmapSW;
- this.heightmapSE = heightmapSE;
- this.heightmapNE = heightmapNE;
- this.heightmapNW = heightmapNW;
+ public LocEntity(int id, int rotation, int kind, int heightmapSE, int heightmapNE, int heightmapSW, int heightmapNW, int seqID, boolean randomFrame) {
+ this.id = id;
+ this.kind = kind;
+ this.rotation = rotation;
+ this.heightmapSW = heightmapSW;
+ this.heightmapSE = heightmapSE;
+ this.heightmapNE = heightmapNE;
+ this.heightmapNW = heightmapNW;
- if (seqID != -1) {
- seq = SeqType.instances[seqID];
- seqFrame = 0;
- seqCycle = Game.loopCycle;
+ if (seqID != -1) {
+ seq = SeqType.instances[seqID];
+ seqFrame = 0;
+ seqCycle = Game.loopCycle;
- if (randomFrame && (seq.loopFrameCount != -1)) {
- seqFrame = (int) (Math.random() * (double) seq.frameCount);
- seqCycle -= (int) (Math.random() * (double) seq.getFrameDuration(seqFrame));
- }
- }
- LocType type = LocType.get(this.id);
- varbit = type.varbit;
- varp = type.varp;
- overrideTypeIDs = type.overrideTypeIDs;
- }
+ if (randomFrame && (seq.loopFrameCount != -1)) {
+ seqFrame = (int) (Math.random() * (double) seq.frameCount);
+ seqCycle -= (int) (Math.random() * (double) seq.getFrameDuration(seqFrame));
+ }
+ }
+ LocType type = LocType.get(this.id);
+ varbit = type.varbit;
+ varp = type.varp;
+ overrideTypeIDs = type.overrideTypeIDs;
+ }
- @Override
- public Model getModel() {
- int transformID = -1;
+ @Override
+ public Model getModel() {
+ int transformID = -1;
- if (seq != null) {
- int delta = Game.loopCycle - seqCycle;
+ if (seq != null) {
+ int delta = Game.loopCycle - seqCycle;
- if ((delta > 100) && (seq.loopFrameCount > 0)) {
- delta = 100;
- }
+ if ((delta > 100) && (seq.loopFrameCount > 0)) {
+ delta = 100;
+ }
- while (delta > seq.getFrameDuration(seqFrame)) {
- delta -= seq.getFrameDuration(seqFrame);
- seqFrame++;
+ while (delta > seq.getFrameDuration(seqFrame)) {
+ delta -= seq.getFrameDuration(seqFrame);
+ seqFrame++;
- if (seqFrame < seq.frameCount) {
- continue;
- }
+ if (seqFrame < seq.frameCount) {
+ continue;
+ }
- seqFrame -= seq.loopFrameCount;
+ seqFrame -= seq.loopFrameCount;
- if ((seqFrame >= 0) && (seqFrame < seq.frameCount)) {
- continue;
- }
+ if ((seqFrame >= 0) && (seqFrame < seq.frameCount)) {
+ continue;
+ }
- seq = null;
- break;
- }
- seqCycle = Game.loopCycle - delta;
+ seq = null;
+ break;
+ }
+ seqCycle = Game.loopCycle - delta;
- if (seq != null) {
- transformID = seq.transformIDs[seqFrame];
- }
- }
+ if (seq != null) {
+ transformID = seq.transformIDs[seqFrame];
+ }
+ }
- LocType type;
+ LocType type;
- if (overrideTypeIDs != null) {
- type = getOverrideType();
- } else {
- type = LocType.get(id);
- }
+ if (overrideTypeIDs != null) {
+ type = getOverrideType();
+ } else {
+ type = LocType.get(id);
+ }
- if (type == null) {
- return null;
- } else {
- return type.getModel(kind, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, transformID);
- }
- }
+ if (type == null) {
+ return null;
+ } else {
+ return type.getModel(kind, rotation, heightmapSW, heightmapSE, heightmapNE, heightmapNW, transformID);
+ }
+ }
- public LocType getOverrideType() {
- int value = -1;
+ 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];
- }
+ 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 LocType.get(overrideTypeIDs[value]);
- }
- }
+ if ((value < 0) || (value >= overrideTypeIDs.length) || (overrideTypeIDs[value] == -1)) {
+ return null;
+ } else {
+ return LocType.get(overrideTypeIDs[value]);
+ }
+ }
}
diff --git a/src/main/java/LocType.java b/src/main/java/LocType.java
index a1ac908..d140d3f 100644
--- a/src/main/java/LocType.java
+++ b/src/main/java/LocType.java
@@ -8,552 +8,552 @@ import java.io.IOException;
public class LocType {
- 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 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 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 LRUMapdynamic 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[] options;
+ public static void unload() {
+ modelCacheStatic = null;
+ modelCacheDynamic = null;
+ offsets = null;
+ cache = null;
+ dat = null;
+ }
- public LocType() {
+ 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();
}
-
- 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;
- options = 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;
+ cache = new LocType[20];
+ for (int i = 0; i < 20; i++) {
+ cache[i] = new LocType();
}
+ }
- public void prefetch(OnDemand onDemand) {
- if (modelIDs == null) {
- return;
- }
- for (int modelID : modelIDs) {
- onDemand.prefetch(modelID & 0xffff, 0);
- }
+ 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[] options;
+
+ 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;
+ decorOffset = 16;
+ lightAmbient = 0;
+ lightAttenuation = 0;
+ options = 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;
}
-
- 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);
- }
- }
- return true;
+ for (int modelID : modelIDs) {
+ onDemand.prefetch(modelID & 0xffff, 0);
}
+ }
- 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;
- }
- model.calculateBoundsY();
- }
- return model;
- }
-
- public boolean validate() {
+ public boolean validate(int kind) {
+ if (modelKinds == null) {
if (modelIDs == null) {
return true;
}
- boolean ok = true;
+ if (kind != 10) {
+ return true;
+ }
+ boolean valid = true;
for (int modelID : modelIDs) {
- ok &= Model.validate(modelID & 0xffff);
+ valid &= Model.validate(modelID & 0xffff);
}
- return ok;
+ return valid;
+ }
+ for (int i = 0; i < modelKinds.length; i++) {
+ if (modelKinds[i] == kind) {
+ return Model.validate(modelIDs[i] & 0xffff);
+ }
+ }
+ 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;
}
- public LocType getOverrideType() {
- int value = -1;
+ if (adjustToTerrain || dynamic) {
+ model = new Model(adjustToTerrain, dynamic, model);
+ }
- 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 (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;
+ }
- if ((value < 0) || (value >= overrideTypeIDs.length) || (overrideTypeIDs[value] == -1)) {
+ 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;
+
+ 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) {
return null;
- } else {
- return get(overrideTypeIDs[value]);
}
- }
- public Model getModel(int kind, int transformID, int rotation) {
- Model model = null;
- long bitset;
+ bitset = ((long) index << 6) + rotation + ((long) (transformID + 1) << 32);
+ Model cached = modelCacheDynamic.get(bitset);
- if (modelKinds == null) {
- if (kind != 10) {
- return null;
- }
+ if (cached != null) {
+ return cached;
+ }
- bitset = ((long) index << 6) + rotation + ((long) (transformID + 1) << 32);
- Model cached = modelCacheDynamic.get(bitset);
+ if (modelIDs == null) {
+ return null;
+ }
- if (cached != null) {
- return cached;
- }
+ boolean flip = invert ^ (rotation > 3);
+ int modelCount = modelIDs.length;
- 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);
+ 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);
}
- }
- 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) {
+ TMP_MODELS[i] = model;
}
}
- if (scaled) {
- modified.scale(scaleX, scaleY, scaleZ);
+ 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 (translated) {
- modified.translate(translateX, translateY, translateZ);
+ if (kindIndex == -1) {
+ return null;
}
- modified.calculateNormals(64 + lightAmbient, 768 + (lightAttenuation * 5), -50, -10, -50, !dynamic);
+ bitset = ((long) this.index << 6) + ((long) kindIndex << 3) + rotation + ((long) (transformID + 1) << 32);
- if (supportsObj == 1) {
- modified.objRaise = modified.minY;
+ Model cached = modelCacheDynamic.get(bitset);
+
+ if (cached != null) {
+ return cached;
}
- modelCacheDynamic.put(bitset, modified);
- return modified;
+ 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);
+ }
}
- public void method582(Buffer buffer) {
- int i = -1;
- label0:
+ 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;
do {
- 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;
+ 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 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 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 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 (options == null) {
- options = new String[5];
- }
- options[j - 30] = buffer.readString();
- if (options[j - 30].equalsIgnoreCase("hidden")) {
- options[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;
- }
- 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;
+ } 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 (options == null) {
+ options = new String[5];
+ }
+ options[j - 30] = buffer.readString();
+ if (options[j - 30].equalsIgnoreCase("hidden")) {
+ options[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();
}
- } while (true);
- if (i == -1) {
- interactable = (modelIDs != null) && ((modelKinds == null) || (modelKinds[0] == 10));
- if (options != null) {
- interactable = true;
+ 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;
}
}
- if (decorative) {
- solid = false;
- blocksProjectiles = false;
- }
- if (supportsObj == -1) {
- supportsObj = solid ? 1 : 0;
+ } while (true);
+ if (i == -1) {
+ interactable = (modelIDs != null) && ((modelKinds == null) || (modelKinds[0] == 10));
+ if (options != null) {
+ interactable = true;
}
}
+ if (decorative) {
+ solid = false;
+ blocksProjectiles = false;
+ }
+ if (supportsObj == -1) {
+ supportsObj = solid ? 1 : 0;
+ }
+ }
}
diff --git a/src/main/java/MapUtil.java b/src/main/java/MapUtil.java
index eded028..4f3961b 100644
--- a/src/main/java/MapUtil.java
+++ b/src/main/java/MapUtil.java
@@ -4,64 +4,64 @@
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 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 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 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;
- }
- }
+ 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/Model.java b/src/main/java/Model.java
index b5026ba..a2d2edf 100644
--- a/src/main/java/Model.java
+++ b/src/main/java/Model.java
@@ -4,2460 +4,2460 @@
public class Model extends Entity {
- public static final Model EMPTY = new Model();
-
- public static final int[] clippedX = new int[10];
- public static final int[] clippedY = new int[10];
- public static final int[] clippedColor = new int[10];
- public static final int[] pickedBitsets = new int[1000];
-
- public static int counter;
-
- public static int[] tmpVertexX = new int[2000];
- public static int[] tmpVertexY = new int[2000];
- public static int[] tmpVertexZ = new int[2000];
- public static int[] tmpFaceAlpha = new int[2000];
- public static Header[] headers;
- public static OnDemand ondemand;
- public static boolean[] faceClippedX = new boolean[4096];
- public static boolean[] faceNearClipped = new boolean[4096];
- public static int[] vertexScreenX = new int[4096];
- public static int[] vertexScreenY = new int[4096];
- public static int[] vertexScreenZ = new int[4096];
- public static int[] vertexViewSpaceX = new int[4096];
- public static int[] vertexViewSpaceY = new int[4096];
- public static int[] vertexViewSpaceZ = new int[4096];
-
- public static int[] tmpDepthFaceCount = new int[1500];
- public static int[][] tmpDepthFaces = new int[1500][512];
- public static int[] tmpPriorityFaceCount = new int[12];
- public static int[][] tmpPriorityFaces = new int[12][2000];
- public static int[] tmpPriority10FaceDepth = new int[2000];
- public static int[] tmpPriority11FaceDepth = new int[2000];
- public static int[] tmpPriorityDepthSum = new int[12];
- public static int baseX;
- public static int baseY;
- public static int baseZ;
- public static boolean checkHover;
- public static int mouseX;
- public static int mouseY;
- public static int pickedCount;
- public static int[] sin = Draw3D.sin;
- public static int[] cos = Draw3D.cos;
- public static int[] palette = Draw3D.palette;
- public static int[] reciprical16 = Draw3D.reciprocal16;
-
- public static final class Header {
- public byte[] data;
- public int vertexCount;
- public int faceCount;
- public int texturedFaceCount;
- public int vertexFlagsOffset;
- public int vertexXOffset;
- public int vertexYOffset;
- public int vertexZOffset;
- public int vertexLabelsOffset;
- public int faceVerticesOffset;
- public int faceOrientationsOffset;
- public int faceColorsOffset;
- public int faceInfosOffset;
- public int facePrioritiesOffset;
- public int faceAlphasOffset;
- public int faceLabelsOffset;
- public int faceTextureAxisOffset;
-
- }
-
- public static void unload() {
- headers = null;
- faceClippedX = null;
- faceNearClipped = null;
- vertexScreenX = null;
- vertexScreenY = null;
- vertexScreenZ = null;
- vertexViewSpaceX = null;
- vertexViewSpaceY = null;
- vertexViewSpaceZ = null;
- tmpDepthFaceCount = null;
- tmpDepthFaces = null;
- tmpPriorityFaceCount = null;
- tmpPriorityFaces = null;
- tmpPriority10FaceDepth = null;
- tmpPriority11FaceDepth = null;
- tmpPriorityDepthSum = null;
- sin = null;
- cos = null;
- palette = null;
- reciprical16 = null;
- }
-
- public static void init(int count, OnDemand ondemand) {
- headers = new Header[count];
- Model.ondemand = ondemand;
- }
-
- public static void unpack(byte[] src, int id) {
- if (src == null) {
- Header header = headers[id] = new Header();
- header.vertexCount = 0;
- header.faceCount = 0;
- header.texturedFaceCount = 0;
- return;
- }
- Buffer buffer = new Buffer(src);
- buffer.position = src.length - 18;
- Header header = headers[id] = new Header();
- header.data = src;
- header.vertexCount = buffer.read16U();
- header.faceCount = buffer.read16U();
- header.texturedFaceCount = buffer.read8U();
-
- int hasInfo = buffer.read8U();
- int priority = buffer.read8U();
- int hasAlpha = buffer.read8U();
- int hasFaceLabels = buffer.read8U();
- int hasVertexLabels = buffer.read8U();
-
- int dataLengthX = buffer.read16U();
- int dataLengthY = buffer.read16U();
- int dataLengthZ = buffer.read16U();
- int dataLengthFaceOrientations = buffer.read16U();
-
- int offset = 0;
- header.vertexFlagsOffset = offset;
- offset += header.vertexCount;
-
- header.faceOrientationsOffset = offset;
- offset += header.faceCount;
-
- header.facePrioritiesOffset = offset;
- if (priority == 255) {
- offset += header.faceCount;
- } else {
- header.facePrioritiesOffset = -priority - 1;
- }
-
- header.faceLabelsOffset = offset;
- if (hasFaceLabels == 1) {
- offset += header.faceCount;
- } else {
- header.faceLabelsOffset = -1;
- }
-
- header.faceInfosOffset = offset;
- if (hasInfo == 1) {
- offset += header.faceCount;
- } else {
- header.faceInfosOffset = -1;
- }
-
- header.vertexLabelsOffset = offset;
- if (hasVertexLabels == 1) {
- offset += header.vertexCount;
- } else {
- header.vertexLabelsOffset = -1;
- }
-
- header.faceAlphasOffset = offset;
- if (hasAlpha == 1) {
- offset += header.faceCount;
- } else {
- header.faceAlphasOffset = -1;
- }
-
- header.faceVerticesOffset = offset;
- offset += dataLengthFaceOrientations;
-
- header.faceColorsOffset = offset;
- offset += header.faceCount * 2;
-
- header.faceTextureAxisOffset = offset;
- offset += header.texturedFaceCount * 6;
-
- header.vertexXOffset = offset;
- offset += dataLengthX;
- header.vertexYOffset = offset;
- offset += dataLengthY;
- header.vertexZOffset = offset;
- offset += dataLengthZ;
- }
-
- public static void unload(int id) {
- headers[id] = null;
- }
-
- /**
- * Tries to get the model. Sends a request to the ondemand service to load the model if it isn't loaded.
- *
- * @param id the model id.
- * @return the model, or null if not loaded.
- */
- public static Model tryGet(int id) {
- if (headers == null) {
- return null;
- }
-
- Header header = headers[id];
-
- if (header != null) {
- return new Model(id);
- } else {
- ondemand.requestModel(id);
- return null;
- }
- }
-
- /**
- * Validates the provided model id. If the model is not loaded then a request is sent to the ondemand service.
- *
- * @param id the model id.
- * @return true if the model is loaded.
- */
- public static boolean validate(int id) {
- if (headers == null) {
- return false;
- }
-
- Header header = headers[id];
-
- if (header != null) {
- return true;
- } else {
- ondemand.requestModel(id);
- return false;
- }
- }
-
- /**
- * Utility function. Multiplies the input HSL lightness component by the provided scalar.
- *
- * @param hsl the color value.
- * @param scalar the scalar. [0...127]
- * @param faceInfo Provided face info to determine the type of color to return. Textured triangles (type 2) only have
- * a lightness component.
- * @return the color.
- * @see #palette
- */
- public static int mulColorLightness(int hsl, int scalar, int faceInfo) {
- if ((faceInfo & 2) == 2) {
- if (scalar < 0) {
- scalar = 0;
- } else if (scalar > 127) {
- scalar = 127;
- }
- scalar = 127 - scalar;
- return scalar;
- }
- scalar = (scalar * (hsl & 0x7f)) >> 7;
- if (scalar < 2) {
- scalar = 2;
- } else if (scalar > 126) {
- scalar = 126;
- }
- return (hsl & 0xff80) + scalar;
- }
-
- public int vertexCount;
- public int[] vertexX;
- public int[] vertexY;
- public int[] vertexZ;
- public int faceCount;
- public int[] faceVertexA;
- public int[] faceVertexB;
- public int[] faceVertexC;
- public int[] faceColorA;
- public int[] faceColorB;
- public int[] faceColorC;
- public int[] faceInfo;
- public int[] facePriority;
- public int[] faceAlpha;
- public int[] faceColor;
- public int priority;
- public int texturedFaceCount;
- public int[] texturedVertexA;
- public int[] texturedVertexB;
- public int[] texturedVertexC;
- public int minX;
- public int maxX;
- public int maxY;
- public int minZ;
- public int maxZ;
- /**
- * The radius of this model on the XZ plane.
- *
- * @see #calculateBoundsAABB()
- */
- public int radius;
- public int minDepth;
- public int maxDepth;
- /**
- * minDepth = (int) Math.sqrt((radius * radius) + (super.minY * super.minY));
- * maxDepth = minDepth + (int) Math.sqrt((radius * radius) + (maxY * maxY));
- */
- public int objRaise;
- /**
- * The label the vertex belongs to.
- */
- public int[] vertexLabel;
- /**
- * The label the face belongs to.
- */
- public int[] faceLabel;
- /**
- * A lookup table for label->vertex.
- */
- public int[][] labelVertices;
- /**
- * A lookup table for label->face.
- */
- public int[][] labelFaces;
- /**
- * When set to true, this model will be picked based on its projected screen bounds.
- *
- * @see #draw(int, int, int, int, int, int, int, int, int)
- */
- public boolean pickable = false;
- /**
- * A storage for the original vertex normals to give {@link Scene#mergeNormals(Model, Model, int, int, int, boolean)}
- * a reference.
- */
- public VertexNormal[] vertexNormalOriginal;
-
- /**
- * Constructs an empty model.
- */
- public Model() {
- }
-
- /**
- * Constructs a new model and loads it from its header.
- *
- * Note: This constructor only works if the model has already been loaded. {@link #unpack(byte[], int)} must
- * have already been called for the given id.
- *
- * @param id the model id.
- */
- public Model(int id) {
- counter++;
-
- Header header = headers[id];
- vertexCount = header.vertexCount;
- faceCount = header.faceCount;
- texturedFaceCount = header.texturedFaceCount;
- vertexX = new int[vertexCount];
- vertexY = new int[vertexCount];
- vertexZ = new int[vertexCount];
- faceVertexA = new int[faceCount];
- faceVertexB = new int[faceCount];
- faceVertexC = new int[faceCount];
- texturedVertexA = new int[texturedFaceCount];
- texturedVertexB = new int[texturedFaceCount];
- texturedVertexC = new int[texturedFaceCount];
-
- if (header.vertexLabelsOffset >= 0) {
- vertexLabel = new int[vertexCount];
- }
-
- if (header.faceInfosOffset >= 0) {
- faceInfo = new int[faceCount];
- }
-
- if (header.facePrioritiesOffset >= 0) {
- facePriority = new int[faceCount];
- } else {
- priority = -header.facePrioritiesOffset - 1;
- }
-
- if (header.faceAlphasOffset >= 0) {
- faceAlpha = new int[faceCount];
- }
-
- if (header.faceLabelsOffset >= 0) {
- faceLabel = new int[faceCount];
- }
-
- faceColor = new int[faceCount];
-
- Buffer buf0 = new Buffer(header.data);
- buf0.position = header.vertexFlagsOffset;
-
- Buffer buf1 = new Buffer(header.data);
- buf1.position = header.vertexXOffset;
-
- Buffer buf2 = new Buffer(header.data);
- buf2.position = header.vertexYOffset;
-
- Buffer buf3 = new Buffer(header.data);
- buf3.position = header.vertexZOffset;
-
- Buffer buf4 = new Buffer(header.data);
- buf4.position = header.vertexLabelsOffset;
-
- int x = 0;
- int y = 0;
- int z = 0;
-
- for (int v = 0; v < vertexCount; v++) {
- int flags = buf0.read8U();
-
- int dx = 0;
- int dy = 0;
- int dz = 0;
-
- if ((flags & 1) != 0) {
- dx = buf1.readSmart();
- }
-
- if ((flags & 2) != 0) {
- dy = buf2.readSmart();
- }
-
- if ((flags & 4) != 0) {
- dz = buf3.readSmart();
- }
-
- vertexX[v] = x + dx;
- vertexY[v] = y + dy;
- vertexZ[v] = z + dz;
-
- x = vertexX[v];
- y = vertexY[v];
- z = vertexZ[v];
-
- if (vertexLabel != null) {
- vertexLabel[v] = buf4.read8U();
- }
- }
-
- buf0.position = header.faceColorsOffset;
- buf1.position = header.faceInfosOffset;
- buf2.position = header.facePrioritiesOffset;
- buf3.position = header.faceAlphasOffset;
- buf4.position = header.faceLabelsOffset;
-
- for (int face = 0; face < faceCount; face++) {
- faceColor[face] = buf0.read16U();
-
- if (faceInfo != null) {
- faceInfo[face] = buf1.read8U();
- }
-
- if (facePriority != null) {
- facePriority[face] = buf2.read8U();
- }
-
- if (faceAlpha != null) {
- faceAlpha[face] = buf3.read8U();
- }
-
- if (faceLabel != null) {
- faceLabel[face] = buf4.read8U();
- }
- }
-
- buf0.position = header.faceVerticesOffset;
- buf1.position = header.faceOrientationsOffset;
-
- int a = 0;
- int b = 0;
- int c = 0;
- int last = 0;
-
- for (int face = 0; face < faceCount; face++) {
- int orientation = buf1.read8U();
-
- // fancy shmansy compression type stuff.
- // vertex indices stored as deltas, with some faces
- // sharing indices.
-
- // new a, b, c
- if (orientation == 1) {
- a = buf0.readSmart() + last;
- last = a;
- b = buf0.readSmart() + last;
- last = b;
- c = buf0.readSmart() + last;
- last = c;
- faceVertexA[face] = a;
- faceVertexB[face] = b;
- faceVertexC[face] = c;
- }
-
- // reuse a, c, new b
- if (orientation == 2) {
- b = c;
- c = buf0.readSmart() + last;
- last = c;
- faceVertexA[face] = a;
- faceVertexB[face] = b;
- faceVertexC[face] = c;
- }
-
- // reuse c, b, new a
- if (orientation == 3) {
- a = c;
- c = buf0.readSmart() + last;
- last = c;
- faceVertexA[face] = a;
- faceVertexB[face] = b;
- faceVertexC[face] = c;
- }
-
- // reuse b, a, new c
- if (orientation == 4) {
- int tmp = a;
- a = b;
- b = tmp;
- c = buf0.readSmart() + last;
- last = c;
- faceVertexA[face] = a;
- faceVertexB[face] = b;
- faceVertexC[face] = c;
- }
- }
-
- buf0.position = header.faceTextureAxisOffset;
-
- for (int face = 0; face < texturedFaceCount; face++) {
- texturedVertexA[face] = buf0.read16U();
- texturedVertexB[face] = buf0.read16U();
- texturedVertexC[face] = buf0.read16U();
- }
- }
-
- /**
- * Constructs a new model by merging the provided models. This constructor is used to combine models before
- * {@link SeqTransform}'s have been applied. Using this constructor implies all models merged are compatible with any
- * animations played on them.
- *
- * @param count the model count.
- * @param models the models to merge.
- */
- public Model(int count, Model[] models) {
- counter++;
-
- boolean copyInfo = false;
- boolean copyPriority = false;
- boolean copyAlpha = false;
- boolean copyLabels = false;
-
- vertexCount = 0;
- faceCount = 0;
- texturedFaceCount = 0;
- priority = -1;
-
- for (int i = 0; i < count; i++) {
- Model model = models[i];
-
- if (model == null) {
- continue;
- }
-
- vertexCount += model.vertexCount;
- faceCount += model.faceCount;
- texturedFaceCount += model.texturedFaceCount;
-
- copyInfo |= model.faceInfo != null;
-
- if (model.facePriority != null) {
- copyPriority = true;
- } else {
- if (priority == -1) {
- priority = model.priority;
- }
- if (priority != model.priority) {
- copyPriority = true;
- }
- }
-
- copyAlpha |= model.faceAlpha != null;
- copyLabels |= model.faceLabel != null;
- }
-
- vertexX = new int[vertexCount];
- vertexY = new int[vertexCount];
- vertexZ = new int[vertexCount];
- vertexLabel = new int[vertexCount];
- faceVertexA = new int[faceCount];
- faceVertexB = new int[faceCount];
- faceVertexC = new int[faceCount];
- texturedVertexA = new int[texturedFaceCount];
- texturedVertexB = new int[texturedFaceCount];
- texturedVertexC = new int[texturedFaceCount];
-
- if (copyInfo) {
- faceInfo = new int[faceCount];
- }
-
- if (copyPriority) {
- facePriority = new int[faceCount];
- }
-
- if (copyAlpha) {
- faceAlpha = new int[faceCount];
- }
-
- if (copyLabels) {
- faceLabel = new int[faceCount];
- }
-
- faceColor = new int[faceCount];
- vertexCount = 0;
- faceCount = 0;
- texturedFaceCount = 0;
-
- int tfaceCount = 0;
-
- for (int i = 0; i < count; i++) {
- Model model = models[i];
-
- if (model == null) {
- continue;
- }
-
- for (int face = 0; face < model.faceCount; face++) {
- if (copyInfo) {
- if (model.faceInfo == null) {
- faceInfo[faceCount] = 0;
- } else {
- int info = model.faceInfo[face];
-
- if ((info & 2) == 2) {
- info += tfaceCount << 2;
- }
-
- faceInfo[faceCount] = info;
- }
- }
-
- if (copyPriority) {
- if (model.facePriority == null) {
- facePriority[faceCount] = model.priority;
- } else {
- facePriority[faceCount] = model.facePriority[face];
- }
- }
-
- if (copyAlpha) {
- if (model.faceAlpha == null) {
- faceAlpha[faceCount] = 0;
- } else {
- faceAlpha[faceCount] = model.faceAlpha[face];
- }
- }
-
- if (copyLabels && (model.faceLabel != null)) {
- faceLabel[faceCount] = model.faceLabel[face];
- }
-
- faceColor[faceCount] = model.faceColor[face];
- faceVertexA[faceCount] = addVertex(model, model.faceVertexA[face]);
- faceVertexB[faceCount] = addVertex(model, model.faceVertexB[face]);
- faceVertexC[faceCount] = addVertex(model, model.faceVertexC[face]);
- faceCount++;
- }
-
- for (int tface = 0; tface < model.texturedFaceCount; tface++) {
- texturedVertexA[texturedFaceCount] = addVertex(model, model.texturedVertexA[tface]);
- texturedVertexB[texturedFaceCount] = addVertex(model, model.texturedVertexB[tface]);
- texturedVertexC[texturedFaceCount] = addVertex(model, model.texturedVertexC[tface]);
- texturedFaceCount++;
- }
-
- tfaceCount += model.texturedFaceCount;
- }
- }
-
- /**
- * Constructs a new model by combining models. This constructor is commonly used to combine models which have already
- * had a {@link SeqTransform} applied, and does not copy label information.
- *
- * @param count the model count.
- * @param dummy dummy.
- * @param models the models.
- */
- public Model(int count, int dummy, Model[] models) {
- counter++;
-
- boolean copyInfo = false;
- boolean copyPriority = false;
- boolean copyAlpha = false;
- boolean copyColor = false;
-
- vertexCount = 0;
- faceCount = 0;
- texturedFaceCount = 0;
- priority = -1;
-
- for (int i = 0; i < count; i++) {
- Model model = models[i];
-
- if (model == null) {
- continue;
- }
-
- vertexCount += model.vertexCount;
- faceCount += model.faceCount;
- texturedFaceCount += model.texturedFaceCount;
- copyInfo |= model.faceInfo != null;
-
- if (model.facePriority != null) {
- copyPriority = true;
- } else {
- if (priority == -1) {
- priority = model.priority;
- }
- if (priority != model.priority) {
- copyPriority = true;
- }
- }
-
- copyAlpha |= model.faceAlpha != null;
- copyColor |= model.faceColor != null;
- }
-
- vertexX = new int[vertexCount];
- vertexY = new int[vertexCount];
- vertexZ = new int[vertexCount];
- faceVertexA = new int[faceCount];
- faceVertexB = new int[faceCount];
- faceVertexC = new int[faceCount];
- faceColorA = new int[faceCount];
- faceColorB = new int[faceCount];
- faceColorC = new int[faceCount];
- texturedVertexA = new int[texturedFaceCount];
- texturedVertexB = new int[texturedFaceCount];
- texturedVertexC = new int[texturedFaceCount];
-
- if (copyInfo) {
- faceInfo = new int[faceCount];
- }
-
- if (copyPriority) {
- facePriority = new int[faceCount];
- }
-
- if (copyAlpha) {
- faceAlpha = new int[faceCount];
- }
-
- if (copyColor) {
- faceColor = new int[faceCount];
- }
-
- vertexCount = 0;
- faceCount = 0;
- texturedFaceCount = 0;
-
- int tfaceCount = 0;
- for (int i = 0; i < count; i++) {
- Model model = models[i];
-
- if (model == null) {
- continue;
- }
-
- int vertexCount = this.vertexCount;
-
- for (int v = 0; v < model.vertexCount; v++) {
- vertexX[this.vertexCount] = model.vertexX[v];
- vertexY[this.vertexCount] = model.vertexY[v];
- vertexZ[this.vertexCount] = model.vertexZ[v];
- this.vertexCount++;
- }
-
- for (int f = 0; f < model.faceCount; f++) {
- faceVertexA[faceCount] = model.faceVertexA[f] + vertexCount;
- faceVertexB[faceCount] = model.faceVertexB[f] + vertexCount;
- faceVertexC[faceCount] = model.faceVertexC[f] + vertexCount;
-
- faceColorA[faceCount] = model.faceColorA[f];
- faceColorB[faceCount] = model.faceColorB[f];
- faceColorC[faceCount] = model.faceColorC[f];
-
- if (copyInfo) {
- if (model.faceInfo == null) {
- faceInfo[faceCount] = 0;
- } else {
- int info = model.faceInfo[f];
-
- if ((info & 2) == 2) {
- info += tfaceCount << 2;
- }
-
- faceInfo[faceCount] = info;
- }
- }
-
- if (copyPriority) {
- if (model.facePriority == null) {
- facePriority[faceCount] = model.priority;
- } else {
- facePriority[faceCount] = model.facePriority[f];
- }
- }
-
- if (copyAlpha) {
- if (model.faceAlpha == null) {
- faceAlpha[faceCount] = 0;
- } else {
- faceAlpha[faceCount] = model.faceAlpha[f];
- }
- }
-
- if (copyColor && (model.faceColor != null)) {
- faceColor[faceCount] = model.faceColor[f];
- }
- faceCount++;
- }
-
- for (int f = 0; f < model.texturedFaceCount; f++) {
- texturedVertexA[texturedFaceCount] = model.texturedVertexA[f] + vertexCount;
- texturedVertexB[texturedFaceCount] = model.texturedVertexB[f] + vertexCount;
- texturedVertexC[texturedFaceCount] = model.texturedVertexC[f] + vertexCount;
- texturedFaceCount++;
- }
-
- tfaceCount += model.texturedFaceCount;
- }
- calculateBoundsCylinder();
- }
-
- /**
- * Constructs a new model that can either share or clone the provided models attributes. This constructor is used to
- * save memory by avoiding allocations, and is meant to be used with models prior to having a {@link SeqTransform} applied.
- *
- * @param shareColors true to reference the provided model's colors.
- * @param shareAlpha true to reference the provided model's face alpha.
- * @param shareVertices true to reference the provided model's vertices.
- * @param model the model to share or clone.
- */
- public Model(boolean shareColors, boolean shareAlpha, boolean shareVertices, Model model) {
- counter++;
- vertexCount = model.vertexCount;
- faceCount = model.faceCount;
- texturedFaceCount = model.texturedFaceCount;
-
- if (shareVertices) {
- vertexX = model.vertexX;
- vertexY = model.vertexY;
- vertexZ = model.vertexZ;
- } else {
- vertexX = new int[vertexCount];
- vertexY = new int[vertexCount];
- vertexZ = new int[vertexCount];
-
- for (int j = 0; j < vertexCount; j++) {
- vertexX[j] = model.vertexX[j];
- vertexY[j] = model.vertexY[j];
- vertexZ[j] = model.vertexZ[j];
- }
- }
-
- if (shareColors) {
- faceColor = model.faceColor;
- } else {
- faceColor = new int[faceCount];
-
- for (int k = 0; k < faceCount; k++) {
- faceColor[k] = model.faceColor[k];
- }
- }
-
- if (shareAlpha) {
- faceAlpha = model.faceAlpha;
- } else {
- faceAlpha = new int[faceCount];
- if (model.faceAlpha == null) {
- for (int l = 0; l < faceCount; l++) {
- faceAlpha[l] = 0;
- }
- } else {
- for (int i1 = 0; i1 < faceCount; i1++) {
- faceAlpha[i1] = model.faceAlpha[i1];
- }
- }
- }
-
- vertexLabel = model.vertexLabel;
- faceLabel = model.faceLabel;
- faceInfo = model.faceInfo;
- faceVertexA = model.faceVertexA;
- faceVertexB = model.faceVertexB;
- faceVertexC = model.faceVertexC;
- facePriority = model.facePriority;
- priority = model.priority;
- texturedVertexA = model.texturedVertexA;
- texturedVertexB = model.texturedVertexB;
- texturedVertexC = model.texturedVertexC;
- }
-
- /**
- * Constructs a new model with the options to copy either vertex Y positions and faces.
- *
- * This constructor is specifically used by Locs which adjust to terrain.
- *
- * @param copyVertexY true to copy model.vertexY.
- * @param copyFaces true to copy all face data from model.
- * @param model the model to copy.
- * @see LocType#getModel(int, int, int, int, int, int, int)
- */
- public Model(boolean copyVertexY, boolean copyFaces, Model model) {
- counter++;
- vertexCount = model.vertexCount;
- faceCount = model.faceCount;
- texturedFaceCount = model.texturedFaceCount;
-
- if (copyVertexY) {
- vertexY = new int[vertexCount];
- for (int v = 0; v < vertexCount; v++) {
- vertexY[v] = model.vertexY[v];
- }
- } else {
- vertexY = model.vertexY;
- }
-
- if (copyFaces) {
- faceColorA = new int[faceCount];
- faceColorB = new int[faceCount];
- faceColorC = new int[faceCount];
-
- for (int k = 0; k < faceCount; k++) {
- faceColorA[k] = model.faceColorA[k];
- faceColorB[k] = model.faceColorB[k];
- faceColorC[k] = model.faceColorC[k];
- }
-
- faceInfo = new int[faceCount];
-
- if (model.faceInfo == null) {
- for (int l = 0; l < faceCount; l++) {
- faceInfo[l] = 0;
- }
- } else {
- for (int face = 0; face < faceCount; face++) {
- faceInfo[face] = model.faceInfo[face];
- }
- }
-
- super.vertexNormal = new VertexNormal[vertexCount];
- for (int v = 0; v < vertexCount; v++) {
- VertexNormal duplicate = super.vertexNormal[v] = new VertexNormal();
- VertexNormal original = model.vertexNormal[v];
- duplicate.x = original.x;
- duplicate.y = original.y;
- duplicate.z = original.z;
- duplicate.w = original.w;
- }
- vertexNormalOriginal = model.vertexNormalOriginal;
- } else {
- faceColorA = model.faceColorA;
- faceColorB = model.faceColorB;
- faceColorC = model.faceColorC;
- faceInfo = model.faceInfo;
- }
-
- vertexX = model.vertexX;
- vertexZ = model.vertexZ;
- faceColor = model.faceColor;
- faceAlpha = model.faceAlpha;
- facePriority = model.facePriority;
- priority = model.priority;
- faceVertexA = model.faceVertexA;
- faceVertexB = model.faceVertexB;
- faceVertexC = model.faceVertexC;
- texturedVertexA = model.texturedVertexA;
- texturedVertexB = model.texturedVertexB;
- texturedVertexC = model.texturedVertexC;
- super.minY = model.minY;
- maxY = model.maxY;
- radius = model.radius;
- minDepth = model.minDepth;
- maxDepth = model.maxDepth;
- minX = model.minX;
- maxZ = model.maxZ;
- minZ = model.minZ;
- maxX = model.maxX;
- }
-
- /**
- * Sets this model to the provided model using a vertex pool.
- *
- * Face alpha may be optionally copied in case an applied {@link SeqTransform} modifies the alpha of the model.
- *
- * @param model the model.
- * @param shareAlpha whether to copy or share a reference to face alphas.
- */
- public void set(Model model, boolean shareAlpha) {
- vertexCount = model.vertexCount;
- faceCount = model.faceCount;
- texturedFaceCount = model.texturedFaceCount;
-
- if (tmpVertexX.length < vertexCount) {
- tmpVertexX = new int[vertexCount + 100];
- tmpVertexY = new int[vertexCount + 100];
- tmpVertexZ = new int[vertexCount + 100];
- }
-
- vertexX = tmpVertexX;
- vertexY = tmpVertexY;
- vertexZ = tmpVertexZ;
-
- for (int k = 0; k < vertexCount; k++) {
- vertexX[k] = model.vertexX[k];
- vertexY[k] = model.vertexY[k];
- vertexZ[k] = model.vertexZ[k];
- }
-
- if (shareAlpha) {
- faceAlpha = model.faceAlpha;
- } else {
- if (tmpFaceAlpha.length < faceCount) {
- tmpFaceAlpha = new int[faceCount + 100];
- }
- faceAlpha = tmpFaceAlpha;
- if (model.faceAlpha == null) {
- for (int face = 0; face < faceCount; face++) {
- faceAlpha[face] = 0;
- }
- } else {
- for (int face = 0; face < faceCount; face++) {
- faceAlpha[face] = model.faceAlpha[face];
- }
- }
- }
-
- faceInfo = model.faceInfo;
- faceColor = model.faceColor;
- facePriority = model.facePriority;
- priority = model.priority;
- labelFaces = model.labelFaces;
- labelVertices = model.labelVertices;
- faceVertexA = model.faceVertexA;
- faceVertexB = model.faceVertexB;
- faceVertexC = model.faceVertexC;
- faceColorA = model.faceColorA;
- faceColorB = model.faceColorB;
- faceColorC = model.faceColorC;
- texturedVertexA = model.texturedVertexA;
- texturedVertexB = model.texturedVertexB;
- texturedVertexC = model.texturedVertexC;
- }
-
- /**
- * Adds vertexId from src to this. Reuses vertex if one already exists at the
- * same location.
- *
- * @param src the source model.
- * @param vertexId the vertex id to add from the src.
- * @return the vertex id of the added vertex.
- */
- public int addVertex(Model src, int vertexId) {
- int x = src.vertexX[vertexId];
- int y = src.vertexY[vertexId];
- int z = src.vertexZ[vertexId];
-
- int identical = -1;
- for (int v = 0; v < vertexCount; v++) {
- if ((x == vertexX[v]) && (y == vertexY[v]) && (z == vertexZ[v])) {
- identical = v;
- break;
- }
- }
-
- // append new one if no matches were found
- if (identical == -1) {
- vertexX[vertexCount] = x;
- vertexY[vertexCount] = y;
- vertexZ[vertexCount] = z;
- if (src.vertexLabel != null) {
- vertexLabel[vertexCount] = src.vertexLabel[vertexId];
- }
- identical = vertexCount++;
- }
-
- return identical;
- }
-
- /**
- * Calculates {@link #minY}, {@link #maxY}, {@link #radius}, {@link #minDepth} and {@link #maxDepth}.
- */
- public void calculateBoundsCylinder() {
- super.minY = 0;
- radius = 0;
- maxY = 0;
- for (int i = 0; i < vertexCount; i++) {
- int x = vertexX[i];
- int y = vertexY[i];
- int z = vertexZ[i];
- if (-y > super.minY) {
- super.minY = -y;
- }
- if (y > maxY) {
- maxY = y;
- }
- int radiusSqr = (x * x) + (z * z);
- if (radiusSqr > radius) {
- radius = radiusSqr;
- }
- }
- radius = (int) (Math.sqrt(radius) + 0.99);
- minDepth = (int) (Math.sqrt((radius * radius) + (super.minY * super.minY)) + 0.99);
- maxDepth = minDepth + (int) (Math.sqrt((radius * radius) + (maxY * maxY)) + 0.99);
- }
-
- /**
- * Calculates {@link #minY}, {@link #maxY}, {@link #minDepth} and {@link #maxDepth}.
- */
- public void calculateBoundsY() {
- super.minY = 0;
- maxY = 0;
- for (int i = 0; i < vertexCount; i++) {
- int y = vertexY[i];
- if (-y > super.minY) {
- super.minY = -y;
- }
- if (y > maxY) {
- maxY = y;
- }
- }
- minDepth = (int) (Math.sqrt((radius * radius) + (super.minY * super.minY)) + 0.99);
- maxDepth = minDepth + (int) (Math.sqrt((radius * radius) + (maxY * maxY)) + 0.99);
- }
-
- /**
- * Calculates this models axis-aligned bounding box (AABB) and stores it.
- */
- public void calculateBoundsAABB() {
- super.minY = 0;
- radius = 0;
- maxY = 0;
- minX = 999999;
- maxX = -999999;
- maxZ = -99999;
- minZ = 99999;
- for (int j = 0; j < vertexCount; j++) {
- int x = vertexX[j];
- int y = vertexY[j];
- int z = vertexZ[j];
- if (x < minX) {
- minX = x;
- }
- if (x > maxX) {
- maxX = x;
- }
- if (z < minZ) {
- minZ = z;
- }
- if (z > maxZ) {
- maxZ = z;
- }
- if (-y > super.minY) {
- super.minY = -y;
- }
- if (y > maxY) {
- maxY = y;
- }
- int radiusSqr = (x * x) + (z * z);
- if (radiusSqr > radius) {
- radius = radiusSqr;
- }
- }
- radius = (int) Math.sqrt(radius);
- minDepth = (int) Math.sqrt((radius * radius) + (super.minY * super.minY));
- maxDepth = minDepth + (int) Math.sqrt((radius * radius) + (maxY * maxY));
- }
-
- /**
- * Builds {@link #labelVertices} and {@link #labelFaces} using {@link #vertexLabel} and {@link #faceLabel}.
- *
- * This method is destructive, meaning it sets {@link #vertexLabel} and {@link #faceLabel} to null
- * after being called.
- *
- * This method is required for applying animations to a model and should only be called once on a single instance
- * of a {@link Model}.
- *
- * @see #applyTransform(int)
- * @see #applyTransforms(int, int, int[])
- * @see #applyTransform(int, int[], int, int, int)
- */
- public void createLabelReferences() {
- if (vertexLabel != null) {
- int[] labelVertexCount = new int[256];
-
- int count = 0;
- for (int v = 0; v < vertexCount; v++) {
- int label = vertexLabel[v];
- labelVertexCount[label]++;
- if (label > count) {
- count = label;
- }
- }
-
- labelVertices = new int[count + 1][];
-
- for (int label = 0; label <= count; label++) {
- labelVertices[label] = new int[labelVertexCount[label]];
- labelVertexCount[label] = 0;
- }
-
- for (int v = 0; v < vertexCount; v++) {
- int label = vertexLabel[v];
- labelVertices[label][labelVertexCount[label]++] = v;
- }
-
- vertexLabel = null;
- }
-
- if (faceLabel != null) {
- int[] labelFaceCount = new int[256];
-
- int count = 0;
- for (int f = 0; f < faceCount; f++) {
- int label = faceLabel[f];
- labelFaceCount[label]++;
- if (label > count) {
- count = label;
- }
- }
-
- labelFaces = new int[count + 1][];
- for (int label = 0; label <= count; label++) {
- labelFaces[label] = new int[labelFaceCount[label]];
- labelFaceCount[label] = 0;
- }
-
- for (int face = 0; face < faceCount; face++) {
- int label = faceLabel[face];
- labelFaces[label][labelFaceCount[label]++] = face;
- }
-
- faceLabel = null;
- }
- }
-
- /**
- * Applies a {@link SeqTransform} of the specified id.
- *
- * @param id the transform id.
- */
- public void applyTransform(int id) {
- if (labelVertices == null) {
- return;
- }
- if (id == -1) {
- return;
- }
- SeqTransform transform = SeqTransform.get(id);
- if (transform == null) {
- return;
- }
- SeqSkeleton skeleton = transform.skeleton;
- baseX = 0;
- baseY = 0;
- baseZ = 0;
- for (int i = 0; i < transform.length; i++) {
- int base = transform.bases[i];
- applyTransform(skeleton.baseTypes[base], skeleton.baseLabels[base], transform.x[i], transform.y[i], transform.z[i]);
- }
- }
-
- /**
- * Applies the specified {@link SeqTransform} ids.
- *
- * @param primaryID the primary transform id.
- * @param secondaryID the secondary transform id.
- * @param mask the mask contains base ids to prevent the primary transform from using the same bases as the secondary transform.
- */
- public void applyTransforms(int primaryID, int secondaryID, int[] mask) {
- if (primaryID == -1) {
- return;
- }
-
- if ((mask == null) || (secondaryID == -1)) {
- applyTransform(primaryID);
- return;
- }
-
- SeqTransform primary = SeqTransform.get(primaryID);
-
- if (primary == null) {
- return;
- }
-
- SeqTransform secondary = SeqTransform.get(secondaryID);
-
- if (secondary == null) {
- applyTransform(primaryID);
- return;
- }
-
- SeqSkeleton skeleton = primary.skeleton;
-
- baseX = 0;
- baseY = 0;
- baseZ = 0;
-
- int counter = 0;
- int maskBase = mask[counter++];
-
- for (int i = 0; i < primary.length; i++) {
- int base = primary.bases[i];
-
- while (base > maskBase) {
- maskBase = mask[counter++];
- }
-
- if ((base != maskBase) || (skeleton.baseTypes[base] == 0)) {
- applyTransform(skeleton.baseTypes[base], skeleton.baseLabels[base], primary.x[i], primary.y[i], primary.z[i]);
- }
- }
-
- baseX = 0;
- baseY = 0;
- baseZ = 0;
-
- counter = 0;
- maskBase = mask[counter++];
-
- for (int i = 0; i < secondary.length; i++) {
- int base = secondary.bases[i];
-
- while (base > maskBase) {
- maskBase = mask[counter++];
- }
-
- if ((base == maskBase) || (skeleton.baseTypes[base] == 0)) {
- applyTransform(skeleton.baseTypes[base], skeleton.baseLabels[base], secondary.x[i], secondary.y[i], secondary.z[i]);
- }
- }
- }
-
- /**
- * Applies a transform of the given type to the specified list of labels using the parameters
- * x, y, z.
- *
- * @param type the transform type.
- * @param labels the transform labels.
- * @param x the param x.
- * @param y the param y.
- * @param z the param z.
- * @see #applyTransforms(int, int, int[])
- * @see #applyTransform(int)
- * @see SeqSkeleton#OP_BASE
- * @see SeqSkeleton#OP_TRANSLATE
- * @see SeqSkeleton#OP_ROTATE
- * @see SeqSkeleton#OP_SCALE
- * @see SeqSkeleton#OP_ALPHA
- */
- public void applyTransform(int type, int[] labels, int x, int y, int z) {
- switch (type) {
- case SeqSkeleton.OP_BASE:
- int count = 0;
- baseX = 0;
- baseY = 0;
- baseZ = 0;
- for (int label : labels) {
- if (label >= labelVertices.length) {
- continue;
- }
- int[] vertices = labelVertices[label];
- for (int v : vertices) {
- baseX += vertexX[v];
- baseY += vertexY[v];
- baseZ += vertexZ[v];
- count++;
- }
- }
- if (count > 0) {
- baseX = (baseX / count) + x;
- baseY = (baseY / count) + y;
- baseZ = (baseZ / count) + z;
- } else {
- baseX = x;
- baseY = y;
- baseZ = z;
- }
- break;
- case SeqSkeleton.OP_TRANSLATE:
- for (int group : labels) {
- if (group >= labelVertices.length) {
- continue;
- }
- int[] vertices = labelVertices[group];
- for (int v : vertices) {
- vertexX[v] += x;
- vertexY[v] += y;
- vertexZ[v] += z;
- }
- }
- break;
- case SeqSkeleton.OP_ROTATE:
- for (int label : labels) {
- if (label >= labelVertices.length) {
- continue;
- }
- int[] vertices = labelVertices[label];
- for (int v : vertices) {
- vertexX[v] -= baseX;
- vertexY[v] -= baseY;
- vertexZ[v] -= baseZ;
- int pitch = (x & 0xff) * 8;
- int yaw = (y & 0xff) * 8;
- int roll = (z & 0xff) * 8;
- if (roll != 0) {
- int sin = Model.sin[roll];
- int cos = Model.cos[roll];
- int x_ = ((vertexY[v] * sin) + (vertexX[v] * cos)) >> 16;
- vertexY[v] = ((vertexY[v] * cos) - (vertexX[v] * sin)) >> 16;
- vertexX[v] = x_;
- }
- if (pitch != 0) {
- int sin = Model.sin[pitch];
- int cos = Model.cos[pitch];
- int y_ = ((vertexY[v] * cos) - (vertexZ[v] * sin)) >> 16;
- vertexZ[v] = ((vertexY[v] * sin) + (vertexZ[v] * cos)) >> 16;
- vertexY[v] = y_;
- }
- if (yaw != 0) {
- int sin = Model.sin[yaw];
- int cos = Model.cos[yaw];
- int x_ = ((vertexZ[v] * sin) + (vertexX[v] * cos)) >> 16;
- vertexZ[v] = ((vertexZ[v] * cos) - (vertexX[v] * sin)) >> 16;
- vertexX[v] = x_;
- }
- vertexX[v] += baseX;
- vertexY[v] += baseY;
- vertexZ[v] += baseZ;
- }
- }
- break;
- case SeqSkeleton.OP_SCALE:
- for (int label : labels) {
- if (label >= labelVertices.length) {
- continue;
- }
- int[] vertices = labelVertices[label];
- for (int v : vertices) {
- vertexX[v] -= baseX;
- vertexY[v] -= baseY;
- vertexZ[v] -= baseZ;
- vertexX[v] = (vertexX[v] * x) / 128;
- vertexY[v] = (vertexY[v] * y) / 128;
- vertexZ[v] = (vertexZ[v] * z) / 128;
- vertexX[v] += baseX;
- vertexY[v] += baseY;
- vertexZ[v] += baseZ;
- }
- }
- break;
- case SeqSkeleton.OP_ALPHA:
- if ((labelFaces != null) && (faceAlpha != null)) {
- for (int label : labels) {
- if (label >= labelFaces.length) {
- continue;
- }
- int[] triangles = labelFaces[label];
- for (int t : triangles) {
- faceAlpha[t] += x * 8;
- if (faceAlpha[t] < 0) {
- faceAlpha[t] = 0;
- }
- if (faceAlpha[t] > 255) {
- faceAlpha[t] = 255;
- }
- }
- }
- }
- break;
- }
- }
-
- /**
- * Rotates clockwise on the Y axis by 90 degrees.
- */
- public void rotateY90() {
- for (int v = 0; v < vertexCount; v++) {
- int x_ = vertexX[v];
- vertexX[v] = vertexZ[v];
- vertexZ[v] = -x_;
- }
- }
-
- /**
- * Rotates the model on the X/Pitch axis.
- *
- * @param angle the angle.
- */
- public void rotateX(int angle) {
- int sin = Model.sin[angle];
- int cos = Model.cos[angle];
- for (int v = 0; v < vertexCount; v++) {
- int y_ = ((vertexY[v] * cos) - (vertexZ[v] * sin)) >> 16;
- vertexZ[v] = ((vertexY[v] * sin) + (vertexZ[v] * cos)) >> 16;
- vertexY[v] = y_;
- }
- }
-
- /**
- * Translates the model by the offset provided.
- *
- * @param x the x.
- * @param y the y.
- * @param z the z.
- */
- public void translate(int x, int y, int z) {
- for (int v = 0; v < vertexCount; v++) {
- vertexX[v] += x;
- vertexY[v] += y;
- vertexZ[v] += z;
- }
- }
-
- /**
- * Replaces use of the color src with color dst.
- *
- * @param src the source texture id.
- * @param dst the destination texture id.
- */
- public void recolor(int src, int dst) {
- for (int k = 0; k < faceCount; k++) {
- if (faceColor[k] == src) {
- faceColor[k] = dst;
- }
- }
- }
-
- /**
- * Performs the equivalent operation of rotating the entire model on the Y axis by 180 degrees.
- */
- public void rotateY180() {
- for (int v = 0; v < vertexCount; v++) {
- vertexZ[v] = -vertexZ[v];
- }
- for (int f = 0; f < faceCount; f++) {
- int a = faceVertexA[f];
- faceVertexA[f] = faceVertexC[f];
- faceVertexC[f] = a;
- }
- }
-
- /**
- * Scales the model. This method assumes 25.7 fixed-point integers, which means the value 1.0 will be 1<<7
- * or 128.
- *
- * @param x the x scalar.
- * @param y the y scalar.
- * @param z the z scalar.
- */
- public void scale(int x, int y, int z) {
- for (int v = 0; v < vertexCount; v++) {
- vertexX[v] = (vertexX[v] * x) / 128;
- vertexY[v] = (vertexY[v] * z) / 128;
- vertexZ[v] = (vertexZ[v] * y) / 128;
- }
- }
-
- /**
- * Recalculates the normals and optionally applies the lighting immediately after. This method can be
- * destructive if applyLighting is set to true.
- *
- * @param lightAmbient the ambient light.
- * @param lightAttenuation the light attenuation.
- * @param lightSrcX the light source x.
- * @param lightSrcY the light source y.
- * @param lightSrcZ the light source z.
- * @param applyLighting true to invoke {@link #applyLighting(int, int, int, int, int)} after normals are
- * calculated.
- * @see #applyLighting(int, int, int, int, int)
- */
- public void calculateNormals(int lightAmbient, int lightAttenuation, int lightSrcX, int lightSrcY, int lightSrcZ, boolean applyLighting) {
- int lightMagnitude = (int) Math.sqrt((lightSrcX * lightSrcX) + (lightSrcY * lightSrcY) + (lightSrcZ * lightSrcZ));
- int attenuation = (lightAttenuation * lightMagnitude) >> 8;
-
- if (faceColorA == null) {
- faceColorA = new int[faceCount];
- faceColorB = new int[faceCount];
- faceColorC = new int[faceCount];
- }
-
- if (super.vertexNormal == null) {
- super.vertexNormal = new VertexNormal[vertexCount];
- for (int v = 0; v < vertexCount; v++) {
- super.vertexNormal[v] = new VertexNormal();
- }
- }
-
- for (int f = 0; f < faceCount; f++) {
- int a = faceVertexA[f];
- int b = faceVertexB[f];
- int c = faceVertexC[f];
-
- int dxAB = vertexX[b] - vertexX[a];
- int dyAB = vertexY[b] - vertexY[a];
- int dzAB = vertexZ[b] - vertexZ[a];
-
- int dxAC = vertexX[c] - vertexX[a];
- int dyAC = vertexY[c] - vertexY[a];
- int dzAC = vertexZ[c] - vertexZ[a];
-
- int nx = (dyAB * dzAC) - (dyAC * dzAB);
- int ny = (dzAB * dxAC) - (dzAC * dxAB);
- int nz = (dxAB * dyAC) - (dxAC * dyAB);
-
- while ((nx > 8192) || (ny > 8192) || (nz > 8192) || (nx < -8192) || (ny < -8192) || (nz < -8192)) {
- nx >>= 1;
- ny >>= 1;
- nz >>= 1;
- }
-
- int length = (int) Math.sqrt((nx * nx) + (ny * ny) + (nz * nz));
-
- if (length <= 0) {
- length = 1;
- }
-
- // normalize
- nx = (nx * 256) / length;
- ny = (ny * 256) / length;
- nz = (nz * 256) / length;
-
- if ((faceInfo == null) || ((faceInfo[f] & 1) == 0)) {
- VertexNormal n = super.vertexNormal[a];
- n.x += nx;
- n.y += ny;
- n.z += nz;
- n.w++;
- n = super.vertexNormal[b];
- n.x += nx;
- n.y += ny;
- n.z += nz;
- n.w++;
- n = super.vertexNormal[c];
- n.x += nx;
- n.y += ny;
- n.z += nz;
- n.w++;
- } else {
- int lightness = lightAmbient + (((lightSrcX * nx) + (lightSrcY * ny) + (lightSrcZ * nz)) / (attenuation + (attenuation / 2)));
- faceColorA[f] = mulColorLightness(faceColor[f], lightness, faceInfo[f]);
- }
- }
-
- if (applyLighting) {
- applyLighting(lightAmbient, attenuation, lightSrcX, lightSrcY, lightSrcZ);
- } else {
- vertexNormalOriginal = new VertexNormal[vertexCount];
-
- for (int v = 0; v < vertexCount; v++) {
- VertexNormal normal = super.vertexNormal[v];
- VertexNormal copy = vertexNormalOriginal[v] = new VertexNormal();
- copy.x = normal.x;
- copy.y = normal.y;
- copy.z = normal.z;
- copy.w = normal.w;
- }
- }
-
- if (applyLighting) {
- calculateBoundsCylinder();
- } else {
- calculateBoundsAABB();
- }
- }
-
- /**
- * Calculates the lightness values for all faces using the provided lighting parameters. This method is destructive
- * and nullifies normals and labels, which means it is meant to be applied once to a model.
- *
- * @param lightAmbient the ambient lighting value. [0...127]
- * @param lightAttenuation the light attenuation.
- * @param lightSrcX the light source x.
- * @param lightSrcY the light source y.
- * @param lightSrcZ the light source z.
- */
- public void applyLighting(int lightAmbient, int lightAttenuation, int lightSrcX, int lightSrcY, int lightSrcZ) {
- for (int f = 0; f < faceCount; f++) {
- int a = faceVertexA[f];
- int b = faceVertexB[f];
- int c = faceVertexC[f];
-
- if (faceInfo == null) {
- int color = faceColor[f];
-
- VertexNormal n = super.vertexNormal[a];
- int lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
- faceColorA[f] = mulColorLightness(color, lightness, 0);
-
- n = super.vertexNormal[b];
- lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
- faceColorB[f] = mulColorLightness(color, lightness, 0);
-
- n = super.vertexNormal[c];
- lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
- faceColorC[f] = mulColorLightness(color, lightness, 0);
- } else if ((faceInfo[f] & 1) == 0) {
- int color = faceColor[f];
- int info = faceInfo[f];
-
- VertexNormal n = super.vertexNormal[a];
- int lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
- faceColorA[f] = mulColorLightness(color, lightness, info);
-
- n = super.vertexNormal[b];
- lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
- faceColorB[f] = mulColorLightness(color, lightness, info);
-
- n = super.vertexNormal[c];
- lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
- faceColorC[f] = mulColorLightness(color, lightness, info);
- }
- }
-
- super.vertexNormal = null;
- vertexNormalOriginal = null;
- vertexLabel = null;
- faceLabel = null;
-
- if (faceInfo != null) {
- for (int f = 0; f < faceCount; f++) {
- if ((faceInfo[f] & 2) == 2) {
- return;
- }
- }
- }
-
- faceColor = null;
- }
-
- /**
- * Draws this model with reduced parameters.
- *
- * @param pitch the model pitch.
- * @param yaw the model yaw.
- * @param roll the model roll.
- * @param eyePitch the eye pitch.
- * @param eyeX the eye x.
- * @param eyeY the eye y.
- * @param eyeZ the eye z.
- */
- public void drawSimple(int pitch, int yaw, int roll, int eyePitch, int eyeX, int eyeY, int eyeZ) {
- int centerX = Draw3D.centerX;
- int centerY = Draw3D.centerY;
- int sinPitch = sin[pitch];
- int cosPitch = cos[pitch];
- int sinYaw = sin[yaw];
- int cosYaw = cos[yaw];
- int sinRoll = sin[roll];
- int cosRoll = cos[roll];
- int sinEyePitch = sin[eyePitch];
- int cosEyePitch = cos[eyePitch];
- int midZ = ((eyeY * sinEyePitch) + (eyeZ * cosEyePitch)) >> 16;
-
- for (int v = 0; v < vertexCount; v++) {
- int x = vertexX[v];
- int y = vertexY[v];
- int z = vertexZ[v];
-
- // Local Space -> Model Space
-
- if (roll != 0) {
- int x_ = ((y * sinRoll) + (x * cosRoll)) >> 16;
- y = ((y * cosRoll) - (x * sinRoll)) >> 16;
- x = x_;
- }
-
- if (pitch != 0) {
- int y_ = ((y * cosPitch) - (z * sinPitch)) >> 16;
- z = ((y * sinPitch) + (z * cosPitch)) >> 16;
- y = y_;
- }
-
- if (yaw != 0) {
- int x_ = ((z * sinYaw) + (x * cosYaw)) >> 16;
- z = ((z * cosYaw) - (x * sinYaw)) >> 16;
- x = x_;
- }
-
- // Model Space -> View Space
-
- x += eyeX;
- y += eyeY;
- z += eyeZ;
-
- int y_ = ((y * cosEyePitch) - (z * sinEyePitch)) >> 16;
- z = ((y * sinEyePitch) + (z * cosEyePitch)) >> 16;
- y = y_;
-
- // View Space -> Screen Space
-
- vertexScreenX[v] = centerX + ((x << 9) / z);
- vertexScreenY[v] = centerY + ((y << 9) / z);
- vertexScreenZ[v] = z - midZ;
-
- // Store viewspace coordinates to be transformed into screen space later (textured or clipped triangles)
-
- if (texturedFaceCount > 0) {
- vertexViewSpaceX[v] = x;
- vertexViewSpaceY[v] = y;
- vertexViewSpaceZ[v] = z;
- }
- }
- try {
- draw(false, false, 0);
- } catch (Exception ignored) {
- }
- }
-
- /**
- * Draws this model.
- *
- * @param yaw the yaw of this model.
- * @param sinEyePitch the sin(eyePitch).
- * @param cosEyePitch the cos(eyePitch).
- * @param sinEyeYaw the sin(eyeYaw).
- * @param cosEyeYaw the cos(eyeYaw).
- * @param relativeX the relative x. (SceneX - EyeX)
- * @param relativeY the relative y. (SceneY - EyeY)
- * @param relativeZ the relative z. (SceneZ - EyeZ)
- * @param bitset the bitset.
- */
- @Override
- public void draw(int yaw, int sinEyePitch, int cosEyePitch, int sinEyeYaw, int cosEyeYaw, int relativeX, int relativeY, int relativeZ, int bitset) {
- // Relative coordinates are ScenePos - EyePos
-
- // z' is our relative z value rotated by eye yaw.
- int zPrime = ((relativeZ * cosEyeYaw) - (relativeX * sinEyeYaw)) >> 16;
-
- // midZ is our relative z value rotated by eye yaw and pitch. It's the distance from the camera from the center
- // of our model.
- int midZ = ((relativeY * sinEyePitch) + (zPrime * cosEyePitch)) >> 16;
-
- // Our pitch is clamped between 128 and 384 (22.5 degrees and 67.5 degrees)
- // We know this will be positive and within 92->38% its original value.
- int radiusCosEyePitch = (radius * cosEyePitch) >> 16;
-
- // +Z goes forward, which makes this value supposedly the farthest Z the model should be away from the camera.
- int maxZ = midZ + radiusCosEyePitch;
-
- // early z testing
- if ((maxZ <= 50) || (midZ >= 3500)) {
- return;
- }
-
- // calculate x'
- int midX = ((relativeZ * sinEyeYaw) + (relativeX * cosEyeYaw)) >> 16;
-
- // calculate left bound
- int leftX = (midX - radius) << 9;
-
- // early fail
- if ((leftX / maxZ) >= Draw2D.centerX) {
- return;
- }
-
- // calculate right bound
- int rightX = (midX + radius) << 9;
-
- // early fail
- if ((rightX / maxZ) <= -Draw2D.centerX) {
- return;
- }
-
- // midY is our relative y value rotated by eye pitch
- int midY = ((relativeY * cosEyePitch) - (zPrime * sinEyePitch)) >> 16;
-
- // Our pitch is clamped between 128 and 384 (22.5 degrees and 67.5 degrees)
- // We know this will be positive and within 38->92% its original value.
- int radiusSinEyePitch = (radius * sinEyePitch) >> 16;
-
- // calculate bottom bound
- int bottomY = (midY + radiusSinEyePitch) << 9;
-
- // early fail
- if ((bottomY / maxZ) <= -Draw2D.centerY) {
- return;
- }
-
- // y' = (radius * sin(eyePitch)) + (minY * cos(eyePitch))
- int yPrime = radiusSinEyePitch + ((super.minY * cosEyePitch) >> 16);
-
- // calculate top boundary
- int topY = (midY - yPrime) << 9;
-
- // early fail
- if ((topY / maxZ) >= Draw2D.centerY) {
- return;
- }
-
- // (minY * sin(eyePitch)) + (radius * cos(eyePitch))
- int radiusZ = ((super.minY * sinEyePitch) >> 16) + radiusCosEyePitch;
-
- boolean clipped = (midZ - radiusZ) <= 50;
- boolean picking = false;
-
- if ((bitset > 0) && Model.checkHover) {
- int z = midZ - radiusCosEyePitch;
-
- if (z <= 50) {
- z = 50;
- }
-
- if (midX > 0) {
- leftX /= maxZ;
- rightX /= z;
- } else {
- rightX /= maxZ;
- leftX /= z;
- }
-
- if (midY > 0) {
- topY /= maxZ;
- bottomY /= z;
- } else {
- bottomY /= maxZ;
- topY /= z;
- }
-
- int mouseX = Model.mouseX - Draw3D.centerX;
- int mouseY = Model.mouseY - Draw3D.centerY;
-
- if ((mouseX > leftX) && (mouseX < rightX) && (mouseY > topY) && (mouseY < bottomY)) {
- if (pickable) {
- pickedBitsets[pickedCount++] = bitset;
- } else {
- picking = true;
- }
- }
- }
-
- int centerX = Draw3D.centerX;
- int centerY = Draw3D.centerY;
- int sinYaw = 0;
- int cosYaw = 0;
-
- if (yaw != 0) {
- sinYaw = sin[yaw];
- cosYaw = cos[yaw];
- }
-
- for (int v = 0; v < vertexCount; v++) {
- int x = vertexX[v];
- int y = vertexY[v];
- int z = vertexZ[v];
-
- // Local Space -> Model Space
-
- if (yaw != 0) {
- int x_ = ((z * sinYaw) + (x * cosYaw)) >> 16;
- z = ((z * cosYaw) - (x * sinYaw)) >> 16;
- x = x_;
- }
-
- // Model Space -> View Space
-
- x += relativeX;
- y += relativeY;
- z += relativeZ;
-
- // Rotate on Y axis (Yaw)
- int tmp = ((z * sinEyeYaw) + (x * cosEyeYaw)) >> 16;
- z = ((z * cosEyeYaw) - (x * sinEyeYaw)) >> 16;
- x = tmp;
-
- // Rotate on X axis (Pitch)
- tmp = ((y * cosEyePitch) - (z * sinEyePitch)) >> 16;
- z = ((y * sinEyePitch) + (z * cosEyePitch)) >> 16;
- y = tmp;
-
- if (z >= 50) {
- vertexScreenX[v] = centerX + ((x << 9) / z);
- vertexScreenY[v] = centerY + ((y << 9) / z);
- } else {
- vertexScreenX[v] = -5000; // used in drawTriangle to denote a near-clipped triangle.
- clipped = true;
- }
-
- vertexScreenZ[v] = z - midZ;
-
- if (clipped || (texturedFaceCount > 0)) {
- vertexViewSpaceX[v] = x;
- vertexViewSpaceY[v] = y;
- vertexViewSpaceZ[v] = z;
- }
- }
- try {
- draw(clipped, picking, bitset);
- } catch (Exception ignored) {
- }
- }
-
- /**
- * Draws the {@link Model} with the provided parameters. This method performs depth and priority sorting.
- *
- * @param clipped whether to check near plane clipping.
- * @param picking true to enable picking.
- * @param bitset the bitset. Used with pick set to true.
- */
- public void draw(boolean clipped, boolean picking, int bitset) {
- for (int depth = 0; depth < maxDepth; depth++) {
- tmpDepthFaceCount[depth] = 0;
- }
-
- for (int f = 0; f < faceCount; f++) {
- if ((faceInfo != null) && (faceInfo[f] == -1)) {
- continue;
- }
-
- int a = faceVertexA[f];
- int b = faceVertexB[f];
- int c = faceVertexC[f];
- int xA = vertexScreenX[a];
- int xB = vertexScreenX[b];
- int xC = vertexScreenX[c];
-
- if (clipped && ((xA == -5000) || (xB == -5000) || (xC == -5000))) {
- faceNearClipped[f] = true;
- int depthAverage = ((vertexScreenZ[a] + vertexScreenZ[b] + vertexScreenZ[c]) / 3) + minDepth;
- tmpDepthFaces[depthAverage][tmpDepthFaceCount[depthAverage]++] = f;
- } else {
- if (picking && pointWithinTriangle(mouseX, mouseY, vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], xA, xB, xC)) {
- pickedBitsets[pickedCount++] = bitset;
- picking = false;
- }
-
- // Back-face culling
- int dxAB = xA - xB;
- int dyAB = vertexScreenY[a] - vertexScreenY[b];
- int dxCB = xC - xB;
- int dyCB = vertexScreenY[c] - vertexScreenY[b];
-
- if (((dxAB * dyCB) - (dyAB * dxCB)) <= 0) {
- continue;
- }
-
- faceNearClipped[f] = false;
- faceClippedX[f] = (xA < 0) || (xB < 0) || (xC < 0) || (xA > Draw2D.boundX) || (xB > Draw2D.boundX) || (xC > Draw2D.boundX);
-
- int depthAverage = ((vertexScreenZ[a] + vertexScreenZ[b] + vertexScreenZ[c]) / 3) + minDepth;
- tmpDepthFaces[depthAverage][tmpDepthFaceCount[depthAverage]++] = f;
- }
- }
-
- if (facePriority == null) {
- for (int depth = maxDepth - 1; depth >= 0; depth--) {
- int count = tmpDepthFaceCount[depth];
- if (count > 0) {
- int[] faces = tmpDepthFaces[depth];
- for (int f = 0; f < count; f++) {
- drawFace(faces[f]);
- }
- }
- }
- return;
- }
-
- for (int priority = 0; priority < 12; priority++) {
- Model.tmpPriorityFaceCount[priority] = 0;
- tmpPriorityDepthSum[priority] = 0;
- }
-
- for (int depth = maxDepth - 1; depth >= 0; depth--) {
- int faceCount = tmpDepthFaceCount[depth];
-
- if (faceCount <= 0) {
- continue;
- }
-
- int[] faces = tmpDepthFaces[depth];
-
- for (int i = 0; i < faceCount; i++) {
- int face = faces[i];
- int priority = facePriority[face];
- int count = Model.tmpPriorityFaceCount[priority]++;
- Model.tmpPriorityFaces[priority][count] = face;
-
- if (priority < 10) {
- tmpPriorityDepthSum[priority] += depth;
- } else if (priority == 10) {
- tmpPriority10FaceDepth[count] = depth;
- } else {
- tmpPriority11FaceDepth[count] = depth;
- }
- }
- }
-
- // These are as the name implies, the average depth between two priorities.
- int averagePriorityDepth1_2 = 0;
- int averagePriorityDepth3_4 = 0;
- int averagePriorityDepth6_8 = 0;
-
- // Don't think too hard about it. It's just a way of calculating averages with integers but with two sums averaged together.
-
- if ((Model.tmpPriorityFaceCount[1] > 0) || (Model.tmpPriorityFaceCount[2] > 0)) {
- averagePriorityDepth1_2 = (tmpPriorityDepthSum[1] + tmpPriorityDepthSum[2]) / (Model.tmpPriorityFaceCount[1] + Model.tmpPriorityFaceCount[2]);
- }
-
- if ((Model.tmpPriorityFaceCount[3] > 0) || (Model.tmpPriorityFaceCount[4] > 0)) {
- averagePriorityDepth3_4 = (tmpPriorityDepthSum[3] + tmpPriorityDepthSum[4]) / (Model.tmpPriorityFaceCount[3] + Model.tmpPriorityFaceCount[4]);
- }
-
- if ((Model.tmpPriorityFaceCount[6] > 0) || (Model.tmpPriorityFaceCount[8] > 0)) {
- averagePriorityDepth6_8 = (tmpPriorityDepthSum[6] + tmpPriorityDepthSum[8]) / (Model.tmpPriorityFaceCount[6] + Model.tmpPriorityFaceCount[8]);
- }
-
- int priorityFace = 0;
- int priorityFaceCount = Model.tmpPriorityFaceCount[10];
- int[] priorityFaces = Model.tmpPriorityFaces[10];
- int[] priorityFaceDepths = tmpPriority10FaceDepth;
-
- if (priorityFace == priorityFaceCount) {
- priorityFace = 0;
- priorityFaceCount = Model.tmpPriorityFaceCount[11];
- priorityFaces = Model.tmpPriorityFaces[11];
- priorityFaceDepths = tmpPriority11FaceDepth;
- }
-
- int priorityDepth;
- if (priorityFace < priorityFaceCount) {
- priorityDepth = priorityFaceDepths[priorityFace];
- } else {
- priorityDepth = -1000;
- }
-
- // The code below essentially gives priorities 10 and 11 a chance to draw during priorities 0, 3, and 5 as long
- // as the current face depth is slightly deeper than the current priority depth. You can think of that slightly
- // deeper concept as a threshold to allow lower priority triangles to draw on top of higher priority triangles.
-
- // If they didn't do this then higher priority triangles would always draw on top, which look weird.
-
- for (int priority = 0; priority < 10; priority++) {
- while ((priority == 0) && (priorityDepth > averagePriorityDepth1_2)) {
- drawFace(priorityFaces[priorityFace++]);
-
- if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
- priorityFace = 0;
- priorityFaceCount = Model.tmpPriorityFaceCount[11];
- priorityFaces = Model.tmpPriorityFaces[11];
- priorityFaceDepths = tmpPriority11FaceDepth;
- }
-
- if (priorityFace < priorityFaceCount) {
- priorityDepth = priorityFaceDepths[priorityFace];
- } else {
- priorityDepth = -1000;
- }
- }
-
- while ((priority == 3) && (priorityDepth > averagePriorityDepth3_4)) {
- drawFace(priorityFaces[priorityFace++]);
-
- if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
- priorityFace = 0;
- priorityFaceCount = Model.tmpPriorityFaceCount[11];
- priorityFaces = Model.tmpPriorityFaces[11];
- priorityFaceDepths = tmpPriority11FaceDepth;
- }
-
- if (priorityFace < priorityFaceCount) {
- priorityDepth = priorityFaceDepths[priorityFace];
- } else {
- priorityDepth = -1000;
- }
- }
-
- while ((priority == 5) && (priorityDepth > averagePriorityDepth6_8)) {
- drawFace(priorityFaces[priorityFace++]);
-
- if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
- priorityFace = 0;
- priorityFaceCount = Model.tmpPriorityFaceCount[11];
- priorityFaces = Model.tmpPriorityFaces[11];
- priorityFaceDepths = tmpPriority11FaceDepth;
- }
-
- if (priorityFace < priorityFaceCount) {
- priorityDepth = priorityFaceDepths[priorityFace];
- } else {
- priorityDepth = -1000;
- }
- }
-
- int count = Model.tmpPriorityFaceCount[priority];
- int[] faces = Model.tmpPriorityFaces[priority];
-
- for (int i = 0; i < count; i++) {
- drawFace(faces[i]);
- }
- }
-
- // finish off remaining faces (priorities 10 and 11)
-
- while (priorityDepth != -1000) {
- drawFace(priorityFaces[priorityFace++]);
-
- if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
- priorityFace = 0;
- priorityFaces = Model.tmpPriorityFaces[11];
- priorityFaceCount = Model.tmpPriorityFaceCount[11];
- priorityFaceDepths = tmpPriority11FaceDepth;
- }
-
- if (priorityFace < priorityFaceCount) {
- priorityDepth = priorityFaceDepths[priorityFace];
- } else {
- priorityDepth = -1000;
- }
- }
- }
-
- /**
- * Draws the provided face id.
- *
- * @param face the face id.
- */
- public void drawFace(int face) {
- if (faceNearClipped[face]) {
- drawNearClippedFace(face);
- return;
- }
-
- int a = faceVertexA[face];
- int b = faceVertexB[face];
- int c = faceVertexC[face];
- Draw3D.clipX = faceClippedX[face];
-
- if (faceAlpha == null) {
- Draw3D.alpha = 0;
- } else {
- Draw3D.alpha = faceAlpha[face];
- }
-
- int type;
-
- if (faceInfo == null) {
- type = 0;
- } else {
- type = faceInfo[face] & 0b11;
- }
-
- if (type == 0) {
- Draw3D.fillGouraudTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], faceColorA[face], faceColorB[face], faceColorC[face]);
- } else if (type == 1) {
- Draw3D.fillTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], palette[faceColorA[face]]);
- } else if (type == 2) {
- int texturedFace = faceInfo[face] >> 2;
- int ta = texturedVertexA[texturedFace];
- int tb = texturedVertexB[texturedFace];
- int tc = texturedVertexC[texturedFace];
- Draw3D.fillTexturedTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], faceColorA[face], faceColorB[face], faceColorC[face], vertexViewSpaceX[ta], vertexViewSpaceX[tb], vertexViewSpaceX[tc], vertexViewSpaceY[ta], vertexViewSpaceY[tb], vertexViewSpaceY[tc], vertexViewSpaceZ[ta], vertexViewSpaceZ[tb], vertexViewSpaceZ[tc], faceColor[face]);
- } else if (type == 3) {
- int texturedFace = faceInfo[face] >> 2;
- int ta = texturedVertexA[texturedFace];
- int tb = texturedVertexB[texturedFace];
- int tc = texturedVertexC[texturedFace];
- Draw3D.fillTexturedTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[ta], vertexViewSpaceX[tb], vertexViewSpaceX[tc], vertexViewSpaceY[ta], vertexViewSpaceY[tb], vertexViewSpaceY[tc], vertexViewSpaceZ[ta], vertexViewSpaceZ[tb], vertexViewSpaceZ[tc], faceColor[face]);
- }
- }
-
- /**
- * Draws the provided face id assuming it has been clipped by the near Z plane.
- *
- * @param face the face id.
- */
- public void drawNearClippedFace(int face) {
- int centerX = Draw3D.centerX;
- int centerY = Draw3D.centerY;
- int elements = 0;
-
- int a = faceVertexA[face];
- int b = faceVertexB[face];
- int c = faceVertexC[face];
-
- int zA = vertexViewSpaceZ[a];
- int zB = vertexViewSpaceZ[b];
- int zC = vertexViewSpaceZ[c];
-
- if (zA >= 50) {
- clippedX[elements] = vertexScreenX[a];
- clippedY[elements] = vertexScreenY[a];
- clippedColor[elements++] = faceColorA[face];
- } else {
- int xA = vertexViewSpaceX[a];
- int yA = vertexViewSpaceY[a];
- int colorA = faceColorA[face];
-
- if (zC >= 50) {
- int scalar = (50 - zA) * reciprical16[zC - zA];
- clippedX[elements] = centerX + (((xA + (((vertexViewSpaceX[c] - xA) * scalar) >> 16)) << 9) / 50);
- clippedY[elements] = centerY + (((yA + (((vertexViewSpaceY[c] - yA) * scalar) >> 16)) << 9) / 50);
- clippedColor[elements++] = colorA + (((faceColorC[face] - colorA) * scalar) >> 16);
- }
-
- if (zB >= 50) {
- int scalar = (50 - zA) * reciprical16[zB - zA];
- clippedX[elements] = centerX + (((xA + (((vertexViewSpaceX[b] - xA) * scalar) >> 16)) << 9) / 50);
- clippedY[elements] = centerY + (((yA + (((vertexViewSpaceY[b] - yA) * scalar) >> 16)) << 9) / 50);
- clippedColor[elements++] = colorA + (((faceColorB[face] - colorA) * scalar) >> 16);
- }
- }
-
- if (zB >= 50) {
- clippedX[elements] = vertexScreenX[b];
- clippedY[elements] = vertexScreenY[b];
- clippedColor[elements++] = faceColorB[face];
- } else {
- int xB = vertexViewSpaceX[b];
- int yB = vertexViewSpaceY[b];
- int colorB = faceColorB[face];
-
- if (zA >= 50) {
- int scalar = (50 - zB) * reciprical16[zA - zB];
- clippedX[elements] = centerX + (((xB + (((vertexViewSpaceX[a] - xB) * scalar) >> 16)) << 9) / 50);
- clippedY[elements] = centerY + (((yB + (((vertexViewSpaceY[a] - yB) * scalar) >> 16)) << 9) / 50);
- clippedColor[elements++] = colorB + (((faceColorA[face] - colorB) * scalar) >> 16);
- }
-
- if (zC >= 50) {
- int scalar = (50 - zB) * reciprical16[zC - zB];
- clippedX[elements] = centerX + (((xB + (((vertexViewSpaceX[c] - xB) * scalar) >> 16)) << 9) / 50);
- clippedY[elements] = centerY + (((yB + (((vertexViewSpaceY[c] - yB) * scalar) >> 16)) << 9) / 50);
- clippedColor[elements++] = colorB + (((faceColorC[face] - colorB) * scalar) >> 16);
- }
- }
-
- if (zC >= 50) {
- clippedX[elements] = vertexScreenX[c];
- clippedY[elements] = vertexScreenY[c];
- clippedColor[elements++] = faceColorC[face];
- } else {
- int xC = vertexViewSpaceX[c];
- int yC = vertexViewSpaceY[c];
- int colorC = faceColorC[face];
-
- if (zB >= 50) {
- int k6 = (50 - zC) * reciprical16[zB - zC];
- clippedX[elements] = centerX + (((xC + (((vertexViewSpaceX[b] - xC) * k6) >> 16)) << 9) / 50);
- clippedY[elements] = centerY + (((yC + (((vertexViewSpaceY[b] - yC) * k6) >> 16)) << 9) / 50);
- clippedColor[elements++] = colorC + (((faceColorB[face] - colorC) * k6) >> 16);
- }
-
- if (zA >= 50) {
- int l6 = (50 - zC) * reciprical16[zA - zC];
- clippedX[elements] = centerX + (((xC + (((vertexViewSpaceX[a] - xC) * l6) >> 16)) << 9) / 50);
- clippedY[elements] = centerY + (((yC + (((vertexViewSpaceY[a] - yC) * l6) >> 16)) << 9) / 50);
- clippedColor[elements++] = colorC + (((faceColorA[face] - colorC) * l6) >> 16);
- }
- }
-
- int x0 = clippedX[0];
- int x1 = clippedX[1];
- int x2 = clippedX[2];
- int y0 = clippedY[0];
- int y1 = clippedY[1];
- int y2 = clippedY[2];
-
- // Back-face culling
- if ((((x0 - x1) * (y2 - y1)) - ((y0 - y1) * (x2 - x1))) <= 0) {
- return;
- }
-
- Draw3D.clipX = false;
-
- // It's possible for a single triangle to be clipped into two separate triangles.
-
- if (elements == 3) {
- if ((x0 < 0) || (x1 < 0) || (x2 < 0) || (x0 > Draw2D.boundX) || (x1 > Draw2D.boundX) || (x2 > Draw2D.boundX)) {
- Draw3D.clipX = true;
- }
-
- int type;
-
- if (faceInfo == null) {
- type = 0;
- } else {
- type = faceInfo[face] & 3;
- }
-
- if (type == 0) {
- Draw3D.fillGouraudTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2]);
- } else if (type == 1) {
- Draw3D.fillTriangle(y0, y1, y2, x0, x1, x2, palette[faceColorA[face]]);
- } else if (type == 2) {
- int texturedFace = faceInfo[face] >> 2;
- int tA = texturedVertexA[texturedFace];
- int tB = texturedVertexB[texturedFace];
- int tC = texturedVertexC[texturedFace];
- Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
- } else if (type == 3) {
- int texturedFace = faceInfo[face] >> 2;
- int tA = texturedVertexA[texturedFace];
- int tB = texturedVertexB[texturedFace];
- int tC = texturedVertexC[texturedFace];
- Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
- }
- } else if (elements == 4) {
- if ((x0 < 0) || (x1 < 0) || (x2 < 0) || (x0 > Draw2D.boundX) || (x1 > Draw2D.boundX) || (x2 > Draw2D.boundX) || (clippedX[3] < 0) || (clippedX[3] > Draw2D.boundX)) {
- Draw3D.clipX = true;
- }
-
- int type;
-
- if (faceInfo == null) {
- type = 0;
- } else {
- type = faceInfo[face] & 3;
- }
-
- if (type == 0) {
- Draw3D.fillGouraudTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2]);
- Draw3D.fillGouraudTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], clippedColor[0], clippedColor[2], clippedColor[3]);
- } else if (type == 1) {
- int colorA = palette[faceColorA[face]];
- Draw3D.fillTriangle(y0, y1, y2, x0, x1, x2, colorA);
- Draw3D.fillTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], colorA);
- } else if (type == 2) {
- int texturedFace = faceInfo[face] >> 2;
- int tA = texturedVertexA[texturedFace];
- int tB = texturedVertexB[texturedFace];
- int tC = texturedVertexC[texturedFace];
- Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
- Draw3D.fillTexturedTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], clippedColor[0], clippedColor[2], clippedColor[3], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
- } else if (type == 3) {
- int texturedFace = faceInfo[face] >> 2;
- int tA = texturedVertexA[texturedFace];
- int tB = texturedVertexB[texturedFace];
- int tC = texturedVertexC[texturedFace];
- Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
- Draw3D.fillTexturedTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
- }
- }
- }
-
- /**
- * Utility function. Checks if (x, y) is within the provided triangle.
- *
- * @param x the x.
- * @param y the y.
- * @param yA y of corner a.
- * @param yB y of corner b.
- * @param yC y of corner c.
- * @param xA x of corner a.
- * @param xB x of corner b.
- * @param xC x of corner c.
- * @return true if (x, y) is within the triangle.
- */
- public boolean pointWithinTriangle(int x, int y, int yA, int yB, int yC, int xA, int xB, int xC) {
- if ((y < yA) && (y < yB) && (y < yC)) {
- return false;
- }
- if ((y > yA) && (y > yB) && (y > yC)) {
- return false;
- }
- if ((x < xA) && (x < xB) && (x < xC)) {
- return false;
- }
- return (x <= xA) || (x <= xB) || (x <= xC);
- }
+ public static final Model EMPTY = new Model();
+
+ public static final int[] clippedX = new int[10];
+ public static final int[] clippedY = new int[10];
+ public static final int[] clippedColor = new int[10];
+ public static final int[] pickedBitsets = new int[1000];
+
+ public static int counter;
+
+ public static int[] tmpVertexX = new int[2000];
+ public static int[] tmpVertexY = new int[2000];
+ public static int[] tmpVertexZ = new int[2000];
+ public static int[] tmpFaceAlpha = new int[2000];
+ public static Header[] headers;
+ public static OnDemand ondemand;
+ public static boolean[] faceClippedX = new boolean[4096];
+ public static boolean[] faceNearClipped = new boolean[4096];
+ public static int[] vertexScreenX = new int[4096];
+ public static int[] vertexScreenY = new int[4096];
+ public static int[] vertexScreenZ = new int[4096];
+ public static int[] vertexViewSpaceX = new int[4096];
+ public static int[] vertexViewSpaceY = new int[4096];
+ public static int[] vertexViewSpaceZ = new int[4096];
+
+ public static int[] tmpDepthFaceCount = new int[1500];
+ public static int[][] tmpDepthFaces = new int[1500][512];
+ public static int[] tmpPriorityFaceCount = new int[12];
+ public static int[][] tmpPriorityFaces = new int[12][2000];
+ public static int[] tmpPriority10FaceDepth = new int[2000];
+ public static int[] tmpPriority11FaceDepth = new int[2000];
+ public static int[] tmpPriorityDepthSum = new int[12];
+ public static int baseX;
+ public static int baseY;
+ public static int baseZ;
+ public static boolean checkHover;
+ public static int mouseX;
+ public static int mouseY;
+ public static int pickedCount;
+ public static int[] sin = Draw3D.sin;
+ public static int[] cos = Draw3D.cos;
+ public static int[] palette = Draw3D.palette;
+ public static int[] reciprical16 = Draw3D.reciprocal16;
+
+ public static final class Header {
+ public byte[] data;
+ public int vertexCount;
+ public int faceCount;
+ public int texturedFaceCount;
+ public int vertexFlagsOffset;
+ public int vertexXOffset;
+ public int vertexYOffset;
+ public int vertexZOffset;
+ public int vertexLabelsOffset;
+ public int faceVerticesOffset;
+ public int faceOrientationsOffset;
+ public int faceColorsOffset;
+ public int faceInfosOffset;
+ public int facePrioritiesOffset;
+ public int faceAlphasOffset;
+ public int faceLabelsOffset;
+ public int faceTextureAxisOffset;
+
+ }
+
+ public static void unload() {
+ headers = null;
+ faceClippedX = null;
+ faceNearClipped = null;
+ vertexScreenX = null;
+ vertexScreenY = null;
+ vertexScreenZ = null;
+ vertexViewSpaceX = null;
+ vertexViewSpaceY = null;
+ vertexViewSpaceZ = null;
+ tmpDepthFaceCount = null;
+ tmpDepthFaces = null;
+ tmpPriorityFaceCount = null;
+ tmpPriorityFaces = null;
+ tmpPriority10FaceDepth = null;
+ tmpPriority11FaceDepth = null;
+ tmpPriorityDepthSum = null;
+ sin = null;
+ cos = null;
+ palette = null;
+ reciprical16 = null;
+ }
+
+ public static void init(int count, OnDemand ondemand) {
+ headers = new Header[count];
+ Model.ondemand = ondemand;
+ }
+
+ public static void unpack(byte[] src, int id) {
+ if (src == null) {
+ Header header = headers[id] = new Header();
+ header.vertexCount = 0;
+ header.faceCount = 0;
+ header.texturedFaceCount = 0;
+ return;
+ }
+ Buffer buffer = new Buffer(src);
+ buffer.position = src.length - 18;
+ Header header = headers[id] = new Header();
+ header.data = src;
+ header.vertexCount = buffer.read16U();
+ header.faceCount = buffer.read16U();
+ header.texturedFaceCount = buffer.read8U();
+
+ int hasInfo = buffer.read8U();
+ int priority = buffer.read8U();
+ int hasAlpha = buffer.read8U();
+ int hasFaceLabels = buffer.read8U();
+ int hasVertexLabels = buffer.read8U();
+
+ int dataLengthX = buffer.read16U();
+ int dataLengthY = buffer.read16U();
+ int dataLengthZ = buffer.read16U();
+ int dataLengthFaceOrientations = buffer.read16U();
+
+ int offset = 0;
+ header.vertexFlagsOffset = offset;
+ offset += header.vertexCount;
+
+ header.faceOrientationsOffset = offset;
+ offset += header.faceCount;
+
+ header.facePrioritiesOffset = offset;
+ if (priority == 255) {
+ offset += header.faceCount;
+ } else {
+ header.facePrioritiesOffset = -priority - 1;
+ }
+
+ header.faceLabelsOffset = offset;
+ if (hasFaceLabels == 1) {
+ offset += header.faceCount;
+ } else {
+ header.faceLabelsOffset = -1;
+ }
+
+ header.faceInfosOffset = offset;
+ if (hasInfo == 1) {
+ offset += header.faceCount;
+ } else {
+ header.faceInfosOffset = -1;
+ }
+
+ header.vertexLabelsOffset = offset;
+ if (hasVertexLabels == 1) {
+ offset += header.vertexCount;
+ } else {
+ header.vertexLabelsOffset = -1;
+ }
+
+ header.faceAlphasOffset = offset;
+ if (hasAlpha == 1) {
+ offset += header.faceCount;
+ } else {
+ header.faceAlphasOffset = -1;
+ }
+
+ header.faceVerticesOffset = offset;
+ offset += dataLengthFaceOrientations;
+
+ header.faceColorsOffset = offset;
+ offset += header.faceCount * 2;
+
+ header.faceTextureAxisOffset = offset;
+ offset += header.texturedFaceCount * 6;
+
+ header.vertexXOffset = offset;
+ offset += dataLengthX;
+ header.vertexYOffset = offset;
+ offset += dataLengthY;
+ header.vertexZOffset = offset;
+ offset += dataLengthZ;
+ }
+
+ public static void unload(int id) {
+ headers[id] = null;
+ }
+
+ /**
+ * Tries to get the model. Sends a request to the ondemand service to load the model if it isn't loaded.
+ *
+ * @param id the model id.
+ * @return the model, or null if not loaded.
+ */
+ public static Model tryGet(int id) {
+ if (headers == null) {
+ return null;
+ }
+
+ Header header = headers[id];
+
+ if (header != null) {
+ return new Model(id);
+ } else {
+ ondemand.requestModel(id);
+ return null;
+ }
+ }
+
+ /**
+ * Validates the provided model id. If the model is not loaded then a request is sent to the ondemand service.
+ *
+ * @param id the model id.
+ * @return true if the model is loaded.
+ */
+ public static boolean validate(int id) {
+ if (headers == null) {
+ return false;
+ }
+
+ Header header = headers[id];
+
+ if (header != null) {
+ return true;
+ } else {
+ ondemand.requestModel(id);
+ return false;
+ }
+ }
+
+ /**
+ * Utility function. Multiplies the input HSL lightness component by the provided scalar.
+ *
+ * @param hsl the color value.
+ * @param scalar the scalar. [0...127]
+ * @param faceInfo Provided face info to determine the type of color to return. Textured triangles (type 2) only have
+ * a lightness component.
+ * @return the color.
+ * @see #palette
+ */
+ public static int mulColorLightness(int hsl, int scalar, int faceInfo) {
+ if ((faceInfo & 2) == 2) {
+ if (scalar < 0) {
+ scalar = 0;
+ } else if (scalar > 127) {
+ scalar = 127;
+ }
+ scalar = 127 - scalar;
+ return scalar;
+ }
+ scalar = (scalar * (hsl & 0x7f)) >> 7;
+ if (scalar < 2) {
+ scalar = 2;
+ } else if (scalar > 126) {
+ scalar = 126;
+ }
+ return (hsl & 0xff80) + scalar;
+ }
+
+ public int vertexCount;
+ public int[] vertexX;
+ public int[] vertexY;
+ public int[] vertexZ;
+ public int faceCount;
+ public int[] faceVertexA;
+ public int[] faceVertexB;
+ public int[] faceVertexC;
+ public int[] faceColorA;
+ public int[] faceColorB;
+ public int[] faceColorC;
+ public int[] faceInfo;
+ public int[] facePriority;
+ public int[] faceAlpha;
+ public int[] faceColor;
+ public int priority;
+ public int texturedFaceCount;
+ public int[] texturedVertexA;
+ public int[] texturedVertexB;
+ public int[] texturedVertexC;
+ public int minX;
+ public int maxX;
+ public int maxY;
+ public int minZ;
+ public int maxZ;
+ /**
+ * The radius of this model on the XZ plane.
+ *
+ * @see #calculateBoundsAABB()
+ */
+ public int radius;
+ public int minDepth;
+ public int maxDepth;
+ /**
+ * minDepth = (int) Math.sqrt((radius * radius) + (super.minY * super.minY));
+ * maxDepth = minDepth + (int) Math.sqrt((radius * radius) + (maxY * maxY));
+ */
+ public int objRaise;
+ /**
+ * The label the vertex belongs to.
+ */
+ public int[] vertexLabel;
+ /**
+ * The label the face belongs to.
+ */
+ public int[] faceLabel;
+ /**
+ * A lookup table for label->vertex.
+ */
+ public int[][] labelVertices;
+ /**
+ * A lookup table for label->face.
+ */
+ public int[][] labelFaces;
+ /**
+ * When set to true, this model will be picked based on its projected screen bounds.
+ *
+ * @see #draw(int, int, int, int, int, int, int, int, int)
+ */
+ public boolean pickable = false;
+ /**
+ * A storage for the original vertex normals to give {@link Scene#mergeNormals(Model, Model, int, int, int, boolean)}
+ * a reference.
+ */
+ public VertexNormal[] vertexNormalOriginal;
+
+ /**
+ * Constructs an empty model.
+ */
+ public Model() {
+ }
+
+ /**
+ * Constructs a new model and loads it from its header.
+ *
+ * Note: This constructor only works if the model has already been loaded. {@link #unpack(byte[], int)} must
+ * have already been called for the given id.
+ *
+ * @param id the model id.
+ */
+ public Model(int id) {
+ counter++;
+
+ Header header = headers[id];
+ vertexCount = header.vertexCount;
+ faceCount = header.faceCount;
+ texturedFaceCount = header.texturedFaceCount;
+ vertexX = new int[vertexCount];
+ vertexY = new int[vertexCount];
+ vertexZ = new int[vertexCount];
+ faceVertexA = new int[faceCount];
+ faceVertexB = new int[faceCount];
+ faceVertexC = new int[faceCount];
+ texturedVertexA = new int[texturedFaceCount];
+ texturedVertexB = new int[texturedFaceCount];
+ texturedVertexC = new int[texturedFaceCount];
+
+ if (header.vertexLabelsOffset >= 0) {
+ vertexLabel = new int[vertexCount];
+ }
+
+ if (header.faceInfosOffset >= 0) {
+ faceInfo = new int[faceCount];
+ }
+
+ if (header.facePrioritiesOffset >= 0) {
+ facePriority = new int[faceCount];
+ } else {
+ priority = -header.facePrioritiesOffset - 1;
+ }
+
+ if (header.faceAlphasOffset >= 0) {
+ faceAlpha = new int[faceCount];
+ }
+
+ if (header.faceLabelsOffset >= 0) {
+ faceLabel = new int[faceCount];
+ }
+
+ faceColor = new int[faceCount];
+
+ Buffer buf0 = new Buffer(header.data);
+ buf0.position = header.vertexFlagsOffset;
+
+ Buffer buf1 = new Buffer(header.data);
+ buf1.position = header.vertexXOffset;
+
+ Buffer buf2 = new Buffer(header.data);
+ buf2.position = header.vertexYOffset;
+
+ Buffer buf3 = new Buffer(header.data);
+ buf3.position = header.vertexZOffset;
+
+ Buffer buf4 = new Buffer(header.data);
+ buf4.position = header.vertexLabelsOffset;
+
+ int x = 0;
+ int y = 0;
+ int z = 0;
+
+ for (int v = 0; v < vertexCount; v++) {
+ int flags = buf0.read8U();
+
+ int dx = 0;
+ int dy = 0;
+ int dz = 0;
+
+ if ((flags & 1) != 0) {
+ dx = buf1.readSmart();
+ }
+
+ if ((flags & 2) != 0) {
+ dy = buf2.readSmart();
+ }
+
+ if ((flags & 4) != 0) {
+ dz = buf3.readSmart();
+ }
+
+ vertexX[v] = x + dx;
+ vertexY[v] = y + dy;
+ vertexZ[v] = z + dz;
+
+ x = vertexX[v];
+ y = vertexY[v];
+ z = vertexZ[v];
+
+ if (vertexLabel != null) {
+ vertexLabel[v] = buf4.read8U();
+ }
+ }
+
+ buf0.position = header.faceColorsOffset;
+ buf1.position = header.faceInfosOffset;
+ buf2.position = header.facePrioritiesOffset;
+ buf3.position = header.faceAlphasOffset;
+ buf4.position = header.faceLabelsOffset;
+
+ for (int face = 0; face < faceCount; face++) {
+ faceColor[face] = buf0.read16U();
+
+ if (faceInfo != null) {
+ faceInfo[face] = buf1.read8U();
+ }
+
+ if (facePriority != null) {
+ facePriority[face] = buf2.read8U();
+ }
+
+ if (faceAlpha != null) {
+ faceAlpha[face] = buf3.read8U();
+ }
+
+ if (faceLabel != null) {
+ faceLabel[face] = buf4.read8U();
+ }
+ }
+
+ buf0.position = header.faceVerticesOffset;
+ buf1.position = header.faceOrientationsOffset;
+
+ int a = 0;
+ int b = 0;
+ int c = 0;
+ int last = 0;
+
+ for (int face = 0; face < faceCount; face++) {
+ int orientation = buf1.read8U();
+
+ // fancy shmansy compression type stuff.
+ // vertex indices stored as deltas, with some faces
+ // sharing indices.
+
+ // new a, b, c
+ if (orientation == 1) {
+ a = buf0.readSmart() + last;
+ last = a;
+ b = buf0.readSmart() + last;
+ last = b;
+ c = buf0.readSmart() + last;
+ last = c;
+ faceVertexA[face] = a;
+ faceVertexB[face] = b;
+ faceVertexC[face] = c;
+ }
+
+ // reuse a, c, new b
+ if (orientation == 2) {
+ b = c;
+ c = buf0.readSmart() + last;
+ last = c;
+ faceVertexA[face] = a;
+ faceVertexB[face] = b;
+ faceVertexC[face] = c;
+ }
+
+ // reuse c, b, new a
+ if (orientation == 3) {
+ a = c;
+ c = buf0.readSmart() + last;
+ last = c;
+ faceVertexA[face] = a;
+ faceVertexB[face] = b;
+ faceVertexC[face] = c;
+ }
+
+ // reuse b, a, new c
+ if (orientation == 4) {
+ int tmp = a;
+ a = b;
+ b = tmp;
+ c = buf0.readSmart() + last;
+ last = c;
+ faceVertexA[face] = a;
+ faceVertexB[face] = b;
+ faceVertexC[face] = c;
+ }
+ }
+
+ buf0.position = header.faceTextureAxisOffset;
+
+ for (int face = 0; face < texturedFaceCount; face++) {
+ texturedVertexA[face] = buf0.read16U();
+ texturedVertexB[face] = buf0.read16U();
+ texturedVertexC[face] = buf0.read16U();
+ }
+ }
+
+ /**
+ * Constructs a new model by merging the provided models. This constructor is used to combine models before
+ * {@link SeqTransform}'s have been applied. Using this constructor implies all models merged are compatible with any
+ * animations played on them.
+ *
+ * @param count the model count.
+ * @param models the models to merge.
+ */
+ public Model(int count, Model[] models) {
+ counter++;
+
+ boolean copyInfo = false;
+ boolean copyPriority = false;
+ boolean copyAlpha = false;
+ boolean copyLabels = false;
+
+ vertexCount = 0;
+ faceCount = 0;
+ texturedFaceCount = 0;
+ priority = -1;
+
+ for (int i = 0; i < count; i++) {
+ Model model = models[i];
+
+ if (model == null) {
+ continue;
+ }
+
+ vertexCount += model.vertexCount;
+ faceCount += model.faceCount;
+ texturedFaceCount += model.texturedFaceCount;
+
+ copyInfo |= model.faceInfo != null;
+
+ if (model.facePriority != null) {
+ copyPriority = true;
+ } else {
+ if (priority == -1) {
+ priority = model.priority;
+ }
+ if (priority != model.priority) {
+ copyPriority = true;
+ }
+ }
+
+ copyAlpha |= model.faceAlpha != null;
+ copyLabels |= model.faceLabel != null;
+ }
+
+ vertexX = new int[vertexCount];
+ vertexY = new int[vertexCount];
+ vertexZ = new int[vertexCount];
+ vertexLabel = new int[vertexCount];
+ faceVertexA = new int[faceCount];
+ faceVertexB = new int[faceCount];
+ faceVertexC = new int[faceCount];
+ texturedVertexA = new int[texturedFaceCount];
+ texturedVertexB = new int[texturedFaceCount];
+ texturedVertexC = new int[texturedFaceCount];
+
+ if (copyInfo) {
+ faceInfo = new int[faceCount];
+ }
+
+ if (copyPriority) {
+ facePriority = new int[faceCount];
+ }
+
+ if (copyAlpha) {
+ faceAlpha = new int[faceCount];
+ }
+
+ if (copyLabels) {
+ faceLabel = new int[faceCount];
+ }
+
+ faceColor = new int[faceCount];
+ vertexCount = 0;
+ faceCount = 0;
+ texturedFaceCount = 0;
+
+ int tfaceCount = 0;
+
+ for (int i = 0; i < count; i++) {
+ Model model = models[i];
+
+ if (model == null) {
+ continue;
+ }
+
+ for (int face = 0; face < model.faceCount; face++) {
+ if (copyInfo) {
+ if (model.faceInfo == null) {
+ faceInfo[faceCount] = 0;
+ } else {
+ int info = model.faceInfo[face];
+
+ if ((info & 2) == 2) {
+ info += tfaceCount << 2;
+ }
+
+ faceInfo[faceCount] = info;
+ }
+ }
+
+ if (copyPriority) {
+ if (model.facePriority == null) {
+ facePriority[faceCount] = model.priority;
+ } else {
+ facePriority[faceCount] = model.facePriority[face];
+ }
+ }
+
+ if (copyAlpha) {
+ if (model.faceAlpha == null) {
+ faceAlpha[faceCount] = 0;
+ } else {
+ faceAlpha[faceCount] = model.faceAlpha[face];
+ }
+ }
+
+ if (copyLabels && (model.faceLabel != null)) {
+ faceLabel[faceCount] = model.faceLabel[face];
+ }
+
+ faceColor[faceCount] = model.faceColor[face];
+ faceVertexA[faceCount] = addVertex(model, model.faceVertexA[face]);
+ faceVertexB[faceCount] = addVertex(model, model.faceVertexB[face]);
+ faceVertexC[faceCount] = addVertex(model, model.faceVertexC[face]);
+ faceCount++;
+ }
+
+ for (int tface = 0; tface < model.texturedFaceCount; tface++) {
+ texturedVertexA[texturedFaceCount] = addVertex(model, model.texturedVertexA[tface]);
+ texturedVertexB[texturedFaceCount] = addVertex(model, model.texturedVertexB[tface]);
+ texturedVertexC[texturedFaceCount] = addVertex(model, model.texturedVertexC[tface]);
+ texturedFaceCount++;
+ }
+
+ tfaceCount += model.texturedFaceCount;
+ }
+ }
+
+ /**
+ * Constructs a new model by combining models. This constructor is commonly used to combine models which have already
+ * had a {@link SeqTransform} applied, and does not copy label information.
+ *
+ * @param count the model count.
+ * @param dummy dummy.
+ * @param models the models.
+ */
+ public Model(int count, int dummy, Model[] models) {
+ counter++;
+
+ boolean copyInfo = false;
+ boolean copyPriority = false;
+ boolean copyAlpha = false;
+ boolean copyColor = false;
+
+ vertexCount = 0;
+ faceCount = 0;
+ texturedFaceCount = 0;
+ priority = -1;
+
+ for (int i = 0; i < count; i++) {
+ Model model = models[i];
+
+ if (model == null) {
+ continue;
+ }
+
+ vertexCount += model.vertexCount;
+ faceCount += model.faceCount;
+ texturedFaceCount += model.texturedFaceCount;
+ copyInfo |= model.faceInfo != null;
+
+ if (model.facePriority != null) {
+ copyPriority = true;
+ } else {
+ if (priority == -1) {
+ priority = model.priority;
+ }
+ if (priority != model.priority) {
+ copyPriority = true;
+ }
+ }
+
+ copyAlpha |= model.faceAlpha != null;
+ copyColor |= model.faceColor != null;
+ }
+
+ vertexX = new int[vertexCount];
+ vertexY = new int[vertexCount];
+ vertexZ = new int[vertexCount];
+ faceVertexA = new int[faceCount];
+ faceVertexB = new int[faceCount];
+ faceVertexC = new int[faceCount];
+ faceColorA = new int[faceCount];
+ faceColorB = new int[faceCount];
+ faceColorC = new int[faceCount];
+ texturedVertexA = new int[texturedFaceCount];
+ texturedVertexB = new int[texturedFaceCount];
+ texturedVertexC = new int[texturedFaceCount];
+
+ if (copyInfo) {
+ faceInfo = new int[faceCount];
+ }
+
+ if (copyPriority) {
+ facePriority = new int[faceCount];
+ }
+
+ if (copyAlpha) {
+ faceAlpha = new int[faceCount];
+ }
+
+ if (copyColor) {
+ faceColor = new int[faceCount];
+ }
+
+ vertexCount = 0;
+ faceCount = 0;
+ texturedFaceCount = 0;
+
+ int tfaceCount = 0;
+ for (int i = 0; i < count; i++) {
+ Model model = models[i];
+
+ if (model == null) {
+ continue;
+ }
+
+ int vertexCount = this.vertexCount;
+
+ for (int v = 0; v < model.vertexCount; v++) {
+ vertexX[this.vertexCount] = model.vertexX[v];
+ vertexY[this.vertexCount] = model.vertexY[v];
+ vertexZ[this.vertexCount] = model.vertexZ[v];
+ this.vertexCount++;
+ }
+
+ for (int f = 0; f < model.faceCount; f++) {
+ faceVertexA[faceCount] = model.faceVertexA[f] + vertexCount;
+ faceVertexB[faceCount] = model.faceVertexB[f] + vertexCount;
+ faceVertexC[faceCount] = model.faceVertexC[f] + vertexCount;
+
+ faceColorA[faceCount] = model.faceColorA[f];
+ faceColorB[faceCount] = model.faceColorB[f];
+ faceColorC[faceCount] = model.faceColorC[f];
+
+ if (copyInfo) {
+ if (model.faceInfo == null) {
+ faceInfo[faceCount] = 0;
+ } else {
+ int info = model.faceInfo[f];
+
+ if ((info & 2) == 2) {
+ info += tfaceCount << 2;
+ }
+
+ faceInfo[faceCount] = info;
+ }
+ }
+
+ if (copyPriority) {
+ if (model.facePriority == null) {
+ facePriority[faceCount] = model.priority;
+ } else {
+ facePriority[faceCount] = model.facePriority[f];
+ }
+ }
+
+ if (copyAlpha) {
+ if (model.faceAlpha == null) {
+ faceAlpha[faceCount] = 0;
+ } else {
+ faceAlpha[faceCount] = model.faceAlpha[f];
+ }
+ }
+
+ if (copyColor && (model.faceColor != null)) {
+ faceColor[faceCount] = model.faceColor[f];
+ }
+ faceCount++;
+ }
+
+ for (int f = 0; f < model.texturedFaceCount; f++) {
+ texturedVertexA[texturedFaceCount] = model.texturedVertexA[f] + vertexCount;
+ texturedVertexB[texturedFaceCount] = model.texturedVertexB[f] + vertexCount;
+ texturedVertexC[texturedFaceCount] = model.texturedVertexC[f] + vertexCount;
+ texturedFaceCount++;
+ }
+
+ tfaceCount += model.texturedFaceCount;
+ }
+ calculateBoundsCylinder();
+ }
+
+ /**
+ * Constructs a new model that can either share or clone the provided models attributes. This constructor is used to
+ * save memory by avoiding allocations, and is meant to be used with models prior to having a {@link SeqTransform} applied.
+ *
+ * @param shareColors true to reference the provided model's colors.
+ * @param shareAlpha true to reference the provided model's face alpha.
+ * @param shareVertices true to reference the provided model's vertices.
+ * @param model the model to share or clone.
+ */
+ public Model(boolean shareColors, boolean shareAlpha, boolean shareVertices, Model model) {
+ counter++;
+ vertexCount = model.vertexCount;
+ faceCount = model.faceCount;
+ texturedFaceCount = model.texturedFaceCount;
+
+ if (shareVertices) {
+ vertexX = model.vertexX;
+ vertexY = model.vertexY;
+ vertexZ = model.vertexZ;
+ } else {
+ vertexX = new int[vertexCount];
+ vertexY = new int[vertexCount];
+ vertexZ = new int[vertexCount];
+
+ for (int j = 0; j < vertexCount; j++) {
+ vertexX[j] = model.vertexX[j];
+ vertexY[j] = model.vertexY[j];
+ vertexZ[j] = model.vertexZ[j];
+ }
+ }
+
+ if (shareColors) {
+ faceColor = model.faceColor;
+ } else {
+ faceColor = new int[faceCount];
+
+ for (int k = 0; k < faceCount; k++) {
+ faceColor[k] = model.faceColor[k];
+ }
+ }
+
+ if (shareAlpha) {
+ faceAlpha = model.faceAlpha;
+ } else {
+ faceAlpha = new int[faceCount];
+ if (model.faceAlpha == null) {
+ for (int l = 0; l < faceCount; l++) {
+ faceAlpha[l] = 0;
+ }
+ } else {
+ for (int i1 = 0; i1 < faceCount; i1++) {
+ faceAlpha[i1] = model.faceAlpha[i1];
+ }
+ }
+ }
+
+ vertexLabel = model.vertexLabel;
+ faceLabel = model.faceLabel;
+ faceInfo = model.faceInfo;
+ faceVertexA = model.faceVertexA;
+ faceVertexB = model.faceVertexB;
+ faceVertexC = model.faceVertexC;
+ facePriority = model.facePriority;
+ priority = model.priority;
+ texturedVertexA = model.texturedVertexA;
+ texturedVertexB = model.texturedVertexB;
+ texturedVertexC = model.texturedVertexC;
+ }
+
+ /**
+ * Constructs a new model with the options to copy either vertex Y positions and faces.
+ *
+ * This constructor is specifically used by Locs which adjust to terrain.
+ *
+ * @param copyVertexY true to copy model.vertexY.
+ * @param copyFaces true to copy all face data from model.
+ * @param model the model to copy.
+ * @see LocType#getModel(int, int, int, int, int, int, int)
+ */
+ public Model(boolean copyVertexY, boolean copyFaces, Model model) {
+ counter++;
+ vertexCount = model.vertexCount;
+ faceCount = model.faceCount;
+ texturedFaceCount = model.texturedFaceCount;
+
+ if (copyVertexY) {
+ vertexY = new int[vertexCount];
+ for (int v = 0; v < vertexCount; v++) {
+ vertexY[v] = model.vertexY[v];
+ }
+ } else {
+ vertexY = model.vertexY;
+ }
+
+ if (copyFaces) {
+ faceColorA = new int[faceCount];
+ faceColorB = new int[faceCount];
+ faceColorC = new int[faceCount];
+
+ for (int k = 0; k < faceCount; k++) {
+ faceColorA[k] = model.faceColorA[k];
+ faceColorB[k] = model.faceColorB[k];
+ faceColorC[k] = model.faceColorC[k];
+ }
+
+ faceInfo = new int[faceCount];
+
+ if (model.faceInfo == null) {
+ for (int l = 0; l < faceCount; l++) {
+ faceInfo[l] = 0;
+ }
+ } else {
+ for (int face = 0; face < faceCount; face++) {
+ faceInfo[face] = model.faceInfo[face];
+ }
+ }
+
+ super.vertexNormal = new VertexNormal[vertexCount];
+ for (int v = 0; v < vertexCount; v++) {
+ VertexNormal duplicate = super.vertexNormal[v] = new VertexNormal();
+ VertexNormal original = model.vertexNormal[v];
+ duplicate.x = original.x;
+ duplicate.y = original.y;
+ duplicate.z = original.z;
+ duplicate.w = original.w;
+ }
+ vertexNormalOriginal = model.vertexNormalOriginal;
+ } else {
+ faceColorA = model.faceColorA;
+ faceColorB = model.faceColorB;
+ faceColorC = model.faceColorC;
+ faceInfo = model.faceInfo;
+ }
+
+ vertexX = model.vertexX;
+ vertexZ = model.vertexZ;
+ faceColor = model.faceColor;
+ faceAlpha = model.faceAlpha;
+ facePriority = model.facePriority;
+ priority = model.priority;
+ faceVertexA = model.faceVertexA;
+ faceVertexB = model.faceVertexB;
+ faceVertexC = model.faceVertexC;
+ texturedVertexA = model.texturedVertexA;
+ texturedVertexB = model.texturedVertexB;
+ texturedVertexC = model.texturedVertexC;
+ super.minY = model.minY;
+ maxY = model.maxY;
+ radius = model.radius;
+ minDepth = model.minDepth;
+ maxDepth = model.maxDepth;
+ minX = model.minX;
+ maxZ = model.maxZ;
+ minZ = model.minZ;
+ maxX = model.maxX;
+ }
+
+ /**
+ * Sets this model to the provided model using a vertex pool.
+ *
+ * Face alpha may be optionally copied in case an applied {@link SeqTransform} modifies the alpha of the model.
+ *
+ * @param model the model.
+ * @param shareAlpha whether to copy or share a reference to face alphas.
+ */
+ public void set(Model model, boolean shareAlpha) {
+ vertexCount = model.vertexCount;
+ faceCount = model.faceCount;
+ texturedFaceCount = model.texturedFaceCount;
+
+ if (tmpVertexX.length < vertexCount) {
+ tmpVertexX = new int[vertexCount + 100];
+ tmpVertexY = new int[vertexCount + 100];
+ tmpVertexZ = new int[vertexCount + 100];
+ }
+
+ vertexX = tmpVertexX;
+ vertexY = tmpVertexY;
+ vertexZ = tmpVertexZ;
+
+ for (int k = 0; k < vertexCount; k++) {
+ vertexX[k] = model.vertexX[k];
+ vertexY[k] = model.vertexY[k];
+ vertexZ[k] = model.vertexZ[k];
+ }
+
+ if (shareAlpha) {
+ faceAlpha = model.faceAlpha;
+ } else {
+ if (tmpFaceAlpha.length < faceCount) {
+ tmpFaceAlpha = new int[faceCount + 100];
+ }
+ faceAlpha = tmpFaceAlpha;
+ if (model.faceAlpha == null) {
+ for (int face = 0; face < faceCount; face++) {
+ faceAlpha[face] = 0;
+ }
+ } else {
+ for (int face = 0; face < faceCount; face++) {
+ faceAlpha[face] = model.faceAlpha[face];
+ }
+ }
+ }
+
+ faceInfo = model.faceInfo;
+ faceColor = model.faceColor;
+ facePriority = model.facePriority;
+ priority = model.priority;
+ labelFaces = model.labelFaces;
+ labelVertices = model.labelVertices;
+ faceVertexA = model.faceVertexA;
+ faceVertexB = model.faceVertexB;
+ faceVertexC = model.faceVertexC;
+ faceColorA = model.faceColorA;
+ faceColorB = model.faceColorB;
+ faceColorC = model.faceColorC;
+ texturedVertexA = model.texturedVertexA;
+ texturedVertexB = model.texturedVertexB;
+ texturedVertexC = model.texturedVertexC;
+ }
+
+ /**
+ * Adds vertexId from src to this. Reuses vertex if one already exists at the
+ * same location.
+ *
+ * @param src the source model.
+ * @param vertexId the vertex id to add from the src.
+ * @return the vertex id of the added vertex.
+ */
+ public int addVertex(Model src, int vertexId) {
+ int x = src.vertexX[vertexId];
+ int y = src.vertexY[vertexId];
+ int z = src.vertexZ[vertexId];
+
+ int identical = -1;
+ for (int v = 0; v < vertexCount; v++) {
+ if ((x == vertexX[v]) && (y == vertexY[v]) && (z == vertexZ[v])) {
+ identical = v;
+ break;
+ }
+ }
+
+ // append new one if no matches were found
+ if (identical == -1) {
+ vertexX[vertexCount] = x;
+ vertexY[vertexCount] = y;
+ vertexZ[vertexCount] = z;
+ if (src.vertexLabel != null) {
+ vertexLabel[vertexCount] = src.vertexLabel[vertexId];
+ }
+ identical = vertexCount++;
+ }
+
+ return identical;
+ }
+
+ /**
+ * Calculates {@link #minY}, {@link #maxY}, {@link #radius}, {@link #minDepth} and {@link #maxDepth}.
+ */
+ public void calculateBoundsCylinder() {
+ super.minY = 0;
+ radius = 0;
+ maxY = 0;
+ for (int i = 0; i < vertexCount; i++) {
+ int x = vertexX[i];
+ int y = vertexY[i];
+ int z = vertexZ[i];
+ if (-y > super.minY) {
+ super.minY = -y;
+ }
+ if (y > maxY) {
+ maxY = y;
+ }
+ int radiusSqr = (x * x) + (z * z);
+ if (radiusSqr > radius) {
+ radius = radiusSqr;
+ }
+ }
+ radius = (int) (Math.sqrt(radius) + 0.99);
+ minDepth = (int) (Math.sqrt((radius * radius) + (super.minY * super.minY)) + 0.99);
+ maxDepth = minDepth + (int) (Math.sqrt((radius * radius) + (maxY * maxY)) + 0.99);
+ }
+
+ /**
+ * Calculates {@link #minY}, {@link #maxY}, {@link #minDepth} and {@link #maxDepth}.
+ */
+ public void calculateBoundsY() {
+ super.minY = 0;
+ maxY = 0;
+ for (int i = 0; i < vertexCount; i++) {
+ int y = vertexY[i];
+ if (-y > super.minY) {
+ super.minY = -y;
+ }
+ if (y > maxY) {
+ maxY = y;
+ }
+ }
+ minDepth = (int) (Math.sqrt((radius * radius) + (super.minY * super.minY)) + 0.99);
+ maxDepth = minDepth + (int) (Math.sqrt((radius * radius) + (maxY * maxY)) + 0.99);
+ }
+
+ /**
+ * Calculates this models axis-aligned bounding box (AABB) and stores it.
+ */
+ public void calculateBoundsAABB() {
+ super.minY = 0;
+ radius = 0;
+ maxY = 0;
+ minX = 999999;
+ maxX = -999999;
+ maxZ = -99999;
+ minZ = 99999;
+ for (int j = 0; j < vertexCount; j++) {
+ int x = vertexX[j];
+ int y = vertexY[j];
+ int z = vertexZ[j];
+ if (x < minX) {
+ minX = x;
+ }
+ if (x > maxX) {
+ maxX = x;
+ }
+ if (z < minZ) {
+ minZ = z;
+ }
+ if (z > maxZ) {
+ maxZ = z;
+ }
+ if (-y > super.minY) {
+ super.minY = -y;
+ }
+ if (y > maxY) {
+ maxY = y;
+ }
+ int radiusSqr = (x * x) + (z * z);
+ if (radiusSqr > radius) {
+ radius = radiusSqr;
+ }
+ }
+ radius = (int) Math.sqrt(radius);
+ minDepth = (int) Math.sqrt((radius * radius) + (super.minY * super.minY));
+ maxDepth = minDepth + (int) Math.sqrt((radius * radius) + (maxY * maxY));
+ }
+
+ /**
+ * Builds {@link #labelVertices} and {@link #labelFaces} using {@link #vertexLabel} and {@link #faceLabel}.
+ *
+ * This method is destructive, meaning it sets {@link #vertexLabel} and {@link #faceLabel} to null
+ * after being called.
+ *
+ * This method is required for applying animations to a model and should only be called once on a single instance
+ * of a {@link Model}.
+ *
+ * @see #applyTransform(int)
+ * @see #applyTransforms(int, int, int[])
+ * @see #applyTransform(int, int[], int, int, int)
+ */
+ public void createLabelReferences() {
+ if (vertexLabel != null) {
+ int[] labelVertexCount = new int[256];
+
+ int count = 0;
+ for (int v = 0; v < vertexCount; v++) {
+ int label = vertexLabel[v];
+ labelVertexCount[label]++;
+ if (label > count) {
+ count = label;
+ }
+ }
+
+ labelVertices = new int[count + 1][];
+
+ for (int label = 0; label <= count; label++) {
+ labelVertices[label] = new int[labelVertexCount[label]];
+ labelVertexCount[label] = 0;
+ }
+
+ for (int v = 0; v < vertexCount; v++) {
+ int label = vertexLabel[v];
+ labelVertices[label][labelVertexCount[label]++] = v;
+ }
+
+ vertexLabel = null;
+ }
+
+ if (faceLabel != null) {
+ int[] labelFaceCount = new int[256];
+
+ int count = 0;
+ for (int f = 0; f < faceCount; f++) {
+ int label = faceLabel[f];
+ labelFaceCount[label]++;
+ if (label > count) {
+ count = label;
+ }
+ }
+
+ labelFaces = new int[count + 1][];
+ for (int label = 0; label <= count; label++) {
+ labelFaces[label] = new int[labelFaceCount[label]];
+ labelFaceCount[label] = 0;
+ }
+
+ for (int face = 0; face < faceCount; face++) {
+ int label = faceLabel[face];
+ labelFaces[label][labelFaceCount[label]++] = face;
+ }
+
+ faceLabel = null;
+ }
+ }
+
+ /**
+ * Applies a {@link SeqTransform} of the specified
- * 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 visible;
- public boolean update;
- public boolean containsLocs;
- public int checkLocSpans;
- public int blockLocSpans;
- public int inverseBlockLocSpans;
- public int backWallTypes;
- public SceneTile bridge;
+ public final int x;
+ public final int z;
+ /**
+ * 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 level;
+ public SceneTileUnderlay underlay;
+ public SceneTileOverlay overlay;
+ public SceneWall wall;
+ public SceneWallDecoration wallDecoration;
+ public SceneGroundDecoration groundDecoration;
+ public SceneObjStack objStack;
+ public int locCount;
+ /**
+ * 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 visible;
+ public boolean update;
+ public boolean containsLocs;
+ public int checkLocSpans;
+ public int blockLocSpans;
+ public int inverseBlockLocSpans;
+ public int backWallTypes;
+ public SceneTile bridge;
- public SceneTile(int level, int x, int z) {
- this.occludeLevel = this.level = level;
- this.x = x;
- this.z = z;
- }
+ public SceneTile(int level, int x, int z) {
+ this.occludeLevel = this.level = level;
+ this.x = x;
+ this.z = z;
+ }
}
diff --git a/src/main/java/SceneTileOverlay.java b/src/main/java/SceneTileOverlay.java
index ee56f63..e3eb669 100644
--- a/src/main/java/SceneTileOverlay.java
+++ b/src/main/java/SceneTileOverlay.java
@@ -5,20 +5,20 @@
public class SceneTileOverlay {
public static final int[][] SHAPE_POINTS = {
- {1, 3, 5, 7},
- {1, 3, 5, 7},
- {1, 3, 5, 7},
- {1, 3, 5, 7, 6},
- {1, 3, 5, 7, 6},
- {1, 3, 5, 7, 6},
- {1, 3, 5, 7, 6},
- {1, 3, 5, 7, 2, 6},
- {1, 3, 5, 7, 2, 8},
- {1, 3, 5, 7, 2, 8},
- {1, 3, 5, 7, 11, 12},
- {1, 3, 5, 7, 11, 12},
- {1, 3, 5, 7, 13, 14},
- };
+ {1, 3, 5, 7},
+ {1, 3, 5, 7},
+ {1, 3, 5, 7},
+ {1, 3, 5, 7, 6},
+ {1, 3, 5, 7, 6},
+ {1, 3, 5, 7, 6},
+ {1, 3, 5, 7, 6},
+ {1, 3, 5, 7, 2, 6},
+ {1, 3, 5, 7, 2, 8},
+ {1, 3, 5, 7, 2, 8},
+ {1, 3, 5, 7, 11, 12},
+ {1, 3, 5, 7, 11, 12},
+ {1, 3, 5, 7, 13, 14},
+ };
public static final int[][] SHAPE_PATHS = {
{0, 1, 2, 3, 0, 0, 1, 3},
{1, 1, 2, 3, 1, 0, 1, 3},
diff --git a/src/main/java/SceneTileUnderlay.java b/src/main/java/SceneTileUnderlay.java
index 5717c65..4dd24bc 100644
--- a/src/main/java/SceneTileUnderlay.java
+++ b/src/main/java/SceneTileUnderlay.java
@@ -4,22 +4,22 @@
public class SceneTileUnderlay {
- public final int southwestColor;
- public final int southeastColor;
- public final int northeastColor;
- public final int northwestColor;
- public final int textureID;
- public final int rgb;
- public boolean flat;
+ public final int southwestColor;
+ public final int southeastColor;
+ public final int northeastColor;
+ public final int northwestColor;
+ public final int textureID;
+ public final int rgb;
+ public boolean flat;
- public SceneTileUnderlay(int southwestColor, int southeastColor, int northeastColor, int northwestColor, int textureID, int rgb, boolean flat) {
- this.southwestColor = southwestColor;
- this.southeastColor = southeastColor;
- this.northeastColor = northeastColor;
- this.northwestColor = northwestColor;
- this.textureID = textureID;
- this.rgb = rgb;
- this.flat = flat;
- }
+ public SceneTileUnderlay(int southwestColor, int southeastColor, int northeastColor, int northwestColor, int textureID, int rgb, boolean flat) {
+ this.southwestColor = southwestColor;
+ this.southeastColor = southeastColor;
+ this.northeastColor = northeastColor;
+ this.northwestColor = northwestColor;
+ this.textureID = textureID;
+ this.rgb = rgb;
+ this.flat = flat;
+ }
}
diff --git a/src/main/java/SceneWall.java b/src/main/java/SceneWall.java
index b88ba64..f3514df 100644
--- a/src/main/java/SceneWall.java
+++ b/src/main/java/SceneWall.java
@@ -4,17 +4,17 @@
public class SceneWall {
- public int y;
- public int x;
- public int z;
- public int typeA;
- public int typeB;
- public Entity entityA;
- public Entity entityB;
- public int bitset;
- public byte info;
+ public int y;
+ public int x;
+ public int z;
+ public int typeA;
+ public int typeB;
+ public Entity entityA;
+ public Entity entityB;
+ public int bitset;
+ public byte info;
- public SceneWall() {
- }
+ public SceneWall() {
+ }
}
diff --git a/src/main/java/SceneWallDecoration.java b/src/main/java/SceneWallDecoration.java
index 140c382..6c2649e 100644
--- a/src/main/java/SceneWallDecoration.java
+++ b/src/main/java/SceneWallDecoration.java
@@ -1,15 +1,15 @@
public class SceneWallDecoration {
- public int y;
- public int x;
- public int z;
- public int type;
- public int rotation;
- public Entity entity;
- public int bitset;
- public byte info;
+ public int y;
+ public int x;
+ public int z;
+ public int type;
+ public int rotation;
+ public Entity entity;
+ public int bitset;
+ public byte info;
- public SceneWallDecoration() {
- }
+ public SceneWallDecoration() {
+ }
}
diff --git a/src/main/java/SeqSkeleton.java b/src/main/java/SeqSkeleton.java
index 26a82fe..fc46193 100644
--- a/src/main/java/SeqSkeleton.java
+++ b/src/main/java/SeqSkeleton.java
@@ -26,7 +26,8 @@ public class SeqSkeleton {
public final int[] baseTypes;
/**
* The labels belonging to the base.
- * @see Model#createLabelReferences()
+ *
+ * @see Model#createLabelReferences()
*/
public final int[][] baseLabels;
diff --git a/src/main/java/SeqTransform.java b/src/main/java/SeqTransform.java
index 00c99d2..2424dac 100644
--- a/src/main/java/SeqTransform.java
+++ b/src/main/java/SeqTransform.java
@@ -6,182 +6,182 @@
*/
public class SeqTransform {
- public static SeqTransform[] instances;
+ public static SeqTransform[] instances;
- /**
- * Syntax sugar.
- *
- * @param id the id
- * @return id.
+ *
+ * @param id the transform id.
+ */
+ public void applyTransform(int id) {
+ if (labelVertices == null) {
+ return;
+ }
+ if (id == -1) {
+ return;
+ }
+ SeqTransform transform = SeqTransform.get(id);
+ if (transform == null) {
+ return;
+ }
+ SeqSkeleton skeleton = transform.skeleton;
+ baseX = 0;
+ baseY = 0;
+ baseZ = 0;
+ for (int i = 0; i < transform.length; i++) {
+ int base = transform.bases[i];
+ applyTransform(skeleton.baseTypes[base], skeleton.baseLabels[base], transform.x[i], transform.y[i], transform.z[i]);
+ }
+ }
+
+ /**
+ * Applies the specified {@link SeqTransform} ids.
+ *
+ * @param primaryID the primary transform id.
+ * @param secondaryID the secondary transform id.
+ * @param mask the mask contains base ids to prevent the primary transform from using the same bases as the secondary transform.
+ */
+ public void applyTransforms(int primaryID, int secondaryID, int[] mask) {
+ if (primaryID == -1) {
+ return;
+ }
+
+ if ((mask == null) || (secondaryID == -1)) {
+ applyTransform(primaryID);
+ return;
+ }
+
+ SeqTransform primary = SeqTransform.get(primaryID);
+
+ if (primary == null) {
+ return;
+ }
+
+ SeqTransform secondary = SeqTransform.get(secondaryID);
+
+ if (secondary == null) {
+ applyTransform(primaryID);
+ return;
+ }
+
+ SeqSkeleton skeleton = primary.skeleton;
+
+ baseX = 0;
+ baseY = 0;
+ baseZ = 0;
+
+ int counter = 0;
+ int maskBase = mask[counter++];
+
+ for (int i = 0; i < primary.length; i++) {
+ int base = primary.bases[i];
+
+ while (base > maskBase) {
+ maskBase = mask[counter++];
+ }
+
+ if ((base != maskBase) || (skeleton.baseTypes[base] == 0)) {
+ applyTransform(skeleton.baseTypes[base], skeleton.baseLabels[base], primary.x[i], primary.y[i], primary.z[i]);
+ }
+ }
+
+ baseX = 0;
+ baseY = 0;
+ baseZ = 0;
+
+ counter = 0;
+ maskBase = mask[counter++];
+
+ for (int i = 0; i < secondary.length; i++) {
+ int base = secondary.bases[i];
+
+ while (base > maskBase) {
+ maskBase = mask[counter++];
+ }
+
+ if ((base == maskBase) || (skeleton.baseTypes[base] == 0)) {
+ applyTransform(skeleton.baseTypes[base], skeleton.baseLabels[base], secondary.x[i], secondary.y[i], secondary.z[i]);
+ }
+ }
+ }
+
+ /**
+ * Applies a transform of the given type to the specified list of labels using the parameters
+ * x, y, z.
+ *
+ * @param type the transform type.
+ * @param labels the transform labels.
+ * @param x the param x.
+ * @param y the param y.
+ * @param z the param z.
+ * @see #applyTransforms(int, int, int[])
+ * @see #applyTransform(int)
+ * @see SeqSkeleton#OP_BASE
+ * @see SeqSkeleton#OP_TRANSLATE
+ * @see SeqSkeleton#OP_ROTATE
+ * @see SeqSkeleton#OP_SCALE
+ * @see SeqSkeleton#OP_ALPHA
+ */
+ public void applyTransform(int type, int[] labels, int x, int y, int z) {
+ switch (type) {
+ case SeqSkeleton.OP_BASE:
+ int count = 0;
+ baseX = 0;
+ baseY = 0;
+ baseZ = 0;
+ for (int label : labels) {
+ if (label >= labelVertices.length) {
+ continue;
+ }
+ int[] vertices = labelVertices[label];
+ for (int v : vertices) {
+ baseX += vertexX[v];
+ baseY += vertexY[v];
+ baseZ += vertexZ[v];
+ count++;
+ }
+ }
+ if (count > 0) {
+ baseX = (baseX / count) + x;
+ baseY = (baseY / count) + y;
+ baseZ = (baseZ / count) + z;
+ } else {
+ baseX = x;
+ baseY = y;
+ baseZ = z;
+ }
+ break;
+ case SeqSkeleton.OP_TRANSLATE:
+ for (int group : labels) {
+ if (group >= labelVertices.length) {
+ continue;
+ }
+ int[] vertices = labelVertices[group];
+ for (int v : vertices) {
+ vertexX[v] += x;
+ vertexY[v] += y;
+ vertexZ[v] += z;
+ }
+ }
+ break;
+ case SeqSkeleton.OP_ROTATE:
+ for (int label : labels) {
+ if (label >= labelVertices.length) {
+ continue;
+ }
+ int[] vertices = labelVertices[label];
+ for (int v : vertices) {
+ vertexX[v] -= baseX;
+ vertexY[v] -= baseY;
+ vertexZ[v] -= baseZ;
+ int pitch = (x & 0xff) * 8;
+ int yaw = (y & 0xff) * 8;
+ int roll = (z & 0xff) * 8;
+ if (roll != 0) {
+ int sin = Model.sin[roll];
+ int cos = Model.cos[roll];
+ int x_ = ((vertexY[v] * sin) + (vertexX[v] * cos)) >> 16;
+ vertexY[v] = ((vertexY[v] * cos) - (vertexX[v] * sin)) >> 16;
+ vertexX[v] = x_;
+ }
+ if (pitch != 0) {
+ int sin = Model.sin[pitch];
+ int cos = Model.cos[pitch];
+ int y_ = ((vertexY[v] * cos) - (vertexZ[v] * sin)) >> 16;
+ vertexZ[v] = ((vertexY[v] * sin) + (vertexZ[v] * cos)) >> 16;
+ vertexY[v] = y_;
+ }
+ if (yaw != 0) {
+ int sin = Model.sin[yaw];
+ int cos = Model.cos[yaw];
+ int x_ = ((vertexZ[v] * sin) + (vertexX[v] * cos)) >> 16;
+ vertexZ[v] = ((vertexZ[v] * cos) - (vertexX[v] * sin)) >> 16;
+ vertexX[v] = x_;
+ }
+ vertexX[v] += baseX;
+ vertexY[v] += baseY;
+ vertexZ[v] += baseZ;
+ }
+ }
+ break;
+ case SeqSkeleton.OP_SCALE:
+ for (int label : labels) {
+ if (label >= labelVertices.length) {
+ continue;
+ }
+ int[] vertices = labelVertices[label];
+ for (int v : vertices) {
+ vertexX[v] -= baseX;
+ vertexY[v] -= baseY;
+ vertexZ[v] -= baseZ;
+ vertexX[v] = (vertexX[v] * x) / 128;
+ vertexY[v] = (vertexY[v] * y) / 128;
+ vertexZ[v] = (vertexZ[v] * z) / 128;
+ vertexX[v] += baseX;
+ vertexY[v] += baseY;
+ vertexZ[v] += baseZ;
+ }
+ }
+ break;
+ case SeqSkeleton.OP_ALPHA:
+ if ((labelFaces != null) && (faceAlpha != null)) {
+ for (int label : labels) {
+ if (label >= labelFaces.length) {
+ continue;
+ }
+ int[] triangles = labelFaces[label];
+ for (int t : triangles) {
+ faceAlpha[t] += x * 8;
+ if (faceAlpha[t] < 0) {
+ faceAlpha[t] = 0;
+ }
+ if (faceAlpha[t] > 255) {
+ faceAlpha[t] = 255;
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ /**
+ * Rotates clockwise on the Y axis by 90 degrees.
+ */
+ public void rotateY90() {
+ for (int v = 0; v < vertexCount; v++) {
+ int x_ = vertexX[v];
+ vertexX[v] = vertexZ[v];
+ vertexZ[v] = -x_;
+ }
+ }
+
+ /**
+ * Rotates the model on the X/Pitch axis.
+ *
+ * @param angle the angle.
+ */
+ public void rotateX(int angle) {
+ int sin = Model.sin[angle];
+ int cos = Model.cos[angle];
+ for (int v = 0; v < vertexCount; v++) {
+ int y_ = ((vertexY[v] * cos) - (vertexZ[v] * sin)) >> 16;
+ vertexZ[v] = ((vertexY[v] * sin) + (vertexZ[v] * cos)) >> 16;
+ vertexY[v] = y_;
+ }
+ }
+
+ /**
+ * Translates the model by the offset provided.
+ *
+ * @param x the x.
+ * @param y the y.
+ * @param z the z.
+ */
+ public void translate(int x, int y, int z) {
+ for (int v = 0; v < vertexCount; v++) {
+ vertexX[v] += x;
+ vertexY[v] += y;
+ vertexZ[v] += z;
+ }
+ }
+
+ /**
+ * Replaces use of the color src with color dst.
+ *
+ * @param src the source texture id.
+ * @param dst the destination texture id.
+ */
+ public void recolor(int src, int dst) {
+ for (int k = 0; k < faceCount; k++) {
+ if (faceColor[k] == src) {
+ faceColor[k] = dst;
+ }
+ }
+ }
+
+ /**
+ * Performs the equivalent operation of rotating the entire model on the Y axis by 180 degrees.
+ */
+ public void rotateY180() {
+ for (int v = 0; v < vertexCount; v++) {
+ vertexZ[v] = -vertexZ[v];
+ }
+ for (int f = 0; f < faceCount; f++) {
+ int a = faceVertexA[f];
+ faceVertexA[f] = faceVertexC[f];
+ faceVertexC[f] = a;
+ }
+ }
+
+ /**
+ * Scales the model. This method assumes 25.7 fixed-point integers, which means the value 1.0 will be 1<<7
+ * or 128.
+ *
+ * @param x the x scalar.
+ * @param y the y scalar.
+ * @param z the z scalar.
+ */
+ public void scale(int x, int y, int z) {
+ for (int v = 0; v < vertexCount; v++) {
+ vertexX[v] = (vertexX[v] * x) / 128;
+ vertexY[v] = (vertexY[v] * z) / 128;
+ vertexZ[v] = (vertexZ[v] * y) / 128;
+ }
+ }
+
+ /**
+ * Recalculates the normals and optionally applies the lighting immediately after. This method can be
+ * destructive if applyLighting is set to true.
+ *
+ * @param lightAmbient the ambient light.
+ * @param lightAttenuation the light attenuation.
+ * @param lightSrcX the light source x.
+ * @param lightSrcY the light source y.
+ * @param lightSrcZ the light source z.
+ * @param applyLighting true to invoke {@link #applyLighting(int, int, int, int, int)} after normals are
+ * calculated.
+ * @see #applyLighting(int, int, int, int, int)
+ */
+ public void calculateNormals(int lightAmbient, int lightAttenuation, int lightSrcX, int lightSrcY, int lightSrcZ, boolean applyLighting) {
+ int lightMagnitude = (int) Math.sqrt((lightSrcX * lightSrcX) + (lightSrcY * lightSrcY) + (lightSrcZ * lightSrcZ));
+ int attenuation = (lightAttenuation * lightMagnitude) >> 8;
+
+ if (faceColorA == null) {
+ faceColorA = new int[faceCount];
+ faceColorB = new int[faceCount];
+ faceColorC = new int[faceCount];
+ }
+
+ if (super.vertexNormal == null) {
+ super.vertexNormal = new VertexNormal[vertexCount];
+ for (int v = 0; v < vertexCount; v++) {
+ super.vertexNormal[v] = new VertexNormal();
+ }
+ }
+
+ for (int f = 0; f < faceCount; f++) {
+ int a = faceVertexA[f];
+ int b = faceVertexB[f];
+ int c = faceVertexC[f];
+
+ int dxAB = vertexX[b] - vertexX[a];
+ int dyAB = vertexY[b] - vertexY[a];
+ int dzAB = vertexZ[b] - vertexZ[a];
+
+ int dxAC = vertexX[c] - vertexX[a];
+ int dyAC = vertexY[c] - vertexY[a];
+ int dzAC = vertexZ[c] - vertexZ[a];
+
+ int nx = (dyAB * dzAC) - (dyAC * dzAB);
+ int ny = (dzAB * dxAC) - (dzAC * dxAB);
+ int nz = (dxAB * dyAC) - (dxAC * dyAB);
+
+ while ((nx > 8192) || (ny > 8192) || (nz > 8192) || (nx < -8192) || (ny < -8192) || (nz < -8192)) {
+ nx >>= 1;
+ ny >>= 1;
+ nz >>= 1;
+ }
+
+ int length = (int) Math.sqrt((nx * nx) + (ny * ny) + (nz * nz));
+
+ if (length <= 0) {
+ length = 1;
+ }
+
+ // normalize
+ nx = (nx * 256) / length;
+ ny = (ny * 256) / length;
+ nz = (nz * 256) / length;
+
+ if ((faceInfo == null) || ((faceInfo[f] & 1) == 0)) {
+ VertexNormal n = super.vertexNormal[a];
+ n.x += nx;
+ n.y += ny;
+ n.z += nz;
+ n.w++;
+ n = super.vertexNormal[b];
+ n.x += nx;
+ n.y += ny;
+ n.z += nz;
+ n.w++;
+ n = super.vertexNormal[c];
+ n.x += nx;
+ n.y += ny;
+ n.z += nz;
+ n.w++;
+ } else {
+ int lightness = lightAmbient + (((lightSrcX * nx) + (lightSrcY * ny) + (lightSrcZ * nz)) / (attenuation + (attenuation / 2)));
+ faceColorA[f] = mulColorLightness(faceColor[f], lightness, faceInfo[f]);
+ }
+ }
+
+ if (applyLighting) {
+ applyLighting(lightAmbient, attenuation, lightSrcX, lightSrcY, lightSrcZ);
+ } else {
+ vertexNormalOriginal = new VertexNormal[vertexCount];
+
+ for (int v = 0; v < vertexCount; v++) {
+ VertexNormal normal = super.vertexNormal[v];
+ VertexNormal copy = vertexNormalOriginal[v] = new VertexNormal();
+ copy.x = normal.x;
+ copy.y = normal.y;
+ copy.z = normal.z;
+ copy.w = normal.w;
+ }
+ }
+
+ if (applyLighting) {
+ calculateBoundsCylinder();
+ } else {
+ calculateBoundsAABB();
+ }
+ }
+
+ /**
+ * Calculates the lightness values for all faces using the provided lighting parameters. This method is destructive
+ * and nullifies normals and labels, which means it is meant to be applied once to a model.
+ *
+ * @param lightAmbient the ambient lighting value. [0...127]
+ * @param lightAttenuation the light attenuation.
+ * @param lightSrcX the light source x.
+ * @param lightSrcY the light source y.
+ * @param lightSrcZ the light source z.
+ */
+ public void applyLighting(int lightAmbient, int lightAttenuation, int lightSrcX, int lightSrcY, int lightSrcZ) {
+ for (int f = 0; f < faceCount; f++) {
+ int a = faceVertexA[f];
+ int b = faceVertexB[f];
+ int c = faceVertexC[f];
+
+ if (faceInfo == null) {
+ int color = faceColor[f];
+
+ VertexNormal n = super.vertexNormal[a];
+ int lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
+ faceColorA[f] = mulColorLightness(color, lightness, 0);
+
+ n = super.vertexNormal[b];
+ lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
+ faceColorB[f] = mulColorLightness(color, lightness, 0);
+
+ n = super.vertexNormal[c];
+ lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
+ faceColorC[f] = mulColorLightness(color, lightness, 0);
+ } else if ((faceInfo[f] & 1) == 0) {
+ int color = faceColor[f];
+ int info = faceInfo[f];
+
+ VertexNormal n = super.vertexNormal[a];
+ int lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
+ faceColorA[f] = mulColorLightness(color, lightness, info);
+
+ n = super.vertexNormal[b];
+ lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
+ faceColorB[f] = mulColorLightness(color, lightness, info);
+
+ n = super.vertexNormal[c];
+ lightness = lightAmbient + (((lightSrcX * n.x) + (lightSrcY * n.y) + (lightSrcZ * n.z)) / (lightAttenuation * n.w));
+ faceColorC[f] = mulColorLightness(color, lightness, info);
+ }
+ }
+
+ super.vertexNormal = null;
+ vertexNormalOriginal = null;
+ vertexLabel = null;
+ faceLabel = null;
+
+ if (faceInfo != null) {
+ for (int f = 0; f < faceCount; f++) {
+ if ((faceInfo[f] & 2) == 2) {
+ return;
+ }
+ }
+ }
+
+ faceColor = null;
+ }
+
+ /**
+ * Draws this model with reduced parameters.
+ *
+ * @param pitch the model pitch.
+ * @param yaw the model yaw.
+ * @param roll the model roll.
+ * @param eyePitch the eye pitch.
+ * @param eyeX the eye x.
+ * @param eyeY the eye y.
+ * @param eyeZ the eye z.
+ */
+ public void drawSimple(int pitch, int yaw, int roll, int eyePitch, int eyeX, int eyeY, int eyeZ) {
+ int centerX = Draw3D.centerX;
+ int centerY = Draw3D.centerY;
+ int sinPitch = sin[pitch];
+ int cosPitch = cos[pitch];
+ int sinYaw = sin[yaw];
+ int cosYaw = cos[yaw];
+ int sinRoll = sin[roll];
+ int cosRoll = cos[roll];
+ int sinEyePitch = sin[eyePitch];
+ int cosEyePitch = cos[eyePitch];
+ int midZ = ((eyeY * sinEyePitch) + (eyeZ * cosEyePitch)) >> 16;
+
+ for (int v = 0; v < vertexCount; v++) {
+ int x = vertexX[v];
+ int y = vertexY[v];
+ int z = vertexZ[v];
+
+ // Local Space -> Model Space
+
+ if (roll != 0) {
+ int x_ = ((y * sinRoll) + (x * cosRoll)) >> 16;
+ y = ((y * cosRoll) - (x * sinRoll)) >> 16;
+ x = x_;
+ }
+
+ if (pitch != 0) {
+ int y_ = ((y * cosPitch) - (z * sinPitch)) >> 16;
+ z = ((y * sinPitch) + (z * cosPitch)) >> 16;
+ y = y_;
+ }
+
+ if (yaw != 0) {
+ int x_ = ((z * sinYaw) + (x * cosYaw)) >> 16;
+ z = ((z * cosYaw) - (x * sinYaw)) >> 16;
+ x = x_;
+ }
+
+ // Model Space -> View Space
+
+ x += eyeX;
+ y += eyeY;
+ z += eyeZ;
+
+ int y_ = ((y * cosEyePitch) - (z * sinEyePitch)) >> 16;
+ z = ((y * sinEyePitch) + (z * cosEyePitch)) >> 16;
+ y = y_;
+
+ // View Space -> Screen Space
+
+ vertexScreenX[v] = centerX + ((x << 9) / z);
+ vertexScreenY[v] = centerY + ((y << 9) / z);
+ vertexScreenZ[v] = z - midZ;
+
+ // Store viewspace coordinates to be transformed into screen space later (textured or clipped triangles)
+
+ if (texturedFaceCount > 0) {
+ vertexViewSpaceX[v] = x;
+ vertexViewSpaceY[v] = y;
+ vertexViewSpaceZ[v] = z;
+ }
+ }
+ try {
+ draw(false, false, 0);
+ } catch (Exception ignored) {
+ }
+ }
+
+ /**
+ * Draws this model.
+ *
+ * @param yaw the yaw of this model.
+ * @param sinEyePitch the sin(eyePitch).
+ * @param cosEyePitch the cos(eyePitch).
+ * @param sinEyeYaw the sin(eyeYaw).
+ * @param cosEyeYaw the cos(eyeYaw).
+ * @param relativeX the relative x. (SceneX - EyeX)
+ * @param relativeY the relative y. (SceneY - EyeY)
+ * @param relativeZ the relative z. (SceneZ - EyeZ)
+ * @param bitset the bitset.
+ */
+ @Override
+ public void draw(int yaw, int sinEyePitch, int cosEyePitch, int sinEyeYaw, int cosEyeYaw, int relativeX, int relativeY, int relativeZ, int bitset) {
+ // Relative coordinates are ScenePos - EyePos
+
+ // z' is our relative z value rotated by eye yaw.
+ int zPrime = ((relativeZ * cosEyeYaw) - (relativeX * sinEyeYaw)) >> 16;
+
+ // midZ is our relative z value rotated by eye yaw and pitch. It's the distance from the camera from the center
+ // of our model.
+ int midZ = ((relativeY * sinEyePitch) + (zPrime * cosEyePitch)) >> 16;
+
+ // Our pitch is clamped between 128 and 384 (22.5 degrees and 67.5 degrees)
+ // We know this will be positive and within 92->38% its original value.
+ int radiusCosEyePitch = (radius * cosEyePitch) >> 16;
+
+ // +Z goes forward, which makes this value supposedly the farthest Z the model should be away from the camera.
+ int maxZ = midZ + radiusCosEyePitch;
+
+ // early z testing
+ if ((maxZ <= 50) || (midZ >= 3500)) {
+ return;
+ }
+
+ // calculate x'
+ int midX = ((relativeZ * sinEyeYaw) + (relativeX * cosEyeYaw)) >> 16;
+
+ // calculate left bound
+ int leftX = (midX - radius) << 9;
+
+ // early fail
+ if ((leftX / maxZ) >= Draw2D.centerX) {
+ return;
+ }
+
+ // calculate right bound
+ int rightX = (midX + radius) << 9;
+
+ // early fail
+ if ((rightX / maxZ) <= -Draw2D.centerX) {
+ return;
+ }
+
+ // midY is our relative y value rotated by eye pitch
+ int midY = ((relativeY * cosEyePitch) - (zPrime * sinEyePitch)) >> 16;
+
+ // Our pitch is clamped between 128 and 384 (22.5 degrees and 67.5 degrees)
+ // We know this will be positive and within 38->92% its original value.
+ int radiusSinEyePitch = (radius * sinEyePitch) >> 16;
+
+ // calculate bottom bound
+ int bottomY = (midY + radiusSinEyePitch) << 9;
+
+ // early fail
+ if ((bottomY / maxZ) <= -Draw2D.centerY) {
+ return;
+ }
+
+ // y' = (radius * sin(eyePitch)) + (minY * cos(eyePitch))
+ int yPrime = radiusSinEyePitch + ((super.minY * cosEyePitch) >> 16);
+
+ // calculate top boundary
+ int topY = (midY - yPrime) << 9;
+
+ // early fail
+ if ((topY / maxZ) >= Draw2D.centerY) {
+ return;
+ }
+
+ // (minY * sin(eyePitch)) + (radius * cos(eyePitch))
+ int radiusZ = ((super.minY * sinEyePitch) >> 16) + radiusCosEyePitch;
+
+ boolean clipped = (midZ - radiusZ) <= 50;
+ boolean picking = false;
+
+ if ((bitset > 0) && Model.checkHover) {
+ int z = midZ - radiusCosEyePitch;
+
+ if (z <= 50) {
+ z = 50;
+ }
+
+ if (midX > 0) {
+ leftX /= maxZ;
+ rightX /= z;
+ } else {
+ rightX /= maxZ;
+ leftX /= z;
+ }
+
+ if (midY > 0) {
+ topY /= maxZ;
+ bottomY /= z;
+ } else {
+ bottomY /= maxZ;
+ topY /= z;
+ }
+
+ int mouseX = Model.mouseX - Draw3D.centerX;
+ int mouseY = Model.mouseY - Draw3D.centerY;
+
+ if ((mouseX > leftX) && (mouseX < rightX) && (mouseY > topY) && (mouseY < bottomY)) {
+ if (pickable) {
+ pickedBitsets[pickedCount++] = bitset;
+ } else {
+ picking = true;
+ }
+ }
+ }
+
+ int centerX = Draw3D.centerX;
+ int centerY = Draw3D.centerY;
+ int sinYaw = 0;
+ int cosYaw = 0;
+
+ if (yaw != 0) {
+ sinYaw = sin[yaw];
+ cosYaw = cos[yaw];
+ }
+
+ for (int v = 0; v < vertexCount; v++) {
+ int x = vertexX[v];
+ int y = vertexY[v];
+ int z = vertexZ[v];
+
+ // Local Space -> Model Space
+
+ if (yaw != 0) {
+ int x_ = ((z * sinYaw) + (x * cosYaw)) >> 16;
+ z = ((z * cosYaw) - (x * sinYaw)) >> 16;
+ x = x_;
+ }
+
+ // Model Space -> View Space
+
+ x += relativeX;
+ y += relativeY;
+ z += relativeZ;
+
+ // Rotate on Y axis (Yaw)
+ int tmp = ((z * sinEyeYaw) + (x * cosEyeYaw)) >> 16;
+ z = ((z * cosEyeYaw) - (x * sinEyeYaw)) >> 16;
+ x = tmp;
+
+ // Rotate on X axis (Pitch)
+ tmp = ((y * cosEyePitch) - (z * sinEyePitch)) >> 16;
+ z = ((y * sinEyePitch) + (z * cosEyePitch)) >> 16;
+ y = tmp;
+
+ if (z >= 50) {
+ vertexScreenX[v] = centerX + ((x << 9) / z);
+ vertexScreenY[v] = centerY + ((y << 9) / z);
+ } else {
+ vertexScreenX[v] = -5000; // used in drawTriangle to denote a near-clipped triangle.
+ clipped = true;
+ }
+
+ vertexScreenZ[v] = z - midZ;
+
+ if (clipped || (texturedFaceCount > 0)) {
+ vertexViewSpaceX[v] = x;
+ vertexViewSpaceY[v] = y;
+ vertexViewSpaceZ[v] = z;
+ }
+ }
+ try {
+ draw(clipped, picking, bitset);
+ } catch (Exception ignored) {
+ }
+ }
+
+ /**
+ * Draws the {@link Model} with the provided parameters. This method performs depth and priority sorting.
+ *
+ * @param clipped whether to check near plane clipping.
+ * @param picking true to enable picking.
+ * @param bitset the bitset. Used with pick set to true.
+ */
+ public void draw(boolean clipped, boolean picking, int bitset) {
+ for (int depth = 0; depth < maxDepth; depth++) {
+ tmpDepthFaceCount[depth] = 0;
+ }
+
+ for (int f = 0; f < faceCount; f++) {
+ if ((faceInfo != null) && (faceInfo[f] == -1)) {
+ continue;
+ }
+
+ int a = faceVertexA[f];
+ int b = faceVertexB[f];
+ int c = faceVertexC[f];
+ int xA = vertexScreenX[a];
+ int xB = vertexScreenX[b];
+ int xC = vertexScreenX[c];
+
+ if (clipped && ((xA == -5000) || (xB == -5000) || (xC == -5000))) {
+ faceNearClipped[f] = true;
+ int depthAverage = ((vertexScreenZ[a] + vertexScreenZ[b] + vertexScreenZ[c]) / 3) + minDepth;
+ tmpDepthFaces[depthAverage][tmpDepthFaceCount[depthAverage]++] = f;
+ } else {
+ if (picking && pointWithinTriangle(mouseX, mouseY, vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], xA, xB, xC)) {
+ pickedBitsets[pickedCount++] = bitset;
+ picking = false;
+ }
+
+ // Back-face culling
+ int dxAB = xA - xB;
+ int dyAB = vertexScreenY[a] - vertexScreenY[b];
+ int dxCB = xC - xB;
+ int dyCB = vertexScreenY[c] - vertexScreenY[b];
+
+ if (((dxAB * dyCB) - (dyAB * dxCB)) <= 0) {
+ continue;
+ }
+
+ faceNearClipped[f] = false;
+ faceClippedX[f] = (xA < 0) || (xB < 0) || (xC < 0) || (xA > Draw2D.boundX) || (xB > Draw2D.boundX) || (xC > Draw2D.boundX);
+
+ int depthAverage = ((vertexScreenZ[a] + vertexScreenZ[b] + vertexScreenZ[c]) / 3) + minDepth;
+ tmpDepthFaces[depthAverage][tmpDepthFaceCount[depthAverage]++] = f;
+ }
+ }
+
+ if (facePriority == null) {
+ for (int depth = maxDepth - 1; depth >= 0; depth--) {
+ int count = tmpDepthFaceCount[depth];
+ if (count > 0) {
+ int[] faces = tmpDepthFaces[depth];
+ for (int f = 0; f < count; f++) {
+ drawFace(faces[f]);
+ }
+ }
+ }
+ return;
+ }
+
+ for (int priority = 0; priority < 12; priority++) {
+ Model.tmpPriorityFaceCount[priority] = 0;
+ tmpPriorityDepthSum[priority] = 0;
+ }
+
+ for (int depth = maxDepth - 1; depth >= 0; depth--) {
+ int faceCount = tmpDepthFaceCount[depth];
+
+ if (faceCount <= 0) {
+ continue;
+ }
+
+ int[] faces = tmpDepthFaces[depth];
+
+ for (int i = 0; i < faceCount; i++) {
+ int face = faces[i];
+ int priority = facePriority[face];
+ int count = Model.tmpPriorityFaceCount[priority]++;
+ Model.tmpPriorityFaces[priority][count] = face;
+
+ if (priority < 10) {
+ tmpPriorityDepthSum[priority] += depth;
+ } else if (priority == 10) {
+ tmpPriority10FaceDepth[count] = depth;
+ } else {
+ tmpPriority11FaceDepth[count] = depth;
+ }
+ }
+ }
+
+ // These are as the name implies, the average depth between two priorities.
+ int averagePriorityDepth1_2 = 0;
+ int averagePriorityDepth3_4 = 0;
+ int averagePriorityDepth6_8 = 0;
+
+ // Don't think too hard about it. It's just a way of calculating averages with integers but with two sums averaged together.
+
+ if ((Model.tmpPriorityFaceCount[1] > 0) || (Model.tmpPriorityFaceCount[2] > 0)) {
+ averagePriorityDepth1_2 = (tmpPriorityDepthSum[1] + tmpPriorityDepthSum[2]) / (Model.tmpPriorityFaceCount[1] + Model.tmpPriorityFaceCount[2]);
+ }
+
+ if ((Model.tmpPriorityFaceCount[3] > 0) || (Model.tmpPriorityFaceCount[4] > 0)) {
+ averagePriorityDepth3_4 = (tmpPriorityDepthSum[3] + tmpPriorityDepthSum[4]) / (Model.tmpPriorityFaceCount[3] + Model.tmpPriorityFaceCount[4]);
+ }
+
+ if ((Model.tmpPriorityFaceCount[6] > 0) || (Model.tmpPriorityFaceCount[8] > 0)) {
+ averagePriorityDepth6_8 = (tmpPriorityDepthSum[6] + tmpPriorityDepthSum[8]) / (Model.tmpPriorityFaceCount[6] + Model.tmpPriorityFaceCount[8]);
+ }
+
+ int priorityFace = 0;
+ int priorityFaceCount = Model.tmpPriorityFaceCount[10];
+ int[] priorityFaces = Model.tmpPriorityFaces[10];
+ int[] priorityFaceDepths = tmpPriority10FaceDepth;
+
+ if (priorityFace == priorityFaceCount) {
+ priorityFace = 0;
+ priorityFaceCount = Model.tmpPriorityFaceCount[11];
+ priorityFaces = Model.tmpPriorityFaces[11];
+ priorityFaceDepths = tmpPriority11FaceDepth;
+ }
+
+ int priorityDepth;
+ if (priorityFace < priorityFaceCount) {
+ priorityDepth = priorityFaceDepths[priorityFace];
+ } else {
+ priorityDepth = -1000;
+ }
+
+ // The code below essentially gives priorities 10 and 11 a chance to draw during priorities 0, 3, and 5 as long
+ // as the current face depth is slightly deeper than the current priority depth. You can think of that slightly
+ // deeper concept as a threshold to allow lower priority triangles to draw on top of higher priority triangles.
+
+ // If they didn't do this then higher priority triangles would always draw on top, which look weird.
+
+ for (int priority = 0; priority < 10; priority++) {
+ while ((priority == 0) && (priorityDepth > averagePriorityDepth1_2)) {
+ drawFace(priorityFaces[priorityFace++]);
+
+ if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
+ priorityFace = 0;
+ priorityFaceCount = Model.tmpPriorityFaceCount[11];
+ priorityFaces = Model.tmpPriorityFaces[11];
+ priorityFaceDepths = tmpPriority11FaceDepth;
+ }
+
+ if (priorityFace < priorityFaceCount) {
+ priorityDepth = priorityFaceDepths[priorityFace];
+ } else {
+ priorityDepth = -1000;
+ }
+ }
+
+ while ((priority == 3) && (priorityDepth > averagePriorityDepth3_4)) {
+ drawFace(priorityFaces[priorityFace++]);
+
+ if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
+ priorityFace = 0;
+ priorityFaceCount = Model.tmpPriorityFaceCount[11];
+ priorityFaces = Model.tmpPriorityFaces[11];
+ priorityFaceDepths = tmpPriority11FaceDepth;
+ }
+
+ if (priorityFace < priorityFaceCount) {
+ priorityDepth = priorityFaceDepths[priorityFace];
+ } else {
+ priorityDepth = -1000;
+ }
+ }
+
+ while ((priority == 5) && (priorityDepth > averagePriorityDepth6_8)) {
+ drawFace(priorityFaces[priorityFace++]);
+
+ if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
+ priorityFace = 0;
+ priorityFaceCount = Model.tmpPriorityFaceCount[11];
+ priorityFaces = Model.tmpPriorityFaces[11];
+ priorityFaceDepths = tmpPriority11FaceDepth;
+ }
+
+ if (priorityFace < priorityFaceCount) {
+ priorityDepth = priorityFaceDepths[priorityFace];
+ } else {
+ priorityDepth = -1000;
+ }
+ }
+
+ int count = Model.tmpPriorityFaceCount[priority];
+ int[] faces = Model.tmpPriorityFaces[priority];
+
+ for (int i = 0; i < count; i++) {
+ drawFace(faces[i]);
+ }
+ }
+
+ // finish off remaining faces (priorities 10 and 11)
+
+ while (priorityDepth != -1000) {
+ drawFace(priorityFaces[priorityFace++]);
+
+ if ((priorityFace == priorityFaceCount) && (priorityFaces != Model.tmpPriorityFaces[11])) {
+ priorityFace = 0;
+ priorityFaces = Model.tmpPriorityFaces[11];
+ priorityFaceCount = Model.tmpPriorityFaceCount[11];
+ priorityFaceDepths = tmpPriority11FaceDepth;
+ }
+
+ if (priorityFace < priorityFaceCount) {
+ priorityDepth = priorityFaceDepths[priorityFace];
+ } else {
+ priorityDepth = -1000;
+ }
+ }
+ }
+
+ /**
+ * Draws the provided face id.
+ *
+ * @param face the face id.
+ */
+ public void drawFace(int face) {
+ if (faceNearClipped[face]) {
+ drawNearClippedFace(face);
+ return;
+ }
+
+ int a = faceVertexA[face];
+ int b = faceVertexB[face];
+ int c = faceVertexC[face];
+ Draw3D.clipX = faceClippedX[face];
+
+ if (faceAlpha == null) {
+ Draw3D.alpha = 0;
+ } else {
+ Draw3D.alpha = faceAlpha[face];
+ }
+
+ int type;
+
+ if (faceInfo == null) {
+ type = 0;
+ } else {
+ type = faceInfo[face] & 0b11;
+ }
+
+ if (type == 0) {
+ Draw3D.fillGouraudTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], faceColorA[face], faceColorB[face], faceColorC[face]);
+ } else if (type == 1) {
+ Draw3D.fillTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], palette[faceColorA[face]]);
+ } else if (type == 2) {
+ int texturedFace = faceInfo[face] >> 2;
+ int ta = texturedVertexA[texturedFace];
+ int tb = texturedVertexB[texturedFace];
+ int tc = texturedVertexC[texturedFace];
+ Draw3D.fillTexturedTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], faceColorA[face], faceColorB[face], faceColorC[face], vertexViewSpaceX[ta], vertexViewSpaceX[tb], vertexViewSpaceX[tc], vertexViewSpaceY[ta], vertexViewSpaceY[tb], vertexViewSpaceY[tc], vertexViewSpaceZ[ta], vertexViewSpaceZ[tb], vertexViewSpaceZ[tc], faceColor[face]);
+ } else if (type == 3) {
+ int texturedFace = faceInfo[face] >> 2;
+ int ta = texturedVertexA[texturedFace];
+ int tb = texturedVertexB[texturedFace];
+ int tc = texturedVertexC[texturedFace];
+ Draw3D.fillTexturedTriangle(vertexScreenY[a], vertexScreenY[b], vertexScreenY[c], vertexScreenX[a], vertexScreenX[b], vertexScreenX[c], faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[ta], vertexViewSpaceX[tb], vertexViewSpaceX[tc], vertexViewSpaceY[ta], vertexViewSpaceY[tb], vertexViewSpaceY[tc], vertexViewSpaceZ[ta], vertexViewSpaceZ[tb], vertexViewSpaceZ[tc], faceColor[face]);
+ }
+ }
+
+ /**
+ * Draws the provided face id assuming it has been clipped by the near Z plane.
+ *
+ * @param face the face id.
+ */
+ public void drawNearClippedFace(int face) {
+ int centerX = Draw3D.centerX;
+ int centerY = Draw3D.centerY;
+ int elements = 0;
+
+ int a = faceVertexA[face];
+ int b = faceVertexB[face];
+ int c = faceVertexC[face];
+
+ int zA = vertexViewSpaceZ[a];
+ int zB = vertexViewSpaceZ[b];
+ int zC = vertexViewSpaceZ[c];
+
+ if (zA >= 50) {
+ clippedX[elements] = vertexScreenX[a];
+ clippedY[elements] = vertexScreenY[a];
+ clippedColor[elements++] = faceColorA[face];
+ } else {
+ int xA = vertexViewSpaceX[a];
+ int yA = vertexViewSpaceY[a];
+ int colorA = faceColorA[face];
+
+ if (zC >= 50) {
+ int scalar = (50 - zA) * reciprical16[zC - zA];
+ clippedX[elements] = centerX + (((xA + (((vertexViewSpaceX[c] - xA) * scalar) >> 16)) << 9) / 50);
+ clippedY[elements] = centerY + (((yA + (((vertexViewSpaceY[c] - yA) * scalar) >> 16)) << 9) / 50);
+ clippedColor[elements++] = colorA + (((faceColorC[face] - colorA) * scalar) >> 16);
+ }
+
+ if (zB >= 50) {
+ int scalar = (50 - zA) * reciprical16[zB - zA];
+ clippedX[elements] = centerX + (((xA + (((vertexViewSpaceX[b] - xA) * scalar) >> 16)) << 9) / 50);
+ clippedY[elements] = centerY + (((yA + (((vertexViewSpaceY[b] - yA) * scalar) >> 16)) << 9) / 50);
+ clippedColor[elements++] = colorA + (((faceColorB[face] - colorA) * scalar) >> 16);
+ }
+ }
+
+ if (zB >= 50) {
+ clippedX[elements] = vertexScreenX[b];
+ clippedY[elements] = vertexScreenY[b];
+ clippedColor[elements++] = faceColorB[face];
+ } else {
+ int xB = vertexViewSpaceX[b];
+ int yB = vertexViewSpaceY[b];
+ int colorB = faceColorB[face];
+
+ if (zA >= 50) {
+ int scalar = (50 - zB) * reciprical16[zA - zB];
+ clippedX[elements] = centerX + (((xB + (((vertexViewSpaceX[a] - xB) * scalar) >> 16)) << 9) / 50);
+ clippedY[elements] = centerY + (((yB + (((vertexViewSpaceY[a] - yB) * scalar) >> 16)) << 9) / 50);
+ clippedColor[elements++] = colorB + (((faceColorA[face] - colorB) * scalar) >> 16);
+ }
+
+ if (zC >= 50) {
+ int scalar = (50 - zB) * reciprical16[zC - zB];
+ clippedX[elements] = centerX + (((xB + (((vertexViewSpaceX[c] - xB) * scalar) >> 16)) << 9) / 50);
+ clippedY[elements] = centerY + (((yB + (((vertexViewSpaceY[c] - yB) * scalar) >> 16)) << 9) / 50);
+ clippedColor[elements++] = colorB + (((faceColorC[face] - colorB) * scalar) >> 16);
+ }
+ }
+
+ if (zC >= 50) {
+ clippedX[elements] = vertexScreenX[c];
+ clippedY[elements] = vertexScreenY[c];
+ clippedColor[elements++] = faceColorC[face];
+ } else {
+ int xC = vertexViewSpaceX[c];
+ int yC = vertexViewSpaceY[c];
+ int colorC = faceColorC[face];
+
+ if (zB >= 50) {
+ int k6 = (50 - zC) * reciprical16[zB - zC];
+ clippedX[elements] = centerX + (((xC + (((vertexViewSpaceX[b] - xC) * k6) >> 16)) << 9) / 50);
+ clippedY[elements] = centerY + (((yC + (((vertexViewSpaceY[b] - yC) * k6) >> 16)) << 9) / 50);
+ clippedColor[elements++] = colorC + (((faceColorB[face] - colorC) * k6) >> 16);
+ }
+
+ if (zA >= 50) {
+ int l6 = (50 - zC) * reciprical16[zA - zC];
+ clippedX[elements] = centerX + (((xC + (((vertexViewSpaceX[a] - xC) * l6) >> 16)) << 9) / 50);
+ clippedY[elements] = centerY + (((yC + (((vertexViewSpaceY[a] - yC) * l6) >> 16)) << 9) / 50);
+ clippedColor[elements++] = colorC + (((faceColorA[face] - colorC) * l6) >> 16);
+ }
+ }
+
+ int x0 = clippedX[0];
+ int x1 = clippedX[1];
+ int x2 = clippedX[2];
+ int y0 = clippedY[0];
+ int y1 = clippedY[1];
+ int y2 = clippedY[2];
+
+ // Back-face culling
+ if ((((x0 - x1) * (y2 - y1)) - ((y0 - y1) * (x2 - x1))) <= 0) {
+ return;
+ }
+
+ Draw3D.clipX = false;
+
+ // It's possible for a single triangle to be clipped into two separate triangles.
+
+ if (elements == 3) {
+ if ((x0 < 0) || (x1 < 0) || (x2 < 0) || (x0 > Draw2D.boundX) || (x1 > Draw2D.boundX) || (x2 > Draw2D.boundX)) {
+ Draw3D.clipX = true;
+ }
+
+ int type;
+
+ if (faceInfo == null) {
+ type = 0;
+ } else {
+ type = faceInfo[face] & 3;
+ }
+
+ if (type == 0) {
+ Draw3D.fillGouraudTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2]);
+ } else if (type == 1) {
+ Draw3D.fillTriangle(y0, y1, y2, x0, x1, x2, palette[faceColorA[face]]);
+ } else if (type == 2) {
+ int texturedFace = faceInfo[face] >> 2;
+ int tA = texturedVertexA[texturedFace];
+ int tB = texturedVertexB[texturedFace];
+ int tC = texturedVertexC[texturedFace];
+ Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
+ } else if (type == 3) {
+ int texturedFace = faceInfo[face] >> 2;
+ int tA = texturedVertexA[texturedFace];
+ int tB = texturedVertexB[texturedFace];
+ int tC = texturedVertexC[texturedFace];
+ Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
+ }
+ } else if (elements == 4) {
+ if ((x0 < 0) || (x1 < 0) || (x2 < 0) || (x0 > Draw2D.boundX) || (x1 > Draw2D.boundX) || (x2 > Draw2D.boundX) || (clippedX[3] < 0) || (clippedX[3] > Draw2D.boundX)) {
+ Draw3D.clipX = true;
+ }
+
+ int type;
+
+ if (faceInfo == null) {
+ type = 0;
+ } else {
+ type = faceInfo[face] & 3;
+ }
+
+ if (type == 0) {
+ Draw3D.fillGouraudTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2]);
+ Draw3D.fillGouraudTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], clippedColor[0], clippedColor[2], clippedColor[3]);
+ } else if (type == 1) {
+ int colorA = palette[faceColorA[face]];
+ Draw3D.fillTriangle(y0, y1, y2, x0, x1, x2, colorA);
+ Draw3D.fillTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], colorA);
+ } else if (type == 2) {
+ int texturedFace = faceInfo[face] >> 2;
+ int tA = texturedVertexA[texturedFace];
+ int tB = texturedVertexB[texturedFace];
+ int tC = texturedVertexC[texturedFace];
+ Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, clippedColor[0], clippedColor[1], clippedColor[2], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
+ Draw3D.fillTexturedTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], clippedColor[0], clippedColor[2], clippedColor[3], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
+ } else if (type == 3) {
+ int texturedFace = faceInfo[face] >> 2;
+ int tA = texturedVertexA[texturedFace];
+ int tB = texturedVertexB[texturedFace];
+ int tC = texturedVertexC[texturedFace];
+ Draw3D.fillTexturedTriangle(y0, y1, y2, x0, x1, x2, faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
+ Draw3D.fillTexturedTriangle(y0, y2, clippedY[3], x0, x2, clippedX[3], faceColorA[face], faceColorA[face], faceColorA[face], vertexViewSpaceX[tA], vertexViewSpaceX[tB], vertexViewSpaceX[tC], vertexViewSpaceY[tA], vertexViewSpaceY[tB], vertexViewSpaceY[tC], vertexViewSpaceZ[tA], vertexViewSpaceZ[tB], vertexViewSpaceZ[tC], faceColor[face]);
+ }
+ }
+ }
+
+ /**
+ * Utility function. Checks if (x, y) is within the provided triangle.
+ *
+ * @param x the x.
+ * @param y the y.
+ * @param yA y of corner a.
+ * @param yB y of corner b.
+ * @param yC y of corner c.
+ * @param xA x of corner a.
+ * @param xB x of corner b.
+ * @param xC x of corner c.
+ * @return true if (x, y) is within the triangle.
+ */
+ public boolean pointWithinTriangle(int x, int y, int yA, int yB, int yC, int xA, int xB, int xC) {
+ if ((y < yA) && (y < yB) && (y < yC)) {
+ return false;
+ }
+ if ((y > yA) && (y > yB) && (y > yC)) {
+ return false;
+ }
+ if ((x < xA) && (x < xB) && (x < xC)) {
+ return false;
+ }
+ return (x <= xA) || (x <= xB) || (x <= xC);
+ }
}
diff --git a/src/main/java/MouseRecorder.java b/src/main/java/MouseRecorder.java
index f303620..b09d3f5 100644
--- a/src/main/java/MouseRecorder.java
+++ b/src/main/java/MouseRecorder.java
@@ -4,32 +4,32 @@
public class MouseRecorder implements Runnable {
- public final Object lock = new Object();
- public final Game game;
- public final int[] y = new int[500];
- public final int[] x = new int[500];
- public boolean active = true;
- public int length;
+ public final Object lock = new Object();
+ public final Game game;
+ public final int[] y = new int[500];
+ public final int[] x = new int[500];
+ public boolean active = true;
+ public int length;
- public MouseRecorder(Game game) {
- this.game = game;
- }
+ public MouseRecorder(Game game) {
+ this.game = game;
+ }
- @Override
- public void run() {
- while (active) {
- synchronized (lock) {
- if (length < 500) {
- x[length] = game.mouseX;
- y[length] = game.mouseY;
- length++;
- }
- }
- try {
- Thread.sleep(50L);
- } catch (Exception ignored) {
- }
- }
- }
+ @Override
+ public void run() {
+ while (active) {
+ synchronized (lock) {
+ if (length < 500) {
+ x[length] = game.mouseX;
+ y[length] = game.mouseY;
+ length++;
+ }
+ }
+ try {
+ Thread.sleep(50L);
+ } catch (Exception ignored) {
+ }
+ }
+ }
}
diff --git a/src/main/java/NPCEntity.java b/src/main/java/NPCEntity.java
index 05a4ef1..56cd97a 100644
--- a/src/main/java/NPCEntity.java
+++ b/src/main/java/NPCEntity.java
@@ -4,76 +4,76 @@
public class NPCEntity extends PathingEntity {
- public NPCType type;
+ public NPCType type;
- public NPCEntity() {
- }
+ public NPCEntity() {
+ }
- public Model getSequencedModel() {
- if ((super.primarySeqID >= 0) && (super.primarySeqDelay == 0)) {
- int primaryTransformID = SeqType.instances[super.primarySeqID].transformIDs[super.primarySeqFrame];
- int secondaryTransformID = -1;
- if ((super.secondarySeqID >= 0) && (super.secondarySeqID != super.seqStandID)) {
- secondaryTransformID = SeqType.instances[super.secondarySeqID].transformIDs[super.secondarySeqFrame];
- }
- return type.getSequencedModel(secondaryTransformID, primaryTransformID, SeqType.instances[super.primarySeqID].mask);
- }
+ public Model getSequencedModel() {
+ if ((super.primarySeqID >= 0) && (super.primarySeqDelay == 0)) {
+ int primaryTransformID = SeqType.instances[super.primarySeqID].transformIDs[super.primarySeqFrame];
+ int secondaryTransformID = -1;
+ if ((super.secondarySeqID >= 0) && (super.secondarySeqID != super.seqStandID)) {
+ secondaryTransformID = SeqType.instances[super.secondarySeqID].transformIDs[super.secondarySeqFrame];
+ }
+ return type.getSequencedModel(secondaryTransformID, primaryTransformID, SeqType.instances[super.primarySeqID].mask);
+ }
- int transformID = -1;
+ int transformID = -1;
- if (super.secondarySeqID >= 0) {
- transformID = SeqType.instances[super.secondarySeqID].transformIDs[super.secondarySeqFrame];
- }
+ if (super.secondarySeqID >= 0) {
+ transformID = SeqType.instances[super.secondarySeqID].transformIDs[super.secondarySeqFrame];
+ }
- return type.getSequencedModel(-1, transformID, null);
- }
+ return type.getSequencedModel(-1, transformID, null);
+ }
- @Override
- public Model getModel() {
- if (type == null) {
- return null;
- }
+ @Override
+ public Model getModel() {
+ if (type == null) {
+ return null;
+ }
- Model model = getSequencedModel();
+ Model model = getSequencedModel();
- if (model == null) {
- return null;
- }
+ if (model == null) {
+ return null;
+ }
- super.height = model.minY;
+ super.height = model.minY;
- if ((super.spotanimID != -1) && (super.spotanimFrame != -1)) {
- SpotAnimType spotanim = SpotAnimType.instances[super.spotanimID];
- Model model0 = spotanim.getModel();
+ if ((super.spotanimID != -1) && (super.spotanimFrame != -1)) {
+ SpotAnimType spotanim = SpotAnimType.instances[super.spotanimID];
+ Model model0 = spotanim.getModel();
- if (model0 != null) {
- int transformID = spotanim.seq.transformIDs[super.spotanimFrame];
+ if (model0 != null) {
+ int transformID = spotanim.seq.transformIDs[super.spotanimFrame];
- // create a copy of the model
- Model model1 = new Model(true, SeqTransform.isNull(transformID), false, model0);
- model1.translate(0, -super.spotanimOffset, 0);
- model1.createLabelReferences();
- model1.applyTransform(transformID);
- model1.labelFaces = null;
- model1.labelVertices = null;
+ // create a copy of the model
+ Model model1 = new Model(true, SeqTransform.isNull(transformID), false, model0);
+ model1.translate(0, -super.spotanimOffset, 0);
+ model1.createLabelReferences();
+ model1.applyTransform(transformID);
+ model1.labelFaces = null;
+ model1.labelVertices = null;
- if ((spotanim.scaleXY != 128) || (spotanim.scaleZ != 128)) {
- model1.scale(spotanim.scaleXY, spotanim.scaleXY, spotanim.scaleZ);
- }
+ if ((spotanim.scaleXY != 128) || (spotanim.scaleZ != 128)) {
+ model1.scale(spotanim.scaleXY, spotanim.scaleXY, spotanim.scaleZ);
+ }
- model1.calculateNormals(64 + spotanim.lightAmbient, 850 + spotanim.lightAttenuation, -30, -50, -30, true);
- model = new Model(2, -819, new Model[]{model, model1});
- }
- }
- if (type.size == 1) {
- model.pickable = true;
- }
- return model;
- }
+ model1.calculateNormals(64 + spotanim.lightAmbient, 850 + spotanim.lightAttenuation, -30, -50, -30, true);
+ model = new Model(2, -819, new Model[]{model, model1});
+ }
+ }
+ if (type.size == 1) {
+ model.pickable = true;
+ }
+ return model;
+ }
- @Override
- public boolean isVisible() {
- return type != null;
- }
+ @Override
+ public boolean isVisible() {
+ return type != null;
+ }
}
diff --git a/src/main/java/NPCType.java b/src/main/java/NPCType.java
index c84b4cb..f4a54b1 100644
--- a/src/main/java/NPCType.java
+++ b/src/main/java/NPCType.java
@@ -321,7 +321,7 @@ public class NPCType {
for (int i = 0; i <= overrideCount; i++) {
overrides[i] = buffer.read16U();
-
+
if (overrides[i] == 65535) {
overrides[i] = -1;
}
diff --git a/src/main/java/ObjEntity.java b/src/main/java/ObjEntity.java
index d4fde35..f44a2aa 100644
--- a/src/main/java/ObjEntity.java
+++ b/src/main/java/ObjEntity.java
@@ -4,16 +4,16 @@
public class ObjEntity extends Entity {
- public int id;
- public int count;
+ public int id;
+ public int count;
- public ObjEntity() {
- }
+ public ObjEntity() {
+ }
- @Override
- public Model getModel() {
- ObjType type = ObjType.get(id);
- return type.getModel(count);
- }
+ @Override
+ public Model getModel() {
+ ObjType type = ObjType.get(id);
+ return type.getModel(count);
+ }
}
diff --git a/src/main/java/OnDemand.java b/src/main/java/OnDemand.java
index 3020fff..cef80a6 100644
--- a/src/main/java/OnDemand.java
+++ b/src/main/java/OnDemand.java
@@ -10,701 +10,701 @@ import java.util.zip.CRC32;
public class OnDemand implements Runnable {
- public final DoublyLinkedList pending = new DoublyLinkedList();
- public final CRC32 crc32 = new CRC32();
- public final byte[] bbuf = new byte[500];
- public final byte[][] storeFilePriorities = new byte[4][];
- public final DoublyLinkedList aList_1344 = new DoublyLinkedList();
- public final DoublyLinkedList completed = new DoublyLinkedList();
- public final byte[] aByteArray1359 = new byte[65000];
- public final LinkedListtrue if the loc models are ready.
*/
public static boolean isLocReady(int locID, int kind) {
@@ -341,7 +341,8 @@ public class SceneBuilder {
* 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
* eventually invokes {@link Model#validate(int)} which causes the {@link OnDemand} to do its job.
- * @param data the data
+ *
+ * @param data the data
* @param originX the region origin x in the scene.
* @param originZ the region origin z in the scene.
* @return true if all locs are valid.
@@ -890,8 +891,9 @@ public class SceneBuilder {
/**
* Flattens the perimeter of the provided area.
- * @param tileX the area x.
- * @param tileZ the area z.
+ *
+ * @param tileX the area x.
+ * @param tileZ the area z.
* @param tileSizeX the area size x.
* @param tileSizeZ the area size z.
*/
diff --git a/src/main/java/SceneGroundDecoration.java b/src/main/java/SceneGroundDecoration.java
index b0ae7b3..43d903a 100644
--- a/src/main/java/SceneGroundDecoration.java
+++ b/src/main/java/SceneGroundDecoration.java
@@ -4,14 +4,14 @@
public class SceneGroundDecoration {
- public int y;
- public int x;
- public int z;
- public Entity entity;
- public int bitset;
- public byte info;
+ public int y;
+ public int x;
+ public int z;
+ public Entity entity;
+ public int bitset;
+ public byte info;
- public SceneGroundDecoration() {
- }
+ public SceneGroundDecoration() {
+ }
}
diff --git a/src/main/java/SceneLoc.java b/src/main/java/SceneLoc.java
index 1e8c167..e536aef 100644
--- a/src/main/java/SceneLoc.java
+++ b/src/main/java/SceneLoc.java
@@ -4,26 +4,26 @@
public class SceneLoc {
- public int level;
- public int y;
- public int x;
- public int z;
- public Entity entity;
- public int yaw;
- public int minSceneTileX;
- public int maxSceneTileX;
- public int minSceneTileZ;
- public int maxSceneTileZ;
- public int distance;
- public int cycle;
- public int bitset;
- public byte info;
+ public int level;
+ public int y;
+ public int x;
+ public int z;
+ public Entity entity;
+ public int yaw;
+ public int minSceneTileX;
+ public int maxSceneTileX;
+ public int minSceneTileZ;
+ public int maxSceneTileZ;
+ public int distance;
+ public int cycle;
+ public int bitset;
+ public byte info;
- public boolean drawn() {
- return cycle == Scene.cycle;
- }
+ public boolean drawn() {
+ return cycle == Scene.cycle;
+ }
- public SceneLoc() {
- }
+ public SceneLoc() {
+ }
}
diff --git a/src/main/java/SceneLocTemporary.java b/src/main/java/SceneLocTemporary.java
index 039353e..9382284 100644
--- a/src/main/java/SceneLocTemporary.java
+++ b/src/main/java/SceneLocTemporary.java
@@ -4,21 +4,21 @@
public class SceneLocTemporary extends DoublyLinkedList.Node {
- public int id;
- public int rotation;
- public int kind;
- public int duration;
- public int level;
- public int classID;
- public int localX;
- public int localZ;
- public int previousLocID;
- public int previousRotation;
- public int previousKind;
- public int delay;
+ public int id;
+ public int rotation;
+ public int kind;
+ public int duration;
+ public int level;
+ public int classID;
+ public int localX;
+ public int localZ;
+ public int previousLocID;
+ public int previousRotation;
+ public int previousKind;
+ public int delay;
- public SceneLocTemporary() {
- duration = -1;
- }
+ public SceneLocTemporary() {
+ duration = -1;
+ }
}
diff --git a/src/main/java/SceneObjStack.java b/src/main/java/SceneObjStack.java
index 93a6db7..212d5bd 100644
--- a/src/main/java/SceneObjStack.java
+++ b/src/main/java/SceneObjStack.java
@@ -4,16 +4,16 @@
public class SceneObjStack {
- public int y;
- public int x;
- public int z;
- public Entity topObj;
- public Entity bottomObj;
- public Entity middleObj;
- public int bitset;
- public int offset;
+ public int y;
+ public int x;
+ public int z;
+ public Entity topObj;
+ public Entity bottomObj;
+ public Entity middleObj;
+ public int bitset;
+ public int offset;
- public SceneObjStack() {
- }
+ public SceneObjStack() {
+ }
}
diff --git a/src/main/java/SceneOccluder.java b/src/main/java/SceneOccluder.java
index dad8fae..0fadd21 100644
--- a/src/main/java/SceneOccluder.java
+++ b/src/main/java/SceneOccluder.java
@@ -4,39 +4,39 @@
public class SceneOccluder {
- /**
- * A wall occluder which runs along the X axis.
- */
- public static final int TYPE_WALL_X = 1;
- /**
- * A wall occluder which runs along the Z axis.
- */
- public static final int TYPE_WALL_Z = 2;
- /**
- * A ground occluder which covers the XZ plane.
- */
- public static final int TYPE_GROUND = 4;
+ /**
+ * A wall occluder which runs along the X axis.
+ */
+ public static final int TYPE_WALL_X = 1;
+ /**
+ * A wall occluder which runs along the Z axis.
+ */
+ public static final int TYPE_WALL_Z = 2;
+ /**
+ * A ground occluder which covers the XZ plane.
+ */
+ public static final int TYPE_GROUND = 4;
- public int minTileX;
- public int maxTileX;
- public int minTileZ;
- public int maxTileZ;
- public int type;
- public int minX;
- public int maxX;
- public int minZ;
- public int maxZ;
- public int minY;
- public int maxY;
- public int mode;
- public int minDeltaX;
- public int maxDeltaX;
- public int minDeltaZ;
- public int maxDeltaZ;
- public int minDeltaY;
- public int maxDeltaY;
+ public int minTileX;
+ public int maxTileX;
+ public int minTileZ;
+ public int maxTileZ;
+ public int type;
+ public int minX;
+ public int maxX;
+ public int minZ;
+ public int maxZ;
+ public int minY;
+ public int maxY;
+ public int mode;
+ public int minDeltaX;
+ public int maxDeltaX;
+ public int minDeltaZ;
+ public int maxDeltaZ;
+ public int minDeltaY;
+ public int maxDeltaY;
- public SceneOccluder() {
- }
+ public SceneOccluder() {
+ }
}
diff --git a/src/main/java/SceneTile.java b/src/main/java/SceneTile.java
index c2540c1..df32fdd 100644
--- a/src/main/java/SceneTile.java
+++ b/src/main/java/SceneTile.java
@@ -4,50 +4,51 @@
public class SceneTile extends DoublyLinkedList.Node {
- public final int x;
- public final int z;
- /**
- * 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 level;
- public SceneTileUnderlay underlay;
- public SceneTileOverlay overlay;
- public SceneWall wall;
- public SceneWallDecoration wallDecoration;
- public SceneGroundDecoration groundDecoration;
- public SceneObjStack objStack;
- public int locCount;
- /**
- * 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.
- * id == -1
- */
- public static boolean isNull(int id) {
- return id == -1;
- }
+ /**
+ * Syntax sugar.
+ *
+ * @param id the id
+ * @return id == -1
+ */
+ public static boolean isNull(int id) {
+ return id == -1;
+ }
- /**
- * Initializes the array of instances.
- *
- * @param count the count
- */
- public static void init(int count) {
- instances = new SeqTransform[count + 1];
- }
+ /**
+ * Initializes the array of instances.
+ *
+ * @param count the count
+ */
+ public static void init(int count) {
+ instances = new SeqTransform[count + 1];
+ }
- /**
- * Nullifies the array of instances.
- */
- public static void unload() {
- instances = null;
- }
+ /**
+ * Nullifies the array of instances.
+ */
+ public static void unload() {
+ instances = null;
+ }
- /**
- * Gets the {@link SeqTransform}
- *
- * @param id the transform id.
- * @return the {@link SeqTransform} or null if it does not exist.
- */
- public static SeqTransform get(int id) {
- if ((instances == null) || (id < 0) || (id >= instances.length)) {
- return null;
- } else {
- return instances[id];
- }
- }
+ /**
+ * Gets the {@link SeqTransform}
+ *
+ * @param id the transform id.
+ * @return the {@link SeqTransform} or null if it does not exist.
+ */
+ public static SeqTransform get(int id) {
+ if ((instances == null) || (id < 0) || (id >= instances.length)) {
+ return null;
+ } else {
+ return instances[id];
+ }
+ }
- /**
- * This method can read multiple {@link SeqTransform}s which means the input data can be all the transforms
- * related to the loaded skeleton.
- *
- * @param src the animation data.
- * @see #get(int)
- */
- public static void unpack(byte[] src) {
- Buffer offsets = new Buffer(src);
- offsets.position = src.length - 8;
+ /**
+ * This method can read multiple {@link SeqTransform}s which means the input data can be all the transforms
+ * related to the loaded skeleton.
+ *
+ * @param src the animation data.
+ * @see #get(int)
+ */
+ public static void unpack(byte[] src) {
+ Buffer offsets = new Buffer(src);
+ offsets.position = src.length - 8;
- Buffer header = new Buffer(src);
- Buffer tran1 = new Buffer(src);
- Buffer tran2 = new Buffer(src);
- Buffer del = new Buffer(src);
- Buffer skel = new Buffer(src);
+ Buffer header = new Buffer(src);
+ Buffer tran1 = new Buffer(src);
+ Buffer tran2 = new Buffer(src);
+ Buffer del = new Buffer(src);
+ Buffer skel = new Buffer(src);
- int offset = 0;
- header.position = offset;
- offset += offsets.read16U() + 2;
+ int offset = 0;
+ header.position = offset;
+ offset += offsets.read16U() + 2;
- tran1.position = offset;
- offset += offsets.read16U();
+ tran1.position = offset;
+ offset += offsets.read16U();
- tran2.position = offset;
- offset += offsets.read16U();
+ tran2.position = offset;
+ offset += offsets.read16U();
- del.position = offset;
- offset += offsets.read16U();
+ del.position = offset;
+ offset += offsets.read16U();
- skel.position = offset;
+ skel.position = offset;
- SeqSkeleton skeleton = new SeqSkeleton(skel);
+ SeqSkeleton skeleton = new SeqSkeleton(skel);
- int frameCount = header.read16U();
- int[] bases = new int[500];
- int[] x = new int[500];
- int[] y = new int[500];
- int[] z = new int[500];
+ int frameCount = header.read16U();
+ int[] bases = new int[500];
+ int[] x = new int[500];
+ int[] y = new int[500];
+ int[] z = new int[500];
- for (int i = 0; i < frameCount; i++) {
- SeqTransform transform = instances[header.read16U()] = new SeqTransform();
- transform.delay = del.read8U();
- transform.skeleton = skeleton;
+ for (int i = 0; i < frameCount; i++) {
+ SeqTransform transform = instances[header.read16U()] = new SeqTransform();
+ transform.delay = del.read8U();
+ transform.skeleton = skeleton;
- int baseCount = header.read8U();
- int lastBase = -1;
- int length = 0;
+ int baseCount = header.read8U();
+ int lastBase = -1;
+ int length = 0;
- for (int base = 0; base < baseCount; base++) {
- int flags = tran1.read8U();
+ for (int base = 0; base < baseCount; base++) {
+ int flags = tran1.read8U();
- if (flags <= 0) {
- continue;
- }
+ if (flags <= 0) {
+ continue;
+ }
- if (skeleton.baseTypes[base] != SeqSkeleton.OP_BASE) {
- // Look for any skipped ORIGIN bases and insert them into this transform.
- for (int cur = base - 1; cur > lastBase; cur--) {
- if (skeleton.baseTypes[cur] == SeqSkeleton.OP_BASE) {
- bases[length] = cur;
- x[length] = 0;
- y[length] = 0;
- z[length] = 0;
- length++;
- break;
- }
- }
- }
+ if (skeleton.baseTypes[base] != SeqSkeleton.OP_BASE) {
+ // Look for any skipped ORIGIN bases and insert them into this transform.
+ for (int cur = base - 1; cur > lastBase; cur--) {
+ if (skeleton.baseTypes[cur] == SeqSkeleton.OP_BASE) {
+ bases[length] = cur;
+ x[length] = 0;
+ y[length] = 0;
+ z[length] = 0;
+ length++;
+ break;
+ }
+ }
+ }
- bases[length] = base;
+ bases[length] = base;
- int defaultValue = 0;
+ int defaultValue = 0;
- if (skeleton.baseTypes[base] == SeqSkeleton.OP_SCALE) {
- defaultValue = 128;
- }
+ if (skeleton.baseTypes[base] == SeqSkeleton.OP_SCALE) {
+ defaultValue = 128;
+ }
- if ((flags & 1) != 0) {
- x[length] = tran2.readSmart();
- } else {
- x[length] = defaultValue;
- }
+ if ((flags & 1) != 0) {
+ x[length] = tran2.readSmart();
+ } else {
+ x[length] = defaultValue;
+ }
- if ((flags & 2) != 0) {
- y[length] = tran2.readSmart();
- } else {
- y[length] = defaultValue;
- }
+ if ((flags & 2) != 0) {
+ y[length] = tran2.readSmart();
+ } else {
+ y[length] = defaultValue;
+ }
- if ((flags & 4) != 0) {
- z[length] = tran2.readSmart();
- } else {
- z[length] = defaultValue;
- }
+ if ((flags & 4) != 0) {
+ z[length] = tran2.readSmart();
+ } else {
+ z[length] = defaultValue;
+ }
- lastBase = base;
- length++;
- }
+ lastBase = base;
+ length++;
+ }
- transform.length = length;
- transform.bases = new int[length];
- transform.x = new int[length];
- transform.y = new int[length];
- transform.z = new int[length];
+ transform.length = length;
+ transform.bases = new int[length];
+ transform.x = new int[length];
+ transform.y = new int[length];
+ transform.z = new int[length];
- for (int j = 0; j < length; j++) {
- transform.bases[j] = bases[j];
- transform.x[j] = x[j];
- transform.y[j] = y[j];
- transform.z[j] = z[j];
- }
- }
- }
+ for (int j = 0; j < length; j++) {
+ transform.bases[j] = bases[j];
+ transform.x[j] = x[j];
+ transform.y[j] = y[j];
+ transform.z[j] = z[j];
+ }
+ }
+ }
- /**
- * The skeleton associated to this transform.
- */
- public SeqSkeleton skeleton;
- /**
- * The delay in ticks.
- */
- public int delay;
- /**
- * The number of operations this transform performs.
- */
- public int length;
- /**
- * The list of bases this transform uses.
- */
- public int[] bases;
- /**
- * This transforms parameters.
- */
- public int[] x, y, z;
+ /**
+ * The skeleton associated to this transform.
+ */
+ public SeqSkeleton skeleton;
+ /**
+ * The delay in ticks.
+ */
+ public int delay;
+ /**
+ * The number of operations this transform performs.
+ */
+ public int length;
+ /**
+ * The list of bases this transform uses.
+ */
+ public int[] bases;
+ /**
+ * This transforms parameters.
+ */
+ public int[] x, y, z;
}
diff --git a/src/main/java/SeqType.java b/src/main/java/SeqType.java
index be7e787..8d54e5d 100644
--- a/src/main/java/SeqType.java
+++ b/src/main/java/SeqType.java
@@ -6,204 +6,212 @@ import java.io.IOException;
public class SeqType {
- public static int count;
- public static SeqType[] instances;
+ public static int count;
+ public static SeqType[] instances;
- public static void unpack(FileArchive archive) throws IOException {
- Buffer buffer = new Buffer(archive.read("seq.dat"));
- count = buffer.read16U();
- if (instances == null) {
- instances = new SeqType[count];
- }
+ public static void unpack(FileArchive archive) throws IOException {
+ Buffer buffer = new Buffer(archive.read("seq.dat"));
+ count = buffer.read16U();
+ if (instances == null) {
+ instances = new SeqType[count];
+ }
- for (int i = 0; i < count; i++) {
- if (instances[i] == null) {
- instances[i] = new SeqType();
- }
- instances[i].load(buffer);
- }
- }
+ for (int i = 0; i < count; i++) {
+ if (instances[i] == null) {
+ instances[i] = new SeqType();
+ }
+ instances[i].load(buffer);
+ }
+ }
- /**
- * The amount of frames in this {@link SeqType}.
- */
- public int frameCount;
+ /**
+ * The amount of frames in this {@link SeqType}.
+ */
+ public int frameCount;
- /**
- * The list of {@link SeqTransform} indices indexed by Frame ID.
- * @see SeqTransform
- */
- public int[] transformIDs;
+ /**
+ * The list of {@link SeqTransform} indices indexed by Frame ID.
+ *
+ * @see SeqTransform
+ */
+ public int[] transformIDs;
- /**
- * Auxiliary transform indices appear to only be used by a {@link IfType} of type 6 as seen in {@link Game#drawParentInterface(IfType, int, int, int)}.
- */
- public int[] auxiliaryTransformIDs;
+ /**
+ * Auxiliary transform indices appear to only be used by a {@link IfType} of type 6 as seen in {@link Game#drawParentInterface(IfType, int, int, int)}.
+ */
+ public int[] auxiliaryTransformIDs;
- /**
- * A list of durations indexed by Frame ID.
- */
- public int[] frameDuration;
+ /**
+ * A list of durations indexed by Frame ID.
+ */
+ public int[] frameDuration;
- /**
- * The number of frames from the end of this {@link SeqType} used for looping.
- */
- public int loopFrameCount = -1;
+ /**
+ * The number of frames from the end of this {@link SeqType} used for looping.
+ */
+ public int loopFrameCount = -1;
- /**
- * Used to determine which transform bases a primary frame is allowed to use, and secondary not.
- * @see Model#applyTransforms(int, int, int[])
- */
- public int[] mask;
+ /**
+ * Used to determine which transform bases a primary frame is allowed to use, and secondary not.
+ *
+ * @see Model#applyTransforms(int, int, int[])
+ */
+ public int[] mask;
- /**
- * Adds additional space to the render bounds.
- * @see Scene#addTemporary(Entity, int, int, int, int, int, int, boolean, int)
- */
- public boolean forwardRenderPadding = false;
+ /**
+ * Adds additional space to the render bounds.
+ *
+ * @see Scene#addTemporary(Entity, int, int, int, int, int, int, boolean, int)
+ */
+ public boolean forwardRenderPadding = false;
- /**
- * The priority.
- */
- public int priority = 5;
+ /**
+ * The priority.
+ */
+ public int priority = 5;
- /**
- * Allows this {@link SeqType} to override the right hand of a {@link PlayerEntity}.
- * @see PlayerEntity#getSequencedModel()
- */
- public int rightHandOverride = -1;
+ /**
+ * Allows this {@link SeqType} to override the right hand of a {@link PlayerEntity}.
+ *
+ * @see PlayerEntity#getSequencedModel()
+ */
+ public int rightHandOverride = -1;
- /**
- * Allows this {@link SeqType} to override the left hand of a {@link PlayerEntity}.
- * @see PlayerEntity#getSequencedModel()
- */
- public int leftHandOverride = -1;
+ /**
+ * Allows this {@link SeqType} to override the left hand of a {@link PlayerEntity}.
+ *
+ * @see PlayerEntity#getSequencedModel()
+ */
+ public int leftHandOverride = -1;
- /**
- * How many times this seq is allowed to loop before stopping.
- */
- public int loopCount = 99;
+ /**
+ * How many times this seq is allowed to loop before stopping.
+ */
+ public int loopCount = 99;
- /**
- * If 0, causes faster movement, allows looking at target
- * If 1, pause while moving
- * If 2, does not look at target, continues playing during movement
- * @see Game#updateMovement(PathingEntity)
- */
- public int moveStyle = -1;
-
- /**
- * If 0, allows looking at a target
- * If 1, stops playing on move
- * If 2, does not look at target, continues playing during movement
- * @see Game#updateMovement(PathingEntity)
- */
- public int idleStyle = -1;
+ /**
+ * If 0, causes faster movement, allows looking at target
+ * If 1, pause while moving
+ * If 2, does not look at target, continues playing during movement
+ *
+ * @see Game#updateMovement(PathingEntity)
+ */
+ public int moveStyle = -1;
- /**
- * If 0, restarts the sequence if already playing
- * If 1, does not restart if already playing
- * @see Game#readNPCUpdates()
- */
- public int replayStyle = 1;
+ /**
+ * If 0, allows looking at a target
+ * If 1, stops playing on move
+ * If 2, does not look at target, continues playing during movement
+ *
+ * @see Game#updateMovement(PathingEntity)
+ */
+ public int idleStyle = -1;
+
+ /**
+ * If 0, restarts the sequence if already playing
+ * If 1, does not restart if already playing
+ *
+ * @see Game#readNPCUpdates()
+ */
+ public int replayStyle = 1;
- public SeqType() {
- }
+ public SeqType() {
+ }
- public int getFrameDuration(int frame) {
- int duration = frameDuration[frame];
+ public int getFrameDuration(int frame) {
+ int duration = frameDuration[frame];
- if (duration == 0) {
- SeqTransform transform = SeqTransform.get(transformIDs[frame]);
- if (transform != null) {
- duration = frameDuration[frame] = transform.delay;
- }
- }
+ if (duration == 0) {
+ SeqTransform transform = SeqTransform.get(transformIDs[frame]);
+ if (transform != null) {
+ duration = frameDuration[frame] = transform.delay;
+ }
+ }
- if (duration == 0) {
- duration = 1;
- }
+ if (duration == 0) {
+ duration = 1;
+ }
- return duration;
- }
+ return duration;
+ }
- public void load(Buffer buffer) {
- while (true) {
- int code = buffer.read8U();
+ public void load(Buffer buffer) {
+ while (true) {
+ int code = buffer.read8U();
- if (code == 0) {
- break;
- } else if (code == 1) {
- frameCount = buffer.read8U();
- transformIDs = new int[frameCount];
- auxiliaryTransformIDs = new int[frameCount];
- frameDuration = new int[frameCount];
- for (int f = 0; f < frameCount; f++) {
- transformIDs[f] = buffer.read16U();
- auxiliaryTransformIDs[f] = buffer.read16U();
- if (auxiliaryTransformIDs[f] == 65535) {
- auxiliaryTransformIDs[f] = -1;
- }
- frameDuration[f] = buffer.read16U();
- }
- } else if (code == 2) {
- loopFrameCount = buffer.read16U();
- } else if (code == 3) {
- int count = buffer.read8U();
- mask = new int[count + 1];
- for (int l = 0; l < count; l++) {
- mask[l] = buffer.read8U();
- }
- mask[count] = 9999999;
- } else if (code == 4) {
- forwardRenderPadding = true;
- } else if (code == 5) {
- priority = buffer.read8U();
- } else if (code == 6) {
- rightHandOverride = buffer.read16U();
- } else if (code == 7) {
- leftHandOverride = buffer.read16U();
- } else if (code == 8) {
- loopCount = buffer.read8U();
- } else if (code == 9) {
- moveStyle = buffer.read8U();
- } else if (code == 10) {
- idleStyle = buffer.read8U();
- } else if (code == 11) {
- replayStyle = buffer.read8U();
- } else if (code == 12) {
- buffer.read32();
- } else {
- System.out.println("Error unrecognised seq config code: " + code);
- }
- }
+ if (code == 0) {
+ break;
+ } else if (code == 1) {
+ frameCount = buffer.read8U();
+ transformIDs = new int[frameCount];
+ auxiliaryTransformIDs = new int[frameCount];
+ frameDuration = new int[frameCount];
+ for (int f = 0; f < frameCount; f++) {
+ transformIDs[f] = buffer.read16U();
+ auxiliaryTransformIDs[f] = buffer.read16U();
+ if (auxiliaryTransformIDs[f] == 65535) {
+ auxiliaryTransformIDs[f] = -1;
+ }
+ frameDuration[f] = buffer.read16U();
+ }
+ } else if (code == 2) {
+ loopFrameCount = buffer.read16U();
+ } else if (code == 3) {
+ int count = buffer.read8U();
+ mask = new int[count + 1];
+ for (int l = 0; l < count; l++) {
+ mask[l] = buffer.read8U();
+ }
+ mask[count] = 9999999;
+ } else if (code == 4) {
+ forwardRenderPadding = true;
+ } else if (code == 5) {
+ priority = buffer.read8U();
+ } else if (code == 6) {
+ rightHandOverride = buffer.read16U();
+ } else if (code == 7) {
+ leftHandOverride = buffer.read16U();
+ } else if (code == 8) {
+ loopCount = buffer.read8U();
+ } else if (code == 9) {
+ moveStyle = buffer.read8U();
+ } else if (code == 10) {
+ idleStyle = buffer.read8U();
+ } else if (code == 11) {
+ replayStyle = buffer.read8U();
+ } else if (code == 12) {
+ buffer.read32();
+ } else {
+ System.out.println("Error unrecognised seq config code: " + code);
+ }
+ }
- if (frameCount == 0) {
- frameCount = 1;
- transformIDs = new int[1];
- transformIDs[0] = -1;
- auxiliaryTransformIDs = new int[1];
- auxiliaryTransformIDs[0] = -1;
- frameDuration = new int[1];
- frameDuration[0] = -1;
- }
+ if (frameCount == 0) {
+ frameCount = 1;
+ transformIDs = new int[1];
+ transformIDs[0] = -1;
+ auxiliaryTransformIDs = new int[1];
+ auxiliaryTransformIDs[0] = -1;
+ frameDuration = new int[1];
+ frameDuration[0] = -1;
+ }
- if (moveStyle == -1) {
- if (mask != null) {
- moveStyle = 2;
- } else {
- moveStyle = 0;
- }
- }
+ if (moveStyle == -1) {
+ if (mask != null) {
+ moveStyle = 2;
+ } else {
+ moveStyle = 0;
+ }
+ }
- if (idleStyle == -1) {
- if (mask != null) {
- idleStyle = 2;
- } else {
- idleStyle = 0;
- }
- }
- }
+ if (idleStyle == -1) {
+ if (mask != null) {
+ idleStyle = 2;
+ } else {
+ idleStyle = 0;
+ }
+ }
+ }
}
diff --git a/src/main/java/Signlink.java b/src/main/java/Signlink.java
index b776e1d..4f369e4 100644
--- a/src/main/java/Signlink.java
+++ b/src/main/java/Signlink.java
@@ -11,269 +11,269 @@ import java.net.URL;
public class Signlink implements Runnable {
- public static final RandomAccessFile[] cache_idx = new RandomAccessFile[5];
- public static final Applet mainapp = null;
- public static int uid;
- public static int storeid = 32;
- public static RandomAccessFile cache_dat = null;
- public static boolean sunjava;
- public static boolean active;
- public static int threadliveid;
- public static InetAddress socketip;
- public static int socketreq;
- public static Socket socket = null;
- public static int threadreqpri = 1;
- public static Runnable threadreq = null;
- public static String dnsreq = null;
- public static String dns = null;
- public static String urlreq = null;
- public static DataInputStream urlstream = null;
- public static int savelen;
- public static String savereq = null;
- public static byte[] savebuf = null;
- public static boolean midiplay;
- public static int midipos;
- public static String midi = null;
- public static int midivol;
- public static int midifade;
- public static boolean waveplay;
- public static int wavepos;
- public static String wave = null;
- public static int wavevol;
- public static boolean reporterror = true;
+ public static final RandomAccessFile[] cache_idx = new RandomAccessFile[5];
+ public static final Applet mainapp = null;
+ public static int uid;
+ public static int storeid = 32;
+ public static RandomAccessFile cache_dat = null;
+ public static boolean sunjava;
+ public static boolean active;
+ public static int threadliveid;
+ public static InetAddress socketip;
+ public static int socketreq;
+ public static Socket socket = null;
+ public static int threadreqpri = 1;
+ public static Runnable threadreq = null;
+ public static String dnsreq = null;
+ public static String dns = null;
+ public static String urlreq = null;
+ public static DataInputStream urlstream = null;
+ public static int savelen;
+ public static String savereq = null;
+ public static byte[] savebuf = null;
+ public static boolean midiplay;
+ public static int midipos;
+ public static String midi = null;
+ public static int midivol;
+ public static int midifade;
+ public static boolean waveplay;
+ public static int wavepos;
+ public static String wave = null;
+ public static int wavevol;
+ public static boolean reporterror = true;
- public static void startpriv(InetAddress inetaddress) {
- threadliveid = (int) (Math.random() * 99999999D);
- if (active) {
- try {
- Thread.sleep(500L);
- } catch (Exception ignored) {
- }
- active = false;
- }
- socketreq = 0;
- threadreq = null;
- dnsreq = null;
- savereq = null;
- urlreq = null;
- socketip = inetaddress;
- Thread thread = new Thread(new Signlink());
- thread.setDaemon(true);
- thread.start();
- while (!active) {
- try {
- Thread.sleep(50L);
- } catch (Exception ignored) {
- }
- }
- }
+ public static void startpriv(InetAddress inetaddress) {
+ threadliveid = (int) (Math.random() * 99999999D);
+ if (active) {
+ try {
+ Thread.sleep(500L);
+ } catch (Exception ignored) {
+ }
+ active = false;
+ }
+ socketreq = 0;
+ threadreq = null;
+ dnsreq = null;
+ savereq = null;
+ urlreq = null;
+ socketip = inetaddress;
+ Thread thread = new Thread(new Signlink());
+ thread.setDaemon(true);
+ thread.start();
+ while (!active) {
+ try {
+ Thread.sleep(50L);
+ } catch (Exception ignored) {
+ }
+ }
+ }
- public static String findcachedir() {
- String[] as = {"c:/windows/", "c:/winnt/", "d:/windows/", "d:/winnt/", "e:/windows/", "e:/winnt/", "f:/windows/", "f:/winnt/", "c:/", "~/", "/tmp/", "", "c:/rscache", "/rscache"};
- if ((storeid < 32) || (storeid > 34)) {
- storeid = 32;
- }
- String s = ".file_store_" + storeid;
- for (String a : as) {
- try {
- if (a.length() > 0) {
- File file = new File(a);
- if (!file.exists()) {
- continue;
- }
- }
- File file1 = new File(a + s);
- if (file1.exists() || file1.mkdir()) {
- return a + s + "/";
- }
- } catch (Exception ignored) {
- }
- }
- return null;
- }
+ public static String findcachedir() {
+ String[] as = {"c:/windows/", "c:/winnt/", "d:/windows/", "d:/winnt/", "e:/windows/", "e:/winnt/", "f:/windows/", "f:/winnt/", "c:/", "~/", "/tmp/", "", "c:/rscache", "/rscache"};
+ if ((storeid < 32) || (storeid > 34)) {
+ storeid = 32;
+ }
+ String s = ".file_store_" + storeid;
+ for (String a : as) {
+ try {
+ if (a.length() > 0) {
+ File file = new File(a);
+ if (!file.exists()) {
+ continue;
+ }
+ }
+ File file1 = new File(a + s);
+ if (file1.exists() || file1.mkdir()) {
+ return a + s + "/";
+ }
+ } catch (Exception ignored) {
+ }
+ }
+ return null;
+ }
- public static int getuid(String s) {
- try {
- File file = new File(s + "uid.dat");
- if (!file.exists() || (file.length() < 4L)) {
- DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(s + "uid.dat"));
- dataoutputstream.writeInt((int) (Math.random() * 99999999D));
- dataoutputstream.close();
- }
- } catch (Exception ignored) {
- }
- try {
- DataInputStream datainputstream = new DataInputStream(new FileInputStream(s + "uid.dat"));
- int i = datainputstream.readInt();
- datainputstream.close();
- return i + 1;
- } catch (Exception _ex) {
- return 0;
- }
- }
+ public static int getuid(String s) {
+ try {
+ File file = new File(s + "uid.dat");
+ if (!file.exists() || (file.length() < 4L)) {
+ DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(s + "uid.dat"));
+ dataoutputstream.writeInt((int) (Math.random() * 99999999D));
+ dataoutputstream.close();
+ }
+ } catch (Exception ignored) {
+ }
+ try {
+ DataInputStream datainputstream = new DataInputStream(new FileInputStream(s + "uid.dat"));
+ int i = datainputstream.readInt();
+ datainputstream.close();
+ return i + 1;
+ } catch (Exception _ex) {
+ return 0;
+ }
+ }
- public static synchronized Socket opensocket(int i) throws IOException {
- for (socketreq = i; socketreq != 0; ) {
- try {
- Thread.sleep(50L);
- } catch (Exception ignored) {
- }
- }
- if (socket == null) {
- throw new IOException("could not open socket");
- } else {
- return socket;
- }
- }
+ public static synchronized Socket opensocket(int i) throws IOException {
+ for (socketreq = i; socketreq != 0; ) {
+ try {
+ Thread.sleep(50L);
+ } catch (Exception ignored) {
+ }
+ }
+ if (socket == null) {
+ throw new IOException("could not open socket");
+ } else {
+ return socket;
+ }
+ }
- public static synchronized DataInputStream openurl(String s) throws IOException {
- for (urlreq = s; urlreq != null; ) {
- try {
- Thread.sleep(50L);
- } catch (Exception ignored) {
- }
- }
- if (urlstream == null) {
- throw new IOException("could not open: " + s);
- } else {
- return urlstream;
- }
- }
+ public static synchronized DataInputStream openurl(String s) throws IOException {
+ for (urlreq = s; urlreq != null; ) {
+ try {
+ Thread.sleep(50L);
+ } catch (Exception ignored) {
+ }
+ }
+ if (urlstream == null) {
+ throw new IOException("could not open: " + s);
+ } else {
+ return urlstream;
+ }
+ }
- public static synchronized void dnslookup(String s) {
- dns = s;
- dnsreq = s;
- }
+ public static synchronized void dnslookup(String s) {
+ dns = s;
+ dnsreq = s;
+ }
- public static synchronized void startthread(Runnable runnable, int i) {
- threadreqpri = i;
- threadreq = runnable;
- }
+ public static synchronized void startthread(Runnable runnable, int i) {
+ threadreqpri = i;
+ threadreq = runnable;
+ }
- public static synchronized boolean wavesave(byte[] src, int len) {
- if (len > 0x1e8480) {
- return false;
- }
- if (savereq != null) {
- return false;
- } else {
- wavepos = (wavepos + 1) % 5;
- savelen = len;
- savebuf = src;
- waveplay = true;
- savereq = "sound" + wavepos + ".wav";
- return true;
- }
- }
+ public static synchronized boolean wavesave(byte[] src, int len) {
+ if (len > 0x1e8480) {
+ return false;
+ }
+ if (savereq != null) {
+ return false;
+ } else {
+ wavepos = (wavepos + 1) % 5;
+ savelen = len;
+ savebuf = src;
+ waveplay = true;
+ savereq = "sound" + wavepos + ".wav";
+ return true;
+ }
+ }
- public static synchronized boolean wavereplay() {
- if (savereq != null) {
- return false;
- } else {
- savebuf = null;
- waveplay = true;
- savereq = "sound" + wavepos + ".wav";
- return true;
- }
- }
+ public static synchronized boolean wavereplay() {
+ if (savereq != null) {
+ return false;
+ } else {
+ savebuf = null;
+ waveplay = true;
+ savereq = "sound" + wavepos + ".wav";
+ return true;
+ }
+ }
- public static synchronized void midisave(byte[] data, int len) {
- if (len > 0x1e8480) {
- return;
- }
- if (savereq != null) {
- } else {
- midipos = (midipos + 1) % 5;
- savelen = len;
- savebuf = data;
- midiplay = true;
- savereq = "jingle" + midipos + ".mid";
- }
- }
+ public static synchronized void midisave(byte[] data, int len) {
+ if (len > 0x1e8480) {
+ return;
+ }
+ if (savereq != null) {
+ } else {
+ midipos = (midipos + 1) % 5;
+ savelen = len;
+ savebuf = data;
+ midiplay = true;
+ savereq = "jingle" + midipos + ".mid";
+ }
+ }
- public static void reporterror(String s) {
- if (!reporterror) {
- return;
- }
- if (!active) {
- return;
- }
- System.out.println("Error: " + s);
- }
+ public static void reporterror(String s) {
+ if (!reporterror) {
+ return;
+ }
+ if (!active) {
+ return;
+ }
+ System.out.println("Error: " + s);
+ }
- public Signlink() {
- }
+ public Signlink() {
+ }
- @Override
- public void run() {
- active = true;
- String s = findcachedir();
- System.out.println(s);
- uid = getuid(s);
- try {
- File file = new File(s + "main_file_cache.dat");
- if (file.exists() && (file.length() > 0x3200000L)) {
- file.delete();
- }
- cache_dat = new RandomAccessFile(s + "main_file_cache.dat", "rw");
- for (int j = 0; j < 5; j++) {
- cache_idx[j] = new RandomAccessFile(s + "main_file_cache.idx" + j, "rw");
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- for (int i = threadliveid; threadliveid == i; ) {
- if (socketreq != 0) {
- try {
- socket = new Socket(socketip, socketreq);
- } catch (Exception _ex) {
- socket = null;
- }
- socketreq = 0;
- } else if (threadreq != null) {
- Thread thread = new Thread(threadreq);
- thread.setDaemon(true);
- thread.start();
- thread.setPriority(threadreqpri);
- threadreq = null;
- } else if (dnsreq != null) {
- try {
- dns = InetAddress.getByName(dnsreq).getHostName();
- } catch (Exception _ex) {
- dns = "unknown";
- }
- dnsreq = null;
- } else if (savereq != null) {
- if (savebuf != null) {
- try {
- FileOutputStream fileoutputstream = new FileOutputStream(s + savereq);
- fileoutputstream.write(savebuf, 0, savelen);
- fileoutputstream.close();
- } catch (Exception ignored) {
- }
- }
- if (waveplay) {
- wave = s + savereq;
- waveplay = false;
- }
- if (midiplay) {
- midi = s + savereq;
- midiplay = false;
- }
- savereq = null;
- } else if (urlreq != null) {
- try {
- urlstream = new DataInputStream(new URL(mainapp.getCodeBase(), urlreq).openStream());
- } catch (Exception _ex) {
- urlstream = null;
- }
- urlreq = null;
- }
- try {
- Thread.sleep(50L);
- } catch (Exception ignored) {
- }
- }
- }
+ @Override
+ public void run() {
+ active = true;
+ String s = findcachedir();
+ System.out.println(s);
+ uid = getuid(s);
+ try {
+ File file = new File(s + "main_file_cache.dat");
+ if (file.exists() && (file.length() > 0x3200000L)) {
+ file.delete();
+ }
+ cache_dat = new RandomAccessFile(s + "main_file_cache.dat", "rw");
+ for (int j = 0; j < 5; j++) {
+ cache_idx[j] = new RandomAccessFile(s + "main_file_cache.idx" + j, "rw");
+ }
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ for (int i = threadliveid; threadliveid == i; ) {
+ if (socketreq != 0) {
+ try {
+ socket = new Socket(socketip, socketreq);
+ } catch (Exception _ex) {
+ socket = null;
+ }
+ socketreq = 0;
+ } else if (threadreq != null) {
+ Thread thread = new Thread(threadreq);
+ thread.setDaemon(true);
+ thread.start();
+ thread.setPriority(threadreqpri);
+ threadreq = null;
+ } else if (dnsreq != null) {
+ try {
+ dns = InetAddress.getByName(dnsreq).getHostName();
+ } catch (Exception _ex) {
+ dns = "unknown";
+ }
+ dnsreq = null;
+ } else if (savereq != null) {
+ if (savebuf != null) {
+ try {
+ FileOutputStream fileoutputstream = new FileOutputStream(s + savereq);
+ fileoutputstream.write(savebuf, 0, savelen);
+ fileoutputstream.close();
+ } catch (Exception ignored) {
+ }
+ }
+ if (waveplay) {
+ wave = s + savereq;
+ waveplay = false;
+ }
+ if (midiplay) {
+ midi = s + savereq;
+ midiplay = false;
+ }
+ savereq = null;
+ } else if (urlreq != null) {
+ try {
+ urlstream = new DataInputStream(new URL(mainapp.getCodeBase(), urlreq).openStream());
+ } catch (Exception _ex) {
+ urlstream = null;
+ }
+ urlreq = null;
+ }
+ try {
+ Thread.sleep(50L);
+ } catch (Exception ignored) {
+ }
+ }
+ }
}
diff --git a/src/main/java/Skill.java b/src/main/java/Skill.java
index 213754b..978c654 100644
--- a/src/main/java/Skill.java
+++ b/src/main/java/Skill.java
@@ -4,8 +4,8 @@
public class Skill {
- public static final int COUNT = 25;
- public static final boolean[] ENABLED = {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, false, false, false, false};
- public static final String[] NAME = {"attack", "defence", "strength", "hitpoints", "ranged", "prayer", "magic", "cooking", "woodcutting", "fletching", "fishing", "firemaking", "crafting", "smithing", "mining", "herblore", "agility", "thieving", "slayer", "farming", "runecraft", "-unused-", "-unused-", "-unused-", "-unused-"};
+ public static final int COUNT = 25;
+ public static final boolean[] ENABLED = {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, false, false, false, false};
+ public static final String[] NAME = {"attack", "defence", "strength", "hitpoints", "ranged", "prayer", "magic", "cooking", "woodcutting", "fletching", "fishing", "firemaking", "crafting", "smithing", "mining", "herblore", "agility", "thieving", "slayer", "farming", "runecraft", "-unused-", "-unused-", "-unused-", "-unused-"};
}
diff --git a/src/main/java/SoundFilter.java b/src/main/java/SoundFilter.java
index 84be3e9..9861d7c 100644
--- a/src/main/java/SoundFilter.java
+++ b/src/main/java/SoundFilter.java
@@ -5,116 +5,116 @@
*/
public class SoundFilter {
- public static final float[][] coefficient = new float[2][8];
- public static final int[][] coefficient16 = new int[2][8];
- public static float unity;
- public static int unity16;
- public final int[] pairs = new int[2];
- public final int[][][] frequencies = new int[2][2][4];
- public final int[][][] ranges = new int[2][2][4];
- public final int[] unities = new int[2];
+ public static final float[][] coefficient = new float[2][8];
+ public static final int[][] coefficient16 = new int[2][8];
+ public static float unity;
+ public static int unity16;
+ public final int[] pairs = new int[2];
+ public final int[][][] frequencies = new int[2][2][4];
+ public final int[][][] ranges = new int[2][2][4];
+ public final int[] unities = new int[2];
- public SoundFilter() {
- }
+ public SoundFilter() {
+ }
- public float gain(int direction, int pair, float delta) {
- float g = (float) ranges[direction][0][pair] + (delta * (float) (ranges[direction][1][pair] - ranges[direction][0][pair]));
- g *= 0.001525879F;
- return 1.0F - (float) Math.pow(10D, -g / 20F);
- }
+ public float gain(int direction, int pair, float delta) {
+ float g = (float) ranges[direction][0][pair] + (delta * (float) (ranges[direction][1][pair] - ranges[direction][0][pair]));
+ g *= 0.001525879F;
+ return 1.0F - (float) Math.pow(10D, -g / 20F);
+ }
- public float normalize(float f) {
- return (32.7032F * (float) Math.pow(2D, f) * 3.141593F) / 11025F;
- }
+ public float normalize(float f) {
+ return (32.7032F * (float) Math.pow(2D, f) * 3.141593F) / 11025F;
+ }
- public float phase(int direction, int pair, float delta) {
- float f1 = (float) frequencies[direction][0][pair] + (delta * (float) (frequencies[direction][1][pair] - frequencies[direction][0][pair]));
- f1 *= 0.0001220703F;
- return normalize(f1);
- }
+ public float phase(int direction, int pair, float delta) {
+ float f1 = (float) frequencies[direction][0][pair] + (delta * (float) (frequencies[direction][1][pair] - frequencies[direction][0][pair]));
+ f1 *= 0.0001220703F;
+ return normalize(f1);
+ }
- public int evaluate(int direction, float delta) {
- if (direction == 0) {
- float u = (float) unities[0] + ((float) (unities[1] - unities[0]) * delta);
- u *= 0.003051758F;
- unity = (float) Math.pow(0.10000000000000001D, u / 20F);
- unity16 = (int) (unity * 65536F);
- }
+ public int evaluate(int direction, float delta) {
+ if (direction == 0) {
+ float u = (float) unities[0] + ((float) (unities[1] - unities[0]) * delta);
+ u *= 0.003051758F;
+ unity = (float) Math.pow(0.10000000000000001D, u / 20F);
+ unity16 = (int) (unity * 65536F);
+ }
- if (pairs[direction] == 0) {
- return 0;
- }
+ if (pairs[direction] == 0) {
+ return 0;
+ }
- float u = gain(direction, 0, delta);
+ float u = gain(direction, 0, delta);
- coefficient[direction][0] = -2F * u * (float) Math.cos(phase(direction, 0, delta));
- coefficient[direction][1] = u * u;
+ coefficient[direction][0] = -2F * u * (float) Math.cos(phase(direction, 0, delta));
+ coefficient[direction][1] = u * u;
- for (int pair = 1; pair < pairs[direction]; pair++) {
- float g = gain(direction, pair, delta);
- float a = -2F * g * (float) Math.cos(phase(direction, pair, delta));
- float b = g * g;
+ for (int pair = 1; pair < pairs[direction]; pair++) {
+ float g = gain(direction, pair, delta);
+ float a = -2F * g * (float) Math.cos(phase(direction, pair, delta));
+ float b = g * g;
- coefficient[direction][(pair * 2) + 1] = coefficient[direction][(pair * 2) - 1] * b;
- coefficient[direction][pair * 2] = (coefficient[direction][(pair * 2) - 1] * a) + (coefficient[direction][(pair * 2) - 2] * b);
+ coefficient[direction][(pair * 2) + 1] = coefficient[direction][(pair * 2) - 1] * b;
+ coefficient[direction][pair * 2] = (coefficient[direction][(pair * 2) - 1] * a) + (coefficient[direction][(pair * 2) - 2] * b);
- for (int j = (pair * 2) - 1; j >= 2; j--) {
- coefficient[direction][j] += (coefficient[direction][j - 1] * a) + (coefficient[direction][j - 2] * b);
- }
+ for (int j = (pair * 2) - 1; j >= 2; j--) {
+ coefficient[direction][j] += (coefficient[direction][j - 1] * a) + (coefficient[direction][j - 2] * b);
+ }
- coefficient[direction][1] += (coefficient[direction][0] * a) + b;
- coefficient[direction][0] += a;
- }
+ coefficient[direction][1] += (coefficient[direction][0] * a) + b;
+ coefficient[direction][0] += a;
+ }
- if (direction == 0) {
- for (int l = 0; l < (pairs[0] * 2); l++) {
- coefficient[0][l] *= unity;
- }
- }
+ if (direction == 0) {
+ for (int l = 0; l < (pairs[0] * 2); l++) {
+ coefficient[0][l] *= unity;
+ }
+ }
- for (int pair = 0; pair < (pairs[direction] * 2); pair++) {
- coefficient16[direction][pair] = (int) (coefficient[direction][pair] * 65536F);
- }
+ for (int pair = 0; pair < (pairs[direction] * 2); pair++) {
+ coefficient16[direction][pair] = (int) (coefficient[direction][pair] * 65536F);
+ }
- return pairs[direction] * 2;
- }
+ return pairs[direction] * 2;
+ }
- public void read(Buffer buffer, SoundEnvelope envelope) {
- int count = buffer.read8U();
- pairs[0] = count >> 4;
- pairs[1] = count & 0xf;
+ public void read(Buffer buffer, SoundEnvelope envelope) {
+ int count = buffer.read8U();
+ pairs[0] = count >> 4;
+ pairs[1] = count & 0xf;
- if (count != 0) {
- unities[0] = buffer.read16U();
- unities[1] = buffer.read16U();
+ if (count != 0) {
+ unities[0] = buffer.read16U();
+ unities[1] = buffer.read16U();
- int migration = buffer.read8U();
+ int migration = buffer.read8U();
- for (int direction = 0; direction < 2; direction++) {
- for (int pair = 0; pair < pairs[direction]; pair++) {
- frequencies[direction][0][pair] = buffer.read16U();
- ranges[direction][0][pair] = buffer.read16U();
- }
- }
+ for (int direction = 0; direction < 2; direction++) {
+ for (int pair = 0; pair < pairs[direction]; pair++) {
+ frequencies[direction][0][pair] = buffer.read16U();
+ ranges[direction][0][pair] = buffer.read16U();
+ }
+ }
- for (int direction = 0; direction < 2; direction++) {
- for (int pair = 0; pair < pairs[direction]; pair++) {
- if ((migration & (1 << (direction * 4) << pair)) != 0) {
- frequencies[direction][1][pair] = buffer.read16U();
- ranges[direction][1][pair] = buffer.read16U();
- } else {
- frequencies[direction][1][pair] = frequencies[direction][0][pair];
- ranges[direction][1][pair] = ranges[direction][0][pair];
- }
- }
- }
+ for (int direction = 0; direction < 2; direction++) {
+ for (int pair = 0; pair < pairs[direction]; pair++) {
+ if ((migration & (1 << (direction * 4) << pair)) != 0) {
+ frequencies[direction][1][pair] = buffer.read16U();
+ ranges[direction][1][pair] = buffer.read16U();
+ } else {
+ frequencies[direction][1][pair] = frequencies[direction][0][pair];
+ ranges[direction][1][pair] = ranges[direction][0][pair];
+ }
+ }
+ }
- if ((migration != 0) || (unities[1] != unities[0])) {
- envelope.readShape(buffer);
- }
- } else {
- unities[0] = unities[1] = 0;
- }
- }
+ if ((migration != 0) || (unities[1] != unities[0])) {
+ envelope.readShape(buffer);
+ }
+ } else {
+ unities[0] = unities[1] = 0;
+ }
+ }
}
diff --git a/src/main/java/SoundTone.java b/src/main/java/SoundTone.java
index 79e8bcf..19c4705 100644
--- a/src/main/java/SoundTone.java
+++ b/src/main/java/SoundTone.java
@@ -4,324 +4,324 @@
public class SoundTone {
- public static final int[] tmpPhases = new int[5];
- public static final int[] tmpDelays = new int[5];
- public static final int[] tmpVolumes = new int[5];
- public static final int[] tmpSemitones = new int[5];
- public static final int[] tmpStarts = new int[5];
- public static int[] buffer;
- public static int[] noise;
- public static int[] sin;
+ public static final int[] tmpPhases = new int[5];
+ public static final int[] tmpDelays = new int[5];
+ public static final int[] tmpVolumes = new int[5];
+ public static final int[] tmpSemitones = new int[5];
+ public static final int[] tmpStarts = new int[5];
+ public static int[] buffer;
+ public static int[] noise;
+ public static int[] sin;
- public static void init() {
- noise = new int[32768];
- for (int i = 0; i < 32768; i++) {
- if (Math.random() > 0.5D) {
- noise[i] = 1;
- } else {
- noise[i] = -1;
- }
- }
- sin = new int[32768];
- for (int j = 0; j < 32768; j++) {
- sin[j] = (int) (Math.sin((double) j / 5215.1903000000002D) * 16384D);
- }
- buffer = new int[22050 * 10]; // 10 second buffer
- }
+ public static void init() {
+ noise = new int[32768];
+ for (int i = 0; i < 32768; i++) {
+ if (Math.random() > 0.5D) {
+ noise[i] = 1;
+ } else {
+ noise[i] = -1;
+ }
+ }
+ sin = new int[32768];
+ for (int j = 0; j < 32768; j++) {
+ sin[j] = (int) (Math.sin((double) j / 5215.1903000000002D) * 16384D);
+ }
+ buffer = new int[22050 * 10]; // 10 second buffer
+ }
- public final int[] harmonicVolume = new int[5];
- public final int[] harmonicSemitone = new int[5];
- public final int[] harmonicDelay = new int[5];
- public SoundEnvelope frequencyBase;
- public SoundEnvelope amplitudeBase;
- public SoundEnvelope frequencyModRate;
- public SoundEnvelope frequencyModRange;
- public SoundEnvelope amplitudeModRate;
- public SoundEnvelope amplitudeModRange;
- public SoundEnvelope release;
- public SoundEnvelope attack;
- public int reverbDelay;
- public int reverbVolume = 100;
- public SoundFilter filter;
- public SoundEnvelope filterRange;
- public int length = 500;
- public int start;
+ public final int[] harmonicVolume = new int[5];
+ public final int[] harmonicSemitone = new int[5];
+ public final int[] harmonicDelay = new int[5];
+ public SoundEnvelope frequencyBase;
+ public SoundEnvelope amplitudeBase;
+ public SoundEnvelope frequencyModRate;
+ public SoundEnvelope frequencyModRange;
+ public SoundEnvelope amplitudeModRate;
+ public SoundEnvelope amplitudeModRange;
+ public SoundEnvelope release;
+ public SoundEnvelope attack;
+ public int reverbDelay;
+ public int reverbVolume = 100;
+ public SoundFilter filter;
+ public SoundEnvelope filterRange;
+ public int length = 500;
+ public int start;
- public SoundTone() {
- }
+ public SoundTone() {
+ }
- public int[] generate(int sampleCount, int length) {
- for (int sample = 0; sample < sampleCount; sample++) {
- buffer[sample] = 0;
- }
+ public int[] generate(int sampleCount, int length) {
+ for (int sample = 0; sample < sampleCount; sample++) {
+ buffer[sample] = 0;
+ }
- if (length < 10) {
- return buffer;
- }
+ if (length < 10) {
+ return buffer;
+ }
- double samplesPerStep = (double) sampleCount / ((double) length + 0.0D);
+ double samplesPerStep = (double) sampleCount / ((double) length + 0.0D);
- frequencyBase.reset();
- amplitudeBase.reset();
+ frequencyBase.reset();
+ amplitudeBase.reset();
- int frequencyStart = 0;
- int frequencyDuration = 0;
- int frequencyPhase = 0;
+ int frequencyStart = 0;
+ int frequencyDuration = 0;
+ int frequencyPhase = 0;
- if (frequencyModRate != null) {
- frequencyModRate.reset();
- frequencyModRange.reset();
- frequencyStart = (int) (((double) (frequencyModRate.end - frequencyModRate.start) * 32.768) / samplesPerStep);
- frequencyDuration = (int) (((double) frequencyModRate.start * 32.768) / samplesPerStep);
- }
+ if (frequencyModRate != null) {
+ frequencyModRate.reset();
+ frequencyModRange.reset();
+ frequencyStart = (int) (((double) (frequencyModRate.end - frequencyModRate.start) * 32.768) / samplesPerStep);
+ frequencyDuration = (int) (((double) frequencyModRate.start * 32.768) / samplesPerStep);
+ }
- int amplitudeStart = 0;
- int amplitudeDuration = 0;
- int amplitudePhase = 0;
+ int amplitudeStart = 0;
+ int amplitudeDuration = 0;
+ int amplitudePhase = 0;
- if (amplitudeModRate != null) {
- amplitudeModRate.reset();
- amplitudeModRange.reset();
- amplitudeStart = (int) (((double) (amplitudeModRate.end - amplitudeModRate.start) * 32.768) / samplesPerStep);
- amplitudeDuration = (int) (((double) amplitudeModRate.start * 32.768) / samplesPerStep);
- }
+ if (amplitudeModRate != null) {
+ amplitudeModRate.reset();
+ amplitudeModRange.reset();
+ amplitudeStart = (int) (((double) (amplitudeModRate.end - amplitudeModRate.start) * 32.768) / samplesPerStep);
+ amplitudeDuration = (int) (((double) amplitudeModRate.start * 32.768) / samplesPerStep);
+ }
- for (int harmonic = 0; harmonic < 5; harmonic++) {
- if (harmonicVolume[harmonic] != 0) {
- tmpPhases[harmonic] = 0;
- tmpDelays[harmonic] = (int) ((double) harmonicDelay[harmonic] * samplesPerStep);
- tmpVolumes[harmonic] = (harmonicVolume[harmonic] << 14) / 100;
- tmpSemitones[harmonic] = (int) (((double) (frequencyBase.end - frequencyBase.start) * 32.768 * Math.pow(1.0057929410678534D, harmonicSemitone[harmonic])) / samplesPerStep);
- tmpStarts[harmonic] = (int) (((double) frequencyBase.start * 32.768) / samplesPerStep);
- }
- }
+ for (int harmonic = 0; harmonic < 5; harmonic++) {
+ if (harmonicVolume[harmonic] != 0) {
+ tmpPhases[harmonic] = 0;
+ tmpDelays[harmonic] = (int) ((double) harmonicDelay[harmonic] * samplesPerStep);
+ tmpVolumes[harmonic] = (harmonicVolume[harmonic] << 14) / 100;
+ tmpSemitones[harmonic] = (int) (((double) (frequencyBase.end - frequencyBase.start) * 32.768 * Math.pow(1.0057929410678534D, harmonicSemitone[harmonic])) / samplesPerStep);
+ tmpStarts[harmonic] = (int) (((double) frequencyBase.start * 32.768) / samplesPerStep);
+ }
+ }
- for (int sample = 0; sample < sampleCount; sample++) {
- int frequency = frequencyBase.evaluate(sampleCount);
- int amplitude = amplitudeBase.evaluate(sampleCount);
+ for (int sample = 0; sample < sampleCount; sample++) {
+ int frequency = frequencyBase.evaluate(sampleCount);
+ int amplitude = amplitudeBase.evaluate(sampleCount);
- if (frequencyModRate != null) {
- int rate = frequencyModRate.evaluate(sampleCount);
- int range = frequencyModRange.evaluate(sampleCount);
- frequency += generate(frequencyModRate.form, frequencyPhase, range) >> 1;
- frequencyPhase += ((rate * frequencyStart) >> 16) + frequencyDuration;
- }
+ if (frequencyModRate != null) {
+ int rate = frequencyModRate.evaluate(sampleCount);
+ int range = frequencyModRange.evaluate(sampleCount);
+ frequency += generate(frequencyModRate.form, frequencyPhase, range) >> 1;
+ frequencyPhase += ((rate * frequencyStart) >> 16) + frequencyDuration;
+ }
- if (amplitudeModRate != null) {
- int rate = amplitudeModRate.evaluate(sampleCount);
- int range = amplitudeModRange.evaluate(sampleCount);
- amplitude = (amplitude * ((generate(amplitudeModRate.form, amplitudePhase, range) >> 1) + 32768)) >> 15;
- amplitudePhase += ((rate * amplitudeStart) >> 16) + amplitudeDuration;
- }
+ if (amplitudeModRate != null) {
+ int rate = amplitudeModRate.evaluate(sampleCount);
+ int range = amplitudeModRange.evaluate(sampleCount);
+ amplitude = (amplitude * ((generate(amplitudeModRate.form, amplitudePhase, range) >> 1) + 32768)) >> 15;
+ amplitudePhase += ((rate * amplitudeStart) >> 16) + amplitudeDuration;
+ }
- for (int harmonic = 0; harmonic < 5; harmonic++) {
- if (harmonicVolume[harmonic] != 0) {
- int position = sample + tmpDelays[harmonic];
+ for (int harmonic = 0; harmonic < 5; harmonic++) {
+ if (harmonicVolume[harmonic] != 0) {
+ int position = sample + tmpDelays[harmonic];
- if (position < sampleCount) {
- buffer[position] += generate(frequencyBase.form, tmpPhases[harmonic], (amplitude * tmpVolumes[harmonic]) >> 15);
- tmpPhases[harmonic] += ((frequency * tmpSemitones[harmonic]) >> 16) + tmpStarts[harmonic];
- }
- }
- }
- }
+ if (position < sampleCount) {
+ buffer[position] += generate(frequencyBase.form, tmpPhases[harmonic], (amplitude * tmpVolumes[harmonic]) >> 15);
+ tmpPhases[harmonic] += ((frequency * tmpSemitones[harmonic]) >> 16) + tmpStarts[harmonic];
+ }
+ }
+ }
+ }
- if (release != null) {
- release.reset();
- attack.reset();
+ if (release != null) {
+ release.reset();
+ attack.reset();
- int counter = 0;
- boolean muted = true;
+ int counter = 0;
+ boolean muted = true;
- for (int sample = 0; sample < sampleCount; sample++) {
- int releaseValue = release.evaluate(sampleCount);
- int attackValue = attack.evaluate(sampleCount);
- int threshold;
+ for (int sample = 0; sample < sampleCount; sample++) {
+ int releaseValue = release.evaluate(sampleCount);
+ int attackValue = attack.evaluate(sampleCount);
+ int threshold;
- if (muted) {
- threshold = release.start + (((release.end - release.start) * releaseValue) >> 8);
- } else {
- threshold = release.start + (((release.end - release.start) * attackValue) >> 8);
- }
+ if (muted) {
+ threshold = release.start + (((release.end - release.start) * releaseValue) >> 8);
+ } else {
+ threshold = release.start + (((release.end - release.start) * attackValue) >> 8);
+ }
- if ((counter += 256) >= threshold) {
- counter = 0;
- muted = !muted;
- }
+ if ((counter += 256) >= threshold) {
+ counter = 0;
+ muted = !muted;
+ }
- if (muted) {
- buffer[sample] = 0;
- }
- }
- }
+ if (muted) {
+ buffer[sample] = 0;
+ }
+ }
+ }
- if ((reverbDelay > 0) && (reverbVolume > 0)) {
- int start = (int) ((double) reverbDelay * samplesPerStep);
+ if ((reverbDelay > 0) && (reverbVolume > 0)) {
+ int start = (int) ((double) reverbDelay * samplesPerStep);
- for (int sample = start; sample < sampleCount; sample++) {
- buffer[sample] += (buffer[sample - start] * reverbVolume) / 100;
- }
- }
+ for (int sample = start; sample < sampleCount; sample++) {
+ buffer[sample] += (buffer[sample - start] * reverbVolume) / 100;
+ }
+ }
- if ((filter.pairs[0] > 0) || (filter.pairs[1] > 0)) {
- filterRange.reset();
+ if ((filter.pairs[0] > 0) || (filter.pairs[1] > 0)) {
+ filterRange.reset();
- int range = filterRange.evaluate(sampleCount + 1);
- int forward = filter.evaluate(0, (float) range / 65536F);
- int backward = filter.evaluate(1, (float) range / 65536F);
+ int range = filterRange.evaluate(sampleCount + 1);
+ int forward = filter.evaluate(0, (float) range / 65536F);
+ int backward = filter.evaluate(1, (float) range / 65536F);
- if (sampleCount >= (forward + backward)) {
- int index = 0;
- int interval = backward;
+ if (sampleCount >= (forward + backward)) {
+ int index = 0;
+ int interval = backward;
- if (interval > (sampleCount - forward)) {
- interval = sampleCount - forward;
- }
+ if (interval > (sampleCount - forward)) {
+ interval = sampleCount - forward;
+ }
- for (; index < interval; index++) {
- int sample = (int) (((long) buffer[index + forward] * (long) SoundFilter.unity16) >> 16);
+ for (; index < interval; index++) {
+ int sample = (int) (((long) buffer[index + forward] * (long) SoundFilter.unity16) >> 16);
- for (int offset = 0; offset < forward; offset++) {
- sample += (int) (((long) buffer[(index + forward) - 1 - offset] * (long) SoundFilter.coefficient16[0][offset]) >> 16);
- }
+ for (int offset = 0; offset < forward; offset++) {
+ sample += (int) (((long) buffer[(index + forward) - 1 - offset] * (long) SoundFilter.coefficient16[0][offset]) >> 16);
+ }
- for (int offset = 0; offset < index; offset++) {
- sample -= (int) (((long) buffer[index - 1 - offset] * (long) SoundFilter.coefficient16[1][offset]) >> 16);
- }
+ for (int offset = 0; offset < index; offset++) {
+ sample -= (int) (((long) buffer[index - 1 - offset] * (long) SoundFilter.coefficient16[1][offset]) >> 16);
+ }
- buffer[index] = sample;
- range = filterRange.evaluate(sampleCount + 1);
- }
+ buffer[index] = sample;
+ range = filterRange.evaluate(sampleCount + 1);
+ }
- interval = 128;
+ interval = 128;
- do {
- if (interval > (sampleCount - forward)) {
- interval = sampleCount - forward;
- }
+ do {
+ if (interval > (sampleCount - forward)) {
+ interval = sampleCount - forward;
+ }
- for (; index < interval; index++) {
- int sample = (int) (((long) buffer[index + forward] * (long) SoundFilter.unity16) >> 16);
+ for (; index < interval; index++) {
+ int sample = (int) (((long) buffer[index + forward] * (long) SoundFilter.unity16) >> 16);
- for (int offset = 0; offset < forward; offset++) {
- sample += (int) (((long) buffer[(index + forward) - 1 - offset] * (long) SoundFilter.coefficient16[0][offset]) >> 16);
- }
+ for (int offset = 0; offset < forward; offset++) {
+ sample += (int) (((long) buffer[(index + forward) - 1 - offset] * (long) SoundFilter.coefficient16[0][offset]) >> 16);
+ }
- for (int offset = 0; offset < backward; offset++) {
- sample -= (int) (((long) buffer[index - 1 - offset] * (long) SoundFilter.coefficient16[1][offset]) >> 16);
- }
+ for (int offset = 0; offset < backward; offset++) {
+ sample -= (int) (((long) buffer[index - 1 - offset] * (long) SoundFilter.coefficient16[1][offset]) >> 16);
+ }
- buffer[index] = sample;
- range = filterRange.evaluate(sampleCount + 1);
- }
+ buffer[index] = sample;
+ range = filterRange.evaluate(sampleCount + 1);
+ }
- if (index >= (sampleCount - forward)) {
- break;
- }
+ if (index >= (sampleCount - forward)) {
+ break;
+ }
- forward = filter.evaluate(0, (float) range / 65536F);
- backward = filter.evaluate(1, (float) range / 65536F);
- interval += 128;
- } while (true);
+ forward = filter.evaluate(0, (float) range / 65536F);
+ backward = filter.evaluate(1, (float) range / 65536F);
+ interval += 128;
+ } while (true);
- for (; index < sampleCount; index++) {
- int sample = 0;
+ for (; index < sampleCount; index++) {
+ int sample = 0;
- for (int offset = (index + forward) - sampleCount; offset < forward; offset++) {
- sample += (int) (((long) buffer[(index + forward) - 1 - offset] * (long) SoundFilter.coefficient16[0][offset]) >> 16);
- }
+ for (int offset = (index + forward) - sampleCount; offset < forward; offset++) {
+ sample += (int) (((long) buffer[(index + forward) - 1 - offset] * (long) SoundFilter.coefficient16[0][offset]) >> 16);
+ }
- for (int offset = 0; offset < backward; offset++) {
- sample -= (int) (((long) buffer[index - 1 - offset] * (long) SoundFilter.coefficient16[1][offset]) >> 16);
- }
+ for (int offset = 0; offset < backward; offset++) {
+ sample -= (int) (((long) buffer[index - 1 - offset] * (long) SoundFilter.coefficient16[1][offset]) >> 16);
+ }
- buffer[index] = sample;
- filterRange.evaluate(sampleCount + 1);
- }
- }
- }
+ buffer[index] = sample;
+ filterRange.evaluate(sampleCount + 1);
+ }
+ }
+ }
- for (int sample = 0; sample < sampleCount; sample++) {
- if (buffer[sample] < -32768) {
- buffer[sample] = -32768;
- }
- if (buffer[sample] > 32767) {
- buffer[sample] = 32767;
- }
- }
+ for (int sample = 0; sample < sampleCount; sample++) {
+ if (buffer[sample] < -32768) {
+ buffer[sample] = -32768;
+ }
+ if (buffer[sample] > 32767) {
+ buffer[sample] = 32767;
+ }
+ }
- return buffer;
- }
+ return buffer;
+ }
- public int generate(int form, int phase, int amplitude) {
- if (form == 1) {
- if ((phase & 0x7fff) < 16384) {
- return amplitude;
- } else {
- return -amplitude;
- }
- } else if (form == 2) {
- return (sin[phase & 0x7fff] * amplitude) >> 14;
- } else if (form == 3) {
- return (((phase & 0x7fff) * amplitude) >> 14) - amplitude;
- } else if (form == 4) {
- return noise[(phase / 2607) & 0x7fff] * amplitude;
- } else {
- return 0;
- }
- }
+ public int generate(int form, int phase, int amplitude) {
+ if (form == 1) {
+ if ((phase & 0x7fff) < 16384) {
+ return amplitude;
+ } else {
+ return -amplitude;
+ }
+ } else if (form == 2) {
+ return (sin[phase & 0x7fff] * amplitude) >> 14;
+ } else if (form == 3) {
+ return (((phase & 0x7fff) * amplitude) >> 14) - amplitude;
+ } else if (form == 4) {
+ return noise[(phase / 2607) & 0x7fff] * amplitude;
+ } else {
+ return 0;
+ }
+ }
- public void read(Buffer buffer) {
- frequencyBase = new SoundEnvelope();
- frequencyBase.read(buffer);
- amplitudeBase = new SoundEnvelope();
- amplitudeBase.read(buffer);
+ public void read(Buffer buffer) {
+ frequencyBase = new SoundEnvelope();
+ frequencyBase.read(buffer);
+ amplitudeBase = new SoundEnvelope();
+ amplitudeBase.read(buffer);
- if (buffer.read8U() != 0) {
- buffer.position--;
- frequencyModRate = new SoundEnvelope();
- frequencyModRate.read(buffer);
- frequencyModRange = new SoundEnvelope();
- frequencyModRange.read(buffer);
- }
+ if (buffer.read8U() != 0) {
+ buffer.position--;
+ frequencyModRate = new SoundEnvelope();
+ frequencyModRate.read(buffer);
+ frequencyModRange = new SoundEnvelope();
+ frequencyModRange.read(buffer);
+ }
- if (buffer.read8U() != 0) {
- buffer.position--;
- amplitudeModRate = new SoundEnvelope();
- amplitudeModRate.read(buffer);
- amplitudeModRange = new SoundEnvelope();
- amplitudeModRange.read(buffer);
- }
+ if (buffer.read8U() != 0) {
+ buffer.position--;
+ amplitudeModRate = new SoundEnvelope();
+ amplitudeModRate.read(buffer);
+ amplitudeModRange = new SoundEnvelope();
+ amplitudeModRange.read(buffer);
+ }
- if (buffer.read8U() != 0) {
- buffer.position--;
- release = new SoundEnvelope();
- release.read(buffer);
- attack = new SoundEnvelope();
- attack.read(buffer);
- }
+ if (buffer.read8U() != 0) {
+ buffer.position--;
+ release = new SoundEnvelope();
+ release.read(buffer);
+ attack = new SoundEnvelope();
+ attack.read(buffer);
+ }
- for (int i = 0; i < 10; i++) {
- int volume = buffer.readSmartU();
+ for (int i = 0; i < 10; i++) {
+ int volume = buffer.readSmartU();
- if (volume == 0) {
- break;
- }
+ if (volume == 0) {
+ break;
+ }
- harmonicVolume[i] = volume;
- harmonicSemitone[i] = buffer.readSmart();
- harmonicDelay[i] = buffer.readSmartU();
- }
+ harmonicVolume[i] = volume;
+ harmonicSemitone[i] = buffer.readSmart();
+ harmonicDelay[i] = buffer.readSmartU();
+ }
- reverbDelay = buffer.readSmartU();
- reverbVolume = buffer.readSmartU();
+ reverbDelay = buffer.readSmartU();
+ reverbVolume = buffer.readSmartU();
- length = buffer.read16U();
- start = buffer.read16U();
+ length = buffer.read16U();
+ start = buffer.read16U();
- filter = new SoundFilter();
- filterRange = new SoundEnvelope();
- filter.read(buffer, filterRange);
- }
+ filter = new SoundFilter();
+ filterRange = new SoundEnvelope();
+ filter.read(buffer, filterRange);
+ }
}
diff --git a/src/main/java/SoundTrack.java b/src/main/java/SoundTrack.java
index 429b006..ef22909 100644
--- a/src/main/java/SoundTrack.java
+++ b/src/main/java/SoundTrack.java
@@ -1,172 +1,172 @@
public class SoundTrack {
- public static final SoundTrack[] tracks = new SoundTrack[5000];
- public static final int[] delays = new int[5000];
- public static byte[] waveBytes = new byte[441000];
- public static Buffer waveBuffer = new Buffer(waveBytes);
+ public static final SoundTrack[] tracks = new SoundTrack[5000];
+ public static final int[] delays = new int[5000];
+ public static byte[] waveBytes = new byte[441000];
+ public static Buffer waveBuffer = new Buffer(waveBytes);
- public static void unpack(Buffer in) {
- SoundTone.init();
+ public static void unpack(Buffer in) {
+ SoundTone.init();
- do {
- int id = in.read16U();
+ do {
+ int id = in.read16U();
- if (id == 65535) {
- return;
- }
+ if (id == 65535) {
+ return;
+ }
- tracks[id] = new SoundTrack();
- tracks[id].read(in);
- delays[id] = tracks[id].trim();
- } while (true);
- }
+ tracks[id] = new SoundTrack();
+ tracks[id].read(in);
+ delays[id] = tracks[id].trim();
+ } while (true);
+ }
- public static Buffer generate(int loopCount, int id) {
- if (tracks[id] != null) {
- SoundTrack track = tracks[id];
- return track.getWave(loopCount);
- } else {
- return null;
- }
- }
+ public static Buffer generate(int loopCount, int id) {
+ if (tracks[id] != null) {
+ SoundTrack track = tracks[id];
+ return track.getWave(loopCount);
+ } else {
+ return null;
+ }
+ }
- public final SoundTone[] tones = new SoundTone[10];
- public int loopBegin;
- public int loopEnd;
+ public final SoundTone[] tones = new SoundTone[10];
+ public int loopBegin;
+ public int loopEnd;
- public SoundTrack() {
- }
+ public SoundTrack() {
+ }
- public void read(Buffer buffer) {
- for (int tone = 0; tone < 10; tone++) {
- if (buffer.read8U() != 0) {
- buffer.position--;
- tones[tone] = new SoundTone();
- tones[tone].read(buffer);
- }
- }
- loopBegin = buffer.read16U();
- loopEnd = buffer.read16U();
- }
+ public void read(Buffer buffer) {
+ for (int tone = 0; tone < 10; tone++) {
+ if (buffer.read8U() != 0) {
+ buffer.position--;
+ tones[tone] = new SoundTone();
+ tones[tone].read(buffer);
+ }
+ }
+ loopBegin = buffer.read16U();
+ loopEnd = buffer.read16U();
+ }
- public int trim() {
- int start = 9999999;
- for (int tone = 0; tone < 10; tone++) {
- if ((tones[tone] != null) && ((tones[tone].start / 20) < start)) {
- start = tones[tone].start / 20;
- }
- }
+ public int trim() {
+ int start = 9999999;
+ for (int tone = 0; tone < 10; tone++) {
+ if ((tones[tone] != null) && ((tones[tone].start / 20) < start)) {
+ start = tones[tone].start / 20;
+ }
+ }
- if ((loopBegin < loopEnd) && ((loopBegin / 20) < start)) {
- start = loopBegin / 20;
- }
+ if ((loopBegin < loopEnd) && ((loopBegin / 20) < start)) {
+ start = loopBegin / 20;
+ }
- if ((start == 9999999) || (start == 0)) {
- return 0;
- }
+ if ((start == 9999999) || (start == 0)) {
+ return 0;
+ }
- for (int tone = 0; tone < 10; tone++) {
- if (tones[tone] != null) {
- tones[tone].start -= start * 20;
- }
- }
- if (loopBegin < loopEnd) {
- loopBegin -= start * 20;
- loopEnd -= start * 20;
- }
- return start;
- }
+ for (int tone = 0; tone < 10; tone++) {
+ if (tones[tone] != null) {
+ tones[tone].start -= start * 20;
+ }
+ }
+ if (loopBegin < loopEnd) {
+ loopBegin -= start * 20;
+ loopEnd -= start * 20;
+ }
+ return start;
+ }
- /**
- * WaveFormat
- *
- * @param loopCount the loop count.
- * @return the {@link Buffer} containing the waveform data.
- */
- public Buffer getWave(int loopCount) {
- int length = generate(loopCount);
- waveBuffer.position = 0;
- waveBuffer.write32(0x52494646); // "RIFF" ChunkID
- waveBuffer.write32LE(36 + length); // ChunkSize
- waveBuffer.write32(0x57415645); // "WAVE" format
- waveBuffer.write32(0x666d7420); // "fmt " chunk id
- waveBuffer.write32LE(16); // chunk size
- waveBuffer.write16LE(1); // audio format
- waveBuffer.write16LE(1); // num channels
- waveBuffer.write32LE(22050); // sample rate
- waveBuffer.write32LE(22050); // byte rate
- waveBuffer.write16LE(1); // block align
- waveBuffer.write16LE(8); // bits per sample
- waveBuffer.write32(0x64617461); // "data"
- waveBuffer.write32LE(length);
- waveBuffer.position += length;
- return waveBuffer;
- }
+ /**
+ * WaveFormat
+ *
+ * @param loopCount the loop count.
+ * @return the {@link Buffer} containing the waveform data.
+ */
+ public Buffer getWave(int loopCount) {
+ int length = generate(loopCount);
+ waveBuffer.position = 0;
+ waveBuffer.write32(0x52494646); // "RIFF" ChunkID
+ waveBuffer.write32LE(36 + length); // ChunkSize
+ waveBuffer.write32(0x57415645); // "WAVE" format
+ waveBuffer.write32(0x666d7420); // "fmt " chunk id
+ waveBuffer.write32LE(16); // chunk size
+ waveBuffer.write16LE(1); // audio format
+ waveBuffer.write16LE(1); // num channels
+ waveBuffer.write32LE(22050); // sample rate
+ waveBuffer.write32LE(22050); // byte rate
+ waveBuffer.write16LE(1); // block align
+ waveBuffer.write16LE(8); // bits per sample
+ waveBuffer.write32(0x64617461); // "data"
+ waveBuffer.write32LE(length);
+ waveBuffer.position += length;
+ return waveBuffer;
+ }
- public int generate(int loopCount) {
- int duration = 0;
+ public int generate(int loopCount) {
+ int duration = 0;
- for (int tone = 0; tone < 10; tone++) {
- if ((tones[tone] != null) && ((tones[tone].length + tones[tone].start) > duration)) {
- duration = tones[tone].length + tones[tone].start;
- }
- }
+ for (int tone = 0; tone < 10; tone++) {
+ if ((tones[tone] != null) && ((tones[tone].length + tones[tone].start) > duration)) {
+ duration = tones[tone].length + tones[tone].start;
+ }
+ }
- if (duration == 0) {
- return 0;
- }
+ if (duration == 0) {
+ return 0;
+ }
- int sampleCount = (22050 * duration) / 1000;
- int loopStart = (22050 * loopBegin) / 1000;
- int loopStop = (22050 * loopEnd) / 1000;
+ int sampleCount = (22050 * duration) / 1000;
+ int loopStart = (22050 * loopBegin) / 1000;
+ int loopStop = (22050 * loopEnd) / 1000;
- if ((loopStart < 0) || (loopStop < 0) || (loopStop > sampleCount) || (loopStart >= loopStop)) {
- loopCount = 0;
- }
+ if ((loopStart < 0) || (loopStop < 0) || (loopStop > sampleCount) || (loopStart >= loopStop)) {
+ loopCount = 0;
+ }
- int totalSampleCount = sampleCount + ((loopStop - loopStart) * (loopCount - 1));
+ int totalSampleCount = sampleCount + ((loopStop - loopStart) * (loopCount - 1));
- for (int sample = 44; sample < (totalSampleCount + 44); sample++) {
- waveBytes[sample] = -128;
- }
+ for (int sample = 44; sample < (totalSampleCount + 44); sample++) {
+ waveBytes[sample] = -128;
+ }
- for (int tone = 0; tone < 10; tone++) {
- if (tones[tone] == null) {
- continue;
- }
+ for (int tone = 0; tone < 10; tone++) {
+ if (tones[tone] == null) {
+ continue;
+ }
- int toneSampleCount = (tones[tone].length * 22050) / 1000;
- int start = (tones[tone].start * 22050) / 1000;
- int[] samples = tones[tone].generate(toneSampleCount, tones[tone].length);
+ int toneSampleCount = (tones[tone].length * 22050) / 1000;
+ int start = (tones[tone].start * 22050) / 1000;
+ int[] samples = tones[tone].generate(toneSampleCount, tones[tone].length);
- for (int sample = 0; sample < toneSampleCount; sample++) {
- waveBytes[sample + start + 44] += (byte) (samples[sample] >> 8);
- }
- }
+ for (int sample = 0; sample < toneSampleCount; sample++) {
+ waveBytes[sample + start + 44] += (byte) (samples[sample] >> 8);
+ }
+ }
- if (loopCount > 1) {
- // All of these 44's are because we're avoiding the area where the WAV header will be written.
- loopStart += 44;
- loopStop += 44;
- sampleCount += 44;
+ if (loopCount > 1) {
+ // All of these 44's are because we're avoiding the area where the WAV header will be written.
+ loopStart += 44;
+ loopStop += 44;
+ sampleCount += 44;
- // Moves the end of the sound (after the loops) to the true end of the buffer.
- int endOffset = (totalSampleCount += 44) - sampleCount;
- for (int sample = sampleCount - 1; sample >= loopStop; sample--) {
- waveBytes[sample + endOffset] = waveBytes[sample];
- }
+ // Moves the end of the sound (after the loops) to the true end of the buffer.
+ int endOffset = (totalSampleCount += 44) - sampleCount;
+ for (int sample = sampleCount - 1; sample >= loopStop; sample--) {
+ waveBytes[sample + endOffset] = waveBytes[sample];
+ }
- // Duplicates loop area.
- for (int loop = 1; loop < loopCount; loop++) {
- int offset = (loopStop - loopStart) * loop;
- for (int sample = loopStart; sample < loopStop; sample++) {
- waveBytes[sample + offset] = waveBytes[sample];
- }
- }
+ // Duplicates loop area.
+ for (int loop = 1; loop < loopCount; loop++) {
+ int offset = (loopStop - loopStart) * loop;
+ for (int sample = loopStart; sample < loopStop; sample++) {
+ waveBytes[sample + offset] = waveBytes[sample];
+ }
+ }
- totalSampleCount -= 44;
- }
- return totalSampleCount;
- }
+ totalSampleCount -= 44;
+ }
+ return totalSampleCount;
+ }
}
diff --git a/src/main/java/SpotAnimEntity.java b/src/main/java/SpotAnimEntity.java
index e45177c..458205f 100644
--- a/src/main/java/SpotAnimEntity.java
+++ b/src/main/java/SpotAnimEntity.java
@@ -4,76 +4,76 @@
public class SpotAnimEntity extends Entity {
- public final int level;
- public final int x;
- public final int z;
- public final int y;
- public final int startCycle;
- public final SpotAnimType type;
- public boolean seqComplete = false;
- public int seqFrame;
- public int seqCycle;
+ public final int level;
+ public final int x;
+ public final int z;
+ public final int y;
+ public final int startCycle;
+ public final SpotAnimType type;
+ public boolean seqComplete = false;
+ public int seqFrame;
+ public int seqCycle;
- public SpotAnimEntity(int level, int cycle, int delay, int id, int y, int z, int x) {
- type = SpotAnimType.instances[id];
- this.level = level;
- this.x = x;
- this.z = z;
- this.y = y;
- startCycle = cycle + delay;
- }
+ public SpotAnimEntity(int level, int cycle, int delay, int id, int y, int z, int x) {
+ type = SpotAnimType.instances[id];
+ this.level = level;
+ this.x = x;
+ this.z = z;
+ this.y = y;
+ startCycle = cycle + delay;
+ }
- @Override
- public Model getModel() {
- Model base = type.getModel();
+ @Override
+ public Model getModel() {
+ Model base = type.getModel();
- if (base == null) {
- return null;
- }
+ if (base == null) {
+ return null;
+ }
- int transformID = type.seq.transformIDs[seqFrame];
+ int transformID = type.seq.transformIDs[seqFrame];
- Model model = new Model(true, SeqTransform.isNull(transformID), false, base);
+ Model model = new Model(true, SeqTransform.isNull(transformID), false, base);
- if (!seqComplete) {
- model.createLabelReferences();
- model.applyTransform(transformID);
- model.labelFaces = null;
- model.labelVertices = null;
- }
+ if (!seqComplete) {
+ model.createLabelReferences();
+ model.applyTransform(transformID);
+ model.labelFaces = null;
+ model.labelVertices = null;
+ }
- if ((type.scaleXY != 128) || (type.scaleZ != 128)) {
- model.scale(type.scaleXY, type.scaleXY, type.scaleZ);
- }
+ if ((type.scaleXY != 128) || (type.scaleZ != 128)) {
+ model.scale(type.scaleXY, type.scaleXY, type.scaleZ);
+ }
- if (type.rotation != 0) {
- if (type.rotation == 90) {
- model.rotateY90();
- }
- if (type.rotation == 180) {
- model.rotateY90();
- model.rotateY90();
- }
- if (type.rotation == 270) {
- model.rotateY90();
- model.rotateY90();
- model.rotateY90();
- }
- }
- model.calculateNormals(64 + type.lightAmbient, 850 + type.lightAttenuation, -30, -50, -30, true);
- return model;
- }
+ if (type.rotation != 0) {
+ if (type.rotation == 90) {
+ model.rotateY90();
+ }
+ if (type.rotation == 180) {
+ model.rotateY90();
+ model.rotateY90();
+ }
+ if (type.rotation == 270) {
+ model.rotateY90();
+ model.rotateY90();
+ model.rotateY90();
+ }
+ }
+ model.calculateNormals(64 + type.lightAmbient, 850 + type.lightAttenuation, -30, -50, -30, true);
+ return model;
+ }
- public void update(int delta) {
- for (seqCycle += delta; seqCycle > type.seq.getFrameDuration(seqFrame); ) {
- seqCycle -= type.seq.getFrameDuration(seqFrame) + 1;
- seqFrame++;
-
- if (seqFrame >= type.seq.frameCount) {
- seqFrame = 0;
- seqComplete = true;
- }
- }
- }
+ public void update(int delta) {
+ for (seqCycle += delta; seqCycle > type.seq.getFrameDuration(seqFrame); ) {
+ seqCycle -= type.seq.getFrameDuration(seqFrame) + 1;
+ seqFrame++;
+
+ if (seqFrame >= type.seq.frameCount) {
+ seqFrame = 0;
+ seqComplete = true;
+ }
+ }
+ }
}
diff --git a/src/main/java/StringUtil.java b/src/main/java/StringUtil.java
index f246dff..039c53b 100644
--- a/src/main/java/StringUtil.java
+++ b/src/main/java/StringUtil.java
@@ -5,93 +5,94 @@ import java.util.Arrays;
*/
public class StringUtil {
- private static final char[] BASE37_TABLE = { //
- '_', //
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', //
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' //
- };
+ private static final char[] BASE37_TABLE = { //
+ '_', //
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', //
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' //
+ };
- public static long toBase37(String s) {
- long l = 0L;
- for (int i = 0; (i < s.length()) && (i < 12); i++) {
- char c = s.charAt(i);
- l *= 37L;
- if ((c >= 'A') && (c <= 'Z')) {
- l += (1 + c) - 'A';
- } else if ((c >= 'a') && (c <= 'z')) {
- l += (1 + c) - 'a';
- } else if ((c >= '0') && (c <= '9')) {
- l += (27 + c) - '0';
- }
- }
- while (((l % 37L) == 0L) && (l != 0L)) {
- l /= 37L;
- }
- return l;
- }
+ public static long toBase37(String s) {
+ long l = 0L;
+ for (int i = 0; (i < s.length()) && (i < 12); i++) {
+ char c = s.charAt(i);
+ l *= 37L;
+ if ((c >= 'A') && (c <= 'Z')) {
+ l += (1 + c) - 'A';
+ } else if ((c >= 'a') && (c <= 'z')) {
+ l += (1 + c) - 'a';
+ } else if ((c >= '0') && (c <= '9')) {
+ l += (27 + c) - '0';
+ }
+ }
+ while (((l % 37L) == 0L) && (l != 0L)) {
+ l /= 37L;
+ }
+ return l;
+ }
- public static String fromBase37(long value) {
- if ((value <= 0L) || (value >= 0x5b5b57f8a98a5dd1L)/*37^12*/) {
- return "invalid_name";
- }
- if ((value % 37L) == 0L) {
- return "invalid_name";
- }
- int len = 0;
- char[] tmp = new char[12];
- while (value != 0L) {
- long last = value;
- value /= 37L;
- tmp[11 - len++] = BASE37_TABLE[(int) (last - (value * 37L))];
- }
- return new String(tmp, 12 - len, len);
- }
+ public static String fromBase37(long value) {
+ if ((value <= 0L) || (value >= 0x5b5b57f8a98a5dd1L)/*37^12*/) {
+ return "invalid_name";
+ }
+ if ((value % 37L) == 0L) {
+ return "invalid_name";
+ }
+ int len = 0;
+ char[] tmp = new char[12];
+ while (value != 0L) {
+ long last = value;
+ value /= 37L;
+ tmp[11 - len++] = BASE37_TABLE[(int) (last - (value * 37L))];
+ }
+ return new String(tmp, 12 - len, len);
+ }
- public static long hashCode(String s) {
- s = s.toUpperCase();
- long hash = 0L;
- for (int i = 0; i < s.length(); i++) {
- hash = ((hash * 61L) + (long) s.charAt(i)) - 32L;
- hash = (hash + (hash >> 56)) & 0xffffffffffffffL;
- }
- return hash;
- }
+ public static long hashCode(String s) {
+ s = s.toUpperCase();
+ long hash = 0L;
+ for (int i = 0; i < s.length(); i++) {
+ hash = ((hash * 61L) + (long) s.charAt(i)) - 32L;
+ hash = (hash + (hash >> 56)) & 0xffffffffffffffL;
+ }
+ return hash;
+ }
- public static String formatIPv4(int ipv4) {
- return String.format("%d.%d.%d.%d", (ipv4 >> 24) & 0xff, (ipv4 >> 16) & 0xff, (ipv4 >> 8) & 0xff, ipv4 & 0xff);
- }
+ public static String formatIPv4(int ipv4) {
+ return String.format("%d.%d.%d.%d", (ipv4 >> 24) & 0xff, (ipv4 >> 16) & 0xff, (ipv4 >> 8) & 0xff, ipv4 & 0xff);
+ }
- public static String formatName(long name37) {
- return formatName(fromBase37(name37));
- }
- public static String formatName(String s) {
- if (s.length() > 0) {
- char[] ac = s.toCharArray();
- for (int j = 0; j < ac.length; j++) {
- if (ac[j] == '_') {
- ac[j] = ' ';
- if (((j + 1) < ac.length) && (ac[j + 1] >= 'a') && (ac[j + 1] <= 'z')) {
- ac[j + 1] = (char) ((ac[j + 1] + 'A') - 'a');
- }
- }
- }
- if ((ac[0] >= 'a') && (ac[0] <= 'z')) {
- ac[0] = (char) ((ac[0] + 'A') - 'a');
- }
- return new String(ac);
- } else {
- return s;
- }
- }
+ public static String formatName(long name37) {
+ return formatName(fromBase37(name37));
+ }
- public static String toAsterisks(String s) {
- char[] chars = new char[s.length()];
- Arrays.fill(chars, '*');
- return new String(chars, 0, chars.length);
- }
+ public static String formatName(String s) {
+ if (s.length() > 0) {
+ char[] ac = s.toCharArray();
+ for (int j = 0; j < ac.length; j++) {
+ if (ac[j] == '_') {
+ ac[j] = ' ';
+ if (((j + 1) < ac.length) && (ac[j + 1] >= 'a') && (ac[j + 1] <= 'z')) {
+ ac[j + 1] = (char) ((ac[j + 1] + 'A') - 'a');
+ }
+ }
+ }
+ if ((ac[0] >= 'a') && (ac[0] <= 'z')) {
+ ac[0] = (char) ((ac[0] + 'A') - 'a');
+ }
+ return new String(ac);
+ } else {
+ return s;
+ }
+ }
- private StringUtil() {
+ public static String toAsterisks(String s) {
+ char[] chars = new char[s.length()];
+ Arrays.fill(chars, '*');
+ return new String(chars, 0, chars.length);
+ }
- }
+ private StringUtil() {
+
+ }
}
diff --git a/src/main/java/VarbitType.java b/src/main/java/VarbitType.java
index 1dffefc..262ebb2 100644
--- a/src/main/java/VarbitType.java
+++ b/src/main/java/VarbitType.java
@@ -6,57 +6,57 @@ import java.io.IOException;
public class VarbitType {
- public static VarbitType[] instances;
+ public static VarbitType[] instances;
- public static void unpack(FileArchive archive) throws IOException {
- Buffer buffer = new Buffer(archive.read("varbit.dat"));
- int count = buffer.read16U();
+ public static void unpack(FileArchive archive) throws IOException {
+ Buffer buffer = new Buffer(archive.read("varbit.dat"));
+ int count = buffer.read16U();
- if (instances == null) {
- instances = new VarbitType[count];
- }
+ if (instances == null) {
+ instances = new VarbitType[count];
+ }
- for (int j = 0; j < count; j++) {
- if (instances[j] == null) {
- instances[j] = new VarbitType();
- }
- instances[j].read(buffer);
- }
- if (buffer.position != buffer.data.length) {
- System.out.println("varbit load mismatch");
- }
- }
+ for (int j = 0; j < count; j++) {
+ if (instances[j] == null) {
+ instances[j] = new VarbitType();
+ }
+ instances[j].read(buffer);
+ }
+ if (buffer.position != buffer.data.length) {
+ System.out.println("varbit load mismatch");
+ }
+ }
- public int varp;
- /**
- * The least significant bit.
- */
- public int lsb;
- /**
- * The most significant bit.
- */
- public int msb;
+ public int varp;
+ /**
+ * The least significant bit.
+ */
+ public int lsb;
+ /**
+ * The most significant bit.
+ */
+ public int msb;
- public VarbitType() {
- }
+ public VarbitType() {
+ }
- public void read(Buffer buffer) {
- do {
- int code = buffer.read8U();
- if (code == 0) {
- return;
- } else if (code == 1) {
- varp = buffer.read16U();
- lsb = buffer.read8U();
- msb = buffer.read8U();
- } else if (code == 10) {
- buffer.readString();
- } else if (code == 3 || code == 4) {
- buffer.read32();
- } else {
- System.out.println("Error unrecognised varbit config code: " + code);
- }
- } while (true);
- }
+ public void read(Buffer buffer) {
+ do {
+ int code = buffer.read8U();
+ if (code == 0) {
+ return;
+ } else if (code == 1) {
+ varp = buffer.read16U();
+ lsb = buffer.read8U();
+ msb = buffer.read8U();
+ } else if (code == 10) {
+ buffer.readString();
+ } else if (code == 3 || code == 4) {
+ buffer.read32();
+ } else {
+ System.out.println("Error unrecognised varbit config code: " + code);
+ }
+ } while (true);
+ }
}
diff --git a/src/main/java/VarpType.java b/src/main/java/VarpType.java
index cdac3d2..c1b3c49 100644
--- a/src/main/java/VarpType.java
+++ b/src/main/java/VarpType.java
@@ -6,48 +6,48 @@ import java.io.IOException;
public class VarpType {
- public static int count;
- public static VarpType[] instances;
+ public static int count;
+ public static VarpType[] instances;
- public static void unpack(FileArchive archive) throws IOException {
- Buffer buffer = new Buffer(archive.read("varp.dat"));
- count = buffer.read16U();
- if (instances == null) {
- instances = new VarpType[count];
- }
- for (int i = 0; i < count; i++) {
- if (instances[i] == null) {
- instances[i] = new VarpType();
- }
- instances[i].read(buffer);
- }
- if (buffer.position != buffer.data.length) {
- System.out.println("varptype load mismatch");
- }
- }
+ public static void unpack(FileArchive archive) throws IOException {
+ Buffer buffer = new Buffer(archive.read("varp.dat"));
+ count = buffer.read16U();
+ if (instances == null) {
+ instances = new VarpType[count];
+ }
+ for (int i = 0; i < count; i++) {
+ if (instances[i] == null) {
+ instances[i] = new VarpType();
+ }
+ instances[i].read(buffer);
+ }
+ if (buffer.position != buffer.data.length) {
+ System.out.println("varptype load mismatch");
+ }
+ }
- public int type;
+ public int type;
- public VarpType() {
- }
+ public VarpType() {
+ }
- public void read(Buffer in) {
- while (true) {
- int code = in.read8U();
- if (code == 0) {
- return;
- } else if (code == 1 || code == 2) {
- in.read8U();
- } else if (code == 5) {
- type = in.read16U();
- } else if (code == 7 || code == 12) {
- in.read32();
- } else if (code == 10) {
- in.readString();
- } else {
- System.out.println("Error unrecognised varp config code: " + code);
- }
- }
- }
+ public void read(Buffer in) {
+ while (true) {
+ int code = in.read8U();
+ if (code == 0) {
+ return;
+ } else if (code == 1 || code == 2) {
+ in.read8U();
+ } else if (code == 5) {
+ type = in.read16U();
+ } else if (code == 7 || code == 12) {
+ in.read32();
+ } else if (code == 10) {
+ in.readString();
+ } else {
+ System.out.println("Error unrecognised varp config code: " + code);
+ }
+ }
+ }
}
diff --git a/src/main/java/VertexNormal.java b/src/main/java/VertexNormal.java
index c6892a1..8bbfdcb 100644
--- a/src/main/java/VertexNormal.java
+++ b/src/main/java/VertexNormal.java
@@ -4,12 +4,12 @@
public class VertexNormal {
- public int x;
- public int y;
- public int z;
- public int w;
+ public int x;
+ public int y;
+ public int z;
+ public int w;
- public VertexNormal() {
- }
+ public VertexNormal() {
+ }
}