From a57b1f9be0c9f6871d1350c99d96303d92ca349d Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 22 Jul 2018 16:50:44 +0300 Subject: [PATCH 01/19] use only allocated edges --- src/client/refresh/soft/header/local.h | 2 -- src/client/refresh/soft/sw_edge.c | 1 - src/client/refresh/soft/sw_main.c | 35 ++++++-------------------- src/client/refresh/soft/sw_rast.c | 4 +++ 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 521379e0..3f03ed33 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -159,7 +159,6 @@ extern oldrefdef_t r_refdef; #define DS_SPAN_LIST_END -128 #define NUMSTACKEDGES 2000 -#define MINEDGES NUMSTACKEDGES #define NUMSTACKSURFACES 1000 #define MINSURFACES NUMSTACKSURFACES #define MAXSPANS 3000 @@ -504,7 +503,6 @@ extern int r_currentbkey; void R_DrawParticles (void); extern int r_amodels_drawn; -extern edge_t *auxedges; extern int r_numallocatededges; extern edge_t *r_edges, *edge_p, *edge_max; diff --git a/src/client/refresh/soft/sw_edge.c b/src/client/refresh/soft/sw_edge.c index 5ef65711..3512fcdf 100644 --- a/src/client/refresh/soft/sw_edge.c +++ b/src/client/refresh/soft/sw_edge.c @@ -30,7 +30,6 @@ have a sentinal at both ends? */ -edge_t *auxedges; edge_t *r_edges, *edge_p, *edge_max; surf_t *surfaces, *surface_p, *surf_max; diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index f7eb1a48..42d6e18f 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -411,7 +411,8 @@ void R_NewMap (void) surfaces = malloc (r_cnumsurfs * sizeof(surf_t)); if (!surfaces) { - R_Printf(PRINT_ALL, "R_NewMap: Couldn't malloc %d bytes\n", (int)(r_cnumsurfs * sizeof(surf_t))); + R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", + __func__, (int)(r_cnumsurfs * sizeof(surf_t))); return; } @@ -432,17 +433,12 @@ void R_NewMap (void) r_numallocatededges = sw_maxedges->value; - if (r_numallocatededges < MINEDGES) - r_numallocatededges = MINEDGES; + if (r_numallocatededges < NUMSTACKEDGES) + r_numallocatededges = NUMSTACKEDGES; - if (r_numallocatededges <= NUMSTACKEDGES) - { - auxedges = NULL; - } - else - { - auxedges = malloc (r_numallocatededges * sizeof(edge_t)); - } + R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", + __func__, r_numallocatededges); + r_edges = malloc (r_numallocatededges * sizeof(edge_t)); } @@ -862,7 +858,6 @@ R_DrawBEntitiesOnList (void) insubmodel = false; } -static edge_t *ledges; static surf_t *lsurfs; /* @@ -878,15 +873,6 @@ R_EdgeDrawing (void) if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) return; - if (auxedges) - { - r_edges = auxedges; - } - else - { - r_edges = ledges; - } - if (r_surfsonstack) { surfaces = lsurfs; @@ -1760,12 +1746,6 @@ static void SWimp_DestroyRender(void) } finalverts = NULL; - if(ledges) - { - free(ledges); - } - ledges = NULL; - if(lsurfs) { free(lsurfs); @@ -1927,7 +1907,6 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) edge_basespans = malloc((vid.width*2) * sizeof(espan_t)); finalverts = malloc((MAXALIASVERTS + 3) * sizeof(finalvert_t)); - ledges = malloc((NUMSTACKEDGES + 1) * sizeof(edge_t)); lsurfs = malloc((NUMSTACKSURFACES + 1) * sizeof(surf_t)); r_warpbuffer = malloc(vid.height * vid.width * sizeof(pixel_t)); diff --git a/src/client/refresh/soft/sw_rast.c b/src/client/refresh/soft/sw_rast.c index ddb1f979..bcabced7 100644 --- a/src/client/refresh/soft/sw_rast.c +++ b/src/client/refresh/soft/sw_rast.c @@ -546,6 +546,8 @@ void R_RenderFace (msurface_t *fa, int clipflags) // ditto if not enough edges left, or switch to auxedges if possible if ((edge_p + fa->numedges + 4) >= edge_max) { + R_Printf(PRINT_ALL, "%s: not enough %d edges\n", + __func__, r_numallocatededges); r_outofedges += fa->numedges; return; } @@ -752,6 +754,8 @@ void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) // ditto if not enough edges left, or switch to auxedges if possible if ((edge_p + psurf->numedges + 4) >= edge_max) { + R_Printf(PRINT_ALL, "%s: not enough %d edges\n", + __func__, r_numallocatededges); r_outofedges += psurf->numedges; return; } From d36f19fda54d0117a09e55aee9259519cbdd8e9e Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 22 Jul 2018 17:20:33 +0300 Subject: [PATCH 02/19] use only allocated surfaces --- src/client/refresh/soft/header/local.h | 1 - src/client/refresh/soft/sw_main.c | 35 ++++++-------------------- src/client/refresh/soft/sw_rast.c | 4 --- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 3f03ed33..cf5d02e0 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -160,7 +160,6 @@ extern oldrefdef_t r_refdef; #define NUMSTACKEDGES 2000 #define NUMSTACKSURFACES 1000 -#define MINSURFACES NUMSTACKSURFACES #define MAXSPANS 3000 // flags in finalvert_t.flags diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 42d6e18f..3b6253ca 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -68,7 +68,6 @@ mvertex_t *r_pcurrentvertbase; int c_surf; static int r_maxsurfsseen, r_maxedgesseen, r_cnumsurfs; -static qboolean r_surfsonstack; int r_clipflags; // @@ -403,10 +402,9 @@ void R_NewMap (void) r_cnumsurfs = sw_maxsurfs->value; - if (r_cnumsurfs <= MINSURFACES) - r_cnumsurfs = MINSURFACES; + if (r_cnumsurfs <= NUMSTACKSURFACES) + r_cnumsurfs = NUMSTACKSURFACES; - if (r_cnumsurfs > NUMSTACKSURFACES) { surfaces = malloc (r_cnumsurfs * sizeof(surf_t)); if (!surfaces) @@ -418,15 +416,10 @@ void R_NewMap (void) surface_p = surfaces; surf_max = &surfaces[r_cnumsurfs]; - r_surfsonstack = false; // surface 0 doesn't really exist; it's just a dummy because index 0 // is used to indicate no edge attached to surface surfaces--; } - else - { - r_surfsonstack = true; - } r_maxedgesseen = 0; r_maxsurfsseen = 0; @@ -858,8 +851,6 @@ R_DrawBEntitiesOnList (void) insubmodel = false; } -static surf_t *lsurfs; - /* ================ R_EdgeDrawing @@ -873,15 +864,6 @@ R_EdgeDrawing (void) if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) return; - if (r_surfsonstack) - { - surfaces = lsurfs; - surf_max = &surfaces[r_cnumsurfs]; - // surface 0 doesn't really exist; it's just a dummy because index 0 - // is used to indicate no edge attached to surface - surfaces--; - } - // Set function pointer pdrawfunc used later in this function R_BeginEdgeFrame (); @@ -1075,9 +1057,15 @@ RE_RenderFrame (refdef_t *fd) if (sw_reportsurfout->value && r_outofsurfaces) R_Printf(PRINT_ALL,"Short %d surfaces\n", r_outofsurfaces); + else if (r_outofsurfaces) + R_Printf(PRINT_ALL, "%s: not enough %d surfaces\n", + __func__, r_cnumsurfs); if (sw_reportedgeout->value && r_outofedges) R_Printf(PRINT_ALL,"Short roughly %d edges\n", r_outofedges * 2 / 3); + else if (r_outofedges) + R_Printf(PRINT_ALL, "%s: not enough %d edges\n", + __func__, r_numallocatededges); } /* @@ -1746,12 +1734,6 @@ static void SWimp_DestroyRender(void) } finalverts = NULL; - if(lsurfs) - { - free(lsurfs); - } - lsurfs = NULL; - if(r_warpbuffer) { free(r_warpbuffer); @@ -1907,7 +1889,6 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) edge_basespans = malloc((vid.width*2) * sizeof(espan_t)); finalverts = malloc((MAXALIASVERTS + 3) * sizeof(finalvert_t)); - lsurfs = malloc((NUMSTACKSURFACES + 1) * sizeof(surf_t)); r_warpbuffer = malloc(vid.height * vid.width * sizeof(pixel_t)); if ((vid.width >= 2048) && (sizeof(shift20_t) == 4)) // 2k+ resolution and 32 == shift20_t diff --git a/src/client/refresh/soft/sw_rast.c b/src/client/refresh/soft/sw_rast.c index bcabced7..ddb1f979 100644 --- a/src/client/refresh/soft/sw_rast.c +++ b/src/client/refresh/soft/sw_rast.c @@ -546,8 +546,6 @@ void R_RenderFace (msurface_t *fa, int clipflags) // ditto if not enough edges left, or switch to auxedges if possible if ((edge_p + fa->numedges + 4) >= edge_max) { - R_Printf(PRINT_ALL, "%s: not enough %d edges\n", - __func__, r_numallocatededges); r_outofedges += fa->numedges; return; } @@ -754,8 +752,6 @@ void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) // ditto if not enough edges left, or switch to auxedges if possible if ((edge_p + psurf->numedges + 4) >= edge_max) { - R_Printf(PRINT_ALL, "%s: not enough %d edges\n", - __func__, r_numallocatededges); r_outofedges += psurf->numedges; return; } From 1a5a0922c89c58ba0eed775fb5dd4cd784d7e6a8 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 23 Jul 2018 00:34:34 +0300 Subject: [PATCH 03/19] Set bigger limits --- src/client/refresh/soft/header/local.h | 7 +++---- src/client/refresh/soft/sw_alias.c | 8 ++++---- src/client/refresh/soft/sw_main.c | 15 +++++++++------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index cf5d02e0..ceadbaf6 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -158,9 +158,8 @@ extern oldrefdef_t r_refdef; #define DS_SPAN_LIST_END -128 -#define NUMSTACKEDGES 2000 -#define NUMSTACKSURFACES 1000 -#define MAXSPANS 3000 +#define NUMSTACKEDGES 3072 +#define NUMSTACKSURFACES 2048 // flags in finalvert_t.flags #define ALIAS_LEFT_CLIP 0x0001 @@ -185,7 +184,7 @@ extern oldrefdef_t r_refdef; #define NEAR_CLIP 0.01 -#define MAXALIASVERTS 2000 // TODO: tune this +#define MAXALIASVERTS 2048 // TODO: tune this #define ALIAS_Z_CLIP_PLANE 4 // turbulence stuff diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index 9f7ca9de..a0efc04f 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -235,7 +235,7 @@ finalvert_t *finalverts; static void R_AliasPreparePoints (void) { - int i; + int i; dstvert_t *pstverts; dtriangle_t *ptri; finalvert_t *pfv[3]; @@ -250,9 +250,9 @@ R_AliasPreparePoints (void) aliasbatchedtransformdata.dest_verts = pfinalverts; R_AliasTransformFinalVerts( aliasbatchedtransformdata.num_points, - aliasbatchedtransformdata.dest_verts, - aliasbatchedtransformdata.last_verts, - aliasbatchedtransformdata.this_verts ); + aliasbatchedtransformdata.dest_verts, + aliasbatchedtransformdata.last_verts, + aliasbatchedtransformdata.this_verts ); // clip and draw all triangles // diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 3b6253ca..097d37e4 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -429,9 +429,12 @@ void R_NewMap (void) if (r_numallocatededges < NUMSTACKEDGES) r_numallocatededges = NUMSTACKEDGES; - R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", - __func__, r_numallocatededges); r_edges = malloc (r_numallocatededges * sizeof(edge_t)); + + R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", + __func__, r_numallocatededges); + R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n", + __func__, r_cnumsurfs); } @@ -1058,14 +1061,14 @@ RE_RenderFrame (refdef_t *fd) if (sw_reportsurfout->value && r_outofsurfaces) R_Printf(PRINT_ALL,"Short %d surfaces\n", r_outofsurfaces); else if (r_outofsurfaces) - R_Printf(PRINT_ALL, "%s: not enough %d surfaces\n", - __func__, r_cnumsurfs); + R_Printf(PRINT_ALL, "%s: not enough %d(+%d) surfaces\n", + __func__, r_cnumsurfs, r_outofsurfaces); if (sw_reportedgeout->value && r_outofedges) R_Printf(PRINT_ALL,"Short roughly %d edges\n", r_outofedges * 2 / 3); else if (r_outofedges) - R_Printf(PRINT_ALL, "%s: not enough %d edges\n", - __func__, r_numallocatededges); + R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n", + __func__, r_numallocatededges, r_outofedges * 2 / 3); } /* From 789cd0128a00628ba10b3f28813a13cb6bb0fc1d Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 23 Jul 2018 16:51:16 +0300 Subject: [PATCH 04/19] use only allocated finalverts --- src/client/refresh/soft/header/local.h | 15 +++++----- src/client/refresh/soft/sw_alias.c | 40 ++++++++++++++------------ src/client/refresh/soft/sw_main.c | 26 ++++++++++++----- src/client/refresh/soft/sw_misc.c | 1 + 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index ceadbaf6..85538bea 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -160,6 +160,7 @@ extern oldrefdef_t r_refdef; #define NUMSTACKEDGES 3072 #define NUMSTACKSURFACES 2048 +#define MAXALIASVERTS 2048 // TODO: tune this // flags in finalvert_t.flags #define ALIAS_LEFT_CLIP 0x0001 @@ -183,8 +184,6 @@ extern oldrefdef_t r_refdef; #define NEAR_CLIP 0.01 - -#define MAXALIASVERTS 2048 // TODO: tune this #define ALIAS_Z_CLIP_PLANE 4 // turbulence stuff @@ -519,16 +518,18 @@ extern spanpackage_t *triangle_spans; extern byte **warp_rowptr; extern int *warp_column; extern espan_t *edge_basespans; -extern finalvert_t *finalverts; +extern int r_numallocatedverts; +extern finalvert_t *finalverts, *finalverts_max; extern int r_aliasblendcolor; -extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter; +extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter; -extern int r_outofsurfaces; -extern int r_outofedges; +extern int r_outofsurfaces; +extern int r_outofedges; +extern int r_outofverts; -extern mvertex_t *r_pcurrentvertbase; +extern mvertex_t *r_pcurrentvertbase; typedef struct { diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index a0efc04f..765608ba 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -221,16 +221,7 @@ R_AliasPreparePoints General clipped case ================ */ -typedef struct -{ - int num_points; - dtrivertx_t *last_verts; // verts from the last frame - dtrivertx_t *this_verts; // verts from this frame - finalvert_t *dest_verts; // destination for transformed verts -} aliasbatchedtransformdata_t; - -static aliasbatchedtransformdata_t aliasbatchedtransformdata; -finalvert_t *finalverts; +finalvert_t *finalverts, *finalverts_max; static void R_AliasPreparePoints (void) @@ -244,15 +235,11 @@ R_AliasPreparePoints (void) // put work vertexes on stack, cache aligned pfinalverts = finalverts; - aliasbatchedtransformdata.num_points = s_pmdl->num_xyz; - aliasbatchedtransformdata.last_verts = r_lastframe->verts; - aliasbatchedtransformdata.this_verts = r_thisframe->verts; - aliasbatchedtransformdata.dest_verts = pfinalverts; - - R_AliasTransformFinalVerts( aliasbatchedtransformdata.num_points, - aliasbatchedtransformdata.dest_verts, - aliasbatchedtransformdata.last_verts, - aliasbatchedtransformdata.this_verts ); + R_AliasTransformFinalVerts( s_pmdl->num_xyz, + pfinalverts, // destination for transformed verts + r_lastframe->verts, // verts from the last frame + r_thisframe->verts // verts from this frame + ); // clip and draw all triangles // @@ -267,6 +254,11 @@ R_AliasPreparePoints (void) pfv[1] = &pfinalverts[ptri->index_xyz[1]]; pfv[2] = &pfinalverts[ptri->index_xyz[2]]; + if ( pfv[0] >= finalverts_max || + pfv[1] >= finalverts_max || + pfv[2] >= finalverts_max ) + continue; // not enough verts + if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags ) continue; // completely clipped @@ -302,6 +294,11 @@ R_AliasPreparePoints (void) pfv[1] = &pfinalverts[ptri->index_xyz[1]]; pfv[2] = &pfinalverts[ptri->index_xyz[2]]; + if ( pfv[0] >= finalverts_max || + pfv[1] >= finalverts_max || + pfv[2] >= finalverts_max ) + continue; // not enough verts + if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags ) continue; // completely clipped @@ -417,6 +414,11 @@ R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, d float lightcos, *plightnormal; vec3_t lerped_vert; + if (fv >= finalverts_max) { + r_outofverts ++; + continue; + } + lerped_vert[0] = r_lerp_move[0] + oldv->v[0]*r_lerp_backv[0] + newv->v[0]*r_lerp_frontv[0]; lerped_vert[1] = r_lerp_move[1] + oldv->v[1]*r_lerp_backv[1] + newv->v[1]*r_lerp_frontv[1]; lerped_vert[2] = r_lerp_move[2] + oldv->v[2]*r_lerp_backv[2] + newv->v[2]*r_lerp_frontv[2]; diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 097d37e4..20223a14 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -55,12 +55,14 @@ pixel_t *r_warpbuffer; static swstate_t sw_state; -void *colormap; -float r_time1; -int r_numallocatededges; -float r_aliasuvscale = 1.0; -int r_outofsurfaces; -int r_outofedges; +void *colormap; +float r_time1; +int r_numallocatededges; +int r_numallocatedverts; +float r_aliasuvscale = 1.0; +int r_outofsurfaces; +int r_outofedges; +int r_outofverts; qboolean r_dowarp; @@ -431,10 +433,16 @@ void R_NewMap (void) r_edges = malloc (r_numallocatededges * sizeof(edge_t)); + r_numallocatedverts = MAXALIASVERTS; + finalverts = malloc(r_numallocatedverts * sizeof(finalvert_t)); + finalverts_max = &finalverts[r_numallocatedverts]; + R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", __func__, r_numallocatededges); R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n", __func__, r_cnumsurfs); + R_Printf(PRINT_ALL, "%s: Allocated %d verts\n", + __func__, r_numallocatedverts); } @@ -1069,6 +1077,10 @@ RE_RenderFrame (refdef_t *fd) else if (r_outofedges) R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n", __func__, r_numallocatededges, r_outofedges * 2 / 3); + + if (r_outofverts) + R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n", + __func__, r_numallocatedverts, r_outofverts); } /* @@ -1891,7 +1903,7 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) warp_column = malloc((vid.width+AMP2*2) * sizeof(int)); edge_basespans = malloc((vid.width*2) * sizeof(espan_t)); - finalverts = malloc((MAXALIASVERTS + 3) * sizeof(finalvert_t)); + r_warpbuffer = malloc(vid.height * vid.width * sizeof(pixel_t)); if ((vid.width >= 2048) && (sizeof(shift20_t) == 4)) // 2k+ resolution and 32 == shift20_t diff --git a/src/client/refresh/soft/sw_misc.c b/src/client/refresh/soft/sw_misc.c index f3aa14a0..d3bc444d 100644 --- a/src/client/refresh/soft/sw_misc.c +++ b/src/client/refresh/soft/sw_misc.c @@ -389,6 +389,7 @@ void R_SetupFrame (void) r_drawnpolycount = 0; r_amodels_drawn = 0; r_outofsurfaces = 0; + r_outofverts = 0; r_outofedges = 0; // d_setup From ad771fdd99f48d97541874e4b5c41eaaa38fcb8d Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 23 Jul 2018 17:02:24 +0300 Subject: [PATCH 05/19] more warnings --- src/client/refresh/soft/sw_main.c | 41 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 20223a14..8a2989aa 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -68,8 +68,8 @@ qboolean r_dowarp; mvertex_t *r_pcurrentvertbase; -int c_surf; -static int r_maxsurfsseen, r_maxedgesseen, r_cnumsurfs; +int c_surf; +static int r_cnumsurfs; int r_clipflags; // @@ -407,24 +407,19 @@ void R_NewMap (void) if (r_cnumsurfs <= NUMSTACKSURFACES) r_cnumsurfs = NUMSTACKSURFACES; + surfaces = malloc (r_cnumsurfs * sizeof(surf_t)); + if (!surfaces) { - surfaces = malloc (r_cnumsurfs * sizeof(surf_t)); - if (!surfaces) - { - R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", - __func__, (int)(r_cnumsurfs * sizeof(surf_t))); - return; - } - - surface_p = surfaces; - surf_max = &surfaces[r_cnumsurfs]; - // surface 0 doesn't really exist; it's just a dummy because index 0 - // is used to indicate no edge attached to surface - surfaces--; + R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", + __func__, (int)(r_cnumsurfs * sizeof(surf_t))); + return; } - r_maxedgesseen = 0; - r_maxsurfsseen = 0; + surface_p = surfaces; + surf_max = &surfaces[r_cnumsurfs]; + // surface 0 doesn't really exist; it's just a dummy because index 0 + // is used to indicate no edge attached to surface + surfaces--; r_numallocatededges = sw_maxedges->value; @@ -432,9 +427,21 @@ void R_NewMap (void) r_numallocatededges = NUMSTACKEDGES; r_edges = malloc (r_numallocatededges * sizeof(edge_t)); + if (!r_edges) + { + R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", + __func__, (int)(r_numallocatededges * sizeof(edge_t))); + return; + } r_numallocatedverts = MAXALIASVERTS; finalverts = malloc(r_numallocatedverts * sizeof(finalvert_t)); + if (!finalverts) + { + R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", + __func__, (int)(r_numallocatedverts * sizeof(finalvert_t))); + return; + } finalverts_max = &finalverts[r_numallocatedverts]; R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", From f9a77d2d668e1daa80ec545b291d8fbd23b30b34 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 23 Jul 2018 17:40:06 +0300 Subject: [PATCH 06/19] Share same Mod_DecompressVis --- CMakeLists.txt | 3 ++ Makefile | 3 ++ src/client/refresh/files/pvs.c | 76 +++++++++++++++++++++++++++++ src/client/refresh/gl1/gl1_model.c | 47 +----------------- src/client/refresh/gl3/gl3_model.c | 47 +----------------- src/client/refresh/ref_shared.h | 1 + src/client/refresh/soft/sw_aclip.c | 2 +- src/client/refresh/soft/sw_alias.c | 2 +- src/client/refresh/soft/sw_bsp.c | 2 +- src/client/refresh/soft/sw_edge.c | 2 +- src/client/refresh/soft/sw_light.c | 2 +- src/client/refresh/soft/sw_main.c | 4 +- src/client/refresh/soft/sw_misc.c | 2 +- src/client/refresh/soft/sw_model.c | 52 ++------------------ src/client/refresh/soft/sw_rast.c | 2 +- src/client/refresh/soft/sw_sprite.c | 2 +- src/client/refresh/soft/sw_surf.c | 2 +- 17 files changed, 99 insertions(+), 152 deletions(-) create mode 100644 src/client/refresh/files/pvs.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a180c8c..3609b5aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -454,6 +454,7 @@ set(GL1-Source ${REF_SRC_DIR}/files/pcx.c ${REF_SRC_DIR}/files/stb.c ${REF_SRC_DIR}/files/wal.c + ${REF_SRC_DIR}/files/pvs.c ${COMMON_SRC_DIR}/shared/shared.c ${COMMON_SRC_DIR}/md4.c ) @@ -490,6 +491,7 @@ set(GL3-Source ${REF_SRC_DIR}/files/pcx.c ${REF_SRC_DIR}/files/stb.c ${REF_SRC_DIR}/files/wal.c + ${REF_SRC_DIR}/files/pvs.c ${COMMON_SRC_DIR}/shared/shared.c ${COMMON_SRC_DIR}/md4.c ) @@ -531,6 +533,7 @@ set(SOFT-Source ${REF_SRC_DIR}/files/pcx.c ${REF_SRC_DIR}/files/stb.c ${REF_SRC_DIR}/files/wal.c + ${REF_SRC_DIR}/files/pvs.c ${COMMON_SRC_DIR}/shared/shared.c ${COMMON_SRC_DIR}/md4.c ) diff --git a/Makefile b/Makefile index 5e9d11d6..d8bc7609 100755 --- a/Makefile +++ b/Makefile @@ -920,6 +920,7 @@ REFGL1_OBJS_ := \ src/client/refresh/files/pcx.o \ src/client/refresh/files/stb.o \ src/client/refresh/files/wal.o \ + src/client/refresh/files/pvs.o \ src/common/shared/shared.o \ src/common/md4.o @@ -952,6 +953,7 @@ REFGL3_OBJS_ := \ src/client/refresh/files/pcx.o \ src/client/refresh/files/stb.o \ src/client/refresh/files/wal.o \ + src/client/refresh/files/pvs.o \ src/common/shared/shared.o \ src/common/md4.o @@ -986,6 +988,7 @@ REFSOFT_OBJS_ := \ src/client/refresh/files/pcx.o \ src/client/refresh/files/stb.o \ src/client/refresh/files/wal.o \ + src/client/refresh/files/pvs.o \ src/common/shared/shared.o \ src/common/md4.o diff --git a/src/client/refresh/files/pvs.c b/src/client/refresh/files/pvs.c new file mode 100644 index 00000000..843db94f --- /dev/null +++ b/src/client/refresh/files/pvs.c @@ -0,0 +1,76 @@ +/* + * 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. + * + * ======================================================================= + * + * The PVS Decompress + * + * ======================================================================= + */ + +#include "../ref_shared.h" + + +/* +=================== +Mod_DecompressVis +=================== +*/ +byte * +Mod_DecompressVis(byte *in, int row) +{ + static byte decompressed[MAX_MAP_LEAFS / 8]; + int c; + byte *out; + + out = decompressed; + + if (!in) + { + /* no vis info, so make all visible */ + while (row) + { + *out++ = 0xff; + row--; + } + + return decompressed; + } + + do + { + if (*in) + { + *out++ = *in++; + continue; + } + + c = in[1]; + in += 2; + + while (c) + { + *out++ = 0; + c--; + } + } + while (out - decompressed < row); + + return decompressed; +} diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 44b41278..056cdd45 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -84,51 +84,6 @@ Mod_PointInLeaf(vec3_t p, model_t *model) return NULL; /* never reached */ } -byte * -Mod_DecompressVis(byte *in, model_t *model) -{ - static byte decompressed[MAX_MAP_LEAFS / 8]; - int c; - byte *out; - int row; - - row = (model->vis->numclusters + 7) >> 3; - out = decompressed; - - if (!in) - { - /* no vis info, so make all visible */ - while (row) - { - *out++ = 0xff; - row--; - } - - return decompressed; - } - - do - { - if (*in) - { - *out++ = *in++; - continue; - } - - c = in[1]; - in += 2; - - while (c) - { - *out++ = 0; - c--; - } - } - while (out - decompressed < row); - - return decompressed; -} - byte * Mod_ClusterPVS(int cluster, model_t *model) { @@ -139,7 +94,7 @@ Mod_ClusterPVS(int cluster, model_t *model) return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], - model); + (model->vis->numclusters + 7) >> 3); } void diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 4e8723fa..0c88ed9f 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -76,51 +76,6 @@ GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model) return NULL; /* never reached */ } -static byte * -Mod_DecompressVis(byte *in, gl3model_t *model) -{ - static byte decompressed[MAX_MAP_LEAFS / 8]; - int c; - byte *out; - int row; - - row = (model->vis->numclusters + 7) >> 3; - out = decompressed; - - if (!in) - { - /* no vis info, so make all visible */ - while (row) - { - *out++ = 0xff; - row--; - } - - return decompressed; - } - - do - { - if (*in) - { - *out++ = *in++; - continue; - } - - c = in[1]; - in += 2; - - while (c) - { - *out++ = 0; - c--; - } - } - while (out - decompressed < row); - - return decompressed; -} - byte* GL3_Mod_ClusterPVS(int cluster, gl3model_t *model) { @@ -131,7 +86,7 @@ GL3_Mod_ClusterPVS(int cluster, gl3model_t *model) return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], - model); + (model->vis->numclusters + 7) >> 3); } void diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index bd4586a7..4ebb06a4 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -67,4 +67,5 @@ extern qboolean LoadSTB(const char *origname, const char* type, byte **pic, int extern void GetWalInfo(char *name, int *width, int *height); +extern byte* Mod_DecompressVis(byte *in, int row); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/client/refresh/soft/sw_aclip.c b/src/client/refresh/soft/sw_aclip.c index ca59daab..65a4f27a 100644 --- a/src/client/refresh/soft/sw_aclip.c +++ b/src/client/refresh/soft/sw_aclip.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_aclip.c: clip routines for drawing Alias models directly to the screen +// sw_aclip.c: clip routines for drawing Alias models directly to the screen #include "header/local.h" diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index 765608ba..712a3fbb 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_alias.c: routines for setting up to draw alias models +// sw_alias.c: routines for setting up to draw alias models /* ** use a real variable to control lerping diff --git a/src/client/refresh/soft/sw_bsp.c b/src/client/refresh/soft/sw_bsp.c index 84883131..41662245 100644 --- a/src/client/refresh/soft/sw_bsp.c +++ b/src/client/refresh/soft/sw_bsp.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_bsp.c +// sw_bsp.c #include "header/local.h" diff --git a/src/client/refresh/soft/sw_edge.c b/src/client/refresh/soft/sw_edge.c index 3512fcdf..dc6f6cd8 100644 --- a/src/client/refresh/soft/sw_edge.c +++ b/src/client/refresh/soft/sw_edge.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_edge.c +// sw_edge.c #include #include #include "header/local.h" diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index 04efb25f..4ed19685 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_light.c +// sw_light.c #include "header/local.h" diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 8a2989aa..5dd79b77 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_main.c +// sw_main.c #include #ifdef SDL2 @@ -150,7 +150,7 @@ static cvar_t *r_lockpvs; #define STRINGER(x) "x" -// r_vars.c +// sw_vars.c // all global and static refresh variables are collected in a contiguous block // to avoid cache conflicts. diff --git a/src/client/refresh/soft/sw_misc.c b/src/client/refresh/soft/sw_misc.c index d3bc444d..c094b915 100644 --- a/src/client/refresh/soft/sw_misc.c +++ b/src/client/refresh/soft/sw_misc.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_misc.c +// sw_misc.c #ifdef SDL2 #include #else // SDL1.2 diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index de2407ed..2d0b9e1f 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -209,53 +209,6 @@ mleaf_t *Mod_PointInLeaf (vec3_t p, model_t *model) } -/* -=================== -Mod_DecompressVis -=================== -*/ -static byte * -Mod_DecompressVis (byte *in, model_t *model) -{ - static byte decompressed[MAX_MAP_LEAFS/8]; - int c; - byte *out; - int row; - - row = (model->vis->numclusters+7)>>3; - out = decompressed; - - if (!in) - { - // no vis info, so make all visible - while (row) - { - *out++ = 0xff; - row--; - } - return decompressed; - } - - do - { - if (*in) - { - *out++ = *in++; - continue; - } - - c = in[1]; - in += 2; - while (c) - { - *out++ = 0; - c--; - } - } while (out - decompressed < row); - - return decompressed; -} - /* ============== Mod_ClusterPVS @@ -265,8 +218,9 @@ byte *Mod_ClusterPVS (int cluster, model_t *model) { if (cluster == -1 || !model->vis) return mod_novis; - return Mod_DecompressVis ( (byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], - model); + return Mod_DecompressVis ( (byte *)model->vis + + model->vis->bitofs[cluster][DVIS_PVS], + (model->vis->numclusters+7)>>3); } /* diff --git a/src/client/refresh/soft/sw_rast.c b/src/client/refresh/soft/sw_rast.c index ddb1f979..87eb78f7 100644 --- a/src/client/refresh/soft/sw_rast.c +++ b/src/client/refresh/soft/sw_rast.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_rast.c +// sw_rast.c #include #include diff --git a/src/client/refresh/soft/sw_sprite.c b/src/client/refresh/soft/sw_sprite.c index d9f29572..6e034b44 100644 --- a/src/client/refresh/soft/sw_sprite.c +++ b/src/client/refresh/soft/sw_sprite.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_sprite.c +// sw_sprite.c #include "header/local.h" extern polydesc_t r_polydesc; diff --git a/src/client/refresh/soft/sw_surf.c b/src/client/refresh/soft/sw_surf.c index efbb3028..0cf41b8d 100644 --- a/src/client/refresh/soft/sw_surf.c +++ b/src/client/refresh/soft/sw_surf.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// r_surf.c: surface-related refresh code +// sw_surf.c: surface-related refresh code #include "header/local.h" From 6136900facd94be070ab2f0a5d8b0c6a8e2008fd Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 24 Jul 2018 00:16:31 +0300 Subject: [PATCH 07/19] little speedup --- src/client/refresh/soft/sw_alias.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index 712a3fbb..c8d2c5a5 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -235,6 +235,12 @@ R_AliasPreparePoints (void) // put work vertexes on stack, cache aligned pfinalverts = finalverts; + if ((finalverts + s_pmdl->num_xyz) >= finalverts_max) + { + r_outofverts += s_pmdl->num_xyz - (finalverts_max - finalverts); + return; + } + R_AliasTransformFinalVerts( s_pmdl->num_xyz, pfinalverts, // destination for transformed verts r_lastframe->verts, // verts from the last frame @@ -254,11 +260,6 @@ R_AliasPreparePoints (void) pfv[1] = &pfinalverts[ptri->index_xyz[1]]; pfv[2] = &pfinalverts[ptri->index_xyz[2]]; - if ( pfv[0] >= finalverts_max || - pfv[1] >= finalverts_max || - pfv[2] >= finalverts_max ) - continue; // not enough verts - if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags ) continue; // completely clipped @@ -294,11 +295,6 @@ R_AliasPreparePoints (void) pfv[1] = &pfinalverts[ptri->index_xyz[1]]; pfv[2] = &pfinalverts[ptri->index_xyz[2]]; - if ( pfv[0] >= finalverts_max || - pfv[1] >= finalverts_max || - pfv[2] >= finalverts_max ) - continue; // not enough verts - if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags ) continue; // completely clipped @@ -414,11 +410,6 @@ R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, d float lightcos, *plightnormal; vec3_t lerped_vert; - if (fv >= finalverts_max) { - r_outofverts ++; - continue; - } - lerped_vert[0] = r_lerp_move[0] + oldv->v[0]*r_lerp_backv[0] + newv->v[0]*r_lerp_frontv[0]; lerped_vert[1] = r_lerp_move[1] + oldv->v[1]*r_lerp_backv[1] + newv->v[1]*r_lerp_frontv[1]; lerped_vert[2] = r_lerp_move[2] + oldv->v[2]*r_lerp_backv[2] + newv->v[2]*r_lerp_frontv[2]; From a37d6cb07ae399bf9dfcaf557c3943f5a669c48f Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 24 Jul 2018 16:54:43 +0300 Subject: [PATCH 08/19] clean up code --- src/client/refresh/soft/sw_alias.c | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index c8d2c5a5..76aae399 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -221,28 +221,30 @@ R_AliasPreparePoints General clipped case ================ */ -finalvert_t *finalverts, *finalverts_max; static void -R_AliasPreparePoints (void) +R_AliasPreparePoints (finalvert_t *verts, finalvert_t *verts_max) { int i; dstvert_t *pstverts; dtriangle_t *ptri; finalvert_t *pfv[3]; - finalvert_t *pfinalverts; - // put work vertexes on stack, cache aligned - pfinalverts = finalverts; - - if ((finalverts + s_pmdl->num_xyz) >= finalverts_max) + // not fully initialized buffers? + if (!verts) { - r_outofverts += s_pmdl->num_xyz - (finalverts_max - finalverts); + R_Printf(PRINT_ALL, "%s: verts are empty.\n", __func__); + return; + } + + if ((verts + s_pmdl->num_xyz) >= verts_max) + { + r_outofverts += s_pmdl->num_xyz - (verts_max - verts); return; } R_AliasTransformFinalVerts( s_pmdl->num_xyz, - pfinalverts, // destination for transformed verts + verts, // destination for transformed verts r_lastframe->verts, // verts from the last frame r_thisframe->verts // verts from this frame ); @@ -256,9 +258,9 @@ R_AliasPreparePoints (void) { for (i=0 ; inum_tris ; i++, ptri++) { - pfv[0] = &pfinalverts[ptri->index_xyz[0]]; - pfv[1] = &pfinalverts[ptri->index_xyz[1]]; - pfv[2] = &pfinalverts[ptri->index_xyz[2]]; + pfv[0] = &verts[ptri->index_xyz[0]]; + pfv[1] = &verts[ptri->index_xyz[1]]; + pfv[2] = &verts[ptri->index_xyz[2]]; if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags ) continue; // completely clipped @@ -291,9 +293,9 @@ R_AliasPreparePoints (void) { for (i=0 ; inum_tris ; i++, ptri++) { - pfv[0] = &pfinalverts[ptri->index_xyz[0]]; - pfv[1] = &pfinalverts[ptri->index_xyz[1]]; - pfv[2] = &pfinalverts[ptri->index_xyz[2]]; + pfv[0] = &verts[ptri->index_xyz[0]]; + pfv[1] = &verts[ptri->index_xyz[1]]; + pfv[2] = &verts[ptri->index_xyz[2]]; if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags ) continue; // completely clipped @@ -697,6 +699,8 @@ R_AliasSetUpLerpData( dmdl_t *pmdl, float backlerp ) } } +finalvert_t *finalverts, *finalverts_max; + /* ================ R_AliasDrawModel @@ -855,7 +859,7 @@ void R_AliasDrawModel (void) else s_ziscale = (float)0x8000 * (float)SHIFT16XYZ_MULT; - R_AliasPreparePoints (); + R_AliasPreparePoints (finalverts, finalverts_max); if ( currententity->flags & RF_WEAPONMODEL ) { From 25cb7acda8f58b0432baecd5728affad1f971878 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 24 Jul 2018 16:56:42 +0300 Subject: [PATCH 09/19] Restore allocate buffers on render init --- Makefile | 2 +- src/client/refresh/soft/header/local.h | 1 + src/client/refresh/soft/sw_main.c | 144 ++++++++++++++++++------- 3 files changed, 107 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index d8bc7609..b140ae58 100755 --- a/Makefile +++ b/Makefile @@ -173,7 +173,7 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ -Wall -pipe -g -fwrapv CFLAGS += $(OSX_ARCH) else -CFLAGS := -std=gnu99 -O2 -fno-strict-aliasing \ +CFLAGS := -std=gnu99 -fno-strict-aliasing \ -Wall -pipe -g -ggdb -MMD -fwrapv endif diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 85538bea..4f279c7e 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -569,6 +569,7 @@ extern void *colormap; //==================================================================== void R_NewMap (void); +void R_ReallocateMapBuffers (void); void Draw_InitLocal(void); void R_InitCaches(void); void D_FlushCaches(void); diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 5dd79b77..ed808b4a 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -401,55 +401,98 @@ R_NewMap void R_NewMap (void) { r_viewcluster = -1; +} - r_cnumsurfs = sw_maxsurfs->value; +surf_t *lsurfs; - if (r_cnumsurfs <= NUMSTACKSURFACES) - r_cnumsurfs = NUMSTACKSURFACES; - - surfaces = malloc (r_cnumsurfs * sizeof(surf_t)); - if (!surfaces) +/* +=============== +R_ReallocateMapBuffers +=============== +*/ +void +R_ReallocateMapBuffers (void) +{ + if (!r_cnumsurfs) { - R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", - __func__, (int)(r_cnumsurfs * sizeof(surf_t))); - return; + + if(lsurfs) + { + free(lsurfs); + } + + if (r_cnumsurfs < NUMSTACKSURFACES) + r_cnumsurfs = NUMSTACKSURFACES; + + if (r_cnumsurfs < sw_maxsurfs->value) + r_cnumsurfs = sw_maxsurfs->value; + + lsurfs = malloc (r_cnumsurfs * sizeof(surf_t)); + if (!lsurfs) + { + R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", + __func__, (int)(r_cnumsurfs * sizeof(surf_t))); + return; + } + + surface_p = surfaces = lsurfs; + surf_max = &surfaces[r_cnumsurfs]; + // surface 0 doesn't really exist; it's just a dummy because index 0 + // is used to indicate no edge attached to surface + surfaces--; + + R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n", + __func__, r_cnumsurfs); + } - surface_p = surfaces; - surf_max = &surfaces[r_cnumsurfs]; - // surface 0 doesn't really exist; it's just a dummy because index 0 - // is used to indicate no edge attached to surface - surfaces--; - - r_numallocatededges = sw_maxedges->value; - - if (r_numallocatededges < NUMSTACKEDGES) - r_numallocatededges = NUMSTACKEDGES; - - r_edges = malloc (r_numallocatededges * sizeof(edge_t)); - if (!r_edges) + if (!r_numallocatededges) { - R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", - __func__, (int)(r_numallocatededges * sizeof(edge_t))); - return; + if (!r_edges) + { + free(r_edges); + } + + if (r_numallocatededges < NUMSTACKEDGES) + r_numallocatededges = NUMSTACKEDGES; + + if (r_numallocatededges < sw_maxedges->value) + r_numallocatededges = sw_maxedges->value; + + r_edges = malloc (r_numallocatededges * sizeof(edge_t)); + if (!r_edges) + { + R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", + __func__, (int)(r_numallocatededges * sizeof(edge_t))); + return; + } + + R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", + __func__, r_numallocatededges); } - r_numallocatedverts = MAXALIASVERTS; - finalverts = malloc(r_numallocatedverts * sizeof(finalvert_t)); - if (!finalverts) + if (!r_numallocatedverts) { - R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", - __func__, (int)(r_numallocatedverts * sizeof(finalvert_t))); - return; - } - finalverts_max = &finalverts[r_numallocatedverts]; + if (finalverts) + { + free(finalverts); + } - R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", - __func__, r_numallocatededges); - R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n", - __func__, r_cnumsurfs); - R_Printf(PRINT_ALL, "%s: Allocated %d verts\n", - __func__, r_numallocatedverts); + if (r_numallocatedverts < MAXALIASVERTS) + r_numallocatedverts = MAXALIASVERTS; + + finalverts = malloc(r_numallocatedverts * sizeof(finalvert_t)); + if (!finalverts) + { + R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", + __func__, (int)(r_numallocatedverts * sizeof(finalvert_t))); + return; + } + finalverts_max = &finalverts[r_numallocatedverts]; + + R_Printf(PRINT_ALL, "%s: Allocated %d verts\n", + __func__, r_numallocatedverts); + } } @@ -1756,6 +1799,18 @@ static void SWimp_DestroyRender(void) } finalverts = NULL; + if(r_edges) + { + free(r_edges); + } + r_edges = NULL; + + if(lsurfs) + { + free(lsurfs); + } + lsurfs = NULL; + if(r_warpbuffer) { free(r_warpbuffer); @@ -1911,6 +1966,17 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) edge_basespans = malloc((vid.width*2) * sizeof(espan_t)); + // count of "out of items" + r_outofsurfaces = r_outofedges = r_outofverts = 0; + // pointers to allocated buffers + finalverts = NULL; + r_edges = NULL; + lsurfs = NULL; + // curently allocated items + r_cnumsurfs = r_numallocatededges = r_numallocatedverts = 0; + + R_ReallocateMapBuffers(); + r_warpbuffer = malloc(vid.height * vid.width * sizeof(pixel_t)); if ((vid.width >= 2048) && (sizeof(shift20_t) == 4)) // 2k+ resolution and 32 == shift20_t From e1a9e7e4e2937f57df28eb653d0a1a9debf0a77b Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 24 Jul 2018 17:49:14 +0300 Subject: [PATCH 10/19] add auto reallocate --- Makefile | 2 +- src/client/refresh/soft/header/local.h | 5 --- src/client/refresh/soft/sw_main.c | 46 +++++++++++++++++--------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index b140ae58..d8bc7609 100755 --- a/Makefile +++ b/Makefile @@ -173,7 +173,7 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ -Wall -pipe -g -fwrapv CFLAGS += $(OSX_ARCH) else -CFLAGS := -std=gnu99 -fno-strict-aliasing \ +CFLAGS := -std=gnu99 -O2 -fno-strict-aliasing \ -Wall -pipe -g -ggdb -MMD -fwrapv endif diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 4f279c7e..ea47b9f3 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -158,10 +158,6 @@ extern oldrefdef_t r_refdef; #define DS_SPAN_LIST_END -128 -#define NUMSTACKEDGES 3072 -#define NUMSTACKSURFACES 2048 -#define MAXALIASVERTS 2048 // TODO: tune this - // flags in finalvert_t.flags #define ALIAS_LEFT_CLIP 0x0001 #define ALIAS_TOP_CLIP 0x0002 @@ -569,7 +565,6 @@ extern void *colormap; //==================================================================== void R_NewMap (void); -void R_ReallocateMapBuffers (void); void Draw_InitLocal(void); void R_InitCaches(void); void D_FlushCaches(void); diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index ed808b4a..47813c15 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -31,6 +31,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "header/local.h" +#define NUMSTACKEDGES 2048 +#define NUMSTACKSURFACES 1024 +#define MAXALIASVERTS 2048 + viddef_t vid; pixel_t *vid_buffer = NULL; espan_t *vid_polygon_spans = NULL; @@ -403,24 +407,30 @@ void R_NewMap (void) r_viewcluster = -1; } -surf_t *lsurfs; +static surf_t *lsurfs; /* =============== R_ReallocateMapBuffers =============== */ -void +static void R_ReallocateMapBuffers (void) { - if (!r_cnumsurfs) + if (!r_cnumsurfs || r_outofsurfaces) { - if(lsurfs) { free(lsurfs); } + if (r_outofsurfaces) + { + R_Printf(PRINT_ALL, "%s: not enough %d(+%d) surfaces\n", + __func__, r_cnumsurfs, r_outofsurfaces); + r_cnumsurfs *= 2; + } + if (r_cnumsurfs < NUMSTACKSURFACES) r_cnumsurfs = NUMSTACKSURFACES; @@ -446,13 +456,20 @@ R_ReallocateMapBuffers (void) } - if (!r_numallocatededges) + if (!r_numallocatededges || r_outofedges) { if (!r_edges) { free(r_edges); } + if (r_outofedges) + { + R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n", + __func__, r_numallocatededges, r_outofedges * 2 / 3); + r_numallocatededges *= 2; + } + if (r_numallocatededges < NUMSTACKEDGES) r_numallocatededges = NUMSTACKEDGES; @@ -471,13 +488,20 @@ R_ReallocateMapBuffers (void) __func__, r_numallocatededges); } - if (!r_numallocatedverts) + if (!r_numallocatedverts || r_outofverts) { if (finalverts) { free(finalverts); } + if (r_outofverts) + { + R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n", + __func__, r_numallocatedverts, r_outofverts); + r_numallocatedverts *= 2; + } + if (r_numallocatedverts < MAXALIASVERTS) r_numallocatedverts = MAXALIASVERTS; @@ -1118,19 +1142,11 @@ RE_RenderFrame (refdef_t *fd) if (sw_reportsurfout->value && r_outofsurfaces) R_Printf(PRINT_ALL,"Short %d surfaces\n", r_outofsurfaces); - else if (r_outofsurfaces) - R_Printf(PRINT_ALL, "%s: not enough %d(+%d) surfaces\n", - __func__, r_cnumsurfs, r_outofsurfaces); if (sw_reportedgeout->value && r_outofedges) R_Printf(PRINT_ALL,"Short roughly %d edges\n", r_outofedges * 2 / 3); - else if (r_outofedges) - R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n", - __func__, r_numallocatededges, r_outofedges * 2 / 3); - if (r_outofverts) - R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n", - __func__, r_numallocatedverts, r_outofverts); + R_ReallocateMapBuffers(); } /* From 125d6db8b60c3c34ae36f13757054539930f0065 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 24 Jul 2018 23:38:31 +0300 Subject: [PATCH 11/19] code clean up --- src/client/refresh/soft/sw_alias.c | 7 ------- src/client/refresh/soft/sw_edge.c | 10 ++++++---- src/client/refresh/soft/sw_light.c | 3 --- src/client/refresh/soft/sw_main.c | 15 ++++++++------- src/client/refresh/soft/sw_poly.c | 3 ++- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index 76aae399..2dba56f4 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -230,13 +230,6 @@ R_AliasPreparePoints (finalvert_t *verts, finalvert_t *verts_max) dtriangle_t *ptri; finalvert_t *pfv[3]; - // not fully initialized buffers? - if (!verts) - { - R_Printf(PRINT_ALL, "%s: verts are empty.\n", __func__); - return; - } - if ((verts + s_pmdl->num_xyz) >= verts_max) { r_outofverts += s_pmdl->num_xyz - (verts_max - verts); diff --git a/src/client/refresh/soft/sw_edge.c b/src/client/refresh/soft/sw_edge.c index dc6f6cd8..32652fcf 100644 --- a/src/client/refresh/soft/sw_edge.c +++ b/src/client/refresh/soft/sw_edge.c @@ -197,7 +197,7 @@ R_StepActiveU (edge_t *pedge) // find out where the edge goes in the edge list pwedge = pedge->prev->prev; - while (pwedge && (pwedge->u > pedge->u)) + while (pwedge->u > pedge->u) { pwedge = pwedge->prev; } @@ -297,8 +297,6 @@ R_LeadingEdgeBackwards (edge_t *edge) // end edge) if (++surf->spanstate == 1) { - shift20_t iu; - surf2 = surfaces[1].next; // if it's two surfaces on the same plane, the one that's already @@ -306,6 +304,8 @@ R_LeadingEdgeBackwards (edge_t *edge) // must be two bmodels in the same leaf; don't care, because they'll // never be farthest anyway if (surf->key > surf2->key || (surf->insubmodel && (surf->key == surf2->key))) { + shift20_t iu; + // emit a span (obscures current top) iu = edge->u >> shift_size; @@ -407,10 +407,12 @@ R_LeadingEdgeSearch static surf_t* R_LeadingEdgeSearch (edge_t *edge, surf_t *surf, surf_t *surf2) { - float fu, newzi, testzi, newzitop, newzibottom; + float testzi, newzitop; do { + float fu, newzi, newzibottom; + surf2 = D_SurfSearchForward(surf, surf2); if (surf->key != surf2->key) diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index 4ed19685..e3bdc9f1 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -160,9 +160,6 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end) if (r >= 0) return r; // hit something - if ((back < 0) == side) - return -1; // didn't hit anything - // check for impact on this node VectorCopy (mid, lightspot); diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 47813c15..2fc83065 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -426,8 +426,8 @@ R_ReallocateMapBuffers (void) if (r_outofsurfaces) { - R_Printf(PRINT_ALL, "%s: not enough %d(+%d) surfaces\n", - __func__, r_cnumsurfs, r_outofsurfaces); + //R_Printf(PRINT_ALL, "%s: not enough %d(+%d) surfaces\n", + // __func__, r_cnumsurfs, r_outofsurfaces); r_cnumsurfs *= 2; } @@ -465,8 +465,8 @@ R_ReallocateMapBuffers (void) if (r_outofedges) { - R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n", - __func__, r_numallocatededges, r_outofedges * 2 / 3); + //R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n", + // __func__, r_numallocatededges, r_outofedges * 2 / 3); r_numallocatededges *= 2; } @@ -497,8 +497,8 @@ R_ReallocateMapBuffers (void) if (r_outofverts) { - R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n", - __func__, r_numallocatedverts, r_outofverts); + //R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n", + // __func__, r_numallocatedverts, r_outofverts); r_numallocatedverts *= 2; } @@ -1269,7 +1269,6 @@ static void RE_SetPalette(const unsigned char *palette) { byte palette32[1024]; - int i; // clear screen to black to avoid any palette flash memset(vid_buffer, 0, vid.height * vid.width * sizeof(pixel_t)); @@ -1279,6 +1278,8 @@ RE_SetPalette(const unsigned char *palette) if (palette) { + int i; + for ( i = 0; i < 256; i++ ) { palette32[i*4+0] = palette[i*3+0]; diff --git a/src/client/refresh/soft/sw_poly.c b/src/client/refresh/soft/sw_poly.c index 45b85eee..3a4d661e 100644 --- a/src/client/refresh/soft/sw_poly.c +++ b/src/client/refresh/soft/sw_poly.c @@ -595,7 +595,6 @@ R_ClipPolyFace (int nump, clipplane_t *pclipplane) static void R_PolygonDrawSpans(espan_t *pspan, int iswater ) { - int count; int snext, tnext; float sdivz, tdivz, zi, z, du, dv, spancountminus1; float sdivzspanletstepu, tdivzspanletstepu, zispanletstepu; @@ -621,6 +620,8 @@ R_PolygonDrawSpans(espan_t *pspan, int iswater ) do { + int count; + s_spanletvars.pdest = d_viewbuffer + (r_screenwidth * pspan->v) + pspan->u; s_spanletvars.pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; s_spanletvars.u = pspan->u; From fcae2fcbcd40959d0a98b7857dbcfacf498c2273 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Wed, 25 Jul 2018 15:16:32 +0300 Subject: [PATCH 12/19] change messages --- src/client/refresh/soft/sw_main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 2fc83065..ad03aefc 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -451,9 +451,7 @@ R_ReallocateMapBuffers (void) // is used to indicate no edge attached to surface surfaces--; - R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n", - __func__, r_cnumsurfs); - + R_Printf(PRINT_ALL, "Allocated %d surfaces\n", r_cnumsurfs); } if (!r_numallocatededges || r_outofedges) @@ -484,8 +482,7 @@ R_ReallocateMapBuffers (void) return; } - R_Printf(PRINT_ALL, "%s: Allocated %d edges\n", - __func__, r_numallocatededges); + R_Printf(PRINT_ALL, "Allocated %d edges\n", r_numallocatededges); } if (!r_numallocatedverts || r_outofverts) @@ -514,8 +511,7 @@ R_ReallocateMapBuffers (void) } finalverts_max = &finalverts[r_numallocatedverts]; - R_Printf(PRINT_ALL, "%s: Allocated %d verts\n", - __func__, r_numallocatedverts); + R_Printf(PRINT_ALL, "Allocated %d verts\n", r_numallocatedverts); } } From aec8f3fc8bb89e87c792935d3357c1edb0782a76 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Wed, 25 Jul 2018 17:06:23 +0300 Subject: [PATCH 13/19] make r_dlightframecount and surfrowbytes local --- src/client/refresh/soft/header/local.h | 1 - src/client/refresh/soft/sw_aclip.c | 7 +------ src/client/refresh/soft/sw_light.c | 17 +++++++--------- src/client/refresh/soft/sw_main.c | 1 - src/client/refresh/soft/sw_surf.c | 28 +++++++++++++++----------- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index ea47b9f3..0fddb86b 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -545,7 +545,6 @@ extern float se_time1, se_time2, de_time1, de_time2, dv_time1, dv_time2; extern int r_viewcluster, r_oldviewcluster; extern int r_clipflags; -extern int r_dlightframecount; extern image_t *r_notexture_mip; extern model_t *r_worldmodel; diff --git a/src/client/refresh/soft/sw_aclip.c b/src/client/refresh/soft/sw_aclip.c index 65a4f27a..afdaae05 100644 --- a/src/client/refresh/soft/sw_aclip.c +++ b/src/client/refresh/soft/sw_aclip.c @@ -21,13 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "header/local.h" -static finalvert_t fv[2][8]; - void R_AliasProjectAndClipTestFinalVert (finalvert_t *fv); -static void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out); -static void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out); -static void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out); -static void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out); /* ================ @@ -226,6 +220,7 @@ void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t { int i, k, pingpong; unsigned clipflags; + finalvert_t fv[2][8]; // copy vertexes and fix seam texture coordinates fv[0][0] = *index0; diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index e3bdc9f1..052ec7f9 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -21,9 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "header/local.h" -int r_dlightframecount; - - /* ============================================================================= @@ -38,7 +35,7 @@ R_MarkLights ============= */ static void -R_MarkLights (dlight_t *light, int bit, mnode_t *node) +R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount) { mplane_t *splitplane; float dist; @@ -61,12 +58,12 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node) if (dist > i) // PGM (dist > light->intensity) { - R_MarkLights (light, bit, node->children[0]); + R_MarkLights (light, bit, node->children[0], r_dlightframecount); return; } if (dist < -i) // PGM (dist < -light->intensity) { - R_MarkLights (light, bit, node->children[1]); + R_MarkLights (light, bit, node->children[1], r_dlightframecount); return; } @@ -82,8 +79,8 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node) surf->dlightbits |= bit; } - R_MarkLights (light, bit, node->children[0]); - R_MarkLights (light, bit, node->children[1]); + R_MarkLights (light, bit, node->children[0], r_dlightframecount); + R_MarkLights (light, bit, node->children[1], r_dlightframecount); } @@ -97,11 +94,11 @@ void R_PushDlights (model_t *model) int i; dlight_t *l; - r_dlightframecount = r_framecount; for (i=0, l = r_newrefdef.dlights ; inodes + model->firstnode); + model->nodes + model->firstnode, + r_framecount); } } diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index ad03aefc..2c1c0da3 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -866,7 +866,6 @@ R_DrawBEntitiesOnList (void) VectorCopy (modelorg, oldorigin); insubmodel = true; - r_dlightframecount = r_framecount; for (i=0 ; ipixels[r_drawsurf.surfmip]; @@ -134,7 +133,7 @@ static void R_DrawSurface (void) pbasesource = basetptr + soffset; - R_DrawSurfaceBlock8_anymip(NUM_MIPS - r_drawsurf.surfmip); + R_DrawSurfaceBlock8_anymip(NUM_MIPS - r_drawsurf.surfmip, r_drawsurf.rowbytes); soffset = soffset + blocksize; if (soffset >= smax) @@ -152,7 +151,8 @@ static void R_DrawSurface (void) R_DrawSurfaceBlock8_anymip ================ */ -static void R_DrawSurfaceBlock8_anymip (int level) +static void +R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes) { int v, i, b, lightstep, lighttemp, light, size; unsigned char pix, *psource, *prowdest; @@ -206,7 +206,8 @@ R_InitCaches ================ */ -void R_InitCaches (void) +void +R_InitCaches (void) { int size; @@ -245,7 +246,8 @@ void R_InitCaches (void) D_FlushCaches ================== */ -void D_FlushCaches (void) +void +D_FlushCaches (void) { surfcache_t *c; @@ -269,7 +271,8 @@ void D_FlushCaches (void) D_SCAlloc ================= */ -static surfcache_t *D_SCAlloc (int width, int size) +static surfcache_t * +D_SCAlloc (int width, int size) { surfcache_t *new; @@ -340,7 +343,8 @@ static surfcache_t *D_SCAlloc (int width, int size) D_CacheSurface ================ */ -surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) +surfcache_t * +D_CacheSurface (msurface_t *surface, int miplevel) { surfcache_t *cache; From 2b9b039139aab4393aeaeeb9f6d77fbcf46f5cc7 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Wed, 25 Jul 2018 17:49:00 +0300 Subject: [PATCH 14/19] make r_drawsurf local --- src/client/refresh/soft/header/local.h | 2 -- src/client/refresh/soft/sw_light.c | 13 ++++---- src/client/refresh/soft/sw_surf.c | 45 +++++++++++++------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 0fddb86b..13844890 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -352,8 +352,6 @@ void R_PolysetUpdateTables(void); // callbacks to Quake -extern drawsurf_t r_drawsurf; - extern int c_surf; extern pixel_t *r_warpbuffer; diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index 052ec7f9..cf3c5042 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -275,7 +275,7 @@ R_AddDynamicLights =============== */ static void -R_AddDynamicLights (void) +R_AddDynamicLights (drawsurf_t* drawsurf) { msurface_t *surf; int lnum; @@ -289,7 +289,7 @@ R_AddDynamicLights (void) dlight_t *dl; int negativeLight; //PGM - surf = r_drawsurf.surf; + surf = drawsurf->surf; smax = (surf->extents[0]>>4)+1; tmax = (surf->extents[1]>>4)+1; tex = surf->texinfo; @@ -376,14 +376,15 @@ R_BuildLightMap Combine and scale multiple lightmaps into the 8.8 format in blocklights =============== */ -void R_BuildLightMap (void) +void +R_BuildLightMap (drawsurf_t* drawsurf) { int smax, tmax; int i, size; byte *lightmap; msurface_t *surf; - surf = r_drawsurf.surf; + surf = drawsurf->surf; smax = (surf->extents[0]>>4)+1; tmax = (surf->extents[1]>>4)+1; @@ -412,7 +413,7 @@ void R_BuildLightMap (void) { unsigned scale; - scale = r_drawsurf.lightadj[maps]; // 8.8 fraction + scale = drawsurf->lightadj[maps]; // 8.8 fraction for (i=0 ; idlightframe == r_framecount) - R_AddDynamicLights (); + R_AddDynamicLights (drawsurf); // bound, invert, and shift for (i=0 ; iimage; - r_source = mt->pixels[r_drawsurf.surfmip]; + r_source = mt->pixels[drawsurf->surfmip]; // the fractional light values should range from 0 to (VID_GRADES - 1) << 16 // from a source range of 0 - 255 - texwidth = mt->width >> r_drawsurf.surfmip; + texwidth = mt->width >> drawsurf->surfmip; - blocksize = 16 >> r_drawsurf.surfmip; - blockdivshift = NUM_MIPS - r_drawsurf.surfmip; + blocksize = 16 >> drawsurf->surfmip; + blockdivshift = NUM_MIPS - drawsurf->surfmip; - r_lightwidth = (r_drawsurf.surf->extents[0]>>4)+1; + r_lightwidth = (drawsurf->surf->extents[0]>>4)+1; - r_numhblocks = r_drawsurf.surfwidth >> blockdivshift; - r_numvblocks = r_drawsurf.surfheight >> blockdivshift; + r_numhblocks = drawsurf->surfwidth >> blockdivshift; + r_numvblocks = drawsurf->surfheight >> blockdivshift; //============================== // TODO: only needs to be set when there is a display settings change horzblockstep = blocksize; - smax = mt->width >> r_drawsurf.surfmip; + smax = mt->width >> drawsurf->surfmip; twidth = texwidth; - tmax = mt->height >> r_drawsurf.surfmip; + tmax = mt->height >> drawsurf->surfmip; sourcetstep = texwidth; r_stepback = tmax * twidth; r_sourcemax = r_source + (tmax * smax); - soffset = r_drawsurf.surf->texturemins[0]; - basetoffset = r_drawsurf.surf->texturemins[1]; + soffset = drawsurf->surf->texturemins[0]; + basetoffset = drawsurf->surf->texturemins[1]; // << 16 components are to guarantee positive values for % - soffset = ((soffset >> r_drawsurf.surfmip) + (smax << SHIFT16XYZ)) % smax; - basetptr = &r_source[((((basetoffset >> r_drawsurf.surfmip) + soffset = ((soffset >> drawsurf->surfmip) + (smax << SHIFT16XYZ)) % smax; + basetptr = &r_source[((((basetoffset >> drawsurf->surfmip) + (tmax << SHIFT16XYZ)) % tmax) * twidth)]; - pcolumndest = r_drawsurf.surfdat; + pcolumndest = drawsurf->surfdat; for (u=0 ; usurfmip, drawsurf->rowbytes); soffset = soffset + blocksize; if (soffset >= smax) @@ -338,6 +337,8 @@ D_SCAlloc (int width, int size) //============================================================================= +static drawsurf_t r_drawsurf; + /* ================ D_CacheSurface @@ -346,7 +347,7 @@ D_CacheSurface surfcache_t * D_CacheSurface (msurface_t *surface, int miplevel) { - surfcache_t *cache; + surfcache_t *cache; // // if the surface is animating or flashing, flush the cache @@ -412,10 +413,10 @@ D_CacheSurface (msurface_t *surface, int miplevel) c_surf++; // calculate the lightings - R_BuildLightMap (); + R_BuildLightMap (&r_drawsurf); // rasterize the surface into the cache - R_DrawSurface (); + R_DrawSurface (&r_drawsurf); return cache; } From bec4c4acccb05d2f2928f457cd8f181b89250313 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Wed, 25 Jul 2018 21:33:10 +0300 Subject: [PATCH 15/19] change code style --- src/client/refresh/soft/header/local.h | 2 +- src/client/refresh/soft/sw_aclip.c | 6 +- src/client/refresh/soft/sw_alias.c | 11 ++-- src/client/refresh/soft/sw_bsp.c | 6 +- src/client/refresh/soft/sw_draw.c | 33 ++++++---- src/client/refresh/soft/sw_edge.c | 37 +++++------ src/client/refresh/soft/sw_image.c | 21 +++--- src/client/refresh/soft/sw_light.c | 6 +- src/client/refresh/soft/sw_main.c | 28 ++++++-- src/client/refresh/soft/sw_misc.c | 18 +++-- src/client/refresh/soft/sw_model.c | 30 ++++++--- src/client/refresh/soft/sw_part.c | 29 +++----- src/client/refresh/soft/sw_poly.c | 12 ++-- src/client/refresh/soft/sw_polyse.c | 91 ++++++++++++++------------ src/client/refresh/soft/sw_rast.c | 12 +++- src/client/refresh/soft/sw_scan.c | 18 +++-- src/client/refresh/soft/sw_sprite.c | 3 +- 17 files changed, 213 insertions(+), 150 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 13844890..fd4cce1d 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -477,7 +477,7 @@ void R_DrawSolidClippedSubmodelPolygons(model_t *pmodel, mnode_t *topnode); void R_AliasDrawModel(void); void R_BeginEdgeFrame(void); -void R_ScanEdges(void); +void R_ScanEdges(surf_t *surface); void R_PushDlights(model_t *model); extern void R_RotateBmodel (void); diff --git a/src/client/refresh/soft/sw_aclip.c b/src/client/refresh/soft/sw_aclip.c index afdaae05..38d08fec 100644 --- a/src/client/refresh/soft/sw_aclip.c +++ b/src/client/refresh/soft/sw_aclip.c @@ -170,7 +170,8 @@ R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1, } -int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count, +int +R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count, void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) ) { int i,j,k; @@ -216,7 +217,8 @@ int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count, R_AliasClipTriangle ================ */ -void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2) +void +R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2) { int i, k, pingpong; unsigned clipflags; diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index 2dba56f4..2b033020 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -457,7 +457,8 @@ R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, d R_AliasProjectAndClipTestFinalVert ================ */ -void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ) +void +R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ) { float zi; float x, y, z; @@ -488,7 +489,8 @@ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ) R_AliasSetupSkin =============== */ -static qboolean R_AliasSetupSkin (void) +static qboolean +R_AliasSetupSkin (void) { image_t *pskindesc; @@ -692,14 +694,15 @@ R_AliasSetUpLerpData( dmdl_t *pmdl, float backlerp ) } } -finalvert_t *finalverts, *finalverts_max; +finalvert_t *finalverts = NULL, *finalverts_max = NULL; /* ================ R_AliasDrawModel ================ */ -void R_AliasDrawModel (void) +void +R_AliasDrawModel (void) { extern void (*d_pdrawspans)(void *); extern void R_PolysetDrawSpans8_Opaque( void * ); diff --git a/src/client/refresh/soft/sw_bsp.c b/src/client/refresh/soft/sw_bsp.c index 41662245..172d689f 100644 --- a/src/client/refresh/soft/sw_bsp.c +++ b/src/client/refresh/soft/sw_bsp.c @@ -74,7 +74,8 @@ R_EntityRotate (vec3_t vec) R_RotateBmodel ================ */ -void R_RotateBmodel (void) +void +R_RotateBmodel (void) { float angle, s, c, temp1[3][3], temp2[3][3], temp3[3][3]; @@ -624,7 +625,8 @@ R_RecursiveWorldNode (mnode_t *node, int clipflags) R_RenderWorld ================ */ -void R_RenderWorld (void) +void +R_RenderWorld (void) { if (!r_drawworld->value) diff --git a/src/client/refresh/soft/sw_draw.c b/src/client/refresh/soft/sw_draw.c index 63255bae..bfc22332 100644 --- a/src/client/refresh/soft/sw_draw.c +++ b/src/client/refresh/soft/sw_draw.c @@ -32,7 +32,8 @@ static image_t *draw_chars; // 8*8 graphic characters RE_Draw_FindPic ================ */ -image_t *RE_Draw_FindPic (char *name) +image_t * +RE_Draw_FindPic (char *name) { image_t *image; @@ -56,7 +57,8 @@ image_t *RE_Draw_FindPic (char *name) Draw_InitLocal =============== */ -void Draw_InitLocal (void) +void +Draw_InitLocal (void) { draw_chars = RE_Draw_FindPic ("conchars"); if (!draw_chars) @@ -76,7 +78,8 @@ It can be clipped to the top of the screen to allow the console to be smoothly scrolled off. ================ */ -void RE_Draw_CharScaled(int x, int y, int num, float scale) +void +RE_Draw_CharScaled(int x, int y, int num, float scale) { pixel_t *dest; byte *source; @@ -134,7 +137,8 @@ void RE_Draw_CharScaled(int x, int y, int num, float scale) RE_Draw_GetPicSize ============= */ -void RE_Draw_GetPicSize (int *w, int *h, char *pic) +void +RE_Draw_GetPicSize (int *w, int *h, char *pic) { image_t *gl; @@ -153,7 +157,8 @@ void RE_Draw_GetPicSize (int *w, int *h, char *pic) RE_Draw_StretchPicImplementation ============= */ -void RE_Draw_StretchPicImplementation (int x, int y, int w, int h, image_t *pic) +void +RE_Draw_StretchPicImplementation (int x, int y, int w, int h, image_t *pic) { pixel_t *dest; byte *source; @@ -205,7 +210,8 @@ void RE_Draw_StretchPicImplementation (int x, int y, int w, int h, image_t *pic) RE_Draw_StretchPic ============= */ -void RE_Draw_StretchPic (int x, int y, int w, int h, char *name) +void +RE_Draw_StretchPic (int x, int y, int w, int h, char *name) { image_t *pic; @@ -223,7 +229,8 @@ void RE_Draw_StretchPic (int x, int y, int w, int h, char *name) RE_Draw_StretchRaw ============= */ -void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data) +void +RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data) { image_t pic; @@ -238,7 +245,8 @@ void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *d Draw_Pic ============= */ -void RE_Draw_PicScaled(int x, int y, char *name, float scale) +void +RE_Draw_PicScaled(int x, int y, char *name, float scale) { image_t *pic; pixel_t *dest; @@ -320,7 +328,8 @@ This repeats a 64*64 tile graphic to fill the screen around a sized down refresh window. ============= */ -void RE_Draw_TileClear (int x, int y, int w, int h, char *name) +void +RE_Draw_TileClear (int x, int y, int w, int h, char *name) { int i, j; byte *psrc; @@ -369,7 +378,8 @@ RE_Draw_Fill Fills a box of pixels with a single color ============= */ -void RE_Draw_Fill (int x, int y, int w, int h, int c) +void +RE_Draw_Fill (int x, int y, int w, int h, int c) { pixel_t *dest; int u, v; @@ -406,7 +416,8 @@ RE_Draw_FadeScreen ================ */ -void RE_Draw_FadeScreen (void) +void +RE_Draw_FadeScreen (void) { int x,y; diff --git a/src/client/refresh/soft/sw_edge.c b/src/client/refresh/soft/sw_edge.c index 32652fcf..af173d86 100644 --- a/src/client/refresh/soft/sw_edge.c +++ b/src/client/refresh/soft/sw_edge.c @@ -29,11 +29,6 @@ low depth complexity -- 1 to 3 or so have a sentinal at both ends? */ - -edge_t *r_edges, *edge_p, *edge_max; - -surf_t *surfaces, *surface_p, *surf_max; - // surfaces are generated in back to front order by the bsp, so if a surf // pointer is greater than another one, it should be drawn in front // surfaces[1] is the background, and is used as the active surface stack @@ -84,13 +79,9 @@ EDGE SCANNING R_BeginEdgeFrame ============== */ -void R_BeginEdgeFrame (void) +void +R_BeginEdgeFrame (void) { - edge_p = r_edges; - edge_max = &r_edges[r_numallocatededges]; - - surface_p = &surfaces[2]; // background is surface 1, - // surface 0 is a dummy surfaces[1].spans = NULL; // no background spans yet surfaces[1].flags = SURF_DRAWBACKGROUND; @@ -154,7 +145,8 @@ R_InsertNewEdges (edge_t *edgestoadd, edge_t *edgelist) R_RemoveEdges ============== */ -static void R_RemoveEdges (edge_t *pedge) +static void +R_RemoveEdges (edge_t *pedge) { do @@ -586,7 +578,7 @@ R_GenerateSpansBackward (void) R_CleanupSpan (); } -static void D_DrawSurfaces (void); +static void D_DrawSurfaces (surf_t *surface); /* ============== @@ -601,7 +593,8 @@ Each surface has a linked list of its visible spans ============== */ -void R_ScanEdges (void) +void +R_ScanEdges (surf_t *surface) { shift20_t iv, bottom; espan_t *basespan_p; @@ -671,10 +664,10 @@ void R_ScanEdges (void) if (span_p > max_span_p) { // Draw stuff on screen - D_DrawSurfaces (); + D_DrawSurfaces (surface); // clear the surface span pointers - for (s = &surfaces[1] ; sspans = NULL; span_p = basespan_p; @@ -703,7 +696,7 @@ void R_ScanEdges (void) (*pdrawfunc) (); // draw whatever's left in the span list - D_DrawSurfaces (); + D_DrawSurfaces (surface); } @@ -1015,12 +1008,12 @@ To allow developers to see the polygon carving of the world ============= */ static void -D_DrawflatSurfaces (void) +D_DrawflatSurfaces (surf_t *surface) { surf_t *s; int color = 0; - for (s = &surfaces[1] ; sspans) continue; @@ -1047,7 +1040,7 @@ May be called more than once a frame if the surf list overflows (higher res) ============== */ static void -D_DrawSurfaces (void) +D_DrawSurfaces (surf_t *surface) { // currententity = NULL; // &r_worldentity; @@ -1059,7 +1052,7 @@ D_DrawSurfaces (void) { surf_t *s; - for (s = &surfaces[1] ; sspans) continue; @@ -1077,7 +1070,7 @@ D_DrawSurfaces (void) } } else - D_DrawflatSurfaces (); + D_DrawflatSurfaces (surface); currententity = NULL; //&r_worldentity; VectorSubtract (r_origin, vec3_origin, modelorg); diff --git a/src/client/refresh/soft/sw_image.c b/src/client/refresh/soft/sw_image.c index 00c726bf..c3e792e1 100644 --- a/src/client/refresh/soft/sw_image.c +++ b/src/client/refresh/soft/sw_image.c @@ -31,7 +31,8 @@ static int numr_images; R_ImageList_f =============== */ -void R_ImageList_f (void) +void +R_ImageList_f (void) { int i; image_t *image; @@ -72,8 +73,8 @@ void R_ImageList_f (void) //======================================================= -static image_t -*R_FindFreeImage (void) +static image_t * +R_FindFreeImage (void) { image_t *image; int i; @@ -101,7 +102,7 @@ R_LoadPic ================ */ -static image_t* +static image_t * R_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type) { image_t *image; @@ -221,7 +222,8 @@ R_FindImage Finds or loads the given image =============== */ -image_t *R_FindImage (char *name, imagetype_t type) +image_t * +R_FindImage (char *name, imagetype_t type) { image_t *image; int i, len; @@ -290,7 +292,8 @@ Any image that was not touched on this registration sequence will be freed. ================ */ -void R_FreeUnusedImages (void) +void +R_FreeUnusedImages (void) { int i; image_t *image; @@ -318,7 +321,8 @@ void R_FreeUnusedImages (void) R_InitImages =============== */ -void R_InitImages (void) +void +R_InitImages (void) { registration_sequence = 1; } @@ -328,7 +332,8 @@ void R_InitImages (void) R_ShutdownImages =============== */ -void R_ShutdownImages (void) +void +R_ShutdownImages (void) { int i; image_t *image; diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index cf3c5042..9e11fc58 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -89,7 +89,8 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount) R_PushDlights ============= */ -void R_PushDlights (model_t *model) +void +R_PushDlights (model_t *model) { int i; dlight_t *l; @@ -215,7 +216,8 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end) R_LightPoint =============== */ -void R_LightPoint (vec3_t p, vec3_t color) +void +R_LightPoint (vec3_t p, vec3_t color) { vec3_t end; float r; diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 2c1c0da3..42b85be3 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -402,7 +402,8 @@ RE_Shutdown (void) R_NewMap =============== */ -void R_NewMap (void) +void +R_NewMap (void) { r_viewcluster = -1; } @@ -445,8 +446,10 @@ R_ReallocateMapBuffers (void) return; } - surface_p = surfaces = lsurfs; + surfaces = lsurfs; + // set limits surf_max = &surfaces[r_cnumsurfs]; + surface_p = lsurfs; // surface 0 doesn't really exist; it's just a dummy because index 0 // is used to indicate no edge attached to surface surfaces--; @@ -482,6 +485,10 @@ R_ReallocateMapBuffers (void) return; } + // set limits + edge_max = &r_edges[r_numallocatededges]; + edge_p = r_edges; + R_Printf(PRINT_ALL, "Allocated %d edges\n", r_numallocatededges); } @@ -946,6 +953,9 @@ R_EdgeDrawing (void) // Set function pointer pdrawfunc used later in this function R_BeginEdgeFrame (); + edge_p = r_edges; + surface_p = &surfaces[2]; // background is surface 1, + // surface 0 is a dummy if (r_dspeeds->value) { @@ -972,7 +982,7 @@ R_EdgeDrawing (void) // Use the Global Edge Table to maintin the Active Edge Table: Draw the world as scanlines // Write the Z-Buffer (but no read) - R_ScanEdges (); + R_ScanEdges (surface_p); } //======================================================================= @@ -1702,7 +1712,8 @@ R_InitContext(void* win) return true; } -static qboolean CreateSDLWindow(int flags, int w, int h) +static qboolean +CreateSDLWindow(int flags, int w, int h) { #if SDL_VERSION_ATLEAST(2, 0, 0) Uint32 Rmask, Gmask, Bmask, Amask; @@ -1737,7 +1748,8 @@ static qboolean CreateSDLWindow(int flags, int w, int h) #endif } -static void SWimp_DestroyRender(void) +static void +SWimp_DestroyRender(void) { if (vid_buffer) { @@ -2122,7 +2134,8 @@ SWimp_Shutdown( void ) } // this is only here so the functions in q_shared.c and q_shwin.c can link -void Sys_Error (char *error, ...) +void +Sys_Error (char *error, ...) { va_list argptr; char text[1024]; @@ -2134,7 +2147,8 @@ void Sys_Error (char *error, ...) ri.Sys_Error (ERR_FATAL, "%s", text); } -void Com_Printf (char *fmt, ...) +void +Com_Printf (char *fmt, ...) { va_list argptr; char text[1024]; diff --git a/src/client/refresh/soft/sw_misc.c b/src/client/refresh/soft/sw_misc.c index c094b915..3f82065b 100644 --- a/src/client/refresh/soft/sw_misc.c +++ b/src/client/refresh/soft/sw_misc.c @@ -87,7 +87,8 @@ D_ViewChanged (void) R_PrintTimes ============= */ -void R_PrintTimes (void) +void +R_PrintTimes (void) { int r_time2; int ms; @@ -107,7 +108,8 @@ void R_PrintTimes (void) R_PrintDSpeeds ============= */ -void R_PrintDSpeeds (void) +void +R_PrintDSpeeds (void) { int ms, dp_time, r_time2, rw_time, db_time, se_time, de_time, da_time; @@ -131,7 +133,8 @@ void R_PrintDSpeeds (void) R_PrintAliasStats ============= */ -void R_PrintAliasStats (void) +void +R_PrintAliasStats (void) { R_Printf(PRINT_ALL,"%3i polygon model drawn\n", r_amodels_drawn); } @@ -143,7 +146,8 @@ void R_PrintAliasStats (void) R_TransformFrustum =================== */ -void R_TransformFrustum (void) +void +R_TransformFrustum (void) { int i; vec3_t v, v2; @@ -170,7 +174,8 @@ void R_TransformFrustum (void) TransformVector ================ */ -void TransformVector (vec3_t in, vec3_t out) +void +TransformVector (vec3_t in, vec3_t out) { out[0] = DotProduct(in,vright); out[1] = DotProduct(in,vup); @@ -316,7 +321,8 @@ R_ViewChanged (vrect_t *vr) R_SetupFrame =============== */ -void R_SetupFrame (void) +void +R_SetupFrame (void) { int i; vrect_t vrect; diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 2d0b9e1f..b3a798ae 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -50,7 +50,8 @@ static int modfilelen; Mod_Modellist_f ================ */ -void Mod_Modellist_f (void) +void +Mod_Modellist_f (void) { int i; model_t *mod; @@ -73,7 +74,8 @@ void Mod_Modellist_f (void) Mod_Init =============== */ -void Mod_Init (void) +void +Mod_Init (void) { memset (mod_novis, 0xff, sizeof(mod_novis)); } @@ -184,7 +186,8 @@ Mod_ForName (char *name, qboolean crash) Mod_PointInLeaf =============== */ -mleaf_t *Mod_PointInLeaf (vec3_t p, model_t *model) +mleaf_t * +Mod_PointInLeaf (vec3_t p, model_t *model) { mnode_t *node; @@ -214,7 +217,8 @@ mleaf_t *Mod_PointInLeaf (vec3_t p, model_t *model) Mod_ClusterPVS ============== */ -byte *Mod_ClusterPVS (int cluster, model_t *model) +byte * +Mod_ClusterPVS (int cluster, model_t *model) { if (cluster == -1 || !model->vis) return mod_novis; @@ -272,7 +276,8 @@ static int r_leaftovis[MAX_MAP_LEAFS]; static int r_vistoleaf[MAX_MAP_LEAFS]; static int r_numvisleafs; -void R_NumberLeafs (mnode_t *node) +void +R_NumberLeafs (mnode_t *node) { if (node->contents != -1) { @@ -1108,7 +1113,8 @@ RE_BeginRegistration Specifies the model that will be used as the world ===================== */ -void RE_BeginRegistration (char *model) +void +RE_BeginRegistration (char *model) { char fullname[MAX_QPATH]; cvar_t *flushmap; @@ -1134,7 +1140,8 @@ RE_RegisterModel ===================== */ -struct model_s *RE_RegisterModel (char *name) +struct model_s * +RE_RegisterModel (char *name) { model_t *mod; @@ -1180,7 +1187,8 @@ RE_EndRegistration ===================== */ -void RE_EndRegistration (void) +void +RE_EndRegistration (void) { int i; model_t *mod; @@ -1207,7 +1215,8 @@ void RE_EndRegistration (void) Mod_Free ================ */ -void Mod_Free (model_t *mod) +void +Mod_Free (model_t *mod) { Hunk_Free (mod->extradata); memset (mod, 0, sizeof(*mod)); @@ -1218,7 +1227,8 @@ void Mod_Free (model_t *mod) Mod_FreeAll ================ */ -void Mod_FreeAll (void) +void +Mod_FreeAll (void) { int i; diff --git a/src/client/refresh/soft/sw_part.c b/src/client/refresh/soft/sw_part.c index b230a7e1..c974354b 100644 --- a/src/client/refresh/soft/sw_part.c +++ b/src/client/refresh/soft/sw_part.c @@ -26,13 +26,6 @@ extern cvar_t *sw_custom_particles; #define PARTICLE_66 1 #define PARTICLE_OPAQUE 2 -typedef struct -{ - particle_t *particle; - int level; - int color; -} partparms_t; - /* ** R_DrawParticle ** @@ -46,10 +39,9 @@ typedef struct ** function pointer route. This exacts some overhead, but ** it pays off in clean and easy to understand code. */ -static void R_DrawParticle(partparms_t *partparms) +static void +R_DrawParticle(particle_t *pparticle, int level) { - particle_t *pparticle = partparms->particle; - int level = partparms->level; vec3_t local, transformed; float zi; byte *pdest; @@ -226,10 +218,9 @@ static void R_DrawParticle(partparms_t *partparms) ** if we're using the asm path, it simply assigns a function pointer ** and goes. */ -void R_DrawParticles (void) +void +R_DrawParticles (void) { - partparms_t partparms; - particle_t *p; int i; @@ -239,17 +230,15 @@ void R_DrawParticles (void) for (p=r_newrefdef.particles, i=0 ; ialpha > 0.66 ) - partparms.level = PARTICLE_OPAQUE; + level = PARTICLE_OPAQUE; else if ( p->alpha > 0.33 ) - partparms.level = PARTICLE_66; + level = PARTICLE_66; else - partparms.level = PARTICLE_33; + level = PARTICLE_33; - partparms.particle = p; - partparms.color = p->color; - - R_DrawParticle(&partparms); + R_DrawParticle(p, level); } } diff --git a/src/client/refresh/soft/sw_poly.c b/src/client/refresh/soft/sw_poly.c index 3a4d661e..b5ef8c1c 100644 --- a/src/client/refresh/soft/sw_poly.c +++ b/src/client/refresh/soft/sw_poly.c @@ -911,7 +911,8 @@ R_PolygonScanRightEdge(espan_t *s_polygon_spans) ** R_ClipAndDrawPoly */ // PGM - isturbulent was qboolean. changed to int to allow passing more flags -void R_ClipAndDrawPoly ( float alpha, int isturbulent, qboolean textured ) +void +R_ClipAndDrawPoly ( float alpha, int isturbulent, qboolean textured ) { vec_t *pv; int i, nump; @@ -1151,7 +1152,8 @@ R_PolygonCalculateGradients (void) ** This should NOT be called externally since it doesn't do clipping! */ // PGM - iswater was qboolean. changed to support passing more flags -static void R_DrawPoly(int iswater) +static void +R_DrawPoly(int iswater) { int i, nump; float ymin, ymax; @@ -1207,7 +1209,8 @@ static void R_DrawPoly(int iswater) /* ** R_DrawAlphaSurfaces */ -void R_DrawAlphaSurfaces( void ) +void +R_DrawAlphaSurfaces( void ) { msurface_t *s = r_alpha_surfaces; @@ -1245,7 +1248,8 @@ void R_DrawAlphaSurfaces( void ) /* ** R_IMFlatShadedQuad */ -void R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha ) +void +R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha ) { vec3_t s0, s1; diff --git a/src/client/refresh/soft/sw_polyse.c b/src/client/refresh/soft/sw_polyse.c index 71d5f967..b0a38403 100644 --- a/src/client/refresh/soft/sw_polyse.c +++ b/src/client/refresh/soft/sw_polyse.c @@ -110,45 +110,45 @@ static void R_PolysetScanLeftEdge_C(int height); // ====================== // PGM // 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 -byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white - 71, 70, 69, 68, 67, 66, 65, 64, - 64, 65, 66, 67, 68, 69, 70, 71, // dark taupe - 72, 73, 74, 75, 76, 77, 78, 79, +static byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white + 71, 70, 69, 68, 67, 66, 65, 64, + 64, 65, 66, 67, 68, 69, 70, 71, // dark taupe + 72, 73, 74, 75, 76, 77, 78, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // slate grey - 72, 73, 74, 75, 76, 77, 78, 79, - 208, 208, 208, 208, 208, 208, 208, 208, // unused?' - 64, 66, 68, 70, 72, 74, 76, 78, // dark yellow + 64, 65, 66, 67, 68, 69, 70, 71, // slate grey + 72, 73, 74, 75, 76, 77, 78, 79, + 208, 208, 208, 208, 208, 208, 208, 208, // unused?' + 64, 66, 68, 70, 72, 74, 76, 78, // dark yellow - 64, 65, 66, 67, 68, 69, 70, 71, // dark red - 72, 73, 74, 75, 76, 77, 78, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // grey/tan - 72, 73, 74, 75, 76, 77, 78, 79, + 64, 65, 66, 67, 68, 69, 70, 71, // dark red + 72, 73, 74, 75, 76, 77, 78, 79, + 64, 65, 66, 67, 68, 69, 70, 71, // grey/tan + 72, 73, 74, 75, 76, 77, 78, 79, - 64, 66, 68, 70, 72, 74, 76, 78, // chocolate - 68, 67, 66, 65, 64, 65, 66, 67, // mauve / teal - 68, 69, 70, 71, 72, 73, 74, 75, - 76, 76, 77, 77, 78, 78, 79, 79, + 64, 66, 68, 70, 72, 74, 76, 78, // chocolate + 68, 67, 66, 65, 64, 65, 66, 67, // mauve / teal + 68, 69, 70, 71, 72, 73, 74, 75, + 76, 76, 77, 77, 78, 78, 79, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // more mauve - 72, 73, 74, 75, 76, 77, 78, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // olive - 72, 73, 74, 75, 76, 77, 78, 79, + 64, 65, 66, 67, 68, 69, 70, 71, // more mauve + 72, 73, 74, 75, 76, 77, 78, 79, + 64, 65, 66, 67, 68, 69, 70, 71, // olive + 72, 73, 74, 75, 76, 77, 78, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // maroon - 72, 73, 74, 75, 76, 77, 78, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // sky blue - 72, 73, 74, 75, 76, 77, 78, 79, + 64, 65, 66, 67, 68, 69, 70, 71, // maroon + 72, 73, 74, 75, 76, 77, 78, 79, + 64, 65, 66, 67, 68, 69, 70, 71, // sky blue + 72, 73, 74, 75, 76, 77, 78, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // olive again - 72, 73, 74, 75, 76, 77, 78, 79, - 64, 65, 66, 67, 68, 69, 70, 71, // nuclear green - 64, 65, 66, 67, 68, 69, 70, 71, // bright yellow + 64, 65, 66, 67, 68, 69, 70, 71, // olive again + 72, 73, 74, 75, 76, 77, 78, 79, + 64, 65, 66, 67, 68, 69, 70, 71, // nuclear green + 64, 65, 66, 67, 68, 69, 70, 71, // bright yellow - 64, 65, 66, 67, 68, 69, 70, 71, // fire colors - 72, 73, 74, 75, 76, 77, 78, 79, - 208, 208, 64, 64, 70, 71, 72, 64, // mishmash1 - 66, 68, 70, 64, 65, 66, 67, 68}; // mishmash2 + 64, 65, 66, 67, 68, 69, 70, 71, // fire colors + 72, 73, 74, 75, 76, 77, 78, 79, + 208, 208, 64, 64, 70, 71, 72, 64, // mishmash1 + 66, 68, 70, 64, 65, 66, 67, 68}; // mishmash2 // PGM // ====================== @@ -157,7 +157,8 @@ byte irtable[256] = { 79, 78, 77, 76, 75, 74, 73, 72, // black/white R_PolysetUpdateTables ================ */ -void R_PolysetUpdateTables (void) +void +R_PolysetUpdateTables (void) { byte *s; @@ -179,7 +180,8 @@ void R_PolysetUpdateTables (void) R_DrawTriangle ================ */ -void R_DrawTriangle( void ) +void +R_DrawTriangle( void ) { int dv1_ab, dv0_ac; int dv0_ab, dv1_ac; @@ -239,7 +241,8 @@ void R_DrawTriangle( void ) R_PolysetScanLeftEdge_C ==================== */ -static void R_PolysetScanLeftEdge_C(int height) +static void +R_PolysetScanLeftEdge_C(int height) { do { @@ -390,7 +393,8 @@ R_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv, R_PolysetCalcGradients ================ */ -static void R_PolysetCalcGradients (int skinwidth) +static void +R_PolysetCalcGradients (int skinwidth) { float xstepdenominv, ystepdenominv, t0, t1; float p01_minus_p21, p11_minus_p21, p00_minus_p20, p10_minus_p20; @@ -449,7 +453,8 @@ static void R_PolysetCalcGradients (int skinwidth) R_PolysetDrawSpans8 ================ */ -void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage) +void +R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage) { byte *lpdest; byte *lptex; @@ -514,7 +519,8 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage) } while (pspanpackage->count != -999999); } -void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage) +void +R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage) { pixel_t *lpdest; int lzi; @@ -559,7 +565,8 @@ void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage) } while (pspanpackage->count != -999999); } -void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage) +void +R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage) { pixel_t *lpdest; pixel_t *lptex; @@ -625,7 +632,8 @@ void R_PolysetDrawSpans8_66(spanpackage_t *pspanpackage) } while (pspanpackage->count != -999999); } -void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage) +void +R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage) { pixel_t *lpdest; int lzi; @@ -670,7 +678,8 @@ void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage) } while (pspanpackage->count != -999999); } -void R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage) +void +R_PolysetDrawSpans8_Opaque (spanpackage_t *pspanpackage) { do { diff --git a/src/client/refresh/soft/sw_rast.c b/src/client/refresh/soft/sw_rast.c index 87eb78f7..fd393ee8 100644 --- a/src/client/refresh/soft/sw_rast.c +++ b/src/client/refresh/soft/sw_rast.c @@ -37,6 +37,9 @@ clipplane_t view_clipplanes[4]; medge_t *r_pedge; +edge_t *r_edges = NULL, *edge_p = NULL, *edge_max = NULL; +surf_t *surfaces = NULL, *surface_p = NULL, *surf_max = NULL; + static qboolean r_leftclipped, r_rightclipped; static qboolean makeleftedge, makerightedge; static qboolean r_nearzionly; @@ -101,7 +104,8 @@ R_InitSkyBox ================ */ -void R_InitSkyBox (void) +void +R_InitSkyBox (void) { int i; extern model_t *loadmodel; @@ -510,7 +514,8 @@ R_EmitCachedEdge (void) R_RenderFace ================ */ -void R_RenderFace (msurface_t *fa, int clipflags) +void +R_RenderFace (msurface_t *fa, int clipflags) { int i; unsigned mask; @@ -725,7 +730,8 @@ void R_RenderFace (msurface_t *fa, int clipflags) R_RenderBmodelFace ================ */ -void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) +void +R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf) { int i; unsigned mask; diff --git a/src/client/refresh/soft/sw_scan.c b/src/client/refresh/soft/sw_scan.c index 9b9d230b..8e7177a8 100644 --- a/src/client/refresh/soft/sw_scan.c +++ b/src/client/refresh/soft/sw_scan.c @@ -41,7 +41,8 @@ this performs a slight compression of the screen at the same time as the sine warp, to keep the edges from wrapping ============= */ -void D_WarpScreen (void) +void +D_WarpScreen (void) { int w, h; int u,v; @@ -98,7 +99,8 @@ void D_WarpScreen (void) D_DrawTurbulent8Span ============= */ -static void D_DrawTurbulent8Span (void) +static void +D_DrawTurbulent8Span (void) { do { @@ -116,7 +118,8 @@ static void D_DrawTurbulent8Span (void) Turbulent8 ============= */ -void Turbulent8 (espan_t *pspan) +void +Turbulent8 (espan_t *pspan) { int snext, tnext; float spancountminus1; @@ -252,7 +255,8 @@ NonTurbulent8 - this is for drawing scrolling textures. they're warping water te but the turbulence is automatically 0. ============= */ -void NonTurbulent8 (espan_t *pspan) +void +NonTurbulent8 (espan_t *pspan) { int snext, tnext; float spancountminus1; @@ -402,7 +406,8 @@ D_DrawSpans16 FIXME: actually make this subdivide by 16 instead of 8!!! ============= */ -void D_DrawSpans16 (espan_t *pspan) +void +D_DrawSpans16 (espan_t *pspan) { int spancount; unsigned char *pbase; @@ -569,7 +574,8 @@ void D_DrawSpans16 (espan_t *pspan) D_DrawZSpans ============= */ -void D_DrawZSpans (espan_t *pspan) +void +D_DrawZSpans (espan_t *pspan) { int izistep; diff --git a/src/client/refresh/soft/sw_sprite.c b/src/client/refresh/soft/sw_sprite.c index 6e034b44..a4221fa9 100644 --- a/src/client/refresh/soft/sw_sprite.c +++ b/src/client/refresh/soft/sw_sprite.c @@ -32,7 +32,8 @@ extern void R_ClipAndDrawPoly( float alpha, qboolean isturbulent, qboolean textu ** Draw currententity / currentmodel as a single texture ** mapped polygon */ -void R_DrawSprite (void) +void +R_DrawSprite (void) { vec5_t *pverts; vec3_t left, up, right, down; From a4b011c5fd3f2b083e0000e9112c118785b2cd1c Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 28 Jul 2018 13:57:08 +0300 Subject: [PATCH 16/19] palette check --- src/client/refresh/soft/header/local.h | 11 --- src/client/refresh/soft/sw_main.c | 105 ++++++++++++++++--------- 2 files changed, 70 insertions(+), 46 deletions(-) diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index fd4cce1d..adbd8307 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -589,17 +589,6 @@ image_t *R_FindImage(char *name, imagetype_t type); void R_FreeUnusedImages(void); void R_InitSkyBox(void); - -typedef struct swstate_s -{ - qboolean fullscreen; - int prev_mode; // last valid SW mode - - unsigned char gammatable[256]; - unsigned char currentpalette[1024]; - -} swstate_t; - void R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha ); /* diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 42b85be3..60082fe4 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -57,6 +57,19 @@ model_t *r_worldmodel; pixel_t *r_warpbuffer; +typedef struct swstate_s +{ + qboolean fullscreen; + int prev_mode; // last valid SW mode + + unsigned char gammatable[256]; + unsigned char currentpalette[1024]; + + // SDL colors + Uint32 palette_colors[256]; + +} swstate_t; + static swstate_t sw_state; void *colormap; @@ -193,6 +206,8 @@ unsigned int d_zwidth; qboolean insubmodel; +static qboolean sdl_palette_outdated; + static struct texture_buffer { image_t image; byte buffer[1024]; @@ -307,7 +322,7 @@ R_Register (void) r_mode->modified = true; // force us to do mode specific stuff later vid_gamma->modified = true; // force us to rebuild the gamma table later - sw_overbrightbits->modified = true; // force us to rebuild pallete later + sw_overbrightbits->modified = true; // force us to rebuild palette later //PGM r_lockpvs = ri.Cvar_Get ("r_lockpvs", "0", 0); @@ -1265,6 +1280,8 @@ R_GammaCorrectAndSetPalette( const unsigned char *palette ) sw_state.currentpalette[i*4+1] = sw_state.gammatable[palette[i*4+1]]; sw_state.currentpalette[i*4+2] = sw_state.gammatable[palette[i*4+2]]; } + + sdl_palette_outdated = true; } /* @@ -1737,9 +1754,9 @@ CreateSDLWindow(int flags, int w, int h) surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask); texture = SDL_CreateTexture(renderer, - SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STREAMING, - w, h); + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + w, h); return window != NULL; #else window = SDL_SetVideoMode(w, h, 0, flags); @@ -2017,12 +2034,47 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) vid_polygon_spans = malloc(sizeof(espan_t) * (vid.height + 1)); memset(sw_state.currentpalette, 0, sizeof(sw_state.currentpalette)); + memset(sw_state.palette_colors, 0, sizeof(sw_state.palette_colors)); + sdl_palette_outdated = true; X11_active = true; return true; } + +static void +RE_SDLPaletteConvert (void) +{ + int i; + const unsigned char *palette = sw_state.currentpalette; + Uint32 *sdl_palette = sw_state.palette_colors; + + if (!sdl_palette_outdated) + return; + + sdl_palette_outdated = false; + for ( i = 0; i < 256; i++ ) + { +#if SDL_VERSION_ATLEAST(2, 0, 0) + if (surface) + sdl_palette[i] = SDL_MapRGB(surface->format, + palette[i * 4 + 0], // red + palette[i * 4 + 1], // green + palette[i * 4 + 2] //blue + ); +#else + if (window) + sdl_palette[i] = SDL_MapRGB(window->format, + palette[i * 4 + 0], // red + palette[i * 4 + 1], // green + palette[i * 4 + 2] //blue + ); +#endif + } +} + + /* ** RE_EndFrame ** @@ -2034,44 +2086,27 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight) static void RE_EndFrame (void) { - int y,x, i; - const unsigned char *pallete = sw_state.currentpalette; - Uint32 pallete_colors[256]; - - for(i=0; i < 256; i++) - { -#if SDL_VERSION_ATLEAST(2, 0, 0) - pallete_colors[i] = SDL_MapRGB(surface->format, - pallete[i * 4 + 0], // red - pallete[i * 4 + 1], // green - pallete[i * 4 + 2] //blue - ); -#else - pallete_colors[i] = SDL_MapRGB(window->format, - pallete[i * 4 + 0], // red - pallete[i * 4 + 1], // green - pallete[i * 4 + 2] //blue - ); -#endif - } + int y,x, pitch, buffer_pos; #if SDL_VERSION_ATLEAST(2, 0, 0) Uint32 * pixels = (Uint32 *)surface->pixels; + pitch = surface->pitch / sizeof(Uint32); #else Uint32 * pixels = (Uint32 *)window->pixels; + pitch = window->pitch / sizeof(Uint32); #endif + + RE_SDLPaletteConvert(); + + buffer_pos = 0; for (y=0; y < vid.height; y++) { for (x=0; x < vid.width; x ++) { - int buffer_pos = y * vid.width + x; - Uint32 color = pallete_colors[vid_buffer[buffer_pos]]; -#if SDL_VERSION_ATLEAST(2, 0, 0) - pixels[y * surface->pitch / sizeof(Uint32) + x] = color; -#else - pixels[y * window->pitch / sizeof(Uint32) + x] = color; -#endif + pixels[x] = sw_state.palette_colors[vid_buffer[buffer_pos + x]]; } + pixels += pitch; + buffer_pos += vid.width; } #if SDL_VERSION_ATLEAST(2, 0, 0) @@ -2178,7 +2213,7 @@ R_ScreenShot_f(void) { int x, y; byte *buffer = malloc(vid.width * vid.height * 3); - const unsigned char *pallete = sw_state.currentpalette; + const unsigned char *palette = sw_state.currentpalette; if (!buffer) { @@ -2190,9 +2225,9 @@ R_ScreenShot_f(void) { for (y=0; y < vid.height; y ++) { int buffer_pos = y * vid.width + x; - buffer[buffer_pos * 3 + 0] = pallete[vid_buffer[buffer_pos] * 4 + 0]; // red - buffer[buffer_pos * 3 + 1] = pallete[vid_buffer[buffer_pos] * 4 + 1]; // green - buffer[buffer_pos * 3 + 2] = pallete[vid_buffer[buffer_pos] * 4 + 2]; // blue + buffer[buffer_pos * 3 + 0] = palette[vid_buffer[buffer_pos] * 4 + 0]; // red + buffer[buffer_pos * 3 + 1] = palette[vid_buffer[buffer_pos] * 4 + 1]; // green + buffer[buffer_pos * 3 + 2] = palette[vid_buffer[buffer_pos] * 4 + 2]; // blue } } From ea27c460f28c36fa869e82cc9fe1fd6410c0f576 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 29 Jul 2018 00:04:10 +0300 Subject: [PATCH 17/19] move trenslate palette based image to full color texture to separate function --- src/client/refresh/soft/sw_main.c | 44 ++++++++++++++++++------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 60082fe4..01aa11a6 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -2075,26 +2075,10 @@ RE_SDLPaletteConvert (void) } -/* -** RE_EndFrame -** -** This does an implementation specific copy from the backbuffer to the -** front buffer. In the Win32 case it uses BitBlt or BltFast depending -** on whether we're using DIB sections/GDI or DDRAW. -*/ - static void -RE_EndFrame (void) +RE_CopyFrame (Uint32 * pixels, int pitch) { - int y,x, pitch, buffer_pos; - -#if SDL_VERSION_ATLEAST(2, 0, 0) - Uint32 * pixels = (Uint32 *)surface->pixels; - pitch = surface->pitch / sizeof(Uint32); -#else - Uint32 * pixels = (Uint32 *)window->pixels; - pitch = window->pitch / sizeof(Uint32); -#endif + int y,x, buffer_pos; RE_SDLPaletteConvert(); @@ -2108,6 +2092,30 @@ RE_EndFrame (void) pixels += pitch; buffer_pos += vid.width; } +} + +/* +** RE_EndFrame +** +** This does an implementation specific copy from the backbuffer to the +** front buffer. In the Win32 case it uses BitBlt or BltFast depending +** on whether we're using DIB sections/GDI or DDRAW. +*/ + +static void +RE_EndFrame (void) +{ + int pitch; + +#if SDL_VERSION_ATLEAST(2, 0, 0) + Uint32 * pixels = (Uint32 *)surface->pixels; + pitch = surface->pitch / sizeof(Uint32); +#else + Uint32 * pixels = (Uint32 *)window->pixels; + pitch = window->pitch / sizeof(Uint32); +#endif + + RE_CopyFrame (pixels, pitch); #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch); From 27cbd0d4e7a8d1151266e520ab1eb8f91efe183c Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 29 Jul 2018 15:29:00 +0300 Subject: [PATCH 18/19] reorder copy vid_buffer to texture. --- src/client/refresh/soft/sw_main.c | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 01aa11a6..7201c6d5 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -2078,19 +2078,38 @@ RE_SDLPaletteConvert (void) static void RE_CopyFrame (Uint32 * pixels, int pitch) { - int y,x, buffer_pos; - RE_SDLPaletteConvert(); - buffer_pos = 0; - for (y=0; y < vid.height; y++) + // no gaps between images rows + if (pitch == vid.width) { - for (x=0; x < vid.width; x ++) + int y,x, buffer_pos; + + buffer_pos = 0; + for (y=0; y < vid.height; y++) { - pixels[x] = sw_state.palette_colors[vid_buffer[buffer_pos + x]]; + for (x=0; x < vid.width; x ++) + { + pixels[x] = sw_state.palette_colors[vid_buffer[buffer_pos + x]]; + } + pixels += pitch; + buffer_pos += vid.width; + } + } + else + { + const Uint32 *max_pixels; + Uint32 *pixels_pos; + pixel_t *buffer_pos; + + max_pixels = pixels + vid.height * vid.width; + buffer_pos = vid_buffer; + + for (pixels_pos = pixels; pixels_pos < max_pixels; pixels_pos++) + { + *pixels_pos = sw_state.palette_colors[*buffer_pos]; + buffer_pos++; } - pixels += pitch; - buffer_pos += vid.width; } } From cf4887c4ba4b9f0c2aff72e4a4d47f9d74236dde Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 30 Jul 2018 15:47:00 +0300 Subject: [PATCH 19/19] fix issue introduced in e5ef665e:Use more short code in *EdgeSearch --- src/client/refresh/soft/sw_edge.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/refresh/soft/sw_edge.c b/src/client/refresh/soft/sw_edge.c index af173d86..87868e0f 100644 --- a/src/client/refresh/soft/sw_edge.c +++ b/src/client/refresh/soft/sw_edge.c @@ -419,8 +419,10 @@ R_LeadingEdgeSearch (edge_t *edge, surf_t *surf, surf_t *surf2) testzi = surf2->d_ziorigin + fv*surf2->d_zistepv + fu*surf2->d_zistepu; - if (newzibottom < testzi) + if (newzibottom >= testzi) + { return surf2; + } newzitop = newzi * 1.01; }