/* */ package NET.worlds.scape; /* */ /* */ import java.io.DataInputStream; /* */ import java.io.DataOutputStream; /* */ import java.io.IOException; /* */ import java.io.PrintStream; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class TCompressor /* */ { /* */ private static final int CMAP_MAXPOSCOMP = 128; /* */ private static final int CMAP_DEFAULTAXIS = 0; /* */ private static final int CMAP_XUNITARY = 32; /* */ private static final int CMAP_YUNITARY = 64; /* */ private static final int CMAP_ZUNITARY = 96; /* */ private static final int CMAP_ROTATION = 16; /* */ private static final int CMAP_ROTSIGN1 = 8; /* */ private static final int CMAP_ROTSIGN2 = 4; /* */ private static final int CMAP_SCALE = 2; /* */ private static final int CMAP_UNIFORMSCALE = 1; /* */ private static final int MODE_SENDCMAP = 8388608; /* */ private static final int MODE_SENDZ = 4194304; /* */ private static final int MODE_MAXPOSCOMP = 128; /* */ private static final int MODE_SENDROTAXIS = 96; /* */ private static final int MODE_SENDROTATION = 16; /* */ private static final int MODE_SENDSCALE = 2; /* */ public static final int USER_SEND_POSITION = 32768; /* */ public static final int USER_SEND_ROTATION = 16384; /* */ public static final int USER_SEND_SCALE = 8192; /* */ public static final int USER_SEND_ALL = 57344; /* */ private static final int LOW21BITSMASK = 2097151; /* */ private static final int LOW18BITSMASK = 262143; /* */ private static final int LOW12BITSMASK = 4095; /* */ private static final int LOW10BITSMASK = 1023; /* */ private static final int LOW8BITSMASK = 255; /* */ private static final int BIT20 = 1048576; /* */ private static final double SCFACT = 16.0D; /* */ private static final double SCOFFSET = 121.6D; /* 88 */ static int wroteBytes = 0; /* */ /* 90 */ public static boolean dontSend = false; /* */ /* */ /* */ /* */ /* */ /* */ /* */ public static void compress(WObject w, Point3Temp defPos, Point3Temp defRAxis, float defRotation, Point3Temp defScale, int inputModes, DataOutputStream ds) /* */ throws IOException /* */ { /* 100 */ Point3Temp pos = w.getPosition(); /* 101 */ Point3Temp rAxis = Point3Temp.make(); /* 102 */ float rotation = w.getSpin(rAxis); /* 103 */ Point3Temp scale = w.getScale(); /* */ /* 105 */ if (dontSend) /* */ { /* 107 */ System.err.println("DONTSEND is TRUE on COMPRESS CALL"); /* 108 */ return; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 119 */ int mode = inputModes; /* */ /* 121 */ if ((mode & 0x8000) != 0) /* */ { /* */ /* 124 */ if ((pos.x >= 0.0F) && (pos.x <= 4095.0D) && /* 125 */ (pos.y >= 0.0F) && (pos.y <= 4095.0D) && ( /* 126 */ ((pos.z >= 0.0F) && (pos.z <= 255.0D)) || (pos.z == defPos.z))) /* 127 */ mode |= 0x80; /* 128 */ if (pos.z != defPos.z) { mode |= 0x400000; /* */ } /* */ } /* */ /* */ /* 133 */ int outaxis1 = 0;int outaxis2 = 0; /* */ /* 135 */ if (((mode & 0x4000) != 0) && (!rAxis.sameValue(defRAxis))) /* */ { /* 137 */ int axisFlag = 0; /* */ /* */ /* */ /* */ /* 142 */ float maxAxis = rAxis.x; /* 143 */ axisFlag = 32; /* */ /* 145 */ if (Math.abs(rAxis.y) > Math.abs(maxAxis)) /* */ { /* 147 */ maxAxis = rAxis.y; /* 148 */ axisFlag = 64; /* */ } /* 150 */ if (Math.abs(rAxis.z) > Math.abs(maxAxis)) /* */ { /* 152 */ maxAxis = rAxis.z; /* 153 */ axisFlag = 96; /* */ } /* */ /* 156 */ rAxis.x /= maxAxis; /* 157 */ rAxis.y /= maxAxis; /* 158 */ rAxis.z /= maxAxis; /* */ /* 160 */ mode |= axisFlag; /* */ /* 162 */ if (maxAxis < 0.0F) { /* 163 */ rotation *= -1.0F; /* */ } /* */ /* 166 */ switch (axisFlag) /* */ { /* */ case 32: /* 169 */ if (rAxis.y < 0.0F) mode |= 0x8; /* 170 */ if (rAxis.z < 0.0F) mode |= 0x4; /* 171 */ outaxis1 = Math.round(Math.abs(255.0F * rAxis.y)); /* 172 */ outaxis2 = Math.round(Math.abs(255.0F * rAxis.z)); /* 173 */ break; /* */ case 64: /* 175 */ if (rAxis.x < 0.0F) mode |= 0x8; /* 176 */ if (rAxis.z < 0.0F) mode |= 0x4; /* 177 */ outaxis1 = Math.round(Math.abs(255.0F * rAxis.x)); /* 178 */ outaxis2 = Math.round(Math.abs(255.0F * rAxis.z)); /* 179 */ break; /* */ case 96: /* 181 */ if (rAxis.x < 0.0F) mode |= 0x8; /* 182 */ if (rAxis.y < 0.0F) mode |= 0x4; /* 183 */ outaxis1 = Math.round(Math.abs(255.0F * rAxis.x)); /* 184 */ outaxis2 = Math.round(Math.abs(255.0F * rAxis.y)); /* 185 */ break; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 194 */ if ((outaxis1 == 0) && (outaxis2 == 0) && (maxAxis < 0.0F)) /* */ { /* 196 */ mode |= 0x8; /* 197 */ mode |= 0x4; /* */ } /* */ /* 200 */ while (rotation >= 360.0F) /* 201 */ rotation -= 360.0F; /* 202 */ while (rotation < 0.0F) { /* 203 */ rotation += 360.0F; /* */ } /* 205 */ if (rotation != defRotation) /* */ { /* 207 */ mode |= 0x800000; /* 208 */ mode |= 0x10; /* */ } /* */ } /* */ /* 212 */ if ((mode & 0x2000) != 0) /* */ { /* 214 */ if (!scale.sameValue(defScale)) /* */ { /* 216 */ mode |= 0x800000; /* 217 */ mode |= 0x2; /* 218 */ if ((scale.x == scale.y) && (scale.x == scale.z)) { /* 219 */ mode |= 0x1; /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* 228 */ if ((mode & 0x800000) != 0) /* */ { /* 230 */ ds.writeByte(mode & 0xFF); /* 231 */ wroteBytes += 1; /* */ } /* */ /* 234 */ if ((mode & 0x8000) != 0) /* */ { /* 236 */ if ((mode & 0x80) != 0) /* */ { /* 238 */ maxCompressXY(pos.x, pos.y, ds); /* 239 */ if (((mode & 0x400000) != 0) || /* 240 */ ((mode & 0x800000) != 0)) /* */ { /* 242 */ short iz = (short)Math.round(pos.z); /* 243 */ int outbyte = iz & 0xFF; /* 244 */ ds.writeByte(outbyte); /* 245 */ wroteBytes += 1; /* */ } /* */ } /* */ else /* */ { /* 250 */ minCompressXYZ(pos.x, pos.y, pos.z, ds); /* */ } /* */ } /* */ /* */ /* 255 */ if ((mode & 0x60) != 0) /* */ { /* 257 */ ds.writeByte(outaxis1); /* 258 */ ds.writeByte(outaxis2); /* 259 */ wroteBytes += 2; /* */ } /* */ /* */ /* 263 */ if ((mode & 0x10) != 0) /* */ { /* 265 */ int outbyte = (int)Math.round(256.0D * (rotation / 360.0D)); /* 266 */ ds.writeByte(outbyte); /* 267 */ wroteBytes += 1; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 278 */ if ((mode & 0x2) != 0) /* */ { /* 280 */ double y = 16.0D * Math.log(scale.x / defScale.x) + 121.6D; /* 281 */ if (y < 0.0D) y = 0.0D; /* 282 */ if (y > 255.0D) y = 255.0D; /* 283 */ int outbyte = (int)Math.round(y); /* 284 */ ds.writeByte(outbyte); /* 285 */ wroteBytes += 1; /* 286 */ if ((mode & 0x1) == 0) /* */ { /* 288 */ y = 16.0D * Math.log(scale.y / defScale.y) + 121.6D; /* 289 */ if (y < 0.0D) y = 0.0D; /* 290 */ if (y > 255.0D) y = 255.0D; /* 291 */ outbyte = (int)Math.round(y); /* 292 */ ds.writeByte(outbyte); /* 293 */ wroteBytes += 1; /* */ /* 295 */ y = 16.0D * Math.log(scale.z / defScale.z) + 121.6D; /* 296 */ if (y < 0.0D) y = 0.0D; /* 297 */ if (y > 255.0D) y = 255.0D; /* 298 */ outbyte = (int)Math.round(y); /* 299 */ ds.writeByte(outbyte); /* 300 */ wroteBytes += 1; /* */ } /* */ } /* */ /* */ /* 305 */ wroteBytes = 0; /* */ } /* */ /* */ /* */ /* */ private static void maxCompressXY(float x, float y, DataOutputStream ds) /* */ throws IOException /* */ { /* 313 */ short ix = (short)Math.round(x); /* 314 */ short iy = (short)Math.round(y); /* */ /* */ /* 317 */ ix = (short)(ix & 0xFFF); /* 318 */ iy = (short)(iy & 0xFFF); /* */ /* */ /* */ /* */ /* 323 */ int posbyte = ix >>> 4; /* 324 */ ds.writeByte(posbyte); /* 325 */ wroteBytes += 1; /* */ /* */ /* 328 */ ix = (short)(ix << 4); /* 329 */ ix = (short)(ix & 0xFF); /* */ /* 331 */ posbyte = ix | iy >>> 8; /* 332 */ ds.writeByte(posbyte); /* 333 */ wroteBytes += 1; /* */ /* */ /* 336 */ posbyte = iy & 0xFF; /* 337 */ ds.writeByte(posbyte); /* 338 */ wroteBytes += 1; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ private static void minCompressXYZ(float x, float y, float z, DataOutputStream ds) /* */ throws IOException /* */ { /* 348 */ int xval = floatTo21bits(x); /* 349 */ int yval = floatTo21bits(y); /* 350 */ int zval = floatTo21bits(z); /* */ /* */ /* */ /* 354 */ int outbits = xval << 10 | yval >>> 11; /* 355 */ ds.writeInt(outbits); /* 356 */ wroteBytes += 4; /* */ /* 358 */ outbits = yval << 21 | zval; /* 359 */ ds.writeInt(outbits); /* 360 */ wroteBytes += 4; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ private static int floatTo21bits(float f) /* */ { /* 370 */ for (int e = 0; e <= 3; e++) /* */ { /* 372 */ double decimal = Math.pow(10.0D, e - 2); /* 373 */ float limit = (float)(262144.0D * decimal); /* 374 */ float af = Math.abs(f); /* 375 */ if ((af < limit) || (e == 3)) /* */ { /* 377 */ int m = (int)Math.round(af / decimal); /* 378 */ m &= 0x3FFFF; /* 379 */ m <<= 2; /* 380 */ m |= e; /* 381 */ if (f < 0.0F) m |= 0x100000; /* 382 */ return m; /* */ } /* */ } /* 385 */ return 0; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public static void decompress(WObject w, Point3Temp defPos, Point3Temp defRAxis, float defRotation, Point3Temp defScale, int inputModes, int len, DataInputStream ds) /* */ throws IOException /* */ { /* 397 */ int mode = inputModes; /* */ /* */ /* 400 */ Point3Temp pos = w.getPosition(); /* 401 */ Point3Temp rAxis = Point3Temp.make(); /* 402 */ float rotation = w.getSpin(rAxis); /* 403 */ Point3Temp scale = w.getScale(); /* */ /* 405 */ dontSend = true; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 416 */ if (len == 0) /* */ { /* 418 */ w.moveTo(defPos); /* 419 */ defScale.x /= scale.x; /* 420 */ defScale.y /= scale.y; /* 421 */ defScale.z /= scale.z; /* 422 */ w.scale(scale); /* 423 */ dontSend = false; /* 424 */ return; /* */ } /* */ /* 427 */ if (len == 24) /* */ { /* 429 */ pos.x = ds.readFloat(); /* 430 */ pos.y = ds.readFloat(); /* 431 */ pos.z = ds.readFloat(); /* */ /* 433 */ scale.x = (ds.readFloat() / scale.x); /* 434 */ scale.y = (ds.readFloat() / scale.y); /* 435 */ scale.z = (ds.readFloat() / scale.z); /* */ /* 437 */ w.moveTo(pos); /* 438 */ w.scale(scale); /* 439 */ dontSend = false; /* 440 */ return; /* */ } /* */ /* 443 */ if (len > 4) { /* 444 */ mode |= 0x800000; /* */ } else { /* 446 */ mode |= 0x80; /* */ } /* 448 */ if (len == 4) { /* 449 */ mode |= 0x400000; /* */ } /* 451 */ if ((mode & 0x800000) != 0) /* */ { /* 453 */ int inbyte = ds.readUnsignedByte(); /* 454 */ mode |= inbyte; /* */ /* */ /* 457 */ mode |= 0x400000; /* */ } /* */ /* 460 */ if ((mode & 0x8000) != 0) /* */ { /* 462 */ if ((mode & 0x80) != 0) /* */ { /* 464 */ pos = maxDecompressXY(pos, ds); /* 465 */ if ((mode & 0x400000) != 0) /* */ { /* 467 */ int iz = ds.readUnsignedByte(); /* 468 */ pos.z = iz; /* */ } /* */ } /* */ else /* */ { /* 473 */ pos = minDecompressXYZ(pos, ds); /* */ } /* 475 */ w.moveTo(pos); /* */ } /* */ /* */ /* */ /* 480 */ if ((mode & 0x800000) == 0) /* */ { /* 482 */ dontSend = false; /* 483 */ return; /* */ } /* */ /* */ /* 487 */ if ((mode & 0x10) != 0) { /* 488 */ w.spin(rAxis.x, rAxis.y, rAxis.z, -rotation); /* */ } /* */ /* */ /* 492 */ rAxis.x = defRAxis.x; /* 493 */ rAxis.y = defRAxis.y; /* 494 */ rAxis.z = defRAxis.z; /* 495 */ if ((mode & 0x60) != 0) /* */ { /* 497 */ int inaxis1 = ds.readUnsignedByte(); /* 498 */ int inaxis2 = ds.readUnsignedByte(); /* */ /* 500 */ switch (mode & 0x60) /* */ { /* */ case 0: /* */ break; /* */ /* */ /* */ case 32: /* 507 */ rAxis.x = 1.0F; /* 508 */ rAxis.y = ((float)(inaxis1 / 255.0D)); /* 509 */ rAxis.z = ((float)(inaxis2 / 255.0D)); /* 510 */ if ((mode & 0x8) != 0) { Point3Temp tmp529_527 = rAxis;tmp529_527.y = ((float)(tmp529_527.y * -1.0D)); } /* 511 */ if ((mode & 0x4) != 0) { Point3Temp tmp551_549 = rAxis;tmp551_549.z = ((float)(tmp551_549.z * -1.0D)); /* */ } /* 513 */ if ((rAxis.y == 0.0F) && (rAxis.z == 0.0F) && /* 514 */ ((mode & 0x8) != 0) && ((mode & 0x4) != 0)) { /* 515 */ rAxis.x = -1.0F; /* */ } /* 517 */ break; /* */ /* */ /* */ case 64: /* 521 */ rAxis.y = 1.0F; /* 522 */ rAxis.x = ((float)(inaxis1 / 255.0D)); /* 523 */ rAxis.z = ((float)(inaxis2 / 255.0D)); /* 524 */ if ((mode & 0x8) != 0) { Point3Temp tmp651_649 = rAxis;tmp651_649.x = ((float)(tmp651_649.x * -1.0D)); } /* 525 */ if ((mode & 0x4) != 0) { Point3Temp tmp673_671 = rAxis;tmp673_671.z = ((float)(tmp673_671.z * -1.0D)); /* */ } /* 527 */ if ((rAxis.x == 0.0F) && (rAxis.z == 0.0F) && /* 528 */ ((mode & 0x8) != 0) && ((mode & 0x4) != 0)) { /* 529 */ rAxis.y = -1.0F; /* */ } /* 531 */ break; /* */ /* */ /* */ case 96: /* 535 */ rAxis.z = 1.0F; /* 536 */ rAxis.x = ((float)(inaxis1 / 255.0D)); /* 537 */ rAxis.y = ((float)(inaxis2 / 255.0D)); /* 538 */ if ((mode & 0x8) != 0) { Point3Temp tmp773_771 = rAxis;tmp773_771.x = ((float)(tmp773_771.x * -1.0D)); } /* 539 */ if ((mode & 0x4) != 0) { Point3Temp tmp795_793 = rAxis;tmp795_793.y = ((float)(tmp795_793.y * -1.0D)); /* */ } /* 541 */ if ((rAxis.x == 0.0F) && (rAxis.y == 0.0F) && /* 542 */ ((mode & 0x8) != 0) && ((mode & 0x4) != 0)) { /* 543 */ rAxis.z = -1.0F; /* */ } /* */ break; /* */ } /* */ /* */ } /* 549 */ if ((mode & 0x10) != 0) /* */ { /* 551 */ int inbyte = ds.readUnsignedByte(); /* 552 */ rotation = (float)(360.0D * (inbyte / 256.0D)); /* 553 */ w.worldSpin(rAxis.x, rAxis.y, rAxis.z, rotation); /* */ } /* */ /* */ /* 557 */ if ((mode & 0x2) != 0) /* */ { /* 559 */ int inbyte = ds.readUnsignedByte(); /* 560 */ double s = defScale.x * Math.exp((inbyte - 121.6D) / 16.0D); /* 561 */ scale.x = ((float)s); /* */ /* 563 */ if ((mode & 0x1) != 0) /* */ { /* 565 */ scale.y = scale.x; /* 566 */ scale.z = scale.x; /* */ } /* */ else /* */ { /* 570 */ inbyte = ds.readUnsignedByte(); /* 571 */ s = defScale.y * Math.exp((inbyte - 121.6D) / 16.0D); /* 572 */ scale.y = ((float)s); /* 573 */ inbyte = ds.readUnsignedByte(); /* 574 */ s = defScale.z * Math.exp((inbyte - 121.6D) / 16.0D); /* 575 */ scale.z = ((float)s); /* */ } /* 577 */ Point3Temp oldScale = w.getScale(); /* 578 */ scale.x /= oldScale.x; /* 579 */ scale.y /= oldScale.y; /* 580 */ scale.z /= oldScale.z; /* 581 */ w.scale(scale); /* */ } /* */ /* 584 */ dontSend = false; /* */ } /* */ /* */ private static Point3Temp maxDecompressXY(Point3Temp pos, DataInputStream ds) /* */ throws IOException /* */ { /* 590 */ int ix = ds.readUnsignedByte(); /* 591 */ ix <<= 4; /* */ /* 593 */ int iy = ds.readUnsignedByte(); /* 594 */ ix |= iy >>> 4; /* */ /* 596 */ iy &= 0xF; /* 597 */ iy <<= 8; /* */ /* 599 */ iy |= ds.readUnsignedByte(); /* */ /* 601 */ pos.x = ix; /* 602 */ pos.y = iy; /* */ /* 604 */ return pos; /* */ } /* */ /* */ /* */ /* */ private static Point3Temp minDecompressXYZ(Point3Temp pos, DataInputStream ds) /* */ throws IOException /* */ { /* 612 */ int i1 = ds.readInt(); /* 613 */ int i2 = ds.readInt(); /* */ /* 615 */ int tmp = i1 >>> 10; /* 616 */ pos.x = floatFrom21bits(tmp); /* */ /* 618 */ tmp = (i1 & 0x3FF) << 11; /* 619 */ tmp |= i2 >>> 21; /* 620 */ pos.y = floatFrom21bits(tmp); /* */ /* 622 */ tmp = i2 & 0x1FFFFF; /* 623 */ pos.z = floatFrom21bits(tmp); /* */ /* 625 */ return pos; /* */ } /* */ /* */ /* */ /* */ /* */ private static float floatFrom21bits(int bits) /* */ { /* 633 */ int e = bits & 0x3; /* 634 */ int s = (bits & 0x100000) << 11 | 0x1; /* */ /* 636 */ int m = (bits & 0xFFEFFFFF) >>> 2; /* 637 */ double d = Math.pow(10.0D, e - 2); /* */ /* 639 */ return (float)(m * d * s); /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\TCompressor.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */