From: Carsten W. <ca...@us...> - 2005-01-17 16:50:43
|
Update of /cvsroot/jake2/jake2/src/jake2/render/lwjgl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26541/src/jake2/render/lwjgl Modified Files: Surf.java Log Message: local float[] optimize; code clean up Index: Surf.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/lwjgl/Surf.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Surf.java 10 Jan 2005 00:12:00 -0000 1.6 --- Surf.java 17 Jan 2005 16:50:24 -0000 1.7 *************** *** 115,133 **** */ ! /* ! =============== ! R_TextureAnimation ! ! Returns the proper texture for a given time and base texture ! =============== ! */ image_t R_TextureAnimation(mtexinfo_t tex) { - int c; - if (tex.next == null) return tex.image; ! c = currententity.frame % tex.numframes; while (c != 0) { --- 115,128 ---- */ ! /** ! * R_TextureAnimation ! * Returns the proper texture for a given time and base texture ! */ image_t R_TextureAnimation(mtexinfo_t tex) { if (tex.next == null) return tex.image; ! int c = currententity.frame % tex.numframes; while (c != 0) { *************** *** 139,147 **** } ! /* ! ================ ! DrawGLPoly ! ================ ! */ void DrawGLPoly(glpoly_t p) { --- 134,140 ---- } ! /** ! * DrawGLPoly ! */ void DrawGLPoly(glpoly_t p) { *************** *** 149,165 **** } ! // ============ ! // PGM ! /* ! ================ ! DrawGLFlowingPoly -- version of DrawGLPoly that handles scrolling texture ! ================ ! */ void DrawGLFlowingPoly(glpoly_t p) { ! int i; ! float scroll; ! ! scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) ); if(scroll == 0.0f) scroll = -64.0f; --- 142,152 ---- } ! /** ! * DrawGLFlowingPoly ! * version that handles scrolling texture ! */ void DrawGLFlowingPoly(glpoly_t p) { ! float scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) ); if(scroll == 0.0f) scroll = -64.0f; *************** *** 168,176 **** p.endScrolling(); } - // PGM - // ============ ! /* ! ** R_DrawTriangleOutlines */ void R_DrawTriangleOutlines() --- 155,161 ---- p.endScrolling(); } ! /** ! * R_DrawTriangleOutlines */ void R_DrawTriangleOutlines() *************** *** 183,190 **** gl.glColor4f(1, 1, 1, 1); for (int i = 0; i < MAX_LIGHTMAPS; i++) { ! for (msurface_t surf = gl_lms.lightmap_surfaces[i]; surf != null; surf = surf.lightmapchain) { ! for (glpoly_t p = surf.polys; p != null; p = p.chain) { ! for (int j = 2; j < p.numverts; j++) { gl.glBegin(GL11.GL_LINE_STRIP); gl.glVertex3f(p.x(0), p.y(0), p.z(0)); --- 168,178 ---- gl.glColor4f(1, 1, 1, 1); + msurface_t surf; + glpoly_t p; + int j; for (int i = 0; i < MAX_LIGHTMAPS; i++) { ! for (surf = gl_lms.lightmap_surfaces[i]; surf != null; surf = surf.lightmapchain) { ! for (p = surf.polys; p != null; p = p.chain) { ! for (j = 2; j < p.numverts; j++) { gl.glBegin(GL11.GL_LINE_STRIP); gl.glVertex3f(p.x(0), p.y(0), p.z(0)); *************** *** 202,221 **** } ! private IntBuffer temp2 = Lib.newIntBuffer(34 * 34, ByteOrder.LITTLE_ENDIAN); ! /* ! ================ ! R_RenderBrushPoly ! ================ ! */ void R_RenderBrushPoly(msurface_t fa) { - int maps; - image_t image; - boolean is_dynamic = false; - c_brush_polys++; ! image = R_TextureAnimation(fa.texinfo); if ((fa.flags & Defines.SURF_DRAWTURB) != 0) --- 190,203 ---- } ! private final IntBuffer temp2 = Lib.newIntBuffer(34 * 34, ByteOrder.LITTLE_ENDIAN); ! /** ! * R_RenderBrushPoly ! */ void R_RenderBrushPoly(msurface_t fa) { c_brush_polys++; ! image_t image = R_TextureAnimation(fa.texinfo); if ((fa.flags & Defines.SURF_DRAWTURB) != 0) *************** *** 254,257 **** --- 236,240 ---- ** check for lightmap modification */ + int maps; for ( maps = 0; maps < Defines.MAXLIGHTMAPS && fa.styles[maps] != (byte)255; maps++ ) { *************** *** 266,269 **** --- 249,253 ---- // dynamic this frame or dynamic previously + boolean is_dynamic = false; if ( gotoDynamic || ( fa.dlightframe == r_framecount ) ) { *************** *** 316,333 **** ! /* ! ================ ! R_DrawAlphaSurfaces ! ! Draw water surfaces and windows. ! The BSP tree is waled front to back, so unwinding the chain ! of alpha_surfaces will draw back to front, giving proper ordering. ! ================ ! */ void R_DrawAlphaSurfaces() { - msurface_t s; - float intens; - r_world_matrix.clear(); // --- 300,311 ---- ! /** ! * R_DrawAlphaSurfaces ! * Draw water surfaces and windows. ! * The BSP tree is waled front to back, so unwinding the chain ! * of alpha_surfaces will draw back to front, giving proper ordering. ! */ void R_DrawAlphaSurfaces() { r_world_matrix.clear(); // *************** *** 342,350 **** // the textures are prescaled up for a better lighting range, // so scale it back down ! intens = gl_state.inverse_intensity; gl.glInterleavedArrays(GL11.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); ! for (s=r_alpha_surfaces ; s != null ; s=s.texturechain) { GL_Bind(s.texinfo.image.texnum); --- 320,328 ---- // the textures are prescaled up for a better lighting range, // so scale it back down ! float intens = gl_state.inverse_intensity; gl.glInterleavedArrays(GL11.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); ! for (msurface_t s = r_alpha_surfaces ; s != null ; s=s.texturechain) { GL_Bind(s.texinfo.image.texnum); *************** *** 371,387 **** } ! /* ! ================ ! DrawTextureChains ! ================ ! */ void DrawTextureChains() { - int i; - msurface_t s; - image_t image; - c_visible_textures = 0; for (i = 0; i < numgltextures ; i++) { --- 349,362 ---- } ! /** ! * DrawTextureChains ! */ void DrawTextureChains() { c_visible_textures = 0; + msurface_t s; + image_t image; + int i; for (i = 0; i < numgltextures ; i++) { *************** *** 425,445 **** // direct buffer ! private IntBuffer temp = Lib.newIntBuffer(128 * 128, ByteOrder.LITTLE_ENDIAN); ! void GL_RenderLightmappedPoly( msurface_t surf ) { - int i, nv = surf.polys.numverts; - int map = 0; - int index; - float[][] v; - FloatBuffer texCoord = globalPolygonInterleavedBuf; - image_t image = R_TextureAnimation( surf.texinfo ); - boolean is_dynamic = false; - int lmtex = surf.lightmaptexturenum; - glpoly_t p; // ersetzt goto boolean gotoDynamic = false; ! for ( map = 0; map < Defines.MAXLIGHTMAPS && (surf.styles[map] != (byte)255); map++ ) { --- 400,415 ---- // direct buffer ! private final IntBuffer temp = Lib.newIntBuffer(128 * 128, ByteOrder.LITTLE_ENDIAN); ! ! /** ! * GL_RenderLightmappedPoly ! * @param surf ! */ void GL_RenderLightmappedPoly( msurface_t surf ) { // ersetzt goto boolean gotoDynamic = false; ! int map; for ( map = 0; map < Defines.MAXLIGHTMAPS && (surf.styles[map] != (byte)255); map++ ) { *************** *** 454,457 **** --- 424,428 ---- // dynamic this frame or dynamic previously + boolean is_dynamic = false; if ( gotoDynamic || ( surf.dlightframe == r_framecount ) ) { *************** *** 466,469 **** --- 437,445 ---- } + glpoly_t p; + FloatBuffer texCoord = globalPolygonInterleavedBuf; + image_t image = R_TextureAnimation( surf.texinfo ); + int lmtex = surf.lightmaptexturenum; + if ( is_dynamic ) { *************** *** 582,602 **** } ! /* ! ================= ! R_DrawInlineBModel ! ================= ! */ void R_DrawInlineBModel() { - int i, k; - cplane_t pplane; - float dot; - msurface_t psurf; - dlight_t lt; - // calculate dynamic lighting for bmodel if ( gl_flashblend.value == 0 ) { ! for (k=0 ; k<r_newrefdef.num_dlights ; k++) { lt = r_newrefdef.dlights[k]; --- 558,571 ---- } ! /** ! * R_DrawInlineBModel ! */ void R_DrawInlineBModel() { // calculate dynamic lighting for bmodel if ( gl_flashblend.value == 0 ) { ! dlight_t lt; ! for (int k=0 ; k<r_newrefdef.num_dlights ; k++) { lt = r_newrefdef.dlights[k]; *************** *** 607,612 **** // psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; int psurfp = currentmodel.firstmodelsurface; ! msurface_t[] surfaces; ! surfaces = currentmodel.surfaces; //psurf = surfaces[psurfp]; --- 576,580 ---- // psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; int psurfp = currentmodel.firstmodelsurface; ! msurface_t[] surfaces = currentmodel.surfaces; //psurf = surfaces[psurfp]; *************** *** 621,625 **** // draw texture // ! for (i=0 ; i<currentmodel.nummodelsurfaces ; i++) { psurf = surfaces[psurfp++]; --- 589,596 ---- // draw texture // ! msurface_t psurf; ! cplane_t pplane; ! float dot; ! for (int i=0 ; i<currentmodel.nummodelsurfaces ; i++) { psurf = surfaces[psurfp++]; *************** *** 658,673 **** } ! /* ! ================= ! R_DrawBrushModel ! ================= ! */ void R_DrawBrushModel(entity_t e) { - float[] mins = {0, 0, 0}; - float[] maxs = {0, 0, 0}; - int i; - boolean rotated; - if (currentmodel.nummodelsurfaces == 0) return; --- 629,644 ---- } ! // stack variable ! private final float[] mins = {0, 0, 0}; ! private final float[] maxs = {0, 0, 0}; ! private final float[] org = {0, 0, 0}; ! private final float[] forward = {0, 0, 0}; ! private final float[] right = {0, 0, 0}; ! private final float[] up = {0, 0, 0}; ! /** ! * R_DrawBrushModel ! */ void R_DrawBrushModel(entity_t e) { if (currentmodel.nummodelsurfaces == 0) return; *************** *** 676,683 **** gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; if (e.angles[0] != 0 || e.angles[1] != 0 || e.angles[2] != 0) { rotated = true; ! for (i=0 ; i<3 ; i++) { mins[i] = e.origin[i] - currentmodel.radius; --- 647,655 ---- gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; + boolean rotated; if (e.angles[0] != 0 || e.angles[1] != 0 || e.angles[2] != 0) { rotated = true; ! for (int i=0 ; i<3 ; i++) { mins[i] = e.origin[i] - currentmodel.radius; *************** *** 704,717 **** if (rotated) { ! float[] temp = {0, 0, 0}; ! float[] forward = {0, 0, 0}; ! float[] right = {0, 0, 0}; ! float[] up = {0, 0, 0}; ! ! Math3D.VectorCopy (modelorg, temp); Math3D.AngleVectors (e.angles, forward, right, up); ! modelorg[0] = Math3D.DotProduct (temp, forward); ! modelorg[1] = -Math3D.DotProduct (temp, right); ! modelorg[2] = Math3D.DotProduct (temp, up); } --- 676,684 ---- if (rotated) { ! Math3D.VectorCopy (modelorg, org); Math3D.AngleVectors (e.angles, forward, right, up); ! modelorg[0] = Math3D.DotProduct (org, forward); ! modelorg[1] = -Math3D.DotProduct (org, right); ! modelorg[2] = Math3D.DotProduct (org, up); } *************** *** 751,769 **** */ ! /* ! ================ ! R_RecursiveWorldNode ! ================ ! */ void R_RecursiveWorldNode (mnode_t node) { - int c, side, sidebit; - cplane_t plane; - msurface_t surf; - msurface_t mark; - mleaf_t pleaf; - float dot = 0; - image_t image; - if (node.contents == Defines.CONTENTS_SOLID) return; // solid --- 718,726 ---- */ ! /** ! * R_RecursiveWorldNode ! */ void R_RecursiveWorldNode (mnode_t node) { if (node.contents == Defines.CONTENTS_SOLID) return; // solid *************** *** 775,782 **** return; // if a leaf node, draw stuff if (node.contents != -1) { ! pleaf = (mleaf_t)node; // check for door connected areas --- 732,741 ---- return; + int c; + msurface_t mark; // if a leaf node, draw stuff if (node.contents != -1) { ! mleaf_t pleaf = (mleaf_t)node; // check for door connected areas *************** *** 807,812 **** // find which side of the node we are on ! plane = node.plane; ! switch (plane.type) { --- 766,771 ---- // find which side of the node we are on ! cplane_t plane = node.plane; ! float dot; switch (plane.type) { *************** *** 825,828 **** --- 784,788 ---- } + int side, sidebit; if (dot >= 0.0f) { *************** *** 840,843 **** --- 800,805 ---- // draw stuff + msurface_t surf; + image_t image; //for ( c = node.numsurfaces, surf = r_worldmodel.surfaces[node.firstsurface]; c != 0 ; c--, surf++) for ( c = 0; c < node.numsurfaces; c++) *************** *** 876,897 **** } } - // recurse down the back side R_RecursiveWorldNode(node.children[1 - side]); } ! ! /* ! ============= ! R_DrawWorld ! ============= ! */ void R_DrawWorld() { - entity_t ent = new entity_t(); - // auto cycle the world frame for texture animation - ent.frame = (int)(r_newrefdef.time*2); - currententity = ent; - if (r_drawworld.value == 0) return; --- 838,852 ---- } } // recurse down the back side R_RecursiveWorldNode(node.children[1 - side]); } ! private final entity_t worldEntity = new entity_t(); ! ! /** ! * R_DrawWorld ! */ void R_DrawWorld() { if (r_drawworld.value == 0) return; *************** *** 904,907 **** --- 859,868 ---- Math3D.VectorCopy(r_newrefdef.vieworg, modelorg); + entity_t ent = worldEntity; + // auto cycle the world frame for texture animation + ent.clear(); + ent.frame = (int)(r_newrefdef.time*2); + currententity = ent; + gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; *************** *** 939,964 **** } ! byte[] fatvis = new byte[Defines.MAX_MAP_LEAFS / 8]; ! ! /* ! =============== ! R_MarkLeaves ! Mark the leaves and nodes that are in the PVS for the current ! cluster ! =============== ! */ void R_MarkLeaves() { - //byte[] vis; - //byte[] fatvis = new byte[Defines.MAX_MAP_LEAFS / 8]; - - //Arrays.fill(fatvis, (byte)0); - - mnode_t node; - int i, c; - mleaf_t leaf; - int cluster; - if (r_oldviewcluster == r_viewcluster && r_oldviewcluster2 == r_viewcluster2 && r_novis.value == 0 && r_viewcluster != -1) return; --- 900,912 ---- } ! final byte[] fatvis = new byte[Defines.MAX_MAP_LEAFS / 8]; ! /** ! * R_MarkLeaves ! * Mark the leaves and nodes that are in the PVS for the current ! * cluster ! */ void R_MarkLeaves() { if (r_oldviewcluster == r_viewcluster && r_oldviewcluster2 == r_viewcluster2 && r_novis.value == 0 && r_viewcluster != -1) return; *************** *** 973,976 **** --- 921,925 ---- r_oldviewcluster2 = r_viewcluster2; + int i; if (r_novis.value != 0 || r_viewcluster == -1 || r_worldmodel.vis == null) { *************** *** 984,987 **** --- 933,937 ---- byte[] vis = Mod_ClusterPVS(r_viewcluster, r_worldmodel); + int c; // may have to combine two clusters because of solid water boundaries if (r_viewcluster2 != r_viewcluster) *************** *** 1001,1005 **** vis = fatvis; } ! for ( i=0; i < r_worldmodel.numleafs; i++) { --- 951,958 ---- vis = fatvis; } ! ! mnode_t node; ! mleaf_t leaf; ! int cluster; for ( i=0; i < r_worldmodel.numleafs; i++) { *************** *** 1022,1027 **** } - - /* ============================================================================= --- 975,978 ---- *************** *** 1032,1035 **** --- 983,989 ---- */ + /** + * LM_InitBlock + */ void LM_InitBlock() { *************** *** 1037,1053 **** } void LM_UploadBlock( boolean dynamic ) { ! int texture; ! int height = 0; ! ! if ( dynamic ) ! { ! texture = 0; ! } ! else ! { ! texture = gl_lms.current_lightmap_texture; ! } GL_Bind( gl_state.lightmap_textures + texture ); --- 991,1001 ---- } + /** + * LM_UploadBlock + * @param dynamic + */ void LM_UploadBlock( boolean dynamic ) { ! int texture = ( dynamic ) ? 0 : gl_lms.current_lightmap_texture; GL_Bind( gl_state.lightmap_textures + texture ); *************** *** 1058,1064 **** if ( dynamic ) { ! int i; ! ! for ( i = 0; i < BLOCK_WIDTH; i++ ) { if ( gl_lms.allocated[i] > height ) --- 1006,1011 ---- if ( dynamic ) { ! int height = 0; ! for (int i = 0; i < BLOCK_WIDTH; i++ ) { if ( gl_lms.allocated[i] > height ) *************** *** 1087,1106 **** Com.Error( Defines.ERR_DROP, "LM_UploadBlock() - MAX_LIGHTMAPS exceeded\n" ); - //debugLightmap(gl_lms.lightmap_buffer, 128, 128, 4); - } } ! // returns a texture number and the position inside it boolean LM_AllocBlock (int w, int h, pos_t pos) { int x = pos.x; int y = pos.y; - int i, j; - int best, best2; - - best = BLOCK_HEIGHT; for (i=0 ; i<BLOCK_WIDTH-w ; i++) { --- 1034,1056 ---- Com.Error( Defines.ERR_DROP, "LM_UploadBlock() - MAX_LIGHTMAPS exceeded\n" ); //debugLightmap(gl_lms.lightmap_buffer, 128, 128, 4); } } ! /** ! * LM_AllocBlock ! * @param w ! * @param h ! * @param pos ! * @return a texture number and the position inside it ! */ boolean LM_AllocBlock (int w, int h, pos_t pos) { + int best = BLOCK_HEIGHT; int x = pos.x; int y = pos.y; + int best2; + int i, j; for (i=0 ; i<BLOCK_WIDTH-w ; i++) { *************** *** 1130,1154 **** } ! /* ! ================ ! GL_BuildPolygonFromSurface ! ================ ! */ void GL_BuildPolygonFromSurface(msurface_t fa) { - int i, lindex, lnumverts; - medge_t[] pedges; - medge_t r_pedge; - int vertpage; - float[] vec; - float s, t; - float[] total = {0, 0, 0}; - // reconstruct the polygon ! pedges = currentmodel.edges; ! lnumverts = fa.numedges; ! vertpage = 0; ! ! Math3D.VectorClear(total); // // draw texture --- 1080,1092 ---- } ! /** ! * GL_BuildPolygonFromSurface ! */ void GL_BuildPolygonFromSurface(msurface_t fa) { // reconstruct the polygon ! medge_t[] pedges = currentmodel.edges; ! int lnumverts = fa.numedges; ! int vertpage = 0; // // draw texture *************** *** 1161,1165 **** fa.polys = poly; ! for (i=0 ; i<lnumverts ; i++) { lindex = currentmodel.surfedges[fa.firstedge + i]; --- 1099,1107 ---- fa.polys = poly; ! int lindex; ! float[] vec; ! medge_t r_pedge; ! float s, t; ! for (int i=0 ; i<lnumverts ; i++) { lindex = currentmodel.surfedges[fa.firstedge + i]; *************** *** 1181,1185 **** t /= fa.texinfo.image.height; - Math3D.VectorAdd (total, vec, total); poly.x(i, vec[0]); poly.y(i, vec[1]); --- 1123,1126 ---- *************** *** 1209,1227 **** } ! /* ! ======================== ! GL_CreateSurfaceLightmap ! ======================== ! */ void GL_CreateSurfaceLightmap(msurface_t surf) { - int smax, tmax; - IntBuffer base; - if ( (surf.flags & (Defines.SURF_DRAWSKY | Defines.SURF_DRAWTURB)) != 0) return; ! smax = (surf.extents[0]>>4)+1; ! tmax = (surf.extents[1]>>4)+1; pos_t lightPos = new pos_t(surf.light_s, surf.light_t); --- 1150,1163 ---- } ! /** ! * GL_CreateSurfaceLightmap ! */ void GL_CreateSurfaceLightmap(msurface_t surf) { if ( (surf.flags & (Defines.SURF_DRAWSKY | Defines.SURF_DRAWTURB)) != 0) return; ! int smax = (surf.extents[0]>>4)+1; ! int tmax = (surf.extents[1]>>4)+1; pos_t lightPos = new pos_t(surf.light_s, surf.light_t); *************** *** 1244,1248 **** surf.lightmaptexturenum = gl_lms.current_lightmap_texture; ! base = gl_lms.lightmap_buffer; base.position(surf.light_t * BLOCK_WIDTH + surf.light_s); --- 1180,1184 ---- surf.lightmaptexturenum = gl_lms.current_lightmap_texture; ! IntBuffer base = gl_lms.lightmap_buffer; base.position(surf.light_t * BLOCK_WIDTH + surf.light_s); *************** *** 1252,1263 **** lightstyle_t[] lightstyles; ! IntBuffer dummy = BufferUtils.createIntBuffer(128*128); ! ! /* ! ================== ! GL_BeginBuildingLightmaps ! ================== ! */ void GL_BeginBuildingLightmaps(model_t m) { --- 1188,1196 ---- lightstyle_t[] lightstyles; ! private final IntBuffer dummy = BufferUtils.createIntBuffer(128*128); ! /** ! * GL_BeginBuildingLightmaps ! */ void GL_BeginBuildingLightmaps(model_t m) { *************** *** 1358,1366 **** } ! /* ! ======================= ! GL_EndBuildingLightmaps ! ======================= ! */ void GL_EndBuildingLightmaps() { --- 1291,1297 ---- } ! /** ! * GL_EndBuildingLightmaps ! */ void GL_EndBuildingLightmaps() { |