From: Rene S. <sa...@us...> - 2004-09-22 19:22:55
|
Update of /cvsroot/jake2/jake2/src/jake2/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11556/src/jake2/util Modified Files: QuakeFile.java Lib.java Math3D.java Log Message: major refactoring in game, server and client package Index: Lib.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/Lib.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Lib.java 23 Jul 2004 10:09:55 -0000 1.5 --- Lib.java 22 Sep 2004 19:22:13 -0000 1.6 *************** *** 49,57 **** return (int) v[0] + " " + (int) v[1] + " " + (int) v[2]; } - public static String vtofs(float[] v) { return v[0] + " " + v[1] + " " + v[2]; } - public static String vtofsbeaty(float[] v) { return Com.sprintf("%8.2f %8.2f %8.2f", new Vargs().add(v[0]).add(v[1]).add(v[2])); --- 49,55 ---- *************** *** 71,86 **** return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } - public static int strcmp(String in1, String in2) { return in1.compareTo(in2); } - public static boolean strstr(String i1, String i2) { return (i1.indexOf(i2) != -1); } - public static float atof(String in) { float res = 0; ! try { res = Float.parseFloat(in); --- 69,81 ---- return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } public static int strcmp(String in1, String in2) { return in1.compareTo(in2); } public static boolean strstr(String i1, String i2) { return (i1.indexOf(i2) != -1); } public static float atof(String in) { float res = 0; ! try { res = Float.parseFloat(in); *************** *** 88,101 **** catch (Exception e) { } ! return res; } - public static int Q_stricmp(String in1, String in2) { return in1.compareToIgnoreCase(in2); } - // ================================================================================= ! public static int atoi(String in) { try { --- 83,94 ---- catch (Exception e) { } ! return res; } public static int Q_stricmp(String in1, String in2) { return in1.compareToIgnoreCase(in2); } // ================================================================================= ! public static int atoi(String in) { try { *************** *** 106,123 **** } } - public static float[] atov(String v) { float[] res = { 0, 0, 0 }; ! int i1 = v.indexOf(" "); int i2 = v.indexOf(" ", i1 + 1); ! res[0] = atof(v.substring(0, i1)); res[1] = atof(v.substring(i1 + 1, i2)); res[2] = atof(v.substring(i2 + 1, v.length())); ! return res; } - public static int strlen(char in[]) { for (int i = 0; i < in.length; i++) --- 99,114 ---- } } public static float[] atov(String v) { float[] res = { 0, 0, 0 }; ! int i1 = v.indexOf(" "); int i2 = v.indexOf(" ", i1 + 1); ! res[0] = atof(v.substring(0, i1)); res[1] = atof(v.substring(i1 + 1, i2)); res[2] = atof(v.substring(i2 + 1, v.length())); ! return res; } public static int strlen(char in[]) { for (int i = 0; i < in.length; i++) *************** *** 126,130 **** return in.length; } - public static int strlen(byte in[]) { for (int i = 0; i < in.length; i++) --- 117,120 ---- *************** *** 133,137 **** return in.length; } - static byte[] buffer = new byte[Defines.MAX_INFO_STRING]; public static String readString(ByteBuffer bb, int len) { --- 123,126 ---- *************** *** 139,154 **** return new String(buffer, 0, len); } - public static String hexdumpfile(ByteBuffer bb, int len) throws IOException { ! ByteBuffer bb1 = bb.slice(); ! byte buf[] = new byte[len]; ! bb1.get(buf); ! return hexDump(buf, len, false); } - // dump data as hexstring public static String hexDump(byte data1[], int len, boolean showAddress) { --- 128,141 ---- return new String(buffer, 0, len); } public static String hexdumpfile(ByteBuffer bb, int len) throws IOException { ! ByteBuffer bb1 = bb.slice(); ! byte buf[] = new byte[len]; ! bb1.get(buf); ! return hexDump(buf, len, false); } // dump data as hexstring public static String hexDump(byte data1[], int len, boolean showAddress) { *************** *** 165,175 **** } int v = data1[i]; ! result.append(hex2(v)); result.append(" "); ! charfield.append(readableChar(v)); i++; ! // nach dem letzten, newline einfuegen if ((i & 0xf) == 0) { --- 152,162 ---- } int v = data1[i]; ! result.append(hex2(v)); result.append(" "); ! charfield.append(readableChar(v)); i++; ! // nach dem letzten, newline einfuegen if ((i & 0xf) == 0) { *************** *** 185,189 **** return result.toString(); } - //formats an hex byte public static String hex2(int i) { --- 172,175 ---- *************** *** 191,195 **** return ("00".substring(0, 2 - val.length()) + val).toUpperCase(); } - public static char readableChar(int i) { if ((i < 0x20) || (i > 0x7f)) --- 177,180 ---- *************** *** 198,202 **** return (char) i; } - public static void printv(String in, float arr[]) { for (int n = 0; n < arr.length; n++) { --- 183,186 ---- *************** *** 204,210 **** } } - static final byte nullfiller[] = new byte[8192]; - public static void fwriteString(String s, int len, RandomAccessFile f) throws IOException { if (s == null) --- 188,192 ---- *************** *** 213,217 **** if (diff > 0) { f.write(s.getBytes()); ! f.write(nullfiller, 0, diff); } --- 195,199 ---- if (diff > 0) { f.write(s.getBytes()); ! f.write(nullfiller, 0, diff); } *************** *** 219,223 **** f.write(s.getBytes(), 0, len); } - public static RandomAccessFile fopen(String name, String mode) { try { --- 201,204 ---- *************** *** 229,233 **** } } - public static void fclose(RandomAccessFile f) { try { --- 210,213 ---- *************** *** 237,248 **** } } - public static String freadString(RandomAccessFile f, int len) { byte buffer[] = new byte[len]; FS.Read(buffer, len, f); ! return new String(buffer).trim(); } - public static String rightFrom(String in, char c) { int pos = in.lastIndexOf(c); --- 217,226 ---- } } public static String freadString(RandomAccessFile f, int len) { byte buffer[] = new byte[len]; FS.Read(buffer, len, f); ! return new String(buffer).trim(); } public static String rightFrom(String in, char c) { int pos = in.lastIndexOf(c); *************** *** 253,257 **** return ""; } - public static String leftFrom(String in, char c) { int pos = in.lastIndexOf(c); --- 231,234 ---- *************** *** 262,284 **** return ""; } - public static String[] linesplit(String in) { ! StringTokenizer tk = new StringTokenizer(in, "\r\n"); ! int count = tk.countTokens(); if (count == 0) return new String[] { }; ! String result[] = new String[count]; ! for (int i = 0; tk.hasMoreTokens(); i++) { result[i] = tk.nextToken(); } ! return result; } - public static int rename(String oldn, String newn) { try { --- 239,259 ---- return ""; } public static String[] linesplit(String in) { ! StringTokenizer tk = new StringTokenizer(in, "\r\n"); ! int count = tk.countTokens(); if (count == 0) return new String[] { }; ! String result[] = new String[count]; ! for (int i = 0; tk.hasMoreTokens(); i++) { result[i] = tk.nextToken(); } ! return result; } public static int rename(String oldn, String newn) { try { *************** *** 292,296 **** } } - public static byte[] getIntBytes(int c) { byte b[] = new byte[4]; --- 267,270 ---- *************** *** 301,318 **** return b; } - public static int getInt(byte b[]) { return (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | ((b[3] & 0xff) << 24); } - public static float[] clone(float in[]) { float out[] = new float[in.length]; ! if (in.length != 0) System.arraycopy(in, 0, out, 0, in.length); ! return out; } ! /* * java.nio.* Buffer util functions --- 275,290 ---- return b; } public static int getInt(byte b[]) { return (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | ((b[3] & 0xff) << 24); } public static float[] clone(float in[]) { float out[] = new float[in.length]; ! if (in.length != 0) System.arraycopy(in, 0, out, 0, in.length); ! return out; } ! /* * java.nio.* Buffer util functions *************** *** 321,345 **** public static final int SIZEOF_FLOAT = BufferUtils.SIZEOF_FLOAT; public static final int SIZEOF_INT = BufferUtils.SIZEOF_INT; - public static FloatBuffer newFloatBuffer(int numElements) { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); return bb.asFloatBuffer(); } - public static FloatBuffer newFloatBuffer(int numElements, ByteOrder order) { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT, order); return bb.asFloatBuffer(); } - public static IntBuffer newIntBuffer(int numElements) { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); return bb.asIntBuffer(); } - public static IntBuffer newIntBuffer(int numElements, ByteOrder order) { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT, order); return bb.asIntBuffer(); } - public static ByteBuffer newByteBuffer(int numElements) { ByteBuffer bb = ByteBuffer.allocateDirect(numElements); --- 293,312 ---- *************** *** 347,351 **** return bb; } - public static ByteBuffer newByteBuffer(int numElements, ByteOrder order) { ByteBuffer bb = ByteBuffer.allocateDirect(numElements); --- 314,317 ---- *************** *** 353,356 **** return bb; } - } --- 319,321 ---- Index: Math3D.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/Math3D.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Math3D.java 10 Sep 2004 19:02:56 -0000 1.6 --- Math3D.java 22 Sep 2004 19:22:13 -0000 1.7 *************** *** 28,36 **** import jake2.qcommon.Com; ! public class Math3D extends Lib { ! static final float shortratio = 360.0f / 65536.0f; ! static final float piratio = (float)(Math.PI / 360.0); ! public static void set(float v1[], float v2[]) { v1[0] = v2[0]; --- 28,35 ---- import jake2.qcommon.Com; ! public class Math3D { ! static final float shortratio = 360.0f / 65536.0f; ! static final float piratio = (float) (Math.PI / 360.0); public static void set(float v1[], float v2[]) { v1[0] = v2[0]; *************** *** 38,43 **** v1[2] = v2[2]; } - - public static void VectorSubtract(float[] a, float[] b, float[] c) { c[0] = a[0] - b[0]; --- 37,40 ---- *************** *** 45,49 **** c[2] = a[2] - b[2]; } - public static void VectorSubtract(short[] a, short[] b, int[] c) { c[0] = a[0] - b[0]; --- 42,45 ---- *************** *** 51,55 **** c[2] = a[2] - b[2]; } - public static void VectorAdd(float[] a, float[] b, float[] to) { to[0] = a[0] + b[0]; --- 47,50 ---- *************** *** 57,61 **** to[2] = a[2] + b[2]; } - public static void VectorCopy(float[] from, float[] to) { to[0] = from[0]; --- 52,55 ---- *************** *** 63,67 **** to[2] = from[2]; } - public static void VectorCopy(short[] from, short[] to) { to[0] = from[0]; --- 57,60 ---- *************** *** 69,73 **** to[2] = from[2]; } - public static void VectorCopy(short[] from, float[] to) { to[0] = from[0]; --- 62,65 ---- *************** *** 75,79 **** to[2] = from[2]; } - public static void VectorCopy(float[] from, short[] to) { to[0] = (short) from[0]; --- 67,70 ---- *************** *** 81,85 **** to[2] = (short) from[2]; } - public static void VectorClear(float[] a) { a[0] = a[1] = a[2] = 0; --- 72,75 ---- *************** *** 117,121 **** return length; } - public static final float VectorLength(float v[]) { return (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); --- 107,110 ---- *************** *** 131,135 **** out[2] = in[2] * scale; } - public static float vectoyaw(float[] vec) { float yaw; --- 120,123 ---- *************** *** 152,156 **** return yaw; } - public static void vectoangles(float[] value1, float[] angles) { --- 140,143 ---- *************** *** 184,195 **** angles[Defines.ROLL] = 0; } - private static float m[][] = new float[3][3]; private static float im[][] = new float[3][3]; private static float tmpmat[][] = new float[3][3]; private static float zrot[][] = new float[3][3]; - public static void RotatePointAroundVector(float[] dst, float[] dir, float[] point, float degrees) { ! float[] vr = { 0.0f, 0.0f, 0.0f }; float[] vup = { 0.0f, 0.0f, 0.0f }; --- 171,180 ---- angles[Defines.ROLL] = 0; } private static float m[][] = new float[3][3]; private static float im[][] = new float[3][3]; private static float tmpmat[][] = new float[3][3]; private static float zrot[][] = new float[3][3]; public static void RotatePointAroundVector(float[] dst, float[] dir, float[] point, float degrees) { ! float[] vr = { 0.0f, 0.0f, 0.0f }; float[] vup = { 0.0f, 0.0f, 0.0f }; *************** *** 200,205 **** vf[2] = dir[2]; ! Math3D.PerpendicularVector(vr, dir); ! Math3D.CrossProduct(vr, vf, vup); m[0][0] = vr[0]; --- 185,190 ---- vf[2] = dir[2]; ! PerpendicularVector(vr, dir); ! CrossProduct(vr, vf, vup); m[0][0] = vr[0]; *************** *** 229,238 **** zrot[2][2] = 1.0F; ! zrot[0][0] = zrot[1][1] = (float) Math.cos(Math3D.DEG2RAD(degrees)); ! zrot[0][1] = (float) Math.sin(Math3D.DEG2RAD(degrees)); zrot[1][0] = -zrot[0][1]; ! Math3D.R_ConcatRotations(m, zrot, tmpmat); ! Math3D.R_ConcatRotations(tmpmat, im, zrot); for (int i = 0; i < 3; i++) { --- 214,223 ---- zrot[2][2] = 1.0F; ! zrot[0][0] = zrot[1][1] = (float) Math.cos(DEG2RAD(degrees)); ! zrot[0][1] = (float) Math.sin(DEG2RAD(degrees)); zrot[1][0] = -zrot[0][1]; ! R_ConcatRotations(m, zrot, tmpmat); ! R_ConcatRotations(tmpmat, im, zrot); for (int i = 0; i < 3; i++) { *************** *** 240,245 **** } } - - public static void MakeNormalVectors(float[] forward, float[] right, float[] up) { // this rotate and negat guarantees a vector --- 225,228 ---- *************** *** 254,263 **** CrossProduct(right, forward, up); } - - public static float SHORT2ANGLE(int x) { return (x * shortratio); } - /* ================ --- 237,243 ---- *************** *** 279,283 **** out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + in1[2][2] * in2[2][3] + in1[2][3]; } - /** * concatenates 2 matrices each [3][3]. --- 259,262 ---- *************** *** 294,303 **** out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2]; } - public static void ProjectPointOnPlane(float[] dst, float[] p, float[] normal) { ! float inv_denom = 1.0F / Math3D.DotProduct(normal, normal); ! float d = Math3D.DotProduct(normal, p) * inv_denom; dst[0] = normal[0] * inv_denom; --- 273,281 ---- out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2]; } public static void ProjectPointOnPlane(float[] dst, float[] p, float[] normal) { ! float inv_denom = 1.0F / DotProduct(normal, normal); ! float d = DotProduct(normal, p) * inv_denom; dst[0] = normal[0] * inv_denom; *************** *** 309,313 **** dst[2] = p[2] - d * dst[2]; } - /** assumes "src" is normalized */ public static void PerpendicularVector(float[] dst, float[] src) { --- 287,290 ---- *************** *** 316,320 **** float minelem = 1.0F; - // find the smallest magnitude axially aligned vector for (pos = 0, i = 0; i < 3; i++) { --- 293,296 ---- *************** *** 331,337 **** //normalize the result ! Math3D.VectorNormalize(dst); } - //===================================================================== /** --- 307,312 ---- //normalize the result ! VectorNormalize(dst); } //===================================================================== /** *************** *** 340,346 **** erste Version mit vec3_t... */ public static final int BoxOnPlaneSide(float emins[], float emaxs[], cplane_t p) { ! ! assert (emins.length == 3 && emaxs.length == 3) : "vec3_t bug"; ! float dist1, dist2; int sides; --- 315,321 ---- erste Version mit vec3_t... */ public static final int BoxOnPlaneSide(float emins[], float emaxs[], cplane_t p) { ! ! assert(emins.length == 3 && emaxs.length == 3) : "vec3_t bug"; ! float dist1, dist2; int sides; *************** *** 391,395 **** default : dist1 = dist2 = 0; ! assert (false) : "BoxOnPlaneSide bug"; break; } --- 366,370 ---- default : dist1 = dist2 = 0; ! assert(false) : "BoxOnPlaneSide bug"; break; } *************** *** 401,413 **** sides |= 2; ! assert (sides != 0) : "BoxOnPlaneSide(): sides == 0 bug"; return sides; ! } ! // this is the slow, general version private static float corners[][] = new float[2][3]; public static final int BoxOnPlaneSide2(float[] emins, float[] emaxs, cplane_t p) { - for (int i = 0; i < 3; i++) { --- 376,386 ---- sides |= 2; ! assert(sides != 0) : "BoxOnPlaneSide(): sides == 0 bug"; return sides; ! } // this is the slow, general version private static float corners[][] = new float[2][3]; public static final int BoxOnPlaneSide2(float[] emins, float[] emaxs, cplane_t p) { for (int i = 0; i < 3; i++) { *************** *** 421,426 **** } } ! float dist1 = Math3D.DotProduct(p.normal, corners[0]) - p.dist; ! float dist2 = Math3D.DotProduct(p.normal, corners[1]) - p.dist; int sides = 0; if (dist1 >= 0) --- 394,399 ---- } } ! float dist1 = DotProduct(p.normal, corners[0]) - p.dist; ! float dist2 = DotProduct(p.normal, corners[1]) - p.dist; int sides = 0; if (dist1 >= 0) *************** *** 431,435 **** return sides; } - public static void AngleVectors(float[] angles, float[] forward, float[] right, float[] up) { --- 404,407 ---- *************** *** 465,483 **** } } ! ! public static void G_ProjectSource(float[] point, float[] distance, float[] forward, float[] right, float[] result) { result[0] = point[0] + forward[0] * distance[0] + right[0] * distance[1]; result[1] = point[1] + forward[1] * distance[0] + right[1] * distance[1]; result[2] = point[2] + forward[2] * distance[0] + right[2] * distance[1] + distance[2]; } - - - public static final float DotProduct(float[] x, float[] y) { return x[0] * y[0] + x[1] * y[1] + x[2] * y[2]; } - - - public static void CrossProduct(float[] v1, float[] v2, float[] cross) { cross[0] = v1[1] * v2[2] - v1[2] * v2[1]; --- 437,453 ---- } } ! public static void G_ProjectSource( ! float[] point, ! float[] distance, ! float[] forward, ! float[] right, ! float[] result) { result[0] = point[0] + forward[0] * distance[0] + right[0] * distance[1]; result[1] = point[1] + forward[1] * distance[0] + right[1] * distance[1]; result[2] = point[2] + forward[2] * distance[0] + right[2] * distance[1] + distance[2]; } public static final float DotProduct(float[] x, float[] y) { return x[0] * y[0] + x[1] * y[1] + x[2] * y[2]; } public static void CrossProduct(float[] v1, float[] v2, float[] cross) { cross[0] = v1[1] * v2[2] - v1[2] * v2[1]; *************** *** 485,491 **** cross[2] = v1[0] * v2[1] - v1[1] * v2[0]; } - - - public static int Q_log2(int val) { int answer = 0; --- 455,458 ---- *************** *** 494,518 **** return answer; } - - - public static float DEG2RAD(float in) { return (in * (float) Math.PI) / 180.0f; } - - - public static float anglemod(float a) { return (float) (shortratio) * ((int) (a / (shortratio)) & 65535); } - - - public static int ANGLE2SHORT(float x) { return ((int) ((x) / shortratio) & 65535); } - - - public static float LerpAngle(float a2, float a1, float frac) { if (a1 - a2 > 180) --- 461,473 ---- *************** *** 522,527 **** return a2 + frac * (a1 - a2); } - - public static float CalcFov(float fov_x, float width, float height) { double a = 0.0f; --- 477,480 ---- *************** *** 537,541 **** a = a / piratio; ! return (float)a; } } --- 490,494 ---- a = a / piratio; ! return (float) a; } } Index: QuakeFile.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/QuakeFile.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** QuakeFile.java 10 Sep 2004 19:02:56 -0000 1.3 --- QuakeFile.java 22 Sep 2004 19:22:13 -0000 1.4 *************** *** 1,28 **** /* ! Copyright (C) 1997-2001 Id Software, Inc. ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! See the GNU General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ // Created on 24.07.2004 by RST. // $Id$ - package jake2.util; ! import jake2.game.Game; import jake2.game.SuperAdapter; import jake2.game.edict_t; --- 1,28 ---- /* ! Copyright (C) 1997-2001 Id Software, Inc. ! This program is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! See the GNU General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ // Created on 24.07.2004 by RST. // $Id$ package jake2.util; ! import jake2.game.GameAI; ! import jake2.game.GameBase; import jake2.game.SuperAdapter; import jake2.game.edict_t; *************** *** 30,182 **** import jake2.qcommon.Com; ! import java.io.*; ! /** ! * RandomAccessFile, but handles readString/WriteString specially and ! * offers other helper functions */ ! public class QuakeFile extends RandomAccessFile ! { ! /** Standard Constructor.*/ ! public QuakeFile(String filename, String mode) throws FileNotFoundException ! { ! super(filename, mode); ! } ! /** Writes a Vector to a RandomAccessFile. */ ! public void writeVector(float v[]) throws IOException ! { ! for (int n= 0; n < 3; n++) ! writeFloat(v[n]); ! } ! /** Writes a Vector to a RandomAccessFile. */ ! public float[] readVector() throws IOException ! { ! float res[]= { 0, 0, 0 }; ! for (int n= 0; n < 3; n++) ! res[n]= readFloat(); ! return res; ! } ! /** Reads a length specified string from a file. */ ! public String readString() throws IOException ! { ! int len= readInt(); ! if (len == -1) ! return null; ! if (len == 0) ! return ""; ! byte bb[]= new byte[len]; ! super.read(bb, 0, len); ! return new String(bb, 0, len); ! } ! /** Writes a length specified string to a file. */ ! public void writeString(String s) throws IOException ! { ! if (s == null) ! { ! writeInt(-1); ! return; ! } ! writeInt(s.length()); ! if (s.length() != 0) ! writeBytes(s); ! } ! /** Writes the edict reference. */ ! public void writeEdictRef(edict_t ent) throws IOException ! { ! if (ent == null) ! writeInt(-1); ! else ! { ! writeInt(ent.s.number); ! } ! } ! /** ! * Reads an edict index from a file and returns the edict. ! */ ! public edict_t readEdictRef() throws IOException ! { ! int i= readInt(); ! // handle -1 ! if (i < 0) ! return null; ! if (i > Game.g_edicts.length) ! { ! Com.DPrintf("jake2: illegal edict num:" + i + "\n"); ! return null; ! } ! // valid edict. ! return Game.g_edicts[i]; ! } ! /** Writes the Adapter-ID to the file. */ ! public void writeAdapter(SuperAdapter a) throws IOException ! { ! writeInt(3988); ! if (a == null) ! writeString(null); ! else ! { ! String str= a.getID(); ! if (a == null) ! { ! Com.DPrintf("writeAdapter: invalid Adapter id for " + a + "\n"); ! } ! writeString(str); ! } ! } ! /** Reads the adapter id and returns the adapter. */ ! public SuperAdapter readAdapter() throws IOException ! { ! if (readInt() != 3988) ! Com.DPrintf("wrong read position: readadapter 3988 \n"); ! String id= readString(); ! if (id == null) ! { ! // null adapter. :-) ! return null; ! } ! return SuperAdapter.getFromID(id); ! } ! /** Writes an item reference. */ ! public void writeItem(gitem_t item) throws IOException ! { ! if (item == null) ! writeInt(-1); ! else ! writeInt(item.index); ! } ! /** Reads the item index and returns the game item. */ ! public gitem_t readItem() throws IOException ! { ! int ndx= readInt(); ! if (ndx == -1) ! return null; ! else ! return Game.itemlist[ndx]; ! } ! } --- 30,166 ---- import jake2.qcommon.Com; ! import java.io.FileNotFoundException; ! import java.io.IOException; ! import java.io.RandomAccessFile; ! /** ! * RandomAccessFile, but handles readString/WriteString specially and offers ! * other helper functions */ ! public class QuakeFile extends RandomAccessFile { ! /** Standard Constructor. */ ! public QuakeFile(String filename, String mode) throws FileNotFoundException { ! super(filename, mode); ! } ! /** Writes a Vector to a RandomAccessFile. */ ! public void writeVector(float v[]) throws IOException { ! for (int n = 0; n < 3; n++) ! writeFloat(v[n]); ! } ! /** Writes a Vector to a RandomAccessFile. */ ! public float[] readVector() throws IOException { ! float res[] = { 0, 0, 0 }; ! for (int n = 0; n < 3; n++) ! res[n] = readFloat(); ! return res; ! } ! /** Reads a length specified string from a file. */ ! public String readString() throws IOException { ! int len = readInt(); ! if (len == -1) ! return null; ! if (len == 0) ! return ""; ! byte bb[] = new byte[len]; ! super.read(bb, 0, len); ! return new String(bb, 0, len); ! } ! /** Writes a length specified string to a file. */ ! public void writeString(String s) throws IOException { ! if (s == null) { ! writeInt(-1); ! return; ! } ! writeInt(s.length()); ! if (s.length() != 0) ! writeBytes(s); ! } ! /** Writes the edict reference. */ ! public void writeEdictRef(edict_t ent) throws IOException { ! if (ent == null) ! writeInt(-1); ! else { ! writeInt(ent.s.number); ! } ! } ! /** ! * Reads an edict index from a file and returns the edict. ! */ ! public edict_t readEdictRef() throws IOException { ! int i = readInt(); ! // handle -1 ! if (i < 0) ! return null; ! if (i > GameBase.g_edicts.length) { ! Com.DPrintf("jake2: illegal edict num:" + i + "\n"); ! return null; ! } ! // valid edict. ! return GameBase.g_edicts[i]; ! } ! /** Writes the Adapter-ID to the file. */ ! public void writeAdapter(SuperAdapter a) throws IOException { ! writeInt(3988); ! if (a == null) ! writeString(null); ! else { ! String str = a.getID(); ! if (a == null) { ! Com.DPrintf("writeAdapter: invalid Adapter id for " + a + "\n"); ! } ! writeString(str); ! } ! } ! /** Reads the adapter id and returns the adapter. */ ! public SuperAdapter readAdapter() throws IOException { ! if (readInt() != 3988) ! Com.DPrintf("wrong read position: readadapter 3988 \n"); ! String id = readString(); ! if (id == null) { ! // null adapter. :-) ! return null; ! } ! return SuperAdapter.getFromID(id); ! } ! /** Writes an item reference. */ ! public void writeItem(gitem_t item) throws IOException { ! if (item == null) ! writeInt(-1); ! else ! writeInt(item.index); ! } ! /** Reads the item index and returns the game item. */ ! public gitem_t readItem() throws IOException { ! int ndx = readInt(); ! if (ndx == -1) ! return null; ! else ! return GameAI.itemlist[ndx]; ! } ! } \ No newline at end of file |