From: Carsten W. <ca...@us...> - 2005-01-17 15:42:39
|
Update of /cvsroot/jake2/jake2/src/jake2/render/lwjgl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12727/src/jake2/render/lwjgl Modified Files: Warp.java Log Message: local float[] optimize; code clean up Index: Warp.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/lwjgl/Warp.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Warp.java 10 Jan 2005 00:05:22 -0000 1.4 --- Warp.java 17 Jan 2005 15:42:29 -0000 1.5 *************** *** 31,34 **** --- 31,35 ---- import jake2.render.*; import jake2.util.Math3D; + import jake2.util.Vec3Cache; import org.lwjgl.opengl.GL11; *************** *** 40,45 **** */ public abstract class Warp extends Model { - - // warpsin.h public static final float[] SIN = { --- 41,44 ---- *************** *** 78,84 **** }; - // gl_warp.c -- sky and water polygons - //extern model_t *loadmodel; // Model.java - String skyname; float skyrotate; --- 77,80 ---- *************** *** 90,105 **** static final int SUBDIVIDE_SIZE = 64; ! void BoundPoly(int numverts, float[][] verts, float[] mins, float[] maxs) ! { ! int i, j; ! float[] v; ! mins[0] = mins[1] = mins[2] = 9999; maxs[0] = maxs[1] = maxs[2] = -9999; ! for (i=0 ; i<numverts ; i++) ! { v = verts[i]; ! for (j=0 ; j<3 ; j++) ! { if (v[j] < mins[j]) mins[j] = v[j]; --- 86,105 ---- static final int SUBDIVIDE_SIZE = 64; ! /** ! * BoundPoly ! * @param numverts ! * @param verts ! * @param mins ! * @param maxs ! */ ! void BoundPoly(int numverts, float[][] verts, float[] mins, float[] maxs) { mins[0] = mins[1] = mins[2] = 9999; maxs[0] = maxs[1] = maxs[2] = -9999; ! ! int j; ! float[] v; ! for (int i=0 ; i<numverts ; i++) { v = verts[i]; ! for (j=0 ; j<3 ; j++) { if (v[j] < mins[j]) mins[j] = v[j]; *************** *** 110,120 **** } void SubdividePolygon(int numverts, float[][] verts) { int i, j, k; - float[] mins = {0, 0, 0}; - float[] maxs = {0, 0, 0}; float m; - float[] v = {0, 0, 0}; float[][] front = new float[64][3]; float[][] back = new float[64][3]; --- 110,122 ---- } + /** + * SubdividePolygon + * @param numverts + * @param verts + */ void SubdividePolygon(int numverts, float[][] verts) { int i, j, k; float m; float[][] front = new float[64][3]; float[][] back = new float[64][3]; *************** *** 123,135 **** float[] dist = new float[64]; float frac; - float s, t; - float[] total = {0, 0, 0}; - float total_s, total_t; if (numverts > 60) Com.Error(Defines.ERR_DROP, "numverts = " + numverts); ! BoundPoly(numverts, verts, mins, maxs); // x,y und z for (i=0 ; i<3 ; i++) --- 125,137 ---- float[] dist = new float[64]; float frac; if (numverts > 60) Com.Error(Defines.ERR_DROP, "numverts = " + numverts); ! float[] mins = Vec3Cache.get(); ! float[] maxs = Vec3Cache.get(); + BoundPoly(numverts, verts, mins, maxs); + float[] v; // x,y und z for (i=0 ; i<3 ; i++) *************** *** 151,155 **** Math3D.VectorCopy(verts[0], verts[numverts]); ! f = b = 0; for (j=0 ; j<numverts ; j++) --- 153,157 ---- Math3D.VectorCopy(verts[0], verts[numverts]); ! f = b = 0; for (j=0 ; j<numverts ; j++) *************** *** 182,188 **** SubdividePolygon(f, front); SubdividePolygon(b, back); return; } ! // add a point in the center to help keep warp valid --- 184,194 ---- SubdividePolygon(f, front); SubdividePolygon(b, back); + + Vec3Cache.release(2); // mins, maxs return; } ! ! Vec3Cache.release(2); // mins, maxs ! // add a point in the center to help keep warp valid *************** *** 195,202 **** poly.next = warpface.polys; warpface.polys = poly; Math3D.VectorClear(total); ! total_s = 0; ! total_t = 0; ! for (i = 0; i < numverts; i++) { poly.x(i + 1, verts[i][0]); poly.y(i + 1, verts[i][1]); --- 201,211 ---- poly.next = warpface.polys; warpface.polys = poly; + + float[] total = Vec3Cache.get(); Math3D.VectorClear(total); ! float total_s = 0; ! float total_t = 0; ! float s, t; ! for (i = 0; i < numverts; i++) { poly.x(i + 1, verts[i][0]); poly.y(i + 1, verts[i][1]); *************** *** 227,243 **** poly.s2(i + 1, poly.s2(1)); poly.t2(i + 1, poly.t2(1)); } ! /* ! ================ ! GL_SubdivideSurface ! ! Breaks a polygon up along axial 64 unit ! boundaries so that turbulent and sky warps ! can be done reasonably. ! ================ ! */ ! float[][] tmpVerts = new float[64][3]; ! void GL_SubdivideSurface(msurface_t fa) { float[][] verts = tmpVerts; --- 236,250 ---- poly.s2(i + 1, poly.s2(1)); poly.t2(i + 1, poly.t2(1)); + + Vec3Cache.release(); // total } ! private final float[][] tmpVerts = new float[64][3]; ! /** ! * GL_SubdivideSurface ! * Breaks a polygon up along axial 64 unit ! * boundaries so that turbulent and sky warps ! * can be done reasonably. ! */ void GL_SubdivideSurface(msurface_t fa) { float[][] verts = tmpVerts; *************** *** 261,293 **** } ! // ========================================================= ! ! ! ! //// speed up sin calculations - Ed ! // float r_turbsin[] = ! // { ! // #include "warpsin.h" ! // }; static final float TURBSCALE = (float)(256.0f / (2 * Math.PI)); ! /* ! ============= ! EmitWaterPolys ! ! Does a water warp on the pre-fragmented glpoly_t chain ! ============= ! */ void EmitWaterPolys(msurface_t fa) { - glpoly_t p, bp; - float[] v; - int i; - float s = 0; - float t = 0; - float os, ot; - float scroll; float rdt = r_newrefdef.time; if ((fa.texinfo.flags & Defines.SURF_FLOWING) != 0) scroll = -64 * ( (r_newrefdef.time*0.5f) - (int)(r_newrefdef.time*0.5f) ); --- 268,283 ---- } ! // ========================================================= static final float TURBSCALE = (float)(256.0f / (2 * Math.PI)); ! /** ! * EmitWaterPolys ! * Does a water warp on the pre-fragmented glpoly_t chain ! */ void EmitWaterPolys(msurface_t fa) { float rdt = r_newrefdef.time; + float scroll; if ((fa.texinfo.flags & Defines.SURF_FLOWING) != 0) scroll = -64 * ( (r_newrefdef.time*0.5f) - (int)(r_newrefdef.time*0.5f) ); *************** *** 295,298 **** --- 285,291 ---- scroll = 0; + int i; + float s, t, os, ot; + glpoly_t p, bp; for (bp = fa.polys; bp != null; bp = bp.next) { p = bp; *************** *** 321,325 **** // =================================================================== - float[][] skyclip = { { 1, 1, 0}, --- 314,317 ---- *************** *** 364,379 **** float sky_min, sky_max; ! void DrawSkyPolygon (int nump, float[][] vecs) { - int i,j; - float[] v = {0, 0, 0}; - float[] av = {0, 0, 0}; - float s, t, dv; - int axis; - float[] vp; - c_sky++; // decide which face it maps to Math3D.VectorCopy(Globals.vec3_origin, v); for (i=0; i<nump ; i++) { --- 356,373 ---- float sky_min, sky_max; ! // stack variable ! private final float[] v = {0, 0, 0}; ! private final float[] av = {0, 0, 0}; ! /** ! * DrawSkyPolygon ! * @param nump ! * @param vecs ! */ ! void DrawSkyPolygon(int nump, float[][] vecs) { c_sky++; // decide which face it maps to Math3D.VectorCopy(Globals.vec3_origin, v); + int i, axis; for (i=0; i<nump ; i++) { *************** *** 406,409 **** --- 400,405 ---- // project new texture coords + float s, t, dv; + int j; for (i=0 ; i<nump ; i++) { *************** *** 448,460 **** float[][][][] newv = new float[6][2][MAX_CLIP_VERTS][3]; void ClipSkyPolygon(int nump, float[][] vecs, int stage) { - float[] norm; - float[] v; - boolean front, back; - float d, e; - int[] newc = { 0, 0 }; - int i, j; - if (nump > MAX_CLIP_VERTS-2) Com.Error(Defines.ERR_DROP, "ClipSkyPolygon: MAX_CLIP_VERTS"); --- 444,455 ---- float[][][][] newv = new float[6][2][MAX_CLIP_VERTS][3]; + /** + * ClipSkyPolygon + * @param nump + * @param vecs + * @param stage + */ void ClipSkyPolygon(int nump, float[][] vecs, int stage) { if (nump > MAX_CLIP_VERTS-2) Com.Error(Defines.ERR_DROP, "ClipSkyPolygon: MAX_CLIP_VERTS"); *************** *** 465,470 **** } ! front = back = false; ! norm = skyclip[stage]; for (i=0 ; i<nump ; i++) { --- 460,469 ---- } ! boolean front = false; ! boolean back = false; ! float[] norm = skyclip[stage]; ! ! int i; ! float d; for (i=0 ; i<nump ; i++) { *************** *** 495,500 **** dists[i] = dists[0]; Math3D.VectorCopy(vecs[0], vecs[i]); - newc[0] = newc[1] = 0; for (i=0; i<nump ; i++) { --- 494,502 ---- dists[i] = dists[0]; Math3D.VectorCopy(vecs[0], vecs[i]); + int newc0 = 0; int newc1 = 0; + float[] v; + float e; + int j; for (i=0; i<nump ; i++) { *************** *** 503,518 **** { case SIDE_FRONT: ! Math3D.VectorCopy(v, newv[stage][0][newc[0]]); ! newc[0]++; break; case SIDE_BACK: ! Math3D.VectorCopy(v, newv[stage][1][newc[1]]); ! newc[1]++; break; case SIDE_ON: ! Math3D.VectorCopy(v, newv[stage][0][newc[0]]); ! newc[0]++; ! Math3D.VectorCopy (v, newv[stage][1][newc[1]]); ! newc[1]++; break; } --- 505,520 ---- { case SIDE_FRONT: ! Math3D.VectorCopy(v, newv[stage][0][newc0]); ! newc0++; break; case SIDE_BACK: ! Math3D.VectorCopy(v, newv[stage][1][newc1]); ! newc1++; break; case SIDE_ON: ! Math3D.VectorCopy(v, newv[stage][0][newc0]); ! newc0++; ! Math3D.VectorCopy (v, newv[stage][1][newc1]); ! newc1++; break; } *************** *** 525,547 **** { e = v[j] + d * (vecs[i + 1][j] - v[j]); ! newv[stage][0][newc[0]][j] = e; ! newv[stage][1][newc[1]][j] = e; } ! newc[0]++; ! newc[1]++; } // continue ! ClipSkyPolygon(newc[0], newv[stage][0], stage+1); ! ClipSkyPolygon(newc[1], newv[stage][1], stage+1); } float[][] verts = new float[MAX_CLIP_VERTS][3]; ! /* ! ================= ! R_AddSkySurface ! ================= ! */ void R_AddSkySurface(msurface_t fa) { --- 527,547 ---- { e = v[j] + d * (vecs[i + 1][j] - v[j]); ! newv[stage][0][newc0][j] = e; ! newv[stage][1][newc1][j] = e; } ! newc0++; ! newc1++; } // continue ! ClipSkyPolygon(newc0, newv[stage][0], stage+1); ! ClipSkyPolygon(newc1, newv[stage][1], stage+1); } float[][] verts = new float[MAX_CLIP_VERTS][3]; ! /** ! * R_AddSkySurface ! */ void R_AddSkySurface(msurface_t fa) { *************** *** 557,593 **** } ! ! /* ! ============== ! R_ClearSkyBox ! ============== ! */ void R_ClearSkyBox() { for (int i=0 ; i<6 ; i++) { ! skymins[0][i] = skymins[1][i] = 9999; ! skymaxs[0][i] = skymaxs[1][i] = -9999; } } ! ! ! void MakeSkyVec (float s, float t, int axis) { - float[] v = {0, 0, 0}; - float[] b = {0, 0, 0}; - int j, k; - b[0] = s*2300; b[1] = t*2300; b[2] = 2300; for (j=0 ; j<3 ; j++) { k = st_to_vec[axis][j]; if (k < 0) ! v[j] = -b[-k - 1]; else ! v[j] = b[k - 1]; } --- 557,600 ---- } ! /** ! * R_ClearSkyBox ! */ void R_ClearSkyBox() { + float[] skymins0 = skymins[0]; + float[] skymins1 = skymins[1]; + float[] skymaxs0 = skymaxs[0]; + float[] skymaxs1 = skymaxs[1]; + for (int i=0 ; i<6 ; i++) { ! skymins0[i] = skymins1[i] = 9999; ! skymaxs0[i] = skymaxs1[i] = -9999; } } ! ! // stack variable ! private final float[] v1 = {0, 0, 0}; ! private final float[] b = {0, 0, 0}; ! /** ! * MakeSkyVec ! * @param s ! * @param t ! * @param axis ! */ ! void MakeSkyVec(float s, float t, int axis) { b[0] = s*2300; b[1] = t*2300; b[2] = 2300; + int j, k; for (j=0 ; j<3 ; j++) { k = st_to_vec[axis][j]; if (k < 0) ! v1[j] = -b[-k - 1]; else ! v1[j] = b[k - 1]; } *************** *** 607,620 **** t = 1.0f - t; gl.glTexCoord2f (s, t); ! gl.glVertex3f(v[0], v[1], v[2]); } - /* - ============== - R_DrawSkyBox - ============== - */ int[] skytexorder = {0,2,1,3,4,5}; void R_DrawSkyBox() { --- 614,625 ---- t = 1.0f - t; gl.glTexCoord2f (s, t); ! gl.glVertex3f(v1[0], v1[1], v1[2]); } int[] skytexorder = {0,2,1,3,4,5}; + /** + * R_DrawSkyBox + */ void R_DrawSkyBox() { *************** *** 661,680 **** } - - /* - ============ - R_SetSky - ============ - */ // 3dstudio environment map names String[] suf = {"rt", "bk", "lf", "ft", "up", "dn"}; protected void R_SetSky(String name, float rotate, float[] axis) { assert (axis.length == 3) : "vec3_t bug"; - int i; String pathname; - - // strncpy (skyname, name, sizeof(skyname)-1); skyname = name; --- 666,682 ---- } // 3dstudio environment map names String[] suf = {"rt", "bk", "lf", "ft", "up", "dn"}; + /** + * R_SetSky + * @param name + * @param rotate + * @param axis + */ protected void R_SetSky(String name, float rotate, float[] axis) { assert (axis.length == 3) : "vec3_t bug"; String pathname; skyname = name; *************** *** 682,686 **** Math3D.VectorCopy(axis, skyaxis); ! for (i=0 ; i<6 ; i++) { // chop down rotating skies for less memory --- 684,688 ---- Math3D.VectorCopy(axis, skyaxis); ! for (int i=0 ; i<6 ; i++) { // chop down rotating skies for less memory *************** *** 714,716 **** } } ! } --- 716,718 ---- } } ! } \ No newline at end of file |