From: Holger Z. <hz...@us...> - 2004-09-06 19:39:32
|
Update of /cvsroot/jake2/jake2/src/jake2/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2637/src/jake2/util Modified Files: Tag: r_0_9 Lib.java Math3D.java Added Files: Tag: r_0_9 QuakeFile.java Log Message: merge changes for 0.9.3 Index: Lib.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/Lib.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -C2 -d -r1.2.2.1 -r1.2.2.2 *** Lib.java 9 Jul 2004 08:38:23 -0000 1.2.2.1 --- Lib.java 6 Sep 2004 19:39:20 -0000 1.2.2.2 *************** *** 24,27 **** --- 24,28 ---- package jake2.util; + import jake2.Defines; import jake2.Globals; import jake2.qcommon.Com; *************** *** 30,36 **** import java.io.*; import java.nio.*; - import java.nio.ByteBuffer; - import java.nio.FloatBuffer; - import java.util.Arrays; import java.util.StringTokenizer; --- 31,34 ---- *************** *** 78,85 **** } - public static int stricmp(String in1, String in2) { - return in1.compareToIgnoreCase(in2); - } - public static boolean strstr(String i1, String i2) { return (i1.indexOf(i2) != -1); --- 76,79 ---- *************** *** 126,133 **** } - // public static int strlen(String in) { - // return in.length(); - // } - public static int strlen(char in[]) { for (int i = 0; i < in.length; i++) --- 120,123 ---- *************** *** 144,173 **** } ! public static void strcat(String in, String i) { ! in += i; ! } ! ! public static void strcpy(byte dest[], byte src[]) { ! for (int i = 0; i < dest.length && i < src.length; i++) ! if (src[i] == 0) { ! dest[i] = 0; ! return; ! } ! else ! dest[i] = src[i]; ! ! } ! ! public static String readString(RandomAccessFile file, int len) throws IOException { ! byte buf[] = new byte[len]; ! ! file.read(buf, 0, len); ! return new String(buf, 0, strlen(buf)); ! } ! ! public static String readString(ByteBuffer bb, int len) throws IOException { ! byte buf[] = new byte[len]; ! bb.get(buf); ! return new String(buf, 0, strlen(buf)); } --- 134,141 ---- } ! 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); } *************** *** 237,253 **** } ! public static void memset(byte[] dest, byte c, int len) { ! Arrays.fill(dest, 0, len, c); ! } ! ! public static void memset(byte[] dest, int c, int len) { ! Arrays.fill(dest, 0, len, (byte) c); ! } ! ! public static void memcpy(byte[] bs, byte[] bs2, int i) { ! System.arraycopy(bs2, 0, bs, 0, i); ! } ! ! static byte nullfiller[] = new byte[8192]; public static void fwriteString(String s, int len, RandomAccessFile f) throws IOException { --- 205,209 ---- } ! static final byte nullfiller[] = new byte[8192]; public static void fwriteString(String s, int len, RandomAccessFile f) throws IOException { *************** *** 264,275 **** } - public static String cut(String in, char c) { - int pos = in.indexOf(c); - - if (pos != -1) - return in.substring(0, pos); - return in; - } - public static RandomAccessFile fopen(String name, String mode) { try { --- 220,223 ---- *************** *** 367,415 **** } - public static long[] clone(long in[]) { - long out[] = new long[in.length]; - - if (in.length != 0) - System.arraycopy(in, 0, out, 0, in.length); - - return out; - } - - public static boolean[] clone(boolean in[]) { - boolean out[] = new boolean[in.length]; - - if (in.length != 0) - System.arraycopy(in, 0, out, 0, in.length); - - return out; - } - - public static int[] clone(int in[]) { - int out[] = new int[in.length]; - - if (in.length != 0) - System.arraycopy(in, 0, out, 0, in.length); - - return out; - } - - public static double[] clone(double in[]) { - double out[] = new double[in.length]; - - if (in.length != 0) - System.arraycopy(in, 0, out, 0, in.length); - - return out; - } - - // this works with Strings also. - public static String[] clone(String in[]) { - String out[] = new String[in.length]; - if (in.length != 0) - System.arraycopy(in, 0, out, 0, in.length); - - return out; - } - /* * java.nio.* Buffer util functions --- 315,318 ---- Index: Math3D.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/util/Math3D.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** Math3D.java 8 Jul 2004 20:56:54 -0000 1.4 --- Math3D.java 6 Sep 2004 19:39:20 -0000 1.4.2.1 *************** *** 316,334 **** public static void ProjectPointOnPlane(float[] dst, float[] p, float[] normal) { - float d; - float[] n = { 0.0f, 0.0f, 0.0f }; - float inv_denom; ! inv_denom = 1.0F / Math3D.DotProduct(normal, normal); ! d = Math3D.DotProduct(normal, p) * inv_denom; ! n[0] = normal[0] * inv_denom; ! n[1] = normal[1] * inv_denom; ! n[2] = normal[2] * inv_denom; ! dst[0] = p[0] - d * n[0]; ! dst[1] = p[1] - d * n[1]; ! dst[2] = p[2] - d * n[2]; } --- 316,331 ---- 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; ! dst[1] = normal[1] * inv_denom; ! dst[2] = normal[2] * inv_denom; ! dst[0] = p[0] - d * dst[0]; ! dst[1] = p[1] - d * dst[1]; ! dst[2] = p[2] - d * dst[2]; } *************** *** 362,366 **** durch Entfernung und Senkrechten-Normale gegeben ist. erste Version mit vec3_t... */ - public static final int BoxOnPlaneSide(float emins[], float emaxs[], cplane_t p) { --- 359,362 ---- *************** *** 428,432 **** return sides; ! } // this is the slow, general version --- 424,428 ---- return sides; ! } // this is the slow, general version *************** *** 457,473 **** public static void AngleVectors(float[] angles, float[] forward, float[] right, float[] up) { - float angle; - float sr, sp, sy, cr, cp, cy; ! cr = 2.0f * piratio; ! angle = (float) (angles[Defines.YAW] * (cr)); ! sy = (float) Math.sin(angle); ! cy = (float) Math.cos(angle); angle = (float) (angles[Defines.PITCH] * (cr)); ! sp = (float) Math.sin(angle); ! cp = (float) Math.cos(angle); ! angle = (float) (angles[Defines.ROLL] * (cr)); ! sr = (float) Math.sin(angle); ! cr = (float) Math.cos(angle); if (forward != null) { --- 453,464 ---- public static void AngleVectors(float[] angles, float[] forward, float[] right, float[] up) { ! float cr = 2.0f * piratio; ! float angle = (float) (angles[Defines.YAW] * (cr)); ! float sy = (float) Math.sin(angle); ! float cy = (float) Math.cos(angle); angle = (float) (angles[Defines.PITCH] * (cr)); ! float sp = (float) Math.sin(angle); ! float cp = (float) Math.cos(angle); if (forward != null) { *************** *** 476,488 **** forward[2] = -sp; } ! if (right != null) { ! right[0] = (-sr * sp * cy + cr * sy); ! right[1] = (-sr * sp * sy + -cr * cy); ! right[2] = -sr * cp; ! } ! if (up != null) { ! up[0] = (cr * sp * cy + -sr * -sy); ! up[1] = (cr * sp * sy + -sr * cy); ! up[2] = cr * cp; } } --- 467,486 ---- forward[2] = -sp; } ! ! if (right != null || up != null) { ! angle = (float) (angles[Defines.ROLL] * (cr)); ! float sr = (float) Math.sin(angle); ! cr = (float) Math.cos(angle); ! ! if (right != null) { ! right[0] = (-sr * sp * cy + cr * sy); ! right[1] = (-sr * sp * sy + -cr * cy); ! right[2] = -sr * cp; ! } ! if (up != null) { ! up[0] = (cr * sp * cy + sr * sy); ! up[1] = (cr * sp * sy + -sr * cy); ! up[2] = cr * cp; ! } } } --- NEW FILE: QuakeFile.java --- /* 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: QuakeFile.java,v 1.2.2.1 2004/09/06 19:39:20 hzi Exp $ package jake2.util; import jake2.game.Game; import jake2.game.SuperAdapter; import jake2.game.edict_t; import jake2.game.gitem_t; import jake2.qcommon.Com; import java.io.*; /** RandomAccessFile, bur 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]; } } |