From 05e9dad90a93896d223ff0070911cd5f2ccf3c4c Mon Sep 17 00:00:00 2001 From: Holger Zickner Date: Wed, 12 Jan 2005 12:14:27 +0000 Subject: small performance improvements --- src/jake2/game/GameSpawn.java | 4 +- src/jake2/game/GameUtil.java | 4 +- src/jake2/game/Monster.java | 4 +- src/jake2/qcommon/Com.java | 87 ++++++++++++++------------ src/jake2/qcommon/PMove.java | 15 ++--- src/jake2/render/fastjogl/Light.java | 115 ++++++++++++++++++++--------------- 6 files changed, 123 insertions(+), 106 deletions(-) (limited to 'src/jake2') diff --git a/src/jake2/game/GameSpawn.java b/src/jake2/game/GameSpawn.java index 6fe9924..fb96d12 100644 --- a/src/jake2/game/GameSpawn.java +++ b/src/jake2/game/GameSpawn.java @@ -19,7 +19,7 @@ */ // Created on 18.11.2003 by RST. -// $Id: GameSpawn.java,v 1.9 2004-09-22 19:22:05 salomo Exp $ +// $Id: GameSpawn.java,v 1.10 2005-01-12 12:14:17 hzi Exp $ package jake2.game; import jake2.Defines; @@ -349,7 +349,7 @@ public class GameSpawn { float[] vec = { 0, 0, 0 }; if (key.equals("nextmap")) - Com.p("nextmap: " + value); + Com.Println("nextmap: " + value); if (!GameBase.st.set(key, value)) if (!ent.set(key, value)) GameBase.gi.dprintf("??? The key [" + key diff --git a/src/jake2/game/GameUtil.java b/src/jake2/game/GameUtil.java index 90c266c..8867a7e 100644 --- a/src/jake2/game/GameUtil.java +++ b/src/jake2/game/GameUtil.java @@ -19,7 +19,7 @@ */ // Created on 01.11.2003 by RST. -// $Id: GameUtil.java,v 1.7 2004-09-22 19:22:05 salomo Exp $ +// $Id: GameUtil.java,v 1.8 2005-01-12 12:14:17 hzi Exp $ package jake2.game; import jake2.Defines; @@ -828,7 +828,7 @@ public class GameUtil { if (it.pickup_name.equalsIgnoreCase(pickup_name)) return it; } - Com.p("Item not found:" + pickup_name); + Com.Println("Item not found:" + pickup_name); return null; } diff --git a/src/jake2/game/Monster.java b/src/jake2/game/Monster.java index 8ced270..f74612f 100644 --- a/src/jake2/game/Monster.java +++ b/src/jake2/game/Monster.java @@ -19,7 +19,7 @@ */ // Created on 17.12.2003 by RST. -// $Id: Monster.java,v 1.4 2004-09-22 19:22:06 salomo Exp $ +// $Id: Monster.java,v 1.5 2005-01-12 12:14:17 hzi Exp $ package jake2.game; import jake2.Defines; @@ -348,7 +348,7 @@ public class Monster { public static EntThinkAdapter monster_triggered_start = new EntThinkAdapter() { public boolean think(edict_t self) { if (self.index == 312) - Com.p("monster_triggered_start"); + Com.Printf("monster_triggered_start\n"); self.solid = Defines.SOLID_NOT; self.movetype = Defines.MOVETYPE_NONE; self.svflags |= Defines.SVF_NOCLIENT; diff --git a/src/jake2/qcommon/Com.java b/src/jake2/qcommon/Com.java index b7ae3b4..cc6907c 100644 --- a/src/jake2/qcommon/Com.java +++ b/src/jake2/qcommon/Com.java @@ -2,7 +2,7 @@ * Com.java * Copyright (C) 2003 * - * $Id: Com.java,v 1.6 2004-08-22 18:30:15 hzi Exp $ + * $Id: Com.java,v 1.7 2005-01-12 12:14:16 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -91,10 +91,12 @@ public final class Com if (in == null) { data= null; + length = 0; } else { data= in.toCharArray(); + length = data.length; } index= 0; } @@ -108,39 +110,50 @@ public final class Com { data= in; index= offset; + if (data != null) length = data.length; + else length = 0; } public char getchar() { - // faster than if - try - { - return data[index]; - } - catch (Exception e) - { - data= null; - // last char - return 0; - } + if (index < length) { + return data[index]; + } + return 0; +// // faster than if +// try +// { +// return data[index]; +// } +// catch (Exception e) +// { +// data= null; +// // last char +// return 0; +// } } public char nextchar() { // faster than if - try - { - index++; - return data[index]; - } - catch (Exception e) - { - data= null; - // avoid int wraps; - index--; - // last char - return 0; - } + index++; + if (index < length) { + return data[index]; + } + return 0; +// try +// { +// index++; +// return data[index]; +// } +// catch (Exception e) +// { +// data= null; +// // avoid int wraps; +// index--; +// // last char +// return 0; +// } } public char prevchar() { @@ -154,32 +167,33 @@ public final class Com public boolean isEof() { - return data == null; + return index >= length; } public int index; public char data[]; + private int length; public char skipwhites() { - char c; - while (((c= getchar()) <= ' ') && c != 0) + char c = 0; + while ( index < length && ((c= data[index]) <= ' ') && c != 0) index++; return c; } public char skipwhitestoeol() { - char c; - while (((c= getchar()) <= ' ') && c != '\n' && c != 0) + char c = 0; + while ( index < length &&((c= data[index]) <= ' ') && c != '\n' && c != 0) index++; return c; } public char skiptoeol() { - char c; - while ((c= getchar()) != '\n' && c != 0) + char c = 0; + while ( index < length &&(c= data[index]) != '\n' && c != 0) index++; return c; } @@ -407,14 +421,7 @@ public final class Com public static void Println(String fmt) { - Printf(fmt); - Printf("\n"); - } - - public static void p(String fmt) - { - Printf(fmt); - Printf("\n"); + Printf(fmt + "\n"); } public static String sprintf(String fmt, Vargs vargs) diff --git a/src/jake2/qcommon/PMove.java b/src/jake2/qcommon/PMove.java index f4e92c3..3a35523 100644 --- a/src/jake2/qcommon/PMove.java +++ b/src/jake2/qcommon/PMove.java @@ -19,14 +19,12 @@ */ // Created on 25.01.2004 by RST. -// $Id: PMove.java,v 1.5 2004-09-22 19:22:09 salomo Exp $ +// $Id: PMove.java,v 1.6 2005-01-12 12:14:16 hzi Exp $ package jake2.qcommon; -import jake2.*; -import jake2.client.*; +import jake2.Defines; +import jake2.Globals; import jake2.game.*; -import jake2.render.*; -import jake2.server.*; import jake2.util.Math3D; public class PMove { @@ -47,8 +45,6 @@ public class PMove { public csurface_t groundsurface; - public cplane_t groundplane = new cplane_t(); - public int groundcontents; public float[] previous_origin = { 0, 0, 0 }; @@ -618,7 +614,6 @@ public class PMove { } else { trace = PMove.pm.trace.trace(PMove.pml.origin, PMove.pm.mins, PMove.pm.maxs, point); - PMove.pml.groundplane = trace.plane; PMove.pml.groundsurface = trace.surface; PMove.pml.groundcontents = trace.contents; @@ -1069,8 +1064,8 @@ public class PMove { PMove.pm.watertype = 0; PMove.pm.waterlevel = 0; - // clear all pmove local vars - PMove.pml = new PMove.pml_t(); + PMove.pml.groundsurface = null; + PMove.pml.groundcontents = 0; // convert origin and velocity to float values PMove.pml.origin[0] = PMove.pm.s.origin[0] * 0.125f; diff --git a/src/jake2/render/fastjogl/Light.java b/src/jake2/render/fastjogl/Light.java index 97d0e18..208946b 100644 --- a/src/jake2/render/fastjogl/Light.java +++ b/src/jake2/render/fastjogl/Light.java @@ -2,7 +2,7 @@ * Light.java * Copyright (C) 2003 * - * $Id: Light.java,v 1.9 2004-09-22 19:22:11 salomo Exp $ + * $Id: Light.java,v 1.10 2005-01-12 12:14:27 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -208,7 +208,9 @@ public abstract class Light extends Warp { cplane_t lightplane; // used as shadow plane float[] lightspot = { 0, 0, 0 }; // vec3_t - + + float scalef = 1.0f/255; + int RecursiveLightPoint(mnode_t node, float[] start, float[] end) { if (node.contents != -1) return -1; // didn't hit anything @@ -219,7 +221,6 @@ public abstract class Light extends Warp { mtexinfo_t tex; ByteBuffer lightmap; int maps; - float[] mid = { 0, 0, 0 }; // calculate mid point @@ -234,6 +235,7 @@ public abstract class Light extends Warp { return RecursiveLightPoint(node.children[sideIndex], start, end); float frac = front / (front - back); + float[] mid = { 0, 0, 0 }; mid[0] = start[0] + (end[0] - start[0]) * frac; mid[1] = start[1] + (end[1] - start[1]) * frac; mid[2] = start[2] + (end[2] - start[2]) * frac; @@ -251,7 +253,9 @@ public abstract class Light extends Warp { lightplane = plane; int surfIndex = node.firstsurface; - float[] scale = { 0, 0, 0 }; + float scale0; + float scale1; + float scale2; for (i = 0; i < node.numsurfaces; i++, surfIndex++) { surf = r_worldmodel.surfaces[surfIndex]; @@ -283,23 +287,22 @@ public abstract class Light extends Warp { Math3D.VectorCopy(Globals.vec3_origin, pointcolor); if (lightmap != null) { - //float[] scale = {0, 0, 0}; float[] rgb; lightmapIndex += 3 * (dt * ((surf.extents[0] >> 4) + 1) + ds); for (maps = 0; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte) 255; maps++) { rgb = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb; - scale[0] = gl_modulate.value * rgb[0]; - scale[1] = gl_modulate.value * rgb[1]; - scale[2] = gl_modulate.value * rgb[2]; + scale0 = gl_modulate.value * rgb[0]; + scale1 = gl_modulate.value * rgb[1]; + scale2 = gl_modulate.value * rgb[2]; pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) - * scale[0] * (1.0f / 255); + * scale0 * scalef; pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) - * scale[1] * (1.0f / 255); + * scale1 * scalef; pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) - * scale[2] * (1.0f / 255); + * scale2 * scalef; lightmapIndex += 3 * ((surf.extents[0] >> 4) + 1) * ((surf.extents[1] >> 4) + 1); } @@ -318,15 +321,12 @@ public abstract class Light extends Warp { assert (p.length == 3) : "vec3_t bug"; assert (color.length == 3) : "rgb bug"; - float[] end = { 0, 0, 0 }; - dlight_t dl; - float add; - if (r_worldmodel.lightdata == null) { color[0] = color[1] = color[2] = 1.0f; return; } - + + float[] end = { 0, 0, 0 }; end[0] = p[0]; end[1] = p[1]; end[2] = p[2] - 2048; @@ -342,14 +342,16 @@ public abstract class Light extends Warp { // // add dynamic lights // + float add; + dlight_t dl; for (int lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) { dl = r_newrefdef.dlights[lnum]; Math3D.VectorSubtract(currententity.origin, dl.origin, end); - add = dl.intensity - Math3D.VectorLength(end); - add *= (1.0f / 256); + add = (dl.intensity - Math3D.VectorLength(end)); + if (add > 0) { - Math3D.VectorMA(color, add, dl.color, color); + Math3D.VectorMA(color, add * scalef, dl.color, color); } } @@ -368,7 +370,6 @@ public abstract class Light extends Warp { int sd, td; float fdist, frad, fminlight; float[] impact = { 0, 0, 0 }; - float[] local = { 0, 0, 0 }; int s, t; dlight_t dl; float[] pfBL; @@ -378,6 +379,8 @@ public abstract class Light extends Warp { int tmax = (surf.extents[1] >> 4) + 1; mtexinfo_t tex = surf.texinfo; + float local0; + float local1; for (int lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) { if ((surf.dlightbits & (1 << lnum)) == 0) continue; // not lit by this light @@ -398,20 +401,20 @@ public abstract class Light extends Warp { impact[i] = dl.origin[i] - surf.plane.normal[i] * fdist; } - local[0] = Math3D.DotProduct(impact, tex.vecs[0]) + tex.vecs[0][3] + local0 = Math3D.DotProduct(impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0]; - local[1] = Math3D.DotProduct(impact, tex.vecs[1]) + tex.vecs[1][3] + local1 = Math3D.DotProduct(impact, tex.vecs[1]) + tex.vecs[1][3] - surf.texturemins[1]; pfBL = s_blocklights; int pfBLindex = 0; for (t = 0, ftacc = 0; t < tmax; t++, ftacc += 16) { - td = (int) (local[1] - ftacc); + td = (int) (local1 - ftacc); if (td < 0) td = -td; for (s = 0, fsacc = 0; s < smax; s++, fsacc += 16, pfBLindex += 3) { - sd = (int) (local[0] - fsacc); + sd = (int) (local0 - fsacc); if (sd < 0) sd = -sd; @@ -451,8 +454,6 @@ public abstract class Light extends Warp { void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride) { int r, g, b, a, max; int i, j; - ByteBuffer lightmap; - float[] scale = { 0, 0, 0 }; int nummaps; float[] bl; //lightstyle_t style; @@ -492,10 +493,13 @@ public abstract class Light extends Warp { && surf.styles[nummaps] != (byte) 255; nummaps++) ; - lightmap = surf.samples; + ByteBuffer lightmap = surf.samples; int lightmapIndex = 0; // add all the lightmaps + float scale0; + float scale1; + float scale2; if (nummaps == 1) { int maps; @@ -504,12 +508,15 @@ public abstract class Light extends Warp { bl = s_blocklights; int blp = 0; - for (i = 0; i < 3; i++) - scale[i] = gl_modulate.value - * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; +// for (i = 0; i < 3; i++) +// scale[i] = gl_modulate.value +// * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; + scale0 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0]; + scale1 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1]; + scale2 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2]; - if (scale[0] == 1.0F && scale[1] == 1.0F - && scale[2] == 1.0F) { + if (scale0 == 1.0F && scale1 == 1.0F + && scale2 == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; @@ -518,11 +525,11 @@ public abstract class Light extends Warp { } else { for (i = 0; i < size; i++) { bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) - * scale[0]; + * scale0; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) - * scale[1]; + * scale1; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) - * scale[2]; + * scale2; } } //lightmap += size*3; // skip to next lightmap @@ -540,12 +547,21 @@ public abstract class Light extends Warp { bl = s_blocklights; int blp = 0; - for (i = 0; i < 3; i++) - scale[i] = gl_modulate.value - * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; +// for (i = 0; i < 3; i++) +// scale[i] = gl_modulate.value +// * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; + scale0 = gl_modulate.value + * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0]; + scale1 = gl_modulate.value + * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1]; + scale2 = gl_modulate.value + * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2]; + + + - if (scale[0] == 1.0F && scale[1] == 1.0F - && scale[2] == 1.0F) { + if (scale0 == 1.0F && scale1 == 1.0F + && scale2 == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; @@ -554,11 +570,11 @@ public abstract class Light extends Warp { } else { for (i = 0; i < size; i++) { bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) - * scale[0]; + * scale0; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) - * scale[1]; + * scale1; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) - * scale[2]; + * scale2; } } //lightmap += size*3; // skip to next lightmap @@ -630,8 +646,7 @@ public abstract class Light extends Warp { a = (int) (a * t); } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; - dest.put(destp++, (a << 24) | (b << 16) | (g << 8) - | (r << 0)); + dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r); } } } else { @@ -696,9 +711,10 @@ public abstract class Light extends Warp { case 'C': // try faking colored lighting a = 255 - ((r + g + b) / 3); - r *= a / 255.0f; - g *= a / 255.0f; - b *= a / 255.0f; + float af = a / 255.0f; + r *= af; + g *= af; + b *= af; break; case 'A': default: @@ -707,8 +723,7 @@ public abstract class Light extends Warp { break; } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; - dest.put(destp++, (a << 24) | (b << 16) | (g << 8) - | (r << 0)); + dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r); } } } -- cgit v1.2.3