From: Carsten W. <ca...@us...> - 2005-12-25 18:11:56
|
Update of /cvsroot/jake2/jake2/src/jake2/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27365/src/jake2/util Modified Files: Tag: render-refactoring Lib.java QuakeFile.java Log Message: merge with current HEAD Index: Lib.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/Lib.java,v retrieving revision 1.13 retrieving revision 1.13.4.1 diff -C2 -d -r1.13 -r1.13.4.1 *** Lib.java 26 May 2005 16:56:31 -0000 1.13 --- Lib.java 25 Dec 2005 18:11:16 -0000 1.13.4.1 *************** *** 34,72 **** ! /* ! ============= ! VectorToString ! ! This is just a convenience function ! for printing vectors ! ============= ! */ public static String vtos(float[] v) { 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])); } public static short rand() { - //return (short) (Math.random() * 0x8000); return (short)Globals.rnd.nextInt(Short.MAX_VALUE+1); } public static float crandom() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; - //return (float) (Math.random() - 0.5) * 2.0f; } public static float random() { return Globals.rnd.nextFloat(); } public static float crand() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } public static int strcmp(String in1, String in2) { return in1.compareTo(in2); } public static float atof(String in) { float res = 0; --- 34,78 ---- ! /** Converts a vector to a string. */ public static String vtos(float[] v) { return (int) v[0] + " " + (int) v[1] + " " + (int) v[2]; } + + /** Converts a vector to a string. */ public static String vtofs(float[] v) { return v[0] + " " + v[1] + " " + v[2]; } + + /** Converts a vector to a beatiful string. */ 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])); } + + /** Like in libc. */ public static short rand() { return (short)Globals.rnd.nextInt(Short.MAX_VALUE+1); } + + /** Like in libc. */ public static float crandom() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } + + /** Like in libc. */ public static float random() { return Globals.rnd.nextFloat(); } + + /** Like in libc. */ public static float crand() { return (Globals.rnd.nextFloat() - 0.5f) * 2.0f; } + + /** Like in libc. */ public static int strcmp(String in1, String in2) { return in1.compareTo(in2); } + /** Like in libc. */ public static float atof(String in) { float res = 0; *************** *** 80,88 **** return res; } public static int Q_stricmp(String in1, String in2) { return in1.compareToIgnoreCase(in2); } - // ================================================================================= public static int atoi(String in) { try { --- 86,96 ---- return res; } + + /** Like in quake2. */ public static int Q_stricmp(String in1, String in2) { return in1.compareToIgnoreCase(in2); } + /** Like in libc. */ public static int atoi(String in) { try { *************** *** 97,112 **** } } 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++) --- 105,121 ---- } } + + /** Converts a string to a vector. Needs improvement. */ public static float[] atov(String v) { float[] res = { 0, 0, 0 }; ! String strres[] = v.split(" "); ! for (int n=0; n < 3 && n < strres.length; n++) ! { ! res[n] = atof(strres[n]); ! } return res; } + + /** Like in libc. */ public static int strlen(char in[]) { for (int i = 0; i < in.length; i++) *************** *** 115,118 **** --- 124,129 ---- return in.length; } + + /** Like in libc. */ public static int strlen(byte in[]) { for (int i = 0; i < in.length; i++) *************** *** 122,125 **** --- 133,137 ---- } + /** Converts memory to a memory dump string. */ public static String hexdumpfile(ByteBuffer bb, int len) throws IOException { *************** *** 132,136 **** return hexDump(buf, len, false); } ! // dump data as hexstring public static String hexDump(byte data1[], int len, boolean showAddress) { StringBuffer result = new StringBuffer(); --- 144,149 ---- return hexDump(buf, len, false); } ! ! /** Converts memory to a memory dump string. */ public static String hexDump(byte data1[], int len, boolean showAddress) { StringBuffer result = new StringBuffer(); *************** *** 166,174 **** return result.toString(); } ! //formats an hex byte public static String hex2(int i) { String val = Integer.toHexString(i & 0xff); ! return ("00".substring(0, 2 - val.length()) + val).toUpperCase(); } public static char readableChar(int i) { if ((i < 0x20) || (i > 0x7f)) --- 179,190 ---- return result.toString(); } ! ! /** Formats an hex byte. */ public static String hex2(int i) { String val = Integer.toHexString(i & 0xff); ! return ("00".substring(0, 2 - val.length()) + val).toUpperCase(); } + + /** Returns true if the char is alphanumeric. */ public static char readableChar(int i) { if ((i < 0x20) || (i > 0x7f)) *************** *** 177,180 **** --- 193,198 ---- return (char) i; } + + /** Prints a vector to the quake console. */ public static void printv(String in, float arr[]) { for (int n = 0; n < arr.length; n++) { *************** *** 182,186 **** --- 200,207 ---- } } + static final byte nullfiller[] = new byte[8192]; + + /** Like in libc. */ public static void fwriteString(String s, int len, RandomAccessFile f) throws IOException { if (s == null) *************** *** 188,198 **** int diff = len - s.length(); if (diff > 0) { ! f.write(s.getBytes()); f.write(nullfiller, 0, diff); } else ! f.write(s.getBytes(), 0, len); } public static RandomAccessFile fopen(String name, String mode) { try { --- 209,221 ---- int diff = len - s.length(); if (diff > 0) { ! f.write(stringToBytes(s)); f.write(nullfiller, 0, diff); } else ! f.write(stringToBytes(s), 0, len); } + + /** Like in libc */ public static RandomAccessFile fopen(String name, String mode) { try { *************** *** 204,207 **** --- 227,232 ---- } } + + /** Like in libc */ public static void fclose(RandomAccessFile f) { try { *************** *** 211,214 **** --- 236,241 ---- } } + + /** Like in libc */ public static String freadString(RandomAccessFile f, int len) { byte buffer[] = new byte[len]; *************** *** 217,220 **** --- 244,249 ---- return Lib.CtoJava(buffer); } + + /** Returns the right part of the string from the last occruence of c. */ public static String rightFrom(String in, char c) { int pos = in.lastIndexOf(c); *************** *** 225,228 **** --- 254,259 ---- return ""; } + + /** Returns the left part of the string from the last occruence of c. */ public static String leftFrom(String in, char c) { int pos = in.lastIndexOf(c); *************** *** 234,237 **** --- 265,269 ---- } + /** Renames a file. */ public static int rename(String oldn, String newn) { try { *************** *** 245,248 **** --- 277,282 ---- } } + + /** Converts an int to 4 bytes java representation. */ public static byte[] getIntBytes(int c) { byte b[] = new byte[4]; *************** *** 253,259 **** --- 287,297 ---- return b; } + + /** Converts an 4 bytes java int representation to an int. */ public static int getInt(byte b[]) { return (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | ((b[3] & 0xff) << 24); } + + /** Duplicates a float array. */ public static float[] clone(float in[]) { float out[] = new float[in.length]; *************** *** 264,268 **** --- 302,335 ---- return out; } + + /** + * convert a java string to byte[] with 8bit latin 1 + * + * avoid String.getBytes() because it is using system specific character encoding. + */ + public static byte[] stringToBytes(String value) { + try { + return value.getBytes("ISO-8859-1"); + } catch (UnsupportedEncodingException e) { + // can't happen: Latin 1 is a standard encoding + return null; + } + } + + /** + * convert a byte[] with 8bit latin 1 to java string + * + * avoid new String(bytes) because it is using system specific character encoding. + */ + public static String bytesToString(byte[] value) { + try { + return new String(value, "ISO-8859-1"); + } catch (UnsupportedEncodingException e) { + // can't happen: Latin 1 is a standard encoding + return null; + } + } + /** Helper method that savely handles the null termination of old C String data. */ public static String CtoJava(String old) { int index = old.indexOf('\0'); *************** *** 271,289 **** } public static String CtoJava(byte[] old) { return CtoJava(old, 0, old.length); } public static String CtoJava(byte[] old, int offset, int maxLenght) { if (old.length == 0 || old[0] == 0) return ""; int i; ! for (i = offset; old[i] != 0 && (i - offset) < maxLenght; i++); return new String(old, offset, i - offset); } ! /* ! * java.nio.* Buffer util functions ! */ public static final int SIZEOF_FLOAT = 4; --- 338,356 ---- } + /** Helper method that savely handles the null termination of old C String data. */ public static String CtoJava(byte[] old) { return CtoJava(old, 0, old.length); } + /** Helper method that savely handles the null termination of old C String data. */ public static String CtoJava(byte[] old, int offset, int maxLenght) { if (old.length == 0 || old[0] == 0) return ""; int i; ! for (i = offset; (i - offset) < maxLenght && old[i] != 0; i++); return new String(old, offset, i - offset); } ! /* java.nio.* Buffer util functions */ public static final int SIZEOF_FLOAT = 4; Index: QuakeFile.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/QuakeFile.java,v retrieving revision 1.4 retrieving revision 1.4.12.1 diff -C2 -d -r1.4 -r1.4.12.1 *** QuakeFile.java 22 Sep 2004 19:22:13 -0000 1.4 --- QuakeFile.java 25 Dec 2005 18:11:18 -0000 1.4.12.1 *************** *** 20,36 **** // 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; ! import jake2.game.gitem_t; import jake2.qcommon.Com; ! import java.io.FileNotFoundException; ! import java.io.IOException; ! import java.io.RandomAccessFile; /** --- 20,32 ---- // Created on 24.07.2004 by RST. + // $Id$ + package jake2.util; ! import jake2.game.*; import jake2.qcommon.Com; ! import java.io.*; /** *************** *** 161,165 **** return null; else ! return GameAI.itemlist[ndx]; } --- 157,161 ---- return null; else ! return GameItemList.itemlist[ndx]; } |