summaryrefslogtreecommitdiffstats
path: root/src/jake2/util/Lib.java
diff options
context:
space:
mode:
authorRene Stoeckel <[email protected]>2004-09-22 19:22:16 +0000
committerRene Stoeckel <[email protected]>2004-09-22 19:22:16 +0000
commitc4fcffe436fbfb5b0f3b7be2e5ee103ec74932f7 (patch)
tree7c9439ab1d9f5a4fd61bd57c755069007b23e0b6 /src/jake2/util/Lib.java
parentbcb4ac6eefb425d5b0a90009da506361d5739e75 (diff)
major refactoring in game, server and client package
Diffstat (limited to 'src/jake2/util/Lib.java')
-rw-r--r--src/jake2/util/Lib.java83
1 files changed, 24 insertions, 59 deletions
diff --git a/src/jake2/util/Lib.java b/src/jake2/util/Lib.java
index e0d1791..ab3a40e 100644
--- a/src/jake2/util/Lib.java
+++ b/src/jake2/util/Lib.java
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 09.12.2003 by RST.
-// $Id: Lib.java,v 1.5 2004-07-23 10:09:55 hzi Exp $
+// $Id: Lib.java,v 1.6 2004-09-22 19:22:13 salomo Exp $
package jake2.util;
@@ -48,11 +48,9 @@ public class Lib {
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]));
}
@@ -70,33 +68,28 @@ public class Lib {
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 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);
}
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 {
return Integer.parseInt(in);
@@ -105,51 +98,45 @@ public class Lib {
return 0;
}
}
-
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++)
if (in[i] == 0)
return i;
return in.length;
}
-
public static int strlen(byte in[]) {
for (int i = 0; i < in.length; i++)
if (in[i] == 0)
return i;
return in.length;
}
-
static byte[] buffer = new byte[Defines.MAX_INFO_STRING];
public static String readString(ByteBuffer bb, int len) {
bb.get(buffer, 0, len);
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) {
StringBuffer result = new StringBuffer();
@@ -164,13 +151,13 @@ public class Lib {
}
}
int v = data1[i];
-
+
result.append(hex2(v));
result.append(" ");
-
+
charfield.append(readableChar(v));
i++;
-
+
// nach dem letzten, newline einfuegen
if ((i & 0xf) == 0) {
result.append(charfield);
@@ -184,41 +171,35 @@ public class Lib {
}
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))
return '.';
else
return (char) i;
}
-
public static void printv(String in, float arr[]) {
for (int n = 0; n < arr.length; n++) {
Com.Println(in + "[" + n + "]: " + arr[n]);
}
}
-
static final byte nullfiller[] = new byte[8192];
-
public static void fwriteString(String s, int len, RandomAccessFile f) throws IOException {
if (s == null)
return;
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 {
return new RandomAccessFile(name, mode);
@@ -228,7 +209,6 @@ public class Lib {
return null;
}
}
-
public static void fclose(RandomAccessFile f) {
try {
f.close();
@@ -236,14 +216,12 @@ public class Lib {
catch (Exception e) {
}
}
-
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);
if (pos == -1)
@@ -252,7 +230,6 @@ public class Lib {
return in.substring(pos + 1, in.length());
return "";
}
-
public static String leftFrom(String in, char c) {
int pos = in.lastIndexOf(c);
if (pos == -1)
@@ -261,25 +238,23 @@ public class Lib {
return in.substring(0, pos);
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 {
File f1 = new File(oldn);
@@ -291,7 +266,6 @@ public class Lib {
return 1;
}
}
-
public static byte[] getIntBytes(int c) {
byte b[] = new byte[4];
b[0] = (byte) ((c & 0xff));
@@ -300,57 +274,48 @@ public class Lib {
b[3] = (byte) ((c >>> 24) & 0xff);
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
*/
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);
bb.order(ByteOrder.nativeOrder());
return bb;
}
-
public static ByteBuffer newByteBuffer(int numElements, ByteOrder order) {
ByteBuffer bb = ByteBuffer.allocateDirect(numElements);
bb.order(order);
return bb;
}
-
}