From 09ce33abb9fd72c2840fd13c02b86055d32fabf1 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Jun 2025 19:16:00 +0200 Subject: [PATCH 01/43] just always clamp the non psprite texture column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this may underflow, which the check in the lööp body does not account for --- src/r_things.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index 5f40d79ca..9d91ae19f 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -919,12 +919,10 @@ static void R_DrawVisSprite(vissprite_t *vis) else { // Non-paper drawing loop - for (dc.x = vis->x1; dc.x <= vis->x2 && (frac>>FRACBITS) < pwidth; dc.x++, frac += vis->xiscale) + for (dc.x = vis->x1; dc.x <= vis->x2; dc.x++, frac += vis->xiscale) { - //texturecolumn = CLAMP(frac >> FRACBITS, 0, pwidth - 1); - texturecolumn = (frac >> FRACBITS); + texturecolumn = CLAMP(frac >> FRACBITS, 0, pwidth - 1); column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn])); - localcolfunc(&dc, column); } } From 24eb888af3ebe07700d2fc7fd61f6c7a7e8dd2cb Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Jun 2025 19:20:20 +0200 Subject: [PATCH 02/43] make skytextures support texture offsets in software --- src/r_data.c | 6 +++++- src/r_data.h | 9 +++++++++ src/r_plane.cpp | 2 ++ src/r_sky.c | 25 ++++++++++++++++++++++--- src/r_sky.h | 10 +++++++++- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index ca73e7e42..7ac8ffe2d 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -649,6 +649,7 @@ void R_LoadTextures(void) M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); texture->width = SHORT(patchlump->width); texture->height = SHORT(patchlump->height); + texture->type = TEXTURETYPE_SINGLEPATCH; texture->patchcount = 1; texture->holes = false; @@ -915,19 +916,22 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) // Left Curly Brace texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where open curly brace for texture \"%s\" should be",newTextureName); } + if (strcmp(texturesToken,"{")==0) { if (actuallyLoadTexture) { // Allocate memory for a zero-patch texture. Obviously, we'll be adding patches momentarily. - resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t),PU_STATIC,NULL); + resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t), PU_STATIC, NULL); M_Memcpy(resultTexture->name, newTextureName, 8); resultTexture->width = newTextureWidth; resultTexture->height = newTextureHeight; + resultTexture->type = TEXTURETYPE_COMPOSITE; } Z_Free(texturesToken); texturesToken = M_GetToken(NULL); diff --git a/src/r_data.h b/src/r_data.h index 45f7ee484..c3abab0c1 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -37,6 +37,14 @@ typedef struct UINT16 wad, lump; } texpatch_t; +// texture type +enum +{ + TEXTURETYPE_UNKNOWN, + TEXTURETYPE_SINGLEPATCH, + TEXTURETYPE_COMPOSITE, +}; + // A maptexturedef_t describes a rectangular texture, // which is composed of one or more mappatch_t structures // that arrange graphic patches. @@ -44,6 +52,7 @@ typedef struct { // Keep name for switch changing, etc. char name[8]; + UINT8 type; // TEXTURETYPE_ INT16 width, height; boolean holes; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 81e02c370..b46912b2f 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -839,6 +839,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b } INT32 angle = (pl->viewangle + xtoviewangle[x + i])>>ANGLETOSKYSHIFT; + angle -= (skytextureoffset >> FRACBITS); + dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x + i]>>ANGLETOFINESHIFT)); dc.x = x + i; dc.source = diff --git a/src/r_sky.c b/src/r_sky.c index 1ed47d43b..8cbdd3a59 100644 --- a/src/r_sky.c +++ b/src/r_sky.c @@ -41,6 +41,10 @@ INT32 skytexture; */ INT32 skytexturemid; +/** \brief the x offset of the sky texture + */ +INT32 skytextureoffset; + /** \brief the scale of the sky */ fixed_t skyscale; @@ -50,6 +54,7 @@ fixed_t skyscale; INT32 levelskynum; INT32 globallevelskynum; + /** \brief The R_SetupSkyDraw function Called at loadlevel after skytexture is set, or when sky texture changes. @@ -61,8 +66,20 @@ INT32 globallevelskynum; */ void R_SetupSkyDraw(void) { - // the horizon line in a 256x128 sky texture - skytexturemid = (textures[skytexture]->height/2)<height / 2) << FRACBITS; + skytextureoffset = 0; + + if (textures[skytexture]->type == TEXTURETYPE_SINGLEPATCH) + { + // Sal: Allow for sky offsets + texpatch_t *const tex_patch = &textures[skytexture]->patches[0]; + patch_t *patch = W_CachePatchNumPwad(tex_patch->wad, tex_patch->lump, PU_CACHE); + + skytexturemid += (patch->topoffset << FRACBITS); + skytextureoffset += (patch->leftoffset << FRACBITS); + } + R_SetSkyScale(); } @@ -74,5 +91,7 @@ void R_SetupSkyDraw(void) */ void R_SetSkyScale(void) { - skyscale = FixedDiv(fovtan, FixedDiv(vid.width*FRACUNIT, BASEVIDWIDTH*FRACUNIT)); + //skyscale = FixedDiv(fovtan, FixedDiv(vid.width*FRACUNIT, BASEVIDWIDTH*FRACUNIT)); + fixed_t difference = vid.fdupx-(vid.dupx< Date: Mon, 23 Jun 2025 19:23:56 +0200 Subject: [PATCH 03/43] use const_cast for colfunccopy idk its from rr idk why it was like this --- src/r_things.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index 9d91ae19f..1b63d302a 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -664,9 +664,7 @@ void R_DrawMaskedColumn(drawcolumndata_t* dc, column_t *column) drawcolumndata_t dc_copy = *dc; void (*colfunccopy)(drawcolumndata_t*); colfunccopy = colfunc; - colfunccopy((drawcolumndata_t*)(&dc_copy)); - - //colfunc(); + colfunccopy(const_cast(&dc_copy)); } column = (column_t *)((UINT8 *)column + column->length + 4); } @@ -729,9 +727,7 @@ static void R_DrawFlippedMaskedColumn(drawcolumndata_t* dc, column_t *column) drawcolumndata_t dc_copy = *dc; void (*colfunccopy)(drawcolumndata_t*); colfunccopy = colfunc; - colfunccopy((drawcolumndata_t*)(&dc_copy)); - - //colfunc(); + colfunccopy(const_cast(&dc_copy)); Z_Free(dc->source); } From 4fb3b631528d3c4204f2e6a3a562ed934fc8e66e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Jun 2025 19:38:37 +0200 Subject: [PATCH 04/43] optimize R_StoreWallRange with cut down version of rendersegloop when a seg is untextured from srb2, its just a cut down rendersegloop with alot less things to check and such --- src/r_segs.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++--- src/r_things.cpp | 3 -- 2 files changed, 90 insertions(+), 8 deletions(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 9e39d29e7..8d9f28b03 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1554,6 +1554,74 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) } } +static void R_MarkSegBounds(void) +{ + INT32 yl, yh; + INT32 top, bottom; + INT16 topclip, bottomclip; + + for (; rw_x < rw_stopx; rw_x++) + { + // mark floor / ceiling areas + yl = (topfrac+HEIGHTUNIT-1)>>HEIGHTBITS; + + // no space above wall? + top = ceilingclip[rw_x]+1; + + // no space above wall? + if (yl < top) + yl = top; + + if (markceiling) + { + bottom = yl > floorclip[rw_x] ? floorclip[rw_x] : yl; + + if (top <= --bottom && ceilingplane) + { + R_ExpandPlaneY(ceilingplane, rw_x, top, bottom); + } + } + + yh = bottomfrac>>HEIGHTBITS; + + bottom = floorclip[rw_x]-1; + + if (yh > bottom) + yh = bottom; + + if (markfloor) + { + top = yh < ceilingclip[rw_x] ? ceilingclip[rw_x] : yh; + + if (++top <= bottom && floorplane) + { + R_ExpandPlaneY(floorplane, rw_x, top, bottom); + } + } + + frontscale[rw_x] = rw_scale; + + topclip = (yl >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; + bottomclip = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; + + if (markceiling) // no top wall + ceilingclip[rw_x] = topclip; + + if (markfloor) // no bottom wall + floorclip[rw_x] = bottomclip; + + if (floorclip[rw_x] <= ceilingclip[rw_x] + 1) + { + solidcol[rw_x] = 1; + didsolidcol = true; + } + + rw_scale += rw_scalestep; + topfrac += topstep; + bottomfrac += bottomstep; + } +} + // Uses precalculated seg->length static INT64 R_CalcSegDist(seg_t* seg, INT64 x2, INT64 y2) { @@ -2811,13 +2879,30 @@ void R_StoreWallRange(INT32 start, INT32 stop) } - rw_silhouette = &(ds_p->silhouette); - rw_tsilheight = &(ds_p->tsilheight); - rw_bsilheight = &(ds_p->bsilheight); - didsolidcol = false; - R_RenderSegLoop(&dc); + if (!segtextured && !numffloors) + { + if (markfloor || markceiling) + R_MarkSegBounds(); + else + { + for (; rw_x < rw_stopx; rw_x++) + { + frontscale[rw_x] = rw_scale; + rw_scale += rw_scalestep; + } + } + } + else + { + rw_silhouette = &ds_p->silhouette; + rw_tsilheight = &ds_p->tsilheight; + rw_bsilheight = &ds_p->bsilheight; + + R_RenderSegLoop(&dc); + } + R_SetColumnFunc(BASEDRAWFUNC); if (g_portal) // if curline is a portal, set portalrender for drawseg diff --git a/src/r_things.cpp b/src/r_things.cpp index 1b63d302a..bf33fb97c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -844,9 +844,6 @@ static void R_DrawVisSprite(vissprite_t *vis) frac = vis->startfrac; windowtop = windowbottom = sprbotscreen = INT32_MAX; - //if ((vis->mobj->skin || vis->mobj->localskin) && K_GetMobjSkin(vis->mobj)->flags & SF_HIRES) - // this_scale = FixedMul(this_scale, K_GetMobjSkin(vis->mobj)->highresscale); - if (this_scale <= 0) this_scale = 1; From 07432c038108b93cecb370546c4b0f180ab59c41 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Jun 2025 12:27:13 +0200 Subject: [PATCH 05/43] turn angle stuff into a switch in R_SetupSkyScale --- src/r_main.cpp | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index e0d75b6df..d9ae9a70c 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1114,6 +1114,7 @@ static void R_SetupSkyScale(player_t *player, camera_t *thiscam, mapheader_t *mh { if (skyboxmo[1]) { + angle_t ang; fixed_t x = 0, y = 0; if (mh->skybox_scalex > 0) @@ -1126,31 +1127,29 @@ static void R_SetupSkyScale(player_t *player, camera_t *thiscam, mapheader_t *mh else if (mh->skybox_scaley < 0) y = (moy - skyboxmo[1]->y) * -mh->skybox_scaley; - if (viewmobj->angle == 0) + switch (viewmobj->angle) { - newview->x += x; - newview->y += y; - } - else if (viewmobj->angle == ANGLE_90) - { - newview->x -= y; - newview->y += x; - } - else if (viewmobj->angle == ANGLE_180) - { - newview->x -= x;\ - newview->y -= y;\ - } - else if (viewmobj->angle == ANGLE_270) - { - newview->x += y; - newview->y -= x; - } - else - { - angle_t ang = viewmobj->angle>>ANGLETOFINESHIFT; - newview->x += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang)); - newview->y += FixedMul(x, FINESINE(ang)) + FixedMul(y,FINECOSINE(ang)); + case 0: + newview->x += x; + newview->y += y; + break; + case ANGLE_90: + newview->x -= y; + newview->y += x; + break; + case ANGLE_180: + newview->x -= x;\ + newview->y -= y;\ + break; + case ANGLE_270: + newview->x += y; + newview->y -= x; + break; + default: + ang = viewmobj->angle>>ANGLETOFINESHIFT; + newview->x += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang)); + newview->y += FixedMul(x, FINESINE(ang)) + FixedMul(y,FINECOSINE(ang)); + break; } } From d19a2e09128fd162306973808dd18553a7d1fef0 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Jun 2025 12:45:14 +0200 Subject: [PATCH 06/43] attempt to make fofs in software always cut cyan pixels if they do contain cyan pixels lel kinda meh, and needs a toggle --- src/p_setup.c | 26 ++++++++++++++++++++++++++ src/p_setup.h | 1 + src/r_plane.cpp | 5 +++++ src/r_plane.h | 1 + src/r_segs.cpp | 3 +++ 5 files changed, 36 insertions(+) diff --git a/src/p_setup.c b/src/p_setup.c index fc4f6d892..7457b44ee 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -672,6 +672,19 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat) levelflat->lumpnum = R_GetFlatNumForName(flatname); levelflat->baselumpnum = LUMPERROR; + { + UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL); + size_t size = W_LumpLength(levelflat->lumpnum); + for (size_t steppy = 0; steppy < size; steppy++) + { + if (flat[steppy] == TRANSPARENTPIXEL) + { + levelflat->cyan = true; + break; + } + } + } + #ifndef ZDEBUG CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); #endif @@ -717,6 +730,19 @@ INT32 P_AddLevelFlatRuntime(const char *flatname) levelflat->lumpnum = R_GetFlatNumForName(flatname); levelflat->baselumpnum = LUMPERROR; + { + UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL); + size_t size = W_LumpLength(levelflat->lumpnum); + for (size_t steppy = 0; steppy < size; steppy++) + { + if (flat[steppy] == TRANSPARENTPIXEL) + { + levelflat->cyan = true; + break; + } + } + } + #ifndef ZDEBUG CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); #endif diff --git a/src/p_setup.h b/src/p_setup.h index 86b958adf..646415d28 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -52,6 +52,7 @@ typedef struct INT32 animseq; // start pos. in the anim sequence INT32 numpics; INT32 speed; + boolean cyan; } levelflat_t; extern size_t numlevelflats; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index b46912b2f..a875f3eea 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -507,6 +507,7 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, check->polyobj = polyobj; check->slope = slope; check->noencore = noencore; + check->cyan = levelflats[picnum].cyan; memset(check->top, 0xff, sizeof(*check->top) * viewwidth); memset(check->bottom, 0x00, sizeof(*check->bottom) * viewwidth); @@ -583,6 +584,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) new_pl->polyobj = pl->polyobj; new_pl->slope = pl->slope; new_pl->noencore = pl->noencore; + new_pl->cyan = pl->cyan; pl = new_pl; pl->minx = start; pl->maxx = stop; @@ -1086,6 +1088,9 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle } } + if (pl->cyan && !(pl->ffloor->flags & FF_RIPPLE)) + spanfunctype = SPANDRAWFUNC_SPLAT; + if (pl->ffloor->flags & FF_TRANSLUCENT) { spanfunctype = SPANDRAWFUNC_TRANS; diff --git a/src/r_plane.h b/src/r_plane.h index 35e3f2b08..f330baa3d 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -58,6 +58,7 @@ typedef struct visplane_s pslope_t *slope; boolean noencore; + boolean cyan; } visplane_t; extern visplane_t *visplanes[MAXVISPLANES]; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 8d9f28b03..0cafdeb6f 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -582,6 +582,9 @@ static void R_DrawRepeatMaskedColumn(drawcolumndata_t* dc, column_t *col) // Returns true if a fake floor is translucent. static boolean R_IsFFloorTranslucent(visffloor_t *pfloor) { + if (pfloor->plane->cyan) + return true; + if (pfloor->polyobj) return true; From 8353c1efddbdb2c3b3cf193ec4d4b2f76122d8d8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Jun 2025 12:47:25 +0200 Subject: [PATCH 07/43] add toggle for software cyan cut stuff "softwarecyancut" this is disabled by default, since some vanilla maps were designed around this also costs a bit of performance (splat span drawers are slooooow) --- src/p_setup.c | 8 ++++++-- src/r_main.cpp | 50 ++++++++++++++++++++++++------------------------- src/r_main.h | 1 + src/r_plane.cpp | 2 +- src/r_segs.cpp | 2 +- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 7457b44ee..8218e045e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -672,8 +672,10 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat) levelflat->lumpnum = R_GetFlatNumForName(flatname); levelflat->baselumpnum = LUMPERROR; + // check if our flat contains cyan pixels + // not sure if this is the best way to do it but it works { - UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL); + const UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL); size_t size = W_LumpLength(levelflat->lumpnum); for (size_t steppy = 0; steppy < size; steppy++) { @@ -730,8 +732,10 @@ INT32 P_AddLevelFlatRuntime(const char *flatname) levelflat->lumpnum = R_GetFlatNumForName(flatname); levelflat->baselumpnum = LUMPERROR; + // check if our flat contains cyan pixels + // not sure if this is the best way to do it but it works { - UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL); + const UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL); size_t size = W_LumpLength(levelflat->lumpnum); for (size_t steppy = 0; steppy < size; steppy++) { diff --git a/src/r_main.cpp b/src/r_main.cpp index d9ae9a70c..4c21a76c7 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -183,38 +183,37 @@ consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS] = { {"flipcam4", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam4_OnChange, 0, NULL, NULL, 0, 0, NULL} }; -consvar_t cv_shadow = {"shadow", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_shadowoffs = {"offsetshadows", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_skybox = {"skybox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_ffloorclip = {"r_ffloorclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_spriteclip = {"r_spriteclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_soniccd = {"soniccd", "Off", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_allowmlook = {"allowmlook", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showhud = {"showhud", "Yes", CV_CALL, CV_YesNo, R_SetViewSize, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_translucenthud = {"translucenthud", "10", CV_SAVE, translucenthud_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_uncappedhud = {"uncappedhud", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_translucency = {"translucency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_drawdist = {"drawdist", "Infinite", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shadow = {"shadow", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shadowoffs = {"offsetshadows", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_skybox = {"skybox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ffloorclip = {"r_ffloorclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_spriteclip = {"r_spriteclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_softcyancut = {"softwarecyancut", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_translucency = {"translucency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_drawdist = {"drawdist", "Infinite", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_drawdist_precip = {"drawdist_precip", "1024", CV_SAVE|CV_CALL|CV_NOINIT, drawdist_precip_cons_t, Precipstuff_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Precipstuff_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Precipstuff_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_mobjscaleprecip = {"scaleprecipmobjscale", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Precipstuff_OnChange, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_maxinterpdist = {"maxinterpdist", "Infinite", CV_SAVE, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_ripplewater = {"waterripples", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -// cap fov, fov too high tears software apart. -consvar_t cv_fov = {"fov", "90", CV_FLOAT|CV_CALL|CV_SAVE, fov_cons_t, Fov_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_fovchange = {"fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_maxinterpdist = {"maxinterpdist", "Infinite", CV_SAVE, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ripplewater = {"waterripples", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // Okay, whoever said homremoval causes a performance hit should be shot. -consvar_t cv_homremoval = {"homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_homremoval = {"homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_maxportals = {"maxportals", "2", CV_SAVE, maxportals_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_maxportals = {"maxportals", "2", CV_SAVE, maxportals_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// cap fov, fov too high tears software apart. +consvar_t cv_fov = {"fov", "90", CV_FLOAT|CV_CALL|CV_SAVE, fov_cons_t, Fov_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fovchange = {"fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // randomized directional lightning -consvar_t cv_randomdirlight = {"randomdirectionallight", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, DirLight_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_randomdirlight = {"randomdirectionallight", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, DirLight_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_showhud = {"showhud", "Yes", CV_CALL, CV_YesNo, R_SetViewSize, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_translucenthud = {"translucenthud", "10", CV_SAVE, translucenthud_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_uncappedhud = {"uncappedhud", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_soniccd = {"soniccd", "Off", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_allowmlook = {"allowmlook", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; // tells to reset the maplight at next map change static void DirLight_OnChange(void) @@ -1542,6 +1541,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_skybox); CV_RegisterVar(&cv_ffloorclip); CV_RegisterVar(&cv_spriteclip); + CV_RegisterVar(&cv_softcyancut); for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { diff --git a/src/r_main.h b/src/r_main.h index 6f62855da..808f11b6f 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -211,6 +211,7 @@ extern consvar_t cv_chasecam[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_shadow, cv_shadowoffs; extern consvar_t cv_ffloorclip, cv_spriteclip; +extern consvar_t cv_softcyancut; extern consvar_t cv_translucency; extern consvar_t cv_drawdist, cv_drawdist_precip, cv_lessprecip, cv_mobjscaleprecip; extern consvar_t cv_fov, cv_fovchange; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index a875f3eea..5cb48b355 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1088,7 +1088,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle } } - if (pl->cyan && !(pl->ffloor->flags & FF_RIPPLE)) + if (cv_softcyancut.value && pl->cyan && !(pl->ffloor->flags & FF_RIPPLE)) spanfunctype = SPANDRAWFUNC_SPLAT; if (pl->ffloor->flags & FF_TRANSLUCENT) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 0cafdeb6f..452d1eb8e 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -582,7 +582,7 @@ static void R_DrawRepeatMaskedColumn(drawcolumndata_t* dc, column_t *col) // Returns true if a fake floor is translucent. static boolean R_IsFFloorTranslucent(visffloor_t *pfloor) { - if (pfloor->plane->cyan) + if (cv_softcyancut.value && pfloor->plane->cyan) return true; if (pfloor->polyobj) From be8ddebd804ec08063aa92bb10d2747c81b48883 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Jun 2025 00:38:48 +0200 Subject: [PATCH 08/43] forgor about the new signal handler oop --- src/sdl/i_system.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 249f1f6f2..2d8ae4e70 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -533,6 +533,16 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { +#ifdef HAVE_THREADS + if (g_main_thread_id != std::this_thread::get_id()) + { + // Do not attempt any sort of recovery if this signal triggers off the main thread + signal(num, SIG_DFL); + raise(num); + exit(-2); + } +#endif + signal(num, SIG_DFL); //default signal action raise(num); I_Quit(); From 604bc400211ba3f298cbfef8195cd5cb1f68b595 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Jun 2025 20:06:09 +0200 Subject: [PATCH 09/43] add "for_each" to srb2 threadpool this exectures something for EACH thread not some abritatrily choosen ones --- src/core/thread_pool.h | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/core/thread_pool.h b/src/core/thread_pool.h index 75961614e..535e77a9f 100644 --- a/src/core/thread_pool.h +++ b/src/core/thread_pool.h @@ -80,6 +80,7 @@ public: /// Enqueue but don't notify template void schedule(T&& thunk); + template void for_each(F&& task); /// Notify threads after several schedules void notify(); void notify_sema(const Sema& sema); @@ -143,6 +144,60 @@ void ThreadPool::schedule(T&& thunk) } } +template +void ThreadPool::for_each(F&& thunk) +{ + static_assert(sizeof(std::decay_t) <= sizeof(std::declval().raw)); + + if (immediate_mode_) + { + thunk(); + return; + } + + Sema sync_sema; + begin_sema(); + + auto counter = std::make_shared>(threads_.size()); + + for (size_t i = 0; i < threads_.size(); i++) { + std::shared_ptr q = work_queues_[i]; + Task task; + + struct TaskData { + std::decay_t func; + std::shared_ptr> counter; + Sema sema; + ThreadPool* pool; + }; + static_assert(sizeof(TaskData) <= sizeof(task.raw)); + + new (task.raw.data()) TaskData{ + std::forward(thunk), + counter, + sync_sema, + this + }; + + task.thunk = [](void* ptr) { + auto* data = static_cast(ptr); + data->func(); + if (--(*data->counter) == 0) { + data->pool->notify_sema(data->sema); + } + }; + + task.deleter = [](void* ptr) { + static_cast(ptr)->~TaskData(); + }; + + task.pseudosema = cur_sema_; + q->push(std::move(task)); + } + + wait_sema(sync_sema); +} + } // namespace srb2 extern "C" { From b541de4f8cad976eb2c26c3ec0b7d7ed2775a08d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Jun 2025 20:08:04 +0200 Subject: [PATCH 10/43] allocate tiltlighting buffer in R_AllocViewMemory again just removes the ugly stuff in the span drawers needs to be tested a little, but should be fine --- src/r_draw.cpp | 27 ++++++++++++++++++++++++++- src/r_draw_span.cpp | 31 ------------------------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 23d512a19..83fbe82ae 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -34,6 +34,10 @@ #include "hardware/hw_main.h" #endif +#ifdef HAVE_THREADS +#include "core/thread_pool.h" +#endif + // ========================================================================== // COMMON DATA FOR 8bpp AND 16bpp // ========================================================================== @@ -77,7 +81,19 @@ floatv3_t *ds_su, *ds_sv, *ds_sz; float focallengthf; // For, uh, tilted lighting, duh. -//static INT32 *tiltlighting; +#ifdef HAVE_THREADS +#ifdef _WIN32 +#include +#define local_for_thread static __thread +#else +#include +#define local_for_thread thread_local static +#endif +#else +#define local_for_thread static +#endif + +local_for_thread INT32 *tiltlighting; // -------------------------------------------- // c drawer routines @@ -470,6 +486,15 @@ static void R_AllocViewMemory(void) xtoviewangle = static_cast(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL)); + auto init_tiltlighting = [] { + tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); // dont use Zone memory since its not thread safe + }; + + init_tiltlighting(); +#ifdef HAVE_THREADS + srb2::g_main_threadpool->for_each(std::move(init_tiltlighting)); +#endif + R_AllocSegMemory(); R_AllocClipSegMemory(); R_AllocPlaneMemory(); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index bd74b4f83..833b5c1eb 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -13,18 +13,6 @@ /// \brief span drawer functions /// \note no includes because this is included as part of r_draw.cpp -#ifdef HAVE_THREADS -#ifdef _WIN32 -#include -#define local_for_thread static __thread -#else -#include -#define local_for_thread thread_local static -#endif -#else -#define local_for_thread static -#endif - // ========================================================================== // SPANS // ========================================================================== @@ -210,15 +198,6 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) float endz, endu, endv; UINT32 stepu, stepv; UINT32 bit; - local_for_thread INT32 *tiltlighting = NULL; - local_for_thread INT32 oldviewwidth = 0; - - // dont realloc every frame pls thx - if (tiltlighting == NULL || oldviewwidth != viewwidth) - { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); - oldviewwidth = viewwidth; - } INT32 x1 = ds->x1; const INT32 nflatxshift = ds->nflatxshift; @@ -411,16 +390,6 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); UINT8 *dest; - local_for_thread INT32 *tiltlighting = NULL; - local_for_thread INT32 oldviewwidth = 0; - - // dont realloc every frame pls thx - if (tiltlighting == NULL || oldviewwidth != viewwidth) - { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); - oldviewwidth = viewwidth; - } - dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; From e351c1e62a90730c3147f49cf5a5c6ac577f4c02 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Jun 2025 12:44:51 +0200 Subject: [PATCH 11/43] omit realloc and use unique_ptr for our tiltlighting buffer this makes asan shut up, since those effectively clean up after themselves --- src/r_draw.cpp | 32 ++++++++++++++------------------ src/r_draw_span.cpp | 2 ++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 83fbe82ae..6cec68b9f 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -36,6 +36,15 @@ #ifdef HAVE_THREADS #include "core/thread_pool.h" +#ifdef _WIN32 +#include +#define local_for_thread static __thread +#else +#include +#define local_for_thread thread_local static +#endif +#else +#define local_for_thread static #endif // ========================================================================== @@ -81,19 +90,7 @@ floatv3_t *ds_su, *ds_sv, *ds_sz; float focallengthf; // For, uh, tilted lighting, duh. -#ifdef HAVE_THREADS -#ifdef _WIN32 -#include -#define local_for_thread static __thread -#else -#include -#define local_for_thread thread_local static -#endif -#else -#define local_for_thread static -#endif - -local_for_thread INT32 *tiltlighting; +local_for_thread std::unique_ptr tiltlight; // -------------------------------------------- // c drawer routines @@ -486,13 +483,12 @@ static void R_AllocViewMemory(void) xtoviewangle = static_cast(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL)); - auto init_tiltlighting = [] { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); // dont use Zone memory since its not thread safe + auto init_tiltlighting = [](INT32 size) { + tiltlight = std::make_unique(size); }; - - init_tiltlighting(); + init_tiltlighting(viewwidth); // allocate for main thread #ifdef HAVE_THREADS - srb2::g_main_threadpool->for_each(std::move(init_tiltlighting)); + srb2::g_main_threadpool->for_each([=] { init_tiltlighting(viewwidth); }); #endif R_AllocSegMemory(); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 833b5c1eb..c8b051913 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -204,6 +204,7 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) const INT32 nflatyshift = ds->nflatyshift; const INT32 nflatmask = ds->nflatmask; const INT32 stride = vid.width; + INT32 * __restrict tiltlighting = tiltlight.get(); iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); @@ -392,6 +393,7 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; + INT32 * __restrict tiltlighting = tiltlight.get(); // Lighting is simple. It's just linear interpolation from start to end { From 0db437aadde436842878f9768288ae2baa33487b Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Jun 2025 12:46:53 +0200 Subject: [PATCH 12/43] do some more tiny optimizations -those can all be declared with restrict -our ternary clamp macro is slightly faster than std::clamp --- src/r_draw_column.cpp | 22 +++++++++++----------- src/r_draw_span.cpp | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 97273e728..7754a2705 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -31,7 +31,7 @@ enum DrawColumnType }; template -static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 *colormap) +static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * __restrict colormap) { if constexpr (Type & DrawColumnType::DC_COLORMAP) { @@ -42,7 +42,7 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co } template -static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 *dest, UINT8 col, const UINT8 *colormap) +static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT8 col, const UINT8 * __restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); @@ -57,7 +57,7 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 *dest, } template -static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 *dest, UINT32 bit, const UINT8 *source, const UINT8 *colormap) +static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT32 bit, const __restrict UINT8 *source, const __restrict UINT8 *colormap) { UINT8 col = source[bit]; @@ -182,18 +182,18 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // // killough 2/1/98: more performance tuning - fixed_t frac; + intptr_t frac; const intptr_t fracstep = dc->iscale; const intptr_t heightmask = dc->sourcelength-1; - static const INT32 npow2min = -1; + constexpr INT32 npow2min = -1; const INT32 npow2max = dc->sourcelength; const INT32 stride = vid.width; - const UINT8 *source = dc->source; - const lighttable_t *colormap = dc->colormap; + const UINT8 * __restrict source = dc->source; + const lighttable_t * __restrict colormap = dc->colormap; // Framebuffer destination address. - UINT8 *dest = R_Address(dc->x, dc->yl); + UINT8 * __restrict dest = R_Address(dc->x, dc->yl); count++; @@ -275,7 +275,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // -1 is the lower clamp bound because column posts have a "safe" byte before the real data // and a few bytes after as well - *dest = R_DrawColumnPixel(dc, dest, std::clamp((frac >> FRACBITS), npow2min, npow2max), source, colormap); + *dest = R_DrawColumnPixel(dc, dest, CLAMP((frac >> FRACBITS), npow2min, npow2max), source, colormap); dest += stride; @@ -325,7 +325,7 @@ DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_HOLES|DC_TRANSMAP) void R_DrawFogColumn(drawcolumndata_t* dc) { INT32 count; - UINT8 *dest; + UINT8 * __restrict dest; count = dc->yh - dc->yl; @@ -344,7 +344,7 @@ void R_DrawFogColumn(drawcolumndata_t* dc) dest = R_Address(dc->x, dc->yl); const INT32 stride = vid.width; - const lighttable_t *colormap = dc->colormap; + const lighttable_t * __restrict colormap = dc->colormap; // Determine scaling, which is the only mapping to be done. do diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index c8b051913..8ea30a80a 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -76,10 +76,10 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) UINT32 xstep, ystep; UINT32 bit; - UINT8 *dest = R_Address(ds->x1, ds->y); - UINT8 *dsrc; + UINT8 * __restrict dest = R_Address(ds->x1, ds->y); + UINT8 * __restrict dsrc; - const UINT8 *deststop = vid.screens[0] + vid.rowbytes * vid.height; + const UINT8 * __restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; if (dest+8 > deststop) { @@ -92,8 +92,8 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) xposition = ds->xfrac; yposition = ds->yfrac; xstep = ds->xstep; ystep = ds->ystep; - const UINT8 *source = ds->source; - const UINT8 *colormap = ds->colormap; + const UINT8 * __restrict source = ds->source; + const UINT8 * __restrict colormap = ds->colormap; if constexpr (Type & DS_RIPPLE) { @@ -190,8 +190,8 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) UINT32 u, v; int i; - UINT8 *dest = R_Address(ds->x1, ds->y); - UINT8 *dsrc; + UINT8 * __restrict dest = R_Address(ds->x1, ds->y); + UINT8 * __restrict dsrc; float startz, startu, startv; float izstep, uzstep, vzstep; @@ -362,8 +362,8 @@ DEFINE_SPAN_COMBO(R_DrawTranslucentWaterSpan, DS_TRANSMAP|DS_RIPPLE) */ void R_DrawFogSpan(drawspandata_t* ds) { - const UINT8 *colormap = ds->colormap; - UINT8 *dest = R_Address(ds->x1, ds->y); + const UINT8 * __restrict colormap = ds->colormap; + UINT8 * __restrict dest = R_Address(ds->x1, ds->y); intptr_t count = ds->x2 - ds->x1 + 1; @@ -389,7 +389,7 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) { int width = ds->x2 - ds->x1; float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); - UINT8 *dest; + UINT8 * __restrict dest; dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; From d23c51e70701ad1aefcb1a4dda69e9a8980c69a7 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Jun 2025 12:47:10 +0200 Subject: [PATCH 13/43] mark node as restrict again pointonside --- src/r_main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_main.h b/src/r_main.h index 808f11b6f..e95862c57 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -88,7 +88,7 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // // killough 5/2/98: reformatted // -FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *node) +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * __restrict node) { if (!node->dx) return x <= node->x ? node->dy > 0 : node->dy < 0; From 36e485b2a3c070df99936af1783b9c72d99cdca5 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Jun 2025 15:13:54 +0200 Subject: [PATCH 14/43] move gl portalcullsector check back to the right place lel oopsie --- src/hardware/hw_main.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 906ac9161..c3cd01ad7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3199,17 +3199,6 @@ static void HWR_RenderBSPNode(INT32 bspnum) bspnum = bsp->children[side^1]; } - // PORTAL CULLING - if (portalcullsector) - { - // skip all subsectors encountered before the portal - // destination's front sector - if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector) - return; - else - portalcullsector = NULL; - } - // e6y: support for extended nodes HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); } @@ -3241,6 +3230,17 @@ static void HWR_RenderPortalBSPNode(INT32 bspnum) bspnum = bsp->children[side^1]; } + // PORTAL CULLING + if (portalcullsector) + { + // skip all subsectors encountered before the portal + // destination's front sector + if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector) + return; + else + portalcullsector = NULL; + } + // e6y: support for extended nodes HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); } From aef02cb3478c7048ae8d10b9bef1d1c9567620be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Thu, 26 Jun 2025 19:51:01 +0200 Subject: [PATCH 15/43] Fix one-pixel wide gaps in tall sprites --- src/r_draw_column.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 7754a2705..bc91ef0d3 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -220,7 +220,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) frac += FRACUNIT; // texture has no height, so just go - while (--count > 0) + while (--count >= 0) { *dest = R_DrawColumnPixel(dc, dest, frac>>FRACBITS, source, colormap); dest += stride; From 972ee5cf7629afb2f96b2434a2ce61920587ca91 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Jun 2025 20:11:23 +0200 Subject: [PATCH 16/43] remove erronous BACKSLASH was from when this was a macro lel edit: screw you comptime --- src/r_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index 044aa918a..836fb66e8 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1129,8 +1129,8 @@ static void R_SetupSkyScale(player_t *player, camera_t *thiscam, mapheader_t *mh newview->y += x; break; case ANGLE_180: - newview->x -= x;\ - newview->y -= y;\ + newview->x -= x; + newview->y -= y; break; case ANGLE_270: newview->x += y; From 054a40a4b2d4d7a981ad3a9f53c4025e7d5547c4 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Jun 2025 16:38:13 +0200 Subject: [PATCH 17/43] Revert "omit realloc and use unique_ptr for our tiltlighting buffer" This reverts commit e351c1e62a90730c3147f49cf5a5c6ac577f4c02. --- src/r_draw.cpp | 32 ++++++++++++++++++-------------- src/r_draw_span.cpp | 2 -- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 6cec68b9f..83fbe82ae 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -36,15 +36,6 @@ #ifdef HAVE_THREADS #include "core/thread_pool.h" -#ifdef _WIN32 -#include -#define local_for_thread static __thread -#else -#include -#define local_for_thread thread_local static -#endif -#else -#define local_for_thread static #endif // ========================================================================== @@ -90,7 +81,19 @@ floatv3_t *ds_su, *ds_sv, *ds_sz; float focallengthf; // For, uh, tilted lighting, duh. -local_for_thread std::unique_ptr tiltlight; +#ifdef HAVE_THREADS +#ifdef _WIN32 +#include +#define local_for_thread static __thread +#else +#include +#define local_for_thread thread_local static +#endif +#else +#define local_for_thread static +#endif + +local_for_thread INT32 *tiltlighting; // -------------------------------------------- // c drawer routines @@ -483,12 +486,13 @@ static void R_AllocViewMemory(void) xtoviewangle = static_cast(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL)); - auto init_tiltlighting = [](INT32 size) { - tiltlight = std::make_unique(size); + auto init_tiltlighting = [] { + tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); // dont use Zone memory since its not thread safe }; - init_tiltlighting(viewwidth); // allocate for main thread + + init_tiltlighting(); #ifdef HAVE_THREADS - srb2::g_main_threadpool->for_each([=] { init_tiltlighting(viewwidth); }); + srb2::g_main_threadpool->for_each(std::move(init_tiltlighting)); #endif R_AllocSegMemory(); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 8ea30a80a..ebdb4b8d7 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -204,7 +204,6 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) const INT32 nflatyshift = ds->nflatyshift; const INT32 nflatmask = ds->nflatmask; const INT32 stride = vid.width; - INT32 * __restrict tiltlighting = tiltlight.get(); iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); @@ -393,7 +392,6 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; - INT32 * __restrict tiltlighting = tiltlight.get(); // Lighting is simple. It's just linear interpolation from start to end { From 96501394704e5c04ac775819a65e0fe18ac32c58 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Jun 2025 16:38:16 +0200 Subject: [PATCH 18/43] Revert "allocate tiltlighting buffer in R_AllocViewMemory again" This reverts commit b541de4f8cad976eb2c26c3ec0b7d7ed2775a08d. --- src/r_draw.cpp | 27 +-------------------------- src/r_draw_span.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 83fbe82ae..23d512a19 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -34,10 +34,6 @@ #include "hardware/hw_main.h" #endif -#ifdef HAVE_THREADS -#include "core/thread_pool.h" -#endif - // ========================================================================== // COMMON DATA FOR 8bpp AND 16bpp // ========================================================================== @@ -81,19 +77,7 @@ floatv3_t *ds_su, *ds_sv, *ds_sz; float focallengthf; // For, uh, tilted lighting, duh. -#ifdef HAVE_THREADS -#ifdef _WIN32 -#include -#define local_for_thread static __thread -#else -#include -#define local_for_thread thread_local static -#endif -#else -#define local_for_thread static -#endif - -local_for_thread INT32 *tiltlighting; +//static INT32 *tiltlighting; // -------------------------------------------- // c drawer routines @@ -486,15 +470,6 @@ static void R_AllocViewMemory(void) xtoviewangle = static_cast(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL)); - auto init_tiltlighting = [] { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); // dont use Zone memory since its not thread safe - }; - - init_tiltlighting(); -#ifdef HAVE_THREADS - srb2::g_main_threadpool->for_each(std::move(init_tiltlighting)); -#endif - R_AllocSegMemory(); R_AllocClipSegMemory(); R_AllocPlaneMemory(); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index ebdb4b8d7..7ead430c4 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -13,6 +13,18 @@ /// \brief span drawer functions /// \note no includes because this is included as part of r_draw.cpp +#ifdef HAVE_THREADS +#ifdef _WIN32 +#include +#define local_for_thread static __thread +#else +#include +#define local_for_thread thread_local static +#endif +#else +#define local_for_thread static +#endif + // ========================================================================== // SPANS // ========================================================================== @@ -198,6 +210,15 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) float endz, endu, endv; UINT32 stepu, stepv; UINT32 bit; + local_for_thread INT32 *tiltlighting = NULL; + local_for_thread INT32 oldviewwidth = 0; + + // dont realloc every frame pls thx + if (tiltlighting == NULL || oldviewwidth != viewwidth) + { + tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); + oldviewwidth = viewwidth; + } INT32 x1 = ds->x1; const INT32 nflatxshift = ds->nflatxshift; @@ -390,6 +411,16 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); UINT8 * __restrict dest; + local_for_thread INT32 *tiltlighting = NULL; + local_for_thread INT32 oldviewwidth = 0; + + // dont realloc every frame pls thx + if (tiltlighting == NULL || oldviewwidth != viewwidth) + { + tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); + oldviewwidth = viewwidth; + } + dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; From 4e9f9b7e0e4272d3210d80b1bcf972c0097d0c0e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Jun 2025 16:38:19 +0200 Subject: [PATCH 19/43] Revert "add "for_each" to srb2 threadpool" This reverts commit 604bc400211ba3f298cbfef8195cd5cb1f68b595. --- src/core/thread_pool.h | 55 ------------------------------------------ 1 file changed, 55 deletions(-) diff --git a/src/core/thread_pool.h b/src/core/thread_pool.h index 535e77a9f..75961614e 100644 --- a/src/core/thread_pool.h +++ b/src/core/thread_pool.h @@ -80,7 +80,6 @@ public: /// Enqueue but don't notify template void schedule(T&& thunk); - template void for_each(F&& task); /// Notify threads after several schedules void notify(); void notify_sema(const Sema& sema); @@ -144,60 +143,6 @@ void ThreadPool::schedule(T&& thunk) } } -template -void ThreadPool::for_each(F&& thunk) -{ - static_assert(sizeof(std::decay_t) <= sizeof(std::declval().raw)); - - if (immediate_mode_) - { - thunk(); - return; - } - - Sema sync_sema; - begin_sema(); - - auto counter = std::make_shared>(threads_.size()); - - for (size_t i = 0; i < threads_.size(); i++) { - std::shared_ptr q = work_queues_[i]; - Task task; - - struct TaskData { - std::decay_t func; - std::shared_ptr> counter; - Sema sema; - ThreadPool* pool; - }; - static_assert(sizeof(TaskData) <= sizeof(task.raw)); - - new (task.raw.data()) TaskData{ - std::forward(thunk), - counter, - sync_sema, - this - }; - - task.thunk = [](void* ptr) { - auto* data = static_cast(ptr); - data->func(); - if (--(*data->counter) == 0) { - data->pool->notify_sema(data->sema); - } - }; - - task.deleter = [](void* ptr) { - static_cast(ptr)->~TaskData(); - }; - - task.pseudosema = cur_sema_; - q->push(std::move(task)); - } - - wait_sema(sync_sema); -} - } // namespace srb2 extern "C" { From 5638709670563de5e5e9dca1b5d232ee74517240 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 11:44:04 +0200 Subject: [PATCH 20/43] some cleanup k_kart perhaps we could also move the saturn stuff into arrays, those massive walls of variables are kinda ugly lel --- src/d_main.c | 40 +-- src/k_kart.c | 926 ++++++++++++++++++++++++++------------------------- 2 files changed, 498 insertions(+), 468 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index ecd7e6247..f8cf89f54 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1216,32 +1216,32 @@ static boolean AddIWAD(void) } // extra graphic patches for saturn specific thingies -boolean found_extra_kart = false; +boolean found_extra_kart = false; boolean found_extra2_kart = false; boolean found_extra3_kart = false; -boolean xtra_speedo = false; // extra speedometer check -boolean xtra_speedo_clr = false; // extra speedometer colour check -boolean xtra_speedo3 = false; // 80x 11 extra speedometer check -boolean xtra_speedo_clr3 = false; // 80x 11 extra speedometer colour check -boolean achi_speedo = false; // achiiro speedometer check -boolean achi_speedo_clr = false; // extra speedometer colour check -boolean dial_speedo = false; // dial speedometer check -boolean dial_speedo_clr = false; // dial speedometer colour check -boolean kartz_speedo = false; // kartZ speedo +boolean xtra_speedo = false; // extra speedometer check +boolean xtra_speedo_clr = false; // extra speedometer colour check +boolean xtra_speedo3 = false; // 80x 11 extra speedometer check +boolean xtra_speedo_clr3 = false; // 80x 11 extra speedometer colour check +boolean achi_speedo = false; // achiiro speedometer check +boolean achi_speedo_clr = false; // extra speedometer colour check +boolean dial_speedo = false; // dial speedometer check +boolean dial_speedo_clr = false; // dial speedometer colour check +boolean kartz_speedo = false; // kartZ speedo boolean kartz_speedo_smol = false; // kartZ speedo but smol -boolean clr_hud = false; // colour hud check +boolean clr_hud = false; // colour hud check boolean driftgaugegfx_clr = false; // driftgauge colour check -boolean big_lap = false; // bigger lap counter -boolean big_lap_color = false; // bigger lap counter but colour -boolean statdp = false; // stat display for extended player setup -boolean nametaggfx = false; // Nametag stuffs -boolean driftgaugegfx = false; // Driftgauge stuffs -boolean multiitem_icon = false; // Extra icons for Sneakers, Banana and Jawz -boolean joystickicon = false; // Extra icons for the joystick input display -boolean minidoticon = false; // Dot graphic for minimap player angle display -boolean minilighticon = false; // mkwii-style minimap headlight +boolean big_lap = false; // bigger lap counter +boolean big_lap_color = false; // bigger lap counter but colour +boolean statdp = false; // stat display for extended player setup +boolean nametaggfx = false; // Nametag stuffs +boolean driftgaugegfx = false; // Driftgauge stuffs +boolean multiitem_icon = false; // Extra icons for Sneakers, Banana and Jawz +boolean joystickicon = false; // Extra icons for the joystick input display +boolean minidoticon = false; // Dot graphic for minimap player angle display +boolean minilighticon = false; // mkwii-style minimap headlight // static void IdentifyVersion(void) diff --git a/src/k_kart.c b/src/k_kart.c index 5589bdb6e..c8dc049a3 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -745,7 +745,8 @@ UINT8 K_GetKartColorByName(const char *name) UINT8 K_GetHudColor(void) { - if (cv_colorizedhud.value && cv_colorizedhudcolor.value) return cv_colorizedhudcolor.value; + if (cv_colorizedhud.value && cv_colorizedhudcolor.value) + return cv_colorizedhudcolor.value; return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : cv_playercolor.value); } @@ -766,7 +767,7 @@ enum SPEEDO_EXTRA3, }; -static UINT8 K_GetSpeedometerStyle(void) +static SINT8 K_GetSpeedometerStyle(void) { if (cv_newspeedometer.value == 2 && xtra_speedo) return SPEEDO_EXTRA; @@ -4480,14 +4481,14 @@ static void K_DoShrink(player_t *user) void K_DoPogoSpring(mobj_t *mo, fixed_t vertispeed, UINT8 sound) { - const fixed_t vscale = mapobjectscale + (mo->scale - mapobjectscale); - if (mo->player && mo->player->spectator) return; if (mo->eflags & MFE_SPRUNG) return; + const fixed_t vscale = mapobjectscale + (mo->scale - mapobjectscale); + mo->standingslope = NULL; mo->eflags |= MFE_SPRUNG; @@ -5390,12 +5391,12 @@ player_t *K_FindJawzTarget(mobj_t *actor, player_t *source) // Engine Sounds. static void K_UpdateEngineSounds(player_t *player, ticcmd_t *cmd) { - const INT32 numsnds = 13; + static const INT32 numsnds = 13; - const fixed_t closedist = 160*FRACUNIT; - const fixed_t fardist = 1536*FRACUNIT; + static const fixed_t closedist = 160*FRACUNIT; + static const fixed_t fardist = 1536*FRACUNIT; - const UINT8 dampenval = 48; // 255 * 48 = close enough to FRACUNIT/6 + static const UINT8 dampenval = 48; // 255 * 48 = close enough to FRACUNIT/6 INT32 class, s, w; // engine class number @@ -5405,18 +5406,6 @@ static void K_UpdateEngineSounds(player_t *player, ticcmd_t *cmd) INT32 targetsnd = 0; INT32 i; - s = (player->kartspeed - 1) / 3; - w = (player->kartweight - 1) / 3; - -#define LOCKSTAT(stat) \ - if (stat < 0) { stat = 0; } \ - if (stat > 2) { stat = 2; } - LOCKSTAT(s); - LOCKSTAT(w); -#undef LOCKSTAT - - class = s + (3*w); - if (leveltime < 8 || player->spectator || player->exiting) { // Silence the engines, and reset sound number while we're at it. @@ -5522,13 +5511,25 @@ static void K_UpdateEngineSounds(player_t *player, ticcmd_t *cmd) return; } + s = (player->kartspeed - 1) / 3; + w = (player->kartweight - 1) / 3; + +#define LOCKSTAT(stat) \ + if (stat < 0) { stat = 0; } \ + if (stat > 2) { stat = 2; } + LOCKSTAT(s); + LOCKSTAT(w); +#undef LOCKSTAT + + class = s + (3*w); + S_StartSoundAtVolume(player->mo, (sfx_krta00 + player->kartstuff[k_enginesnd]) + (class * numsnds), volume); } static void K_UpdateInvincibilitySounds(player_t *player) { INT32 sfxnum = sfx_None; - boolean localplayer = P_IsLocalPlayer(player); + const boolean localplayer = P_IsLocalPlayer(player); if (player->mo->health > 0) { @@ -5594,21 +5595,14 @@ void K_KartPlayerHUDUpdate(player_t *player) static boolean K_SpeedLinesShouldBlend(player_t *player) { - fixed_t percentspeed = 0; - - if (!cv_playerblendeffects.value) - return false; - - if (!player->mo) + if (!cv_playerblendeffects.value || !player->mo) return false; if (player->kartstuff[k_sneakertimer]) return true; // this is how the percentage speedometer calcs, i suck at maths so this was the easiest thing to do lmao - percentspeed = (FixedDiv(player->speed, FixedMul(K_GetKartSpeed(player, false), ORIG_FRICTION))*100)>>FRACBITS; - - if (percentspeed > 127) // sneaker boost is around 25% + if ((FixedDiv(player->speed, FixedMul(K_GetKartSpeed(player, false), ORIG_FRICTION))*100)>>FRACBITS > 127) // sneaker boost is around 25% return true; return false; @@ -5724,6 +5718,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) else if (player->kartstuff[k_eggmanexplode]) // You're gonna diiiiie { const INT32 flashtime = 4<<(player->kartstuff[k_eggmanexplode]/TICRATE); + if (player->kartstuff[k_eggmanexplode] == 1 || (player->kartstuff[k_eggmanexplode] % (flashtime/2) != 0)) { player->mo->colorized = false; @@ -6055,6 +6050,7 @@ boolean K_CheckPlayersRespawnColliding(INT32 playernum, fixed_t x, fixed_t y) { INT32 i; fixed_t p1radius = players[playernum].mo->radius; + for (i = 0; i < MAXPLAYERS; i++) { if (playernum == i || !playeringame[i] || players[i].spectator || !players[i].mo || players[i].mo->health <= 0 @@ -6114,9 +6110,9 @@ INT16 K_GetKartTurnValue(player_t *player, INT16 turnvalue) return turnvalue; } - fixed_t p_topspeed = K_GetKartSpeed(player, false); - fixed_t p_curspeed = min(player->speed, p_topspeed * 2); - fixed_t p_maxspeed = p_topspeed * 3; + fixed_t p_topspeed = K_GetKartSpeed(player, false); + fixed_t p_curspeed = min(player->speed, p_topspeed * 2); + fixed_t p_maxspeed = p_topspeed * 3; fixed_t adjustangle = FixedDiv((p_maxspeed>>16) - (p_curspeed>>16), (p_maxspeed>>16) + player->kartweight); turnvalue = FixedMul(turnvalue, adjustangle); // Weight has a small effect on turning @@ -6337,7 +6333,7 @@ static void K_KartDrift(player_t *player, boolean onground) void K_KartUpdatePosition(player_t *player) { fixed_t position = 1; - fixed_t oldposition = player->kartstuff[k_position]; + fixed_t oldposition; fixed_t i, ppcd, pncd, ipcd, incd; fixed_t pmo, imo; mobj_t *mo; @@ -6345,6 +6341,8 @@ void K_KartUpdatePosition(player_t *player) if (player->spectator || !player->mo) return; + oldposition = player->kartstuff[k_position]; + for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i] || players[i].spectator || !players[i].mo) @@ -7542,14 +7540,294 @@ void K_UpdateSpectateGrief(void) #define NUMPOSFRAMES 7 // White, three blues, three reds #define NUMWINFRAMES 6 // Red, yellow, green, cyan, blue, purple -//{ Patch Definitions -static patch_t *kp_nodraw; +//{ Patch Definitions +// --Saturn patches-- +// dont leave those unitialized incase we missed a check somewhere + +// -Speedometers- + +// Smol speedo +static patch_t *skp_smallsticker = NULL; +static patch_t *skp_smallsticker3 = NULL; + +static patch_t *skp_speedpatches[5] = {NULL}; + +// Achii speedo +static patch_t *skp_smallstickerachi = NULL; +static patch_t *skp_speedpatchesachi[5] = {NULL}; +static patch_t *skp_smallstickerachiclr = NULL; +static patch_t *skp_speedpatchesachiclr[5] = {NULL}; + +// Kartz speedo +static patch_t *kp_kartzspeedo[25] = {NULL}; +static patch_t *kp_kartzspeedo_smol[25] = {NULL}; + +// dial speedometer +static patch_t *skp_rankfinish = NULL; +static patch_t *skp_dialbase[2] = {NULL}; +static patch_t *skp_speedpatchesdial[5] = {NULL}; +static patch_t *skp_dialnum[10] = {NULL}; +//static patch_t *skp_dialclr = NULL; +static patch_t *skp_dialbaseclr[2] = {NULL}; +static patch_t *skp_speedpatchesdialclr[5] = {NULL}; +static patch_t *skp_dialnumclr[10] = {NULL}; + +// -Colourized hud- + +static patch_t *kp_timestickerclr = NULL; +static patch_t *kp_timestickerwideclr = NULL; +static patch_t *kp_lapstickerclr = NULL; +static patch_t *kp_lapstickerbigclr = NULL; +static patch_t *kp_lapstickerbig2clr = NULL; +static patch_t *kp_lapstickerwideclr = NULL; +//static patch_t *kp_lapstickernarrowclr = NULL; +static patch_t *kp_bumperstickerclr = NULL; +static patch_t *kp_bumperstickerwideclr = NULL; +static patch_t *kp_karmastickerclr = NULL; +static patch_t *kp_timeoutstickerclr = NULL; +static patch_t *skp_smallstickerclr = NULL; +static patch_t *skp_smallstickerclr3 = NULL; +static patch_t *kp_itemmulstickerclr[2] = {NULL}; +static patch_t *kp_itembgclr[4] = {NULL}; + +// -Misc.- + +static patch_t *kp_lapstickerbig = NULL; +static patch_t *kp_lapstickerbig2 = NULL; + +static patch_t *nametagpic = NULL; +static patch_t *nametagline = NULL; +static patch_t *nametagspeed = NULL; +static patch_t *nametagweight = NULL; + +static patch_t *driftgauge = NULL; +static patch_t *driftgaugecolor = NULL; +static patch_t *driftgaugesmall = NULL; +static patch_t *driftgaugesmallcolor = NULL; + +static patch_t *kp_minimapdot = NULL; + +static patch_t *joybacking = NULL; +static patch_t *joyknob = NULL; +static patch_t *joyshadow = NULL; + +static patch_t *kp_multjawz = NULL; +static patch_t *kp_multsneaker[2] = {NULL}; +static patch_t *kp_multbanana[3] = {NULL}; + +static void K_LoadSaturnHUDGraphics(void) +{ + INT32 i; + char buffer[9]; + + if (found_extra_kart) + { + if (xtra_speedo) // smol speedometer + { + skp_smallsticker = (patch_t *)W_CachePatchName("SP_SMSTC", PU_HUDGFX); + skp_speedpatches[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatches[1] = (patch_t *)W_CachePatchName("SP_MKMH", PU_HUDGFX); + skp_speedpatches[2] = (patch_t *)W_CachePatchName("SP_MMPH", PU_HUDGFX); + skp_speedpatches[3] = (patch_t *)W_CachePatchName("SP_MFRAC", PU_HUDGFX); + skp_speedpatches[4] = (patch_t *)W_CachePatchName("SP_MPERC", PU_HUDGFX); + } + + if (achi_speedo) + { + skp_smallstickerachi = (patch_t *)W_CachePatchName("SP_AMSTC", PU_HUDGFX); + skp_speedpatchesachi[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesachi[1] = (patch_t *)W_CachePatchName("SP_AKMH", PU_HUDGFX); + skp_speedpatchesachi[2] = (patch_t *)W_CachePatchName("SP_AMPH", PU_HUDGFX); + skp_speedpatchesachi[3] = (patch_t *)W_CachePatchName("SP_AFRAC", PU_HUDGFX); + skp_speedpatchesachi[4] = (patch_t *)W_CachePatchName("SP_APERC", PU_HUDGFX); + } + + if (dial_speedo) + { + skp_rankfinish = (patch_t *)W_CachePatchName("RANKFIN", PU_HUDGFX); + skp_dialbase[0] = (patch_t *)W_CachePatchName("K_DSPBS1", PU_HUDGFX); + skp_dialbase[1] = (patch_t *)W_CachePatchName("K_DSPBS2", PU_HUDGFX); + + skp_speedpatchesdial[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesdial[1] = (patch_t *)W_CachePatchName("SP_DKMH", PU_HUDGFX); + skp_speedpatchesdial[2] = (patch_t *)W_CachePatchName("SP_DMPH", PU_HUDGFX); + skp_speedpatchesdial[3] = (patch_t *)W_CachePatchName("SP_DFRAC", PU_HUDGFX); + skp_speedpatchesdial[4] = (patch_t *)W_CachePatchName("SP_DPERC", PU_HUDGFX); + + sprintf(buffer, "K_DSPNMx"); + for (i = 0; i < 10; i++) + { + buffer[7] = '0'+(i%10); + skp_dialnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + } + + // KartZ speedo + if (kartz_speedo) + { + const char* patchNames[] = { + "K_KZSP1", "K_KZSP2", "K_KZSP3", "K_KZSP4", "K_KZSP5", + "K_KZSP6", "K_KZSP7", "K_KZSP8", "K_KZSP9", "K_KZSP10", + "K_KZSP11", "K_KZSP12", "K_KZSP13", "K_KZSP14", "K_KZSP15", + "K_KZSP16", "K_KZSP17", "K_KZSP18", "K_KZSP19", "K_KZSP20", + "K_KZSP21", "K_KZSP22", "K_KZSP23", "K_KZSP24", "K_KZSP25" + }; + + for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) + { + kp_kartzspeedo[m] = (patch_t *)W_CachePatchName(patchNames[m], PU_HUDGFX); + } + } + + if (kartz_speedo_smol) + { + const char* patchNames[] = { + "K_KZSS1", "K_KZSS2", "K_KZSS3", "K_KZSS4", "K_KZSS5", + "K_KZSS6", "K_KZSS7", "K_KZSS8", "K_KZSS9", "K_KZSS10", + "K_KZSS11", "K_KZSS12", "K_KZSS13", "K_KZSS14", "K_KZSS15", + "K_KZSS16", "K_KZSS17", "K_KZSS18", "K_KZSS19", "K_KZSS20", + "K_KZSS21", "K_KZSS22", "K_KZSS23", "K_KZSS24", "K_KZSS25" + }; + + for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) + { + kp_kartzspeedo_smol[m] = (patch_t *)W_CachePatchName(patchNames[m], PU_HUDGFX); + } + } + + if (big_lap) + { + kp_lapstickerbig = (patch_t *)W_CachePatchName("K_STLAPB", PU_HUDGFX); + kp_lapstickerbig2 = (patch_t *)W_CachePatchName("K_STLA2B", PU_HUDGFX); + } + + // Nametags + if (nametaggfx) + { + nametagpic = (patch_t *)W_CachePatchName("NTLINE", PU_HUDGFX); + nametagline = (patch_t *)W_CachePatchName("NTLINEV", PU_HUDGFX); + nametagspeed = (patch_t *)W_CachePatchName("NTSP", PU_HUDGFX); + nametagweight = (patch_t *)W_CachePatchName("NTWH", PU_HUDGFX); + } + + if (driftgaugegfx) + { + driftgauge = (patch_t *)W_CachePatchName("K_DGAU", PU_HUDGFX); + driftgaugesmall = (patch_t *)W_CachePatchName("K_DGSU", PU_HUDGFX); + + if (driftgaugegfx_clr) + { + driftgaugecolor = (patch_t *)W_CachePatchName("K_DCAU", PU_HUDGFX); + driftgaugesmallcolor = (patch_t *)W_CachePatchName("K_DCSU", PU_HUDGFX); + } + } + + if (joystickicon) + { + joybacking = (patch_t *)W_CachePatchName("JOYBCK", PU_HUDGFX); + joyknob = (patch_t *)W_CachePatchName("JOYKNB", PU_HUDGFX); + joyshadow = (patch_t *)W_CachePatchName("JOYSHD", PU_HUDGFX); + } + + if (minidoticon) + { + kp_minimapdot = (patch_t *)W_CachePatchName("MMAPDOT", PU_HUDGFX); + } + + if (multiitem_icon) + { + kp_multsneaker[0] = (patch_t *)W_CachePatchName("K_ITSHO2", PU_HUDGFX); + kp_multsneaker[1] = (patch_t *)W_CachePatchName("K_ITSHO3", PU_HUDGFX); + kp_multbanana[0] = (patch_t *)W_CachePatchName("K_ITBAN2", PU_HUDGFX); + kp_multbanana[1] = (patch_t *)W_CachePatchName("K_ITBAN3", PU_HUDGFX); + kp_multbanana[2] = (patch_t *)W_CachePatchName("K_ITBAN4", PU_HUDGFX); + kp_multjawz = (patch_t *)W_CachePatchName("K_ITJAW2", PU_HUDGFX); + } + } + + if (found_extra2_kart) + { + if (xtra_speedo_clr) + { + skp_smallstickerclr = (patch_t *)W_CachePatchName("SC_SMSTC", PU_HUDGFX); + } + + if (xtra_speedo_clr3) + { + skp_smallstickerclr3 = (patch_t *)W_CachePatchName("SC_SM3TC", PU_HUDGFX); + } + + if (achi_speedo_clr) + { + skp_smallstickerachiclr = (patch_t *)W_CachePatchName("SC_AMSTC", PU_HUDGFX); + skp_speedpatchesachiclr[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesachiclr[1] = (patch_t *)W_CachePatchName("SC_AKMH", PU_HUDGFX); + skp_speedpatchesachiclr[2] = (patch_t *)W_CachePatchName("SC_AMPH", PU_HUDGFX); + skp_speedpatchesachiclr[3] = (patch_t *)W_CachePatchName("SC_AFRAC", PU_HUDGFX); + skp_speedpatchesachiclr[4] = (patch_t *)W_CachePatchName("SC_APERC", PU_HUDGFX); + } + + if (dial_speedo_clr) + { + skp_dialbaseclr[0] = (patch_t *)W_CachePatchName("K_DSPBC1", PU_HUDGFX); + skp_dialbaseclr[1] = (patch_t *)W_CachePatchName("K_DSPBC2", PU_HUDGFX); + + skp_speedpatchesdialclr[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesdialclr[1] = (patch_t *)W_CachePatchName("SC_DKMH", PU_HUDGFX); + skp_speedpatchesdialclr[2] = (patch_t *)W_CachePatchName("SC_DMPH", PU_HUDGFX); + skp_speedpatchesdialclr[3] = (patch_t *)W_CachePatchName("SC_DFRAC", PU_HUDGFX); + skp_speedpatchesdialclr[4] = (patch_t *)W_CachePatchName("SC_DPERC", PU_HUDGFX); + + sprintf(buffer, "K_DSPNCx"); + for (i = 0; i < 10; i++) + { + buffer[7] = '0'+(i%10); + skp_dialnumclr[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + } + + if (big_lap_color) + { + kp_lapstickerbigclr = (patch_t *)W_CachePatchName("K_SCLAPB", PU_HUDGFX); + kp_lapstickerbig2clr = (patch_t *)W_CachePatchName("K_SCLA2B", PU_HUDGFX); + } + + // Colourized hud + if (clr_hud) + { + kp_timestickerclr = (patch_t *)W_CachePatchName("K_SCTIME", PU_HUDGFX); + kp_timestickerwideclr = (patch_t *)W_CachePatchName("K_SCTIMW", PU_HUDGFX); + kp_lapstickerclr = (patch_t *)W_CachePatchName("K_SCLAPS", PU_HUDGFX); + kp_lapstickerwideclr = (patch_t *)W_CachePatchName("K_SCLAPW", PU_HUDGFX); + kp_bumperstickerclr = (patch_t *)W_CachePatchName("K_SCBALN", PU_HUDGFX); + kp_bumperstickerwideclr = (patch_t *)W_CachePatchName("K_SCBALW", PU_HUDGFX); + kp_karmastickerclr = (patch_t *)W_CachePatchName("K_SCKARM", PU_HUDGFX); + kp_timeoutstickerclr = (patch_t *)W_CachePatchName("K_SCTOUT", PU_HUDGFX); + kp_itembgclr[0] = (patch_t *)W_CachePatchName("K_ITBC" , PU_HUDGFX); + kp_itembgclr[1] = (patch_t *)W_CachePatchName("K_ITBCD" , PU_HUDGFX); + kp_itembgclr[2] = (patch_t *)W_CachePatchName("K_ISBC" , PU_HUDGFX); + kp_itembgclr[3] = (patch_t *)W_CachePatchName("K_ISBCD" , PU_HUDGFX); + kp_itemmulstickerclr[1] = (patch_t *)W_CachePatchName("K_ISMULC", PU_HUDGFX); + kp_itemmulstickerclr[0] = (patch_t *)W_CachePatchName("K_ITMULC", PU_HUDGFX); + } + } + + if (found_extra3_kart) + { + if (xtra_speedo3) // 80x11 patch scaled to size + { + skp_smallsticker3 = (patch_t *)W_CachePatchName("SP_SM3TC", PU_HUDGFX); + } + } +} + +// -- Kart patches -- + +static patch_t *kp_nodraw; static patch_t *kp_timesticker; static patch_t *kp_timestickerwide; static patch_t *kp_lapsticker; -static patch_t *kp_lapstickerbig; -static patch_t *kp_lapstickerbig2; static patch_t *kp_lapstickerwide; //static patch_t *kp_lapstickernarrow; static patch_t *kp_splitlapflag; @@ -7559,27 +7837,6 @@ static patch_t *kp_karmasticker; static patch_t *kp_splitkarmabomb; static patch_t *kp_timeoutsticker; -//Colourized hud -static patch_t *kp_timestickerclr; -static patch_t *kp_timestickerwideclr; -static patch_t *kp_lapstickerclr; -static patch_t *kp_lapstickerbigclr; -static patch_t *kp_lapstickerbig2clr; -static patch_t *kp_lapstickerwideclr; -//static patch_t *kp_lapstickernarrowclr; -static patch_t *kp_bumperstickerclr; -static patch_t *kp_bumperstickerwideclr; -static patch_t *kp_karmastickerclr; -static patch_t *kp_timeoutstickerclr; -static patch_t *skp_smallstickerclr; -static patch_t *skp_smallstickerclr3; -static patch_t *kp_itemmulstickerclr[2]; -static patch_t *kp_itembgclr[4]; - -//Kartz speedo -static patch_t *kp_kartzspeedo[25]; -static patch_t *kp_kartzspeedo_smol[25]; - static patch_t *kp_startcountdown[16]; static patch_t *kp_racefinish[6]; @@ -7608,15 +7865,12 @@ static patch_t *kp_itemmulsticker[2]; static patch_t *kp_itemx; static patch_t *kp_sneaker[2]; -static patch_t *kp_multsneaker[2]; static patch_t *kp_rocketsneaker[2]; static patch_t *kp_invincibility[13]; static patch_t *kp_banana[2]; -static patch_t *kp_multbanana[3]; static patch_t *kp_eggman[2]; static patch_t *kp_orbinaut[5]; static patch_t *kp_jawz[2]; -static patch_t *kp_multjawz[1]; static patch_t *kp_mine[2]; static patch_t *kp_ballhog[2]; static patch_t *kp_selfpropelledbomb[2]; @@ -7643,264 +7897,60 @@ static patch_t *kp_lapanim_number[10][3]; static patch_t *kp_lapanim_emblem[2]; static patch_t *kp_lapanim_hand[3]; -static patch_t *nametagpic; -static patch_t *nametagline; -static patch_t *nametagspeed; -static patch_t *nametagweight; - -static patch_t *driftgauge; -static patch_t *driftgaugecolor; -static patch_t *driftgaugesmall; -static patch_t *driftgaugesmallcolor; - static patch_t *kp_yougotem; -static patch_t *skp_smallsticker; -static patch_t *skp_smallsticker3; -static patch_t *skp_speedpatches[5]; - -static patch_t *skp_smallstickerachi; -static patch_t *skp_speedpatchesachi[5]; -static patch_t *skp_smallstickerachiclr; -static patch_t *skp_speedpatchesachiclr[5]; - -// dial speedometer -static patch_t *skp_rankfinish; -static patch_t *skp_dialbase[2]; -static patch_t *skp_speedpatchesdial[5]; -static patch_t *skp_dialnum[10]; -//static patch_t *skp_dialclr; -static patch_t *skp_dialbaseclr[2]; -static patch_t *skp_speedpatchesdialclr[5]; -static patch_t *skp_dialnumclr[10]; - -static patch_t *joybacking; -static patch_t *joyknob; -static patch_t *joyshadow; - -static patch_t *kp_minimapdot; - void K_LoadKartHUDGraphics(void) { INT32 i, j; char buffer[9]; // Null Stuff - kp_nodraw = W_CachePatchName("K_TRNULL", PU_HUDGFX); + kp_nodraw = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // Stickers - kp_timesticker = W_CachePatchName("K_STTIME", PU_HUDGFX); - kp_timestickerwide = W_CachePatchName("K_STTIMW", PU_HUDGFX); - kp_lapsticker = W_CachePatchName("K_STLAPS", PU_HUDGFX); - kp_lapstickerwide = W_CachePatchName("K_STLAPW", PU_HUDGFX); - //kp_lapstickernarrow = W_CachePatchName("K_STLAPN", PU_HUDGFX); - kp_splitlapflag = W_CachePatchName("K_SPTLAP", PU_HUDGFX); - kp_bumpersticker = W_CachePatchName("K_STBALN", PU_HUDGFX); - kp_bumperstickerwide = W_CachePatchName("K_STBALW", PU_HUDGFX); - kp_karmasticker = W_CachePatchName("K_STKARM", PU_HUDGFX); - kp_splitkarmabomb = W_CachePatchName("K_SPTKRM", PU_HUDGFX); - kp_timeoutsticker = W_CachePatchName("K_STTOUT", PU_HUDGFX); - - if (xtra_speedo) // snowy speedometer - { - skp_smallsticker = W_CachePatchName("SP_SMSTC", PU_HUDGFX); - skp_speedpatches[0] = W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatches[1] = W_CachePatchName("SP_MKMH", PU_HUDGFX); - skp_speedpatches[2] = W_CachePatchName("SP_MMPH", PU_HUDGFX); - skp_speedpatches[3] = W_CachePatchName("SP_MFRAC", PU_HUDGFX); - skp_speedpatches[4] = W_CachePatchName("SP_MPERC", PU_HUDGFX); - } - - if (xtra_speedo3) // 80x11 patch scaled to size - { - skp_smallsticker3 = W_CachePatchName("SP_SM3TC", PU_HUDGFX); - } - - if (achi_speedo) - { - skp_smallstickerachi = W_CachePatchName("SP_AMSTC", PU_HUDGFX); - skp_speedpatchesachi[0] = W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesachi[1] = W_CachePatchName("SP_AKMH", PU_HUDGFX); - skp_speedpatchesachi[2] = W_CachePatchName("SP_AMPH", PU_HUDGFX); - skp_speedpatchesachi[3] = W_CachePatchName("SP_AFRAC", PU_HUDGFX); - skp_speedpatchesachi[4] = W_CachePatchName("SP_APERC", PU_HUDGFX); - } - - if (dial_speedo) - { - skp_rankfinish = W_CachePatchName("RANKFIN", PU_HUDGFX); - skp_dialbase[0] = W_CachePatchName("K_DSPBS1", PU_HUDGFX); - skp_dialbase[1] = W_CachePatchName("K_DSPBS2", PU_HUDGFX); - - skp_speedpatchesdial[0] = W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesdial[1] = W_CachePatchName("SP_DKMH", PU_HUDGFX); - skp_speedpatchesdial[2] = W_CachePatchName("SP_DMPH", PU_HUDGFX); - skp_speedpatchesdial[3] = W_CachePatchName("SP_DFRAC", PU_HUDGFX); - skp_speedpatchesdial[4] = W_CachePatchName("SP_DPERC", PU_HUDGFX); - - sprintf(buffer, "K_DSPNMx"); - for (i = 0; i < 10; i++) - { - buffer[7] = '0'+(i%10); - skp_dialnum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); - } - } - - if (big_lap) - { - kp_lapstickerbig = W_CachePatchName("K_STLAPB", PU_HUDGFX); - kp_lapstickerbig2 = W_CachePatchName("K_STLA2B", PU_HUDGFX); - } - - // Colourized hud - if (clr_hud) - { - kp_timestickerclr = W_CachePatchName("K_SCTIME", PU_HUDGFX); - kp_timestickerwideclr = W_CachePatchName("K_SCTIMW", PU_HUDGFX); - kp_lapstickerclr = W_CachePatchName("K_SCLAPS", PU_HUDGFX); - kp_lapstickerwideclr = W_CachePatchName("K_SCLAPW", PU_HUDGFX); - kp_bumperstickerclr = W_CachePatchName("K_SCBALN", PU_HUDGFX); - kp_bumperstickerwideclr = W_CachePatchName("K_SCBALW", PU_HUDGFX); - kp_karmastickerclr = W_CachePatchName("K_SCKARM", PU_HUDGFX); - kp_timeoutstickerclr = W_CachePatchName("K_SCTOUT", PU_HUDGFX); - kp_itembgclr[0] = W_CachePatchName("K_ITBC" , PU_HUDGFX); - kp_itembgclr[1] = W_CachePatchName("K_ITBCD" , PU_HUDGFX); - kp_itembgclr[2] = W_CachePatchName("K_ISBC" , PU_HUDGFX); - kp_itembgclr[3] = W_CachePatchName("K_ISBCD" , PU_HUDGFX); - kp_itemmulstickerclr[1] = W_CachePatchName("K_ISMULC", PU_HUDGFX); - kp_itemmulstickerclr[0] = W_CachePatchName("K_ITMULC", PU_HUDGFX); - } - - if (big_lap_color) - { - kp_lapstickerbigclr = W_CachePatchName("K_SCLAPB", PU_HUDGFX); - kp_lapstickerbig2clr = W_CachePatchName("K_SCLA2B", PU_HUDGFX); - } - - if (xtra_speedo && xtra_speedo_clr) - skp_smallstickerclr = W_CachePatchName("SC_SMSTC", PU_HUDGFX); - - if (xtra_speedo3 && xtra_speedo_clr3) // 80x11 patch scaled to size - skp_smallstickerclr3 = W_CachePatchName("SC_SM3TC", PU_HUDGFX); - - if (achi_speedo && achi_speedo_clr) - { - skp_smallstickerachiclr = W_CachePatchName("SC_AMSTC", PU_HUDGFX); - skp_speedpatchesachiclr[0] = W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesachiclr[1] = W_CachePatchName("SC_AKMH", PU_HUDGFX); - skp_speedpatchesachiclr[2] = W_CachePatchName("SC_AMPH", PU_HUDGFX); - skp_speedpatchesachiclr[3] = W_CachePatchName("SC_AFRAC", PU_HUDGFX); - skp_speedpatchesachiclr[4] = W_CachePatchName("SC_APERC", PU_HUDGFX); - } - - if (dial_speedo && dial_speedo_clr) - { - skp_dialbaseclr[0] = W_CachePatchName("K_DSPBC1", PU_HUDGFX); - skp_dialbaseclr[1] = W_CachePatchName("K_DSPBC2", PU_HUDGFX); - - skp_speedpatchesdialclr[0] = W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesdialclr[1] = W_CachePatchName("SC_DKMH", PU_HUDGFX); - skp_speedpatchesdialclr[2] = W_CachePatchName("SC_DMPH", PU_HUDGFX); - skp_speedpatchesdialclr[3] = W_CachePatchName("SC_DFRAC", PU_HUDGFX); - skp_speedpatchesdialclr[4] = W_CachePatchName("SC_DPERC", PU_HUDGFX); - - sprintf(buffer, "K_DSPNCx"); - for (i = 0; i < 10; i++) - { - buffer[7] = '0'+(i%10); - skp_dialnumclr[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); - } - } - - // KartZ speedo - if (kartz_speedo) - { - const char* patchNames[] = { - "K_KZSP1", "K_KZSP2", "K_KZSP3", "K_KZSP4", "K_KZSP5", - "K_KZSP6", "K_KZSP7", "K_KZSP8", "K_KZSP9", "K_KZSP10", - "K_KZSP11", "K_KZSP12", "K_KZSP13", "K_KZSP14", "K_KZSP15", - "K_KZSP16", "K_KZSP17", "K_KZSP18", "K_KZSP19", "K_KZSP20", - "K_KZSP21", "K_KZSP22", "K_KZSP23", "K_KZSP24", "K_KZSP25" - }; - - for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) - { - kp_kartzspeedo[m] = W_CachePatchName(patchNames[m], PU_HUDGFX); - } - } - - if (kartz_speedo_smol) - { - const char* patchNames[] = { - "K_KZSS1", "K_KZSS2", "K_KZSS3", "K_KZSS4", "K_KZSS5", - "K_KZSS6", "K_KZSS7", "K_KZSS8", "K_KZSS9", "K_KZSS10", - "K_KZSS11", "K_KZSS12", "K_KZSS13", "K_KZSS14", "K_KZSS15", - "K_KZSS16", "K_KZSS17", "K_KZSS18", "K_KZSS19", "K_KZSS20", - "K_KZSS21", "K_KZSS22", "K_KZSS23", "K_KZSS24", "K_KZSS25" - }; - - for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) - { - kp_kartzspeedo_smol[m] = W_CachePatchName(patchNames[m], PU_HUDGFX); - } - } - - // Nametags - if (nametaggfx) - { - nametagpic = W_CachePatchName("NTLINE", PU_HUDGFX); - nametagline = W_CachePatchName("NTLINEV", PU_HUDGFX); - nametagspeed = W_CachePatchName("NTSP", PU_HUDGFX); - nametagweight = W_CachePatchName("NTWH", PU_HUDGFX); - } - - if (driftgaugegfx) - { - driftgauge = W_CachePatchName("K_DGAU", PU_HUDGFX); - driftgaugecolor = W_CachePatchName("K_DCAU", PU_HUDGFX); - } - - if (driftgaugegfx_clr) - { - driftgaugesmall = W_CachePatchName("K_DGSU", PU_HUDGFX); - driftgaugesmallcolor = W_CachePatchName("K_DCSU", PU_HUDGFX); - } - - if (joystickicon) - { - joybacking = W_CachePatchName("JOYBCK", PU_HUDGFX); - joyknob = W_CachePatchName("JOYKNB", PU_HUDGFX); - joyshadow = W_CachePatchName("JOYSHD", PU_HUDGFX); - } + kp_timesticker = (patch_t *)W_CachePatchName("K_STTIME", PU_HUDGFX); + kp_timestickerwide = (patch_t *)W_CachePatchName("K_STTIMW", PU_HUDGFX); + kp_lapsticker = (patch_t *)W_CachePatchName("K_STLAPS", PU_HUDGFX); + kp_lapstickerwide = (patch_t *)W_CachePatchName("K_STLAPW", PU_HUDGFX); + //kp_lapstickernarrow = (patch_t *)W_CachePatchName("K_STLAPN", PU_HUDGFX); + kp_splitlapflag = (patch_t *)W_CachePatchName("K_SPTLAP", PU_HUDGFX); + kp_bumpersticker = (patch_t *)W_CachePatchName("K_STBALN", PU_HUDGFX); + kp_bumperstickerwide = (patch_t *)W_CachePatchName("K_STBALW", PU_HUDGFX); + kp_karmasticker = (patch_t *)W_CachePatchName("K_STKARM", PU_HUDGFX); + kp_splitkarmabomb = (patch_t *)W_CachePatchName("K_SPTKRM", PU_HUDGFX); + kp_timeoutsticker = (patch_t *)W_CachePatchName("K_STTOUT", PU_HUDGFX); // Starting countdown - kp_startcountdown[0] = W_CachePatchName("K_CNT3A", PU_HUDGFX); - kp_startcountdown[1] = W_CachePatchName("K_CNT2A", PU_HUDGFX); - kp_startcountdown[2] = W_CachePatchName("K_CNT1A", PU_HUDGFX); - kp_startcountdown[3] = W_CachePatchName("K_CNTGOA", PU_HUDGFX); - kp_startcountdown[4] = W_CachePatchName("K_CNT3B", PU_HUDGFX); - kp_startcountdown[5] = W_CachePatchName("K_CNT2B", PU_HUDGFX); - kp_startcountdown[6] = W_CachePatchName("K_CNT1B", PU_HUDGFX); - kp_startcountdown[7] = W_CachePatchName("K_CNTGOB", PU_HUDGFX); + kp_startcountdown[0] = (patch_t *)W_CachePatchName("K_CNT3A", PU_HUDGFX); + kp_startcountdown[1] = (patch_t *)W_CachePatchName("K_CNT2A", PU_HUDGFX); + kp_startcountdown[2] = (patch_t *)W_CachePatchName("K_CNT1A", PU_HUDGFX); + kp_startcountdown[3] = (patch_t *)W_CachePatchName("K_CNTGOA", PU_HUDGFX); + kp_startcountdown[4] = (patch_t *)W_CachePatchName("K_CNT3B", PU_HUDGFX); + kp_startcountdown[5] = (patch_t *)W_CachePatchName("K_CNT2B", PU_HUDGFX); + kp_startcountdown[6] = (patch_t *)W_CachePatchName("K_CNT1B", PU_HUDGFX); + kp_startcountdown[7] = (patch_t *)W_CachePatchName("K_CNTGOB", PU_HUDGFX); + // Splitscreen - kp_startcountdown[8] = W_CachePatchName("K_SMC3A", PU_HUDGFX); - kp_startcountdown[9] = W_CachePatchName("K_SMC2A", PU_HUDGFX); - kp_startcountdown[10] = W_CachePatchName("K_SMC1A", PU_HUDGFX); - kp_startcountdown[11] = W_CachePatchName("K_SMCGOA", PU_HUDGFX); - kp_startcountdown[12] = W_CachePatchName("K_SMC3B", PU_HUDGFX); - kp_startcountdown[13] = W_CachePatchName("K_SMC2B", PU_HUDGFX); - kp_startcountdown[14] = W_CachePatchName("K_SMC1B", PU_HUDGFX); - kp_startcountdown[15] = W_CachePatchName("K_SMCGOB", PU_HUDGFX); + kp_startcountdown[8] = (patch_t *)W_CachePatchName("K_SMC3A", PU_HUDGFX); + kp_startcountdown[9] = (patch_t *)W_CachePatchName("K_SMC2A", PU_HUDGFX); + kp_startcountdown[10] = (patch_t *)W_CachePatchName("K_SMC1A", PU_HUDGFX); + kp_startcountdown[11] = (patch_t *)W_CachePatchName("K_SMCGOA", PU_HUDGFX); + kp_startcountdown[12] = (patch_t *)W_CachePatchName("K_SMC3B", PU_HUDGFX); + kp_startcountdown[13] = (patch_t *)W_CachePatchName("K_SMC2B", PU_HUDGFX); + kp_startcountdown[14] = (patch_t *)W_CachePatchName("K_SMC1B", PU_HUDGFX); + kp_startcountdown[15] = (patch_t *)W_CachePatchName("K_SMCGOB", PU_HUDGFX); // Finish - kp_racefinish[0] = W_CachePatchName("K_FINA", PU_HUDGFX); - kp_racefinish[1] = W_CachePatchName("K_FINB", PU_HUDGFX); + kp_racefinish[0] = (patch_t *)W_CachePatchName("K_FINA", PU_HUDGFX); + kp_racefinish[1] = (patch_t *)W_CachePatchName("K_FINB", PU_HUDGFX); + // Splitscreen - kp_racefinish[2] = W_CachePatchName("K_SMFINA", PU_HUDGFX); - kp_racefinish[3] = W_CachePatchName("K_SMFINB", PU_HUDGFX); + kp_racefinish[2] = (patch_t *)W_CachePatchName("K_SMFINA", PU_HUDGFX); + kp_racefinish[3] = (patch_t *)W_CachePatchName("K_SMFINB", PU_HUDGFX); + // 2P splitscreen - kp_racefinish[4] = W_CachePatchName("K_2PFINA", PU_HUDGFX); - kp_racefinish[5] = W_CachePatchName("K_2PFINB", PU_HUDGFX); + kp_racefinish[4] = (patch_t *)W_CachePatchName("K_2PFINA", PU_HUDGFX); + kp_racefinish[5] = (patch_t *)W_CachePatchName("K_2PFINB", PU_HUDGFX); // Position numbers sprintf(buffer, "K_POSNxx"); @@ -7909,9 +7959,8 @@ void K_LoadKartHUDGraphics(void) buffer[6] = '0'+i; for (j = 0; j < NUMPOSFRAMES; j++) { - //sprintf(buffer, "K_POSN%d%d", i, j); buffer[7] = '0'+j; - kp_positionnum[i][j] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_positionnum[i][j] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } } @@ -7919,7 +7968,7 @@ void K_LoadKartHUDGraphics(void) for (i = 0; i < NUMWINFRAMES; i++) { buffer[7] = '0'+i; - kp_winnernum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_winnernum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } sprintf(buffer, "OPPRNKxx"); @@ -7927,122 +7976,105 @@ void K_LoadKartHUDGraphics(void) { buffer[6] = '0'+(i/10); buffer[7] = '0'+(i%10); - kp_facenum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_facenum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } sprintf(buffer, "K_CHILIx"); for (i = 0; i < 8; i++) { buffer[7] = '0'+(i+1); - kp_facehighlight[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_facehighlight[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } // Extra ranking icons - kp_rankbumper = W_CachePatchName("K_BLNICO", PU_HUDGFX); - kp_tinybumper[0] = W_CachePatchName("K_BLNA", PU_HUDGFX); - kp_tinybumper[1] = W_CachePatchName("K_BLNB", PU_HUDGFX); - kp_ranknobumpers = W_CachePatchName("K_NOBLNS", PU_HUDGFX); + kp_rankbumper = (patch_t *)W_CachePatchName("K_BLNICO", PU_HUDGFX); + kp_tinybumper[0] = (patch_t *)W_CachePatchName("K_BLNA", PU_HUDGFX); + kp_tinybumper[1] = (patch_t *)W_CachePatchName("K_BLNB", PU_HUDGFX); + kp_ranknobumpers = (patch_t *)W_CachePatchName("K_NOBLNS", PU_HUDGFX); // Battle graphics - kp_battlewin = W_CachePatchName("K_BWIN", PU_HUDGFX); - kp_battlecool = W_CachePatchName("K_BCOOL", PU_HUDGFX); - kp_battlelose = W_CachePatchName("K_BLOSE", PU_HUDGFX); - kp_battlewait = W_CachePatchName("K_BWAIT", PU_HUDGFX); - kp_battleinfo = W_CachePatchName("K_BINFO", PU_HUDGFX); - kp_wanted = W_CachePatchName("K_WANTED", PU_HUDGFX); - kp_wantedsplit = W_CachePatchName("4PWANTED", PU_HUDGFX); - kp_wantedreticle = W_CachePatchName("MMAPWANT", PU_HUDGFX); - - if (minidoticon) - kp_minimapdot = W_CachePatchName("MMAPDOT", PU_HUDGFX); + kp_battlewin = (patch_t *)W_CachePatchName("K_BWIN", PU_HUDGFX); + kp_battlecool = (patch_t *)W_CachePatchName("K_BCOOL", PU_HUDGFX); + kp_battlelose = (patch_t *)W_CachePatchName("K_BLOSE", PU_HUDGFX); + kp_battlewait = (patch_t *)W_CachePatchName("K_BWAIT", PU_HUDGFX); + kp_battleinfo = (patch_t *)W_CachePatchName("K_BINFO", PU_HUDGFX); + kp_wanted = (patch_t *)W_CachePatchName("K_WANTED", PU_HUDGFX); + kp_wantedsplit = (patch_t *)W_CachePatchName("4PWANTED", PU_HUDGFX); + kp_wantedreticle = (patch_t *)W_CachePatchName("MMAPWANT", PU_HUDGFX); // Kart Item Windows - kp_itembg[0] = W_CachePatchName("K_ITBG", PU_HUDGFX); - kp_itembg[1] = W_CachePatchName("K_ITBGD", PU_HUDGFX); - kp_itemtimer[0] = W_CachePatchName("K_ITIMER", PU_HUDGFX); - kp_itemmulsticker[0] = W_CachePatchName("K_ITMUL", PU_HUDGFX); - kp_itemx = W_CachePatchName("K_ITX", PU_HUDGFX); + kp_itembg[0] = (patch_t *)W_CachePatchName("K_ITBG", PU_HUDGFX); + kp_itembg[1] = (patch_t *)W_CachePatchName("K_ITBGD", PU_HUDGFX); + kp_itemtimer[0] = (patch_t *)W_CachePatchName("K_ITIMER", PU_HUDGFX); + kp_itemmulsticker[0] = (patch_t *)W_CachePatchName("K_ITMUL", PU_HUDGFX); + kp_itemx = (patch_t *)W_CachePatchName("K_ITX", PU_HUDGFX); + // Splitscreen + kp_itembg[2] = (patch_t *)W_CachePatchName("K_ISBG", PU_HUDGFX); + kp_itembg[3] = (patch_t *)W_CachePatchName("K_ISBGD", PU_HUDGFX); + kp_itemtimer[1] = (patch_t *)W_CachePatchName("K_ISIMER", PU_HUDGFX); + kp_itemmulsticker[1] = (patch_t *)W_CachePatchName("K_ISMUL", PU_HUDGFX); - kp_sneaker[0] = W_CachePatchName("K_ITSHOE", PU_HUDGFX); - if (multiitem_icon) - { - kp_multsneaker[0] = W_CachePatchName("K_ITSHO2", PU_HUDGFX); - kp_multsneaker[1] = W_CachePatchName("K_ITSHO3", PU_HUDGFX); - } - kp_rocketsneaker[0] = W_CachePatchName("K_ITRSHE", PU_HUDGFX); + // Kart Items + kp_sneaker[0] = (patch_t *)W_CachePatchName("K_ITSHOE", PU_HUDGFX); + kp_rocketsneaker[0] = (patch_t *)W_CachePatchName("K_ITRSHE", PU_HUDGFX); + kp_banana[0] = (patch_t *)W_CachePatchName("K_ITBANA", PU_HUDGFX); + kp_eggman[0] = (patch_t *)W_CachePatchName("K_ITEGGM", PU_HUDGFX); + kp_jawz[0] = (patch_t *)W_CachePatchName("K_ITJAWZ", PU_HUDGFX); + kp_mine[0] = (patch_t *)W_CachePatchName("K_ITMINE", PU_HUDGFX); + kp_ballhog[0] = (patch_t *)W_CachePatchName("K_ITBHOG", PU_HUDGFX); + kp_selfpropelledbomb[0] = (patch_t *)W_CachePatchName("K_ITSPB", PU_HUDGFX); + kp_grow[0] = (patch_t *)W_CachePatchName("K_ITGROW", PU_HUDGFX); + kp_shrink[0] = (patch_t *)W_CachePatchName("K_ITSHRK", PU_HUDGFX); + kp_thundershield[0] = (patch_t *)W_CachePatchName("K_ITTHNS", PU_HUDGFX); + kp_hyudoro[0] = (patch_t *)W_CachePatchName("K_ITHYUD", PU_HUDGFX); + kp_pogospring[0] = (patch_t *)W_CachePatchName("K_ITPOGO", PU_HUDGFX); + kp_kitchensink[0] = (patch_t *)W_CachePatchName("K_ITSINK", PU_HUDGFX); + kp_sadface[0] = (patch_t *)W_CachePatchName("K_ITSAD", PU_HUDGFX); + // Splitscreen + kp_sneaker[1] = (patch_t *)W_CachePatchName("K_ISSHOE", PU_HUDGFX); + kp_rocketsneaker[1] = (patch_t *)W_CachePatchName("K_ISRSHE", PU_HUDGFX); + kp_banana[1] = (patch_t *)W_CachePatchName("K_ISBANA", PU_HUDGFX); + kp_eggman[1] = (patch_t *)W_CachePatchName("K_ISEGGM", PU_HUDGFX); + kp_orbinaut[4] = (patch_t *)W_CachePatchName("K_ISORBN", PU_HUDGFX); + kp_jawz[1] = (patch_t *)W_CachePatchName("K_ISJAWZ", PU_HUDGFX); + kp_mine[1] = (patch_t *)W_CachePatchName("K_ISMINE", PU_HUDGFX); + kp_ballhog[1] = (patch_t *)W_CachePatchName("K_ISBHOG", PU_HUDGFX); + kp_selfpropelledbomb[1] = (patch_t *)W_CachePatchName("K_ISSPB", PU_HUDGFX); + kp_grow[1] = (patch_t *)W_CachePatchName("K_ISGROW", PU_HUDGFX); + kp_shrink[1] = (patch_t *)W_CachePatchName("K_ISSHRK", PU_HUDGFX); + kp_thundershield[1] = (patch_t *)W_CachePatchName("K_ISTHNS", PU_HUDGFX); + kp_hyudoro[1] = (patch_t *)W_CachePatchName("K_ISHYUD", PU_HUDGFX); + kp_pogospring[1] = (patch_t *)W_CachePatchName("K_ISPOGO", PU_HUDGFX); + kp_kitchensink[1] = (patch_t *)W_CachePatchName("K_ISSINK", PU_HUDGFX); + kp_sadface[1] = (patch_t *)W_CachePatchName("K_ISSAD", PU_HUDGFX); sprintf(buffer, "K_ITINVx"); for (i = 0; i < 7; i++) { buffer[7] = '1'+i; - kp_invincibility[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_invincibility[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - kp_banana[0] = W_CachePatchName("K_ITBANA", PU_HUDGFX); - if (multiitem_icon) - { - kp_multbanana[0] = W_CachePatchName("K_ITBAN2", PU_HUDGFX); - kp_multbanana[1] = W_CachePatchName("K_ITBAN3", PU_HUDGFX); - kp_multbanana[2] = W_CachePatchName("K_ITBAN4", PU_HUDGFX); - } - kp_eggman[0] = W_CachePatchName("K_ITEGGM", PU_HUDGFX); sprintf(buffer, "K_ITORBx"); for (i = 0; i < 4; i++) { buffer[7] = '1'+i; - kp_orbinaut[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_orbinaut[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - kp_jawz[0] = W_CachePatchName("K_ITJAWZ", PU_HUDGFX); - if (multiitem_icon) - { - kp_multjawz[0] = W_CachePatchName("K_ITJAW2", PU_HUDGFX); - } - kp_mine[0] = W_CachePatchName("K_ITMINE", PU_HUDGFX); - kp_ballhog[0] = W_CachePatchName("K_ITBHOG", PU_HUDGFX); - kp_selfpropelledbomb[0] = W_CachePatchName("K_ITSPB", PU_HUDGFX); - kp_grow[0] = W_CachePatchName("K_ITGROW", PU_HUDGFX); - kp_shrink[0] = W_CachePatchName("K_ITSHRK", PU_HUDGFX); - kp_thundershield[0] = W_CachePatchName("K_ITTHNS", PU_HUDGFX); - kp_hyudoro[0] = W_CachePatchName("K_ITHYUD", PU_HUDGFX); - kp_pogospring[0] = W_CachePatchName("K_ITPOGO", PU_HUDGFX); - kp_kitchensink[0] = W_CachePatchName("K_ITSINK", PU_HUDGFX); - kp_sadface[0] = W_CachePatchName("K_ITSAD", PU_HUDGFX); - // Splitscreen - kp_itembg[2] = W_CachePatchName("K_ISBG", PU_HUDGFX); - kp_itembg[3] = W_CachePatchName("K_ISBGD", PU_HUDGFX); - kp_itemtimer[1] = W_CachePatchName("K_ISIMER", PU_HUDGFX); - kp_itemmulsticker[1] = W_CachePatchName("K_ISMUL", PU_HUDGFX); - - kp_sneaker[1] = W_CachePatchName("K_ISSHOE", PU_HUDGFX); - kp_rocketsneaker[1] = W_CachePatchName("K_ISRSHE", PU_HUDGFX); sprintf(buffer, "K_ISINVx"); for (i = 0; i < 6; i++) { buffer[7] = '1'+i; - kp_invincibility[i+7] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_invincibility[i+7] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - kp_banana[1] = W_CachePatchName("K_ISBANA", PU_HUDGFX); - kp_eggman[1] = W_CachePatchName("K_ISEGGM", PU_HUDGFX); - kp_orbinaut[4] = W_CachePatchName("K_ISORBN", PU_HUDGFX); - kp_jawz[1] = W_CachePatchName("K_ISJAWZ", PU_HUDGFX); - kp_mine[1] = W_CachePatchName("K_ISMINE", PU_HUDGFX); - kp_ballhog[1] = W_CachePatchName("K_ISBHOG", PU_HUDGFX); - kp_selfpropelledbomb[1] = W_CachePatchName("K_ISSPB", PU_HUDGFX); - kp_grow[1] = W_CachePatchName("K_ISGROW", PU_HUDGFX); - kp_shrink[1] = W_CachePatchName("K_ISSHRK", PU_HUDGFX); - kp_thundershield[1] = W_CachePatchName("K_ISTHNS", PU_HUDGFX); - kp_hyudoro[1] = W_CachePatchName("K_ISHYUD", PU_HUDGFX); - kp_pogospring[1] = W_CachePatchName("K_ISPOGO", PU_HUDGFX); - kp_kitchensink[1] = W_CachePatchName("K_ISSINK", PU_HUDGFX); - kp_sadface[1] = W_CachePatchName("K_ISSAD", PU_HUDGFX); // CHECK indicators sprintf(buffer, "K_CHECKx"); for (i = 0; i < 6; i++) { buffer[7] = '1'+i; - kp_check[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_check[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } // Eggman warning numbers @@ -8050,20 +8082,20 @@ void K_LoadKartHUDGraphics(void) for (i = 0; i < 4; i++) { buffer[6] = '0'+i; - kp_eggnum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_eggnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } // First person mode - kp_fpview[0] = W_CachePatchName("VIEWA0", PU_HUDGFX); - kp_fpview[1] = W_CachePatchName("VIEWB0D0", PU_HUDGFX); - kp_fpview[2] = W_CachePatchName("VIEWC0E0", PU_HUDGFX); + kp_fpview[0] = (patch_t *)W_CachePatchName("VIEWA0", PU_HUDGFX); + kp_fpview[1] = (patch_t *)W_CachePatchName("VIEWB0D0", PU_HUDGFX); + kp_fpview[2] = (patch_t *)W_CachePatchName("VIEWC0E0", PU_HUDGFX); // Input UI Wheel sprintf(buffer, "K_WHEELx"); for (i = 0; i < 5; i++) { buffer[7] = '0'+i; - kp_inputwheel[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_inputwheel[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } // HERE COMES A NEW CHALLENGER @@ -8072,7 +8104,7 @@ void K_LoadKartHUDGraphics(void) { buffer[6] = '0'+((i+1)/10); buffer[7] = '0'+((i+1)%10); - kp_challenger[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_challenger[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } // Lap start animation @@ -8080,7 +8112,7 @@ void K_LoadKartHUDGraphics(void) for (i = 0; i < 7; i++) { buffer[6] = '0'+(i+1); - kp_lapanim_lap[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_lapanim_lap[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } sprintf(buffer, "K_LAPFxx"); @@ -8088,7 +8120,7 @@ void K_LoadKartHUDGraphics(void) { buffer[6] = '0'+((i+1)/10); buffer[7] = '0'+((i+1)%10); - kp_lapanim_final[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_lapanim_final[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } sprintf(buffer, "K_LAPNxx"); @@ -8098,7 +8130,7 @@ void K_LoadKartHUDGraphics(void) for (j = 0; j < 3; j++) { buffer[7] = '0'+(j+1); - kp_lapanim_number[i][j] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_lapanim_number[i][j] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } } @@ -8106,17 +8138,20 @@ void K_LoadKartHUDGraphics(void) for (i = 0; i < 2; i++) { buffer[7] = '0'+(i+1); - kp_lapanim_emblem[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_lapanim_emblem[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } sprintf(buffer, "K_LAPH0x"); for (i = 0; i < 3; i++) { buffer[7] = '0'+(i+1); - kp_lapanim_hand[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + kp_lapanim_hand[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - kp_yougotem = (patch_t *) W_CachePatchName("YOUGOTEM", PU_HUDGFX); + kp_yougotem = (patch_t *)W_CachePatchName("YOUGOTEM", PU_HUDGFX); + + if (found_extra_kart || found_extra2_kart || found_extra3_kart) + K_LoadSaturnHUDGraphics(); } // For the item toggle menu @@ -8596,7 +8631,6 @@ static void K_drawKartItem(void) patch_t *localinv = ((offset) ? kp_invincibility[((leveltime % (6*3)) / 3) + 7] : kp_invincibility[(leveltime % (7*3)) / 3]); INT32 fx = 0, fy = 0, fflags = 0; // final coords for hud and flags... - //INT32 splitflags = K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTOLEFT); INT32 numberdisplaymin = cv_huditemamount.value == 2 ? 1 : 2; // No longer a constant so other things can modify this value INT32 itembar = 0; INT32 maxl = 0; // itembar's normal highest value @@ -8606,10 +8640,6 @@ static void K_drawKartItem(void) UINT8 *colmap = NULL; UINT8 *colormap = NULL; - boolean flipamount = splitscreen > 1 && stplyrnum & 1; // Used for 3P/4P splitscreen to flip item amount stuff - - const boolean usemultiicon = (multiitem_icon && cv_multiitemicon.value && !offset); - if (stplyr->kartstuff[k_itemroulette]) { localcolor = K_GetHudColor(); @@ -8744,7 +8774,9 @@ static void K_drawKartItem(void) if (stplyr->kartstuff[k_itemamount] <= 0) return; - switch(stplyr->kartstuff[k_itemtype]) + const boolean usemultiicon = (multiitem_icon && cv_multiitemicon.value && !offset); + + switch (stplyr->kartstuff[k_itemtype]) { case KITEM_SNEAKER: if (usemultiicon) @@ -8815,7 +8847,7 @@ static void K_drawKartItem(void) { if (!cv_huditemamount.value) numberdisplaymin = 3; - localpatch = ((stplyr->kartstuff[k_itemamount] == 1) ? kp_jawz[offset] : kp_multjawz[0]); + localpatch = ((stplyr->kartstuff[k_itemamount] == 1) ? kp_jawz[offset] : kp_multjawz); } else { @@ -8888,6 +8920,8 @@ static void K_drawKartItem(void) fy = info.y; fflags = info.flags; + boolean flipamount = splitscreen > 1 && stplyrnum & 1; // Used for 3P/4P splitscreen to flip item amount stuff + if (K_UseColorHud()) colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); @@ -8960,7 +8994,6 @@ static void K_drawKartItem(void) // Quick Eggman numbers if (stplyr->kartstuff[k_eggmanexplode] > 1 /*&& stplyr->kartstuff[k_eggmanexplode] <= 3*TICRATE*/) V_DrawScaledPatch(fx+17, fy+13-offset, V_HUDTRANS|fflags, kp_eggnum[min(3, G_TicsToSeconds(stplyr->kartstuff[k_eggmanexplode]))]); - } void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UINT8 mode) @@ -8969,6 +9002,7 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UI // TIME_Y = 6; // 6 INT32 splitflags = 0; + if (!mode) { splitflags = V_HUDTRANS|K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTORIGHT); @@ -9115,17 +9149,15 @@ static void K_DrawKartPositionNum(INT32 num) // POSI_Y = BASEVIDHEIGHT- 64; // 136 const boolean wheeloffs = (cv_showinput.value && cv_posi_xoffset.value == 0 && cv_posi_yoffset.value == 0 && cv_wheel_xoffset.value == 0 && cv_wheel_yoffset.value == 0); - boolean win = (stplyr->exiting && num == 1); - //INT32 X = POSI_X; + const boolean win = (stplyr->exiting && num == 1); INT32 W = kp_positionnum[0][0]->width; fixed_t scale = FRACUNIT; patch_t *localpatch = kp_positionnum[0][0]; - //INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTORIGHT); INT32 fx = 0, fy = 0, fflags = 0; - INT32 xoffs = wheeloffs ? -48 : 0; - boolean flipdraw = false; // flip the order we draw it in for MORE splitscreen bs. fun. - boolean flipvdraw = false; // used only for 2p splitscreen so overtaking doesn't make 1P's position fly off the screen. - boolean overtake = false; + const INT32 xoffs = wheeloffs ? -48 : 0; + boolean flipdraw = false; // flip the order we draw it in for MORE splitscreen bs. fun. + boolean flipvdraw = false; // used only for 2p splitscreen so overtaking doesn't make 1P's position fly off the screen. + boolean overtake = false; if ((cv_posanim.value && stplyr->kartstuff[k_positiondelay]) || stplyr->exiting) { @@ -9388,7 +9420,7 @@ void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, I { INT32 i, rightoffset = 240; const UINT8 *colormap; - INT32 dupadjust = cv_betainterscreen.value ? 314 : (vid.width/vid.dupx), duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; + const INT32 dupadjust = cv_betainterscreen.value ? 314 : (vid.width/vid.dupx), duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; boolean (*_isHighlightedPlayer)(const player_t *) = (demo.playback ? P_IsDisplayPlayer : P_IsLocalPlayer); @@ -9507,9 +9539,9 @@ static boolean K_BigLap(void) static void K_drawKartLaps(void) { - INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); + const INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); INT32 fx = 0, fy = 0, fflags = 0; // stuff for 3p / 4p splitscreen. - boolean flipstring = splitscreen > 1 && stplyrnum & 1; // used for 3p or 4p + const boolean flipstring = splitscreen > 1 && stplyrnum & 1; // used for 3p or 4p INT32 stringw = 0; // used with the above const char *laps; @@ -9605,13 +9637,13 @@ static void K_DrawDialSpeedometer(fixed_t speed, boolean infoactive, boolean colorized) { - UINT8* colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + const UINT8* colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); INT32 rot = 0; - UINT8 infoidx = (infoactive) ? 1 : 0; + const UINT8 infoidx = (infoactive) ? 1 : 0; patch_t* dialpatch; - angle_t speedangle = + const angle_t speedangle = FixedAngle(((min(135 * FRACUNIT, FixedDiv(speed, divisor)) - (45 * FRACUNIT)))); rot = R_GetRollAngle(speedangle); @@ -9870,9 +9902,9 @@ static void K_drawKartSpeedometer(void) static void K_drawKartBumpersOrKarma(void) { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + const UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); INT32 fx, fy, fflags; - boolean flipstring = splitscreen > 1 && stplyrnum & 1; // same as laps, used for splitscreen + const boolean flipstring = splitscreen > 1 && stplyrnum & 1; // same as laps, used for splitscreen INT32 stringw = 0; // used with the above const char *bumpval = ""; @@ -10308,13 +10340,13 @@ static void K_drawDriftGauge(void) int i; UINT8 *cmap; - static UINT8 driftcolors[3][4] = { + static const UINT8 driftcolors[3][4] = { {0, 0, 10, 16}, // no drift {215, 215, 204, 253}, // blue {125, 125, 151, 159} // red }; - static UINT8 driftskins[3] = { + static const UINT8 driftskins[3] = { SKINCOLOR_NONE, SKINCOLOR_TEAL, SKINCOLOR_SALMON, @@ -10348,10 +10380,10 @@ skipcrap: fixed_t bary; INT32 BAR_WIDTH; - const INT32 driftval = K_GetKartDriftSparkValue(stplyr); + const INT32 driftval = K_GetKartDriftSparkValue(stplyr); const INT32 driftcharge = min(driftval*4, stplyr->kartstuff[k_driftcharge]); - const INT32 driftlevel = min(driftcharge / driftval, 2); - const INT32 drifttrans = ((cv_driftgaugetrans.value) ? V_LocalTransFlag() : 0); + const INT32 driftlevel = min(driftcharge / driftval, 2); + const INT32 drifttrans = ((cv_driftgaugetrans.value) ? V_LocalTransFlag() : 0); basex = pos.x>>FRACBITS; basey = pos.y>>FRACBITS; @@ -10400,7 +10432,6 @@ skipcrap: } else V_DrawMappedPatch(cv_driftgaugestyle.value == 2 ? basex + dup*11 : basex, basey, V_NOSCALESTART|V_OFFSET|drifttrans, cv_driftgaugestyle.value == 2 ? driftgaugesmall : driftgauge, NULL); - } if (driftcharge >= driftval*4) // rainbow sparks @@ -10557,7 +10588,7 @@ static void K_drawKartPlayerCheck(void) UINT8 *colormap; INT32 x; - INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM); + const INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM); if (!stplyr->mo || stplyr->spectator) return; @@ -10699,7 +10730,7 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags) if (cv_minihead.value) { - amxpos += (minimaphead->width / 4)<width / 4)<height / 4)<cmd; + const ticcmd_t *cmd = &stplyr->cmd; if (timeinmap < 113) { @@ -11336,11 +11364,14 @@ static void K_drawInput(void) if (cv_showinput.value == 2 || cv_showinput.value == 3) { - INT32 joyx, joyxoffs, joyy, joyyoffs, axis; - joyxoffs = -8, joyyoffs = -24; - joyx = x>>FRACBITS, joyy = y>>FRACBITS; + INT32 axis; + INT32 hudforward = 0; // for the stick input display :chaosleep: UINT8 *shadowcolormap = NULL; - const boolean usejoysprite = (cv_showinput.value == 3 && joystickicon); + const INT32 joyx = x>>FRACBITS; + const INT32 joyy = y>>FRACBITS; + static const INT32 joyxoffs = -8; + static const INT32 joyyoffs = -24; + const boolean usejoysprite = (cv_showinput.value == 3 && joystickicon); // O backing if (usejoysprite) @@ -11357,7 +11388,6 @@ static void K_drawInput(void) // time for pain and suffering // kart does not have anything we can get analogue joystick y axis values from // during normal gameplay, so replicate shit here - INT32 hudforward = 0; // for the stick input display :chaosleep: // this is horrid but we cant get actual input in replays so uhh if (demo.playback || !P_IsLocalPlayer(stplyr)) // yeah........... @@ -11388,9 +11418,9 @@ static void K_drawInput(void) hudforward-= KART_FULLTURN; } } - } - hudforward = CLAMP(hudforward, -KART_FULLTURN, KART_FULLTURN); + hudforward = CLAMP(hudforward, -KART_FULLTURN, KART_FULLTURN); + } if (cmd->driftturn || hudforward) { @@ -11464,7 +11494,7 @@ static void K_drawInput(void) static void K_drawChallengerScreen(void) { // This is an insanely complicated animation. - static UINT8 anim[52] = { + static const UINT8 anim[52] = { 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13, // frame 1-14, 2 tics: HERE COMES A NEW slides in 14,14,14,14,14,14, // frame 15, 6 tics: pause on the W 15,16,17,18, // frame 16-19, 1 tic: CHALLENGER approaches screen @@ -11534,7 +11564,7 @@ void K_drawKartFreePlay(UINT32 flashtime) { // no splitscreen support because it's not FREE PLAY if you have more than one player in-game - if (! cv_showfreeplay.value) + if (!cv_showfreeplay.value) return; if ((flashtime % TICRATE) < TICRATE/2) From 7ef2da592289a35ca99a1b96d5ac393c28ebc812 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 11:43:23 +0200 Subject: [PATCH 21/43] tiny cleanup hw_batching --- src/hardware/hw_batching.c | 103 +++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 801442b6f..6e9ac4d7b 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -25,22 +25,23 @@ GLMipmap_t *current_texture = NULL; boolean currently_batching = false; -FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu +FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion // NOTE have this alloced as 3x finalVertexArray size int finalVertexArrayAllocSize = 65536; + //GLubyte* colorArray = NULL;// contains color data to be sent to gpu, if needed //int colorArrayAllocSize = 65536; // not gonna use this for now, just sort by color and change state when it changes // later maybe when using vertex attributes if it's needed -PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed -int polygonArraySize = 0; -PolygonArrayEntry **polygonArraySorted = NULL;// contains sorted pointers to polygonArray +PolygonArrayEntry* polygonArray = NULL ;// contains the polygon data from DrawPolygon, waiting to be processed +PolygonArrayEntry **polygonArraySorted = NULL; // contains sorted pointers to polygonArray +int polygonArraySize = 0; int polygonArrayAllocSize = 65536; -FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon -int unsortedVertexArraySize = 0; +FOutVector* unsortedVertexArray = NULL; // contains unsorted vertices and texture coordinates from DrawPolygon +int unsortedVertexArraySize = 0; int unsortedVertexArrayAllocSize = 65536; // Enables batching mode. HWR_ProcessPolygon will collect polygons instead of passing them directly to the rendering backend. @@ -55,11 +56,11 @@ void HWR_StartBatching(void) // init arrays if that has not been done yet if (!finalVertexArray) { - finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); + finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); - polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); - polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); - unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); + polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); + polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); + unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); } currently_batching = true; @@ -132,13 +133,13 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt static int comparePolygons(const void *p1, const void *p2) { - const PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; - const PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; int diff; INT64 diff64; + const PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; + const PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; - int shader1 = (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) ? -1 : poly1->shader; - int shader2 = (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) ? -1 : poly2->shader; + const int shader1 = (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) ? -1 : poly1->shader; + const int shader2 = (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) ? -1 : poly2->shader; // skywalls and horizon lines must retain their order for horizon lines to work if (shader1 == -1 && shader2 == -1) @@ -174,13 +175,13 @@ static int comparePolygons(const void *p1, const void *p2) static int comparePolygonsNoShaders(const void *p1, const void *p2) { - PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; - PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; int diff; INT64 diff64; + const PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; + const PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; - GLMipmap_t *texture1 = (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) ? NULL : poly1->texture; - GLMipmap_t *texture2 = (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) ? NULL : poly2->texture; + const GLMipmap_t *texture1 = (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) ? NULL : poly1->texture; + const GLMipmap_t *texture2 = (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) ? NULL : poly2->texture; // skywalls and horizon lines must retain their order for horizon lines to work if (!texture1 && !texture2) @@ -204,17 +205,16 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) // the rendering backend to draw them. void HWR_RenderBatches(void) { - int finalVertexWritePos = 0;// position in finalVertexArray - int finalIndexWritePos = 0;// position in finalVertexIndexArray - - int polygonReadPos = 0;// position in polygonArraySorted + int finalVertexWritePos = 0; // position in finalVertexArray + int finalIndexWritePos = 0; // position in finalVertexIndexArray + int polygonReadPos = 0; // position in polygonArraySorted int currentShader; int nextShader = 0; - GLMipmap_t *currentTexture = NULL; - GLMipmap_t *nextTexture = NULL; - FBITFIELD currentPolyFlags = 0; - FBITFIELD nextPolyFlags = 0; + GLMipmap_t *currentTexture = NULL; + GLMipmap_t *nextTexture = NULL; + FBITFIELD currentPolyFlags = 0; + FBITFIELD nextPolyFlags = 0; FSurfaceInfo currentSurfaceInfo; FSurfaceInfo nextSurfaceInfo; @@ -225,8 +225,8 @@ void HWR_RenderBatches(void) I_Error("HWR_RenderBatches called without starting batching"); } - nextSurfaceInfo.LightInfo.fade_end = 0; - nextSurfaceInfo.LightInfo.fade_start = 0; + nextSurfaceInfo.LightInfo.fade_end = 0; + nextSurfaceInfo.LightInfo.fade_start = 0; nextSurfaceInfo.LightInfo.light_level = 0; nextSurfaceInfo.LightInfo.directional = false; @@ -244,7 +244,7 @@ void HWR_RenderBatches(void) ps_hw_numpolys.value.i = polygonArraySize; ps_hw_numcalls.value.i = ps_hw_numverts.value.i = 0; ps_hw_numshaders.value.i = ps_hw_numtextures.value.i - = ps_hw_numpolyflags.value.i = ps_hw_numcolors.value.i = 1; + = ps_hw_numpolyflags.value.i = ps_hw_numcolors.value.i = 1; // init polygonArraySorted for (i = 0; i < polygonArraySize; i++) @@ -254,10 +254,7 @@ void HWR_RenderBatches(void) // sort polygons PS_START_TIMING(ps_hw_batchsorttime); - if (cv_glshaders.value && gl_shadersavailable) - qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygons); - else - qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygonsNoShaders); + qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), (HWR_UseShader() ? comparePolygons : comparePolygonsNoShaders)); PS_STOP_TIMING(ps_hw_batchsorttime); // sort order @@ -269,16 +266,16 @@ void HWR_RenderBatches(void) PS_START_TIMING(ps_hw_batchdrawtime); - currentShader = polygonArraySorted[0]->shader; - currentTexture = polygonArraySorted[0]->texture; - currentPolyFlags = polygonArraySorted[0]->polyFlags; + currentShader = polygonArraySorted[0]->shader; + currentTexture = polygonArraySorted[0]->texture; + currentPolyFlags = polygonArraySorted[0]->polyFlags; currentSurfaceInfo = polygonArraySorted[0]->surf; // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms // and a color array could replace the color calls. // set state for first batch - if (cv_glshaders.value && gl_shadersavailable) + if (HWR_UseShader()) { GL_SetShader(currentShader); } @@ -303,16 +300,17 @@ void HWR_RenderBatches(void) // steps: // write vertices // check for changes or end, otherwise go back to writing - // changes will affect the next vars and the change bools - // end could set flag for stopping + // changes will affect the next vars and the change bools + // end could set flag for stopping // execute draw call // could check ending flag here // change states according to next vars and change bools, updating the current vars and reseting the bools // reset write pos // repeat loop - PolygonArrayEntry *entry = polygonArraySorted[polygonReadPos++]; - int numVerts = entry->numVerts; + const PolygonArrayEntry *entry = polygonArraySorted[polygonReadPos++]; + const int numVerts = entry->numVerts; + // before writing, check if there is enough room // using 'while' instead of 'if' here makes sure that there will *always* be enough room. // probably never will this loop run more than once though @@ -324,13 +322,15 @@ void HWR_RenderBatches(void) // going from fans to triangles increases vertex count to 3x finalVertexIndexArray = realloc(finalVertexIndexArray, finalVertexArrayAllocSize * 3 * sizeof(UINT32)); } + // write the vertices of the polygon - memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[entry->vertsIndex], - numVerts * sizeof(FOutVector)); + memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[entry->vertsIndex], numVerts * sizeof(FOutVector)); + // write the indexes, pointing to the fan vertexes but in triangles format firstIndex = finalVertexWritePos; lastIndex = finalVertexWritePos + numVerts; finalVertexWritePos += 2; + while (finalVertexWritePos < lastIndex) { finalVertexIndexArray[finalIndexWritePos++] = firstIndex; @@ -345,16 +345,16 @@ void HWR_RenderBatches(void) else { // check if a state change is required, set the change bools and next vars - PolygonArrayEntry *nextEntry = polygonArraySorted[polygonReadPos]; - nextShader = nextEntry->shader; - nextTexture = nextEntry->texture; - nextPolyFlags = nextEntry->polyFlags; + const PolygonArrayEntry *nextEntry = polygonArraySorted[polygonReadPos]; + nextShader = nextEntry->shader; + nextTexture = nextEntry->texture; + nextPolyFlags = nextEntry->polyFlags; nextSurfaceInfo = nextEntry->surf; if (nextPolyFlags & PF_NoTexture) nextTexture = 0; - if (currentShader != nextShader && cv_glshaders.value && gl_shadersavailable) + if (currentShader != nextShader && HWR_UseShader()) { changeState = true; changeShader = true; @@ -372,7 +372,7 @@ void HWR_RenderBatches(void) changePolyFlags = true; } - if (cv_glshaders.value && gl_shadersavailable) + if (HWR_UseShader()) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -405,7 +405,7 @@ void HWR_RenderBatches(void) ps_hw_numverts.value.i += finalIndexWritePos; // reset write positions finalVertexWritePos = 0; - finalIndexWritePos = 0; + finalIndexWritePos = 0; } else continue; @@ -451,9 +451,10 @@ void HWR_RenderBatches(void) ps_hw_numcolors.value.i++; } - // and that should be it? } + // and that should be it? } + // reset the arrays (set sizes to 0) polygonArraySize = 0; unsortedVertexArraySize = 0; From d47e20b54e41c294cf453bd640e0bc14bf7c2450 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 11:42:58 +0200 Subject: [PATCH 22/43] those can be const --- src/r_main.cpp | 5 ++--- src/r_plane.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index 836fb66e8..ebea32638 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -491,7 +491,7 @@ boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixe // Returns search dimensions within a blockmap, in the direction of viewangle and out to a certain distance. void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 *yl, INT32 *yh) { - const angle_t left = viewangle - clipangle; + const angle_t left = viewangle - clipangle; const angle_t right = viewangle + clipangle; const fixed_t vxleft = viewx + FixedMul(drawdist, FCOS(left)); @@ -657,7 +657,6 @@ void R_CheckViewMorph(void) rollangle >>= ANGLETOFINESHIFT; rollangle = ((rollangle+2) & ~3) & FINEMASK; // Limit the distinct number of angles to reduce recalcs from angles changing a lot. - if (rollangle == viewmorph.rollangle && viewmorph.scrmapsize == vid.width*vid.height) return; // No change @@ -1363,7 +1362,7 @@ void R_RenderPlayerView(player_t *player) // load previous saved value of skyVisible for the player skyVisible = skyVisiblePerPlayer[viewssnum]; - fixed_t fov = R_GetPlayerFov(player); + const fixed_t fov = R_GetPlayerFov(player); if (viewfov[viewssnum] != fov) { diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 5cb48b355..54a0f04da 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -149,7 +149,7 @@ void R_AllocPlaneMemory(void) // static fixed_t R_CalculateRippleOffset(drawspandata_t* ds, INT32 y) { - fixed_t distance = FixedMul(ds->planeheight, yslope[y]); + const fixed_t distance = FixedMul(ds->planeheight, yslope[y]); const INT32 yay = (ds->planeripple.offset + (distance>>9)) & 8191; return FixedDiv(FINESINE(yay), (1<<12) + (distance>>11)); } @@ -559,6 +559,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) else /* Cannot use existing plane; create a new one */ { visplane_t *new_pl; + if (pl->ffloor) { new_pl = new_visplane(MAXVISPLANES - 1); @@ -782,7 +783,6 @@ void R_DrawSkyPlanes(void) static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), boolean allow_parallel) { INT32 x; - drawcolumndata_t dc = {}; if (!(pl->minx <= pl->maxx)) return; @@ -794,6 +794,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b return; } + drawcolumndata_t dc = {}; + // Reset column drawer function (note: couldn't we just call walldrawerfunc directly?) // (that is, unless we'll need to switch drawers in future for some reason) R_SetColumnFunc(BASEDRAWFUNC); @@ -1006,8 +1008,8 @@ static inline void R_AdjustSlopeCoordinates(drawspandata_t* ds, vector3_t *origi { const fixed_t modmask = ((1 << (32-ds->nflatshiftup)) - 1); - fixed_t ox = (origin->x & modmask); - fixed_t oy = -(origin->y & modmask); + const fixed_t ox = (origin->x & modmask); + const fixed_t oy = -(origin->y & modmask); ds->xoffs &= modmask; ds->yoffs &= modmask; From 04385d9700503cb359e580e939d0282bffa470ce Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 12:01:58 +0200 Subject: [PATCH 23/43] add "songcredits" to saturn hud menu since we have a new style for this now, want to have it in the menu instead --- src/m_menu.c | 54 ++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index c35ff6e4d..2b79379f1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2323,44 +2323,46 @@ static menuitem_t OP_SaturnHudMenu[] = { {IT_HEADER, NULL, "Saturn Hud Options", NULL, 0}, - {IT_STRING | IT_CVAR, NULL, "Speedometer Style", &cv_newspeedometer, 10}, - {IT_STRING | IT_CVAR, NULL, "Battle Speedometer", &cv_battlespeedo, 15}, + {IT_STRING|IT_CVAR, NULL, "Speedometer Style", &cv_newspeedometer, 10}, + {IT_STRING|IT_CVAR, NULL, "Battle Speedometer", &cv_battlespeedo, 15}, - {IT_STRING | IT_CVAR, NULL, "Colourized HUD", &cv_colorizedhud, 25}, - {IT_STRING | IT_CVAR, NULL, "Colourized Itembox", &cv_colorizeditembox, 30}, - {IT_STRING | IT_CVAR, NULL, "Colourized HUD Color", &cv_colorizedhudcolor, 35}, + {IT_STRING|IT_CVAR, NULL, "Colourized HUD", &cv_colorizedhud, 25}, + {IT_STRING|IT_CVAR, NULL, "Colourized Itembox", &cv_colorizeditembox, 30}, + {IT_STRING|IT_CVAR, NULL, "Colourized HUD Color", &cv_colorizedhudcolor, 35}, - {IT_STRING | IT_CVAR, NULL, "Input Display", &cv_showinput, 45}, + {IT_STRING|IT_CVAR, NULL, "Input Display", &cv_showinput, 45}, - {IT_STRING | IT_CVAR, NULL, "Stat Display", &cv_showstats, 55}, + {IT_STRING|IT_CVAR, NULL, "Stat Display", &cv_showstats, 55}, - {IT_STRING | IT_CVAR, NULL, "Higher Resolution Portraits", &cv_highresportrait, 65}, + {IT_STRING|IT_CVAR, NULL, "Higher Resolution Portraits", &cv_highresportrait, 65}, - {IT_STRING | IT_CVAR, NULL, "Small Positionnumber", &cv_smallposnum, 75}, - {IT_STRING | IT_CVAR, NULL, "Positionnumber Animation", &cv_posanim, 80}, + {IT_STRING|IT_CVAR, NULL, "Small Positionnumber", &cv_smallposnum, 75}, + {IT_STRING|IT_CVAR, NULL, "Positionnumber Animation", &cv_posanim, 80}, - {IT_STRING | IT_CVAR, NULL, "Flash Lap Times", &cv_showlaptimes, 90}, + {IT_STRING|IT_CVAR, NULL, "Flash Lap Times", &cv_showlaptimes, 90}, - {IT_STRING | IT_CVAR, NULL, "Multi-Item icons", &cv_multiitemicon, 100}, - {IT_STRING | IT_CVAR, NULL, "Item Amount Number", &cv_huditemamount, 105}, - {IT_STRING | IT_CVAR, NULL, "Animated Roulette", &cv_fancyroulette, 110}, + {IT_STRING|IT_CVAR, NULL, "Multi-Item icons", &cv_multiitemicon, 100}, + {IT_STRING|IT_CVAR, NULL, "Item Amount Number", &cv_huditemamount, 105}, + {IT_STRING|IT_CVAR, NULL, "Animated Roulette", &cv_fancyroulette, 110}, - {IT_STRING | IT_CVAR, NULL, "Show Lap Emblem", &cv_showlapemblem, 120}, - {IT_STRING | IT_CVAR, NULL, "Show Cecho Messages", &cv_cechotoggle, 125}, + {IT_STRING|IT_CVAR, NULL, "Show Lap Emblem", &cv_showlapemblem, 120}, + {IT_STRING|IT_CVAR, NULL, "Show Cecho Messages", &cv_cechotoggle, 125}, - {IT_STRING | IT_CVAR, NULL, "Show Names on Minimap", &cv_showminimapnames, 135}, - {IT_STRING | IT_CVAR, NULL, "Small Minimap Players", &cv_minihead, 140}, - {IT_STRING | IT_CVAR, NULL, "Spin Minimap Icons", &cv_spinoutroll, 145}, - {IT_STRING | IT_CVAR, NULL, "Player Angle Visual", &cv_showminimapangle, 150}, + {IT_STRING|IT_CVAR, NULL, "Show Names on Minimap", &cv_showminimapnames, 135}, + {IT_STRING|IT_CVAR, NULL, "Small Minimap Players", &cv_minihead, 140}, + {IT_STRING|IT_CVAR, NULL, "Spin Minimap Icons", &cv_spinoutroll, 145}, + {IT_STRING|IT_CVAR, NULL, "Player Angle Visual", &cv_showminimapangle, 150}, - {IT_STRING | IT_CVAR, NULL, "Beta Intermissionscreen", &cv_betainterscreen, 160}, + {IT_STRING|IT_CVAR, NULL, "Music Credits", &cv_songcredits, 160}, - {IT_STRING | IT_CVAR, NULL, "Show Director Prompt", &cv_showdirectorhud, 170}, + {IT_STRING|IT_CVAR, NULL, "Beta Intermissionscreen", &cv_betainterscreen, 170}, - {IT_STRING | IT_SUBMENU, NULL, "Nametags...", &OP_NametagDef, 180}, - {IT_STRING | IT_SUBMENU, NULL, "Driftgauge...", &OP_DriftGaugeDef, 185}, + {IT_STRING|IT_CVAR, NULL, "Show Director Prompt", &cv_showdirectorhud, 180}, - {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 195}, + {IT_STRING|IT_SUBMENU, NULL, "Nametags...", &OP_NametagDef, 190}, + {IT_STRING|IT_SUBMENU, NULL, "Driftgauge...", &OP_DriftGaugeDef, 195}, + + {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 205}, }; static const char* OP_SaturnHudTooltips[] = @@ -2386,6 +2388,7 @@ static const char* OP_SaturnHudTooltips[] = "Minimize the player icons on the minimap.", "Erratically rotate player icons during spinouts.", "Visualize the player facing angle.", + "Show the Music Credits and which style.", "Make the Intermission screen look like in beta versions of Kart!\nEither with background or just the rest.", "Show the Director Toggle prompt when spectating.", "Nametag Options.", @@ -2416,6 +2419,7 @@ enum sh_smallmap, sh_iconspinout, sh_minidot, + sh_songcred, sh_betainter, sh_directorhud, sh_nametagmen, From 465fea8bb3415a9fb9265064dd81e565faef3a3c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 12:18:21 +0200 Subject: [PATCH 24/43] "restrict" macro for c++ since it does not have it, use __restrict instead --- src/doomdef.h | 8 ++++++++ src/r_draw_column.cpp | 16 ++++++++-------- src/r_draw_span.cpp | 20 ++++++++++---------- src/r_main.h | 2 +- src/r_plane.cpp | 10 +++++----- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index dbeabce63..ce846ee27 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -566,6 +566,14 @@ UINT32 quickncasehash (const char *p, size_t n) #define UNLIKELY(x) (x) #endif +#ifdef __cplusplus +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + #define restrict __restrict +#else + #define restrict +#endif +#endif + // An assert-type mechanism. #ifdef PARANOIA #define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__)) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index bc91ef0d3..dcc1a5b90 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -31,7 +31,7 @@ enum DrawColumnType }; template -static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * __restrict colormap) +static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) { if constexpr (Type & DrawColumnType::DC_COLORMAP) { @@ -42,7 +42,7 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co } template -static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT8 col, const UINT8 * __restrict colormap) +static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * restrict dest, UINT8 col, const UINT8 * restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); @@ -57,7 +57,7 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __re } template -static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT32 bit, const __restrict UINT8 *source, const __restrict UINT8 *colormap) +static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const restrict UINT8 *source, const restrict UINT8 *colormap) { UINT8 col = source[bit]; @@ -189,11 +189,11 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) const INT32 npow2max = dc->sourcelength; const INT32 stride = vid.width; - const UINT8 * __restrict source = dc->source; - const lighttable_t * __restrict colormap = dc->colormap; + const UINT8 * restrict source = dc->source; + const lighttable_t * restrict colormap = dc->colormap; // Framebuffer destination address. - UINT8 * __restrict dest = R_Address(dc->x, dc->yl); + UINT8 * restrict dest = R_Address(dc->x, dc->yl); count++; @@ -325,7 +325,7 @@ DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_HOLES|DC_TRANSMAP) void R_DrawFogColumn(drawcolumndata_t* dc) { INT32 count; - UINT8 * __restrict dest; + UINT8 * restrict dest; count = dc->yh - dc->yl; @@ -344,7 +344,7 @@ void R_DrawFogColumn(drawcolumndata_t* dc) dest = R_Address(dc->x, dc->yl); const INT32 stride = vid.width; - const lighttable_t * __restrict colormap = dc->colormap; + const lighttable_t * restrict colormap = dc->colormap; // Determine scaling, which is the only mapping to be done. do diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 7ead430c4..cf7878184 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -88,10 +88,10 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) UINT32 xstep, ystep; UINT32 bit; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); - UINT8 * __restrict dsrc; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); + UINT8 * restrict dsrc; - const UINT8 * __restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; + const UINT8 * restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; if (dest+8 > deststop) { @@ -104,8 +104,8 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) xposition = ds->xfrac; yposition = ds->yfrac; xstep = ds->xstep; ystep = ds->ystep; - const UINT8 * __restrict source = ds->source; - const UINT8 * __restrict colormap = ds->colormap; + const UINT8 * restrict source = ds->source; + const UINT8 * restrict colormap = ds->colormap; if constexpr (Type & DS_RIPPLE) { @@ -202,8 +202,8 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) UINT32 u, v; int i; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); - UINT8 * __restrict dsrc; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); + UINT8 * restrict dsrc; float startz, startu, startv; float izstep, uzstep, vzstep; @@ -382,8 +382,8 @@ DEFINE_SPAN_COMBO(R_DrawTranslucentWaterSpan, DS_TRANSMAP|DS_RIPPLE) */ void R_DrawFogSpan(drawspandata_t* ds) { - const UINT8 * __restrict colormap = ds->colormap; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); + const UINT8 * restrict colormap = ds->colormap; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); intptr_t count = ds->x2 - ds->x1 + 1; @@ -409,7 +409,7 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) { int width = ds->x2 - ds->x1; float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); - UINT8 * __restrict dest; + UINT8 * restrict dest; local_for_thread INT32 *tiltlighting = NULL; local_for_thread INT32 oldviewwidth = 0; diff --git a/src/r_main.h b/src/r_main.h index e95862c57..29a6b308e 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -88,7 +88,7 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // // killough 5/2/98: reformatted // -FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * __restrict node) +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * restrict node) { if (!node->dx) return x <= node->x ? node->dy > 0 : node->dy < 0; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 54a0f04da..c52771bc4 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -100,7 +100,7 @@ static void R_ReallocPlaneBounds(visplane_t *pl) { pl->top_memory = static_cast(Z_Realloc(pl->top_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL)); pl->bottom_memory = static_cast(Z_Realloc(pl->bottom_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL)); - pl->top = pl->top_memory + 1; + pl->top = pl->top_memory + 1; pl->bottom = pl->bottom_memory + 1; } @@ -203,14 +203,14 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 if (!R_CheckMapPlane(__func__, y, x1, x2)) return; - angle = (ds->currentplane->viewangle + ds->currentplane->plangle)>>ANGLETOFINESHIFT; + angle = (ds->currentplane->viewangle + ds->currentplane->plangle)>>ANGLETOFINESHIFT; planecos = FINECOSINE(angle); planesin = FINESINE(angle); // [RH] Notice that I dumped the caching scheme used by Doom. // It did not offer any appreciable speedup. distance = FixedMul(ds->planeheight, yslope[y]); - span = abs(centery - y); + span = abs(centery - y); if (span) // don't divide by zero { @@ -259,7 +259,7 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 if (ds->currentplane->extra_colormap) ds->colormap = ds->currentplane->extra_colormap->colormap + (ds->colormap - colormaps); - ds->y = y; + ds->y = y; ds->x1 = x1; ds->x2 = x2; @@ -301,7 +301,7 @@ static void R_MapTiltedPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, ds->colormap += COLORMAP_REMAPOFFSET; } - ds->y = y; + ds->y = y; ds->x1 = x1; ds->x2 = x2; From 612431c1f13e3baa2ffcf6261d40f28a039d1f19 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 14:22:49 +0200 Subject: [PATCH 25/43] dont define min and max with c++ --- src/doomdef.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index f9467199b..ba606cac0 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -524,12 +524,15 @@ UINT32 quickncasehash (const char *p, size_t n) return x; } +#ifndef __cplusplus #ifndef min // Double-Check with WATTCP-32's cdefs.h #define min(x, y) (((x) < (y)) ? (x) : (y)) #endif #ifndef max // Double-Check with WATTCP-32's cdefs.h #define max(x, y) (((x) > (y)) ? (x) : (y)) #endif +#endif + #ifndef CLAMP #define CLAMP(x, y, z) ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))) #endif From f4d40bd55f790175b78e04b4385c0c515a5c129a Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 14:38:32 +0200 Subject: [PATCH 26/43] "-Wno-aggregate-return" for c++ --- src/Makefile.d/versions.mk | 3 +++ src/r_plane.cpp | 6 ------ src/r_things.cpp | 3 --- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index a3cdbbd4b..ce23c3e4e 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -16,6 +16,9 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ $(and $(findstring =,$(v)),\ $(eval $(call _predecessor,$(subst =, ,$(v)))))) +# aggregate returns seem to happen alot in c++ so just supress em lel +CXXFLAGS+= -Wno-aggregate-return + # -W -Wno-unused ifdef GCC150 diff --git a/src/r_plane.cpp b/src/r_plane.cpp index c52771bc4..4d6244468 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -740,12 +740,9 @@ void R_DrawPlanes(void) } } #ifdef HAVE_THREADS -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waggregate-return" tp_sema = srb2::g_main_threadpool->end_sema(); srb2::g_main_threadpool->notify_sema(tp_sema); srb2::g_main_threadpool->wait_sema(tp_sema); -#pragma GCC diagnostic pop #endif } @@ -771,12 +768,9 @@ void R_DrawSkyPlanes(void) } } #ifdef HAVE_THREADS -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waggregate-return" tp_sema = srb2::g_main_threadpool->end_sema(); srb2::g_main_threadpool->notify_sema(tp_sema); srb2::g_main_threadpool->wait_sema(tp_sema); -#pragma GCC diagnostic pop #endif } diff --git a/src/r_things.cpp b/src/r_things.cpp index bf33fb97c..06c346645 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2977,12 +2977,9 @@ static void R_DrawMaskedList(drawnode_t* head) #endif R_DrawSinglePlane(&ds, r2->plane, cv_parallelsoftware.value); #ifdef HAVE_THREADS -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waggregate-return" tp_sema = srb2::g_main_threadpool->end_sema(); srb2::g_main_threadpool->notify_sema(tp_sema); srb2::g_main_threadpool->wait_sema(tp_sema); -#pragma GCC diagnostic pop #endif R_DoneWithNode(r2); r2 = next; From 3c282b5022d85e0667ea4a92f4568fd832ff69af Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 14:42:17 +0200 Subject: [PATCH 27/43] this can use min/max --- src/r_plane.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 4d6244468..653353a2b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1096,6 +1096,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle // and mercilessly shoved into saturn by chearii 02-02-2025 { INT32 trans = (10*((256+12) - pl->ffloor->alpha))/255; + if (trans >= 10) return; // Don't even draw it @@ -1132,13 +1133,8 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle spanfunctype = SPANDRAWFUNC_WATER; // Copy the current scene, ugh - top = pl->high-8; - bottom = pl->low+8; - - if (top < 0) - top = 0; - if (bottom > vid.height) - bottom = vid.height; + top = std::max(0, pl->high - 8); + bottom = std::min(viewheight, pl->low + 8); // Only copy the part of the screen we need UINT8 i = R_GetViewNumber(); From 5a44afcd9fdee9be513bfca839a2483941331391 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Jul 2025 16:07:51 +0300 Subject: [PATCH 28/43] Disable multithreading in R_DrawMaskedList --- src/r_things.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index 06c346645..683904ccb 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2971,16 +2971,8 @@ static void R_DrawMaskedList(drawnode_t* head) { drawspandata_t ds = {}; next = r2->prev; -#ifdef HAVE_THREADS - srb2::ThreadPool::Sema tp_sema; - srb2::g_main_threadpool->begin_sema(); -#endif - R_DrawSinglePlane(&ds, r2->plane, cv_parallelsoftware.value); -#ifdef HAVE_THREADS - tp_sema = srb2::g_main_threadpool->end_sema(); - srb2::g_main_threadpool->notify_sema(tp_sema); - srb2::g_main_threadpool->wait_sema(tp_sema); -#endif + // Force disable multithreading since it is usually slower because of waiting for each plane to render + R_DrawSinglePlane(&ds, r2->plane, false); R_DoneWithNode(r2); r2 = next; } From d275db9bb41a9f9963b8eea97c063a6dbab9076b Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 15:25:14 +0200 Subject: [PATCH 29/43] turn TC_ stuff into enum --- src/r_draw.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/r_draw.h b/src/r_draw.h index a28a09e79..763375709 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -179,12 +179,15 @@ extern lumpnum_t viewborderlump[8]; #define GTC_MENUCACHE GTC_CACHE //@TODO Add a separate caching mechanism for menu colormaps distinct from in-level GTC_CACHE. For now this is still preferable to memory leaks... -#define TC_DEFAULT -1 -#define TC_BOSS -2 -#define TC_METALSONIC -3 // For Metal Sonic battle -#define TC_ALLWHITE -4 // For Cy-Brak-demon -#define TC_RAINBOW -5 // For invincibility power -#define TC_BLINK -6 // For item blinking +enum +{ + TC_BLINK = -6, // For item blinking, according to kart + TC_RAINBOW, // For single colour + TC_ALLWHITE, // For Cy-Brak-demon + TC_METALSONIC, // For Metal Sonic battle + TC_BOSS, + TC_DEFAULT +}; // Initialize color translation tables, for player rendering etc. UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags); From 1b418caf6b7f33a2b52d58bacb4e00ed8f8fa109 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 11:49:36 +0200 Subject: [PATCH 30/43] ceepeepeefy hw_main, abuse templates for portal stuff no idea if this is faster at all lmao --- src/hardware/Sourcefile | 2 +- src/hardware/hw_batching.h | 8 + src/hardware/hw_clip.h | 8 + src/hardware/hw_gl.h | 8 + src/hardware/hw_glob.h | 8 + src/hardware/{hw_main.c => hw_main.cpp} | 633 +++++++++++++----------- src/hardware/hw_main.h | 9 +- src/hardware/hw_portal.c | 2 +- src/hardware/hw_portal.h | 8 + src/hardware/r_opengl/r_opengl.h | 8 + src/m_fixed.h | 8 + src/st_stuff.h | 8 + 12 files changed, 426 insertions(+), 284 deletions(-) rename src/hardware/{hw_main.c => hw_main.cpp} (93%) diff --git a/src/hardware/Sourcefile b/src/hardware/Sourcefile index 3114c975c..e66482c3d 100644 --- a/src/hardware/Sourcefile +++ b/src/hardware/Sourcefile @@ -1,6 +1,6 @@ hw_bsp.c hw_draw.c -hw_main.c +hw_main.cpp hw_clip.c hw_md2.c hw_cache.c diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 7f418fc77..d1808ce43 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -13,6 +13,10 @@ #ifndef __HWR_BATCHING_H__ #define __HWR_BATCHING_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "hw_defs.h" #include "hw_data.h" #include "hw_gl.h" @@ -36,4 +40,8 @@ void HWR_SetCurrentTexture(GLMipmap_t *texture); void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial); void HWR_RenderBatches(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index dfaa87f81..4299fbaea 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -7,6 +7,10 @@ * */ +#ifdef __cplusplus +extern "C" { +#endif + // OpenGL BSP clipping #include "../doomdef.h" #include "../tables.h" @@ -22,3 +26,7 @@ angle_t gld_FrustumAngle(angle_t tiltangle); void gld_FrustumSetup(void); boolean gld_SphereInFrustum(float x, float y, float z, float radius); #endif + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index a21fd0a3a..8780fc57b 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -13,6 +13,10 @@ #ifndef __HWR_GL_H__ #define __HWR_GL_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "../screen.h" #include "hw_data.h" @@ -76,4 +80,8 @@ UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); void GL_ClearLightTables(void); void GL_SetScreenPalette(RGBA_t *palette); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __HWR_GL_H__ diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 0589ba1d2..09956b99d 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -14,6 +14,10 @@ #ifndef _HWR_GLOB_H_ #define _HWR_GLOB_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "hw_defs.h" #include "../m_misc.h" #include "../r_defs.h" @@ -109,4 +113,8 @@ const char *HWR_GetShaderName(INT32 shader); extern customshaderxlat_t shaderxlat[]; +#ifdef __cplusplus +} // extern "C" +#endif + #endif //_HW_GLOB_ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.cpp similarity index 93% rename from src/hardware/hw_main.c rename to src/hardware/hw_main.cpp index c3cd01ad7..0667c9806 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.cpp @@ -11,6 +11,7 @@ /// \file /// \brief hardware renderer, using the standard HardWareRender driver DLL for SRB2 +#include #include #include "../doomstat.h" @@ -107,21 +108,21 @@ static INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT (6144+512)*FRACUNIT, (8192+512)*FRACUNIT, (12288+512)*FRACUNIT, (16384+512)*FRACUNIT}; // Performance stats -ps_metric_t ps_hw_nodesorttime = {0}; -ps_metric_t ps_hw_nodedrawtime = {0}; -ps_metric_t ps_hw_spritesorttime = {0}; -ps_metric_t ps_hw_spritedrawtime = {0}; +ps_metric_t ps_hw_nodesorttime = {}; +ps_metric_t ps_hw_nodedrawtime = {}; +ps_metric_t ps_hw_spritesorttime = {}; +ps_metric_t ps_hw_spritedrawtime = {}; // Performance stats for batching -ps_metric_t ps_hw_numpolys = {0}; -ps_metric_t ps_hw_numverts = {0}; -ps_metric_t ps_hw_numcalls = {0}; -ps_metric_t ps_hw_numshaders = {0}; -ps_metric_t ps_hw_numtextures = {0}; -ps_metric_t ps_hw_numpolyflags = {0}; -ps_metric_t ps_hw_numcolors = {0}; -ps_metric_t ps_hw_batchsorttime = {0}; -ps_metric_t ps_hw_batchdrawtime = {0}; +ps_metric_t ps_hw_numpolys = {}; +ps_metric_t ps_hw_numverts = {}; +ps_metric_t ps_hw_numcalls = {}; +ps_metric_t ps_hw_numshaders = {}; +ps_metric_t ps_hw_numtextures = {}; +ps_metric_t ps_hw_numpolyflags = {}; +ps_metric_t ps_hw_numcolors = {}; +ps_metric_t ps_hw_batchsorttime = {}; +ps_metric_t ps_hw_batchdrawtime = {}; static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, boolean noencore, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags); static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); @@ -372,7 +373,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 fixed_t extralight = R_GetSpriteDirectionalLighting(R_PointToAngle(spr->mobj->x, spr->mobj->y)); // Less change in contrast in dark sectors - extralight = FixedMul(extralight, min(max(0, *lightlevel), 255) * FRACUNIT / 255); + extralight = FixedMul(extralight, CLAMP(*lightlevel, 0, 255) * FRACUNIT / 255); // simple OGL approximation fixed_t tr = R_PointToDist(spr->mobj->x, spr->mobj->y); @@ -380,7 +381,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 // Less change in contrast at further distances, to counteract DOOM diminished light fixed_t n = FixedDiv(FixedMul(xscale, LIGHTRESOLUTIONFIX), ((MAXLIGHTSCALE-1) << LIGHTSCALESHIFT)); - extralight = FixedMul(extralight, min(n, FRACUNIT)); + extralight = FixedMul(extralight, std::min(n, FRACUNIT)); // Contrast is stronger for normal sprites, stronger than wall lighting is at the same distance *lightlevel += FixedFloor((extralight * 2) + (FRACUNIT / 2)) / FRACUNIT; @@ -414,9 +415,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col float tint_alpha, fade_alpha; float red, green, blue; - red = (float)poly_color.s.red; + red = (float)poly_color.s.red; green = (float)poly_color.s.green; - blue = (float)poly_color.s.blue; + blue = (float)poly_color.s.blue; // 48 is just an arbritrary value that looked relatively okay. tint_alpha = (float)(sqrt(tint_color.s.alpha) * 48) / 255.0f; @@ -428,20 +429,20 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col fade_alpha = (float)(sqrt(255-light_level) * 12) / 255.0f; // Clamp the alpha values - tint_alpha = min(max(tint_alpha, 0.0f), 1.0f); - fade_alpha = min(max(fade_alpha, 0.0f), 1.0f); + tint_alpha = CLAMP(tint_alpha, 0.0f, 1.0f); + fade_alpha = CLAMP(fade_alpha, 0.0f, 1.0f); - red = (tint_color.s.red * tint_alpha) + (red * (1.0f - tint_alpha)); + red = (tint_color.s.red * tint_alpha) + (red * (1.0f - tint_alpha)); green = (tint_color.s.green * tint_alpha) + (green * (1.0f - tint_alpha)); - blue = (tint_color.s.blue * tint_alpha) + (blue * (1.0f - tint_alpha)); + blue = (tint_color.s.blue * tint_alpha) + (blue * (1.0f - tint_alpha)); - red = (fade_color.s.red * fade_alpha) + (red * (1.0f - fade_alpha)); + red = (fade_color.s.red * fade_alpha) + (red * (1.0f - fade_alpha)); green = (fade_color.s.green * fade_alpha) + (green * (1.0f - fade_alpha)); - blue = (fade_color.s.blue * fade_alpha) + (blue * (1.0f - fade_alpha)); + blue = (fade_color.s.blue * fade_alpha) + (blue * (1.0f - fade_alpha)); - poly_color.s.red = (UINT8)red; + poly_color.s.red = (UINT8)red; poly_color.s.green = (UINT8)green; - poly_color.s.blue = (UINT8)blue; + poly_color.s.blue = (UINT8)blue; } // Clamp the light level, since it can sometimes go out of the 0-255 range from animations @@ -1192,14 +1193,14 @@ static void HWR_SkyWallList_Add(FOutVector *wallVerts) if (!skyWallVertexArray) { // array has not been allocated yet. allocate it now - skyWallVertexArray = Z_Malloc(sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL); + skyWallVertexArray = static_cast(Z_Malloc(sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL)); } if (skyWallVertexArraySize == skyWallVertexArrayAllocSize) { // allocated array got full, allocate more space skyWallVertexArrayAllocSize *= 2; - skyWallVertexArray = Z_Realloc(skyWallVertexArray, sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL); + skyWallVertexArray = static_cast(Z_Realloc(skyWallVertexArray, sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL)); } memcpy(skyWallVertexArray + skyWallVertexArraySize * 4, wallVerts, sizeof(FOutVector) * 4); @@ -1417,6 +1418,13 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Sky Ceilings wallVerts[3].y = wallVerts[2].y = FixedToFloat(INT32_MAX); + auto draw_sky_walls = [&](int vert1, int vert2, fixed_t world, fixed_t worldslope) + { + wallVerts[vert1].y = FixedToFloat(world); + wallVerts[vert2].y = FixedToFloat(worldslope); + HWR_DrawSkyWall(wallVerts, &Surf); + }; + if (gl_frontsector->ceilingpic == skyflatnum) { if (gl_backsector->ceilingpic == skyflatnum) @@ -1427,25 +1435,19 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom && (worldhigh != worldtop || worldhighslope != worldtopslope)) // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race { - wallVerts[0].y = FixedToFloat(worldhigh); - wallVerts[1].y = FixedToFloat(worldhighslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(0, 1, worldhigh, worldhighslope); } } else { // Only the frontsector is sky, just draw a skywall from the front ceiling - wallVerts[0].y = FixedToFloat(worldtop); - wallVerts[1].y = FixedToFloat(worldtopslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(0, 1, worldtop, worldtopslope); } } else if (gl_backsector->ceilingpic == skyflatnum) { // Only the backsector is sky, just draw a skywall from the front ceiling - wallVerts[0].y = FixedToFloat(worldtop); - wallVerts[1].y = FixedToFloat(worldtopslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(0, 1, worldtop, worldtopslope); } // Sky Floors @@ -1463,25 +1465,19 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race && !(gl_sidedef->bottomtexture)) { - wallVerts[3].y = FixedToFloat(worldlow); - wallVerts[2].y = FixedToFloat(worldlowslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(3, 2, worldlow, worldlowslope); } } else { // Only the backsector has sky, just draw a skywall from the back floor - wallVerts[3].y = FixedToFloat(worldbottom); - wallVerts[2].y = FixedToFloat(worldbottomslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(3, 2, worldbottom, worldbottomslope); } } else if ((gl_backsector->floorpic == skyflatnum) && !(gl_sidedef->bottomtexture)) { // Only the backsector has sky, just draw a skywall from the back floor if there's no bottomtexture - wallVerts[3].y = FixedToFloat(worldlow); - wallVerts[2].y = FixedToFloat(worldlowslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(3, 2, worldlow, worldlowslope); } } @@ -1674,10 +1670,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else { - popentop = min(worldtop, worldhigh); - popenbottom = max(worldbottom, worldlow); - popentopslope = min(worldtopslope, worldhighslope); - popenbottomslope = max(worldbottomslope, worldlowslope); + popentop = std::min(worldtop, worldhigh); + popenbottom = std::max(worldbottom, worldlow); + popentopslope = std::min(worldtopslope, worldhighslope); + popenbottomslope = std::max(worldbottomslope, worldlowslope); } // Find the wall's coordinates @@ -1687,12 +1683,12 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { if (!!(gl_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gl_linedef->flags & ML_EFFECT3)) // Peg it to the floor { - polybottom = max(front->floorheight, back->floorheight) + gl_sidedef->rowoffset; - polytop = polybottom + midtexheight; + polybottom = std::max(front->floorheight, back->floorheight) + gl_sidedef->rowoffset; + polytop = polybottom + midtexheight; } else // Peg it to the ceiling { - polytop = min(front->ceilingheight, back->ceilingheight) + gl_sidedef->rowoffset; + polytop = std::min(front->ceilingheight, back->ceilingheight) + gl_sidedef->rowoffset; polybottom = polytop - midtexheight; } @@ -1709,9 +1705,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else // Skew it according to the ceiling's slope { - polytop = popentop + gl_sidedef->rowoffset; - polybottom = polytop - midtexheight; - polytopslope = popentopslope + gl_sidedef->rowoffset; + polytop = popentop + gl_sidedef->rowoffset; + polybottom = polytop - midtexheight; + polytopslope = popentopslope + gl_sidedef->rowoffset; polybottomslope = polytopslope - midtexheight; } @@ -1720,24 +1716,24 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // you must use the linedef's backsector to be correct if (gl_curline->polyseg) { - lowcut = polybottom; - highcut = polytop; - lowcutslope = polybottomslope; + lowcut = polybottom; + highcut = polytop; + lowcutslope = polybottomslope; highcutslope = polytopslope; } else { // The cut-off values of a linedef can always be constant, since every line has an absoulute front and or back sector - lowcut = popenbottom; - highcut = popentop; - lowcutslope = popenbottomslope; + lowcut = popenbottom; + highcut = popentop; + lowcutslope = popenbottomslope; highcutslope = popentopslope; } - h = min(highcut, polytop); - l = max(polybottom, lowcut); - hS = min(highcutslope, polytopslope); - lS = max(polybottomslope, lowcutslope); + h = std::min(highcut, polytop); + l = std::max(polybottom, lowcut); + hS = std::min(highcutslope, polytopslope); + lS = std::max(polybottomslope, lowcutslope); // PEGGING fixed_t texturevpegslope; @@ -1893,10 +1889,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom INT32 texnum; line_t * newline = NULL; // Multi-Property FOF - lowcut = max(worldbottom, worldlow); - highcut = min(worldtop, worldhigh); - lowcutslope = max(worldbottomslope, worldlowslope); - highcutslope = min(worldtopslope, worldhighslope); + lowcut = std::max(worldbottom, worldlow); + highcut = std::min(worldtop, worldhigh); + lowcutslope = std::max(worldbottomslope, worldlowslope); + highcutslope = std::min(worldtopslope, worldhighslope); if (gl_backsector->ffloors) { @@ -1917,7 +1913,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); + size_t linenum = std::min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -2067,7 +2063,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); + size_t linenum = std::min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -2182,6 +2178,7 @@ static inline boolean HWR_UsePortals(void) boolean checkforemptylines = true; // Don't modify anything here, just check // Kalaron: Modified for sloped linedefs + static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector) { fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends @@ -2315,17 +2312,121 @@ static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector) // HWR_AddLine // Clips the given segment and adds any visible pieces to the line list. +namespace +{ + enum class AddLineType + { + kPortal, + kNormal, + }; + +template +static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) +{ + // SoM: Backsector needs to be run through R_FakeFlat + static sector_t tempsec; + + if constexpr (Type == AddLineType::kPortal) + { + boolean dont_draw = false; + + // do extra checks on the seg when rendering portals: + // don't render segs that are behind the portal destination line + if (portalclipline && + !HWR_PortalCheckPointSide(line->v1->x, line->v1->y) && + !HWR_PortalCheckPointSide(line->v2->x, line->v2->y)) + { + return; + } + + if (gl_portal_state == GLPORTAL_STENCIL || gl_portal_state == GLPORTAL_DEPTH) + goto doaddline; + + if (line->linedef->special == 40) + { + if (line->side == 0) + { + // Find the other side! + INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); + + if (line->linedef == &lines[line2]) + line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); + + if (line2 >= 0) // found it! + { + if (gl_portal_state == GLPORTAL_SEARCH) + HWR_Portal_Add2Lines(line->linedef-lines, line2, line); + else if (gl_portal_state == GLPORTAL_INSIDE) + dont_draw = true; + } + } + else + return;// dont do anything with the other side i guess? + } + + doaddline: + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); + + if (CheckClip(gl_frontsector, gl_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; + } + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) + return; + } + + if (LIKELY(gl_portal_state != GLPORTAL_SEARCH && !dont_draw))// no need to do this during the portal check + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + return; + } + + if constexpr (Type == AddLineType::kNormal) + { + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); + + if (CheckClip(gl_frontsector, gl_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; + } + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) + return; + } + + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + return; + } +} + static void HWR_AddLine(seg_t *line) { angle_t angle1, angle2; - // SoM: Backsector needs to be run through R_FakeFlat - static sector_t tempsec; - fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t - boolean dont_draw = false; - if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; @@ -2369,73 +2470,12 @@ static void HWR_AddLine(seg_t *line) gl_backsector = line->backsector; - if (LIKELY(!HWR_UsePortals())) - { -doaddline: - if (!line->backsector) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - } - else - { - gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); - - if (CheckClip(gl_frontsector, gl_backsector)) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - checkforemptylines = false; - } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) - return; - } - - if (LIKELY(gl_portal_state != GLPORTAL_SEARCH && !dont_draw))// no need to do this during the portal check - HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D - - return; - } - - // do extra checks on the seg when rendering portals: - // don't render segs that are behind the portal destination line - if (portalclipline && - !HWR_PortalCheckPointSide(line->v1->x, line->v1->y) && - !HWR_PortalCheckPointSide(line->v2->x, line->v2->y)) - { - return; - } - - if (gl_portal_state == GLPORTAL_STENCIL || gl_portal_state == GLPORTAL_DEPTH) - goto doaddline; - - if (line->linedef->special == 40) - { - if (line->side == 0) - { - // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); - - if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); - - if (line2 >= 0) // found it! - { - if (gl_portal_state == GLPORTAL_SEARCH) - HWR_Portal_Add2Lines(line->linedef-lines, line2, line); - else if (gl_portal_state == GLPORTAL_INSIDE) - dont_draw = true; - } - } - else - return;// dont do anything with the other side i guess? - } - - goto doaddline; + if (UNLIKELY(HWR_UsePortals())) + DoAddLine(line, angle1, angle2); + else + DoAddLine(line, angle1, angle2); } +}; // HWR_CheckBBox // Checks BSP node/subtree bounding box. @@ -3153,7 +3193,10 @@ doaddline: while (count--) { if (LIKELY(!line->polyseg)) // ignore segs that belong to polyobjects + { HWR_AddLine(line); + } + line++; } } @@ -3176,10 +3219,19 @@ doaddline: // Just call with BSP root. // +namespace +{ + enum class BspType + { + kPortal, + kNormal, + }; + +template static void HWR_RenderBSPNode(INT32 bspnum) { - register const node_t *bsp; - register INT32 side; + const node_t *bsp; + INT32 side; ps_numbspcalls.value.i++; while (!(bspnum & NF_SUBSECTOR)) // Keep going until found a subsector @@ -3189,61 +3241,48 @@ static void HWR_RenderBSPNode(INT32 bspnum) // Decide which side the view point is on. side = R_PointOnSideFast(viewx, viewy, bsp); - // Recursively divide front space (toward the viewer). - HWR_RenderBSPNode(bsp->children[side]); + if constexpr (Type == BspType::kPortal) + { + // Recursively divide front space (toward the viewer). + if (HWR_PortalCheckBBox(bsp->bbox[side])) + HWR_RenderBSPNode(bsp->children[side]); - // Possibly divide back space (away from the viewer). - if (!(HWR_CheckBBox(bsp->bbox[side^1]))) - return; + // Possibly divide back space (away from the viewer). + if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1]))) + return; + } + + if constexpr (Type == BspType::kNormal) + { + // Recursively divide front space (toward the viewer). + HWR_RenderBSPNode(bsp->children[side]); + + // Possibly divide back space (away from the viewer). + if (!(HWR_CheckBBox(bsp->bbox[side^1]))) + return; + } bspnum = bsp->children[side^1]; } + if constexpr (Type == BspType::kPortal) + { + // PORTAL CULLING + if (portalcullsector) + { + // skip all subsectors encountered before the portal + // destination's front sector + if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector) + return; + else + portalcullsector = NULL; + } + } + // e6y: support for extended nodes HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); } - -// -// Same thing but with extra portal checks -// -static void HWR_RenderPortalBSPNode(INT32 bspnum) -{ - register const node_t *bsp; - register INT32 side; - ps_numbspcalls.value.i++; - - while (!(bspnum & NF_SUBSECTOR)) // Keep going until found a subsector - { - bsp = &nodes[bspnum]; - - // Decide which side the view point is on. - side = R_PointOnSideFast(viewx, viewy, bsp); - - // Recursively divide front space (toward the viewer). - if (HWR_PortalCheckBBox(bsp->bbox[side])) - HWR_RenderPortalBSPNode(bsp->children[side]); - - // Possibly divide back space (away from the viewer). - if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1]))) - return; - - bspnum = bsp->children[side^1]; - } - - // PORTAL CULLING - if (portalcullsector) - { - // skip all subsectors encountered before the portal - // destination's front sector - if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector) - return; - else - portalcullsector = NULL; - } - - // e6y: support for extended nodes - HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); -} +}; // ========================================================================== // gl_things.c @@ -3492,6 +3531,8 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t } } +#define std_R_QuickCamDist(x, y) std::max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) + // This is expecting a pointer to an array containing 4 wallVerts for a sprite static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts, const boolean precip, const boolean papersprite) { @@ -3501,12 +3542,12 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts } // uncapped/interpolation - interpmobjstate_t interp = {0}; + interpmobjstate_t interp = {}; float basey, lowy; INT32 dist = -1; if (cv_maxinterpdist.value) - dist = R_QuickCamDist(spr->mobj->x, spr->mobj->y); + dist = std_R_QuickCamDist(spr->mobj->x, spr->mobj->y); // do interpolation if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) @@ -3568,8 +3609,8 @@ static inline void HWR_ApplyDispoffset(gl_vissprite_t *spr, FOutVector *wallVert { HWR_RotateSpritePolyToAim(spr, wallVerts, false, papersprite); - float sprdist = sqrtf((spr->x1 - gl_viewx)*(spr->x1 - gl_viewx) + (spr->z1 - gl_viewy)*(spr->z1 - gl_viewy) + (spr->gzt - gl_viewz)*(spr->gzt - gl_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + const float sprdist = sqrtf((spr->x1 - gl_viewx)*(spr->x1 - gl_viewx) + (spr->z1 - gl_viewy)*(spr->z1 - gl_viewy) + (spr->gzt - gl_viewz)*(spr->gzt - gl_viewz)); + const float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; for (size_t i = 0; i < 4; i++) { @@ -3731,11 +3772,13 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) for (i = 1; i < sector->numlights; i++) { fixed_t h = P_GetLightZAt(§or->lightlist[i], spr->mobj->x, spr->mobj->y); + if (!(h <= temp)) continue; if (!lightset) - lightlevel = min(*list[i-1].lightlevel, 255); + lightlevel = std::min(static_cast(*list[i-1].lightlevel), 255); + colormap = list[i-1].extra_colormap; break; } @@ -3753,7 +3796,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) { if (!lightset) { - lightlevel = min(*list[i].lightlevel, 255); + lightlevel = std::min(static_cast(*list[i].lightlevel), 255); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); } @@ -3762,9 +3805,9 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) if (i + 1 < sector->numlights) { - temp = P_GetLightZAt(&list[i+1], v1x, v1y); - bheight = FixedToFloat(temp); - temp = P_GetLightZAt(&list[i+1], v2x, v2y); + temp = P_GetLightZAt(&list[i+1], v1x, v1y); + bheight = FixedToFloat(temp); + temp = P_GetLightZAt(&list[i+1], v2x, v2y); endbheight = FixedToFloat(temp); } else @@ -3781,7 +3824,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) // Found a break // The heights are clamped to ensure the polygon doesn't cross itself. - bot = CLAMP(bheight, realbot, top); + bot = CLAMP(bheight, realbot, top); endbot = CLAMP(endbheight, endrealbot, endtop); wallVerts[3].t = towtop + ((realtop - top) * towmult); @@ -3961,7 +4004,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) if (!lightset) { - lightlevel = min(sector->lightlevel, 255); + lightlevel = std::min(static_cast(sector->lightlevel), 255); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); } @@ -4067,7 +4110,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = min(*sector->lightlist[light].lightlevel, 255); + lightlevel = std::min(static_cast(*sector->lightlist[light].lightlevel), 255); if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4075,7 +4118,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = min(sector->lightlevel, 255); + lightlevel = std::min(static_cast(sector->lightlevel), 255); if (sector->extra_colormap) colormap = sector->extra_colormap; @@ -4223,7 +4266,7 @@ static void *HWR_CreateDrawNode(gl_drawnode_type_t type) if (!drawnodes) { alloceddrawnodes = DRAWNODES_INIT_SIZE; - drawnodes = Z_Malloc(alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes); + drawnodes = static_cast(Z_Malloc(alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes)); } else if (numdrawnodes >= alloceddrawnodes) { @@ -4249,7 +4292,7 @@ static void *HWR_CreateDrawNode(gl_drawnode_type_t type) static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, boolean noencore, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) { - wallinfo_t *wallinfo = HWR_CreateDrawNode(DRAWNODE_WALL); + wallinfo_t *wallinfo = static_cast(HWR_CreateDrawNode(DRAWNODE_WALL)); M_Memcpy(wallinfo->wallVerts, wallVerts, sizeof (wallinfo->wallVerts)); M_Memcpy(&wallinfo->Surf, pSurf, sizeof (FSurfaceInfo)); @@ -4263,7 +4306,7 @@ static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, I static void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap) { - planeinfo_t *planeinfo = HWR_CreateDrawNode(DRAWNODE_PLANE); + planeinfo_t *planeinfo = static_cast(HWR_CreateDrawNode(DRAWNODE_PLANE)); planeinfo->isceiling = isceiling; planeinfo->fixedheight = fixedheight; @@ -4281,7 +4324,7 @@ static void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, b // When that happens it'll just be done through HWR_AddTransparentFloor and HWR_RenderPlane static void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, extracolormap_t *planecolormap) { - polyplaneinfo_t *polyplaneinfo = HWR_CreateDrawNode(DRAWNODE_POLYOBJECT_PLANE); + polyplaneinfo_t *polyplaneinfo = static_cast(HWR_CreateDrawNode(DRAWNODE_POLYOBJECT_PLANE)); polyplaneinfo->isceiling = isceiling; polyplaneinfo->fixedheight = fixedheight; @@ -4320,7 +4363,7 @@ static void HWR_RenderDrawNodes(void) PS_START_TIMING(ps_hw_nodesorttime); - sortindex = Z_Malloc(sizeof(INT32) * numdrawnodes, PU_STATIC, NULL); + sortindex = static_cast(Z_Malloc(sizeof(INT32) * numdrawnodes, PU_STATIC, NULL)); // Reversed order for (i = 0; i < numdrawnodes; i++) @@ -4519,7 +4562,7 @@ static void HWR_AddSprites(sector_t *sec) { // Use the smaller setting if (limit_dist) - limit_dist = min(current_bsp_culling_distance/mapobjectscale, limit_dist); + limit_dist = std::min(current_bsp_culling_distance/mapobjectscale, limit_dist); else limit_dist = current_bsp_culling_distance/mapobjectscale; } @@ -4565,7 +4608,7 @@ static void HWR_AddPrecipitationSprites(void) } if (current_bsp_culling_distance) - drawdist = min((fixed_t)current_bsp_culling_distance, drawdist); + drawdist = std::min((fixed_t)current_bsp_culling_distance, drawdist); R_GetRenderBlockMapDimensions(drawdist, &xl, &xh, &yl, &yh); @@ -4632,10 +4675,10 @@ static void HWR_ProjectSprite(mobj_t *thing) return; // uncapped/interpolation - interpmobjstate_t interp = {0}; + interpmobjstate_t interp = {}; if (cv_maxinterpdist.value) - dist = R_QuickCamDist(thing->x, thing->y); + dist = std_R_QuickCamDist(thing->x, thing->y); if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) { @@ -4926,21 +4969,21 @@ static void HWR_ProjectSprite(mobj_t *thing) if ((vis->mobj->flags & MF_BOSS) && (vis->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash" { if (vis->mobj->type == MT_CYBRAKDEMON) - vis->colormap = R_GetTranslationColormap(TC_ALLWHITE, 0, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_ALLWHITE, SKINCOLOR_NONE, GTC_CACHE)); else if (vis->mobj->type == MT_METALSONIC_BATTLE) - vis->colormap = R_GetTranslationColormap(TC_METALSONIC, 0, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_METALSONIC, SKINCOLOR_NONE, GTC_CACHE)); else - vis->colormap = R_GetTranslationColormap(TC_BOSS, 0, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_BOSS, SKINCOLOR_NONE, GTC_CACHE)); } else if (thing->color) { // New colormap stuff for skins Tails 06-07-2002 if (thing->colorized) - vis->colormap = R_GetTranslationColormap(TC_RAINBOW, thing->color, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_RAINBOW, static_cast(thing->color), GTC_CACHE)); else if (thing->skin && thing->sprite == SPR_PLAY) // This thing is a player! - vis->colormap = R_GetLocalTranslationColormap(thing->skin, thing->localskin, thing->color, GTC_CACHE, thing->skinlocal); + vis->colormap = static_cast(R_GetLocalTranslationColormap(static_cast(thing->skin), static_cast(thing->localskin), static_cast(thing->color), GTC_CACHE, thing->skinlocal)); else - vis->colormap = R_GetTranslationColormap(TC_DEFAULT, thing->color, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_DEFAULT, static_cast(thing->color), GTC_CACHE)); } else { @@ -4990,10 +5033,10 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) } // uncapped/interpolation - interpmobjstate_t interp = {0}; + interpmobjstate_t interp = {}; if (cv_maxinterpdist.value) - dist = R_QuickCamDist(thing->x, thing->y); + dist = std_R_QuickCamDist(thing->x, thing->y); // do interpolation if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) @@ -5201,11 +5244,11 @@ void HWR_BuildSkyDome(void) sky->vertex_count = 2 * sky->rows * (sky->columns * 2 + 2) + sky->columns * 2; if (!sky->loops) - sky->loops = malloc((sky->rows * 2 + 2) * sizeof(sky->loops[0])); + sky->loops = static_cast(malloc((sky->rows * 2 + 2) * sizeof(sky->loops[0]))); // create vertex array if (!sky->data) - sky->data = malloc(sky->vertex_count * sizeof(sky->data[0])); + sky->data = static_cast(malloc(sky->vertex_count * sizeof(sky->data[0]))); sky->texture = texturetranslation[skytexture]; sky->width = texture->width; @@ -5413,48 +5456,55 @@ void HWR_SetStencilState(int state, int level) GL_SetSpecialState(HWD_SET_PORTAL_MODE, state); } -typedef void (*bspfunc)(INT32 bspnum); - // Renders the current viewpoint, though takes portal arguments for recursive portals. +namespace +{ + enum class RenderViewpointType + { + kPortal, + kNormal, + }; + +template void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { gl_portallist_t portallist; const boolean skybox = (skyboxmo[0] && cv_skybox.value); - const boolean useportals = HWR_UsePortals() && allow_portals; - bspfunc bspFunc = (useportals && portalclipline) ? HWR_RenderPortalBSPNode : HWR_RenderBSPNode; portallist.base = portallist.cap = NULL; + HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regural walls - if (useportals && stencil_level < cv_maxportals.value) // if recursion limit is not reached + if constexpr (Type == RenderViewpointType::kPortal) { - gl_portal_t *portal; - - // search for portals in current frame - currentportallist = &portallist; - HWR_SetPortalState(GLPORTAL_SEARCH); - - HWR_ClearClipper(); - - if (rootportal) - HWR_PortalClipping(rootportal); - - validcount++; - - // no actual rendering happens - bspFunc((INT32)numnodes-1); - - // for each found portal: - // note: if necessary, could sort the portals here? - for (portal = portallist.base; portal; portal = portal->next) + if (allow_portals && stencil_level < cv_maxportals.value) // if recursion limit is not reached { - HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); - } + gl_portal_t *portal; - HWR_SetPortalState(GLPORTAL_INSIDE); // when portal walls are encountered in following bsp traversal, nothing should be drawn + // search for portals in current frame + currentportallist = &portallist; + HWR_SetPortalState(GLPORTAL_SEARCH); + + HWR_ClearClipper(); + + if (rootportal) + HWR_PortalClipping(rootportal); + + validcount++; + + // no actual rendering happens + HWR_RenderBSPNode((INT32)numnodes-1); + + // for each found portal: + // note: if necessary, could sort the portals here? + for (portal = portallist.base; portal; portal = portal->next) + { + HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); + } + + HWR_SetPortalState(GLPORTAL_INSIDE); // when portal walls are encountered in following bsp traversal, nothing should be drawn + } } - else - HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regural walls // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); @@ -5464,10 +5514,13 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl HWR_ClearSprites(); HWR_ClearClipper(); - if (useportals && rootportal) + if constexpr (Type == RenderViewpointType::kPortal) { - HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search - HWR_PortalClipping(rootportal); + if (allow_portals && rootportal) + { + HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search + HWR_PortalClipping(rootportal); + } } if (HWR_IsWireframeMode()) @@ -5482,21 +5535,33 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (LIKELY(cv_glbatching.value)) HWR_StartBatching(); - if (useportals && !rootportal && portallist.base && !skybox) // if portals have been drawn in the main view, then render skywalls differently - gl_collect_skywalls = true; + if constexpr (Type == RenderViewpointType::kPortal) + { + if (allow_portals && !rootportal && portallist.base && !skybox) // if portals have been drawn in the main view, then render skywalls differently + gl_collect_skywalls = true; - // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. - // This fixes specific effects not working, such as horizon lines. - SINT8 oldgl_portal_state = gl_portal_state; + // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. + // This fixes specific effects not working, such as horizon lines. + SINT8 oldgl_portal_state = gl_portal_state; - if (gl_portal_state != GLPORTAL_OFF) // if we already haven't hit the recursion limit or we already ended our portal shenanigans - HWR_SetPortalState(GLPORTAL_INSIDE); // TURN IT OFF + if (gl_portal_state != GLPORTAL_OFF) // if we already haven't hit the recursion limit or we already ended our portal shenanigans + HWR_SetPortalState(GLPORTAL_INSIDE); // TURN IT OFF - // Recursively "render" the BSP tree. - bspFunc((INT32)numnodes-1); + // Recursively "render" the BSP tree. + if (allow_portals && portalclipline) + HWR_RenderBSPNode((INT32)numnodes-1); + else + HWR_RenderBSPNode((INT32)numnodes-1); - // woo we back - HWR_SetPortalState(oldgl_portal_state); + // woo we back + HWR_SetPortalState(oldgl_portal_state); + } + + if constexpr (Type == RenderViewpointType::kNormal) + { + // Recursively "render" the BSP tree. + HWR_RenderBSPNode((INT32)numnodes-1); + } if (allow_portals) // looks weird, but this is only true when its not skybox rendering skipping precip in skyboxes like software does HWR_AddPrecipitationSprites(); @@ -5506,17 +5571,20 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (LIKELY(cv_glbatching.value)) HWR_RenderBatches(); - if (skyWallVertexArraySize) // if there are skywalls to draw using the alternate method + if constexpr (Type == RenderViewpointType::kPortal) { - HWR_SetStencilState(HWR_STENCIL_SKY, -1); - HWR_DrawSkyWallList(); - HWR_SkyWallList_Clear(); - HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); - drewsky = false; - HWR_DrawSkyBackground(); - HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); - GL_ClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer - HWR_SetTransform(fpov);// restore transform + if (skyWallVertexArraySize) // if there are skywalls to draw using the alternate method + { + HWR_SetStencilState(HWR_STENCIL_SKY, -1); + HWR_DrawSkyWallList(); + HWR_SkyWallList_Clear(); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); + drewsky = false; + HWR_DrawSkyBackground(); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); + GL_ClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer + HWR_SetTransform(fpov);// restore transform + } } gl_collect_skywalls = false; @@ -5539,9 +5607,15 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (HWR_IsWireframeMode()) GL_SetSpecialState(HWD_SET_WIREFRAME, 0); - HWR_FreePortalList(portallist); + HWR_FreePortalList(portallist); // always call this just in case } +}; +extern "C" { + void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { + HWR_RenderViewpoint(rootportal, fpov, player, stencil_level, allow_portals); + } +} // ========================================================================== // Render the current frame. @@ -5588,7 +5662,10 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) } portalclipline = NULL; - HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); + if (UNLIKELY(HWR_UsePortals())) + HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); + else + HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); // Unset transform and shader GL_SetTransform(NULL); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 9fd4faa5d..7681309c1 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -20,6 +20,10 @@ #ifndef __HWR_MAIN_H__ #define __HWR_MAIN_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "hw_gl.h" #include "hw_glob.h" #include "hw_data.h" @@ -34,10 +38,6 @@ #define GLENCORE -#ifdef __cplusplus -extern "C" { -#endif - // Startup & Shutdown the hardware mode renderer void HWR_Startup(void); void HWR_Shutdown(void); @@ -110,6 +110,7 @@ void HWR_AddCommands(void); void HWR_RenderPlayerView(void); void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals); +void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals); void HWR_ClearSkyDome(void); void HWR_BuildSkyDome(void); diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index fe643df13..939a60300 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -169,7 +169,7 @@ void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float // go to portal frame lmao HWR_PortalFrame(portal); // call HWR_RenderViewpoint - HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); + HWR_RenderPortalViewpoint(portal, fpov, player, stencil_level + 1, true); // return to current frame if (rootportal) HWR_PortalFrame(rootportal); diff --git a/src/hardware/hw_portal.h b/src/hardware/hw_portal.h index f42d2f61c..494110d79 100644 --- a/src/hardware/hw_portal.h +++ b/src/hardware/hw_portal.h @@ -14,6 +14,10 @@ #ifndef __HW_PORTAL__ #define __HW_PORTAL__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef HWRENDER #include "../doomstat.h" @@ -77,5 +81,9 @@ void HWR_FreePortalList(gl_portallist_t portallist); boolean HWR_PortalCheckPointSide(fixed_t x, fixed_t y); boolean HWR_PortalCheckBBox(const fixed_t *bspcoord); +#endif + +#ifdef __cplusplus +}// extern "C" #endif #endif diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index b70febad4..e0d7e13ac 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -20,6 +20,10 @@ #ifndef _R_OPENGL_H_ #define _R_OPENGL_H_ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef HAVE_SDL #define _MATH_DEFINES_DEFINED @@ -143,4 +147,8 @@ typedef enum GLF_NOTEXENV = 0x02, } oglflags_t; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_fixed.h b/src/m_fixed.h index ae77c83b9..c0afae941 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -15,6 +15,10 @@ #ifndef __M_FIXED__ #define __M_FIXED__ +#ifdef __cplusplus +extern "C" { +#endif + #include "doomtype.h" #ifdef __GNUC__ #include @@ -370,4 +374,8 @@ void FM_MultMatrix(matrix_t *dest, const matrix_t *multme); void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); +#ifdef __cplusplus +} // extern "C" +#endif + #endif //m_fixed.h diff --git a/src/st_stuff.h b/src/st_stuff.h index d0ed92b1a..5ffb3334f 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -14,6 +14,10 @@ #ifndef __STSTUFF_H__ #define __STSTUFF_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "doomtype.h" #include "d_event.h" #include "d_player.h" @@ -142,4 +146,8 @@ extern UINT16 objectsdrawn; extern consvar_t cv_lessflicker; extern consvar_t cv_stagetitle; +#ifdef __cplusplus +} // extern "C" +#endif + #endif From 729c60c9b0abbba8778e55f1d67a8e19c7e0ddf3 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 10:20:33 +0100 Subject: [PATCH 31/43] thanks michaelsoft very cool --- src/hardware/hw_main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 0667c9806..a1185f38d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -11,14 +11,15 @@ /// \file /// \brief hardware renderer, using the standard HardWareRender driver DLL for SRB2 +#ifdef HWRENDER + #include -#include +#define _USE_MATH_DEFINES +#include #include "../doomstat.h" #include "../doomdef.h" -#ifdef HWRENDER - #include "hw_main.h" #include "hw_glob.h" #include "hw_gl.h" From 0dcdcc3da1e04ea0189d6b224cfc92b281a2c61b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 07:54:34 +0200 Subject: [PATCH 32/43] fix hw_main compiler warning --- src/hardware/hw_main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index a1185f38d..acbd865b8 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1026,7 +1026,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, // Lactozilla: If both heights of a side lay on the same position, then this wall is a triangle. // To avoid division by zero, which would result in a NaN, we check if the vertical difference // between the two vertices is not zero. - if (fpclassify(diff) == FP_ZERO) + if (std::fpclassify(diff) == FP_ZERO) pegmul = 0.0; else pegmul = (pegb - pegt) / diff; @@ -1038,7 +1038,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, endpegt = wallVerts[2].t; endpegb = wallVerts[1].t; - if (fpclassify(diff) == FP_ZERO) + if (std::fpclassify(diff) == FP_ZERO) endpegmul = 0.0; else endpegmul = (endpegb - endpegt) / diff; @@ -2028,7 +2028,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((roverflags & FF_TRANSLUCENT && rover->alpha < 256) || rover->blend) { - blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent; + blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent); Surf.PolyColor.s.alpha = CLAMP(rover->alpha, 0, 255); } @@ -2145,7 +2145,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((roverflags & FF_TRANSLUCENT && rover->alpha < 256) || rover->blend) { - blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent; + blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent); Surf.PolyColor.s.alpha = CLAMP(rover->alpha, 0, 255); } @@ -3079,7 +3079,7 @@ static void HWR_Subsector(size_t num) false, *rover->bottomheight, *gl_frontsector->lightlist[light].lightlevel, - CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent), + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent)), false, gl_frontsector->lightlist[light].extra_colormap); } else @@ -3125,7 +3125,7 @@ static void HWR_Subsector(size_t num) true, *rover->topheight, *gl_frontsector->lightlist[light].lightlevel, - CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent), + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent)), false, gl_frontsector->lightlist[light].extra_colormap); } else @@ -5171,7 +5171,7 @@ static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, float z = (realRadius * (float)sin(topAngle)); float timesRepeat = (4 * (256.0f / sky->width)); - if (fpclassify(timesRepeat) == FP_ZERO) + if (std::fpclassify(timesRepeat) == FP_ZERO) timesRepeat = 1.0f; if (!foglayer) From 72a67d306fd7dce569abd8850dbc0374727eb81e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 08:17:08 +0200 Subject: [PATCH 33/43] slightly cleanup addline stuff no clue why i just didnt do this before lel --- src/hardware/hw_bsp.c | 7 +-- src/hardware/hw_main.cpp | 100 ++++++++++++++++----------------------- src/r_bsp.cpp | 6 +-- src/r_defs.h | 1 + 4 files changed, 50 insertions(+), 64 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 934f13a14..76231750c 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -371,12 +371,13 @@ static poly_t *CutOutSubsecPoly(seg_t *lseg, INT32 count, poly_t *poly) line_t *line = lseg->linedef; // portal check - if (!gl_maphasportals && line->special == 40 && lseg->side == 0) + if (!gl_maphasportals && line->special == PORTALSPECIAL && lseg->side == 0) { // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->tag, -1); + INT32 line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->tag, -1); + if (line == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->tag, line2); + line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->tag, line2); if (line2 >= 0) // found it! gl_maphasportals = 1; } diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index acbd865b8..cef5ec941 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2327,6 +2327,40 @@ static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) // SoM: Backsector needs to be run through R_FakeFlat static sector_t tempsec; + auto do_addline = [&](bool dontdraw) { + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); + + if (CheckClip(gl_frontsector, gl_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; + } + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) + return; + } + + if constexpr (Type == AddLineType::kPortal) + { + if (gl_portal_state != GLPORTAL_SEARCH && !dontdraw)// no need to do this during the portal check + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + } + else if constexpr (Type == AddLineType::kNormal) + { + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + } + }; + if constexpr (Type == AddLineType::kPortal) { boolean dont_draw = false; @@ -2343,15 +2377,15 @@ static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) if (gl_portal_state == GLPORTAL_STENCIL || gl_portal_state == GLPORTAL_DEPTH) goto doaddline; - if (line->linedef->special == 40) + if (line->linedef->special == PORTALSPECIAL) { if (line->side == 0) { // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); + INT32 line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, -1); if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); + line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, line2); if (line2 >= 0) // found it! { @@ -2366,59 +2400,11 @@ static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) } doaddline: - if (!line->backsector) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - } - else - { - gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); - - if (CheckClip(gl_frontsector, gl_backsector)) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - checkforemptylines = false; - } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) - return; - } - - if (LIKELY(gl_portal_state != GLPORTAL_SEARCH && !dont_draw))// no need to do this during the portal check - HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D - return; + do_addline(dont_draw); // no need to do this during the portal check } - - if constexpr (Type == AddLineType::kNormal) + else if constexpr (Type == AddLineType::kNormal) { - if (!line->backsector) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - } - else - { - gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); - - if (CheckClip(gl_frontsector, gl_backsector)) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - checkforemptylines = false; - } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) - return; - } - - HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D - return; + do_addline(false); } } @@ -3252,8 +3238,7 @@ static void HWR_RenderBSPNode(INT32 bspnum) if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1]))) return; } - - if constexpr (Type == BspType::kNormal) + else if constexpr (Type == BspType::kNormal) { // Recursively divide front space (toward the viewer). HWR_RenderBSPNode(bsp->children[side]); @@ -5557,8 +5542,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl // woo we back HWR_SetPortalState(oldgl_portal_state); } - - if constexpr (Type == RenderViewpointType::kNormal) + else if constexpr (Type == RenderViewpointType::kNormal) { // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index f0fb7cb4e..482b7c57f 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -385,15 +385,15 @@ static void R_AddLine(seg_t *line) backsector = line->backsector; // Portal line - if (line->linedef->special == 40 && line->side == 0) + if (line->linedef->special == PORTALSPECIAL && line->side == 0) { if (portalrender < cv_maxportals.value) { // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); + INT32 line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, -1); if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); + line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, line2); if (line2 >= 0) // found it! { diff --git a/src/r_defs.h b/src/r_defs.h index c130547db..e1fc574bc 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -420,6 +420,7 @@ typedef enum } slopetype_t; #define HORIZONSPECIAL 41 +#define PORTALSPECIAL 40 typedef struct line_s { From 148fcc8dab66d56a7d64d5285a97fdcf2fe7017c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 12:07:47 +0200 Subject: [PATCH 34/43] friendship with constexpr started --- src/hardware/hw_main.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index cef5ec941..9405bdb9a 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -102,10 +102,10 @@ sector_t *gl_backsector; static boolean gl_maphashorizonlines = false; // values for the far clipping plane -static float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; +static constexpr float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; // values for bsp culling // slightly higher than the far clipping plane to compensate for impreciseness -static INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT, +static constexpr INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT, (6144+512)*FRACUNIT, (8192+512)*FRACUNIT, (12288+512)*FRACUNIT, (16384+512)*FRACUNIT}; // Performance stats @@ -4155,8 +4155,8 @@ static int CompareVisSprites(const void *p1, const void *p2) // "boolean to int" // check for precip first, because then sprX->mobj is actually a precipmobj_t and does not have flags2 or tracer - int transparency1 = (!spr1->precip && (spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK); - int transparency2 = (!spr2->precip && (spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK); + const int transparency1 = (!spr1->precip && (spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK); + const int transparency2 = (!spr2->precip && (spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK); idiff = transparency1 - transparency2; if (idiff != 0) return idiff; @@ -4369,7 +4369,8 @@ static void HWR_RenderDrawNodes(void) for (i = run_start+1; i < numdrawnodes; i++) { - if (drawnodes[sortindex[i]].type != DRAWNODE_PLANE) break; + if (drawnodes[sortindex[i]].type != DRAWNODE_PLANE) + break; } run_end = i-1; @@ -4705,8 +4706,8 @@ static void HWR_ProjectSprite(mobj_t *thing) return; const boolean mirrored = thing->mirrored; - const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); - const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); + const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); this_scale = FixedToFloat(interp.scale); spritexscale = FixedToFloat(interp.spritexscale); @@ -4723,7 +4724,7 @@ static void HWR_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE // determine here if sprite should rotate for optimization const boolean sliprollrotate = (cv_sliptideroll.value && (thing->player && thing->player->sliproll)); - const boolean shouldrotate = (interp.sloperoll || interp.slopepitch || interp.roll || interp.pitch || thing->rollangle || sliprollrotate); + const boolean shouldrotate = (interp.sloperoll || interp.slopepitch || interp.roll || interp.pitch || thing->rollangle || sliprollrotate); #endif //Fab : 02-08-98: 'skin' override spritedef currently used for skin @@ -5144,8 +5145,8 @@ static gl_sky_t gl_sky; static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, signed char yflip, float delta, boolean foglayer) { - static const float scale = 10000.0f; - static const float maxSideAngle = DEG2RADGL(60.0f); + static constexpr float scale = 10000.0f; + static constexpr float maxSideAngle = DEG2RADGL(60.0f); float topAngle = DEG2RADGL(c / (float)sky->columns * 360.0f); float sideAngle = (maxSideAngle * (float)(sky->rows - r) / (float)sky->rows); @@ -5285,7 +5286,7 @@ void HWR_BuildSkyDome(void) static boolean drewsky = false; // precompute to save a bit of division -static const float FINEDEGREE = (360.0f/(float)FINEANGLES); +static constexpr float FINEDEGREE = (360.0f/(float)FINEANGLES); static void HWR_DrawSkyBackground(void) { @@ -5512,7 +5513,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (HWR_IsWireframeMode()) GL_SetSpecialState(HWD_SET_WIREFRAME, 1); - ps_numbspcalls.value.i = 0; + ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; PS_START_TIMING(ps_bsptime); @@ -5584,7 +5585,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl HWR_DrawModels(); PS_STOP_TIMING(ps_hw_spritedrawtime); - ps_numdrawnodes.value.i = 0; + ps_numdrawnodes.value.i = 0; ps_hw_nodesorttime.value.p = 0; ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); @@ -5685,10 +5686,6 @@ static void HWR_RollTransform(FTransform *tr, angle_t roll) void HWR_RenderPlayerView(void) { - player_t * player = &players[displayplayers[viewssnum]]; - - const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on - // Clear the color buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs. if (viewssnum == 0) // Only do it if it's the first screen being rendered { @@ -5719,6 +5716,9 @@ void HWR_RenderPlayerView(void) if (viewssnum > 3) return; + player_t * player = &players[displayplayers[viewssnum]]; + const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on + // Render the skybox if there is one. PS_START_TIMING(ps_skyboxtime); drewsky = false; @@ -6055,7 +6055,7 @@ static void HWR_DoPostProcessor(player_t *player) //UINT8 viewnum = R_GetViewNumber(); // see below //camera_t *thiscam = &camera[viewnum]; - camera_t *thiscam = &camera[0]; + const camera_t *thiscam = &camera[0]; // Not supported in splitscreen - someone want to add support? const boolean screenwave = (!splitscreen && (thiscam->postimg & POSTIMG_WATER || thiscam->postimg & POSTIMG_HEAT)); From 3f5328371a0c280f954bf64c1a95bc75cbcfaa4f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 15:26:18 +0200 Subject: [PATCH 35/43] put interp distance stuff into a function just some code dupe cleanup also account for c++ so we can use the same macro lel --- src/hardware/hw_main.cpp | 20 +++----------------- src/hardware/hw_md2.c | 2 +- src/r_things.cpp | 33 ++++++++++++++++----------------- src/r_things.h | 6 ++++++ 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 9405bdb9a..c7bba9f2a 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3517,8 +3517,6 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t } } -#define std_R_QuickCamDist(x, y) std::max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) - // This is expecting a pointer to an array containing 4 wallVerts for a sprite static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts, const boolean precip, const boolean papersprite) { @@ -3530,13 +3528,9 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts // uncapped/interpolation interpmobjstate_t interp = {}; float basey, lowy; - INT32 dist = -1; - - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(spr->mobj->x, spr->mobj->y); // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(spr->mobj)) { if (precip) { @@ -4647,7 +4641,6 @@ static void HWR_ProjectSprite(mobj_t *thing) angle_t camang = 0; #endif INT32 heightsec, phs; - INT32 dist = -1; fixed_t spr_width, spr_height; fixed_t spr_offset, spr_topoffset; @@ -4664,10 +4657,7 @@ static void HWR_ProjectSprite(mobj_t *thing) // uncapped/interpolation interpmobjstate_t interp = {}; - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(thing)) { R_InterpolateMobjState(thing, rendertimefrac, &interp); } @@ -5008,7 +4998,6 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) size_t lumpoff; unsigned rot = 0; UINT8 flip; - INT32 dist = -1; if (!thing) return; @@ -5022,11 +5011,8 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) // uncapped/interpolation interpmobjstate_t interp = {}; - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist((mobj_t*)thing)) { R_InterpolatePrecipMobjState(thing, rendertimefrac, &interp); } diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 2696cf89d..e1b31bda0 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1187,7 +1187,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) spriteinfo_t *sprinfo; interpmobjstate_t interp; - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || R_QuickCamDist(spr->mobj->x, spr->mobj->y) < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(spr->mobj)) { R_InterpolateMobjState(spr->mobj, rendertimefrac, &interp); } diff --git a/src/r_things.cpp b/src/r_things.cpp index 683904ccb..000139ce1 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1164,8 +1164,6 @@ fixed_t R_GetSpriteDirectionalLighting(angle_t angle) return extralight; } -#define std_R_QuickCamDist(x, y) std::max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) - // // R_ProjectSprite // Generates a vissprite for a thing @@ -1206,7 +1204,6 @@ static void R_ProjectSprite(mobj_t *thing) //SoM: 3/17/2000 fixed_t gz, gzt; INT32 heightsec, phs; - INT32 dist = -1; INT32 light = 0; lighttable_t **lights_array = spritelights; fixed_t this_scale; @@ -1233,14 +1230,11 @@ static void R_ProjectSprite(mobj_t *thing) const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); const boolean papersprite = (thing->frame & FF_PAPERSPRITE); - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - // uncapped/interpolation interpmobjstate_t interp = {}; // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(oldthing)) { R_InterpolateMobjState(oldthing, rendertimefrac, &interp); } @@ -1862,25 +1856,20 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) fixed_t gz, gzt; fixed_t this_scale; - INT32 dist = 1; - if (!thing || thing->subsector == NULL) return; - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - - // uncapped/interpolation - interpmobjstate_t interp = {}; - // okay... this is a hack, but weather isn't networked, so it should be ok if (!P_PrecipThinker(thing)) { return; } + // uncapped/interpolation + interpmobjstate_t interp = {}; + // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist((mobj_t*)thing)) { R_InterpolatePrecipMobjState(thing, rendertimefrac, &interp); } @@ -2919,7 +2908,7 @@ boolean R_ThingVisible (mobj_t *thing) if (splitscreen) { - if ((viewssnum == 0 && (thing->eflags & MFE_DRAWONLYFORP1)) + if ((viewssnum == 0 && (thing->eflags & MFE_DRAWONLYFORP1)) || (viewssnum == 1 && (thing->eflags & MFE_DRAWONLYFORP2)) || (viewssnum == 2 && (thing->eflags & MFE_DRAWONLYFORP2)) || (viewssnum == 3 && (thing->eflags & MFE_DRAWONLYFORP4))) @@ -2942,6 +2931,16 @@ boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist) return true; } +boolean R_CheckInterpDist(mobj_t *thing) +{ + if (!cv_maxinterpdist.value) + return true; + + const INT32 dist = R_QuickCamDist(thing->x, thing->y); + + return (dist < cv_maxinterpdist.value); +} + boolean R_ThingIsFullBright(mobj_t *thing) { return ((thing->frame & FF_BRIGHTMASK) == FF_FULLBRIGHT); diff --git a/src/r_things.h b/src/r_things.h index 45f1fc30e..e7afe7498 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -39,7 +39,12 @@ extern "C" { // as an non-fixed-point integer. // It is very rough, tho it is used only for optimizing out unnecessary // interpolation, so it is kinda ok on big distances. + +#ifdef __cplusplus +#define R_QuickCamDist(x, y) std::max(std::abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), std::abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) +#else #define R_QuickCamDist(x, y) max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) +#endif // Constant arrays used for psprite clipping // and initializing clipping. @@ -84,6 +89,7 @@ void R_DrawMasked(maskcount_t* masks, INT32 nummasks); boolean R_ThingVisible(mobj_t *thing); boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist); +boolean R_CheckInterpDist(mobj_t *thing); boolean R_ThingIsFullBright(mobj_t *thing); boolean R_ThingIsSemiBright(mobj_t *thing); From 7e06fc986f2d64e863ff9695678d645956d057ff Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 15:20:26 +0200 Subject: [PATCH 36/43] this is INT32 so cast to that lel --- src/hardware/hw_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index c7bba9f2a..f266cf64f 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3893,7 +3893,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) return; const boolean papersprite = (spr->mobj->frame & FF_PAPERSPRITE); - sector_t *sector = spr->mobj->subsector->sector; + const sector_t *sector = spr->mobj->subsector->sector; if (sector->numlights) { @@ -3978,13 +3978,13 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) // colormap test INT32 lightlevel = 255; - boolean lightset = HWR_OverrideObjectLightLevel(spr->mobj, &lightlevel); + const boolean lightset = HWR_OverrideObjectLightLevel(spr->mobj, &lightlevel); extracolormap_t *colormap = sector->extra_colormap; const boolean fullbright = R_ThingIsFullBright(spr->mobj); if (!lightset) { - lightlevel = std::min(static_cast(sector->lightlevel), 255); + lightlevel = std::min(static_cast(sector->lightlevel), 255); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); } From 83d0f6bb50c6e9a7daf427b3380acb54a20217fa Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 18:27:39 +0200 Subject: [PATCH 37/43] move kart hud stuff into k_hud hope i got everything lol --- src/Sourcefile | 1 + src/d_main.c | 1 + src/hu_stuff.c | 1 + src/k_hud.c | 4800 +++++++++++++++++++++++++++++++++++++++++++++ src/k_hud.h | 81 + src/k_kart.c | 4763 +------------------------------------------- src/k_kart.h | 47 +- src/lua_baselib.c | 1 + src/lua_hudlib.c | 1 + src/m_menu.c | 1 + src/st_stuff.c | 1 + src/w_wad.c | 1 + src/y_inter.c | 1 + 13 files changed, 4896 insertions(+), 4804 deletions(-) create mode 100644 src/k_hud.c create mode 100644 src/k_hud.h diff --git a/src/Sourcefile b/src/Sourcefile index 4895adc1d..b85cbf060 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -78,6 +78,7 @@ p_tick.c p_user.c k_director.c k_kart.c +k_hud.c k_stats.c lua_baselib.c lua_blockmaplib.c diff --git a/src/d_main.c b/src/d_main.c index 9f46eb79f..fed32eef5 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -72,6 +72,7 @@ #include "d_protocol.h" #include "m_perfstats.h" #include "k_kart.h" +#include "k_hud.h" #include "core/memory.h" diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f8f0524b2..cd4c60dd8 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -49,6 +49,7 @@ #include "s_sound.h" // song credits #include "k_kart.h" +#include "k_hud.h" #include "m_textinput.h" diff --git a/src/k_hud.c b/src/k_hud.c new file mode 100644 index 000000000..6c0488aae --- /dev/null +++ b/src/k_hud.c @@ -0,0 +1,4800 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 2018-2020 by Kart Krew +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file k_hud.c +/// \brief HUD drawing functions exclusive to Kart + +#include "doomdef.h" +#include "doomstat.h" +#include "doomtype.h" +#include "command.h" +#include "d_netcmd.h" +#include "d_player.h" +#include "hu_stuff.h" +#include "g_game.h" +#include "i_joy.h" +#include "m_fixed.h" +#include "m_menu.h" // ffdhidshfuisduifigergho9igj89dgodhfih AAAAAAAAAA +#include "p_local.h" +#include "p_setup.h" +#include "r_defs.h" +#include "r_draw.h" +#include "r_state.h" +#include "r_fps.h" +#include "s_sound.h" +#include "screen.h" +#include "st_stuff.h" +#include "tables.h" +#include "v_video.h" +#include "z_zone.h" +#include "m_cond.h" +#include "k_director.h" +#include "k_kart.h" +#include "lua_hud.h" // For Lua hud checks +#include "d_main.h" // found_extra_kart +#include "i_video.h" + +#include "k_hud.h" + +#ifdef ROTSPRITE +#include "r_patchrotation.h" +#endif + +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + +#define XTRA3PSCALE 50135 //0.765 +#define XTRA3VSCALE 35344 //0.55 + +// Hud offset cvars +#define IMPL_HUD_OFFSET_X(name)\ +consvar_t cv_##name##_xoffset = {"hud_" #name "_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; + +#define IMPL_HUD_OFFSET_Y(name)\ +consvar_t cv_##name##_yoffset = {"hud_" #name "_yoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; + +#define IMPL_HUD_OFFSET(name)\ +IMPL_HUD_OFFSET_X(name)\ +IMPL_HUD_OFFSET_Y(name) + +IMPL_HUD_OFFSET(item); // Item box +IMPL_HUD_OFFSET(time); // Time +IMPL_HUD_OFFSET(laps); // Number of laps +IMPL_HUD_OFFSET(dnft); // Countdown (did not finish timer) +IMPL_HUD_OFFSET(speed); // Speedometer +IMPL_HUD_OFFSET(posi); // Position in race +IMPL_HUD_OFFSET(wheel); // RA Wheel +IMPL_HUD_OFFSET(face); // Mini rankings +IMPL_HUD_OFFSET(stcd); // Starting countdown +IMPL_HUD_OFFSET_Y(chek); // Check gfx +IMPL_HUD_OFFSET(mini); // Minimap +IMPL_HUD_OFFSET(want); // Wanted +IMPL_HUD_OFFSET(stat); // Stats + +#undef IMPL_HUD_OFFSET +#undef IMPL_HUD_OFFSET_X +#undef IMPL_HUD_OFFSET_Y + +// extra hud things +consvar_t cv_showstats = {"showstats", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_highresportrait = {"highresportrait", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // make char potraits use their high-res version instead + +CV_PossibleValue_t inputdisplay_cons_t[NUMINPUTDISPLAYSTUFF]; +consvar_t cv_showinput = {"showinput", "Off", CV_SAVE, inputdisplay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +CV_PossibleValue_t minimapdot_cons_t[NUMMINIMAPDOTSTUFF]; +consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showminimapnames = {"showminimapnames", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showminimapangle = {"showminimapangle", "Off", CV_SAVE, minimapdot_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_posanim = {"postitionanimation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_smallposnum = {"smallpositionnumber", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_showlapemblem = {"showlapemblem", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t huditemamount_cons_t[] = {{0, "Vanilla"}, {1, "Multiple"}, {2, "Always"},{0, NULL}}; +consvar_t cv_huditemamount = {"showitemamountnumber", "Vanilla", CV_SAVE, huditemamount_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fancyroulette = {"animatedroulette", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_darkitembox = {"darkitembox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // itembox gets a dark border with specific items +consvar_t cv_multiitemicon = {"multiitemicon", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_showlaptimes = {"showlaptimes", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_biglaps = {"biglaphud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // here for ppl who dont want to make 2 more patches for their custom hud + +// Speedometer +CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; +consvar_t cv_newspeedometer = {"newspeedometer", "Default", CV_SAVE, speedo_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_battlespeedo = {"battlespeedo", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // toggle for showing the speedometer in battlemode + +// Colourized HUD +consvar_t cv_colorizedhud = {"colorizedhud", "Off", CV_SAVE|CV_CALL, CV_OnOff, SaturnHud_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_colorizeditembox = {"colorizeditembox", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t HudColor_cons_t[MAXSKINCOLORS+1]; +consvar_t cv_colorizedhudcolor = {"colorizedhudcolor", "Skin Color", CV_SAVE, HudColor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// Driftgauge +static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { + {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; +CV_PossibleValue_t driftgaugestyle_cons_t[NUMDGAUGESTUFF]; + +consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_driftgaugetrans = {"kartdriftgaugetransparency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_driftgaugestyle = {"kartdriftgaugestyle", "1", CV_SAVE, driftgaugestyle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// Nametags +static CV_PossibleValue_t nametagtrans_cons_t[] = { + {0, "Never"}, {1, "Far only"}, {2, "Dynamic"}, {3, "Always"}, {4, "HUD Trans."}, {0, NULL}}; +static CV_PossibleValue_t nametagdistance_cons_t[] = { + {0, "MIN"}, {640, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t nametagmaxplayer_cons_t[] = { + {1, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t nametagsize_cons_t[] = { + {0, "Off"}, {1, "Small"}, {2, "Minimal"}, {0, NULL}}; +static CV_PossibleValue_t nametagrestat_cons_t[] = { + {0, "Off"}, {1, "Restat"}, {2, "Always"}, {0, NULL}}; + +consvar_t cv_nametag = {"kartnametag", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagtrans = {"kartnametagtransparency", "Dynamic", CV_SAVE, nametagtrans_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagfacerank = {"kartnametagfacerank", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagrestat = {"kartnametagrestat", "Restat", CV_SAVE, nametagrestat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagdist = {"kartnametagdist", "320", CV_SAVE, nametagdistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagmaxplayers = {"kartnametagmaxplayers", "3", CV_SAVE, nametagmaxplayer_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagmaxlenght = {"kartnametagmaxlenght", "12", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showownnametag = {"kartnametagshowown", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_smallnametags = {"kartnametagsmall", "Off", CV_SAVE, nametagsize_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_nametagscore = {"kartnametagscore", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// Registers kart client commands and variables. +// Nothing needed for a dedicated server should be registered here. +void K_RegisterKartHudStuff(void) +{ + HudColor_cons_t[0].value = 0; + HudColor_cons_t[0].strvalue = "Skin Color"; + + for (INT32 i = 1; i < MAXSKINCOLORS; i++) + { + HudColor_cons_t[i].value = i; + HudColor_cons_t[i].strvalue = KartColor_Names[i]; // SRB2kart + } + HudColor_cons_t[MAXSKINCOLORS].value = 0; + HudColor_cons_t[MAXSKINCOLORS].strvalue = NULL; + +#define REG_HUD_OFFSET_X(name)\ + CV_RegisterVar(&cv_##name##_xoffset); + +#define REG_HUD_OFFSET_Y(name)\ + CV_RegisterVar(&cv_##name##_yoffset); + +#define REG_HUD_OFFSET(name)\ + REG_HUD_OFFSET_X(name)\ + REG_HUD_OFFSET_Y(name) + + REG_HUD_OFFSET(item); // Item box + REG_HUD_OFFSET(time); // Time + REG_HUD_OFFSET(laps); // Number of laps + REG_HUD_OFFSET(dnft); // Countdown (did not finish timer) + REG_HUD_OFFSET(speed); // Speedometer + REG_HUD_OFFSET(posi); // Position in race + REG_HUD_OFFSET(wheel); // Position in race + REG_HUD_OFFSET(face); // Mini rankings + REG_HUD_OFFSET(stcd); // Starting countdown + REG_HUD_OFFSET_Y(chek); // Check gfx + REG_HUD_OFFSET(mini); // Minimap + REG_HUD_OFFSET(want); // Wanted + REG_HUD_OFFSET(stat); // Stats + +#undef REG_HUD_OFFSET +#undef REG_HUD_OFFSET_X +#undef REG_HUD_OFFSET_Y + + CV_RegisterVar(&cv_kartminimap); + CV_RegisterVar(&cv_kartcheck); + + CV_RegisterVar(&cv_kartspeedometer); + + CV_RegisterVar(&cv_showstats); + CV_RegisterVar(&cv_showinput); + + CV_RegisterVar(&cv_posanim); + CV_RegisterVar(&cv_smallposnum); + + CV_RegisterVar(&cv_fancyroulette); + + CV_RegisterVar(&cv_showlaptimes); + CV_RegisterVar(&cv_newspeedometer); + + CV_RegisterVar(&cv_battlespeedo); + + CV_RegisterVar(&cv_minihead); + CV_RegisterVar(&cv_showminimapnames); + CV_RegisterVar(&cv_showminimapangle); + + CV_RegisterVar(&cv_showlapemblem); + + CV_RegisterVar(&cv_stagetitle); + + // Colourized HUD + CV_RegisterVar(&cv_colorizedhud); + CV_RegisterVar(&cv_colorizedhudcolor); + CV_RegisterVar(&cv_colorizeditembox); + + CV_RegisterVar(&cv_biglaps); + + CV_RegisterVar(&cv_darkitembox); + + CV_RegisterVar(&cv_multiitemicon); + CV_RegisterVar(&cv_huditemamount); + + CV_RegisterVar(&cv_highresportrait); + + CV_RegisterVar(&cv_nametag); + CV_RegisterVar(&cv_nametagtrans); + CV_RegisterVar(&cv_nametagfacerank); + CV_RegisterVar(&cv_nametagmaxplayers); + CV_RegisterVar(&cv_nametagmaxlenght); + CV_RegisterVar(&cv_nametagdist); + CV_RegisterVar(&cv_showownnametag); + CV_RegisterVar(&cv_smallnametags); + CV_RegisterVar(&cv_nametagrestat); + CV_RegisterVar(&cv_nametagscore); + CV_RegisterVar(&cv_shownametagspectator); + + CV_RegisterVar(&cv_driftgauge); + CV_RegisterVar(&cv_driftgaugeofs); + CV_RegisterVar(&cv_driftgaugetrans); + CV_RegisterVar(&cv_driftgaugestyle); + + CV_RegisterVar(&cv_lessflicker); +} + +//{ Patch Definitions + +// --Saturn patches-- +// dont leave those unitialized incase we missed a check somewhere + +// -Speedometers- + +// Smol speedo +static patch_t *skp_smallsticker = NULL; +static patch_t *skp_smallsticker3 = NULL; + +static patch_t *skp_speedpatches[5] = {NULL}; + +// Achii speedo +static patch_t *skp_smallstickerachi = NULL; +static patch_t *skp_speedpatchesachi[5] = {NULL}; +static patch_t *skp_smallstickerachiclr = NULL; +static patch_t *skp_speedpatchesachiclr[5] = {NULL}; + +// Kartz speedo +static patch_t *kp_kartzspeedo[25] = {NULL}; +static patch_t *kp_kartzspeedo_smol[25] = {NULL}; + +// dial speedometer +static patch_t *skp_rankfinish = NULL; +static patch_t *skp_dialbase[2] = {NULL}; +static patch_t *skp_speedpatchesdial[5] = {NULL}; +static patch_t *skp_dialnum[10] = {NULL}; +//static patch_t *skp_dialclr = NULL; +static patch_t *skp_dialbaseclr[2] = {NULL}; +static patch_t *skp_speedpatchesdialclr[5] = {NULL}; +static patch_t *skp_dialnumclr[10] = {NULL}; + +// -Colourized hud- + +static patch_t *kp_timestickerclr = NULL; +static patch_t *kp_timestickerwideclr = NULL; +static patch_t *kp_lapstickerclr = NULL; +static patch_t *kp_lapstickerbigclr = NULL; +static patch_t *kp_lapstickerbig2clr = NULL; +static patch_t *kp_lapstickerwideclr = NULL; +//static patch_t *kp_lapstickernarrowclr = NULL; +static patch_t *kp_bumperstickerclr = NULL; +static patch_t *kp_bumperstickerwideclr = NULL; +static patch_t *kp_karmastickerclr = NULL; +static patch_t *kp_timeoutstickerclr = NULL; +static patch_t *skp_smallstickerclr = NULL; +static patch_t *skp_smallstickerclr3 = NULL; +static patch_t *kp_itemmulstickerclr[2] = {NULL}; +static patch_t *kp_itembgclr[4] = {NULL}; + +// -Misc.- + +static patch_t *kp_lapstickerbig = NULL; +static patch_t *kp_lapstickerbig2 = NULL; + +static patch_t *nametagpic = NULL; +static patch_t *nametagline = NULL; +static patch_t *nametagspeed = NULL; +static patch_t *nametagweight = NULL; + +static patch_t *driftgauge = NULL; +static patch_t *driftgaugecolor = NULL; +static patch_t *driftgaugesmall = NULL; +static patch_t *driftgaugesmallcolor = NULL; + +static patch_t *kp_minimapdot = NULL; + +static patch_t *joybacking = NULL; +static patch_t *joyknob = NULL; +static patch_t *joyshadow = NULL; + +static patch_t *kp_multjawz = NULL; +static patch_t *kp_multsneaker[2] = {NULL}; +static patch_t *kp_multbanana[3] = {NULL}; + +static void K_LoadSaturnHUDGraphics(void) +{ + INT32 i; + char buffer[9]; + + if (found_extra_kart) + { + if (xtra_speedo) // smol speedometer + { + skp_smallsticker = (patch_t *)W_CachePatchName("SP_SMSTC", PU_HUDGFX); + skp_speedpatches[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatches[1] = (patch_t *)W_CachePatchName("SP_MKMH", PU_HUDGFX); + skp_speedpatches[2] = (patch_t *)W_CachePatchName("SP_MMPH", PU_HUDGFX); + skp_speedpatches[3] = (patch_t *)W_CachePatchName("SP_MFRAC", PU_HUDGFX); + skp_speedpatches[4] = (patch_t *)W_CachePatchName("SP_MPERC", PU_HUDGFX); + } + + if (achi_speedo) + { + skp_smallstickerachi = (patch_t *)W_CachePatchName("SP_AMSTC", PU_HUDGFX); + skp_speedpatchesachi[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesachi[1] = (patch_t *)W_CachePatchName("SP_AKMH", PU_HUDGFX); + skp_speedpatchesachi[2] = (patch_t *)W_CachePatchName("SP_AMPH", PU_HUDGFX); + skp_speedpatchesachi[3] = (patch_t *)W_CachePatchName("SP_AFRAC", PU_HUDGFX); + skp_speedpatchesachi[4] = (patch_t *)W_CachePatchName("SP_APERC", PU_HUDGFX); + } + + if (dial_speedo) + { + skp_rankfinish = (patch_t *)W_CachePatchName("RANKFIN", PU_HUDGFX); + skp_dialbase[0] = (patch_t *)W_CachePatchName("K_DSPBS1", PU_HUDGFX); + skp_dialbase[1] = (patch_t *)W_CachePatchName("K_DSPBS2", PU_HUDGFX); + + skp_speedpatchesdial[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesdial[1] = (patch_t *)W_CachePatchName("SP_DKMH", PU_HUDGFX); + skp_speedpatchesdial[2] = (patch_t *)W_CachePatchName("SP_DMPH", PU_HUDGFX); + skp_speedpatchesdial[3] = (patch_t *)W_CachePatchName("SP_DFRAC", PU_HUDGFX); + skp_speedpatchesdial[4] = (patch_t *)W_CachePatchName("SP_DPERC", PU_HUDGFX); + + sprintf(buffer, "K_DSPNMx"); + for (i = 0; i < 10; i++) + { + buffer[7] = '0'+(i%10); + skp_dialnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + } + + // KartZ speedo + if (kartz_speedo) + { + const char* patchNames[] = { + "K_KZSP1", "K_KZSP2", "K_KZSP3", "K_KZSP4", "K_KZSP5", + "K_KZSP6", "K_KZSP7", "K_KZSP8", "K_KZSP9", "K_KZSP10", + "K_KZSP11", "K_KZSP12", "K_KZSP13", "K_KZSP14", "K_KZSP15", + "K_KZSP16", "K_KZSP17", "K_KZSP18", "K_KZSP19", "K_KZSP20", + "K_KZSP21", "K_KZSP22", "K_KZSP23", "K_KZSP24", "K_KZSP25" + }; + + for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) + { + kp_kartzspeedo[m] = (patch_t *)W_CachePatchName(patchNames[m], PU_HUDGFX); + } + } + + if (kartz_speedo_smol) + { + const char* patchNames[] = { + "K_KZSS1", "K_KZSS2", "K_KZSS3", "K_KZSS4", "K_KZSS5", + "K_KZSS6", "K_KZSS7", "K_KZSS8", "K_KZSS9", "K_KZSS10", + "K_KZSS11", "K_KZSS12", "K_KZSS13", "K_KZSS14", "K_KZSS15", + "K_KZSS16", "K_KZSS17", "K_KZSS18", "K_KZSS19", "K_KZSS20", + "K_KZSS21", "K_KZSS22", "K_KZSS23", "K_KZSS24", "K_KZSS25" + }; + + for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) + { + kp_kartzspeedo_smol[m] = (patch_t *)W_CachePatchName(patchNames[m], PU_HUDGFX); + } + } + + if (big_lap) + { + kp_lapstickerbig = (patch_t *)W_CachePatchName("K_STLAPB", PU_HUDGFX); + kp_lapstickerbig2 = (patch_t *)W_CachePatchName("K_STLA2B", PU_HUDGFX); + } + + // Nametags + if (nametaggfx) + { + nametagpic = (patch_t *)W_CachePatchName("NTLINE", PU_HUDGFX); + nametagline = (patch_t *)W_CachePatchName("NTLINEV", PU_HUDGFX); + nametagspeed = (patch_t *)W_CachePatchName("NTSP", PU_HUDGFX); + nametagweight = (patch_t *)W_CachePatchName("NTWH", PU_HUDGFX); + } + + if (driftgaugegfx) + { + driftgauge = (patch_t *)W_CachePatchName("K_DGAU", PU_HUDGFX); + driftgaugesmall = (patch_t *)W_CachePatchName("K_DGSU", PU_HUDGFX); + + if (driftgaugegfx_clr) + { + driftgaugecolor = (patch_t *)W_CachePatchName("K_DCAU", PU_HUDGFX); + driftgaugesmallcolor = (patch_t *)W_CachePatchName("K_DCSU", PU_HUDGFX); + } + } + + if (joystickicon) + { + joybacking = (patch_t *)W_CachePatchName("JOYBCK", PU_HUDGFX); + joyknob = (patch_t *)W_CachePatchName("JOYKNB", PU_HUDGFX); + joyshadow = (patch_t *)W_CachePatchName("JOYSHD", PU_HUDGFX); + } + + if (minidoticon) + { + kp_minimapdot = (patch_t *)W_CachePatchName("MMAPDOT", PU_HUDGFX); + } + + if (multiitem_icon) + { + kp_multsneaker[0] = (patch_t *)W_CachePatchName("K_ITSHO2", PU_HUDGFX); + kp_multsneaker[1] = (patch_t *)W_CachePatchName("K_ITSHO3", PU_HUDGFX); + kp_multbanana[0] = (patch_t *)W_CachePatchName("K_ITBAN2", PU_HUDGFX); + kp_multbanana[1] = (patch_t *)W_CachePatchName("K_ITBAN3", PU_HUDGFX); + kp_multbanana[2] = (patch_t *)W_CachePatchName("K_ITBAN4", PU_HUDGFX); + kp_multjawz = (patch_t *)W_CachePatchName("K_ITJAW2", PU_HUDGFX); + } + } + + if (found_extra2_kart) + { + if (xtra_speedo_clr) + { + skp_smallstickerclr = (patch_t *)W_CachePatchName("SC_SMSTC", PU_HUDGFX); + } + + if (xtra_speedo_clr3) + { + skp_smallstickerclr3 = (patch_t *)W_CachePatchName("SC_SM3TC", PU_HUDGFX); + } + + if (achi_speedo_clr) + { + skp_smallstickerachiclr = (patch_t *)W_CachePatchName("SC_AMSTC", PU_HUDGFX); + skp_speedpatchesachiclr[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesachiclr[1] = (patch_t *)W_CachePatchName("SC_AKMH", PU_HUDGFX); + skp_speedpatchesachiclr[2] = (patch_t *)W_CachePatchName("SC_AMPH", PU_HUDGFX); + skp_speedpatchesachiclr[3] = (patch_t *)W_CachePatchName("SC_AFRAC", PU_HUDGFX); + skp_speedpatchesachiclr[4] = (patch_t *)W_CachePatchName("SC_APERC", PU_HUDGFX); + } + + if (dial_speedo_clr) + { + skp_dialbaseclr[0] = (patch_t *)W_CachePatchName("K_DSPBC1", PU_HUDGFX); + skp_dialbaseclr[1] = (patch_t *)W_CachePatchName("K_DSPBC2", PU_HUDGFX); + + skp_speedpatchesdialclr[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatchesdialclr[1] = (patch_t *)W_CachePatchName("SC_DKMH", PU_HUDGFX); + skp_speedpatchesdialclr[2] = (patch_t *)W_CachePatchName("SC_DMPH", PU_HUDGFX); + skp_speedpatchesdialclr[3] = (patch_t *)W_CachePatchName("SC_DFRAC", PU_HUDGFX); + skp_speedpatchesdialclr[4] = (patch_t *)W_CachePatchName("SC_DPERC", PU_HUDGFX); + + sprintf(buffer, "K_DSPNCx"); + for (i = 0; i < 10; i++) + { + buffer[7] = '0'+(i%10); + skp_dialnumclr[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + } + + if (big_lap_color) + { + kp_lapstickerbigclr = (patch_t *)W_CachePatchName("K_SCLAPB", PU_HUDGFX); + kp_lapstickerbig2clr = (patch_t *)W_CachePatchName("K_SCLA2B", PU_HUDGFX); + } + + // Colourized hud + if (clr_hud) + { + kp_timestickerclr = (patch_t *)W_CachePatchName("K_SCTIME", PU_HUDGFX); + kp_timestickerwideclr = (patch_t *)W_CachePatchName("K_SCTIMW", PU_HUDGFX); + kp_lapstickerclr = (patch_t *)W_CachePatchName("K_SCLAPS", PU_HUDGFX); + kp_lapstickerwideclr = (patch_t *)W_CachePatchName("K_SCLAPW", PU_HUDGFX); + kp_bumperstickerclr = (patch_t *)W_CachePatchName("K_SCBALN", PU_HUDGFX); + kp_bumperstickerwideclr = (patch_t *)W_CachePatchName("K_SCBALW", PU_HUDGFX); + kp_karmastickerclr = (patch_t *)W_CachePatchName("K_SCKARM", PU_HUDGFX); + kp_timeoutstickerclr = (patch_t *)W_CachePatchName("K_SCTOUT", PU_HUDGFX); + kp_itembgclr[0] = (patch_t *)W_CachePatchName("K_ITBC" , PU_HUDGFX); + kp_itembgclr[1] = (patch_t *)W_CachePatchName("K_ITBCD" , PU_HUDGFX); + kp_itembgclr[2] = (patch_t *)W_CachePatchName("K_ISBC" , PU_HUDGFX); + kp_itembgclr[3] = (patch_t *)W_CachePatchName("K_ISBCD" , PU_HUDGFX); + kp_itemmulstickerclr[1] = (patch_t *)W_CachePatchName("K_ISMULC", PU_HUDGFX); + kp_itemmulstickerclr[0] = (patch_t *)W_CachePatchName("K_ITMULC", PU_HUDGFX); + } + } + + if (found_extra3_kart) + { + if (xtra_speedo3) // 80x11 patch scaled to size + { + skp_smallsticker3 = (patch_t *)W_CachePatchName("SP_SM3TC", PU_HUDGFX); + } + } +} + +// -- Kart patches -- + +#define NUMPOSNUMS 10 +#define NUMPOSFRAMES 7 // White, three blues, three reds +#define NUMWINFRAMES 6 // Red, yellow, green, cyan, blue, purple + +static patch_t *kp_nodraw; +static patch_t *kp_timesticker; +static patch_t *kp_timestickerwide; +static patch_t *kp_lapsticker; +static patch_t *kp_lapstickerwide; +//static patch_t *kp_lapstickernarrow; +static patch_t *kp_splitlapflag; +static patch_t *kp_bumpersticker; +static patch_t *kp_bumperstickerwide; +static patch_t *kp_karmasticker; +static patch_t *kp_splitkarmabomb; +static patch_t *kp_timeoutsticker; + +static patch_t *kp_startcountdown[16]; +static patch_t *kp_racefinish[6]; + +static patch_t *kp_positionnum[NUMPOSNUMS][NUMPOSFRAMES]; +static patch_t *kp_winnernum[NUMPOSFRAMES]; + +static patch_t *kp_facenum[MAXPLAYERS+1]; +static patch_t *kp_facehighlight[8]; + +static patch_t *kp_rankbumper; +static patch_t *kp_tinybumper[2]; +static patch_t *kp_ranknobumpers; + +static patch_t *kp_battlewin; +static patch_t *kp_battlecool; +static patch_t *kp_battlelose; +static patch_t *kp_battlewait; +static patch_t *kp_battleinfo; +static patch_t *kp_wanted; +static patch_t *kp_wantedsplit; +static patch_t *kp_wantedreticle; + +static patch_t *kp_itembg[4]; +static patch_t *kp_itemtimer[2]; +static patch_t *kp_itemmulsticker[2]; +static patch_t *kp_itemx; + +static patch_t *kp_sneaker[2]; +static patch_t *kp_rocketsneaker[2]; +static patch_t *kp_invincibility[13]; +static patch_t *kp_banana[2]; +static patch_t *kp_eggman[2]; +static patch_t *kp_orbinaut[5]; +static patch_t *kp_jawz[2]; +static patch_t *kp_mine[2]; +static patch_t *kp_ballhog[2]; +static patch_t *kp_selfpropelledbomb[2]; +static patch_t *kp_grow[2]; +static patch_t *kp_shrink[2]; +static patch_t *kp_thundershield[2]; +static patch_t *kp_hyudoro[2]; +static patch_t *kp_pogospring[2]; +static patch_t *kp_kitchensink[2]; +static patch_t *kp_sadface[2]; + +static patch_t *kp_check[6]; + +static patch_t *kp_eggnum[4]; + +static patch_t *kp_fpview[3]; +static patch_t *kp_inputwheel[5]; + +static patch_t *kp_challenger[25]; + +static patch_t *kp_lapanim_lap[7]; +static patch_t *kp_lapanim_final[11]; +static patch_t *kp_lapanim_number[10][3]; +static patch_t *kp_lapanim_emblem[2]; +static patch_t *kp_lapanim_hand[3]; + +static patch_t *kp_yougotem; + +void K_LoadKartHUDGraphics(void) +{ + INT32 i, j; + char buffer[9]; + + // Null Stuff + kp_nodraw = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); + + // Stickers + kp_timesticker = (patch_t *)W_CachePatchName("K_STTIME", PU_HUDGFX); + kp_timestickerwide = (patch_t *)W_CachePatchName("K_STTIMW", PU_HUDGFX); + kp_lapsticker = (patch_t *)W_CachePatchName("K_STLAPS", PU_HUDGFX); + kp_lapstickerwide = (patch_t *)W_CachePatchName("K_STLAPW", PU_HUDGFX); + //kp_lapstickernarrow = (patch_t *)W_CachePatchName("K_STLAPN", PU_HUDGFX); + kp_splitlapflag = (patch_t *)W_CachePatchName("K_SPTLAP", PU_HUDGFX); + kp_bumpersticker = (patch_t *)W_CachePatchName("K_STBALN", PU_HUDGFX); + kp_bumperstickerwide = (patch_t *)W_CachePatchName("K_STBALW", PU_HUDGFX); + kp_karmasticker = (patch_t *)W_CachePatchName("K_STKARM", PU_HUDGFX); + kp_splitkarmabomb = (patch_t *)W_CachePatchName("K_SPTKRM", PU_HUDGFX); + kp_timeoutsticker = (patch_t *)W_CachePatchName("K_STTOUT", PU_HUDGFX); + + // Starting countdown + kp_startcountdown[0] = (patch_t *)W_CachePatchName("K_CNT3A", PU_HUDGFX); + kp_startcountdown[1] = (patch_t *)W_CachePatchName("K_CNT2A", PU_HUDGFX); + kp_startcountdown[2] = (patch_t *)W_CachePatchName("K_CNT1A", PU_HUDGFX); + kp_startcountdown[3] = (patch_t *)W_CachePatchName("K_CNTGOA", PU_HUDGFX); + kp_startcountdown[4] = (patch_t *)W_CachePatchName("K_CNT3B", PU_HUDGFX); + kp_startcountdown[5] = (patch_t *)W_CachePatchName("K_CNT2B", PU_HUDGFX); + kp_startcountdown[6] = (patch_t *)W_CachePatchName("K_CNT1B", PU_HUDGFX); + kp_startcountdown[7] = (patch_t *)W_CachePatchName("K_CNTGOB", PU_HUDGFX); + + // Splitscreen + kp_startcountdown[8] = (patch_t *)W_CachePatchName("K_SMC3A", PU_HUDGFX); + kp_startcountdown[9] = (patch_t *)W_CachePatchName("K_SMC2A", PU_HUDGFX); + kp_startcountdown[10] = (patch_t *)W_CachePatchName("K_SMC1A", PU_HUDGFX); + kp_startcountdown[11] = (patch_t *)W_CachePatchName("K_SMCGOA", PU_HUDGFX); + kp_startcountdown[12] = (patch_t *)W_CachePatchName("K_SMC3B", PU_HUDGFX); + kp_startcountdown[13] = (patch_t *)W_CachePatchName("K_SMC2B", PU_HUDGFX); + kp_startcountdown[14] = (patch_t *)W_CachePatchName("K_SMC1B", PU_HUDGFX); + kp_startcountdown[15] = (patch_t *)W_CachePatchName("K_SMCGOB", PU_HUDGFX); + + // Finish + kp_racefinish[0] = (patch_t *)W_CachePatchName("K_FINA", PU_HUDGFX); + kp_racefinish[1] = (patch_t *)W_CachePatchName("K_FINB", PU_HUDGFX); + + // Splitscreen + kp_racefinish[2] = (patch_t *)W_CachePatchName("K_SMFINA", PU_HUDGFX); + kp_racefinish[3] = (patch_t *)W_CachePatchName("K_SMFINB", PU_HUDGFX); + + // 2P splitscreen + kp_racefinish[4] = (patch_t *)W_CachePatchName("K_2PFINA", PU_HUDGFX); + kp_racefinish[5] = (patch_t *)W_CachePatchName("K_2PFINB", PU_HUDGFX); + + // Position numbers + sprintf(buffer, "K_POSNxx"); + for (i = 0; i < NUMPOSNUMS; i++) + { + buffer[6] = '0'+i; + for (j = 0; j < NUMPOSFRAMES; j++) + { + buffer[7] = '0'+j; + kp_positionnum[i][j] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + } + + sprintf(buffer, "K_POSNWx"); + for (i = 0; i < NUMWINFRAMES; i++) + { + buffer[7] = '0'+i; + kp_winnernum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + sprintf(buffer, "OPPRNKxx"); + for (i = 0; i <= MAXPLAYERS; i++) + { + buffer[6] = '0'+(i/10); + buffer[7] = '0'+(i%10); + kp_facenum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + sprintf(buffer, "K_CHILIx"); + for (i = 0; i < 8; i++) + { + buffer[7] = '0'+(i+1); + kp_facehighlight[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // Extra ranking icons + kp_rankbumper = (patch_t *)W_CachePatchName("K_BLNICO", PU_HUDGFX); + kp_tinybumper[0] = (patch_t *)W_CachePatchName("K_BLNA", PU_HUDGFX); + kp_tinybumper[1] = (patch_t *)W_CachePatchName("K_BLNB", PU_HUDGFX); + kp_ranknobumpers = (patch_t *)W_CachePatchName("K_NOBLNS", PU_HUDGFX); + + // Battle graphics + kp_battlewin = (patch_t *)W_CachePatchName("K_BWIN", PU_HUDGFX); + kp_battlecool = (patch_t *)W_CachePatchName("K_BCOOL", PU_HUDGFX); + kp_battlelose = (patch_t *)W_CachePatchName("K_BLOSE", PU_HUDGFX); + kp_battlewait = (patch_t *)W_CachePatchName("K_BWAIT", PU_HUDGFX); + kp_battleinfo = (patch_t *)W_CachePatchName("K_BINFO", PU_HUDGFX); + kp_wanted = (patch_t *)W_CachePatchName("K_WANTED", PU_HUDGFX); + kp_wantedsplit = (patch_t *)W_CachePatchName("4PWANTED", PU_HUDGFX); + kp_wantedreticle = (patch_t *)W_CachePatchName("MMAPWANT", PU_HUDGFX); + + // Kart Item Windows + kp_itembg[0] = (patch_t *)W_CachePatchName("K_ITBG", PU_HUDGFX); + kp_itembg[1] = (patch_t *)W_CachePatchName("K_ITBGD", PU_HUDGFX); + kp_itemtimer[0] = (patch_t *)W_CachePatchName("K_ITIMER", PU_HUDGFX); + kp_itemmulsticker[0] = (patch_t *)W_CachePatchName("K_ITMUL", PU_HUDGFX); + kp_itemx = (patch_t *)W_CachePatchName("K_ITX", PU_HUDGFX); + // Splitscreen + kp_itembg[2] = (patch_t *)W_CachePatchName("K_ISBG", PU_HUDGFX); + kp_itembg[3] = (patch_t *)W_CachePatchName("K_ISBGD", PU_HUDGFX); + kp_itemtimer[1] = (patch_t *)W_CachePatchName("K_ISIMER", PU_HUDGFX); + kp_itemmulsticker[1] = (patch_t *)W_CachePatchName("K_ISMUL", PU_HUDGFX); + + // Kart Items + kp_sneaker[0] = (patch_t *)W_CachePatchName("K_ITSHOE", PU_HUDGFX); + kp_rocketsneaker[0] = (patch_t *)W_CachePatchName("K_ITRSHE", PU_HUDGFX); + kp_banana[0] = (patch_t *)W_CachePatchName("K_ITBANA", PU_HUDGFX); + kp_eggman[0] = (patch_t *)W_CachePatchName("K_ITEGGM", PU_HUDGFX); + kp_jawz[0] = (patch_t *)W_CachePatchName("K_ITJAWZ", PU_HUDGFX); + kp_mine[0] = (patch_t *)W_CachePatchName("K_ITMINE", PU_HUDGFX); + kp_ballhog[0] = (patch_t *)W_CachePatchName("K_ITBHOG", PU_HUDGFX); + kp_selfpropelledbomb[0] = (patch_t *)W_CachePatchName("K_ITSPB", PU_HUDGFX); + kp_grow[0] = (patch_t *)W_CachePatchName("K_ITGROW", PU_HUDGFX); + kp_shrink[0] = (patch_t *)W_CachePatchName("K_ITSHRK", PU_HUDGFX); + kp_thundershield[0] = (patch_t *)W_CachePatchName("K_ITTHNS", PU_HUDGFX); + kp_hyudoro[0] = (patch_t *)W_CachePatchName("K_ITHYUD", PU_HUDGFX); + kp_pogospring[0] = (patch_t *)W_CachePatchName("K_ITPOGO", PU_HUDGFX); + kp_kitchensink[0] = (patch_t *)W_CachePatchName("K_ITSINK", PU_HUDGFX); + kp_sadface[0] = (patch_t *)W_CachePatchName("K_ITSAD", PU_HUDGFX); + // Splitscreen + kp_sneaker[1] = (patch_t *)W_CachePatchName("K_ISSHOE", PU_HUDGFX); + kp_rocketsneaker[1] = (patch_t *)W_CachePatchName("K_ISRSHE", PU_HUDGFX); + kp_banana[1] = (patch_t *)W_CachePatchName("K_ISBANA", PU_HUDGFX); + kp_eggman[1] = (patch_t *)W_CachePatchName("K_ISEGGM", PU_HUDGFX); + kp_orbinaut[4] = (patch_t *)W_CachePatchName("K_ISORBN", PU_HUDGFX); + kp_jawz[1] = (patch_t *)W_CachePatchName("K_ISJAWZ", PU_HUDGFX); + kp_mine[1] = (patch_t *)W_CachePatchName("K_ISMINE", PU_HUDGFX); + kp_ballhog[1] = (patch_t *)W_CachePatchName("K_ISBHOG", PU_HUDGFX); + kp_selfpropelledbomb[1] = (patch_t *)W_CachePatchName("K_ISSPB", PU_HUDGFX); + kp_grow[1] = (patch_t *)W_CachePatchName("K_ISGROW", PU_HUDGFX); + kp_shrink[1] = (patch_t *)W_CachePatchName("K_ISSHRK", PU_HUDGFX); + kp_thundershield[1] = (patch_t *)W_CachePatchName("K_ISTHNS", PU_HUDGFX); + kp_hyudoro[1] = (patch_t *)W_CachePatchName("K_ISHYUD", PU_HUDGFX); + kp_pogospring[1] = (patch_t *)W_CachePatchName("K_ISPOGO", PU_HUDGFX); + kp_kitchensink[1] = (patch_t *)W_CachePatchName("K_ISSINK", PU_HUDGFX); + kp_sadface[1] = (patch_t *)W_CachePatchName("K_ISSAD", PU_HUDGFX); + + sprintf(buffer, "K_ITINVx"); + for (i = 0; i < 7; i++) + { + buffer[7] = '1'+i; + kp_invincibility[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + sprintf(buffer, "K_ITORBx"); + for (i = 0; i < 4; i++) + { + buffer[7] = '1'+i; + kp_orbinaut[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + sprintf(buffer, "K_ISINVx"); + for (i = 0; i < 6; i++) + { + buffer[7] = '1'+i; + kp_invincibility[i+7] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // CHECK indicators + sprintf(buffer, "K_CHECKx"); + for (i = 0; i < 6; i++) + { + buffer[7] = '1'+i; + kp_check[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // Eggman warning numbers + sprintf(buffer, "K_EGGNx"); + for (i = 0; i < 4; i++) + { + buffer[6] = '0'+i; + kp_eggnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // First person mode + kp_fpview[0] = (patch_t *)W_CachePatchName("VIEWA0", PU_HUDGFX); + kp_fpview[1] = (patch_t *)W_CachePatchName("VIEWB0D0", PU_HUDGFX); + kp_fpview[2] = (patch_t *)W_CachePatchName("VIEWC0E0", PU_HUDGFX); + + // Input UI Wheel + sprintf(buffer, "K_WHEELx"); + for (i = 0; i < 5; i++) + { + buffer[7] = '0'+i; + kp_inputwheel[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // HERE COMES A NEW CHALLENGER + sprintf(buffer, "K_CHALxx"); + for (i = 0; i < 25; i++) + { + buffer[6] = '0'+((i+1)/10); + buffer[7] = '0'+((i+1)%10); + kp_challenger[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // Lap start animation + sprintf(buffer, "K_LAP0x"); + for (i = 0; i < 7; i++) + { + buffer[6] = '0'+(i+1); + kp_lapanim_lap[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + sprintf(buffer, "K_LAPFxx"); + for (i = 0; i < 11; i++) + { + buffer[6] = '0'+((i+1)/10); + buffer[7] = '0'+((i+1)%10); + kp_lapanim_final[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + sprintf(buffer, "K_LAPNxx"); + for (i = 0; i < 10; i++) + { + buffer[6] = '0'+i; + for (j = 0; j < 3; j++) + { + buffer[7] = '0'+(j+1); + kp_lapanim_number[i][j] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + } + + sprintf(buffer, "K_LAPE0x"); + for (i = 0; i < 2; i++) + { + buffer[7] = '0'+(i+1); + kp_lapanim_emblem[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + sprintf(buffer, "K_LAPH0x"); + for (i = 0; i < 3; i++) + { + buffer[7] = '0'+(i+1); + kp_lapanim_hand[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + kp_yougotem = (patch_t *)W_CachePatchName("YOUGOTEM", PU_HUDGFX); + + if (found_extra_kart || found_extra2_kart || found_extra3_kart) + K_LoadSaturnHUDGraphics(); +} + +// For the item toggle menu +const char *K_GetItemPatch(UINT8 item, boolean tiny) +{ + switch (item) + { + case KITEM_SNEAKER: + case KRITEM_TRIPLESNEAKER: + return (tiny ? "K_ISSHOE" : "K_ITSHOE"); + case KITEM_ROCKETSNEAKER: + return (tiny ? "K_ISRSHE" : "K_ITRSHE"); + case KITEM_INVINCIBILITY: + return (tiny ? "K_ISINV1" : "K_ITINV1"); + case KITEM_BANANA: + case KRITEM_TRIPLEBANANA: + case KRITEM_TENFOLDBANANA: + return (tiny ? "K_ISBANA" : "K_ITBANA"); + case KITEM_EGGMAN: + return (tiny ? "K_ISEGGM" : "K_ITEGGM"); + case KITEM_ORBINAUT: + return (tiny ? "K_ISORBN" : "K_ITORB1"); + case KITEM_JAWZ: + case KRITEM_DUALJAWZ: + return (tiny ? "K_ISJAWZ" : "K_ITJAWZ"); + case KITEM_MINE: + return (tiny ? "K_ISMINE" : "K_ITMINE"); + case KITEM_BALLHOG: + return (tiny ? "K_ISBHOG" : "K_ITBHOG"); + case KITEM_SPB: + return (tiny ? "K_ISSPB" : "K_ITSPB"); + case KITEM_GROW: + return (tiny ? "K_ISGROW" : "K_ITGROW"); + case KITEM_SHRINK: + return (tiny ? "K_ISSHRK" : "K_ITSHRK"); + case KITEM_THUNDERSHIELD: + return (tiny ? "K_ISTHNS" : "K_ITTHNS"); + case KITEM_HYUDORO: + return (tiny ? "K_ISHYUD" : "K_ITHYUD"); + case KITEM_POGOSPRING: + return (tiny ? "K_ISPOGO" : "K_ITPOGO"); + case KITEM_KITCHENSINK: + return (tiny ? "K_ISSINK" : "K_ITSINK"); + case KRITEM_TRIPLEORBINAUT: + return (tiny ? "K_ISORBN" : "K_ITORB3"); + case KRITEM_QUADORBINAUT: + return (tiny ? "K_ISORBN" : "K_ITORB4"); + default: + return (tiny ? "K_ISSAD" : "K_ITSAD"); + } +} + +//} + +INT32 ITEM_X, ITEM_Y; // Item Window +INT32 TIME_X, TIME_Y; // Time Sticker +INT32 LAPS_X, LAPS_Y; // Lap Sticker +INT32 SPDM_X, SPDM_Y; // Speedometer +INT32 POSI_X, POSI_Y; // Position Number +INT32 FACE_X, FACE_Y; // Top-four Faces +INT32 STCD_X, STCD_Y; // Starting countdown +INT32 CHEK_Y; // CHECK graphic +INT32 MINI_X, MINI_Y; // Minimap +INT32 WANT_X, WANT_Y; // Battle WANTED poster + +// This is for the P2 and P4 side of splitscreen. Then we'll flip P1's and P2's to the bottom with V_SPLITSCREEN. +INT32 ITEM2_X, ITEM2_Y; +INT32 LAPS2_X, LAPS2_Y; +INT32 POSI2_X, POSI2_Y; + +static void K_initKartHUD(void) +{ + /* + BASEVIDWIDTH = 320 + BASEVIDHEIGHT = 200 + + Item window graphic is 41 x 33 + + Time Sticker graphic is 116 x 11 + Time Font is a solid block of (8 x [12) x 14], equal to 96 x 14 + Therefore, timestamp is 116 x 14 altogether + + Lap Sticker is 80 x 11 + Lap flag is 22 x 20 + Lap Font is a solid block of (3 x [12) x 14], equal to 36 x 14 + Therefore, lapstamp is 80 x 20 altogether + + Position numbers are 43 x 53 + + Faces are 32 x 32 + Faces draw downscaled at 16 x 16 + Therefore, the allocated space for them is 16 x 67 altogether + + ---- + + ORIGINAL CZ64 SPLITSCREEN: + + Item window: + if (!splitscreen) { ICONX = 139; ICONY = 20; } + else { ICONX = BASEVIDWIDTH-315; ICONY = 60; } + + Time: 236, STRINGY( 12) + Lap: BASEVIDWIDTH-304, STRINGY(BASEVIDHEIGHT-189) + + */ + + // Single Screen (defaults) + // Item Window + ITEM_X = 5 + cv_item_xoffset.value; // 5 + ITEM_Y = 5 + cv_item_yoffset.value; // 5 + // Level Timer + TIME_X = BASEVIDWIDTH - 148 + cv_time_xoffset.value; // 172 + TIME_Y = 9 + cv_time_yoffset.value; // 9 + // Level Laps + LAPS_X = 9 + cv_laps_xoffset.value; // 9 + LAPS_Y = BASEVIDHEIGHT - 29 + cv_laps_yoffset.value; // 171 + // Speedometer + SPDM_X = 9 + cv_speed_xoffset.value; // 9 + SPDM_Y = BASEVIDHEIGHT - 45 + cv_speed_yoffset.value; // 155 + // Position Number + POSI_X = BASEVIDWIDTH - 9 + cv_posi_xoffset.value; // 268 + POSI_Y = BASEVIDHEIGHT - 9 + cv_posi_yoffset.value; // 138 + // Top-Four Faces + FACE_X = 9 + cv_face_xoffset.value; // 9 + FACE_Y = 92 + cv_face_yoffset.value; // 92 + // Starting countdown + STCD_X = BASEVIDWIDTH/2 + cv_stcd_xoffset.value; // 9 + STCD_Y = BASEVIDHEIGHT/2 + cv_stcd_yoffset.value; // 92 + // CHECK graphic + CHEK_Y = BASEVIDHEIGHT + cv_chek_yoffset.value; // 200 + // Minimap + MINI_X = BASEVIDWIDTH - 50 + cv_mini_xoffset.value; // 270 + MINI_Y = (BASEVIDHEIGHT/2)-16 + cv_mini_yoffset.value; // 84 + // Battle WANTED poster + WANT_X = BASEVIDWIDTH - 55 + cv_want_xoffset.value; // 270 + WANT_Y = BASEVIDHEIGHT- 71 + cv_want_yoffset.value; // 176 + + if (splitscreen) // Splitscreen + { + ITEM_X = 5; + ITEM_Y = 3; + + LAPS_Y = (BASEVIDHEIGHT/2)-24; + + POSI_Y = (BASEVIDHEIGHT/2)- 2; + + STCD_Y = BASEVIDHEIGHT/4; + + MINI_Y = (BASEVIDHEIGHT/2); + + if (splitscreen > 1) // 3P/4P Small Splitscreen + { + // 1P (top left) + ITEM_X = -9; + ITEM_Y = -8; + + LAPS_X = 3; + LAPS_Y = (BASEVIDHEIGHT/2)-13; + + POSI_X = 24; + POSI_Y = (BASEVIDHEIGHT/2)- 16; + + // 2P (top right) + ITEM2_X = BASEVIDWIDTH-39; + ITEM2_Y = -8; + + LAPS2_X = BASEVIDWIDTH-3; + LAPS2_Y = (BASEVIDHEIGHT/2)-13; + + POSI2_X = BASEVIDWIDTH -4; + POSI2_Y = (BASEVIDHEIGHT/2)- 16; + + // Reminder that 3P and 4P are just 1P and 2P splitscreen'd to the bottom. + + STCD_X = BASEVIDWIDTH/4; + + MINI_X = (3*BASEVIDWIDTH/4); + MINI_Y = (3*BASEVIDHEIGHT/4); + + if (splitscreen > 2) // 4P-only + { + MINI_X = (BASEVIDWIDTH/2); + MINI_Y = (BASEVIDHEIGHT/2); + } + } + } + + if (timeinmap > 113 || forceshowhud) + hudtrans = cv_translucenthud.value; + else if (timeinmap > 105) + hudtrans = ((((INT32)timeinmap) - 105)*cv_translucenthud.value)/(113-105); + else + hudtrans = 0; + + // K_GetScreenCoords needs the right view* variables + R_SetViewContext(stplyrnum); + R_InterpolateView(rendertimefrac_unpaused, !cv_uncappedhud.value); +} + +UINT8 K_GetHudColor(void) +{ + if (cv_colorizedhud.value && cv_colorizedhudcolor.value) + return cv_colorizedhudcolor.value; + + return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : cv_playercolor.value); +} + +boolean K_UseColorHud(void) +{ + return (cv_colorizedhud.value && clr_hud); +} + +enum +{ + SPEEDO_VANILLA, + SPEEDO_EXTRA, + SPEEDO_ACHII, + SPEEDO_DIAL, + SPEEDO_PMETER, + SPEEDO_PMETERSMOL, + SPEEDO_EXTRA3, +}; + +static SINT8 K_GetSpeedometerStyle(void) +{ + if (cv_newspeedometer.value == 2 && xtra_speedo) + return SPEEDO_EXTRA; + else if (cv_newspeedometer.value == 3 && achi_speedo) + return SPEEDO_ACHII; + else if (cv_newspeedometer.value == 4 && dial_speedo) + return SPEEDO_DIAL; + else if (cv_newspeedometer.value == 5 && kartz_speedo) + return SPEEDO_PMETER; + else if (cv_newspeedometer.value == 6 && kartz_speedo_smol) + return SPEEDO_PMETERSMOL; + else if (cv_newspeedometer.value == 7 && xtra_speedo3) + return SPEEDO_EXTRA3; + else + return SPEEDO_VANILLA; +} + +static boolean K_UseColorSpeedo(int speedostyle) +{ + if (!K_UseColorHud()) + return false; + + switch (speedostyle) + { + case SPEEDO_EXTRA: + return xtra_speedo_clr; + case SPEEDO_ACHII: + return achi_speedo_clr; + case SPEEDO_DIAL: + return dial_speedo_clr; + case SPEEDO_EXTRA3: + return xtra_speedo_clr3; + default: + return false; + } +} + +static boolean K_IsHighResolution(void) +{ + return (vid.width >= 640 && vid.height >= 400); +} + +boolean K_UseHighResPortraits(void) +{ + return (cv_highresportrait.value && K_IsHighResolution()); +} + +// returns the players faceprefix +// accounts for localskins +patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum) +{ + if (!player->skinlocal) + return (K_UseHighResPortraits() ? facewantprefix[skinnum] : facerankprefix[skinnum]); + else + return (K_UseHighResPortraits() ? localfacewantprefix[skinnum] : localfacerankprefix[skinnum]); +} + +INT32 K_calcSplitFlags(INT32 snapflags) +{ + INT32 splitflags = 0; + + if (splitscreen == 0) + return snapflags; + + if (stplyrnum != 0) + { + if (splitscreen == 1 && stplyrnum == 1) + { + splitflags |= V_SPLITSCREEN; + } + else if (splitscreen > 1) + { + if (stplyrnum == 2 || (splitscreen == 3 && stplyrnum == 3)) + splitflags |= V_SPLITSCREEN; + if (stplyrnum == 1 || (splitscreen == 3 && stplyrnum == 3)) + splitflags |= V_HORZSCREEN; + } + } + + if (splitflags & V_SPLITSCREEN) + snapflags &= ~V_SNAPTOTOP; + else + snapflags &= ~V_SNAPTOBOTTOM; + + if (splitscreen > 1) + { + if (splitflags & V_HORZSCREEN) + snapflags &= ~V_SNAPTOLEFT; + else + snapflags &= ~V_SNAPTORIGHT; + } + + return (splitflags|snapflags); +} + +void K_getItemBoxDrawinfo(drawinfo_t *out) +{ + INT32 fx, fy, fflags; + + // pain and suffering defined below + if (splitscreen < 2) // don't change shit for THIS splitscreen. + { + fx = ITEM_X; + fy = ITEM_Y; + fflags = K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTOLEFT); + } + else // now we're having a fun game. + { + if (!(stplyrnum & 1)) // If we are P1 or P3... + { + fx = ITEM_X; + fy = ITEM_Y; + fflags = V_SNAPTOLEFT|(stplyrnum & 2 ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P3 to the bottom. + } + else // else, that means we're P2 or P4. + { + fx = ITEM2_X; + fy = ITEM2_Y; + fflags = V_SNAPTORIGHT|(stplyrnum & 2 ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P4 to the bottom + } + } + + out->x = fx; + out->y = fy; + out->flags = fflags; +} + +void K_getLapsDrawinfo(drawinfo_t *out) +{ + INT32 fx, fy, fflags; + + // pain and suffering defined below + if (splitscreen < 2) // don't change shit for THIS splitscreen. + { + fx = LAPS_X; + fy = LAPS_Y; + fflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); + } + else + { + if (!(stplyrnum & 1)) // If we are P1 or P3... + { + fx = LAPS_X; + fy = LAPS_Y; + fflags = V_SNAPTOLEFT|(stplyrnum & 2 ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. + } + else // else, that means we're P2 or P4. + { + fx = LAPS2_X; + fy = LAPS2_Y; + fflags = V_SNAPTORIGHT|(stplyrnum & 2 ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom + } + } + + out->x = fx; + out->y = fy; + out->flags = fflags; +} + +void K_getMinimapDrawinfo(drawinfo_t *out) +{ + INT32 fx = MINI_X, fy = MINI_Y, fflags = (splitscreen == 3 ? 0 : V_SNAPTORIGHT); // flags should only be 0 when it's centered (4p split) + + out->x = fx; + out->y = fy; + out->flags = fflags; +} + +INT32 K_getMinimapTrans(void) +{ + INT32 minimaptrans = cv_kartminimap.value; + + if (!minimaptrans) + return -1; + + if (forceshowhud) + return (10-minimaptrans)<kartstuff[k_bumper] ? -5 : -8) : 0); + + // Customizations c: + if (!splitscreen) + { + x += 18 + cv_stat_xoffset.value + spdxoffset; + y += cv_stat_yoffset.value + spdoffset; + } + else if (splitscreen == 1) // I tried my best, but this is still mess :/ < :Blobcatpats: c: + { + x -= 10; + y -= 40; + y += spdoffset; + + // If we are in 2-player splitscreen, for player 1 we move hud to up and remove snapping + // to bottom + if (splitnum == 0) + { + y /= 2; + flags = V_SNAPTOLEFT; + } + else + { + // Can move it down a bit + y += 45; + } + } + else + { + if (splitnum == 0 || splitnum == 2) // If we are P1 or P3... + { + // ye i just align it to position number lol + x = POSI_X + 19; + y = POSI_Y - 6; + flags = V_SNAPTOLEFT|((splitnum == 2) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. + } + else // else, that means we're P2 or P4. + { + x = POSI2_X - 75; + y = POSI2_Y - 6; + flags = V_SNAPTORIGHT|((splitnum == 3) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom + } + } + + flags |= V_HUDTRANS; + + skin_t *fakeskin; + fakeskin = K_GetPlayerSkin(stplyr); + + if (!splitscreen) + { + // Skin name + if (K_IsHighResolution()) // V_DrawSmallString becomes a mess at low resolutions lel + { + V_DrawSmallString(x+20, y+12, flags|V_ALLOWLOWERCASE|V_SkinColorToHighlightcolor(stplyr->skincolor), fakeskin->realname); + } + else + { + V_DrawThinString(x+20, y+7, flags|V_ALLOWLOWERCASE|V_SkinColorToHighlightcolor(stplyr->skincolor), fakeskin->realname); + } + + // Icon and stats + if (K_UseHighResPortraits()) + V_DrawSmallMappedPatch(x, y, flags, R_GetSkinFaceWant(stplyr), R_GetLocalTranslationColormap(fakeskin, fakeskin, stplyr->skincolor, GTC_CACHE, stplyr->skinlocal)); + else + V_DrawMappedPatch(x, y, flags, R_GetSkinFaceRank(stplyr), R_GetLocalTranslationColormap(fakeskin, fakeskin, stplyr->skincolor, GTC_CACHE, stplyr->skinlocal)); + + V_DrawMappedPatch(x-3, y-2, flags, kp_facenum[min(9, max(1, stplyr->kartspeed))], R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BLUEBERRY, GTC_CACHE)); + V_DrawMappedPatch(x+10, y+10, flags, kp_facenum[min(9, max(1, stplyr->kartweight))], R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BURGUNDY, GTC_CACHE)); + } + else + { + // In splitscreen, just draw a string with stats + V_DrawString(x, y+10, flags, va("\x84%dS \x87%dW", stplyr->kartspeed, stplyr->kartweight)); + } +} + +static void K_drawKartItem(void) +{ + // ITEM_X = BASEVIDWIDTH-50; // 270 + // ITEM_Y = 24; // 24 + + // Why write V_DrawScaledPatch calls over and over when they're all the same? + // Set to 'no item' just in case. + const UINT8 offset = ((splitscreen > 1) ? 1 : 0); + patch_t *localpatch = kp_nodraw; + patch_t *localbg; + boolean dark = false; + + patch_t *localinv = ((offset) ? kp_invincibility[((leveltime % (6*3)) / 3) + 7] : kp_invincibility[(leveltime % (7*3)) / 3]); + INT32 fx = 0, fy = 0, fflags = 0; // final coords for hud and flags... + INT32 numberdisplaymin = cv_huditemamount.value == 2 ? 1 : 2; // No longer a constant so other things can modify this value + INT32 itembar = 0; + INT32 maxl = 0; // itembar's normal highest value + const INT32 barlength = (splitscreen > 1 ? 12 : 26); + UINT8 localcolor = SKINCOLOR_NONE; + SINT8 colormode = TC_RAINBOW; + UINT8 *colmap = NULL; + UINT8 *colormap = NULL; + + if (stplyr->kartstuff[k_itemroulette]) + { + localcolor = K_GetHudColor(); + + switch((stplyr->kartstuff[k_itemroulette] % (14*3)) / 3) + { + // Each case is handled in threes, to give three frames of in-game time to see the item on the roulette + case 0: // Sneaker + localpatch = kp_sneaker[offset]; + //localcolor = SKINCOLOR_RASPBERRY; + break; + case 1: // Banana + localpatch = kp_banana[offset]; + //localcolor = SKINCOLOR_YELLOW; + break; + case 2: // Orbinaut + localpatch = kp_orbinaut[3+offset]; + //localcolor = SKINCOLOR_STEEL; + break; + case 3: // Mine + localpatch = kp_mine[offset]; + //localcolor = SKINCOLOR_JET; + break; + case 4: // Grow + localpatch = kp_grow[offset]; + //localcolor = SKINCOLOR_TEAL; + break; + case 5: // Hyudoro + localpatch = kp_hyudoro[offset]; + //localcolor = SKINCOLOR_STEEL; + break; + case 6: // Rocket Sneaker + localpatch = kp_rocketsneaker[offset]; + //localcolor = SKINCOLOR_TANGERINE; + break; + case 7: // Jawz + localpatch = kp_jawz[offset]; + //localcolor = SKINCOLOR_JAWZ; + break; + case 8: // Self-Propelled Bomb + localpatch = kp_selfpropelledbomb[offset]; + //localcolor = SKINCOLOR_JET; + break; + case 9: // Shrink + localpatch = kp_shrink[offset]; + //localcolor = SKINCOLOR_ORANGE; + break; + case 10: // Invincibility + localpatch = localinv; + //localcolor = SKINCOLOR_GREY; + break; + case 11: // Eggman Monitor + localpatch = kp_eggman[offset]; + //localcolor = SKINCOLOR_ROSE; + break; + case 12: // Ballhog + localpatch = kp_ballhog[offset]; + //localcolor = SKINCOLOR_LILAC; + break; + case 13: // Thunder Shield + localpatch = kp_thundershield[offset]; + //localcolor = SKINCOLOR_CYAN; + break; + /*case 14: // Pogo Spring + localpatch = kp_pogospring[offset]; + localcolor = SKINCOLOR_TANGERINE; + break; + case 15: // Kitchen Sink + localpatch = kp_kitchensink[offset]; + localcolor = SKINCOLOR_STEEL; + break;*/ + default: + break; + } + } + else + { + // I'm doing this a little weird and drawing mostly in reverse order + // The only actual reason is to make sneakers line up this way in the code below + // This shouldn't have any actual baring over how it functions + // Hyudoro is first, because we're drawing it on top of the player's current item + if (stplyr->kartstuff[k_stolentimer] > 0) + { + if (leveltime & 2) + localpatch = kp_hyudoro[offset]; + else + localpatch = kp_nodraw; + } + else if ((stplyr->kartstuff[k_stealingtimer] > 0) && (leveltime & 2)) + { + localpatch = kp_hyudoro[offset]; + } + else if (stplyr->kartstuff[k_eggmanexplode] > 1) + { + if (leveltime & 1) + localpatch = kp_eggman[offset]; + else + localpatch = kp_nodraw; + } + else if (stplyr->kartstuff[k_rocketsneakertimer] > 1) + { + itembar = stplyr->kartstuff[k_rocketsneakertimer]; + maxl = (itemtime*3) - barlength; + + if (leveltime & 1) + localpatch = kp_rocketsneaker[offset]; + else + localpatch = kp_nodraw; + } + else if (stplyr->kartstuff[k_growshrinktimer] > 0) + { + if (stplyr->kartstuff[k_growcancel] > 0) + { + itembar = stplyr->kartstuff[k_growcancel]; + maxl = 26; + } + + if (leveltime & 1) + localpatch = kp_grow[offset]; + else + localpatch = kp_nodraw; + } + else if (stplyr->kartstuff[k_sadtimer] > 0) + { + if (leveltime & 2) + localpatch = kp_sadface[offset]; + else + localpatch = kp_nodraw; + } + else + { + if (stplyr->kartstuff[k_itemamount] <= 0) + return; + + const boolean usemultiicon = (multiitem_icon && cv_multiitemicon.value && !offset); + + switch (stplyr->kartstuff[k_itemtype]) + { + case KITEM_SNEAKER: + if (usemultiicon) + { + if (!cv_huditemamount.value) + numberdisplaymin = 4; + switch(stplyr->kartstuff[k_itemamount]) + { + case 1: + localpatch = kp_sneaker[offset]; + break; + case 2: + localpatch = kp_multsneaker[0]; + break; + default: + localpatch = kp_multsneaker[1]; + break; + } + } + else + { + localpatch = kp_sneaker[offset]; + } + break; + case KITEM_ROCKETSNEAKER: + localpatch = kp_rocketsneaker[offset]; + break; + case KITEM_INVINCIBILITY: + localpatch = localinv; + dark = true; + break; + case KITEM_BANANA: + if (usemultiicon) + { + if (!cv_huditemamount.value) + numberdisplaymin = 4; + switch(stplyr->kartstuff[k_itemamount]) + { + case 1: + localpatch = kp_banana[offset]; + break; + case 2: + localpatch = kp_multbanana[0]; + break; + case 3: + localpatch = kp_multbanana[1]; + break; + default: + localpatch = kp_multbanana[2]; + break; + } + } + else + { + localpatch = kp_banana[offset]; + } + break; + case KITEM_EGGMAN: + localpatch = kp_eggman[offset]; + break; + case KITEM_ORBINAUT: + if (!cv_huditemamount.value) + numberdisplaymin = offset ? 2 : 5; + localpatch = kp_orbinaut[(offset ? 4 : min(stplyr->kartstuff[k_itemamount]-1, 3))]; + break; + case KITEM_JAWZ: + if (usemultiicon) + { + if (!cv_huditemamount.value) + numberdisplaymin = 3; + localpatch = ((stplyr->kartstuff[k_itemamount] == 1) ? kp_jawz[offset] : kp_multjawz); + } + else + { + localpatch = kp_jawz[offset]; + } + break; + case KITEM_MINE: + localpatch = kp_mine[offset]; + break; + case KITEM_BALLHOG: + localpatch = kp_ballhog[offset]; + break; + case KITEM_SPB: + localpatch = kp_selfpropelledbomb[offset]; + dark = true; + break; + case KITEM_GROW: + localpatch = kp_grow[offset]; + break; + case KITEM_SHRINK: + localpatch = kp_shrink[offset]; + break; + case KITEM_THUNDERSHIELD: + localpatch = kp_thundershield[offset]; + dark = true; + break; + case KITEM_HYUDORO: + localpatch = kp_hyudoro[offset]; + break; + case KITEM_POGOSPRING: + localpatch = kp_pogospring[offset]; + break; + case KITEM_KITCHENSINK: + localpatch = kp_kitchensink[offset]; + break; + case KITEM_SAD: + localpatch = kp_sadface[offset]; + break; + default: + return; + } + + if (stplyr->kartstuff[k_itemheld] && !(leveltime & 1)) + localpatch = kp_nodraw; + } + + if (stplyr->kartstuff[k_itemblink] && (leveltime & 1)) + { + colormode = TC_BLINK; + + switch (stplyr->kartstuff[k_itemblinkmode]) + { + case 2: + localcolor = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))); + break; + case 1: + localcolor = SKINCOLOR_RED; + break; + default: + localcolor = SKINCOLOR_WHITE; + break; + } + } + } + + localbg = K_getItemBoxPatch((boolean)offset, dark); + drawinfo_t info; + K_getItemBoxDrawinfo(&info); + fx = info.x; + fy = info.y; + fflags = info.flags; + + boolean flipamount = splitscreen > 1 && stplyrnum & 1; // Used for 3P/4P splitscreen to flip item amount stuff + + if (K_UseColorHud()) + colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + + V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, localbg, cv_colorizeditembox.value ? colormap : NULL); + + fixed_t rfy = fy<kartstuff[k_itemroulette] && !stplyr->deadtimer) + { + fixed_t frac = R_GetHudUncap(); + UINT8 fancystep = (offset ? 6 : 10); + fixed_t fancyoffset = (stplyr->kartstuff[k_itemroulette] % 3)-1; + + if (fancyoffset != 0) + { + fancyflags &= ~V_HUDTRANS; + fancyflags |=V_HUDTRANSHALF; + } + + rfy += (fancystep * fancyoffset * FRACUNIT) + FixedMul(fancystep*FRACUNIT, frac) - fancystep/2*FRACUNIT; + } + + if (localcolor != SKINCOLOR_NONE) + colmap = R_GetTranslationColormap(colormode, localcolor, GTC_CACHE); + + // Then, the numbers: + if (stplyr->kartstuff[k_itemamount] >= numberdisplaymin && !stplyr->kartstuff[k_itemroulette]) + { + localbg = K_getItemMulPatch((boolean)offset); + + V_DrawMappedPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), localbg, colormap); // flip this graphic for p2 and p4 in split and shift it. + V_DrawFixedPatch(fx<kartstuff[k_itemamount])); + } + else + { + V_DrawScaledPatch(fx+28, fy+41, V_HUDTRANS|fflags, kp_itemx); + V_DrawKartString(fx+38, fy+36, V_HUDTRANS|fflags, va("%d", stplyr->kartstuff[k_itemamount])); + } + } + else + V_DrawFixedPatch(fx< 2) + { + V_DrawFill(fx+x+length, fy+y+1, 1, height, 12|fflags); // the right one + if (height == 2) + V_DrawFill(fx+x+2, fy+y+2, length-2, 1, 8|fflags); // the dulled underside + V_DrawFill(fx+x+2, fy+y+1, length-2, 1, 120|fflags); // the shine + } + } + + // Quick Eggman numbers + if (stplyr->kartstuff[k_eggmanexplode] > 1 /*&& stplyr->kartstuff[k_eggmanexplode] <= 3*TICRATE*/) + V_DrawScaledPatch(fx+17, fy+13-offset, V_HUDTRANS|fflags, kp_eggnum[min(3, G_TicsToSeconds(stplyr->kartstuff[k_eggmanexplode]))]); +} + +void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UINT8 mode) +{ + // TIME_X = BASEVIDWIDTH-124; // 196 + // TIME_Y = 6; // 6 + + INT32 splitflags = 0; + + if (!mode) + { + splitflags = V_HUDTRANS|K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTORIGHT); + if (cv_timelimit.value && timelimitintics > 0) + { + if (drawtime >= timelimitintics) + drawtime = 0; + else + drawtime = timelimitintics - drawtime; + } + } + + if (K_UseColorHud()) // Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + V_DrawMappedPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwideclr : kp_timestickerwideclr), colormap); + } + else + V_DrawScaledPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwide : kp_timestickerwide)); + + TX += 33; + + if (drawtime == UINT32_MAX) + ; + else if (mode && !drawtime) + { + V_DrawKartString(TX, TY+3, splitflags, va("--'--\"--")); + } + else + { + tic_t worktime = drawtime/(60*TICRATE); + + if (cv_timelimit.value && cv_overtime.value && G_BattleGametype() && !players[consoleplayer].exiting && (leveltime > (timelimitintics + starttime + TICRATE/2))) // i hate this so much + { + V_DrawKartString(TX, TY+3, splitflags, va("OVERTIME")); + } + else if (worktime < 100) + { + // minutes time 00 __ __ + V_DrawKartString(TX, TY+3, splitflags, va("%d", worktime/10)); + V_DrawKartString(TX+12, TY+3, splitflags, va("%d", worktime%10)); + + // apostrophe location _'__ __ + V_DrawKartString(TX+24, TY+3, splitflags, va("'")); + + worktime = (drawtime/TICRATE % 60); + + // seconds time _ 00 __ + V_DrawKartString(TX+36, TY+3, splitflags, va("%d", worktime/10)); + V_DrawKartString(TX+48, TY+3, splitflags, va("%d", worktime%10)); + + // quotation mark location _ __"__ + V_DrawKartString(TX+60, TY+3, splitflags, va("\"")); + + worktime = G_TicsToCentiseconds(drawtime); + + // tics _ __ 00 + V_DrawKartString(TX+72, TY+3, splitflags, va("%d", worktime/10)); + V_DrawKartString(TX+84, TY+3, splitflags, va("%d", worktime%10)); + } + else if ((drawtime/TICRATE) & 1) + V_DrawKartString(TX, TY+3, splitflags, va("99'59\"99")); + } + + if (emblemmap && (modeattacking || (mode == 1)) && !demo.playback) // emblem time! + { + INT32 workx = TX + 96, worky = TY+18; + SINT8 curemb = 0; + patch_t *emblempic[3] = {NULL, NULL, NULL}; + UINT8 *emblemcol[3] = {NULL, NULL, NULL}; + + emblem_t *emblem = M_GetLevelEmblems(emblemmap); + while (emblem) + { + char targettext[9]; + + switch (emblem->type) + { + case ET_TIME: + { + static boolean canplaysound = true; + tic_t timetoreach = emblem->var; + + if (emblem->collected) + { + emblempic[curemb] = W_CachePatchName(M_GetEmblemPatch(emblem), PU_PATCH); + emblemcol[curemb] = R_GetTranslationColormap(TC_DEFAULT, M_GetEmblemColor(emblem), GTC_CACHE); + if (++curemb == 3) + break; + goto bademblem; + } + + snprintf(targettext, 9, "%i'%02i\"%02i", + G_TicsToMinutes(timetoreach, false), + G_TicsToSeconds(timetoreach), + G_TicsToCentiseconds(timetoreach)); + + if (!mode) + { + if (stplyr->realtime > timetoreach) + { + splitflags = (splitflags &~ V_HUDTRANS)|V_HUDTRANSHALF; + if (canplaysound) + { + S_StartSound(NULL, sfx_s3k72); //sfx_s26d); -- you STOLE fizzy lifting drinks + canplaysound = false; + } + } + else if (!canplaysound) + canplaysound = true; + } + + targettext[8] = 0; + } + break; + default: + goto bademblem; + } + + V_DrawRightAlignedString(workx, worky, splitflags, targettext); + workx -= 67; + V_DrawSmallScaledPatch(workx + 4, worky, splitflags, W_CachePatchName("NEEDIT", PU_PATCH)); + + break; + + bademblem: + emblem = M_GetLevelEmblems(-1); + } + + if (!mode) + splitflags = (splitflags &~ V_HUDTRANSHALF)|V_HUDTRANS; + + while (curemb--) + { + workx -= 12; + V_DrawSmallMappedPatch(workx + 4, worky, splitflags, emblempic[curemb], emblemcol[curemb]); + } + } +} + +static void K_DrawKartPositionNum(INT32 num) +{ + // POSI_X = BASEVIDWIDTH - 51; // 269 + // POSI_Y = BASEVIDHEIGHT- 64; // 136 + + const boolean wheeloffs = (cv_showinput.value && cv_posi_xoffset.value == 0 && cv_posi_yoffset.value == 0 && cv_wheel_xoffset.value == 0 && cv_wheel_yoffset.value == 0); + const boolean win = (stplyr->exiting && num == 1); + INT32 W = kp_positionnum[0][0]->width; + fixed_t scale = FRACUNIT; + patch_t *localpatch = kp_positionnum[0][0]; + INT32 addOrSub = B_SUBTRACT; + INT32 fx = 0, fy = 0, fflags = 0; + const INT32 xoffs = wheeloffs ? -48 : 0; + boolean flipdraw = false; // flip the order we draw it in for MORE splitscreen bs. fun. + boolean flipvdraw = false; // used only for 2p splitscreen so overtaking doesn't make 1P's position fly off the screen. + boolean overtake = false; + + if ((mapheaderinfo[gamemap - 1]->levelflags & LF_SUBTRACTNUM) == LF_SUBTRACTNUM) + { + addOrSub = B_ADD; + } + + if ((cv_posanim.value && stplyr->kartstuff[k_positiondelay]) || stplyr->exiting) + { + scale *= 2; + overtake = true; // this is used for splitscreen stuff in conjunction with flipdraw. + } + + if (splitscreen || cv_smallposnum.value || wheeloffs) + { + scale /= 2; + } + + W = FixedMul(W<>FRACBITS; + + // pain and suffering defined below + if (!splitscreen) + { + fx = POSI_X + xoffs; + fy = BASEVIDHEIGHT - 8 + cv_posi_yoffset.value; + fflags = V_SNAPTOBOTTOM|V_SNAPTORIGHT; + } + else if (splitscreen == 1) // for this splitscreen, we'll use case by case because it's a bit different. + { + fx = POSI_X; + if (stplyrnum == 0) // for player 1: display this at the top right, above the minimap. + { + fy = 30 + cv_posi_yoffset.value; + fflags = V_SNAPTOTOP|V_SNAPTORIGHT; + if (overtake) + flipvdraw = true; // make sure overtaking doesn't explode us + } + else // if we're not p1, that means we're p2. display this at the bottom right, below the minimap. + { + fy = BASEVIDHEIGHT - 8 + cv_posi_yoffset.value; + fflags = V_SNAPTOBOTTOM|V_SNAPTORIGHT; + } + } + else + { + if (!(stplyrnum & 1)) // If we are P1 or P3... + { + fx = POSI_X; + fy = POSI_Y; + fflags = V_SNAPTOLEFT|((stplyrnum == 2) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. + flipdraw = true; + if (num && num >= 10) + fx += W; // this seems dumb, but we need to do this in order for positions above 10 going off screen. + } + else // else, that means we're P2 or P4. + { + fx = POSI2_X; + fy = POSI2_Y; + fflags = V_SNAPTORIGHT|((stplyrnum == 3) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom + } + } + + // Special case for 0 + if (num <= 0) + { + V_DrawBlendingFixedPatch(fx<laps+1 >= cv_numlaps.value || stplyr->exiting) // Check for the final lap, or won + { + boolean useRedNums = K_IsPlayerLosing(stplyr); + + if (addOrSub == B_SUBTRACT) + { + // Subtracting RED will look BLUE, and vice versa. + useRedNums = !useRedNums; + } + + // Alternate frame every three frames + switch ((leveltime % 9) / 3) + { + case 0: + if (useRedNums == true) + localpatch = kp_positionnum[num % 10][4]; + else + localpatch = kp_positionnum[num % 10][1]; + break; + case 1: + if (useRedNums == true) + localpatch = kp_positionnum[num % 10][5]; + else + localpatch = kp_positionnum[num % 10][2]; + break; + case 2: + if (useRedNums == true) + localpatch = kp_positionnum[num % 10][6]; + else + localpatch = kp_positionnum[num % 10][3]; + break; + default: + localpatch = kp_positionnum[num % 10][0]; + break; + } + } + else + { + localpatch = kp_positionnum[num % 10][0]; + } + + V_DrawBlendingFixedPatch((fx<width*scale/2) : 0), (fy<height*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL, addOrSub); + // ^ if we overtake as p1 or p3 in splitscren, we shift it so that it doesn't go off screen. + // ^ if we overtake as p1 in 2p splits, shift vertically so that this doesn't happen either. + + fx -= W; + num /= 10; + } +} + +static boolean K_drawKartPositionFaces(void) +{ + // FACE_X = 15; // 15 + // FACE_Y = 72; // 72 + + INT32 Y = FACE_Y+9; // +9 to offset where it's being drawn if there are more than one + INT32 i, j, ranklines, strank = -1; + boolean completed[MAXPLAYERS]; + INT32 rankplayer[MAXPLAYERS]; + INT32 bumperx, numplayersingame = 0; + UINT8 *colormap; + + ranklines = 0; + memset(completed, 0, sizeof (completed)); + memset(rankplayer, 0, sizeof (rankplayer)); + + for (i = 0; i < MAXPLAYERS; i++) + { + rankplayer[i] = -1; + + if (!playeringame[i] || players[i].spectator || !players[i].mo) + continue; + + numplayersingame++; + } + + if (numplayersingame <= 1) + return true; + + if (!LUA_HudEnabled(hud_minirankings)) + return false; // Don't proceed but still return true for free play above if HUD is disabled. + + for (j = 0; j < numplayersingame; j++) + { + UINT8 lowestposition = MAXPLAYERS+1; + for (i = 0; i < MAXPLAYERS; i++) + { + if (completed[i] || !playeringame[i] || players[i].spectator || !players[i].mo) + continue; + + if (players[i].kartstuff[k_position] >= lowestposition) + continue; + + rankplayer[ranklines] = i; + lowestposition = players[i].kartstuff[k_position]; + } + + i = rankplayer[ranklines]; + + completed[i] = true; + + if (players+i == stplyr) + strank = ranklines; + + ranklines++; + } + + if (ranklines < 5) + Y -= (9*ranklines); + else + Y -= (9*5); + + if (G_BattleGametype() || strank <= 2) // too close to the top, or playing battle, or a spectator? would have had (strank == -1) called out, but already caught by (strank <= 2) + { + i = 0; + if (ranklines > 5) // could be both... + ranklines = 5; + } + else if (strank+3 > ranklines) // too close to the bottom? + { + i = ranklines - 5; + if (i < 0) + i = 0; + } + else + { + i = strank-2; + ranklines = strank+3; + } + + for (; i < ranklines; i++) + { + player_t *player; + player = &players[rankplayer[i]]; + + if (!playeringame[rankplayer[i]]) + continue; + if (player->spectator) + continue; + if (!player->mo) + continue; + + const UINT8 mocolor = player->mo->color; + + bumperx = FACE_X+19; + + if (mocolor) + { + colormap = R_GetTranslationColormap(player->skin, mocolor, GTC_CACHE); + if (player->mo->colorized) + colormap = R_GetTranslationColormap(TC_RAINBOW, mocolor, GTC_CACHE); + + if (K_UseHighResPortraits()) + V_DrawSmallMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, R_GetSkinFaceWant(player), colormap); + else + V_DrawMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, R_GetSkinFaceRank(player), colormap); + + if (LUA_HudEnabled(hud_battlebumpers)) + { + if (G_BattleGametype() && player->kartstuff[k_bumper] > 0) + { + V_DrawMappedPatch(bumperx-2, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[0], colormap); + for (j = 1; j < player->kartstuff[k_bumper]; j++) + { + bumperx += 5; + V_DrawMappedPatch(bumperx, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[1], colormap); + } + } + } // A new level of stupidity: checking if lua is enabled to close a bracket. :Fascinating: + } + + if (i == strank) + V_DrawScaledPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_facehighlight[(leveltime / 4) % 8]); + + if (G_BattleGametype() && player->kartstuff[k_bumper] <= 0) + V_DrawScaledPatch(FACE_X-4, Y-3, V_HUDTRANS|V_SNAPTOLEFT, kp_ranknobumpers); + else + { + INT32 pos = player->kartstuff[k_position]; + if (pos < 0 || pos > MAXPLAYERS) + pos = 0; + // Draws the little number over the face + V_DrawScaledPatch(FACE_X-5, Y+10, V_HUDTRANS|V_SNAPTOLEFT, kp_facenum[pos]); + } + + Y += 18; + } + + return false; +} + +// +// HU_DrawTabRankings -- moved here to take advantage of kart stuff! +// +void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 hilicol) +{ + INT32 i, rightoffset = 240; + const UINT8 *colormap; + const INT32 dupadjust = cv_betainterscreen.value ? 314 : (vid.width/vid.dupx), duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; + + boolean (*_isHighlightedPlayer)(const player_t *) = (demo.playback ? P_IsDisplayPlayer : P_IsLocalPlayer); + + //this function is designed for 9 or less score lines only + //I_Assert(scorelines <= 9); -- not today bitch, kart fixed it up + + V_DrawFill(1-duptweak, 26, dupadjust-2, 1, 0); // Draw a horizontal line because it looks nice! + if (scorelines > 8) + { + V_DrawFill(160, 26, 1, 147, 0); // Draw a vertical line to separate the two sides. + V_DrawFill(1-duptweak, 173, dupadjust-2, 1, 0); // And a horizontal line near the bottom. + rightoffset = (BASEVIDWIDTH/2) - 4 - x; + } + + for (i = 0; i < scorelines; i++) + { + char strtime[MAXPLAYERNAME+1]; + const UINT8 pnum = tab[i].num; + player_t *player = &players[pnum]; + + if (player->spectator || !player->mo) + continue; //ignore them. + + const boolean whiteplayer = _isHighlightedPlayer(player); + const INT32 philicol = (whiteplayer ? V_SkinColorToHighlightcolor(player->skincolor) : 0); + + if ((netgame && pnum != serverplayer) || (cv_mindelay.value && P_IsLocalPlayer(player))) + { + HU_drawPlayerPing(x + ((i < 8) ? -17 : rightoffset + 11), y-4, pnum, 0); + } + + STRBUFCPY(strtime, tab[i].name); + + if (scorelines > 8) + V_DrawThinString(x + 20, y, philicol|V_ALLOWLOWERCASE|V_6WIDTHSPACE, strtime); + else + V_DrawString(x + 20, y, philicol|V_ALLOWLOWERCASE, strtime); + + if (player->mo->color) + { + if (player->mo->colorized) + colormap = R_GetTranslationColormap(TC_RAINBOW, player->mo->color, GTC_CACHE); + else + colormap = R_GetTranslationColormap(player->skin, player->mo->color, GTC_CACHE); + + if (K_UseHighResPortraits()) + V_DrawSmallMappedPatch(x, y-4, 0, R_GetSkinFaceWant(player), colormap); + else + V_DrawMappedPatch(x, y-4, 0, R_GetSkinFaceRank(player), colormap); + + /*if (G_BattleGametype() && player->kartstuff[k_bumper] > 0) -- not enough space for this + { + INT32 bumperx = x+19; + V_DrawMappedPatch(bumperx-2, y-4, 0, kp_tinybumper[0], colormap); + for (j = 1; j < player->kartstuff[k_bumper]; j++) + { + bumperx += 5; + V_DrawMappedPatch(bumperx, y-4, 0, kp_tinybumper[1], colormap); + } + }*/ + } + + if (whiteplayer) + V_DrawScaledPatch(x, y-4, 0, kp_facehighlight[(leveltime / 4) % 8]); + + if (G_BattleGametype() && player->kartstuff[k_bumper] <= 0) + V_DrawScaledPatch(x-4, y-7, 0, kp_ranknobumpers); + else + { + INT32 pos = player->kartstuff[k_position]; + if (pos < 0 || pos > MAXPLAYERS) + pos = 0; + // Draws the little number over the face + V_DrawScaledPatch(x-5, y+6, 0, kp_facenum[pos]); + } + + if (G_RaceGametype()) + { +#define timestring(time) va("%i'%02i\"%02i", G_TicsToMinutes(time, true), G_TicsToSeconds(time), G_TicsToCentiseconds(time)) + if (scorelines > 8) + { + if (player->exiting) + V_DrawRightAlignedThinString(x+rightoffset, y-1, hilicol|V_6WIDTHSPACE, timestring(player->realtime)); + else if (player->pflags & PF_TIMEOVER) + V_DrawRightAlignedThinString(x+rightoffset, y-1, V_6WIDTHSPACE, "NO CONTEST."); + else if (circuitmap) + V_DrawRightAlignedThinString(x+rightoffset, y-1, V_6WIDTHSPACE, va("Lap %d", tab[i].count)); + } + else + { + if (player->exiting) + V_DrawRightAlignedString(x+rightoffset, y, hilicol, timestring(player->realtime)); + else if (player->pflags & PF_TIMEOVER) + V_DrawRightAlignedThinString(x+rightoffset, y-1, 0, "NO CONTEST."); + else if (circuitmap) + V_DrawRightAlignedString(x+rightoffset, y, 0, va("Lap %d", tab[i].count)); + } +#undef timestring + } + else + V_DrawRightAlignedString(x+rightoffset, y, 0, va("%u", tab[i].count)); + + y += 18; + if (i == 7) + { + y = 33; + x = (BASEVIDWIDTH/2) + 4; + } + } +} + +static boolean K_BigLap(void) +{ + return (cv_biglaps.value && (cv_numlaps.value > 9) && (K_UseColorHud() ? big_lap_color : big_lap) && (!stplyr->exiting)); +} + +static void K_drawKartLaps(void) +{ + const INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); + INT32 fx = 0, fy = 0, fflags = 0; // stuff for 3p / 4p splitscreen. + const boolean flipstring = splitscreen > 1 && stplyrnum & 1; // used for 3p or 4p + INT32 stringw = 0; // used with the above + const char *laps; + + drawinfo_t info; + K_getLapsDrawinfo(&info); + fx = info.x; + fy = info.y; + fflags = info.flags; + + laps = (stplyr->exiting ? "FIN" : va("%d/%d", stplyr->laps+1, cv_numlaps.value)); + + // draw stuff as god intended. + if (splitscreen > 1) + { + if (flipstring) + { + stringw = V_StringWidth(laps, 0); + + V_DrawScaledPatch(fx-stringw-13, fy, V_HUDTRANS|fflags, kp_splitlapflag); + V_DrawRightAlignedString(fx, fy+1, V_HUDTRANS|fflags, laps); + } + else // draw stuff NORMALLY. + { + V_DrawScaledPatch(fx, fy, V_HUDTRANS|fflags, kp_splitlapflag); + V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, laps); + } + } + else + { + if (K_UseColorHud()) // Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + patch_t *biglapclr = (K_BigLap() ? ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2clr : kp_lapstickerbigclr) : kp_lapstickerclr); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|splitflags, biglapclr, colormap); + } + else + { + patch_t *biglap = (K_BigLap() ? ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2 : kp_lapstickerbig) : kp_lapsticker); + V_DrawScaledPatch(fx, fy, V_HUDTRANS|splitflags, biglap); + } + + V_DrawKartString(fx+33, fy+3, V_HUDTRANS|splitflags, laps); + } +} + +#ifdef ROTSPRITE + +#define DIALSPDDIV 97090 // 1.48148; converts 200 to 135 +#define MPHDIV 68283 // 1.04192; converts 141 to 135 + +static void K_DrawDialNum(INT32 x, INT32 y, boolean colorized, INT32 flags, INT32 num, INT32 digits, const UINT8 *colormap) +{ + INT32 w; + + if (colorized) + w = skp_dialnumclr[0]->width; + else + w = skp_dialnum[0]->width; + + if (flags & V_NOSCALESTART) + w *= vid.dupx; + + if (num < 0) + num = -num; + + // draw the number + do + { + x -= (w); + + if (colorized) + V_DrawFixedPatch(x << FRACBITS, y << FRACBITS, FRACUNIT, flags, skp_dialnumclr[num % 10], colormap); + else + V_DrawFixedPatch(x << FRACBITS, y << FRACBITS, FRACUNIT, flags, skp_dialnum[num % 10], colormap); + + num /= 10; + } while (--digits); +} + +static void K_DrawDialLaps(INT32 x, INT32 y, INT32 num, INT32 total, INT32 flags) +{ + INT32 fx; + fx = x + ((num < 10) ? 0 : 6); + V_DrawRankNum(fx, y, flags, num, (num < 10) ? 1 : 2, NULL); + V_DrawScaledPatch(fx + 2, y, flags, frameslash); + V_DrawRankNum(fx + 13 + ((total < 10) ? 0 : 6), y, flags, total, (total < 10) ? 1 : 2, NULL); +} + +static void K_DrawDialSpeedometer(fixed_t speed, + fixed_t divisor, + INT32 splitflags, + boolean battlemode, + boolean infoactive, + boolean colorized) +{ + const UINT8* colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + + INT32 rot = 0; + const UINT8 infoidx = (infoactive) ? 1 : 0; + patch_t* dialpatch; + + const angle_t speedangle = + FixedAngle(((min(135 * FRACUNIT, FixedDiv(speed, divisor)) - (45 * FRACUNIT)))); + + rot = R_GetRollAngle(speedangle); + + if (rot) + { + dialpatch = W_CachePatchNameRotated("K_DSDIAL", rot, PU_PATCH); + } + else + { + dialpatch = W_CachePatchName("K_DSDIAL", PU_PATCH); + } + + if (colorized) // Colourized hud + { + V_DrawMappedPatch( + SPDM_X, SPDM_Y - 9, (V_HUDTRANS | splitflags), skp_dialbaseclr[infoidx], colormap); + V_DrawMappedPatch(SPDM_X, + SPDM_Y + 30, + V_HUDTRANS | splitflags, + skp_speedpatchesdialclr[cv_kartspeedometer.value], + colormap); + } + else + { + V_DrawScaledPatch(SPDM_X, SPDM_Y - 9, (V_HUDTRANS | splitflags), skp_dialbase[infoidx]); + V_DrawScaledPatch(SPDM_X, + SPDM_Y + 30, + V_HUDTRANS | splitflags, + skp_speedpatchesdial[cv_kartspeedometer.value]); + } + + K_DrawDialNum(SPDM_X + 10, + SPDM_Y + 25, + colorized, + V_HUDTRANS | splitflags, + speed / FRACUNIT, + 3, + colormap); + + // gotta center the dial manually + V_DrawMappedPatch(SPDM_X - 19, SPDM_Y + 15, (V_HUDTRANS | splitflags), (dialpatch), colormap); + + if (!infoactive) + { + // no need to draw info if we're not supposed to + return; + } + + // draw the info + if (battlemode) + { + if (stplyr->kartstuff[k_bumper] <= 0) + { + V_DrawMappedPatch( + SPDM_X + 28, SPDM_Y + 27, V_HUDTRANS | splitflags, kp_splitkarmabomb, colormap); + K_DrawDialLaps(SPDM_X + 46, + SPDM_Y + 29, + stplyr->kartstuff[k_comebackpoints], + 2, + V_HUDTRANS | splitflags); + } + else // the above doesn't need to account for weird stuff since the max amount of karma + // necessary is always 2 ^^^^ + { + V_DrawMappedPatch( + SPDM_X + 28, SPDM_Y + 27, V_HUDTRANS | splitflags, kp_rankbumper, colormap); + K_DrawDialLaps(SPDM_X + 46, + SPDM_Y + 29, + stplyr->kartstuff[k_bumper], + cv_kartbumpers.value, + V_HUDTRANS | splitflags); + } + } + else + { + V_DrawScaledPatch(SPDM_X + 28, SPDM_Y + 27, V_HUDTRANS | splitflags, kp_splitlapflag); + + if (stplyr->exiting) + V_DrawScaledPatch(SPDM_X + 39, SPDM_Y + 29, V_HUDTRANS | splitflags, skp_rankfinish); + else + K_DrawDialLaps(SPDM_X + 46, + SPDM_Y + 29, + stplyr->laps + 1, + cv_numlaps.value, + V_HUDTRANS | splitflags); + } +} + +#endif + +static void K_drawKartSpeedometer(void) +{ + // why? + if (cv_kartspeedometer.value == 0) + return; + + // index 0 is the raw value, index 1 is the converted value + fixed_t convSpeed[2] = {0,0}; +#ifdef ROTSPRITE + fixed_t dial_divisor = DIALSPDDIV; +#endif + + INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); + + // man. + const UINT8 speedostyle = K_GetSpeedometerStyle(); + + switch (cv_kartspeedometer.value) + { + case 1: + convSpeed[0] = FixedDiv(FixedMul(stplyr->speed, 142371), mapobjectscale); // 2.172409058 + convSpeed[1] = convSpeed[0] / FRACUNIT; + break; + case 2: + convSpeed[0] = FixedDiv(FixedMul(stplyr->speed, 88465), mapobjectscale); // 1.349868774 + convSpeed[1] = convSpeed[0] / FRACUNIT; +#ifdef ROTSPRITE + dial_divisor = MPHDIV; +#endif + break; + case 3: + convSpeed[0] = FixedDiv(stplyr->speed, mapobjectscale); + convSpeed[1] = convSpeed[0] / FRACUNIT; +#ifdef ROTSPRITE + dial_divisor = MPHDIV; +#endif + break; + case 4: + if (stplyr->mo) + { + convSpeed[0] = (FixedDiv(stplyr->speed, FixedMul(K_GetKartSpeed(stplyr, false), ORIG_FRICTION))*100); + convSpeed[1] = convSpeed[0] >> FRACBITS; + } + break; + default: + break; + } + + if (speedostyle == SPEEDO_VANILLA) + { + const char *metric = ""; + + switch (cv_kartspeedometer.value) + { + case 1: + metric = va("%3d km/h", convSpeed[1]); + break; + case 2: + metric = va("%3d mph", convSpeed[1]); + break; + case 3: + metric = va("%3d fu/t", convSpeed[1]); + break; + case 4: + // if extra.kart is found, use its included % symbol + if (!xtra_speedo) + metric = va("%4d P", convSpeed[1]); + else + metric = va("%4d %%", convSpeed[1]); + break; + default: + break; + } + + V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, metric); + } + else if (speedostyle == SPEEDO_EXTRA) // why bother if we dont? + { + if (K_UseColorSpeedo(SPEEDO_EXTRA)) //Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + V_DrawMappedPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallstickerclr, colormap); + } + else + V_DrawScaledPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallsticker); + + V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed[1], 3, NULL); + V_DrawScaledPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatches[cv_kartspeedometer.value]); + } + else if (speedostyle == SPEEDO_ACHII) // why bother if we dont? + { + if (K_UseColorSpeedo(SPEEDO_ACHII)) //Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + V_DrawMappedPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallstickerachiclr, colormap); + V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed[1], 3, NULL); + V_DrawMappedPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatchesachiclr[cv_kartspeedometer.value], colormap); + } + else + { + V_DrawScaledPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallstickerachi); + V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed[1], 3, NULL); + V_DrawScaledPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatchesachi[cv_kartspeedometer.value]); + } + } +#ifdef ROTSPRITE + else if (speedostyle == SPEEDO_DIAL) // why bother if we dont? + { + K_DrawDialSpeedometer(convSpeed[0], + dial_divisor, + splitflags, + (boolean)(G_BattleGametype()), + (LUA_HudEnabled(hud_gametypeinfo)), + (K_UseColorSpeedo(SPEEDO_DIAL))); + } +#endif + else if (speedostyle == SPEEDO_EXTRA3) // why bother if we dont? + { + if (K_UseColorSpeedo(SPEEDO_EXTRA3)) //Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + V_DrawStretchyFixedPatch((SPDM_X-1)<speed, mapobjectscale)/FRACUNIT; + + for (INT32 i = 0; i < 22; ++i) + { + if (fuspeed < speedIntervals[i]) + { + spdpatch = i; + break; + } + } + + if (((fuspeed < 57 && fuspeed > 54) || (fuspeed < 60 && fuspeed > 56) || (fuspeed > 59)) && (leveltime & 4)) + spdpatch = 24; + else if (((fuspeed < 57 && fuspeed > 54) || (fuspeed < 60 && fuspeed > 56) || (fuspeed > 59)) && !(leveltime & 4)) + spdpatch = 23; + + V_DrawScaledPatch(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, (speedostyle == SPEEDO_PMETER) ? kp_kartzspeedo[spdpatch] : kp_kartzspeedo_smol[spdpatch]); + } +} + +#ifdef ROTSPRITE +#undef DIALSPDDIV +#undef MPHDIV +#endif + +static void K_drawKartBumpersOrKarma(void) +{ + const UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + INT32 fx, fy, fflags; + const boolean flipstring = splitscreen > 1 && stplyrnum & 1; // same as laps, used for splitscreen + INT32 stringw = 0; // used with the above + const char *bumpval = ""; + + drawinfo_t info; + K_getLapsDrawinfo(&info); + fx = info.x; + fy = info.y; + fflags = info.flags; + + if (cv_battlespeedo.value && !splitscreen) + { + const UINT8 speedostyle = K_GetSpeedometerStyle(); + + if ((speedostyle == SPEEDO_EXTRA) || (speedostyle == SPEEDO_ACHII) || (speedostyle == SPEEDO_EXTRA3)) + fy += 5; + else + fy += 7; + } + + if (splitscreen > 1) + { + if (stplyr->kartstuff[k_bumper] <= 0) + { + bumpval = va("%d/2", stplyr->kartstuff[k_comebackpoints]); + + if (flipstring) + fx -= 37; + V_DrawMappedPatch(fx, fy-1, V_HUDTRANS|fflags, kp_splitkarmabomb, colormap); + V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, bumpval); + } + else // the above doesn't need to account for weird stuff since the max amount of karma necessary is always 2 ^^^^ + { + bumpval = va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value); + + if (flipstring) // for p2 and p4, assume we can have more than 10 bumpers. It's retarded but who knows. + { + stringw = V_StringWidth(bumpval, 0); + + V_DrawMappedPatch(fx-stringw-13, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); + V_DrawRightAlignedString(fx, fy+1, V_HUDTRANS|fflags, bumpval); + } + else // draw bumpers normally. + { + V_DrawMappedPatch(fx, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); + V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, bumpval); + } + } + } + else + { + patch_t *patch; + + if (stplyr->kartstuff[k_bumper] <= 0) + { + patch = (K_UseColorHud() ? kp_karmastickerclr : kp_karmasticker); + bumpval = va("%d/2", stplyr->kartstuff[k_comebackpoints]); + } + else + { + if (stplyr->kartstuff[k_bumper] > 9 && cv_kartbumpers.value > 9) + patch = (K_UseColorHud() ? kp_bumperstickerwideclr : kp_bumperstickerwide); + else + patch = (K_UseColorHud() ? kp_bumperstickerclr : kp_bumpersticker); + + bumpval = va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value); + } + + V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, patch, colormap); + V_DrawKartString(fx+47, fy+3, V_HUDTRANS|fflags, bumpval); + } +} + +#define lerp(from, to) cv_uncappedhud.value ? from + FixedMul(rendertimefrac, to - from) : to + +// converts mobj coordinates into screen coordinates +// NOTE: use with V_NOSCALESTART! +// Code updated in Lua by GenericHeroGuy for libSG +// Badly ported to C by NepDisk and acutally made to work and fixed by Indev!(Thanks so much!) +// Badly uncapped in C by GenericHeroGuy +// original code by Lat' +static boolean K_GetScreenCoords(vector2_t *vec, player_t *player, mobj_t *target, fixed_t hofs, boolean dontclip) +{ + fixed_t y, x; + fixed_t targx, targy, targz; + + fixed_t dist; + fixed_t distfact; + fixed_t offset; + + fixed_t yres, xres; + fixed_t fov; + + // this should never happen but its also kart so ¯\_(ツ)_/¯ + if (!player || P_MobjWasRemoved(target)) + return false; + + targx = lerp(target->old_x, target->x); + targy = lerp(target->old_y, target->y); + targz = lerp(target->old_z, target->z); + + // X coordinate + // get difference between camangle and angle towards target + x = (INT32)viewangle - (INT32)R_PointToAngle(targx, targy); + + distfact = FINECOSINE((x>>ANGLETOFINESHIFT) & FINEMASK); + if (!distfact) distfact = 1; + + if (encoremode) + x = -x; + if (x < (fixed_t)ANGLE_270 || x > (fixed_t)ANGLE_90) + return false; + + xres = vid.width<<(FRACBITS-1); + yres = vid.height<<(FRACBITS-1); + fov = FixedDiv(xres, FINETANGENT(((FixedAngle(cv_fov.value/2)+ANGLE_90)>>ANGLETOFINESHIFT) & 4095)); + + // flipping + const boolean targflip = target->eflags & MFE_VERTICALFLIP; + const boolean srcflip = player->pflags & PF_FLIPCAM && player->mo->eflags & MFE_VERTICALFLIP; + + // Y coordinate + // getting the angle difference here is a bit more involved... + // start by getting the height difference between the camera and target + y = viewz - targz - (targflip ? ((target->height * 2) / 3) : 0); // for some reason needs to be divided by "1.5" idk + + if (hofs) + y = y - (targflip ? -hofs : hofs); + + // then get the distance between camera and target + dist = R_PointToDist(targx, targy); + +#ifdef HWRENDER + // NOW we can get the angle differnce + if (rendermode == render_opengl && !cv_glshearing.value) + { + angle_t yang = R_PointToAngle2(0, 0, dist, y); // not perspective + x = FixedMul(x, FINECOSINE((yang>>ANGLETOFINESHIFT) & FINEMASK)); // perspective + y = -aimingangle - FixedDiv(yang, distfact); + + if (y < (fixed_t)ANGLE_270 || y > (fixed_t)ANGLE_90) // clip points behind the camera + return false; + if (splitscreen == 1) // multiply by 1.25 for 2P splitscreen + y = y + (y/4) ; + if (srcflip) // flipcam + y = -y; + + y = FixedMul(FINETANGENT((((angle_t)(-y)+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), fov) + yres; // project the angle to get our final Y coordinate + } + else +#endif + { + const fixed_t fovratio = FixedDiv(90*FRACUNIT, 180*FRACUNIT - FixedMul(cv_fov.value, 4*FRACUNIT/3)-FRACUNIT*-30); + + y = FixedDiv(y, FixedMul(dist, distfact)); + if (srcflip) + y = -y; // flipcam + if (y != INT32_MIN) // I_Error(): FixedDiv: divide by zero + y = FixedMul(FixedDiv(y, fovratio), xres) + yres; + //else print("NOPE!") + + offset = FixedMul(FINETANGENT(((aimingangle+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), xres); + + // this isn't fovtan... what am i even doing anymore + if (splitscreen == 1) + offset = 17*offset/120; + + // thanks fickle + offset = FixedDiv(offset, fovratio); + if (srcflip) + offset = -offset; // flipcam + y = y + offset; + } + + // project the angle to get our final X coordinate + x = FixedMul(FINETANGENT(((x+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), fov); + if (splitscreen == 1) // divide by 320/200 (1.6) on 2P splitscreen + x = (x/2) + (x/8); + x = x + xres; + + // now clip in screen-space + if (!dontclip && (x < 0 || x > xres*2 || y < 0 || y > yres*2)) + return false; + + // adjust coords for splitscreen + if (splitscreen == 1) // 2P + { + y = y>>1; + if (stplyrnum > 0) + y = y + yres; + } + if (splitscreen >= 2) // 3P or 4P + { + x = x>>1; + y = y>>1; + if (stplyrnum & 1) + x = x + xres; + if (stplyrnum >= 2) + y = y + yres; + } + + vec->y = y; + vec->x = x; + return true; +} + +//Slighty fixed by Alug and further rewritten by NepDisk +//Decided to port and highly modify sunflower version for the main nametag drawing with additions by NepDisk. My previous one was broken anyway due to the changed screencoords and noscalestart +static void K_drawNameTags(void) +{ + UINT8 i, j; + INT32 trans; + vector2_t pos = {0}; + fixed_t namex, namey; + int tagsdisplayed = 0; + fixed_t distance = 0; + fixed_t maxdistance = 0; + boolean flipped = false; + fixed_t z; + + char *tag; + patch_t *icon = NULL; + + INT32 dup; + UINT8 *cm = NULL; + UINT8 tagcolor = 0; + INT32 vflags = 0; + boolean usenametagrestat = false; + fixed_t tagwidthsmall; + fixed_t tagwidth; + + if (P_MobjWasRemoved(stplyr->mo) || (stplyr->spectator && !cv_shownametagspectator.value) || stplyr->exiting) + return; + + maxdistance = ((10*cv_nametagdist.value) * mapobjectscale); + + for (i = 0; i < MAXPLAYERS; i++) + { + distance = 0; + flipped = false; + + if (i > PLAYERSMASK) + continue; + if (players[i].spectator || !playeringame[i] || P_MobjWasRemoved(players[i].mo)) + continue; + if (i == displayplayers[stplyrnum] && !cv_showownnametag.value && !(leveltime < 130)) + continue; + if (i != displayplayers[stplyrnum] && leveltime < starttime) + continue; + if (players[i].kartstuff[k_hyudorotimer]) // player is invisible + continue; + if (maxdistance) + distance = R_PointToDist(players[i].mo->x, players[i].mo->y); + if (distance > maxdistance) + continue; + if (!P_CheckSightFast(stplyr->mo, players[i].mo)) + continue; + + z = players[i].mo->height; + + //Saltyhop hehe + z += lerp(players[i].mo->old_spriteyoffset, players[i].mo->spriteyoffset); + + if (!K_GetScreenCoords(&pos, stplyr, players[i].mo, z, false)) + continue; + + tagsdisplayed++; + + if (tagsdisplayed > cv_nametagmaxplayers.value) + break; + + trans = 0; + + switch (cv_nametagtrans.value) + { + case 1: + if (distance > (maxdistance*3/4)) + trans = V_60TRANS; + break; + case 2: + if (distance > (maxdistance*3/1)) + trans = V_90TRANS; + else if (distance > (maxdistance*3/2)) + trans = V_80TRANS; + else if (distance > (maxdistance*3/3)) + trans = V_60TRANS; + else if (distance > (maxdistance*3/4)) + trans = V_40TRANS; + else if (distance > (maxdistance*3/5)) + trans = V_20TRANS; + break; + case 3: + trans = V_40TRANS; + break; + case 4: + trans = V_LocalTransFlag(); + break; + case 0: + default: + break; + } + + namex = pos.x>>FRACBITS; + namey = pos.y>>FRACBITS; + + tag = va("%s%s ", HU_SkinColorToConsoleColor(players[i].mo->color), player_names[i]); + icon = R_GetSkinFaceMini(players[i].mo->player); + + dup = vid.dupx; + cm = R_GetTranslationColormap(players[i].skin, players[i].mo->color, GTC_CACHE); + tagcolor = colortranslations[players[i].mo->color][7]; + vflags = trans | V_NOSCALESTART; + usenametagrestat = ((cv_nametagrestat.value == 1 && (players[i].kartspeed != skins[players[i].skin].kartspeed || players[i].kartweight != skins[players[i].skin].kartweight)) || cv_nametagrestat.value == 2); + tagwidthsmall = cv_smallnametags.value ? V_SmallStringWidth(player_names[i], V_ALLOWLOWERCASE) : V_ThinStringWidth(player_names[i], V_ALLOWLOWERCASE); + tagwidth = dup*tagwidthsmall; + + // If flipcam is on, other player is flipped relative to us when we have different + // verticalflip flag value. Otherwise, they are simply flipped when verticalflip flag says so + if ((stplyr->pflags & PF_FLIPCAM) && (stplyr->mo->eflags & MFE_VERTICALFLIP)) + flipped = (players[i].mo->eflags & MFE_VERTICALFLIP) != (stplyr->mo->eflags & MFE_VERTICALFLIP); + else + flipped = players[i].mo->eflags & MFE_VERTICALFLIP; + + if (cv_smallnametags.value || !nametaggfx) + { + if (flipped) + namey += dup*5; + else // small offset + namey -= dup*3; + + if (nametaggfx && cv_smallnametags.value == 1) + { + if (cv_nametagfacerank.value) + tagwidthsmall += icon->width - dup; + + // Have to draw the nametag using patches here since drawfill can't draw at this scale... + if (!flipped) + V_DrawFixedPatch(namex<height/2)<width/2); // add offset to other stuff + } + + //Name + V_DrawSmallString(namex, namey, V_ALLOWLOWERCASE | vflags, tag); + + if (usenametagrestat) + { + V_DrawSmallString(namex, namey - dup*5, vflags, va("\x84S%d ", players[i].kartspeed)); + V_DrawSmallString(namex + dup*10, namey - dup*5, vflags, va("\x87W%d ", players[i].kartweight)); + } + + if (cv_nametagscore.value) + { + INT32 yofs = usenametagrestat ? 10 : 5; + V_DrawSmallString(namex, namey - dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); + } + } + else + { + if (cv_nametagfacerank.value) + tagwidth += dup*(icon->width+1); + + if (flipped) + { + for (j = 0; j < 4; j++) + { + V_DrawFill(namex, namey, dup*3, dup*4, 31 | vflags); + V_DrawFill(namex+dup, namey, dup, dup*4, tagcolor | vflags); + namey += dup*4; + namex += dup; + } + namey -= dup*3; + V_DrawFill(namex, namey+dup*2, dup, dup, 31 | vflags); // a single black pixel + V_DrawFill(namex+dup, namey, tagwidth, dup*3, 31 | vflags); + V_DrawFill(namex+dup, namey+dup, tagwidth - dup, dup, tagcolor | vflags); + namex += dup*2; + } + else + { + for (j = 0; j < 4; j++) + { + namey -= dup*4; + V_DrawFill(namex, namey, dup*3, dup*4, 31 | vflags); + V_DrawFill(namex+dup, namey, dup, dup*4, tagcolor | vflags); + namex += dup; + } + + V_DrawFill(namex, namey, dup, dup, 31 | vflags); + V_DrawFill(namex+dup, namey, tagwidth - dup*2, dup*3, 31 | vflags); + V_DrawFill(namex+dup, namey+dup, tagwidth - dup*3, dup, tagcolor | vflags); + } + + if (cv_nametagfacerank.value) + { + V_DrawMappedPatch(namex, namey - dup*(icon->height+1), vflags, icon, cm); + namex += dup*(icon->height+1); // add offset to other stuff + } + + V_DrawThinString(namex, namey - dup*10, V_ALLOWLOWERCASE | vflags, tag); + + if (usenametagrestat) + { + V_DrawScaledPatch(namex, namey - dup*20, vflags, nametagspeed); + V_DrawScaledPatch(namex + dup*18, namey - dup*20, vflags, nametagweight); + V_DrawString(namex + dup*9, namey - dup*19, V_ALLOWLOWERCASE | vflags, va("\x84%d ", players[i].kartspeed)); + V_DrawString(namex + dup*27, namey - dup*19, V_ALLOWLOWERCASE | vflags, va("\x87%d ", players[i].kartweight)); + } + + if (cv_nametagscore.value) + { + INT32 yofs = usenametagrestat ? 25 : 15; + V_DrawSmallString(namex, namey - dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); + } + } + } +} + +// Based on Driftgauge refactor by GenericHeroGuy ported from lua and expanded by NepDisk +static void K_drawDriftGauge(void) +{ + vector2_t pos = {0}; + fixed_t basex, basey; + const int dup = vid.dupx; + int i; + UINT8 *cmap; + + static const UINT8 driftcolors[3][4] = { + {0, 0, 10, 16}, // no drift + {215, 215, 204, 253}, // blue + {125, 125, 151, 159} // red + }; + + static const UINT8 driftskins[3] = { + SKINCOLOR_NONE, + SKINCOLOR_TEAL, + SKINCOLOR_SALMON, + }; + + static UINT8 driftrainbow[18] = { + 0, 31, 47, 63, 79, 95, 111, 119, 127, 143, 159, 175, 183, 191, 199, 207, 223, 247 + }; + + if (camera[stplyrnum].freecam) + return; + + if (!splitscreen && !camera->chase) + return; + + if (forceshowhud) + goto skipcrap; // i will skip the drift early return and you cant stop me! + + if (!stplyr->kartstuff[k_drift]) + return; + +skipcrap: + + if (P_MobjWasRemoved(stplyr->mo)) + return; + + if (!K_GetScreenCoords(&pos, stplyr, stplyr->mo, FixedMul(cv_driftgaugeofs.value, cv_driftgaugeofs.value > 0 ? stplyr->mo->scale : mapobjectscale), false)) + return; + + fixed_t barx; + fixed_t bary; + INT32 BAR_WIDTH; + + const INT32 driftval = K_GetKartDriftSparkValue(stplyr); + const INT32 driftcharge = min(driftval*4, stplyr->kartstuff[k_driftcharge]); + const INT32 driftlevel = min(driftcharge / driftval, 2); + const INT32 drifttrans = ((cv_driftgaugetrans.value) ? V_LocalTransFlag() : 0); + + basex = pos.x>>FRACBITS; + basey = pos.y>>FRACBITS; + + switch (cv_driftgaugestyle.value) + { + case 1: + case 2: + case 3: + case 5: + { + if (!driftgaugegfx) + break; + + const boolean usescaledpatch = (cv_driftgaugestyle.value == 5 && xtra_speedo3); + + if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || usescaledpatch) + { + barx = basex - dup*23; + BAR_WIDTH = dup*47; + } + else + { + barx = basex - dup*12; + BAR_WIDTH = dup*23; + } + + bary = basey - dup*2; + + if (usescaledpatch) // i hate hud code i hate hud code i hate hud code i hate hud code i hate hud code..... + { + if (K_UseColorSpeedo(SPEEDO_EXTRA3)) // Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + V_DrawStretchyFixedPatch((basex - dup*30)<= driftval*4) // rainbow sparks + { + cmap = R_GetTranslationColormap(TC_RAINBOW, 1 + leveltime % (MAXSKINCOLORS-1),GTC_CACHE); + + for (i = 0; i < 4; i++) + V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, (driftrainbow[min((leveltime % 18) + 1, 18 - 1)] + i*2) | V_NOSCALESTART|drifttrans); + } + else // none/blue/red + { + const INT32 limit = (driftval * (driftcharge >= driftval*2 ? 2 : 1)); + const INT32 width = ((driftcharge - (driftcharge >= driftval ? limit : 0)) * BAR_WIDTH) / limit; + + cmap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel],GTC_CACHE); + + for (i = 0; i < 4; i++) + { + if (driftcharge >= driftval) + V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, driftcolors[driftlevel-1][i] | V_NOSCALESTART|drifttrans); + + V_DrawFill(barx, bary+dup*1+dup*i, width, dup, driftcolors[driftlevel][i] | V_NOSCALESTART|drifttrans); + } + } + + // right, also draw a cool number + //SG_DrawPaddedNum(v, basex + (dup*32), basey, driftcharge*100 / driftval, 3, "PINGN", V_NOSCALESTART|V_OFFSET|drifttrans, cmap) + if (cv_driftgaugestyle.value == 3) + V_DrawPaddedTallColorNum(basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, cmap); + else + V_DrawPingNum(cv_driftgaugestyle.value == 2 ? basex + (dup*22) : basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, cmap); + } + break; + case 4: + { + cmap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel],GTC_CACHE); + + if (driftcharge >= driftval*4) + cmap = R_GetTranslationColormap(TC_RAINBOW, 1 + leveltime % (MAXSKINCOLORS-1),GTC_CACHE); + + V_DrawPaddedTallColorNum(basex + (dup*16), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, cmap); + } + break; + default: + break; + } +} + +static fixed_t K_FindCheckX(fixed_t px, fixed_t py, angle_t ang, fixed_t mx, fixed_t my) +{ + fixed_t dist, x; + fixed_t range = RING_DIST/3; + angle_t diff; + + range *= gamespeed+1; + + dist = abs(R_PointToDist2(px, py, mx, my)); + if (dist > range) + return -BASEVIDWIDTH; + + diff = R_PointToAngle2(px, py, mx, my) - ang; + + if (diff < ANGLE_90 || diff > ANGLE_270) + return -BASEVIDWIDTH; + else + x = (FixedMul(FINETANGENT(((diff+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), 160<>FRACBITS; + + if (encoremode) + x = BASEVIDWIDTH-x; + + if (splitscreen > 1) + x /= 2; + + return x; +} + +static void K_drawKartWanted(void) +{ + UINT8 i, numwanted = 0; + UINT8 *colormap = NULL; + INT32 basex = 0, basey = 0; + + if (stplyrnum != 0) + return; + + for (i = 0; i < 4; i++) + { + if (battlewanted[i] == -1) + break; + numwanted++; + } + + if (numwanted <= 0) + return; + + // set X/Y coords depending on splitscreen. + if (splitscreen < 3) // 1P and 2P use the same code. + { + basex = WANT_X; + basey = WANT_Y; + if (splitscreen == 2) + { + basey += 16; // slight adjust for 3P + basex -= 6; + } + } + else if (splitscreen == 3) // 4P splitscreen... + { + basex = BASEVIDWIDTH/2 - (kp_wantedsplit->width/2); // center on screen + basey = BASEVIDHEIGHT - 55; + //basey2 = 4; + } + + if (battlewanted[0] != -1) + colormap = R_GetTranslationColormap(0, players[battlewanted[0]].skincolor, GTC_CACHE); + + V_DrawFixedPatch(basex< 1 ? kp_wantedsplit : kp_wanted), colormap); + /*if (basey2) + V_DrawFixedPatch(basex< 1 ? 13 : 8), y = basey+(splitscreen > 1 ? 16 : 21); + fixed_t scale = FRACUNIT/2; + + if (battlewanted[i] == -1) + break; + + player_t *p = &players[battlewanted[i]]; + + if (numwanted == 1) + scale = FRACUNIT; + else + { + if (i & 1) + x += 16; + if (i > 1) + y += 16; + } + + if (p->skincolor) + { + colormap = R_GetTranslationColormap(TC_RAINBOW, p->skincolor, GTC_CACHE); + V_DrawFixedPatch(x<skin] : facerankprefix[p->skin]), colormap);*/ + } + } +} + +static void K_drawKartPlayerCheck(void) +{ + INT32 i; + UINT8 *colormap; + INT32 x; + + const INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM); + + if (!stplyr->mo || stplyr->spectator) + return; + + if (stplyr->awayviewtics) + return; + + if (camspin[0]) + return; + + for (i = 0; i < MAXPLAYERS; i++) + { + UINT8 pnum = 0; + + if (&players[i] == stplyr) + continue; + if (!playeringame[i] || players[i].spectator) + continue; + if (!players[i].mo) + continue; + + if ((players[i].kartstuff[k_invincibilitytimer] <= 0) && (leveltime & 2)) + pnum++; // white frames + + if (players[i].kartstuff[k_itemtype] == KITEM_GROW || players[i].kartstuff[k_growshrinktimer] > 0) + pnum += 4; + else if (players[i].kartstuff[k_itemtype] == KITEM_INVINCIBILITY || players[i].kartstuff[k_invincibilitytimer]) + pnum += 2; + + x = K_FindCheckX(stplyr->mo->x, stplyr->mo->y, stplyr->mo->angle, players[i].mo->x, players[i].mo->y); + if (x <= 320 && x >= 0) + { + if (x < 14) + x = 14; + else if (x > 306) + x = 306; + + colormap = R_GetTranslationColormap(TC_DEFAULT, players[i].mo->color, GTC_CACHE); + V_DrawMappedPatch(x, CHEK_Y, V_HUDTRANS|splitflags, kp_check[pnum], colormap); + } + } +} + +static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32 hudy, INT32 flags, INT32 blend, patch_t *icon, UINT8 *colormap, drawinfo_t *dims, boolean scaleme) +{ + // amnum xpos & ypos are the icon's speed around the HUD. + // The number being divided by is for how fast it moves. + // The higher the number, the slower it moves. + + // am xpos & ypos are the icon's starting position. Withouht + // it, they wouldn't 'spawn' on the top-right side of the HUD. + + fixed_t amnumxpos, amnumypos; + INT32 amxpos, amypos; + fixed_t scale = FRACUNIT; + patch_t *AutomapPic; + INT16 w, h; + + AutomapPic = minimapinfo.minimap_pic; + + if (AutomapPic == NULL) + { + return; // no pic, just get outta here + } + + amnumxpos = (FixedMul(objx, minimapinfo.zoom) - minimapinfo.offs_x); + amnumypos = -(FixedMul(objy, minimapinfo.zoom) - minimapinfo.offs_y); + + if (encoremode) + amnumxpos = -amnumxpos; + + if (dims && (dims->x != 0) && (dims->y != 0)) + { + w = dims->x; + h = dims->y; + } + else + { + w = icon->width; + h = icon->height; + } + + amxpos = amnumxpos + ((hudx + (AutomapPic->width-w)/2)<height-h)/2)<player; + const boolean skinlocal = mo->skinlocal; + + fixed_t amnumxpos, amnumypos; + INT32 amxpos, amypos, wntdamxpos, wntdamypos; + fixed_t scale = FRACUNIT; + patch_t *minimaphead = NULL; + +#ifdef ROTSPRITE + angle_t rollangle = 0; + INT32 rot = 0; +#endif + + skin = K_GetMobjSkin(mo); + minimaphead = (skinlocal ? localfacemmapprefix : facemmapprefix)[K_GetMobjSkinNum(skin, skinlocal)]; + + amnumxpos = (FixedMul(lerp(mo->old_x, mo->x), minimapinfo.zoom) - minimapinfo.offs_x); + amnumypos = -(FixedMul(lerp(mo->old_y, mo->y), minimapinfo.zoom) - minimapinfo.offs_y); + + if (encoremode) + amnumxpos = -amnumxpos; + + amxpos = amnumxpos + ((x + (minimapinfo.minimap_pic->width-minimaphead->width) / 2)<height-minimaphead->height) / 2)<color), player_names[player - players]); + } + + // thx wanted reticle for having weird offsets very cool + wntdamxpos = cv_minihead.value ? amxpos + (1<width / 4)<height / 4)<spinoutrot) + { + // Rotate counterclockwise. + rollangle = FixedAngle(player->spinoutrot * -1); + rot = R_GetRollAngle(rollangle); + + if (rot) + { + minimaphead = W_CachePatchNameRotated(skin->facemmap, rot, PU_PATCH); + } + } +#endif + + if (!mo->color) // 'default' color + V_DrawSciencePatch(amxpos, amypos, flags, minimaphead, scale); + else + { + UINT8 *colormap; + + if (mo->colorized) + colormap = R_GetTranslationColormap(TC_RAINBOW, mo->color, GTC_CACHE); + else + colormap = R_GetLocalTranslationColormap(mo->skin, mo->localskin, mo->color, GTC_CACHE, skinlocal); + + V_DrawFixedPatch(amxpos, amypos, scale, flags, minimaphead, colormap); + + if (player + && ((G_RaceGametype() && player->kartstuff[k_position] == spbplace) + || (G_BattleGametype() && K_IsPlayerWanted(player)))) + { + V_DrawFixedPatch(wntdamxpos, wntdamypos, scale, flags, kp_wantedreticle, NULL); + } + } +} + +enum +{ + MINIANGLE_NONE = 0, + MINIANGLE_DOT, + MINIANGLE_LIGHT +}; + +static void K_drawKartMinimap(void) +{ + INT32 i = 0; + INT32 x, y; + INT32 minimaptrans, splitflags; + SINT8 localplayers[MAXSPLITSCREENPLAYERS]; + SINT8 numlocalplayers = 0; + patch_t *AutomapPic; + + // Draw the HUD only when playing in a level. + // hu_stuff needs this, unlike st_stuff. + if (gamestate != GS_LEVEL) + return; + + // Only draw for the first player + if (stplyrnum != 0) + return; + + AutomapPic = minimapinfo.minimap_pic; + + if (AutomapPic == NULL) + { + return; // no pic, just get outta here + } + + minimaptrans = K_getMinimapTrans(); + + // Exit early if it wouldn't draw anyway. + if (minimaptrans == -1) + return; + + drawinfo_t info; + K_getMinimapDrawinfo(&info); + x = info.x - (AutomapPic->width/2); + y = info.y - (AutomapPic->height/2); + splitflags = info.flags; + + splitflags |= minimaptrans; + + if (encoremode) + V_DrawScaledPatch(x+AutomapPic->width, y, splitflags|V_FLIP, AutomapPic); + else + V_DrawScaledPatch(x, y, splitflags, AutomapPic); + + if (!(splitscreen == 2)) + { + splitflags &= ~minimaptrans; + splitflags |= V_HUDTRANSHALF; + } + + // let offsets transfer to the heads, too! + if (encoremode) + x += AutomapPic->leftoffset; + else + x -= AutomapPic->leftoffset; + y -= AutomapPic->topoffset; + + // initialize + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + localplayers[i] = -1; + + // Player's tiny icons on the Automap. (drawn opposite direction so player 1 is drawn last in splitscreen) + if (ghosts) + { + demoghost *g = ghosts; + while (g) + { + K_drawKartMinimapHead(g->mo, x, y, splitflags); + g = g->next; + } + + if (!stplyr->mo || stplyr->spectator) // do we need the latter..? + return; + + localplayers[numlocalplayers++] = stplyr-players; + } + else + { + for (i = MAXPLAYERS-1; i >= 0; i--) + { + if (!playeringame[i]) + continue; + + if (!players[i].mo || players[i].spectator) + continue; + + if (P_IsDisplayPlayer(&players[i])) + { + // Draw display players on top of everything else + localplayers[numlocalplayers++] = i; + continue; + } + + // Now we know it's not a display player, handle non-local player exceptions. + if (G_BattleGametype() && players[i].kartstuff[k_bumper] <= 0) + continue; + + if (players[i].kartstuff[k_hyudorotimer] > 0) + { + if (!((players[i].kartstuff[k_hyudorotimer] < 1*TICRATE/2 + || players[i].kartstuff[k_hyudorotimer] > hyudorotime-(1*TICRATE/2)) + && !(leveltime & 1))) + continue; + } + + K_drawKartMinimapHead(players[i].mo, x, y, splitflags); + } + } + + // draw our local players here, opaque. + splitflags &= ~V_HUDTRANSHALF; + splitflags |= V_HUDTRANS; + + const SINT8 icondotradius = (cv_minihead.value && !cv_showminimapnames.value) ? 8 : 10; + patch_t* minipatch; + INT32 rot; + INT32 blending; + + for (i = 0; i < numlocalplayers; i++) + { + if (localplayers[i] == -1) + continue; // this doesn't interest us + + mobj_t *mobj = players[localplayers[i]].mo; + + // dont draw for no contestants + boolean playertimedout = (mobj->health <= 0 && players[localplayers[i]].pflags & PF_TIMEOVER); + + if (cv_showminimapangle.value && (minidoticon || minilighticon) && !playertimedout) + { + UINT8 *colormap; + drawinfo_t dims; + fixed_t interpx, interpy; + fixed_t xoff = 0, yoff = 0; + blending = 0; + + angle_t ang = R_InterpolateAngle(mobj->old_angle, mobj->angle); + + if (encoremode) + ang = ANGLE_180 - ang; + + if (mobj->colorized) + colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE); + else + colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal); + + interpx = lerp(mobj->old_x, mobj->x); + interpy = lerp(mobj->old_y, mobj->y); + + minipatch = kp_minimapdot; + + dims.x = 0; + dims.y = 0; + + if (cv_showminimapangle.value == MINIANGLE_DOT) + { + xoff = FixedMul(FCOS(ang), icondotradius); + yoff = -FixedMul(FSIN(ang), icondotradius); + } + else if (cv_showminimapangle.value == MINIANGLE_LIGHT) + { + rot = R_GetRollAngle(ang); + minipatch = W_CachePatchNameRotated("MMAPHDLT", rot, PU_PATCH); + + blending = B_ADD; + xoff = yoff = 0; + + dims.x = 48; + dims.y = 24; + } + + K_drawKartMinimapIcon( + interpx, + interpy, + x + xoff, + y + yoff, + splitflags, + blending, + minipatch, + colormap, + &dims, + false + ); + } + + // draw the minimap head after the nonsense above + K_drawKartMinimapHead(mobj, x, y, splitflags); + } +} + +#undef lerp + +static void K_drawKartStartCountdown(void) +{ + INT32 pnum = 0, splitflags = K_calcSplitFlags(0); // 3 + + if (leveltime >= starttime-(2*TICRATE)) // 2 + pnum++; + if (leveltime >= starttime-TICRATE) // 1 + pnum++; + if (leveltime >= starttime) // GO! + pnum++; + if ((leveltime % (2*5)) / 5) // blink + pnum += 4; + if (splitscreen) // splitscreen + pnum += 8; + + V_DrawScaledPatch(STCD_X - (kp_startcountdown[pnum]->width/2), STCD_Y - (kp_startcountdown[pnum]->height/2), splitflags, kp_startcountdown[pnum]); +} + +static void K_drawKartFinish(void) +{ + INT32 pnum = 0, splitflags = K_calcSplitFlags(0); + + if (!stplyr->kartstuff[k_cardanimation] || stplyr->kartstuff[k_cardanimation] >= 2*TICRATE) + return; + + if ((stplyr->kartstuff[k_cardanimation] % (2*5)) / 5) // blink + pnum = 1; + + if (splitscreen > 1) // 3/4p, stationary FIN + { + pnum += 2; + V_DrawScaledPatch(STCD_X - (kp_racefinish[pnum]->width/2), STCD_Y - (kp_racefinish[pnum]->height/2), splitflags, kp_racefinish[pnum]); + return; + } + + //else -- 1/2p, scrolling FINISH + { + INT32 x, xval; + + if (splitscreen) // wide splitscreen + pnum += 4; + + x = ((vid.width<width<kartstuff[k_cardanimation])< x ? xval : x))/TICRATE; + + if (splitscreen && stplyrnum == 1) + x = -x; + + V_DrawFixedPatch(x + (STCD_X<>1), + (STCD_Y<height<<(FRACBITS-1)), + FRACUNIT, + splitflags, kp_racefinish[pnum], NULL); + } +} + +static void K_drawBattleFullscreen(void) +{ + INT32 cardanim = stplyr->kartstuff[k_cardanimation] << FRACBITS; + + // fill in the fractional bits + if (cardanim && cardanim != 164*FRACUNIT) + { + INT32 frac = R_GetHudUncap() * ((164 - stplyr->kartstuff[k_cardanimation])/8 + 1); + if (stplyr->exiting) + cardanim += frac; + else + cardanim += stplyr->kartstuff[k_comebacktimer] < 6*TICRATE ? -frac : frac; + } + + INT32 x = BASEVIDWIDTH/2; + INT32 y = (-64*FRACUNIT) + cardanim; // card animation goes from 0 to 164, 164 is the middle of the screen + INT32 splitflags = V_SNAPTOTOP; // I don't feel like properly supporting non-green resolutions, so you can have a misuse of SNAPTO instead + fixed_t scale = FRACUNIT; + boolean drawcomebacktimer = true; // lazy hack because it's cleaner in the long run. + + if (!LUA_HudEnabled(hud_battlecomebacktimer)) + drawcomebacktimer = false; + + if (splitscreen) + { + if ((splitscreen == 1 && stplyrnum == 1) || (splitscreen > 1 && stplyrnum & 2)) + { + y = (232*FRACUNIT) - (cardanim/2); + splitflags = V_SNAPTOBOTTOM; + } + else + y = (-32*FRACUNIT) + (cardanim/2); + + if (splitscreen > 1) + { + scale /= 2; + + if (stplyrnum & 1) + x = 3*BASEVIDWIDTH/4; + else + x = BASEVIDWIDTH/4; + } + else + { + if (stplyr->exiting) + { + if (stplyrnum == 1) + x = BASEVIDWIDTH-96; + else + x = 96; + } + else + scale /= 2; + } + } + + if (stplyr->exiting) + { + if (stplyrnum == 0) + V_DrawFadeScreen(0xFF00, 16); + if (stplyr->exiting < 6*TICRATE && !stplyr->spectator) + { + if (stplyr->kartstuff[k_position] == 1) + V_DrawFixedPatch(x<kartstuff[k_bumper] <= 0 && stplyr->kartstuff[k_comebacktimer] && comeback && !stplyr->spectator && drawcomebacktimer) + { + UINT16 t = stplyr->kartstuff[k_comebacktimer]/(10*TICRATE); + INT32 txoff, adjust = (splitscreen > 1) ? 4 : 6; // normal string is 8, kart string is 12, half of that for ease + INT32 ty = (BASEVIDHEIGHT/2)+66; + + txoff = adjust; + + while (t) + { + txoff += adjust; + t /= 10; + } + + if (splitscreen) + { + if (splitscreen > 1) + ty = (BASEVIDHEIGHT/4)+33; + if ((splitscreen == 1 && stplyrnum == 1) || (splitscreen > 1 && stplyrnum & 2)) + ty += (BASEVIDHEIGHT/2); + } + else + V_DrawFadeScreen(0xFF00, 16); + + if (!comebackshowninfo) + V_DrawFixedPatch(x< 1) + V_DrawString(x-txoff, ty, 0, va("%d", stplyr->kartstuff[k_comebacktimer]/TICRATE)); + else + { + if (K_UseColorHud()) // Colourized hud + { + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + V_DrawFixedPatch(x<kartstuff[k_comebacktimer]/TICRATE)); + } + } + + if (netgame && !stplyr->spectator && timeinmap > 113) // FREE PLAY? + { + UINT8 i; + + // check to see if there's anyone else at all + for (i = 0; i < MAXPLAYERS; i++) + { + if (i == displayplayers[0]) + continue; + if (playeringame[i] && !stplyr->spectator) + return; + } + + if (LUA_HudEnabled(hud_freeplay)) + K_drawKartFreePlay(leveltime); + } +} + +static void K_drawKartFirstPerson(void) +{ + static INT32 pnum[4], turn[4], drift[4]; + INT32 pn = 0, tn = 0, dr = 0; + INT32 target = 0, splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM); + INT32 x = BASEVIDWIDTH/2, y = BASEVIDHEIGHT; + fixed_t scale; + UINT8 *colmap = NULL; + ticcmd_t *cmd = &stplyr->cmd; + + if (stplyr->spectator || !stplyr->mo || (stplyr->mo->flags2 & MF2_DONTDRAW)) + return; + + pn = pnum[stplyrnum]; + tn = turn[stplyrnum]; + dr = drift[stplyrnum]; + + if (splitscreen) + { + y >>= 1; + if (splitscreen > 1) + x >>= 1; + } + + { + if (stplyr->speed < (20*stplyr->mo->scale) && (leveltime & 1) && !splitscreen) + y++; + // the following isn't EXPLICITLY right, it just gets the result we want, but i'm too lazy to look up the right way to do it + if (stplyr->mo->flags2 & MF2_SHADOW) + splitflags |= FF_TRANS80; + else if (stplyr->mo->frame & FF_TRANSMASK) + splitflags |= (stplyr->mo->frame & FF_TRANSMASK); + } + + if (cmd->driftturn > 400) // strong left turn + target = 2; + else if (cmd->driftturn < -400) // strong right turn + target = -2; + else if (cmd->driftturn > 0) // weak left turn + target = 1; + else if (cmd->driftturn < 0) // weak right turn + target = -1; + else // forward + target = 0; + + if (encoremode) + target = -target; + + if (pn < target) + pn++; + else if (pn > target) + pn--; + + if (pn < 0) + splitflags |= V_FLIP; // right turn + + target = abs(pn); + if (target > 2) + target = 2; + + x <<= FRACBITS; + y <<= FRACBITS; + + if (tn != cmd->driftturn/50) + tn -= (tn - (cmd->driftturn/50))/8; + + if (dr != stplyr->kartstuff[k_drift]*16) + dr -= (dr - (stplyr->kartstuff[k_drift]*16))/8; + + if (splitscreen == 1) + { + scale = (2*FRACUNIT)/3; + y += FRACUNIT/(vid.dupx < vid.dupy ? vid.dupx : vid.dupy); // correct a one-pixel gap on the screen view (not the basevid view) + } + else if (splitscreen) + scale = FRACUNIT/2; + else + scale = FRACUNIT; + + if (stplyr->mo) + { + INT32 dsone = K_GetKartDriftSparkValue(stplyr); + INT32 dstwo = dsone*2; + INT32 dsthree = dstwo*2; + +#ifndef DONTLIKETOASTERSFPTWEAKS + { + const angle_t ang = R_PointToAngle2(0, 0, stplyr->rmomx, stplyr->rmomy) - stplyr->frameangle; + // yes, the following is correct. no, you do not need to swap the x and y. + fixed_t xoffs = -P_ReturnThrustY(stplyr->mo, ang, (BASEVIDWIDTH<<(FRACBITS-2))/2); + fixed_t yoffs = -(P_ReturnThrustX(stplyr->mo, ang, 4*FRACUNIT) - 4*FRACUNIT); + + if (splitscreen) + xoffs = FixedMul(xoffs, scale); + + xoffs -= (tn)*scale; + xoffs -= (dr)*scale; + + if (stplyr->frameangle == stplyr->mo->angle) + { + const fixed_t mag = FixedDiv(stplyr->speed, 10*stplyr->mo->scale); + + if (mag < FRACUNIT) + { + xoffs = FixedMul(xoffs, mag); + if (!splitscreen) + yoffs = FixedMul(yoffs, mag); + } + } + + if (stplyr->mo->momz > 0) // TO-DO: Draw more of the kart so we can remove this if! + yoffs += stplyr->mo->momz/3; + + if (encoremode) + x -= xoffs; + else + x += xoffs; + if (!splitscreen) + y += yoffs; + } + + // drift sparks! + if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dsthree)) + colmap = R_GetTranslationColormap(TC_RAINBOW, (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))), GTC_CACHE); + else if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dstwo)) + colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_KETCHUP, GTC_CACHE); + else if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dsone)) + colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_SAPPHIRE, GTC_CACHE); + else +#endif + // invincibility/grow/shrink! + if (stplyr->mo->colorized && stplyr->mo->color) + colmap = R_GetTranslationColormap(TC_RAINBOW, stplyr->mo->color, GTC_CACHE); + } + + V_DrawFixedPatch(x, y, scale, splitflags, kp_fpview[target], colmap); + + pnum[stplyrnum] = pn; + turn[stplyrnum] = tn; + drift[stplyrnum] = dr; +} + +// doesn't need to ever support 4p +static void K_drawInput(void) +{ + INT32 offs, col; + static INT32 pn = 0; + + if (!cv_showinput.value || (timeinmap <= 105)) // dont bother + return; + + INT32 target = 0, splitflags = (V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS); + INT32 x = (BASEVIDWIDTH - 32 + cv_wheel_xoffset.value)*FRACUNIT, y = (BASEVIDHEIGHT - 24 + cv_wheel_yoffset.value)*FRACUNIT; + + const UINT8 hudcolor = K_GetHudColor(); + const INT32 accent1 = splitflags|colortranslations[hudcolor][5]; + const INT32 accent2 = splitflags|colortranslations[hudcolor][9]; + const UINT8 *hudcolormap = R_GetTranslationColormap(0, hudcolor, GTC_CACHE); + + const ticcmd_t *cmd = &stplyr->cmd; + + if (timeinmap < 113) + { + INT32 count = ((INT32)(timeinmap) - 105); + INT32 frac = count > 0 && count < 6 ? R_GetHudUncap() << (FRACBITS - count - 11) : 0; + + offs = 64*FRACUNIT; + while (count-- > 0) + offs >>= 1; + x += (offs < FRACUNIT ? 0 : offs) - frac; + } + +#define BUTTW 8 +#define BUTTH 11 + +#define drawbutt(xoffs, butt, symb)\ + if (cmd->buttons & butt)\ + {\ + offs = 2*FRACUNIT;\ + col = accent1;\ + }\ + else\ + {\ + offs = 0;\ + col = accent2;\ + V_DrawFill((x + xoffs*FRACUNIT)>>FRACBITS, (y + BUTTH*FRACUNIT)>>FRACBITS, BUTTW-1, 2, splitflags|31);\ + }\ + V_DrawFill((x + xoffs*FRACUNIT)>>FRACBITS, (y+offs)>>FRACBITS, BUTTW-1, BUTTH, col);\ + V_DrawFixedPatch(x + FRACUNIT + xoffs*FRACUNIT, y + offs + FRACUNIT, FRACUNIT, splitflags, tny_font[symb-HU_FONTSTART], NULL) + + drawbutt(-2*BUTTW, BT_ACCELERATE, 'A'); + drawbutt( -BUTTW, BT_BRAKE, 'B'); + drawbutt( 0, BT_DRIFT, 'D'); + drawbutt( BUTTW, BT_ATTACK, 'I'); + +#undef drawbutt + +#undef BUTTW +#undef BUTTH + + y -= FRACUNIT; + + if (cv_showinput.value == 2 || cv_showinput.value == 3) + { + INT32 axis; + INT32 hudforward = 0; // for the stick input display :chaosleep: + UINT8 *shadowcolormap = NULL; + const INT32 joyx = x>>FRACBITS; + const INT32 joyy = y>>FRACBITS; + static const INT32 joyxoffs = -8; + static const INT32 joyyoffs = -24; + const boolean usejoysprite = (cv_showinput.value == 3 && joystickicon); + + // O backing + if (usejoysprite) + { + shadowcolormap = R_GetTranslationColormap(0, SKINCOLOR_BLACK, GTC_CACHE); + V_DrawMappedPatch(joyx+joyxoffs, joyy+joyyoffs-1, splitflags, joybacking, hudcolormap); + } + else + { + V_DrawFill(joyx+joyxoffs, joyy+joyyoffs-1, 16, 16, splitflags|accent2); + V_DrawFill(joyx+joyxoffs, joyy+joyyoffs+15, 16, 1, splitflags|31); + } + + // time for pain and suffering + // kart does not have anything we can get analogue joystick y axis values from + // during normal gameplay, so replicate shit here + + // this is horrid but we cant get actual input in replays so uhh + if (demo.playback || !P_IsLocalPlayer(stplyr)) // yeah........... + { + hudforward = stplyr->kartstuff[k_throwdir] * KART_FULLTURN; + } + else + { + const boolean analogjoystickmove = cv_usejoystick[stplyrnum].value && !Joystick[stplyrnum].bGamepadStyle; + const boolean gamepadjoystickmove = cv_usejoystick[stplyrnum].value && Joystick[stplyrnum].bGamepadStyle; + const UINT8 ssplayer = stplyrnum+1; + + axis = JoyAxis(AXISAIM, ssplayer); + + if (analogjoystickmove && axis != 0) + { + // JOYAXISRANGE is supposed to be 1023 (divide by 1024) + hudforward -= ((axis * KART_FULLTURN) / (JOYAXISRANGE-1)); + } + else + { + if (InputDown(gc_aimforward, ssplayer) || (gamepadjoystickmove && axis < 0)) + { + hudforward += KART_FULLTURN; + } + if (InputDown(gc_aimbackward, ssplayer) || (gamepadjoystickmove && axis > 0)) + { + hudforward-= KART_FULLTURN; + } + } + + hudforward = CLAMP(hudforward, -KART_FULLTURN, KART_FULLTURN); + } + + if (cmd->driftturn || hudforward) + { + INT16 turning = encoremode ? -cmd->driftturn : cmd->driftturn; + + if (usejoysprite) + { + V_DrawMappedPatch(joyx+joyxoffs+3-turning/80, joyy+joyyoffs+2-hudforward/80, splitflags, joyknob, shadowcolormap); + V_DrawMappedPatch(joyx+joyxoffs+3-turning/64, joyy+joyyoffs+1-hudforward/64, splitflags, joyknob, hudcolormap); + } + else + { + // joystick hole + V_DrawFill(joyx+joyxoffs+5, joyy+joyyoffs+4, 6, 6, splitflags|accent1); + // joystick top and back + V_DrawFill(joyx+joyxoffs+3-turning/80, joyy+joyyoffs+2-hudforward/80, 10, 10, splitflags|31); + V_DrawFill(joyx+joyxoffs+3-turning/64, joyy+joyyoffs+1-hudforward/64, 10, 10, splitflags|accent1); + } + } + else + { + if (usejoysprite) + { + V_DrawMappedPatch(joyx+joyxoffs+3, joyy+joyyoffs+8, splitflags, joyshadow, shadowcolormap); + V_DrawMappedPatch(joyx+joyxoffs+3, joyy+joyyoffs+1, splitflags, joyknob, hudcolormap); + } + else + { + V_DrawFill(joyx+joyxoffs+3, joyy+joyyoffs+11, 10, 1, splitflags|accent2); + V_DrawFill(joyx+joyxoffs+3, joyy+joyyoffs+1, 10, 10,splitflags|accent1); + } + } + } + else + { + if (!cmd->driftturn) // no turn + target = 0; + else // turning of multiple strengths! + { + target = ((abs(cmd->driftturn) - 1)/125)+1; + if (target > 4) + target = 4; + if (cmd->driftturn < 0) + target = -target; + } + + if (pn != target) + { + if (abs(pn - target) == 1) + pn = target; + else if (pn < target) + pn += 2; + else //if (pn > target) + pn -= 2; + } + + if (pn < 0) + { + splitflags |= V_FLIP; // right turn + x -= FRACUNIT; + } + + target = abs(pn); + if (target > 4) + target = 4; + + V_DrawFixedPatch(x, y, FRACUNIT, splitflags, kp_inputwheel[target], hudcolormap); + } +} + +static void K_drawChallengerScreen(void) +{ + // This is an insanely complicated animation. + static const UINT8 anim[52] = { + 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13, // frame 1-14, 2 tics: HERE COMES A NEW slides in + 14,14,14,14,14,14, // frame 15, 6 tics: pause on the W + 15,16,17,18, // frame 16-19, 1 tic: CHALLENGER approaches screen + 19,20,19,20,19,20,19,20,19,20, // frame 20-21, 1 tic, 5 alternating: all text vibrates from impact + 21,22,23,24 // frame 22-25, 1 tic: CHALLENGER turns gold + }; + const UINT8 offset = min(52-1, (3*TICRATE)-mapreset); + + V_DrawFadeScreen(0xFF00, 16); // Fade out + V_DrawScaledPatch(0, 0, 0, kp_challenger[anim[offset]]); +} + +static void K_drawLapStartAnim(void) +{ + // This is an EVEN MORE insanely complicated animation. + const UINT8 progress = 80-stplyr->kartstuff[k_lapanimation]; + UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + INT32 vflags = V_SNAPTOTOP|V_HUDTRANS; + + fixed_t slideout = max(0, 32*(((progress - 76)*FRACUNIT) + R_GetHudUncap())); + fixed_t slidein = max(0, 32*(((stplyr->kartstuff[k_lapanimation] - 76)*FRACUNIT) - R_GetHudUncap())); + + // First, draw the emblem and hand + INT32 emblemx = (BASEVIDWIDTH << (FRACBITS - 1)) + slidein; + INT32 y = 48*FRACUNIT - slideout; + + V_DrawFixedPatch(emblemx, y, FRACUNIT, vflags, kp_lapanim_emblem[modeattacking ? 1 : 0], colormap); + + INT32 hand = stplyr->kartstuff[k_laphand]; + if (hand >= 1 && hand <= 3) + { + y += 4*FRACUNIT - abs((int)(leveltime % 8)*FRACUNIT + R_GetHudUncap() - 4*FRACUNIT); + V_DrawFixedPatch(emblemx, y, FRACUNIT, vflags, kp_lapanim_hand[hand - 1], NULL); + } + + // Then the text + INT32 leftx = 82*FRACUNIT - slideout; + INT32 rightx = 188*FRACUNIT + slideout; + y = 30*FRACUNIT; + + if (stplyr->laps == (UINT8)(cv_numlaps.value - 1)) + { + // FINAL + V_DrawFixedPatch(leftx - 20*FRACUNIT, y, FRACUNIT, vflags, kp_lapanim_final[min(progress/2, 10)], NULL); + + // LAP + if (progress/2 - 12 >= 0) + V_DrawFixedPatch(rightx, y, FRACUNIT, vflags, kp_lapanim_lap[min(progress/2 - 12, 6)], NULL); + } + else + { + // LAP + V_DrawFixedPatch(leftx, y, FRACUNIT, vflags, kp_lapanim_lap[min(progress/2, 6)], NULL); + + char *lapnum = va("%02d", stplyr->laps + 1); + for (int i = 0; i < (int)strlen(lapnum); i++) + { + int digit = lapnum[i] - '0'; + int frame = min(2, progress/2 - 8 - (i*2)); + if (frame >= 0) + V_DrawFixedPatch(rightx + (i*20*FRACUNIT), y, FRACUNIT, vflags, kp_lapanim_number[digit][frame], NULL); + } + } +} + +void K_drawKartFreePlay(UINT32 flashtime) +{ + // no splitscreen support because it's not FREE PLAY if you have more than one player in-game + + if (!cv_showfreeplay.value) + return; + + if ((flashtime % TICRATE) < TICRATE/2) + return; + + V_DrawKartString((BASEVIDWIDTH - (LAPS_X+1)) - (12*9), // mirror the laps thingy + LAPS_Y+3, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, "FREE PLAY"); +} + +static void K_drawDistributionDebugger(void) +{ + patch_t *items[NUMKARTRESULTS] = { + kp_sadface[1], + kp_sneaker[1], + kp_rocketsneaker[1], + kp_invincibility[7], + kp_banana[1], + kp_eggman[1], + kp_orbinaut[4], + kp_jawz[1], + kp_mine[1], + kp_ballhog[1], + kp_selfpropelledbomb[1], + kp_grow[1], + kp_shrink[1], + kp_thundershield[1], + kp_hyudoro[1], + kp_pogospring[1], + kp_kitchensink[1], + + kp_sneaker[1], + kp_banana[1], + kp_banana[1], + kp_orbinaut[4], + kp_orbinaut[4], + kp_jawz[1] + }; + INT32 useodds = 0; + INT32 pingame = 0, bestbumper = 0; + INT32 i; + INT32 x = -9, y = -9; + boolean dontforcespb = false; + boolean spbrush = false; + + if (stplyrnum != 0) // only for p1 + return; + + // The only code duplication from the Kart, just to avoid the actual item function from calculating pingame twice + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + continue; + pingame++; + if (players[i].exiting) + dontforcespb = true; + if (players[i].kartstuff[k_bumper] > bestbumper) + bestbumper = players[i].kartstuff[k_bumper]; + } + + if (G_RaceGametype()) + spbrush = (spbplace != -1 && stplyr->kartstuff[k_position] == spbplace+1); + + useodds = K_FindUseodds(stplyr, 0, pingame, bestbumper, spbrush, dontforcespb); + + for (i = 1; i < NUMKARTRESULTS; i++) + { + const INT32 itemodds = K_KartGetItemOdds(useodds, i, 0, spbrush); + if (itemodds <= 0) + continue; + + V_DrawScaledPatch(x, y, V_HUDTRANS|V_SNAPTOTOP, items[i]); + V_DrawThinString(x+11, y+31, V_HUDTRANS|V_SNAPTOTOP, va("%d", itemodds)); + + // Display amount for multi-items + if (i >= NUMKARTITEMS) + { + INT32 amount; + switch (i) + { + case KRITEM_TENFOLDBANANA: + amount = 10; + break; + case KRITEM_QUADORBINAUT: + amount = 4; + break; + case KRITEM_DUALJAWZ: + amount = 2; + break; + default: + amount = 3; + break; + } + V_DrawString(x+24, y+31, V_ALLOWLOWERCASE|V_HUDTRANS|V_SNAPTOTOP, va("x%d", amount)); + } + + x += 32; + if (x >= 297) + { + x = -9; + y += 32; + } + } + + V_DrawString(0, 0, V_HUDTRANS|V_SNAPTOTOP, va("USEODDS %d", useodds)); +} + +static void K_drawCheckpointDebugger(void) +{ + if (stplyrnum != 0) // only for p1 + return; + + if (stplyr->starpostnum >= (numstarposts - (numstarposts/2))) + V_DrawString(8, 184, 0, va("Checkpoint: %d / %d (Can finish)", stplyr->starpostnum, numstarposts)); + else + V_DrawString(8, 184, 0, va("Checkpoint: %d / %d (Skip: %d)", stplyr->starpostnum, numstarposts, ((numstarposts/2) + stplyr->starpostnum))); + V_DrawString(8, 192, 0, va("Waypoint dist: Prev %d, Next %d", stplyr->kartstuff[k_prevcheck], stplyr->kartstuff[k_nextcheck])); +} + +// determines if gametype info (laps/bumpers) should be hidden +static boolean K_DisableGametypeInfo(void) +{ + if (!LUA_HudEnabled(hud_gametypeinfo)) + { + return true; + } + +#ifdef ROTSPRITE + if (splitscreen || (!cv_kartspeedometer.value)) + { + // don't need to run checks if we're in splitscreen, or not using the speedometer + return false; + } + + const UINT8 speedostyle = K_GetSpeedometerStyle(); + + if (G_RaceGametype()) + { + if (speedostyle == SPEEDO_DIAL) + return true; + } + else if (G_BattleGametype()) + { + if ((cv_battlespeedo.value) && (speedostyle == SPEEDO_DIAL)) + return true; + } +#endif + + return false; +} + +void K_drawKartHUD(void) +{ + boolean isfreeplay = false; + boolean battlefullscreen = false; + boolean freecam = camera[stplyrnum].freecam; //disable some hud elements w/ freecam + boolean gameinfovisible = false; + + // Define the X and Y for each drawn object + // This is handled by console/menu values + K_initKartHUD(); + + // Draw that fun first person HUD! Drawn ASAP so it looks more "real". + if (!camera[stplyrnum].chase && !freecam) + K_drawKartFirstPerson(); + + // Draw full screen stuff that turns off the rest of the HUD + if (mapreset && stplyrnum == 0) + { + K_drawChallengerScreen(); + return; + } + + battlefullscreen = ((G_BattleGametype()) + && (stplyr->exiting + || (stplyr->kartstuff[k_bumper] <= 0 + && stplyr->kartstuff[k_comebacktimer] + && comeback + && stplyr->playerstate == PST_LIVE))); + + if (!demo.title && (!battlefullscreen || splitscreen)) + { + // Draw the CHECK indicator before the other items, so it's overlapped by everything else + + if (LUA_HudEnabled(hud_check)) // delete lua when? + { + if (cv_kartcheck.value && !splitscreen && !players[displayplayers[0]].exiting && !freecam) + K_drawKartPlayerCheck(); + } + + // Draw WANTED status + if (G_BattleGametype()) + { + if (LUA_HudEnabled(hud_wanted)) + K_drawKartWanted(); + } + + if (cv_kartminimap.value) + { + if (LUA_HudEnabled(hud_minimap)) + K_drawKartMinimap(); + } + } + + if (battlefullscreen && !freecam) + { + if (LUA_HudEnabled(hud_battlefullscreen)) + K_drawBattleFullscreen(); + return; + } + + // Draw the item window + if (LUA_HudEnabled(hud_item) && !freecam) + K_drawKartItem(); + + if (cv_driftgauge.value && !modeattacking) + { + if (LUA_HudEnabled(hud_driftgauge)) + K_drawDriftGauge(); + } + + if (cv_nametag.value) + { + if (LUA_HudEnabled(hud_nametags)) + K_drawNameTags(); + } + + // If not splitscreen, draw... + if (!splitscreen && !demo.title) + { + tic_t realtime = stplyr->realtime; + + if (cv_showlaptimes.value + && stplyr->kartstuff[k_lapanimation] + && !stplyr->exiting + && stplyr->laptime[LAP_LAST] != 0 + && !midgamejoin) // due to vanilla compat, we cannot synch this oh well + { + if ((stplyr->kartstuff[k_lapanimation] / 5) & 1) + { + realtime = stplyr->laptime[LAP_LAST]; + } + else + { + realtime = UINT32_MAX; + } + } + + // Draw the timestamp + if (LUA_HudEnabled(hud_time)) + K_drawKartTimestamp(realtime, TIME_X, TIME_Y, gamemap, 0); + + if (!modeattacking) + { + // The top-four faces on the left + //if (LUA_HudEnabled(hud_minirankings)) + isfreeplay = K_drawKartPositionFaces(); + } + } + + if (!stplyr->spectator && !freecam) // Bottom of the screen elements, don't need in spectate mode + { + // get gametype info visibility ahead of time + gameinfovisible = (!K_DisableGametypeInfo()); + + if (!(splitscreen || demo.title)) + { + if (LUA_HudEnabled(hud_inputdisplay)) + K_drawInput(); + } + + if (!demo.title && cv_showstats.value) + { + if (LUA_HudEnabled(hud_statdisplay)) + K_drawKartStats(); + } + + if (demo.title) // Draw title logo instead in demo.titles + { + INT32 x = (BASEVIDWIDTH - 32)*FRACUNIT, y = 128*FRACUNIT, offs; + INT32 logoflags = V_SNAPTORIGHT|V_SNAPTOBOTTOM; + + if (splitscreen == 3) + { + x = BASEVIDWIDTH/2 + 10; + y = BASEVIDHEIGHT/2 - 30; + } + + if (timeinmap < 113) + { + INT32 count = ((INT32)(timeinmap) - 104); + INT32 frac = count > 0 ? R_GetHudUncap() << max(0, FRACBITS - count - 9) : 0; + + offs = 256*FRACUNIT; + while (count-- > 0) + offs >>= 1; + x += offs - frac; + } + + V_DrawSciencePatch(x - (54*FRACUNIT), y, logoflags, W_CachePatchName("TTKBANNR", PU_PATCH), FRACUNIT/4); + V_DrawSciencePatch(x - (54*FRACUNIT), y + (25*FRACUNIT), logoflags, W_CachePatchName("TTKART", PU_PATCH), FRACUNIT/4); + } + else if (G_RaceGametype()) // Race-only elements + { + // Draw the lap counter + if (gameinfovisible) + K_drawKartLaps(); + + if (!splitscreen) + { + // Draw the speedometer + // TODO: Make a better speedometer. << done :p + if (LUA_HudEnabled(hud_speedometer)) + K_drawKartSpeedometer(); + } + + if (isfreeplay) + ; + else if (!modeattacking) + { + // Draw the numerical position + if (LUA_HudEnabled(hud_position)) + K_DrawKartPositionNum(stplyr->kartstuff[k_position]); + } + } + else if (G_BattleGametype()) // Battle-only + { + // Draw the hits left! + if (gameinfovisible) + K_drawKartBumpersOrKarma(); + + if ((!splitscreen) && cv_battlespeedo.value) + { + // Draw the speedometer but in battle + // TODO: Make a better speedometer. << done :p + if (LUA_HudEnabled(hud_speedometer)) + K_drawKartSpeedometer(); + } + } + } + + // Draw the countdowns after everything else. + if (leveltime >= starttime-(3*TICRATE) + && leveltime < starttime+TICRATE) + K_drawKartStartCountdown(); + else if (racecountdown && (!splitscreen || !stplyr->exiting)) + { + char *countstr = va("%d", racecountdown/TICRATE); + + // Eeeh dunno if would be better to add another variable instead of LAPS_Y but this works too + int yoff = cv_dnft_yoffset.value - cv_laps_yoffset.value; + int xoff = cv_dnft_xoffset.value; + + if (splitscreen > 1) + V_DrawCenteredString(BASEVIDWIDTH/4+xoff, LAPS_Y+1+yoff, K_calcSplitFlags(V_SNAPTOBOTTOM), countstr); + else + { + INT32 karlen = strlen(countstr)*6; // half of 12 + V_DrawKartString((BASEVIDWIDTH/2)-karlen+xoff, LAPS_Y+3+yoff, K_calcSplitFlags(V_SNAPTOBOTTOM), countstr); + } + } + + // Race overlays + if (G_RaceGametype() && !freecam) + { + if (stplyr->exiting) + K_drawKartFinish(); + else if (stplyr->kartstuff[k_lapanimation] && !splitscreen && cv_showlapemblem.value) + K_drawLapStartAnim(); + } + + if (modeattacking || freecam) // everything after here is MP and debug only + return; + + if (G_BattleGametype() && !splitscreen && (stplyr->kartstuff[k_yougotem] % 2)) // * YOU GOT EM * + V_DrawScaledPatch(BASEVIDWIDTH/2 - (kp_yougotem->width/2), 32, V_HUDTRANS, kp_yougotem); + + // Draw FREE PLAY. + if (isfreeplay && !stplyr->spectator && timeinmap > 113) + { + if (LUA_HudEnabled(hud_freeplay)) + K_drawKartFreePlay(leveltime); + } + + if (cv_kartdebugdistribution.value) + K_drawDistributionDebugger(); + + if (cv_kartdebugcheckpoint.value) + K_drawCheckpointDebugger(); + + if (cv_kartdebugdirector.value) + K_DrawDirectorDebugger(); + + if (cv_kartdebugnodes.value) + { + UINT8 p; + for (p = 0; p < MAXPLAYERS; p++) + V_DrawString(8, 64+(8*p), V_YELLOWMAP, va("%d - %d (%dl)", p, playernode[p], players[p].cmd.latency)); + } + + if (cv_kartdebugcolorize.value && stplyr->mo && stplyr->mo->skin) + { + INT32 x = 0, y = 0; + UINT8 c; + + for (c = 1; c < MAXSKINCOLORS; c++) + { + UINT8 *cm = R_GetTranslationColormap(TC_RAINBOW, c, GTC_CACHE); + V_DrawFixedPatch(x<>1, 0, facewantprefix[stplyr->skin], cm); + + x += 16; + if (x > BASEVIDWIDTH-16) + { + x = 0; + y += 16; + } + } + } +} diff --git a/src/k_hud.h b/src/k_hud.h new file mode 100644 index 000000000..3d2e478a7 --- /dev/null +++ b/src/k_hud.h @@ -0,0 +1,81 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 2018-2020 by Kart Krew +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file k_hud.h +/// \brief HUD drawing functions exclusive to Kart + +#ifndef __K_HUD__ +#define __K_HUD__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "doomdef.h" +#include "d_player.h" // Need for player_t +#include "command.h" +#include "r_defs.h" + +UINT8 K_GetHudColor(void); +boolean K_UseColorHud(void); +boolean K_UseHighResPortraits(void); +patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum); + +void K_RegisterKartHudStuff(void); + +extern consvar_t cv_colorizedhud, + cv_colorizeditembox, + cv_colorizedhudcolor; + +extern consvar_t cv_darkitembox; +extern consvar_t cv_biglaps; +extern consvar_t cv_highresportrait; +extern consvar_t cv_stat_xoffset, cv_stat_yoffset; +extern consvar_t cv_showstats; +extern consvar_t cv_fancyroulette; +extern consvar_t cv_showlaptimes; +extern consvar_t cv_battlespeedo; +extern consvar_t cv_multiitemicon; +extern consvar_t cv_huditemamount; + +#define NUMSPEEDOSTUFF 8 +extern CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; +#define NUMDGAUGESTUFF 6 +extern CV_PossibleValue_t driftgaugestyle_cons_t[NUMDGAUGESTUFF]; +#define NUMINPUTDISPLAYSTUFF 5 +extern CV_PossibleValue_t inputdisplay_cons_t[NUMINPUTDISPLAYSTUFF]; +#define NUMMINIMAPDOTSTUFF 5 +extern CV_PossibleValue_t minimapdot_cons_t[NUMMINIMAPDOTSTUFF]; + +const char *K_GetItemPatch(UINT8 item, boolean tiny); +INT32 K_calcSplitFlags(INT32 snapflags); +void K_LoadKartHUDGraphics(void); +void K_drawKartHUD(void); +void K_drawKartFreePlay(UINT32 flashtime); +void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UINT8 mode); + +typedef struct +{ + INT32 x; + INT32 y; + INT32 flags; +} drawinfo_t; + +patch_t *K_getItemBoxPatch(boolean small, boolean dark); +patch_t *K_getItemMulPatch(boolean small); +void K_getItemBoxDrawinfo(drawinfo_t *out); +INT32 K_getMinimapTrans(void); +void K_getLapsDrawinfo(drawinfo_t *out); +void K_getMinimapDrawinfo(drawinfo_t *out); + +#ifdef __cplusplus +} // extern "C" +#endif + +// ========================================================================= +#endif // __K_HUD__ diff --git a/src/k_kart.c b/src/k_kart.c index c8dc049a3..61da6ba91 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -10,76 +10,28 @@ #include "command.h" #include "d_netcmd.h" #include "d_player.h" -#include "hu_stuff.h" +#include "k_hud.h" #include "g_game.h" -#include "i_joy.h" #include "m_fixed.h" #include "m_random.h" #include "m_menu.h" // ffdhidshfuisduifigergho9igj89dgodhfih AAAAAAAAAA #include "p_local.h" -#include "p_setup.h" #include "p_slopes.h" #include "r_defs.h" #include "r_draw.h" -#include "r_local.h" #include "r_state.h" #include "r_things.h" -#include "r_fps.h" #include "s_sound.h" -#include "screen.h" -#include "st_stuff.h" #include "tables.h" #include "v_video.h" -#include "z_zone.h" #include "m_misc.h" #include "m_cond.h" #include "k_director.h" #include "k_kart.h" #include "k_stats.h" -#include "f_finale.h" -#include "lua_hud.h" // For Lua hud checks #include "lua_hook.h" // For MobjDamage and ShouldDamage -#include "d_main.h" // found_extra_kart - - #include "i_video.h" -#ifdef HWRENDER -#include "hardware/hw_main.h" -#endif - -#ifdef ROTSPRITE -#include "r_patchrotation.h" -#endif - -// Hud offset cvars -#define IMPL_HUD_OFFSET_X(name)\ -consvar_t cv_##name##_xoffset = {"hud_" #name "_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; - -#define IMPL_HUD_OFFSET_Y(name)\ -consvar_t cv_##name##_yoffset = {"hud_" #name "_yoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; - -#define IMPL_HUD_OFFSET(name)\ -IMPL_HUD_OFFSET_X(name)\ -IMPL_HUD_OFFSET_Y(name) - -IMPL_HUD_OFFSET(item); // Item box -IMPL_HUD_OFFSET(time); // Time -IMPL_HUD_OFFSET(laps); // Number of laps -IMPL_HUD_OFFSET(dnft); // Countdown (did not finish timer) -IMPL_HUD_OFFSET(speed); // Speedometer -IMPL_HUD_OFFSET(posi); // Position in race -IMPL_HUD_OFFSET(wheel); // RA Wheel -IMPL_HUD_OFFSET(face); // Mini rankings -IMPL_HUD_OFFSET(stcd); // Starting countdown -IMPL_HUD_OFFSET_Y(chek); // Check gfx -IMPL_HUD_OFFSET(mini); // Minimap -IMPL_HUD_OFFSET(want); // Wanted -IMPL_HUD_OFFSET(stat); // Stats - -#undef IMPL_HUD_OFFSET -#undef IMPL_HUD_OFFSET_X -#undef IMPL_HUD_OFFSET_Y // extra colourisation stuff static CV_PossibleValue_t colorspeedlines_cons_t[] = {{0, "Off"}, {1, "Normal"}, {2, "+Driftcharge"}, {3, "Drift only"}, {0, NULL}}; @@ -93,36 +45,6 @@ consvar_t cv_bananthrowroll = {"bananthrowroll", "0", CV_SAVE, bananthrowroll_co consvar_t cv_airsparks = {"airdriftsparks", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -//extra hud things -consvar_t cv_showstats = {"showstats", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -CV_PossibleValue_t inputdisplay_cons_t[NUMINPUTDISPLAYSTUFF]; -consvar_t cv_showinput = {"showinput", "Off", CV_SAVE, inputdisplay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showlaptimes = {"showlaptimes", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_posanim = {"postitionanimation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_smallposnum = {"smallpositionnumber", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_fancyroulette = {"animatedroulette", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showminimapnames = {"showminimapnames", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -CV_PossibleValue_t minimapdot_cons_t[NUMMINIMAPDOTSTUFF]; -consvar_t cv_showminimapangle = {"showminimapangle", "Off", CV_SAVE, minimapdot_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_highresportrait = {"highresportrait", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // make char potraits use their high-res version instead - -consvar_t cv_showlapemblem = {"showlapemblem", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_biglaps = {"biglaphud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // here for ppl who dont want to make 2 more patches for their custom hud - -consvar_t cv_darkitembox = {"darkitembox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // itembox gets a dark border with specific items -consvar_t cv_multiitemicon = {"multiitemicon", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -static CV_PossibleValue_t huditemamount_cons_t[] = {{0, "Vanilla"}, {1, "Multiple"}, {2, "Always"},{0, NULL}}; -consvar_t cv_huditemamount = {"showitemamountnumber", "Vanilla", CV_SAVE, huditemamount_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; -consvar_t cv_newspeedometer = {"newspeedometer", "Default", CV_SAVE, speedo_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_battlespeedo = {"battlespeedo", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // toggle for showing the speedometer in battlemode - consvar_t cv_playerblendeffects = {"playerblendeffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // funn-E streeetch @@ -182,50 +104,6 @@ static void saltyhop_onchange(void) } } -// Colourized HUD -consvar_t cv_colorizedhud = {"colorizedhud", "Off", CV_SAVE|CV_CALL, CV_OnOff, SaturnHud_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_colorizeditembox = {"colorizeditembox", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -static CV_PossibleValue_t HudColor_cons_t[MAXSKINCOLORS+1]; -consvar_t cv_colorizedhudcolor = {"colorizedhudcolor", "Skin Color", CV_SAVE, HudColor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -// driftgauge stuffs -static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { - {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; -CV_PossibleValue_t driftgaugestyle_cons_t[NUMDGAUGESTUFF]; - -consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_driftgaugetrans = {"kartdriftgaugetransparency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_driftgaugestyle = {"kartdriftgaugestyle", "1", CV_SAVE, driftgaugestyle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -// nametags -static CV_PossibleValue_t nametagtrans_cons_t[] = { - {0, "Never"}, {1, "Far only"}, {2, "Dynamic"}, {3, "Always"}, {4, "HUD Trans."}, {0, NULL}}; -/*static CV_PossibleValue_t nametagscaling_cons_t[] = { - {0, "MIN"}, {320, "MAX"}, {0, NULL}};*/ -static CV_PossibleValue_t nametagdistance_cons_t[] = { - {0, "MIN"}, {640, "MAX"}, {0, NULL}}; -static CV_PossibleValue_t nametagmaxplayer_cons_t[] = { - {1, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; -static CV_PossibleValue_t nametagsize_cons_t[] = { - {0, "Off"}, {1, "Small"}, {2, "Minimal"}, {0, NULL}}; -static CV_PossibleValue_t nametagrestat_cons_t[] = { - {0, "Off"}, {1, "Restat"}, {2, "Always"}, {0, NULL}}; - -consvar_t cv_nametag = {"kartnametag", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagtrans = {"kartnametagtransparency", "Dynamic", CV_SAVE, nametagtrans_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagfacerank = {"kartnametagfacerank", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagrestat = {"kartnametagrestat", "Restat", CV_SAVE, nametagrestat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagdist = {"kartnametagdist", "320", CV_SAVE, nametagdistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagmaxplayers = {"kartnametagmaxplayers", "3", CV_SAVE, nametagmaxplayer_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagmaxlenght = {"kartnametagmaxlenght", "12", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; -//consvar_t cv_nametagscaling = {"nametagscaling", "160", CV_SAVE, nametagscaling_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showownnametag = {"kartnametagshowown", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_smallnametags = {"kartnametagsmall", "Off", CV_SAVE, nametagsize_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_nametagscore = {"kartnametagscore", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; - static boolean K_SpeedLinesShouldBlend(player_t *player); // SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H: @@ -238,9 +116,6 @@ static boolean K_SpeedLinesShouldBlend(player_t *player); // mapreset is set when enough players fill an empty server // nospectategrief is the players in-game needed to eliminate the person in last -#define XTRA3PSCALE 50135 //0.765 -#define XTRA3VSCALE 35344 //0.55 - //{ SRB2kart Color Code #define SKIN_RAMP_LENGTH 16 @@ -743,78 +618,6 @@ UINT8 K_GetKartColorByName(const char *name) return 0; } -UINT8 K_GetHudColor(void) -{ - if (cv_colorizedhud.value && cv_colorizedhudcolor.value) - return cv_colorizedhudcolor.value; - - return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : cv_playercolor.value); -} - -boolean K_UseColorHud(void) -{ - return (cv_colorizedhud.value && clr_hud); -} - -enum -{ - SPEEDO_VANILLA, - SPEEDO_EXTRA, - SPEEDO_ACHII, - SPEEDO_DIAL, - SPEEDO_PMETER, - SPEEDO_PMETERSMOL, - SPEEDO_EXTRA3, -}; - -static SINT8 K_GetSpeedometerStyle(void) -{ - if (cv_newspeedometer.value == 2 && xtra_speedo) - return SPEEDO_EXTRA; - else if (cv_newspeedometer.value == 3 && achi_speedo) - return SPEEDO_ACHII; - else if (cv_newspeedometer.value == 4 && dial_speedo) - return SPEEDO_DIAL; - else if (cv_newspeedometer.value == 5 && kartz_speedo) - return SPEEDO_PMETER; - else if (cv_newspeedometer.value == 6 && kartz_speedo_smol) - return SPEEDO_PMETERSMOL; - else if (cv_newspeedometer.value == 7 && xtra_speedo3) - return SPEEDO_EXTRA3; - else - return SPEEDO_VANILLA; -} - -static boolean K_UseColorSpeedo(int speedostyle) -{ - if (!K_UseColorHud()) - return false; - - switch (speedostyle) - { - case SPEEDO_EXTRA: - return xtra_speedo_clr; - case SPEEDO_ACHII: - return achi_speedo_clr; - case SPEEDO_DIAL: - return dial_speedo_clr; - case SPEEDO_EXTRA3: - return xtra_speedo_clr3; - default: - return false; - } -} - -static boolean K_IsHighResolution(void) -{ - return (vid.width >= 640 && vid.height >= 400); -} - -boolean K_UseHighResPortraits(void) -{ - return (cv_highresportrait.value && K_IsHighResolution()); -} - // returns the players skinnumber // accounts for localskins INT32 K_GetSkinNum(player_t *player) @@ -850,16 +653,6 @@ skin_t *K_GetPlayerSkin(player_t *player) return &K_GetSkinArray(player->skinlocal)[K_GetSkinNum(player)]; } -// returns the players faceprefix -// accounts for localskins -patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum) -{ - if (!player->skinlocal) - return (K_UseHighResPortraits() ? facewantprefix[skinnum] : facerankprefix[skinnum]); - else - return (K_UseHighResPortraits() ? localfacewantprefix[skinnum] : localfacerankprefix[skinnum]); -} - //} //{ SRB2kart Net Variables @@ -890,8 +683,6 @@ void K_RegisterServerKartStuff(void) CV_RegisterVar(&cv_quadorbinaut); CV_RegisterVar(&cv_dualjawz); - CV_RegisterVar(&cv_kartminimap); - CV_RegisterVar(&cv_kartcheck); CV_RegisterVar(&cv_kartinvinsfx); CV_RegisterVar(&cv_kartspeed); CV_RegisterVar(&cv_kartbumpers); @@ -900,7 +691,6 @@ void K_RegisterServerKartStuff(void) CV_RegisterVar(&cv_kartencore); CV_RegisterVar(&cv_kartvoterulechanges); CV_RegisterVar(&cv_kartgametypepreference); - CV_RegisterVar(&cv_kartspeedometer); CV_RegisterVar(&cv_kartvoices); CV_RegisterVar(&cv_karthitemdialog); CV_RegisterVar(&cv_karteliminatelast); @@ -921,44 +711,7 @@ void K_RegisterServerKartStuff(void) // Nothing needed for a dedicated server should be registered here. void K_RegisterClientKartStuff(void) { - HudColor_cons_t[0].value = 0; - HudColor_cons_t[0].strvalue = "Skin Color"; - - for (INT32 i = 1; i < MAXSKINCOLORS; i++) - { - HudColor_cons_t[i].value = i; - HudColor_cons_t[i].strvalue = KartColor_Names[i]; // SRB2kart - } - HudColor_cons_t[MAXSKINCOLORS].value = 0; - HudColor_cons_t[MAXSKINCOLORS].strvalue = NULL; - -#define REG_HUD_OFFSET_X(name)\ - CV_RegisterVar(&cv_##name##_xoffset); - -#define REG_HUD_OFFSET_Y(name)\ - CV_RegisterVar(&cv_##name##_yoffset); - -#define REG_HUD_OFFSET(name)\ - REG_HUD_OFFSET_X(name)\ - REG_HUD_OFFSET_Y(name) - - REG_HUD_OFFSET(item); // Item box - REG_HUD_OFFSET(time); // Time - REG_HUD_OFFSET(laps); // Number of laps - REG_HUD_OFFSET(dnft); // Countdown (did not finish timer) - REG_HUD_OFFSET(speed); // Speedometer - REG_HUD_OFFSET(posi); // Position in race - REG_HUD_OFFSET(wheel); // Position in race - REG_HUD_OFFSET(face); // Mini rankings - REG_HUD_OFFSET(stcd); // Starting countdown - REG_HUD_OFFSET_Y(chek); // Check gfx - REG_HUD_OFFSET(mini); // Minimap - REG_HUD_OFFSET(want); // Wanted - REG_HUD_OFFSET(stat); // Stats - -#undef REG_HUD_OFFSET -#undef REG_HUD_OFFSET_X -#undef REG_HUD_OFFSET_Y + K_RegisterKartHudStuff(); // Colored speedlines CV_RegisterVar(&cv_coloredspeedlines); @@ -971,61 +724,8 @@ void K_RegisterClientKartStuff(void) CV_RegisterVar(&cv_airsparks); - CV_RegisterVar(&cv_showstats); - CV_RegisterVar(&cv_showinput); - - CV_RegisterVar(&cv_posanim); - CV_RegisterVar(&cv_smallposnum); - - CV_RegisterVar(&cv_fancyroulette); - - CV_RegisterVar(&cv_showlaptimes); - CV_RegisterVar(&cv_newspeedometer); - - CV_RegisterVar(&cv_battlespeedo); - - CV_RegisterVar(&cv_minihead); - CV_RegisterVar(&cv_showminimapnames); - CV_RegisterVar(&cv_showminimapangle); - - CV_RegisterVar(&cv_showlapemblem); - - CV_RegisterVar(&cv_stagetitle); - CV_RegisterVar(&cv_playerblendeffects); - // Colourized HUD - CV_RegisterVar(&cv_colorizedhud); - CV_RegisterVar(&cv_colorizedhudcolor); - CV_RegisterVar(&cv_colorizeditembox); - - CV_RegisterVar(&cv_biglaps); - - CV_RegisterVar(&cv_darkitembox); - - CV_RegisterVar(&cv_multiitemicon); - CV_RegisterVar(&cv_huditemamount); - - CV_RegisterVar(&cv_highresportrait); - - CV_RegisterVar(&cv_nametag); - CV_RegisterVar(&cv_nametagtrans); - CV_RegisterVar(&cv_nametagfacerank); - CV_RegisterVar(&cv_nametagmaxplayers); - CV_RegisterVar(&cv_nametagmaxlenght); - //CV_RegisterVar(&cv_nametagscaling); - CV_RegisterVar(&cv_nametagdist); - CV_RegisterVar(&cv_showownnametag); - CV_RegisterVar(&cv_smallnametags); - CV_RegisterVar(&cv_nametagrestat); - CV_RegisterVar(&cv_nametagscore); - CV_RegisterVar(&cv_shownametagspectator); - - CV_RegisterVar(&cv_driftgauge); - CV_RegisterVar(&cv_driftgaugeofs); - CV_RegisterVar(&cv_driftgaugetrans); - CV_RegisterVar(&cv_driftgaugestyle); - CV_RegisterVar(&cv_saltyhop); CV_RegisterVar(&cv_saltyhopsfx); CV_RegisterVar(&cv_saltysquish); @@ -1037,8 +737,6 @@ void K_RegisterClientKartStuff(void) CV_RegisterVar(&cv_squishdance); CV_RegisterVar(&cv_squishdancespeed); - CV_RegisterVar(&cv_lessflicker); - CV_RegisterVar(&cv_mouseturn); } @@ -1206,7 +904,7 @@ static void K_KartGetItemResult(player_t *player, SINT8 getitem) \return void */ -static INT32 K_KartGetItemOdds(UINT8 pos, SINT8 item, fixed_t mashed, boolean spbrush) +INT32 K_KartGetItemOdds(UINT8 pos, SINT8 item, fixed_t mashed, boolean spbrush) { const INT32 distvar = (64*14); INT32 newodds; @@ -1365,7 +1063,7 @@ static INT32 K_KartGetItemOdds(UINT8 pos, SINT8 item, fixed_t mashed, boolean sp //{ SRB2kart Roulette Code - Distance Based, no waypoints -static INT32 K_FindUseodds(player_t *player, fixed_t mashed, INT32 pingame, INT32 bestbumper, boolean spbrush, boolean dontforcespb) +INT32 K_FindUseodds(player_t *player, fixed_t mashed, INT32 pingame, INT32 bestbumper, boolean spbrush, boolean dontforcespb) { const INT32 distvar = (64*14); INT32 i; @@ -7533,4456 +7231,3 @@ void K_UpdateSpectateGrief(void) } //} - -//{ SRB2kart HUD Code - -#define NUMPOSNUMS 10 -#define NUMPOSFRAMES 7 // White, three blues, three reds -#define NUMWINFRAMES 6 // Red, yellow, green, cyan, blue, purple - -//{ Patch Definitions - -// --Saturn patches-- -// dont leave those unitialized incase we missed a check somewhere - -// -Speedometers- - -// Smol speedo -static patch_t *skp_smallsticker = NULL; -static patch_t *skp_smallsticker3 = NULL; - -static patch_t *skp_speedpatches[5] = {NULL}; - -// Achii speedo -static patch_t *skp_smallstickerachi = NULL; -static patch_t *skp_speedpatchesachi[5] = {NULL}; -static patch_t *skp_smallstickerachiclr = NULL; -static patch_t *skp_speedpatchesachiclr[5] = {NULL}; - -// Kartz speedo -static patch_t *kp_kartzspeedo[25] = {NULL}; -static patch_t *kp_kartzspeedo_smol[25] = {NULL}; - -// dial speedometer -static patch_t *skp_rankfinish = NULL; -static patch_t *skp_dialbase[2] = {NULL}; -static patch_t *skp_speedpatchesdial[5] = {NULL}; -static patch_t *skp_dialnum[10] = {NULL}; -//static patch_t *skp_dialclr = NULL; -static patch_t *skp_dialbaseclr[2] = {NULL}; -static patch_t *skp_speedpatchesdialclr[5] = {NULL}; -static patch_t *skp_dialnumclr[10] = {NULL}; - -// -Colourized hud- - -static patch_t *kp_timestickerclr = NULL; -static patch_t *kp_timestickerwideclr = NULL; -static patch_t *kp_lapstickerclr = NULL; -static patch_t *kp_lapstickerbigclr = NULL; -static patch_t *kp_lapstickerbig2clr = NULL; -static patch_t *kp_lapstickerwideclr = NULL; -//static patch_t *kp_lapstickernarrowclr = NULL; -static patch_t *kp_bumperstickerclr = NULL; -static patch_t *kp_bumperstickerwideclr = NULL; -static patch_t *kp_karmastickerclr = NULL; -static patch_t *kp_timeoutstickerclr = NULL; -static patch_t *skp_smallstickerclr = NULL; -static patch_t *skp_smallstickerclr3 = NULL; -static patch_t *kp_itemmulstickerclr[2] = {NULL}; -static patch_t *kp_itembgclr[4] = {NULL}; - -// -Misc.- - -static patch_t *kp_lapstickerbig = NULL; -static patch_t *kp_lapstickerbig2 = NULL; - -static patch_t *nametagpic = NULL; -static patch_t *nametagline = NULL; -static patch_t *nametagspeed = NULL; -static patch_t *nametagweight = NULL; - -static patch_t *driftgauge = NULL; -static patch_t *driftgaugecolor = NULL; -static patch_t *driftgaugesmall = NULL; -static patch_t *driftgaugesmallcolor = NULL; - -static patch_t *kp_minimapdot = NULL; - -static patch_t *joybacking = NULL; -static patch_t *joyknob = NULL; -static patch_t *joyshadow = NULL; - -static patch_t *kp_multjawz = NULL; -static patch_t *kp_multsneaker[2] = {NULL}; -static patch_t *kp_multbanana[3] = {NULL}; - -static void K_LoadSaturnHUDGraphics(void) -{ - INT32 i; - char buffer[9]; - - if (found_extra_kart) - { - if (xtra_speedo) // smol speedometer - { - skp_smallsticker = (patch_t *)W_CachePatchName("SP_SMSTC", PU_HUDGFX); - skp_speedpatches[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatches[1] = (patch_t *)W_CachePatchName("SP_MKMH", PU_HUDGFX); - skp_speedpatches[2] = (patch_t *)W_CachePatchName("SP_MMPH", PU_HUDGFX); - skp_speedpatches[3] = (patch_t *)W_CachePatchName("SP_MFRAC", PU_HUDGFX); - skp_speedpatches[4] = (patch_t *)W_CachePatchName("SP_MPERC", PU_HUDGFX); - } - - if (achi_speedo) - { - skp_smallstickerachi = (patch_t *)W_CachePatchName("SP_AMSTC", PU_HUDGFX); - skp_speedpatchesachi[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesachi[1] = (patch_t *)W_CachePatchName("SP_AKMH", PU_HUDGFX); - skp_speedpatchesachi[2] = (patch_t *)W_CachePatchName("SP_AMPH", PU_HUDGFX); - skp_speedpatchesachi[3] = (patch_t *)W_CachePatchName("SP_AFRAC", PU_HUDGFX); - skp_speedpatchesachi[4] = (patch_t *)W_CachePatchName("SP_APERC", PU_HUDGFX); - } - - if (dial_speedo) - { - skp_rankfinish = (patch_t *)W_CachePatchName("RANKFIN", PU_HUDGFX); - skp_dialbase[0] = (patch_t *)W_CachePatchName("K_DSPBS1", PU_HUDGFX); - skp_dialbase[1] = (patch_t *)W_CachePatchName("K_DSPBS2", PU_HUDGFX); - - skp_speedpatchesdial[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesdial[1] = (patch_t *)W_CachePatchName("SP_DKMH", PU_HUDGFX); - skp_speedpatchesdial[2] = (patch_t *)W_CachePatchName("SP_DMPH", PU_HUDGFX); - skp_speedpatchesdial[3] = (patch_t *)W_CachePatchName("SP_DFRAC", PU_HUDGFX); - skp_speedpatchesdial[4] = (patch_t *)W_CachePatchName("SP_DPERC", PU_HUDGFX); - - sprintf(buffer, "K_DSPNMx"); - for (i = 0; i < 10; i++) - { - buffer[7] = '0'+(i%10); - skp_dialnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - } - - // KartZ speedo - if (kartz_speedo) - { - const char* patchNames[] = { - "K_KZSP1", "K_KZSP2", "K_KZSP3", "K_KZSP4", "K_KZSP5", - "K_KZSP6", "K_KZSP7", "K_KZSP8", "K_KZSP9", "K_KZSP10", - "K_KZSP11", "K_KZSP12", "K_KZSP13", "K_KZSP14", "K_KZSP15", - "K_KZSP16", "K_KZSP17", "K_KZSP18", "K_KZSP19", "K_KZSP20", - "K_KZSP21", "K_KZSP22", "K_KZSP23", "K_KZSP24", "K_KZSP25" - }; - - for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) - { - kp_kartzspeedo[m] = (patch_t *)W_CachePatchName(patchNames[m], PU_HUDGFX); - } - } - - if (kartz_speedo_smol) - { - const char* patchNames[] = { - "K_KZSS1", "K_KZSS2", "K_KZSS3", "K_KZSS4", "K_KZSS5", - "K_KZSS6", "K_KZSS7", "K_KZSS8", "K_KZSS9", "K_KZSS10", - "K_KZSS11", "K_KZSS12", "K_KZSS13", "K_KZSS14", "K_KZSS15", - "K_KZSS16", "K_KZSS17", "K_KZSS18", "K_KZSS19", "K_KZSS20", - "K_KZSS21", "K_KZSS22", "K_KZSS23", "K_KZSS24", "K_KZSS25" - }; - - for (size_t m = 0; m < sizeof(patchNames) / sizeof(patchNames[0]); ++m) - { - kp_kartzspeedo_smol[m] = (patch_t *)W_CachePatchName(patchNames[m], PU_HUDGFX); - } - } - - if (big_lap) - { - kp_lapstickerbig = (patch_t *)W_CachePatchName("K_STLAPB", PU_HUDGFX); - kp_lapstickerbig2 = (patch_t *)W_CachePatchName("K_STLA2B", PU_HUDGFX); - } - - // Nametags - if (nametaggfx) - { - nametagpic = (patch_t *)W_CachePatchName("NTLINE", PU_HUDGFX); - nametagline = (patch_t *)W_CachePatchName("NTLINEV", PU_HUDGFX); - nametagspeed = (patch_t *)W_CachePatchName("NTSP", PU_HUDGFX); - nametagweight = (patch_t *)W_CachePatchName("NTWH", PU_HUDGFX); - } - - if (driftgaugegfx) - { - driftgauge = (patch_t *)W_CachePatchName("K_DGAU", PU_HUDGFX); - driftgaugesmall = (patch_t *)W_CachePatchName("K_DGSU", PU_HUDGFX); - - if (driftgaugegfx_clr) - { - driftgaugecolor = (patch_t *)W_CachePatchName("K_DCAU", PU_HUDGFX); - driftgaugesmallcolor = (patch_t *)W_CachePatchName("K_DCSU", PU_HUDGFX); - } - } - - if (joystickicon) - { - joybacking = (patch_t *)W_CachePatchName("JOYBCK", PU_HUDGFX); - joyknob = (patch_t *)W_CachePatchName("JOYKNB", PU_HUDGFX); - joyshadow = (patch_t *)W_CachePatchName("JOYSHD", PU_HUDGFX); - } - - if (minidoticon) - { - kp_minimapdot = (patch_t *)W_CachePatchName("MMAPDOT", PU_HUDGFX); - } - - if (multiitem_icon) - { - kp_multsneaker[0] = (patch_t *)W_CachePatchName("K_ITSHO2", PU_HUDGFX); - kp_multsneaker[1] = (patch_t *)W_CachePatchName("K_ITSHO3", PU_HUDGFX); - kp_multbanana[0] = (patch_t *)W_CachePatchName("K_ITBAN2", PU_HUDGFX); - kp_multbanana[1] = (patch_t *)W_CachePatchName("K_ITBAN3", PU_HUDGFX); - kp_multbanana[2] = (patch_t *)W_CachePatchName("K_ITBAN4", PU_HUDGFX); - kp_multjawz = (patch_t *)W_CachePatchName("K_ITJAW2", PU_HUDGFX); - } - } - - if (found_extra2_kart) - { - if (xtra_speedo_clr) - { - skp_smallstickerclr = (patch_t *)W_CachePatchName("SC_SMSTC", PU_HUDGFX); - } - - if (xtra_speedo_clr3) - { - skp_smallstickerclr3 = (patch_t *)W_CachePatchName("SC_SM3TC", PU_HUDGFX); - } - - if (achi_speedo_clr) - { - skp_smallstickerachiclr = (patch_t *)W_CachePatchName("SC_AMSTC", PU_HUDGFX); - skp_speedpatchesachiclr[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesachiclr[1] = (patch_t *)W_CachePatchName("SC_AKMH", PU_HUDGFX); - skp_speedpatchesachiclr[2] = (patch_t *)W_CachePatchName("SC_AMPH", PU_HUDGFX); - skp_speedpatchesachiclr[3] = (patch_t *)W_CachePatchName("SC_AFRAC", PU_HUDGFX); - skp_speedpatchesachiclr[4] = (patch_t *)W_CachePatchName("SC_APERC", PU_HUDGFX); - } - - if (dial_speedo_clr) - { - skp_dialbaseclr[0] = (patch_t *)W_CachePatchName("K_DSPBC1", PU_HUDGFX); - skp_dialbaseclr[1] = (patch_t *)W_CachePatchName("K_DSPBC2", PU_HUDGFX); - - skp_speedpatchesdialclr[0] = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd - skp_speedpatchesdialclr[1] = (patch_t *)W_CachePatchName("SC_DKMH", PU_HUDGFX); - skp_speedpatchesdialclr[2] = (patch_t *)W_CachePatchName("SC_DMPH", PU_HUDGFX); - skp_speedpatchesdialclr[3] = (patch_t *)W_CachePatchName("SC_DFRAC", PU_HUDGFX); - skp_speedpatchesdialclr[4] = (patch_t *)W_CachePatchName("SC_DPERC", PU_HUDGFX); - - sprintf(buffer, "K_DSPNCx"); - for (i = 0; i < 10; i++) - { - buffer[7] = '0'+(i%10); - skp_dialnumclr[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - } - - if (big_lap_color) - { - kp_lapstickerbigclr = (patch_t *)W_CachePatchName("K_SCLAPB", PU_HUDGFX); - kp_lapstickerbig2clr = (patch_t *)W_CachePatchName("K_SCLA2B", PU_HUDGFX); - } - - // Colourized hud - if (clr_hud) - { - kp_timestickerclr = (patch_t *)W_CachePatchName("K_SCTIME", PU_HUDGFX); - kp_timestickerwideclr = (patch_t *)W_CachePatchName("K_SCTIMW", PU_HUDGFX); - kp_lapstickerclr = (patch_t *)W_CachePatchName("K_SCLAPS", PU_HUDGFX); - kp_lapstickerwideclr = (patch_t *)W_CachePatchName("K_SCLAPW", PU_HUDGFX); - kp_bumperstickerclr = (patch_t *)W_CachePatchName("K_SCBALN", PU_HUDGFX); - kp_bumperstickerwideclr = (patch_t *)W_CachePatchName("K_SCBALW", PU_HUDGFX); - kp_karmastickerclr = (patch_t *)W_CachePatchName("K_SCKARM", PU_HUDGFX); - kp_timeoutstickerclr = (patch_t *)W_CachePatchName("K_SCTOUT", PU_HUDGFX); - kp_itembgclr[0] = (patch_t *)W_CachePatchName("K_ITBC" , PU_HUDGFX); - kp_itembgclr[1] = (patch_t *)W_CachePatchName("K_ITBCD" , PU_HUDGFX); - kp_itembgclr[2] = (patch_t *)W_CachePatchName("K_ISBC" , PU_HUDGFX); - kp_itembgclr[3] = (patch_t *)W_CachePatchName("K_ISBCD" , PU_HUDGFX); - kp_itemmulstickerclr[1] = (patch_t *)W_CachePatchName("K_ISMULC", PU_HUDGFX); - kp_itemmulstickerclr[0] = (patch_t *)W_CachePatchName("K_ITMULC", PU_HUDGFX); - } - } - - if (found_extra3_kart) - { - if (xtra_speedo3) // 80x11 patch scaled to size - { - skp_smallsticker3 = (patch_t *)W_CachePatchName("SP_SM3TC", PU_HUDGFX); - } - } -} - -// -- Kart patches -- - -static patch_t *kp_nodraw; -static patch_t *kp_timesticker; -static patch_t *kp_timestickerwide; -static patch_t *kp_lapsticker; -static patch_t *kp_lapstickerwide; -//static patch_t *kp_lapstickernarrow; -static patch_t *kp_splitlapflag; -static patch_t *kp_bumpersticker; -static patch_t *kp_bumperstickerwide; -static patch_t *kp_karmasticker; -static patch_t *kp_splitkarmabomb; -static patch_t *kp_timeoutsticker; - -static patch_t *kp_startcountdown[16]; -static patch_t *kp_racefinish[6]; - -static patch_t *kp_positionnum[NUMPOSNUMS][NUMPOSFRAMES]; -static patch_t *kp_winnernum[NUMPOSFRAMES]; - -static patch_t *kp_facenum[MAXPLAYERS+1]; -static patch_t *kp_facehighlight[8]; - -static patch_t *kp_rankbumper; -static patch_t *kp_tinybumper[2]; -static patch_t *kp_ranknobumpers; - -static patch_t *kp_battlewin; -static patch_t *kp_battlecool; -static patch_t *kp_battlelose; -static patch_t *kp_battlewait; -static patch_t *kp_battleinfo; -static patch_t *kp_wanted; -static patch_t *kp_wantedsplit; -static patch_t *kp_wantedreticle; - -static patch_t *kp_itembg[4]; -static patch_t *kp_itemtimer[2]; -static patch_t *kp_itemmulsticker[2]; -static patch_t *kp_itemx; - -static patch_t *kp_sneaker[2]; -static patch_t *kp_rocketsneaker[2]; -static patch_t *kp_invincibility[13]; -static patch_t *kp_banana[2]; -static patch_t *kp_eggman[2]; -static patch_t *kp_orbinaut[5]; -static patch_t *kp_jawz[2]; -static patch_t *kp_mine[2]; -static patch_t *kp_ballhog[2]; -static patch_t *kp_selfpropelledbomb[2]; -static patch_t *kp_grow[2]; -static patch_t *kp_shrink[2]; -static patch_t *kp_thundershield[2]; -static patch_t *kp_hyudoro[2]; -static patch_t *kp_pogospring[2]; -static patch_t *kp_kitchensink[2]; -static patch_t *kp_sadface[2]; - -static patch_t *kp_check[6]; - -static patch_t *kp_eggnum[4]; - -static patch_t *kp_fpview[3]; -static patch_t *kp_inputwheel[5]; - -static patch_t *kp_challenger[25]; - -static patch_t *kp_lapanim_lap[7]; -static patch_t *kp_lapanim_final[11]; -static patch_t *kp_lapanim_number[10][3]; -static patch_t *kp_lapanim_emblem[2]; -static patch_t *kp_lapanim_hand[3]; - -static patch_t *kp_yougotem; - -void K_LoadKartHUDGraphics(void) -{ - INT32 i, j; - char buffer[9]; - - // Null Stuff - kp_nodraw = (patch_t *)W_CachePatchName("K_TRNULL", PU_HUDGFX); - - // Stickers - kp_timesticker = (patch_t *)W_CachePatchName("K_STTIME", PU_HUDGFX); - kp_timestickerwide = (patch_t *)W_CachePatchName("K_STTIMW", PU_HUDGFX); - kp_lapsticker = (patch_t *)W_CachePatchName("K_STLAPS", PU_HUDGFX); - kp_lapstickerwide = (patch_t *)W_CachePatchName("K_STLAPW", PU_HUDGFX); - //kp_lapstickernarrow = (patch_t *)W_CachePatchName("K_STLAPN", PU_HUDGFX); - kp_splitlapflag = (patch_t *)W_CachePatchName("K_SPTLAP", PU_HUDGFX); - kp_bumpersticker = (patch_t *)W_CachePatchName("K_STBALN", PU_HUDGFX); - kp_bumperstickerwide = (patch_t *)W_CachePatchName("K_STBALW", PU_HUDGFX); - kp_karmasticker = (patch_t *)W_CachePatchName("K_STKARM", PU_HUDGFX); - kp_splitkarmabomb = (patch_t *)W_CachePatchName("K_SPTKRM", PU_HUDGFX); - kp_timeoutsticker = (patch_t *)W_CachePatchName("K_STTOUT", PU_HUDGFX); - - // Starting countdown - kp_startcountdown[0] = (patch_t *)W_CachePatchName("K_CNT3A", PU_HUDGFX); - kp_startcountdown[1] = (patch_t *)W_CachePatchName("K_CNT2A", PU_HUDGFX); - kp_startcountdown[2] = (patch_t *)W_CachePatchName("K_CNT1A", PU_HUDGFX); - kp_startcountdown[3] = (patch_t *)W_CachePatchName("K_CNTGOA", PU_HUDGFX); - kp_startcountdown[4] = (patch_t *)W_CachePatchName("K_CNT3B", PU_HUDGFX); - kp_startcountdown[5] = (patch_t *)W_CachePatchName("K_CNT2B", PU_HUDGFX); - kp_startcountdown[6] = (patch_t *)W_CachePatchName("K_CNT1B", PU_HUDGFX); - kp_startcountdown[7] = (patch_t *)W_CachePatchName("K_CNTGOB", PU_HUDGFX); - - // Splitscreen - kp_startcountdown[8] = (patch_t *)W_CachePatchName("K_SMC3A", PU_HUDGFX); - kp_startcountdown[9] = (patch_t *)W_CachePatchName("K_SMC2A", PU_HUDGFX); - kp_startcountdown[10] = (patch_t *)W_CachePatchName("K_SMC1A", PU_HUDGFX); - kp_startcountdown[11] = (patch_t *)W_CachePatchName("K_SMCGOA", PU_HUDGFX); - kp_startcountdown[12] = (patch_t *)W_CachePatchName("K_SMC3B", PU_HUDGFX); - kp_startcountdown[13] = (patch_t *)W_CachePatchName("K_SMC2B", PU_HUDGFX); - kp_startcountdown[14] = (patch_t *)W_CachePatchName("K_SMC1B", PU_HUDGFX); - kp_startcountdown[15] = (patch_t *)W_CachePatchName("K_SMCGOB", PU_HUDGFX); - - // Finish - kp_racefinish[0] = (patch_t *)W_CachePatchName("K_FINA", PU_HUDGFX); - kp_racefinish[1] = (patch_t *)W_CachePatchName("K_FINB", PU_HUDGFX); - - // Splitscreen - kp_racefinish[2] = (patch_t *)W_CachePatchName("K_SMFINA", PU_HUDGFX); - kp_racefinish[3] = (patch_t *)W_CachePatchName("K_SMFINB", PU_HUDGFX); - - // 2P splitscreen - kp_racefinish[4] = (patch_t *)W_CachePatchName("K_2PFINA", PU_HUDGFX); - kp_racefinish[5] = (patch_t *)W_CachePatchName("K_2PFINB", PU_HUDGFX); - - // Position numbers - sprintf(buffer, "K_POSNxx"); - for (i = 0; i < NUMPOSNUMS; i++) - { - buffer[6] = '0'+i; - for (j = 0; j < NUMPOSFRAMES; j++) - { - buffer[7] = '0'+j; - kp_positionnum[i][j] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - } - - sprintf(buffer, "K_POSNWx"); - for (i = 0; i < NUMWINFRAMES; i++) - { - buffer[7] = '0'+i; - kp_winnernum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - sprintf(buffer, "OPPRNKxx"); - for (i = 0; i <= MAXPLAYERS; i++) - { - buffer[6] = '0'+(i/10); - buffer[7] = '0'+(i%10); - kp_facenum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - sprintf(buffer, "K_CHILIx"); - for (i = 0; i < 8; i++) - { - buffer[7] = '0'+(i+1); - kp_facehighlight[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - // Extra ranking icons - kp_rankbumper = (patch_t *)W_CachePatchName("K_BLNICO", PU_HUDGFX); - kp_tinybumper[0] = (patch_t *)W_CachePatchName("K_BLNA", PU_HUDGFX); - kp_tinybumper[1] = (patch_t *)W_CachePatchName("K_BLNB", PU_HUDGFX); - kp_ranknobumpers = (patch_t *)W_CachePatchName("K_NOBLNS", PU_HUDGFX); - - // Battle graphics - kp_battlewin = (patch_t *)W_CachePatchName("K_BWIN", PU_HUDGFX); - kp_battlecool = (patch_t *)W_CachePatchName("K_BCOOL", PU_HUDGFX); - kp_battlelose = (patch_t *)W_CachePatchName("K_BLOSE", PU_HUDGFX); - kp_battlewait = (patch_t *)W_CachePatchName("K_BWAIT", PU_HUDGFX); - kp_battleinfo = (patch_t *)W_CachePatchName("K_BINFO", PU_HUDGFX); - kp_wanted = (patch_t *)W_CachePatchName("K_WANTED", PU_HUDGFX); - kp_wantedsplit = (patch_t *)W_CachePatchName("4PWANTED", PU_HUDGFX); - kp_wantedreticle = (patch_t *)W_CachePatchName("MMAPWANT", PU_HUDGFX); - - // Kart Item Windows - kp_itembg[0] = (patch_t *)W_CachePatchName("K_ITBG", PU_HUDGFX); - kp_itembg[1] = (patch_t *)W_CachePatchName("K_ITBGD", PU_HUDGFX); - kp_itemtimer[0] = (patch_t *)W_CachePatchName("K_ITIMER", PU_HUDGFX); - kp_itemmulsticker[0] = (patch_t *)W_CachePatchName("K_ITMUL", PU_HUDGFX); - kp_itemx = (patch_t *)W_CachePatchName("K_ITX", PU_HUDGFX); - // Splitscreen - kp_itembg[2] = (patch_t *)W_CachePatchName("K_ISBG", PU_HUDGFX); - kp_itembg[3] = (patch_t *)W_CachePatchName("K_ISBGD", PU_HUDGFX); - kp_itemtimer[1] = (patch_t *)W_CachePatchName("K_ISIMER", PU_HUDGFX); - kp_itemmulsticker[1] = (patch_t *)W_CachePatchName("K_ISMUL", PU_HUDGFX); - - // Kart Items - kp_sneaker[0] = (patch_t *)W_CachePatchName("K_ITSHOE", PU_HUDGFX); - kp_rocketsneaker[0] = (patch_t *)W_CachePatchName("K_ITRSHE", PU_HUDGFX); - kp_banana[0] = (patch_t *)W_CachePatchName("K_ITBANA", PU_HUDGFX); - kp_eggman[0] = (patch_t *)W_CachePatchName("K_ITEGGM", PU_HUDGFX); - kp_jawz[0] = (patch_t *)W_CachePatchName("K_ITJAWZ", PU_HUDGFX); - kp_mine[0] = (patch_t *)W_CachePatchName("K_ITMINE", PU_HUDGFX); - kp_ballhog[0] = (patch_t *)W_CachePatchName("K_ITBHOG", PU_HUDGFX); - kp_selfpropelledbomb[0] = (patch_t *)W_CachePatchName("K_ITSPB", PU_HUDGFX); - kp_grow[0] = (patch_t *)W_CachePatchName("K_ITGROW", PU_HUDGFX); - kp_shrink[0] = (patch_t *)W_CachePatchName("K_ITSHRK", PU_HUDGFX); - kp_thundershield[0] = (patch_t *)W_CachePatchName("K_ITTHNS", PU_HUDGFX); - kp_hyudoro[0] = (patch_t *)W_CachePatchName("K_ITHYUD", PU_HUDGFX); - kp_pogospring[0] = (patch_t *)W_CachePatchName("K_ITPOGO", PU_HUDGFX); - kp_kitchensink[0] = (patch_t *)W_CachePatchName("K_ITSINK", PU_HUDGFX); - kp_sadface[0] = (patch_t *)W_CachePatchName("K_ITSAD", PU_HUDGFX); - // Splitscreen - kp_sneaker[1] = (patch_t *)W_CachePatchName("K_ISSHOE", PU_HUDGFX); - kp_rocketsneaker[1] = (patch_t *)W_CachePatchName("K_ISRSHE", PU_HUDGFX); - kp_banana[1] = (patch_t *)W_CachePatchName("K_ISBANA", PU_HUDGFX); - kp_eggman[1] = (patch_t *)W_CachePatchName("K_ISEGGM", PU_HUDGFX); - kp_orbinaut[4] = (patch_t *)W_CachePatchName("K_ISORBN", PU_HUDGFX); - kp_jawz[1] = (patch_t *)W_CachePatchName("K_ISJAWZ", PU_HUDGFX); - kp_mine[1] = (patch_t *)W_CachePatchName("K_ISMINE", PU_HUDGFX); - kp_ballhog[1] = (patch_t *)W_CachePatchName("K_ISBHOG", PU_HUDGFX); - kp_selfpropelledbomb[1] = (patch_t *)W_CachePatchName("K_ISSPB", PU_HUDGFX); - kp_grow[1] = (patch_t *)W_CachePatchName("K_ISGROW", PU_HUDGFX); - kp_shrink[1] = (patch_t *)W_CachePatchName("K_ISSHRK", PU_HUDGFX); - kp_thundershield[1] = (patch_t *)W_CachePatchName("K_ISTHNS", PU_HUDGFX); - kp_hyudoro[1] = (patch_t *)W_CachePatchName("K_ISHYUD", PU_HUDGFX); - kp_pogospring[1] = (patch_t *)W_CachePatchName("K_ISPOGO", PU_HUDGFX); - kp_kitchensink[1] = (patch_t *)W_CachePatchName("K_ISSINK", PU_HUDGFX); - kp_sadface[1] = (patch_t *)W_CachePatchName("K_ISSAD", PU_HUDGFX); - - sprintf(buffer, "K_ITINVx"); - for (i = 0; i < 7; i++) - { - buffer[7] = '1'+i; - kp_invincibility[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - sprintf(buffer, "K_ITORBx"); - for (i = 0; i < 4; i++) - { - buffer[7] = '1'+i; - kp_orbinaut[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - sprintf(buffer, "K_ISINVx"); - for (i = 0; i < 6; i++) - { - buffer[7] = '1'+i; - kp_invincibility[i+7] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - // CHECK indicators - sprintf(buffer, "K_CHECKx"); - for (i = 0; i < 6; i++) - { - buffer[7] = '1'+i; - kp_check[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - // Eggman warning numbers - sprintf(buffer, "K_EGGNx"); - for (i = 0; i < 4; i++) - { - buffer[6] = '0'+i; - kp_eggnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - // First person mode - kp_fpview[0] = (patch_t *)W_CachePatchName("VIEWA0", PU_HUDGFX); - kp_fpview[1] = (patch_t *)W_CachePatchName("VIEWB0D0", PU_HUDGFX); - kp_fpview[2] = (patch_t *)W_CachePatchName("VIEWC0E0", PU_HUDGFX); - - // Input UI Wheel - sprintf(buffer, "K_WHEELx"); - for (i = 0; i < 5; i++) - { - buffer[7] = '0'+i; - kp_inputwheel[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - // HERE COMES A NEW CHALLENGER - sprintf(buffer, "K_CHALxx"); - for (i = 0; i < 25; i++) - { - buffer[6] = '0'+((i+1)/10); - buffer[7] = '0'+((i+1)%10); - kp_challenger[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - // Lap start animation - sprintf(buffer, "K_LAP0x"); - for (i = 0; i < 7; i++) - { - buffer[6] = '0'+(i+1); - kp_lapanim_lap[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - sprintf(buffer, "K_LAPFxx"); - for (i = 0; i < 11; i++) - { - buffer[6] = '0'+((i+1)/10); - buffer[7] = '0'+((i+1)%10); - kp_lapanim_final[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - sprintf(buffer, "K_LAPNxx"); - for (i = 0; i < 10; i++) - { - buffer[6] = '0'+i; - for (j = 0; j < 3; j++) - { - buffer[7] = '0'+(j+1); - kp_lapanim_number[i][j] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - } - - sprintf(buffer, "K_LAPE0x"); - for (i = 0; i < 2; i++) - { - buffer[7] = '0'+(i+1); - kp_lapanim_emblem[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - sprintf(buffer, "K_LAPH0x"); - for (i = 0; i < 3; i++) - { - buffer[7] = '0'+(i+1); - kp_lapanim_hand[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); - } - - kp_yougotem = (patch_t *)W_CachePatchName("YOUGOTEM", PU_HUDGFX); - - if (found_extra_kart || found_extra2_kart || found_extra3_kart) - K_LoadSaturnHUDGraphics(); -} - -// For the item toggle menu -const char *K_GetItemPatch(UINT8 item, boolean tiny) -{ - switch (item) - { - case KITEM_SNEAKER: - case KRITEM_TRIPLESNEAKER: - return (tiny ? "K_ISSHOE" : "K_ITSHOE"); - case KITEM_ROCKETSNEAKER: - return (tiny ? "K_ISRSHE" : "K_ITRSHE"); - case KITEM_INVINCIBILITY: - return (tiny ? "K_ISINV1" : "K_ITINV1"); - case KITEM_BANANA: - case KRITEM_TRIPLEBANANA: - case KRITEM_TENFOLDBANANA: - return (tiny ? "K_ISBANA" : "K_ITBANA"); - case KITEM_EGGMAN: - return (tiny ? "K_ISEGGM" : "K_ITEGGM"); - case KITEM_ORBINAUT: - return (tiny ? "K_ISORBN" : "K_ITORB1"); - case KITEM_JAWZ: - case KRITEM_DUALJAWZ: - return (tiny ? "K_ISJAWZ" : "K_ITJAWZ"); - case KITEM_MINE: - return (tiny ? "K_ISMINE" : "K_ITMINE"); - case KITEM_BALLHOG: - return (tiny ? "K_ISBHOG" : "K_ITBHOG"); - case KITEM_SPB: - return (tiny ? "K_ISSPB" : "K_ITSPB"); - case KITEM_GROW: - return (tiny ? "K_ISGROW" : "K_ITGROW"); - case KITEM_SHRINK: - return (tiny ? "K_ISSHRK" : "K_ITSHRK"); - case KITEM_THUNDERSHIELD: - return (tiny ? "K_ISTHNS" : "K_ITTHNS"); - case KITEM_HYUDORO: - return (tiny ? "K_ISHYUD" : "K_ITHYUD"); - case KITEM_POGOSPRING: - return (tiny ? "K_ISPOGO" : "K_ITPOGO"); - case KITEM_KITCHENSINK: - return (tiny ? "K_ISSINK" : "K_ITSINK"); - case KRITEM_TRIPLEORBINAUT: - return (tiny ? "K_ISORBN" : "K_ITORB3"); - case KRITEM_QUADORBINAUT: - return (tiny ? "K_ISORBN" : "K_ITORB4"); - default: - return (tiny ? "K_ISSAD" : "K_ITSAD"); - } -} - -//} - -INT32 ITEM_X, ITEM_Y; // Item Window -INT32 TIME_X, TIME_Y; // Time Sticker -INT32 LAPS_X, LAPS_Y; // Lap Sticker -INT32 SPDM_X, SPDM_Y; // Speedometer -INT32 POSI_X, POSI_Y; // Position Number -INT32 FACE_X, FACE_Y; // Top-four Faces -INT32 STCD_X, STCD_Y; // Starting countdown -INT32 CHEK_Y; // CHECK graphic -INT32 MINI_X, MINI_Y; // Minimap -INT32 WANT_X, WANT_Y; // Battle WANTED poster - -// This is for the P2 and P4 side of splitscreen. Then we'll flip P1's and P2's to the bottom with V_SPLITSCREEN. -INT32 ITEM2_X, ITEM2_Y; -INT32 LAPS2_X, LAPS2_Y; -INT32 POSI2_X, POSI2_Y; - - -static void K_initKartHUD(void) -{ - /* - BASEVIDWIDTH = 320 - BASEVIDHEIGHT = 200 - - Item window graphic is 41 x 33 - - Time Sticker graphic is 116 x 11 - Time Font is a solid block of (8 x [12) x 14], equal to 96 x 14 - Therefore, timestamp is 116 x 14 altogether - - Lap Sticker is 80 x 11 - Lap flag is 22 x 20 - Lap Font is a solid block of (3 x [12) x 14], equal to 36 x 14 - Therefore, lapstamp is 80 x 20 altogether - - Position numbers are 43 x 53 - - Faces are 32 x 32 - Faces draw downscaled at 16 x 16 - Therefore, the allocated space for them is 16 x 67 altogether - - ---- - - ORIGINAL CZ64 SPLITSCREEN: - - Item window: - if (!splitscreen) { ICONX = 139; ICONY = 20; } - else { ICONX = BASEVIDWIDTH-315; ICONY = 60; } - - Time: 236, STRINGY( 12) - Lap: BASEVIDWIDTH-304, STRINGY(BASEVIDHEIGHT-189) - - */ - - // Single Screen (defaults) - // Item Window - ITEM_X = 5 + cv_item_xoffset.value; // 5 - ITEM_Y = 5 + cv_item_yoffset.value; // 5 - // Level Timer - TIME_X = BASEVIDWIDTH - 148 + cv_time_xoffset.value; // 172 - TIME_Y = 9 + cv_time_yoffset.value; // 9 - // Level Laps - LAPS_X = 9 + cv_laps_xoffset.value; // 9 - LAPS_Y = BASEVIDHEIGHT - 29 + cv_laps_yoffset.value; // 171 - // Speedometer - SPDM_X = 9 + cv_speed_xoffset.value; // 9 - SPDM_Y = BASEVIDHEIGHT - 45 + cv_speed_yoffset.value; // 155 - // Position Number - POSI_X = BASEVIDWIDTH - 9 + cv_posi_xoffset.value; // 268 - POSI_Y = BASEVIDHEIGHT - 9 + cv_posi_yoffset.value; // 138 - // Top-Four Faces - FACE_X = 9 + cv_face_xoffset.value; // 9 - FACE_Y = 92 + cv_face_yoffset.value; // 92 - // Starting countdown - STCD_X = BASEVIDWIDTH/2 + cv_stcd_xoffset.value; // 9 - STCD_Y = BASEVIDHEIGHT/2 + cv_stcd_yoffset.value; // 92 - // CHECK graphic - CHEK_Y = BASEVIDHEIGHT + cv_chek_yoffset.value; // 200 - // Minimap - MINI_X = BASEVIDWIDTH - 50 + cv_mini_xoffset.value; // 270 - MINI_Y = (BASEVIDHEIGHT/2)-16 + cv_mini_yoffset.value; // 84 - // Battle WANTED poster - WANT_X = BASEVIDWIDTH - 55 + cv_want_xoffset.value; // 270 - WANT_Y = BASEVIDHEIGHT- 71 + cv_want_yoffset.value; // 176 - - if (splitscreen) // Splitscreen - { - ITEM_X = 5; - ITEM_Y = 3; - - LAPS_Y = (BASEVIDHEIGHT/2)-24; - - POSI_Y = (BASEVIDHEIGHT/2)- 2; - - STCD_Y = BASEVIDHEIGHT/4; - - MINI_Y = (BASEVIDHEIGHT/2); - - if (splitscreen > 1) // 3P/4P Small Splitscreen - { - // 1P (top left) - ITEM_X = -9; - ITEM_Y = -8; - - LAPS_X = 3; - LAPS_Y = (BASEVIDHEIGHT/2)-13; - - POSI_X = 24; - POSI_Y = (BASEVIDHEIGHT/2)- 16; - - // 2P (top right) - ITEM2_X = BASEVIDWIDTH-39; - ITEM2_Y = -8; - - LAPS2_X = BASEVIDWIDTH-3; - LAPS2_Y = (BASEVIDHEIGHT/2)-13; - - POSI2_X = BASEVIDWIDTH -4; - POSI2_Y = (BASEVIDHEIGHT/2)- 16; - - // Reminder that 3P and 4P are just 1P and 2P splitscreen'd to the bottom. - - STCD_X = BASEVIDWIDTH/4; - - MINI_X = (3*BASEVIDWIDTH/4); - MINI_Y = (3*BASEVIDHEIGHT/4); - - if (splitscreen > 2) // 4P-only - { - MINI_X = (BASEVIDWIDTH/2); - MINI_Y = (BASEVIDHEIGHT/2); - } - } - } - - if (timeinmap > 113 || forceshowhud) - hudtrans = cv_translucenthud.value; - else if (timeinmap > 105) - hudtrans = ((((INT32)timeinmap) - 105)*cv_translucenthud.value)/(113-105); - else - hudtrans = 0; - - // K_GetScreenCoords needs the right view* variables - R_SetViewContext(stplyrnum); - R_InterpolateView(rendertimefrac_unpaused, !cv_uncappedhud.value); -} - -INT32 K_calcSplitFlags(INT32 snapflags) -{ - INT32 splitflags = 0; - - if (splitscreen == 0) - return snapflags; - - if (stplyrnum != 0) - { - if (splitscreen == 1 && stplyrnum == 1) - { - splitflags |= V_SPLITSCREEN; - } - else if (splitscreen > 1) - { - if (stplyrnum == 2 || (splitscreen == 3 && stplyrnum == 3)) - splitflags |= V_SPLITSCREEN; - if (stplyrnum == 1 || (splitscreen == 3 && stplyrnum == 3)) - splitflags |= V_HORZSCREEN; - } - } - - if (splitflags & V_SPLITSCREEN) - snapflags &= ~V_SNAPTOTOP; - else - snapflags &= ~V_SNAPTOBOTTOM; - - if (splitscreen > 1) - { - if (splitflags & V_HORZSCREEN) - snapflags &= ~V_SNAPTOLEFT; - else - snapflags &= ~V_SNAPTORIGHT; - } - - return (splitflags|snapflags); -} - -void K_getItemBoxDrawinfo(drawinfo_t *out) -{ - INT32 fx, fy, fflags; - - // pain and suffering defined below - if (splitscreen < 2) // don't change shit for THIS splitscreen. - { - fx = ITEM_X; - fy = ITEM_Y; - fflags = K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTOLEFT); - } - else // now we're having a fun game. - { - if (!(stplyrnum & 1)) // If we are P1 or P3... - { - fx = ITEM_X; - fy = ITEM_Y; - fflags = V_SNAPTOLEFT|(stplyrnum & 2 ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P3 to the bottom. - } - else // else, that means we're P2 or P4. - { - fx = ITEM2_X; - fy = ITEM2_Y; - fflags = V_SNAPTORIGHT|(stplyrnum & 2 ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P4 to the bottom - } - } - - out->x = fx; - out->y = fy; - out->flags = fflags; -} - -void K_getLapsDrawinfo(drawinfo_t *out) -{ - INT32 fx, fy, fflags; - - // pain and suffering defined below - if (splitscreen < 2) // don't change shit for THIS splitscreen. - { - fx = LAPS_X; - fy = LAPS_Y; - fflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); - } - else - { - if (!(stplyrnum & 1)) // If we are P1 or P3... - { - fx = LAPS_X; - fy = LAPS_Y; - fflags = V_SNAPTOLEFT|(stplyrnum & 2 ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. - } - else // else, that means we're P2 or P4. - { - fx = LAPS2_X; - fy = LAPS2_Y; - fflags = V_SNAPTORIGHT|(stplyrnum & 2 ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom - } - } - - out->x = fx; - out->y = fy; - out->flags = fflags; -} - -void K_getMinimapDrawinfo(drawinfo_t *out) -{ - INT32 fx = MINI_X, fy = MINI_Y, fflags = (splitscreen == 3 ? 0 : V_SNAPTORIGHT); // flags should only be 0 when it's centered (4p split) - - out->x = fx; - out->y = fy; - out->flags = fflags; -} - -INT32 K_getMinimapTrans(void) -{ - INT32 minimaptrans = cv_kartminimap.value; - - if (!minimaptrans) - return -1; - - if (forceshowhud) - return (10-minimaptrans)<kartstuff[k_bumper] ? -5 : -8) : 0); - - // Customizations c: - if (!splitscreen) - { - x += 18 + cv_stat_xoffset.value + spdxoffset; - y += cv_stat_yoffset.value + spdoffset; - } - else if (splitscreen == 1) // I tried my best, but this is still mess :/ < :Blobcatpats: c: - { - x -= 10; - y -= 40; - y += spdoffset; - - // If we are in 2-player splitscreen, for player 1 we move hud to up and remove snapping - // to bottom - if (splitnum == 0) - { - y /= 2; - flags = V_SNAPTOLEFT; - } - else - { - // Can move it down a bit - y += 45; - } - } - else - { - if (splitnum == 0 || splitnum == 2) // If we are P1 or P3... - { - // ye i just align it to position number lol - x = POSI_X + 19; - y = POSI_Y - 6; - flags = V_SNAPTOLEFT|((splitnum == 2) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. - } - else // else, that means we're P2 or P4. - { - x = POSI2_X - 75; - y = POSI2_Y - 6; - flags = V_SNAPTORIGHT|((splitnum == 3) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom - } - } - - flags |= V_HUDTRANS; - - skin_t *fakeskin; - fakeskin = K_GetPlayerSkin(stplyr); - - if (!splitscreen) - { - // Skin name - if (K_IsHighResolution()) // V_DrawSmallString becomes a mess at low resolutions lel - { - V_DrawSmallString(x+20, y+12, flags|V_ALLOWLOWERCASE|V_SkinColorToHighlightcolor(stplyr->skincolor), fakeskin->realname); - } - else - { - V_DrawThinString(x+20, y+7, flags|V_ALLOWLOWERCASE|V_SkinColorToHighlightcolor(stplyr->skincolor), fakeskin->realname); - } - - // Icon and stats - if (K_UseHighResPortraits()) - V_DrawSmallMappedPatch(x, y, flags, R_GetSkinFaceWant(stplyr), R_GetLocalTranslationColormap(fakeskin, fakeskin, stplyr->skincolor, GTC_CACHE, stplyr->skinlocal)); - else - V_DrawMappedPatch(x, y, flags, R_GetSkinFaceRank(stplyr), R_GetLocalTranslationColormap(fakeskin, fakeskin, stplyr->skincolor, GTC_CACHE, stplyr->skinlocal)); - - V_DrawMappedPatch(x-3, y-2, flags, kp_facenum[min(9, max(1, stplyr->kartspeed))], R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BLUEBERRY, GTC_CACHE)); - V_DrawMappedPatch(x+10, y+10, flags, kp_facenum[min(9, max(1, stplyr->kartweight))], R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BURGUNDY, GTC_CACHE)); - } - else - { - // In splitscreen, just draw a string with stats - V_DrawString(x, y+10, flags, va("\x84%dS \x87%dW", stplyr->kartspeed, stplyr->kartweight)); - } -} - -static void K_drawKartItem(void) -{ - // ITEM_X = BASEVIDWIDTH-50; // 270 - // ITEM_Y = 24; // 24 - - // Why write V_DrawScaledPatch calls over and over when they're all the same? - // Set to 'no item' just in case. - const UINT8 offset = ((splitscreen > 1) ? 1 : 0); - patch_t *localpatch = kp_nodraw; - patch_t *localbg; - boolean dark = false; - - patch_t *localinv = ((offset) ? kp_invincibility[((leveltime % (6*3)) / 3) + 7] : kp_invincibility[(leveltime % (7*3)) / 3]); - INT32 fx = 0, fy = 0, fflags = 0; // final coords for hud and flags... - INT32 numberdisplaymin = cv_huditemamount.value == 2 ? 1 : 2; // No longer a constant so other things can modify this value - INT32 itembar = 0; - INT32 maxl = 0; // itembar's normal highest value - const INT32 barlength = (splitscreen > 1 ? 12 : 26); - UINT8 localcolor = SKINCOLOR_NONE; - SINT8 colormode = TC_RAINBOW; - UINT8 *colmap = NULL; - UINT8 *colormap = NULL; - - if (stplyr->kartstuff[k_itemroulette]) - { - localcolor = K_GetHudColor(); - - switch((stplyr->kartstuff[k_itemroulette] % (14*3)) / 3) - { - // Each case is handled in threes, to give three frames of in-game time to see the item on the roulette - case 0: // Sneaker - localpatch = kp_sneaker[offset]; - //localcolor = SKINCOLOR_RASPBERRY; - break; - case 1: // Banana - localpatch = kp_banana[offset]; - //localcolor = SKINCOLOR_YELLOW; - break; - case 2: // Orbinaut - localpatch = kp_orbinaut[3+offset]; - //localcolor = SKINCOLOR_STEEL; - break; - case 3: // Mine - localpatch = kp_mine[offset]; - //localcolor = SKINCOLOR_JET; - break; - case 4: // Grow - localpatch = kp_grow[offset]; - //localcolor = SKINCOLOR_TEAL; - break; - case 5: // Hyudoro - localpatch = kp_hyudoro[offset]; - //localcolor = SKINCOLOR_STEEL; - break; - case 6: // Rocket Sneaker - localpatch = kp_rocketsneaker[offset]; - //localcolor = SKINCOLOR_TANGERINE; - break; - case 7: // Jawz - localpatch = kp_jawz[offset]; - //localcolor = SKINCOLOR_JAWZ; - break; - case 8: // Self-Propelled Bomb - localpatch = kp_selfpropelledbomb[offset]; - //localcolor = SKINCOLOR_JET; - break; - case 9: // Shrink - localpatch = kp_shrink[offset]; - //localcolor = SKINCOLOR_ORANGE; - break; - case 10: // Invincibility - localpatch = localinv; - //localcolor = SKINCOLOR_GREY; - break; - case 11: // Eggman Monitor - localpatch = kp_eggman[offset]; - //localcolor = SKINCOLOR_ROSE; - break; - case 12: // Ballhog - localpatch = kp_ballhog[offset]; - //localcolor = SKINCOLOR_LILAC; - break; - case 13: // Thunder Shield - localpatch = kp_thundershield[offset]; - //localcolor = SKINCOLOR_CYAN; - break; - /*case 14: // Pogo Spring - localpatch = kp_pogospring[offset]; - localcolor = SKINCOLOR_TANGERINE; - break; - case 15: // Kitchen Sink - localpatch = kp_kitchensink[offset]; - localcolor = SKINCOLOR_STEEL; - break;*/ - default: - break; - } - } - else - { - // I'm doing this a little weird and drawing mostly in reverse order - // The only actual reason is to make sneakers line up this way in the code below - // This shouldn't have any actual baring over how it functions - // Hyudoro is first, because we're drawing it on top of the player's current item - if (stplyr->kartstuff[k_stolentimer] > 0) - { - if (leveltime & 2) - localpatch = kp_hyudoro[offset]; - else - localpatch = kp_nodraw; - } - else if ((stplyr->kartstuff[k_stealingtimer] > 0) && (leveltime & 2)) - { - localpatch = kp_hyudoro[offset]; - } - else if (stplyr->kartstuff[k_eggmanexplode] > 1) - { - if (leveltime & 1) - localpatch = kp_eggman[offset]; - else - localpatch = kp_nodraw; - } - else if (stplyr->kartstuff[k_rocketsneakertimer] > 1) - { - itembar = stplyr->kartstuff[k_rocketsneakertimer]; - maxl = (itemtime*3) - barlength; - - if (leveltime & 1) - localpatch = kp_rocketsneaker[offset]; - else - localpatch = kp_nodraw; - } - else if (stplyr->kartstuff[k_growshrinktimer] > 0) - { - if (stplyr->kartstuff[k_growcancel] > 0) - { - itembar = stplyr->kartstuff[k_growcancel]; - maxl = 26; - } - - if (leveltime & 1) - localpatch = kp_grow[offset]; - else - localpatch = kp_nodraw; - } - else if (stplyr->kartstuff[k_sadtimer] > 0) - { - if (leveltime & 2) - localpatch = kp_sadface[offset]; - else - localpatch = kp_nodraw; - } - else - { - if (stplyr->kartstuff[k_itemamount] <= 0) - return; - - const boolean usemultiicon = (multiitem_icon && cv_multiitemicon.value && !offset); - - switch (stplyr->kartstuff[k_itemtype]) - { - case KITEM_SNEAKER: - if (usemultiicon) - { - if (!cv_huditemamount.value) - numberdisplaymin = 4; - switch(stplyr->kartstuff[k_itemamount]) - { - case 1: - localpatch = kp_sneaker[offset]; - break; - case 2: - localpatch = kp_multsneaker[0]; - break; - default: - localpatch = kp_multsneaker[1]; - break; - } - } - else - { - localpatch = kp_sneaker[offset]; - } - break; - case KITEM_ROCKETSNEAKER: - localpatch = kp_rocketsneaker[offset]; - break; - case KITEM_INVINCIBILITY: - localpatch = localinv; - dark = true; - break; - case KITEM_BANANA: - if (usemultiicon) - { - if (!cv_huditemamount.value) - numberdisplaymin = 4; - switch(stplyr->kartstuff[k_itemamount]) - { - case 1: - localpatch = kp_banana[offset]; - break; - case 2: - localpatch = kp_multbanana[0]; - break; - case 3: - localpatch = kp_multbanana[1]; - break; - default: - localpatch = kp_multbanana[2]; - break; - } - } - else - { - localpatch = kp_banana[offset]; - } - break; - case KITEM_EGGMAN: - localpatch = kp_eggman[offset]; - break; - case KITEM_ORBINAUT: - if (!cv_huditemamount.value) - numberdisplaymin = offset ? 2 : 5; - localpatch = kp_orbinaut[(offset ? 4 : min(stplyr->kartstuff[k_itemamount]-1, 3))]; - break; - case KITEM_JAWZ: - if (usemultiicon) - { - if (!cv_huditemamount.value) - numberdisplaymin = 3; - localpatch = ((stplyr->kartstuff[k_itemamount] == 1) ? kp_jawz[offset] : kp_multjawz); - } - else - { - localpatch = kp_jawz[offset]; - } - break; - case KITEM_MINE: - localpatch = kp_mine[offset]; - break; - case KITEM_BALLHOG: - localpatch = kp_ballhog[offset]; - break; - case KITEM_SPB: - localpatch = kp_selfpropelledbomb[offset]; - dark = true; - break; - case KITEM_GROW: - localpatch = kp_grow[offset]; - break; - case KITEM_SHRINK: - localpatch = kp_shrink[offset]; - break; - case KITEM_THUNDERSHIELD: - localpatch = kp_thundershield[offset]; - dark = true; - break; - case KITEM_HYUDORO: - localpatch = kp_hyudoro[offset]; - break; - case KITEM_POGOSPRING: - localpatch = kp_pogospring[offset]; - break; - case KITEM_KITCHENSINK: - localpatch = kp_kitchensink[offset]; - break; - case KITEM_SAD: - localpatch = kp_sadface[offset]; - break; - default: - return; - } - - if (stplyr->kartstuff[k_itemheld] && !(leveltime & 1)) - localpatch = kp_nodraw; - } - - if (stplyr->kartstuff[k_itemblink] && (leveltime & 1)) - { - colormode = TC_BLINK; - - switch (stplyr->kartstuff[k_itemblinkmode]) - { - case 2: - localcolor = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))); - break; - case 1: - localcolor = SKINCOLOR_RED; - break; - default: - localcolor = SKINCOLOR_WHITE; - break; - } - } - } - - localbg = K_getItemBoxPatch((boolean)offset, dark); - drawinfo_t info; - K_getItemBoxDrawinfo(&info); - fx = info.x; - fy = info.y; - fflags = info.flags; - - boolean flipamount = splitscreen > 1 && stplyrnum & 1; // Used for 3P/4P splitscreen to flip item amount stuff - - if (K_UseColorHud()) - colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - - V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, localbg, cv_colorizeditembox.value ? colormap : NULL); - - fixed_t rfy = fy<kartstuff[k_itemroulette] && !stplyr->deadtimer) - { - fixed_t frac = R_GetHudUncap(); - UINT8 fancystep = (offset ? 6 : 10); - fixed_t fancyoffset = (stplyr->kartstuff[k_itemroulette] % 3)-1; - - if (fancyoffset != 0) - { - fancyflags &= ~V_HUDTRANS; - fancyflags |=V_HUDTRANSHALF; - } - - rfy += (fancystep * fancyoffset * FRACUNIT) + FixedMul(fancystep*FRACUNIT, frac) - fancystep/2*FRACUNIT; - } - - if (localcolor != SKINCOLOR_NONE) - colmap = R_GetTranslationColormap(colormode, localcolor, GTC_CACHE); - - // Then, the numbers: - if (stplyr->kartstuff[k_itemamount] >= numberdisplaymin && !stplyr->kartstuff[k_itemroulette]) - { - localbg = K_getItemMulPatch((boolean)offset); - - V_DrawMappedPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), localbg, colormap); // flip this graphic for p2 and p4 in split and shift it. - V_DrawFixedPatch(fx<kartstuff[k_itemamount])); - } - else - { - V_DrawScaledPatch(fx+28, fy+41, V_HUDTRANS|fflags, kp_itemx); - V_DrawKartString(fx+38, fy+36, V_HUDTRANS|fflags, va("%d", stplyr->kartstuff[k_itemamount])); - } - } - else - V_DrawFixedPatch(fx< 2) - { - V_DrawFill(fx+x+length, fy+y+1, 1, height, 12|fflags); // the right one - if (height == 2) - V_DrawFill(fx+x+2, fy+y+2, length-2, 1, 8|fflags); // the dulled underside - V_DrawFill(fx+x+2, fy+y+1, length-2, 1, 120|fflags); // the shine - } - } - - // Quick Eggman numbers - if (stplyr->kartstuff[k_eggmanexplode] > 1 /*&& stplyr->kartstuff[k_eggmanexplode] <= 3*TICRATE*/) - V_DrawScaledPatch(fx+17, fy+13-offset, V_HUDTRANS|fflags, kp_eggnum[min(3, G_TicsToSeconds(stplyr->kartstuff[k_eggmanexplode]))]); -} - -void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UINT8 mode) -{ - // TIME_X = BASEVIDWIDTH-124; // 196 - // TIME_Y = 6; // 6 - - INT32 splitflags = 0; - - if (!mode) - { - splitflags = V_HUDTRANS|K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTORIGHT); - if (cv_timelimit.value && timelimitintics > 0) - { - if (drawtime >= timelimitintics) - drawtime = 0; - else - drawtime = timelimitintics - drawtime; - } - } - - if (K_UseColorHud()) // Colourized hud - { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawMappedPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwideclr : kp_timestickerwideclr), colormap); - } - else - V_DrawScaledPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwide : kp_timestickerwide)); - - TX += 33; - - if (drawtime == UINT32_MAX) - ; - else if (mode && !drawtime) - { - V_DrawKartString(TX, TY+3, splitflags, va("--'--\"--")); - } - else - { - tic_t worktime = drawtime/(60*TICRATE); - - if (cv_timelimit.value && cv_overtime.value && G_BattleGametype() && !players[consoleplayer].exiting && (leveltime > (timelimitintics + starttime + TICRATE/2))) // i hate this so much - { - V_DrawKartString(TX, TY+3, splitflags, va("OVERTIME")); - } - else if (worktime < 100) - { - // minutes time 00 __ __ - V_DrawKartString(TX, TY+3, splitflags, va("%d", worktime/10)); - V_DrawKartString(TX+12, TY+3, splitflags, va("%d", worktime%10)); - - // apostrophe location _'__ __ - V_DrawKartString(TX+24, TY+3, splitflags, va("'")); - - worktime = (drawtime/TICRATE % 60); - - // seconds time _ 00 __ - V_DrawKartString(TX+36, TY+3, splitflags, va("%d", worktime/10)); - V_DrawKartString(TX+48, TY+3, splitflags, va("%d", worktime%10)); - - // quotation mark location _ __"__ - V_DrawKartString(TX+60, TY+3, splitflags, va("\"")); - - worktime = G_TicsToCentiseconds(drawtime); - - // tics _ __ 00 - V_DrawKartString(TX+72, TY+3, splitflags, va("%d", worktime/10)); - V_DrawKartString(TX+84, TY+3, splitflags, va("%d", worktime%10)); - } - else if ((drawtime/TICRATE) & 1) - V_DrawKartString(TX, TY+3, splitflags, va("99'59\"99")); - } - - if (emblemmap && (modeattacking || (mode == 1)) && !demo.playback) // emblem time! - { - INT32 workx = TX + 96, worky = TY+18; - SINT8 curemb = 0; - patch_t *emblempic[3] = {NULL, NULL, NULL}; - UINT8 *emblemcol[3] = {NULL, NULL, NULL}; - - emblem_t *emblem = M_GetLevelEmblems(emblemmap); - while (emblem) - { - char targettext[9]; - - switch (emblem->type) - { - case ET_TIME: - { - static boolean canplaysound = true; - tic_t timetoreach = emblem->var; - - if (emblem->collected) - { - emblempic[curemb] = W_CachePatchName(M_GetEmblemPatch(emblem), PU_PATCH); - emblemcol[curemb] = R_GetTranslationColormap(TC_DEFAULT, M_GetEmblemColor(emblem), GTC_CACHE); - if (++curemb == 3) - break; - goto bademblem; - } - - snprintf(targettext, 9, "%i'%02i\"%02i", - G_TicsToMinutes(timetoreach, false), - G_TicsToSeconds(timetoreach), - G_TicsToCentiseconds(timetoreach)); - - if (!mode) - { - if (stplyr->realtime > timetoreach) - { - splitflags = (splitflags &~ V_HUDTRANS)|V_HUDTRANSHALF; - if (canplaysound) - { - S_StartSound(NULL, sfx_s3k72); //sfx_s26d); -- you STOLE fizzy lifting drinks - canplaysound = false; - } - } - else if (!canplaysound) - canplaysound = true; - } - - targettext[8] = 0; - } - break; - default: - goto bademblem; - } - - V_DrawRightAlignedString(workx, worky, splitflags, targettext); - workx -= 67; - V_DrawSmallScaledPatch(workx + 4, worky, splitflags, W_CachePatchName("NEEDIT", PU_PATCH)); - - break; - - bademblem: - emblem = M_GetLevelEmblems(-1); - } - - if (!mode) - splitflags = (splitflags &~ V_HUDTRANSHALF)|V_HUDTRANS; - - while (curemb--) - { - workx -= 12; - V_DrawSmallMappedPatch(workx + 4, worky, splitflags, emblempic[curemb], emblemcol[curemb]); - } - } -} - -static void K_DrawKartPositionNum(INT32 num) -{ - // POSI_X = BASEVIDWIDTH - 51; // 269 - // POSI_Y = BASEVIDHEIGHT- 64; // 136 - - const boolean wheeloffs = (cv_showinput.value && cv_posi_xoffset.value == 0 && cv_posi_yoffset.value == 0 && cv_wheel_xoffset.value == 0 && cv_wheel_yoffset.value == 0); - const boolean win = (stplyr->exiting && num == 1); - INT32 W = kp_positionnum[0][0]->width; - fixed_t scale = FRACUNIT; - patch_t *localpatch = kp_positionnum[0][0]; - INT32 fx = 0, fy = 0, fflags = 0; - const INT32 xoffs = wheeloffs ? -48 : 0; - boolean flipdraw = false; // flip the order we draw it in for MORE splitscreen bs. fun. - boolean flipvdraw = false; // used only for 2p splitscreen so overtaking doesn't make 1P's position fly off the screen. - boolean overtake = false; - - if ((cv_posanim.value && stplyr->kartstuff[k_positiondelay]) || stplyr->exiting) - { - scale *= 2; - overtake = true; // this is used for splitscreen stuff in conjunction with flipdraw. - } - - if (splitscreen || cv_smallposnum.value || wheeloffs) - { - scale /= 2; - } - - W = FixedMul(W<>FRACBITS; - - // pain and suffering defined below - if (!splitscreen) - { - fx = POSI_X + xoffs; - fy = BASEVIDHEIGHT - 8 + cv_posi_yoffset.value; - fflags = V_SNAPTOBOTTOM|V_SNAPTORIGHT; - } - else if (splitscreen == 1) // for this splitscreen, we'll use case by case because it's a bit different. - { - fx = POSI_X; - if (stplyrnum == 0) // for player 1: display this at the top right, above the minimap. - { - fy = 30 + cv_posi_yoffset.value; - fflags = V_SNAPTOTOP|V_SNAPTORIGHT; - if (overtake) - flipvdraw = true; // make sure overtaking doesn't explode us - } - else // if we're not p1, that means we're p2. display this at the bottom right, below the minimap. - { - fy = BASEVIDHEIGHT - 8 + cv_posi_yoffset.value; - fflags = V_SNAPTOBOTTOM|V_SNAPTORIGHT; - } - } - else - { - if (!(stplyrnum & 1)) // If we are P1 or P3... - { - fx = POSI_X; - fy = POSI_Y; - fflags = V_SNAPTOLEFT|((stplyrnum == 2) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. - flipdraw = true; - if (num && num >= 10) - fx += W; // this seems dumb, but we need to do this in order for positions above 10 going off screen. - } - else // else, that means we're P2 or P4. - { - fx = POSI2_X; - fy = POSI2_Y; - fflags = V_SNAPTORIGHT|((stplyrnum == 3) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom - } - } - - // Special case for 0 - if (!num) - { - V_DrawFixedPatch(fx<= 0); // This function does not draw negative numbers - - // Draw the number - while (num) - { - if (win) // 1st place winner? You get rainbows!! - { - localpatch = kp_winnernum[(leveltime % (NUMWINFRAMES*3)) / 3]; - } - else if (stplyr->laps+1 >= cv_numlaps.value || stplyr->exiting) // Check for the final lap, or won - { - // Alternate frame every three frames - switch (leveltime % 9) - { - case 1: case 2: case 3: - if (K_IsPlayerLosing(stplyr)) - localpatch = kp_positionnum[num % 10][4]; - else - localpatch = kp_positionnum[num % 10][1]; - break; - case 4: case 5: case 6: - if (K_IsPlayerLosing(stplyr)) - localpatch = kp_positionnum[num % 10][5]; - else - localpatch = kp_positionnum[num % 10][2]; - break; - case 7: case 8: case 9: - if (K_IsPlayerLosing(stplyr)) - localpatch = kp_positionnum[num % 10][6]; - else - localpatch = kp_positionnum[num % 10][3]; - break; - default: - localpatch = kp_positionnum[num % 10][0]; - break; - } - } - else - { - localpatch = kp_positionnum[num % 10][0]; - } - - V_DrawFixedPatch((fx<width*scale/2) : 0), (fy<height*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL); - // ^ if we overtake as p1 or p3 in splitscren, we shift it so that it doesn't go off screen. - // ^ if we overtake as p1 in 2p splits, shift vertically so that this doesn't happen either. - - fx -= W; - num /= 10; - } -} - -static boolean K_drawKartPositionFaces(void) -{ - // FACE_X = 15; // 15 - // FACE_Y = 72; // 72 - - INT32 Y = FACE_Y+9; // +9 to offset where it's being drawn if there are more than one - INT32 i, j, ranklines, strank = -1; - boolean completed[MAXPLAYERS]; - INT32 rankplayer[MAXPLAYERS]; - INT32 bumperx, numplayersingame = 0; - UINT8 *colormap; - - ranklines = 0; - memset(completed, 0, sizeof (completed)); - memset(rankplayer, 0, sizeof (rankplayer)); - - for (i = 0; i < MAXPLAYERS; i++) - { - rankplayer[i] = -1; - - if (!playeringame[i] || players[i].spectator || !players[i].mo) - continue; - - numplayersingame++; - } - - if (numplayersingame <= 1) - return true; - - if (!LUA_HudEnabled(hud_minirankings)) - return false; // Don't proceed but still return true for free play above if HUD is disabled. - - for (j = 0; j < numplayersingame; j++) - { - UINT8 lowestposition = MAXPLAYERS+1; - for (i = 0; i < MAXPLAYERS; i++) - { - if (completed[i] || !playeringame[i] || players[i].spectator || !players[i].mo) - continue; - - if (players[i].kartstuff[k_position] >= lowestposition) - continue; - - rankplayer[ranklines] = i; - lowestposition = players[i].kartstuff[k_position]; - } - - i = rankplayer[ranklines]; - - completed[i] = true; - - if (players+i == stplyr) - strank = ranklines; - - ranklines++; - } - - if (ranklines < 5) - Y -= (9*ranklines); - else - Y -= (9*5); - - if (G_BattleGametype() || strank <= 2) // too close to the top, or playing battle, or a spectator? would have had (strank == -1) called out, but already caught by (strank <= 2) - { - i = 0; - if (ranklines > 5) // could be both... - ranklines = 5; - } - else if (strank+3 > ranklines) // too close to the bottom? - { - i = ranklines - 5; - if (i < 0) - i = 0; - } - else - { - i = strank-2; - ranklines = strank+3; - } - - for (; i < ranklines; i++) - { - player_t *player; - player = &players[rankplayer[i]]; - - if (!playeringame[rankplayer[i]]) - continue; - if (player->spectator) - continue; - if (!player->mo) - continue; - - const UINT8 mocolor = player->mo->color; - - bumperx = FACE_X+19; - - if (mocolor) - { - colormap = R_GetTranslationColormap(player->skin, mocolor, GTC_CACHE); - if (player->mo->colorized) - colormap = R_GetTranslationColormap(TC_RAINBOW, mocolor, GTC_CACHE); - - if (K_UseHighResPortraits()) - V_DrawSmallMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, R_GetSkinFaceWant(player), colormap); - else - V_DrawMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, R_GetSkinFaceRank(player), colormap); - - if (LUA_HudEnabled(hud_battlebumpers)) - { - if (G_BattleGametype() && player->kartstuff[k_bumper] > 0) - { - V_DrawMappedPatch(bumperx-2, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[0], colormap); - for (j = 1; j < player->kartstuff[k_bumper]; j++) - { - bumperx += 5; - V_DrawMappedPatch(bumperx, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_tinybumper[1], colormap); - } - } - } // A new level of stupidity: checking if lua is enabled to close a bracket. :Fascinating: - } - - if (i == strank) - V_DrawScaledPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, kp_facehighlight[(leveltime / 4) % 8]); - - if (G_BattleGametype() && player->kartstuff[k_bumper] <= 0) - V_DrawScaledPatch(FACE_X-4, Y-3, V_HUDTRANS|V_SNAPTOLEFT, kp_ranknobumpers); - else - { - INT32 pos = player->kartstuff[k_position]; - if (pos < 0 || pos > MAXPLAYERS) - pos = 0; - // Draws the little number over the face - V_DrawScaledPatch(FACE_X-5, Y+10, V_HUDTRANS|V_SNAPTOLEFT, kp_facenum[pos]); - } - - Y += 18; - } - - return false; -} - -// -// HU_DrawTabRankings -- moved here to take advantage of kart stuff! -// -void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 hilicol) -{ - INT32 i, rightoffset = 240; - const UINT8 *colormap; - const INT32 dupadjust = cv_betainterscreen.value ? 314 : (vid.width/vid.dupx), duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; - - boolean (*_isHighlightedPlayer)(const player_t *) = (demo.playback ? P_IsDisplayPlayer : P_IsLocalPlayer); - - //this function is designed for 9 or less score lines only - //I_Assert(scorelines <= 9); -- not today bitch, kart fixed it up - - V_DrawFill(1-duptweak, 26, dupadjust-2, 1, 0); // Draw a horizontal line because it looks nice! - if (scorelines > 8) - { - V_DrawFill(160, 26, 1, 147, 0); // Draw a vertical line to separate the two sides. - V_DrawFill(1-duptweak, 173, dupadjust-2, 1, 0); // And a horizontal line near the bottom. - rightoffset = (BASEVIDWIDTH/2) - 4 - x; - } - - for (i = 0; i < scorelines; i++) - { - char strtime[MAXPLAYERNAME+1]; - const UINT8 pnum = tab[i].num; - player_t *player = &players[pnum]; - - if (player->spectator || !player->mo) - continue; //ignore them. - - const boolean whiteplayer = _isHighlightedPlayer(player); - const INT32 philicol = (whiteplayer ? V_SkinColorToHighlightcolor(player->skincolor) : 0); - - if ((netgame && pnum != serverplayer) || (cv_mindelay.value && P_IsLocalPlayer(player))) - { - HU_drawPlayerPing(x + ((i < 8) ? -17 : rightoffset + 11), y-4, pnum, 0); - } - - STRBUFCPY(strtime, tab[i].name); - - if (scorelines > 8) - V_DrawThinString(x + 20, y, philicol|V_ALLOWLOWERCASE|V_6WIDTHSPACE, strtime); - else - V_DrawString(x + 20, y, philicol|V_ALLOWLOWERCASE, strtime); - - if (player->mo->color) - { - if (player->mo->colorized) - colormap = R_GetTranslationColormap(TC_RAINBOW, player->mo->color, GTC_CACHE); - else - colormap = R_GetTranslationColormap(player->skin, player->mo->color, GTC_CACHE); - - if (K_UseHighResPortraits()) - V_DrawSmallMappedPatch(x, y-4, 0, R_GetSkinFaceWant(player), colormap); - else - V_DrawMappedPatch(x, y-4, 0, R_GetSkinFaceRank(player), colormap); - - /*if (G_BattleGametype() && player->kartstuff[k_bumper] > 0) -- not enough space for this - { - INT32 bumperx = x+19; - V_DrawMappedPatch(bumperx-2, y-4, 0, kp_tinybumper[0], colormap); - for (j = 1; j < player->kartstuff[k_bumper]; j++) - { - bumperx += 5; - V_DrawMappedPatch(bumperx, y-4, 0, kp_tinybumper[1], colormap); - } - }*/ - } - - if (whiteplayer) - V_DrawScaledPatch(x, y-4, 0, kp_facehighlight[(leveltime / 4) % 8]); - - if (G_BattleGametype() && player->kartstuff[k_bumper] <= 0) - V_DrawScaledPatch(x-4, y-7, 0, kp_ranknobumpers); - else - { - INT32 pos = player->kartstuff[k_position]; - if (pos < 0 || pos > MAXPLAYERS) - pos = 0; - // Draws the little number over the face - V_DrawScaledPatch(x-5, y+6, 0, kp_facenum[pos]); - } - - if (G_RaceGametype()) - { -#define timestring(time) va("%i'%02i\"%02i", G_TicsToMinutes(time, true), G_TicsToSeconds(time), G_TicsToCentiseconds(time)) - if (scorelines > 8) - { - if (player->exiting) - V_DrawRightAlignedThinString(x+rightoffset, y-1, hilicol|V_6WIDTHSPACE, timestring(player->realtime)); - else if (player->pflags & PF_TIMEOVER) - V_DrawRightAlignedThinString(x+rightoffset, y-1, V_6WIDTHSPACE, "NO CONTEST."); - else if (circuitmap) - V_DrawRightAlignedThinString(x+rightoffset, y-1, V_6WIDTHSPACE, va("Lap %d", tab[i].count)); - } - else - { - if (player->exiting) - V_DrawRightAlignedString(x+rightoffset, y, hilicol, timestring(player->realtime)); - else if (player->pflags & PF_TIMEOVER) - V_DrawRightAlignedThinString(x+rightoffset, y-1, 0, "NO CONTEST."); - else if (circuitmap) - V_DrawRightAlignedString(x+rightoffset, y, 0, va("Lap %d", tab[i].count)); - } -#undef timestring - } - else - V_DrawRightAlignedString(x+rightoffset, y, 0, va("%u", tab[i].count)); - - y += 18; - if (i == 7) - { - y = 33; - x = (BASEVIDWIDTH/2) + 4; - } - } -} - -static boolean K_BigLap(void) -{ - return (cv_biglaps.value && (cv_numlaps.value > 9) && (K_UseColorHud() ? big_lap_color : big_lap) && (!stplyr->exiting)); -} - -static void K_drawKartLaps(void) -{ - const INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); - INT32 fx = 0, fy = 0, fflags = 0; // stuff for 3p / 4p splitscreen. - const boolean flipstring = splitscreen > 1 && stplyrnum & 1; // used for 3p or 4p - INT32 stringw = 0; // used with the above - const char *laps; - - drawinfo_t info; - K_getLapsDrawinfo(&info); - fx = info.x; - fy = info.y; - fflags = info.flags; - - laps = (stplyr->exiting ? "FIN" : va("%d/%d", stplyr->laps+1, cv_numlaps.value)); - - // draw stuff as god intended. - if (splitscreen > 1) - { - if (flipstring) - { - stringw = V_StringWidth(laps, 0); - - V_DrawScaledPatch(fx-stringw-13, fy, V_HUDTRANS|fflags, kp_splitlapflag); - V_DrawRightAlignedString(fx, fy+1, V_HUDTRANS|fflags, laps); - } - else // draw stuff NORMALLY. - { - V_DrawScaledPatch(fx, fy, V_HUDTRANS|fflags, kp_splitlapflag); - V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, laps); - } - } - else - { - if (K_UseColorHud()) // Colourized hud - { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - patch_t *biglapclr = (K_BigLap() ? ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2clr : kp_lapstickerbigclr) : kp_lapstickerclr); - V_DrawMappedPatch(fx, fy, V_HUDTRANS|splitflags, biglapclr, colormap); - } - else - { - patch_t *biglap = (K_BigLap() ? ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2 : kp_lapstickerbig) : kp_lapsticker); - V_DrawScaledPatch(fx, fy, V_HUDTRANS|splitflags, biglap); - } - - V_DrawKartString(fx+33, fy+3, V_HUDTRANS|splitflags, laps); - } -} - -#ifdef ROTSPRITE - -#define DIALSPDDIV 97090 // 1.48148; converts 200 to 135 -#define MPHDIV 68283 // 1.04192; converts 141 to 135 - -static void K_DrawDialNum(INT32 x, INT32 y, boolean colorized, INT32 flags, INT32 num, INT32 digits, const UINT8 *colormap) -{ - INT32 w; - - if (colorized) - w = skp_dialnumclr[0]->width; - else - w = skp_dialnum[0]->width; - - if (flags & V_NOSCALESTART) - w *= vid.dupx; - - if (num < 0) - num = -num; - - // draw the number - do - { - x -= (w); - - if (colorized) - V_DrawFixedPatch(x << FRACBITS, y << FRACBITS, FRACUNIT, flags, skp_dialnumclr[num % 10], colormap); - else - V_DrawFixedPatch(x << FRACBITS, y << FRACBITS, FRACUNIT, flags, skp_dialnum[num % 10], colormap); - - num /= 10; - } while (--digits); -} - -static void K_DrawDialLaps(INT32 x, INT32 y, INT32 num, INT32 total, INT32 flags) -{ - INT32 fx; - fx = x + ((num < 10) ? 0 : 6); - V_DrawRankNum(fx, y, flags, num, (num < 10) ? 1 : 2, NULL); - V_DrawScaledPatch(fx + 2, y, flags, frameslash); - V_DrawRankNum(fx + 13 + ((total < 10) ? 0 : 6), y, flags, total, (total < 10) ? 1 : 2, NULL); -} - -static void K_DrawDialSpeedometer(fixed_t speed, - fixed_t divisor, - INT32 splitflags, - boolean battlemode, - boolean infoactive, - boolean colorized) -{ - const UINT8* colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - - INT32 rot = 0; - const UINT8 infoidx = (infoactive) ? 1 : 0; - patch_t* dialpatch; - - const angle_t speedangle = - FixedAngle(((min(135 * FRACUNIT, FixedDiv(speed, divisor)) - (45 * FRACUNIT)))); - - rot = R_GetRollAngle(speedangle); - - if (rot) - { - dialpatch = W_CachePatchNameRotated("K_DSDIAL", rot, PU_PATCH); - } - else - { - dialpatch = W_CachePatchName("K_DSDIAL", PU_PATCH); - } - - if (colorized) // Colourized hud - { - V_DrawMappedPatch( - SPDM_X, SPDM_Y - 9, (V_HUDTRANS | splitflags), skp_dialbaseclr[infoidx], colormap); - V_DrawMappedPatch(SPDM_X, - SPDM_Y + 30, - V_HUDTRANS | splitflags, - skp_speedpatchesdialclr[cv_kartspeedometer.value], - colormap); - } - else - { - V_DrawScaledPatch(SPDM_X, SPDM_Y - 9, (V_HUDTRANS | splitflags), skp_dialbase[infoidx]); - V_DrawScaledPatch(SPDM_X, - SPDM_Y + 30, - V_HUDTRANS | splitflags, - skp_speedpatchesdial[cv_kartspeedometer.value]); - } - - K_DrawDialNum(SPDM_X + 10, - SPDM_Y + 25, - colorized, - V_HUDTRANS | splitflags, - speed / FRACUNIT, - 3, - colormap); - - // gotta center the dial manually - V_DrawMappedPatch(SPDM_X - 19, SPDM_Y + 15, (V_HUDTRANS | splitflags), (dialpatch), colormap); - - if (!infoactive) - { - // no need to draw info if we're not supposed to - return; - } - - // draw the info - if (battlemode) - { - if (stplyr->kartstuff[k_bumper] <= 0) - { - V_DrawMappedPatch( - SPDM_X + 28, SPDM_Y + 27, V_HUDTRANS | splitflags, kp_splitkarmabomb, colormap); - K_DrawDialLaps(SPDM_X + 46, - SPDM_Y + 29, - stplyr->kartstuff[k_comebackpoints], - 2, - V_HUDTRANS | splitflags); - } - else // the above doesn't need to account for weird stuff since the max amount of karma - // necessary is always 2 ^^^^ - { - V_DrawMappedPatch( - SPDM_X + 28, SPDM_Y + 27, V_HUDTRANS | splitflags, kp_rankbumper, colormap); - K_DrawDialLaps(SPDM_X + 46, - SPDM_Y + 29, - stplyr->kartstuff[k_bumper], - cv_kartbumpers.value, - V_HUDTRANS | splitflags); - } - } - else - { - V_DrawScaledPatch(SPDM_X + 28, SPDM_Y + 27, V_HUDTRANS | splitflags, kp_splitlapflag); - - if (stplyr->exiting) - V_DrawScaledPatch(SPDM_X + 39, SPDM_Y + 29, V_HUDTRANS | splitflags, skp_rankfinish); - else - K_DrawDialLaps(SPDM_X + 46, - SPDM_Y + 29, - stplyr->laps + 1, - cv_numlaps.value, - V_HUDTRANS | splitflags); - } -} - -#endif - -static void K_drawKartSpeedometer(void) -{ - // why? - if (cv_kartspeedometer.value == 0) - return; - - // index 0 is the raw value, index 1 is the converted value - fixed_t convSpeed[2] = {0,0}; -#ifdef ROTSPRITE - fixed_t dial_divisor = DIALSPDDIV; -#endif - - INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); - - // man. - const UINT8 speedostyle = K_GetSpeedometerStyle(); - - switch (cv_kartspeedometer.value) - { - case 1: - convSpeed[0] = FixedDiv(FixedMul(stplyr->speed, 142371), mapobjectscale); // 2.172409058 - convSpeed[1] = convSpeed[0] / FRACUNIT; - break; - case 2: - convSpeed[0] = FixedDiv(FixedMul(stplyr->speed, 88465), mapobjectscale); // 1.349868774 - convSpeed[1] = convSpeed[0] / FRACUNIT; -#ifdef ROTSPRITE - dial_divisor = MPHDIV; -#endif - break; - case 3: - convSpeed[0] = FixedDiv(stplyr->speed, mapobjectscale); - convSpeed[1] = convSpeed[0] / FRACUNIT; -#ifdef ROTSPRITE - dial_divisor = MPHDIV; -#endif - break; - case 4: - if (stplyr->mo) - { - convSpeed[0] = (FixedDiv(stplyr->speed, FixedMul(K_GetKartSpeed(stplyr, false), ORIG_FRICTION))*100); - convSpeed[1] = convSpeed[0] >> FRACBITS; - } - break; - default: - break; - } - - if (speedostyle == SPEEDO_VANILLA) - { - const char *metric = ""; - - switch (cv_kartspeedometer.value) - { - case 1: - metric = va("%3d km/h", convSpeed[1]); - break; - case 2: - metric = va("%3d mph", convSpeed[1]); - break; - case 3: - metric = va("%3d fu/t", convSpeed[1]); - break; - case 4: - // if extra.kart is found, use its included % symbol - if (!xtra_speedo) - metric = va("%4d P", convSpeed[1]); - else - metric = va("%4d %%", convSpeed[1]); - break; - default: - break; - } - - V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, metric); - } - else if (speedostyle == SPEEDO_EXTRA) // why bother if we dont? - { - if (K_UseColorSpeedo(SPEEDO_EXTRA)) //Colourized hud - { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawMappedPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallstickerclr, colormap); - } - else - V_DrawScaledPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallsticker); - - V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed[1], 3, NULL); - V_DrawScaledPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatches[cv_kartspeedometer.value]); - } - else if (speedostyle == SPEEDO_ACHII) // why bother if we dont? - { - if (K_UseColorSpeedo(SPEEDO_ACHII)) //Colourized hud - { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawMappedPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallstickerachiclr, colormap); - V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed[1], 3, NULL); - V_DrawMappedPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatchesachiclr[cv_kartspeedometer.value], colormap); - } - else - { - V_DrawScaledPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallstickerachi); - V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed[1], 3, NULL); - V_DrawScaledPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatchesachi[cv_kartspeedometer.value]); - } - } -#ifdef ROTSPRITE - else if (speedostyle == SPEEDO_DIAL) // why bother if we dont? - { - K_DrawDialSpeedometer(convSpeed[0], - dial_divisor, - splitflags, - (boolean)(G_BattleGametype()), - (LUA_HudEnabled(hud_gametypeinfo)), - (K_UseColorSpeedo(SPEEDO_DIAL))); - } -#endif - else if (speedostyle == SPEEDO_EXTRA3) // why bother if we dont? - { - if (K_UseColorSpeedo(SPEEDO_EXTRA3)) //Colourized hud - { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawStretchyFixedPatch((SPDM_X-1)<speed, mapobjectscale)/FRACUNIT; - - for (INT32 i = 0; i < 22; ++i) - { - if (fuspeed < speedIntervals[i]) - { - spdpatch = i; - break; - } - } - - if (((fuspeed < 57 && fuspeed > 54) || (fuspeed < 60 && fuspeed > 56) || (fuspeed > 59)) && (leveltime & 4)) - spdpatch = 24; - else if (((fuspeed < 57 && fuspeed > 54) || (fuspeed < 60 && fuspeed > 56) || (fuspeed > 59)) && !(leveltime & 4)) - spdpatch = 23; - - V_DrawScaledPatch(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, (speedostyle == SPEEDO_PMETER) ? kp_kartzspeedo[spdpatch] : kp_kartzspeedo_smol[spdpatch]); - } -} - -#ifdef ROTSPRITE -#undef DIALSPDDIV -#undef MPHDIV -#endif - -static void K_drawKartBumpersOrKarma(void) -{ - const UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - INT32 fx, fy, fflags; - const boolean flipstring = splitscreen > 1 && stplyrnum & 1; // same as laps, used for splitscreen - INT32 stringw = 0; // used with the above - const char *bumpval = ""; - - drawinfo_t info; - K_getLapsDrawinfo(&info); - fx = info.x; - fy = info.y; - fflags = info.flags; - - if (cv_battlespeedo.value && !splitscreen) - { - const UINT8 speedostyle = K_GetSpeedometerStyle(); - - if ((speedostyle == SPEEDO_EXTRA) || (speedostyle == SPEEDO_ACHII) || (speedostyle == SPEEDO_EXTRA3)) - fy += 5; - else - fy += 7; - } - - if (splitscreen > 1) - { - if (stplyr->kartstuff[k_bumper] <= 0) - { - bumpval = va("%d/2", stplyr->kartstuff[k_comebackpoints]); - - if (flipstring) - fx -= 37; - V_DrawMappedPatch(fx, fy-1, V_HUDTRANS|fflags, kp_splitkarmabomb, colormap); - V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, bumpval); - } - else // the above doesn't need to account for weird stuff since the max amount of karma necessary is always 2 ^^^^ - { - bumpval = va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value); - - if (flipstring) // for p2 and p4, assume we can have more than 10 bumpers. It's retarded but who knows. - { - stringw = V_StringWidth(bumpval, 0); - - V_DrawMappedPatch(fx-stringw-13, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); - V_DrawRightAlignedString(fx, fy+1, V_HUDTRANS|fflags, bumpval); - } - else // draw bumpers normally. - { - V_DrawMappedPatch(fx, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); - V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, bumpval); - } - } - } - else - { - patch_t *patch; - - if (stplyr->kartstuff[k_bumper] <= 0) - { - patch = (K_UseColorHud() ? kp_karmastickerclr : kp_karmasticker); - bumpval = va("%d/2", stplyr->kartstuff[k_comebackpoints]); - } - else - { - if (stplyr->kartstuff[k_bumper] > 9 && cv_kartbumpers.value > 9) - patch = (K_UseColorHud() ? kp_bumperstickerwideclr : kp_bumperstickerwide); - else - patch = (K_UseColorHud() ? kp_bumperstickerclr : kp_bumpersticker); - - bumpval = va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value); - } - - V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, patch, colormap); - V_DrawKartString(fx+47, fy+3, V_HUDTRANS|fflags, bumpval); - } -} - -#define lerp(from, to) cv_uncappedhud.value ? from + FixedMul(rendertimefrac, to - from) : to - -// converts mobj coordinates into screen coordinates -// NOTE: use with V_NOSCALESTART! -// Code updated in Lua by GenericHeroGuy for libSG -// Badly ported to C by NepDisk and acutally made to work and fixed by Indev!(Thanks so much!) -// Badly uncapped in C by GenericHeroGuy -// original code by Lat' -static boolean K_GetScreenCoords(vector2_t *vec, player_t *player, mobj_t *target, fixed_t hofs, boolean dontclip) -{ - fixed_t y, x; - fixed_t targx, targy, targz; - - fixed_t dist; - fixed_t distfact; - fixed_t offset; - - fixed_t yres, xres; - fixed_t fov; - - // this should never happen but its also kart so ¯\_(ツ)_/¯ - if (!player || P_MobjWasRemoved(target)) - return false; - - targx = lerp(target->old_x, target->x); - targy = lerp(target->old_y, target->y); - targz = lerp(target->old_z, target->z); - - // X coordinate - // get difference between camangle and angle towards target - x = (INT32)viewangle - (INT32)R_PointToAngle(targx, targy); - - distfact = FINECOSINE((x>>ANGLETOFINESHIFT) & FINEMASK); - if (!distfact) distfact = 1; - - if (encoremode) - x = -x; - if (x < (fixed_t)ANGLE_270 || x > (fixed_t)ANGLE_90) - return false; - - xres = vid.width<<(FRACBITS-1); - yres = vid.height<<(FRACBITS-1); - fov = FixedDiv(xres, FINETANGENT(((FixedAngle(cv_fov.value/2)+ANGLE_90)>>ANGLETOFINESHIFT) & 4095)); - - // flipping - const boolean targflip = target->eflags & MFE_VERTICALFLIP; - const boolean srcflip = player->pflags & PF_FLIPCAM && player->mo->eflags & MFE_VERTICALFLIP; - - // Y coordinate - // getting the angle difference here is a bit more involved... - // start by getting the height difference between the camera and target - y = viewz - targz - (targflip ? ((target->height * 2) / 3) : 0); // for some reason needs to be divided by "1.5" idk - - if (hofs) - y = y - (targflip ? -hofs : hofs); - - // then get the distance between camera and target - dist = R_PointToDist(targx, targy); - -#ifdef HWRENDER - // NOW we can get the angle differnce - if (rendermode == render_opengl && !cv_glshearing.value) - { - angle_t yang = R_PointToAngle2(0, 0, dist, y); // not perspective - x = FixedMul(x, FINECOSINE((yang>>ANGLETOFINESHIFT) & FINEMASK)); // perspective - y = -aimingangle - FixedDiv(yang, distfact); - - if (y < (fixed_t)ANGLE_270 || y > (fixed_t)ANGLE_90) // clip points behind the camera - return false; - if (splitscreen == 1) // multiply by 1.25 for 2P splitscreen - y = y + (y/4) ; - if (srcflip) // flipcam - y = -y; - - y = FixedMul(FINETANGENT((((angle_t)(-y)+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), fov) + yres; // project the angle to get our final Y coordinate - } - else -#endif - { - const fixed_t fovratio = FixedDiv(90*FRACUNIT, 180*FRACUNIT - FixedMul(cv_fov.value, 4*FRACUNIT/3)-FRACUNIT*-30); - - y = FixedDiv(y, FixedMul(dist, distfact)); - if (srcflip) - y = -y; // flipcam - if (y != INT32_MIN) // I_Error(): FixedDiv: divide by zero - y = FixedMul(FixedDiv(y, fovratio), xres) + yres; - //else print("NOPE!") - - offset = FixedMul(FINETANGENT(((aimingangle+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), xres); - - // this isn't fovtan... what am i even doing anymore - if (splitscreen == 1) - offset = 17*offset/120; - - // thanks fickle - offset = FixedDiv(offset, fovratio); - if (srcflip) - offset = -offset; // flipcam - y = y + offset; - } - - // project the angle to get our final X coordinate - x = FixedMul(FINETANGENT(((x+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), fov); - if (splitscreen == 1) // divide by 320/200 (1.6) on 2P splitscreen - x = (x/2) + (x/8); - x = x + xres; - - // now clip in screen-space - if (!dontclip && (x < 0 || x > xres*2 || y < 0 || y > yres*2)) - return false; - - // adjust coords for splitscreen - if (splitscreen == 1) // 2P - { - y = y>>1; - if (stplyrnum > 0) - y = y + yres; - } - if (splitscreen >= 2) // 3P or 4P - { - x = x>>1; - y = y>>1; - if (stplyrnum & 1) - x = x + xres; - if (stplyrnum >= 2) - y = y + yres; - } - - vec->y = y; - vec->x = x; - return true; -} - -//Slighty fixed by Alug and further rewritten by NepDisk -//Decided to port and highly modify sunflower version for the main nametag drawing with additions by NepDisk. My previous one was broken anyway due to the changed screencoords and noscalestart -static void K_drawNameTags(void) -{ - UINT8 i, j; - INT32 trans; - vector2_t pos = {0}; - fixed_t namex, namey; - int tagsdisplayed = 0; - fixed_t distance = 0; - fixed_t maxdistance = 0; - boolean flipped = false; - fixed_t z; - - char *tag; - patch_t *icon = NULL; - - INT32 dup; - UINT8 *cm = NULL; - UINT8 tagcolor = 0; - INT32 vflags = 0; - boolean usenametagrestat = false; - fixed_t tagwidthsmall; - fixed_t tagwidth; - - if (P_MobjWasRemoved(stplyr->mo) || (stplyr->spectator && !cv_shownametagspectator.value) || stplyr->exiting) - return; - - maxdistance = ((10*cv_nametagdist.value) * mapobjectscale); - - for (i = 0; i < MAXPLAYERS; i++) - { - distance = 0; - flipped = false; - - if (i > PLAYERSMASK) - continue; - if (players[i].spectator || !playeringame[i] || P_MobjWasRemoved(players[i].mo)) - continue; - if (i == displayplayers[stplyrnum] && !cv_showownnametag.value && !(leveltime < 130)) - continue; - if (i != displayplayers[stplyrnum] && leveltime < starttime) - continue; - if (players[i].kartstuff[k_hyudorotimer]) // player is invisible - continue; - if (maxdistance) - distance = R_PointToDist(players[i].mo->x, players[i].mo->y); - if (distance > maxdistance) - continue; - if (!P_CheckSightFast(stplyr->mo, players[i].mo)) - continue; - - z = players[i].mo->height; - - //Saltyhop hehe - z += lerp(players[i].mo->old_spriteyoffset, players[i].mo->spriteyoffset); - - if (!K_GetScreenCoords(&pos, stplyr, players[i].mo, z, false)) - continue; - - tagsdisplayed++; - - if (tagsdisplayed > cv_nametagmaxplayers.value) - break; - - trans = 0; - - switch (cv_nametagtrans.value) - { - case 1: - if (distance > (maxdistance*3/4)) - trans = V_60TRANS; - break; - case 2: - if (distance > (maxdistance*3/1)) - trans = V_90TRANS; - else if (distance > (maxdistance*3/2)) - trans = V_80TRANS; - else if (distance > (maxdistance*3/3)) - trans = V_60TRANS; - else if (distance > (maxdistance*3/4)) - trans = V_40TRANS; - else if (distance > (maxdistance*3/5)) - trans = V_20TRANS; - break; - case 3: - trans = V_40TRANS; - break; - case 4: - trans = V_LocalTransFlag(); - break; - case 0: - default: - break; - } - - namex = pos.x>>FRACBITS; - namey = pos.y>>FRACBITS; - - tag = va("%s%s ", HU_SkinColorToConsoleColor(players[i].mo->color), player_names[i]); - icon = R_GetSkinFaceMini(players[i].mo->player); - - dup = vid.dupx; - cm = R_GetTranslationColormap(players[i].skin, players[i].mo->color, GTC_CACHE); - tagcolor = colortranslations[players[i].mo->color][7]; - vflags = trans | V_NOSCALESTART; - usenametagrestat = ((cv_nametagrestat.value == 1 && (players[i].kartspeed != skins[players[i].skin].kartspeed || players[i].kartweight != skins[players[i].skin].kartweight)) || cv_nametagrestat.value == 2); - tagwidthsmall = cv_smallnametags.value ? V_SmallStringWidth(player_names[i], V_ALLOWLOWERCASE) : V_ThinStringWidth(player_names[i], V_ALLOWLOWERCASE); - tagwidth = dup*tagwidthsmall; - - // If flipcam is on, other player is flipped relative to us when we have different - // verticalflip flag value. Otherwise, they are simply flipped when verticalflip flag says so - if ((stplyr->pflags & PF_FLIPCAM) && (stplyr->mo->eflags & MFE_VERTICALFLIP)) - flipped = (players[i].mo->eflags & MFE_VERTICALFLIP) != (stplyr->mo->eflags & MFE_VERTICALFLIP); - else - flipped = players[i].mo->eflags & MFE_VERTICALFLIP; - - if (cv_smallnametags.value || !nametaggfx) - { - if (flipped) - namey += dup*5; - else // small offset - namey -= dup*3; - - if (nametaggfx && cv_smallnametags.value == 1) - { - if (cv_nametagfacerank.value) - tagwidthsmall += icon->width - dup; - - // Have to draw the nametag using patches here since drawfill can't draw at this scale... - if (!flipped) - V_DrawFixedPatch(namex<height/2)<width/2); // add offset to other stuff - } - - //Name - V_DrawSmallString(namex, namey, V_ALLOWLOWERCASE | vflags, tag); - - if (usenametagrestat) - { - V_DrawSmallString(namex, namey - dup*5, vflags, va("\x84S%d ", players[i].kartspeed)); - V_DrawSmallString(namex + dup*10, namey - dup*5, vflags, va("\x87W%d ", players[i].kartweight)); - } - - if (cv_nametagscore.value) - { - INT32 yofs = usenametagrestat ? 10 : 5; - V_DrawSmallString(namex, namey - dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); - } - } - else - { - if (cv_nametagfacerank.value) - tagwidth += dup*(icon->width+1); - - if (flipped) - { - for (j = 0; j < 4; j++) - { - V_DrawFill(namex, namey, dup*3, dup*4, 31 | vflags); - V_DrawFill(namex+dup, namey, dup, dup*4, tagcolor | vflags); - namey += dup*4; - namex += dup; - } - namey -= dup*3; - V_DrawFill(namex, namey+dup*2, dup, dup, 31 | vflags); // a single black pixel - V_DrawFill(namex+dup, namey, tagwidth, dup*3, 31 | vflags); - V_DrawFill(namex+dup, namey+dup, tagwidth - dup, dup, tagcolor | vflags); - namex += dup*2; - } - else - { - for (j = 0; j < 4; j++) - { - namey -= dup*4; - V_DrawFill(namex, namey, dup*3, dup*4, 31 | vflags); - V_DrawFill(namex+dup, namey, dup, dup*4, tagcolor | vflags); - namex += dup; - } - - V_DrawFill(namex, namey, dup, dup, 31 | vflags); - V_DrawFill(namex+dup, namey, tagwidth - dup*2, dup*3, 31 | vflags); - V_DrawFill(namex+dup, namey+dup, tagwidth - dup*3, dup, tagcolor | vflags); - } - - if (cv_nametagfacerank.value) - { - V_DrawMappedPatch(namex, namey - dup*(icon->height+1), vflags, icon, cm); - namex += dup*(icon->height+1); // add offset to other stuff - } - - V_DrawThinString(namex, namey - dup*10, V_ALLOWLOWERCASE | vflags, tag); - - if (usenametagrestat) - { - V_DrawScaledPatch(namex, namey - dup*20, vflags, nametagspeed); - V_DrawScaledPatch(namex + dup*18, namey - dup*20, vflags, nametagweight); - V_DrawString(namex + dup*9, namey - dup*19, V_ALLOWLOWERCASE | vflags, va("\x84%d ", players[i].kartspeed)); - V_DrawString(namex + dup*27, namey - dup*19, V_ALLOWLOWERCASE | vflags, va("\x87%d ", players[i].kartweight)); - } - - if (cv_nametagscore.value) - { - INT32 yofs = usenametagrestat ? 25 : 15; - V_DrawSmallString(namex, namey - dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); - } - } - } -} - -// Based on Driftgauge refactor by GenericHeroGuy ported from lua and expanded by NepDisk -static void K_drawDriftGauge(void) -{ - vector2_t pos = {0}; - fixed_t basex, basey; - const int dup = vid.dupx; - int i; - UINT8 *cmap; - - static const UINT8 driftcolors[3][4] = { - {0, 0, 10, 16}, // no drift - {215, 215, 204, 253}, // blue - {125, 125, 151, 159} // red - }; - - static const UINT8 driftskins[3] = { - SKINCOLOR_NONE, - SKINCOLOR_TEAL, - SKINCOLOR_SALMON, - }; - - static UINT8 driftrainbow[18] = { - 0, 31, 47, 63, 79, 95, 111, 119, 127, 143, 159, 175, 183, 191, 199, 207, 223, 247 - }; - - if (camera[stplyrnum].freecam) - return; - - if (!splitscreen && !camera->chase) - return; - - if (forceshowhud) - goto skipcrap; // i will skip the drift early return and you cant stop me! - - if (!stplyr->kartstuff[k_drift]) - return; - -skipcrap: - - if (P_MobjWasRemoved(stplyr->mo)) - return; - - if (!K_GetScreenCoords(&pos, stplyr, stplyr->mo, FixedMul(cv_driftgaugeofs.value, cv_driftgaugeofs.value > 0 ? stplyr->mo->scale : mapobjectscale), false)) - return; - - fixed_t barx; - fixed_t bary; - INT32 BAR_WIDTH; - - const INT32 driftval = K_GetKartDriftSparkValue(stplyr); - const INT32 driftcharge = min(driftval*4, stplyr->kartstuff[k_driftcharge]); - const INT32 driftlevel = min(driftcharge / driftval, 2); - const INT32 drifttrans = ((cv_driftgaugetrans.value) ? V_LocalTransFlag() : 0); - - basex = pos.x>>FRACBITS; - basey = pos.y>>FRACBITS; - - switch (cv_driftgaugestyle.value) - { - case 1: - case 2: - case 3: - case 5: - { - if (!driftgaugegfx) - break; - - const boolean usescaledpatch = (cv_driftgaugestyle.value == 5 && xtra_speedo3); - - if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || usescaledpatch) - { - barx = basex - dup*23; - BAR_WIDTH = dup*47; - } - else - { - barx = basex - dup*12; - BAR_WIDTH = dup*23; - } - - bary = basey - dup*2; - - if (usescaledpatch) // i hate hud code i hate hud code i hate hud code i hate hud code i hate hud code..... - { - if (K_UseColorSpeedo(SPEEDO_EXTRA3)) // Colourized hud - { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawStretchyFixedPatch((basex - dup*30)<= driftval*4) // rainbow sparks - { - cmap = R_GetTranslationColormap(TC_RAINBOW, 1 + leveltime % (MAXSKINCOLORS-1),GTC_CACHE); - - for (i = 0; i < 4; i++) - V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, (driftrainbow[min((leveltime % 18) + 1, 18 - 1)] + i*2) | V_NOSCALESTART|drifttrans); - } - else // none/blue/red - { - const INT32 limit = (driftval * (driftcharge >= driftval*2 ? 2 : 1)); - const INT32 width = ((driftcharge - (driftcharge >= driftval ? limit : 0)) * BAR_WIDTH) / limit; - - cmap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel],GTC_CACHE); - - for (i = 0; i < 4; i++) - { - if (driftcharge >= driftval) - V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, driftcolors[driftlevel-1][i] | V_NOSCALESTART|drifttrans); - - V_DrawFill(barx, bary+dup*1+dup*i, width, dup, driftcolors[driftlevel][i] | V_NOSCALESTART|drifttrans); - } - } - - // right, also draw a cool number - //SG_DrawPaddedNum(v, basex + (dup*32), basey, driftcharge*100 / driftval, 3, "PINGN", V_NOSCALESTART|V_OFFSET|drifttrans, cmap) - if (cv_driftgaugestyle.value == 3) - V_DrawPaddedTallColorNum(basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, cmap); - else - V_DrawPingNum(cv_driftgaugestyle.value == 2 ? basex + (dup*22) : basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, cmap); - } - break; - case 4: - { - cmap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel],GTC_CACHE); - - if (driftcharge >= driftval*4) - cmap = R_GetTranslationColormap(TC_RAINBOW, 1 + leveltime % (MAXSKINCOLORS-1),GTC_CACHE); - - V_DrawPaddedTallColorNum(basex + (dup*16), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, cmap); - } - break; - default: - break; - } -} - -static fixed_t K_FindCheckX(fixed_t px, fixed_t py, angle_t ang, fixed_t mx, fixed_t my) -{ - fixed_t dist, x; - fixed_t range = RING_DIST/3; - angle_t diff; - - range *= gamespeed+1; - - dist = abs(R_PointToDist2(px, py, mx, my)); - if (dist > range) - return -BASEVIDWIDTH; - - diff = R_PointToAngle2(px, py, mx, my) - ang; - - if (diff < ANGLE_90 || diff > ANGLE_270) - return -BASEVIDWIDTH; - else - x = (FixedMul(FINETANGENT(((diff+ANGLE_90)>>ANGLETOFINESHIFT) & 4095), 160<>FRACBITS; - - if (encoremode) - x = BASEVIDWIDTH-x; - - if (splitscreen > 1) - x /= 2; - - return x; -} - -static void K_drawKartWanted(void) -{ - UINT8 i, numwanted = 0; - UINT8 *colormap = NULL; - INT32 basex = 0, basey = 0; - - if (stplyrnum != 0) - return; - - for (i = 0; i < 4; i++) - { - if (battlewanted[i] == -1) - break; - numwanted++; - } - - if (numwanted <= 0) - return; - - // set X/Y coords depending on splitscreen. - if (splitscreen < 3) // 1P and 2P use the same code. - { - basex = WANT_X; - basey = WANT_Y; - if (splitscreen == 2) - { - basey += 16; // slight adjust for 3P - basex -= 6; - } - } - else if (splitscreen == 3) // 4P splitscreen... - { - basex = BASEVIDWIDTH/2 - (kp_wantedsplit->width/2); // center on screen - basey = BASEVIDHEIGHT - 55; - //basey2 = 4; - } - - if (battlewanted[0] != -1) - colormap = R_GetTranslationColormap(0, players[battlewanted[0]].skincolor, GTC_CACHE); - - V_DrawFixedPatch(basex< 1 ? kp_wantedsplit : kp_wanted), colormap); - /*if (basey2) - V_DrawFixedPatch(basex< 1 ? 13 : 8), y = basey+(splitscreen > 1 ? 16 : 21); - fixed_t scale = FRACUNIT/2; - - if (battlewanted[i] == -1) - break; - - player_t *p = &players[battlewanted[i]]; - - if (numwanted == 1) - scale = FRACUNIT; - else - { - if (i & 1) - x += 16; - if (i > 1) - y += 16; - } - - if (p->skincolor) - { - colormap = R_GetTranslationColormap(TC_RAINBOW, p->skincolor, GTC_CACHE); - V_DrawFixedPatch(x<skin] : facerankprefix[p->skin]), colormap);*/ - } - } -} - -static void K_drawKartPlayerCheck(void) -{ - INT32 i; - UINT8 *colormap; - INT32 x; - - const INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM); - - if (!stplyr->mo || stplyr->spectator) - return; - - if (stplyr->awayviewtics) - return; - - if (camspin[0]) - return; - - for (i = 0; i < MAXPLAYERS; i++) - { - UINT8 pnum = 0; - - if (&players[i] == stplyr) - continue; - if (!playeringame[i] || players[i].spectator) - continue; - if (!players[i].mo) - continue; - - if ((players[i].kartstuff[k_invincibilitytimer] <= 0) && (leveltime & 2)) - pnum++; // white frames - - if (players[i].kartstuff[k_itemtype] == KITEM_GROW || players[i].kartstuff[k_growshrinktimer] > 0) - pnum += 4; - else if (players[i].kartstuff[k_itemtype] == KITEM_INVINCIBILITY || players[i].kartstuff[k_invincibilitytimer]) - pnum += 2; - - x = K_FindCheckX(stplyr->mo->x, stplyr->mo->y, stplyr->mo->angle, players[i].mo->x, players[i].mo->y); - if (x <= 320 && x >= 0) - { - if (x < 14) - x = 14; - else if (x > 306) - x = 306; - - colormap = R_GetTranslationColormap(TC_DEFAULT, players[i].mo->color, GTC_CACHE); - V_DrawMappedPatch(x, CHEK_Y, V_HUDTRANS|splitflags, kp_check[pnum], colormap); - } - } -} - -static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32 hudy, INT32 flags, INT32 blend, patch_t *icon, UINT8 *colormap, drawinfo_t *dims, boolean scaleme) -{ - // amnum xpos & ypos are the icon's speed around the HUD. - // The number being divided by is for how fast it moves. - // The higher the number, the slower it moves. - - // am xpos & ypos are the icon's starting position. Withouht - // it, they wouldn't 'spawn' on the top-right side of the HUD. - - fixed_t amnumxpos, amnumypos; - INT32 amxpos, amypos; - fixed_t scale = FRACUNIT; - patch_t *AutomapPic; - INT16 w, h; - - AutomapPic = minimapinfo.minimap_pic; - - if (AutomapPic == NULL) - { - return; // no pic, just get outta here - } - - amnumxpos = (FixedMul(objx, minimapinfo.zoom) - minimapinfo.offs_x); - amnumypos = -(FixedMul(objy, minimapinfo.zoom) - minimapinfo.offs_y); - - if (encoremode) - amnumxpos = -amnumxpos; - - if (dims && (dims->x != 0) && (dims->y != 0)) - { - w = dims->x; - h = dims->y; - } - else - { - w = icon->width; - h = icon->height; - } - - amxpos = amnumxpos + ((hudx + (AutomapPic->width-w)/2)<height-h)/2)<player; - const boolean skinlocal = mo->skinlocal; - - fixed_t amnumxpos, amnumypos; - INT32 amxpos, amypos, wntdamxpos, wntdamypos; - fixed_t scale = FRACUNIT; - patch_t *minimaphead = NULL; - -#ifdef ROTSPRITE - angle_t rollangle = 0; - INT32 rot = 0; -#endif - - skin = K_GetMobjSkin(mo); - minimaphead = (skinlocal ? localfacemmapprefix : facemmapprefix)[K_GetMobjSkinNum(skin, skinlocal)]; - - amnumxpos = (FixedMul(lerp(mo->old_x, mo->x), minimapinfo.zoom) - minimapinfo.offs_x); - amnumypos = -(FixedMul(lerp(mo->old_y, mo->y), minimapinfo.zoom) - minimapinfo.offs_y); - - if (encoremode) - amnumxpos = -amnumxpos; - - amxpos = amnumxpos + ((x + (minimapinfo.minimap_pic->width-minimaphead->width) / 2)<height-minimaphead->height) / 2)<color), player_names[player - players]); - } - - // thx wanted reticle for having weird offsets very cool - wntdamxpos = cv_minihead.value ? amxpos + (1<width / 4)<height / 4)<spinoutrot) - { - // Rotate counterclockwise. - rollangle = FixedAngle(player->spinoutrot * -1); - rot = R_GetRollAngle(rollangle); - - if (rot) - { - minimaphead = W_CachePatchNameRotated(skin->facemmap, rot, PU_PATCH); - } - } -#endif - - if (!mo->color) // 'default' color - V_DrawSciencePatch(amxpos, amypos, flags, minimaphead, scale); - else - { - UINT8 *colormap; - - if (mo->colorized) - colormap = R_GetTranslationColormap(TC_RAINBOW, mo->color, GTC_CACHE); - else - colormap = R_GetLocalTranslationColormap(mo->skin, mo->localskin, mo->color, GTC_CACHE, skinlocal); - - V_DrawFixedPatch(amxpos, amypos, scale, flags, minimaphead, colormap); - - if (player - && ((G_RaceGametype() && player->kartstuff[k_position] == spbplace) - || (G_BattleGametype() && K_IsPlayerWanted(player)))) - { - V_DrawFixedPatch(wntdamxpos, wntdamypos, scale, flags, kp_wantedreticle, NULL); - } - } -} - -enum -{ - MINIANGLE_NONE = 0, - MINIANGLE_DOT, - MINIANGLE_LIGHT -}; - -static void K_drawKartMinimap(void) -{ - INT32 i = 0; - INT32 x, y; - INT32 minimaptrans, splitflags; - SINT8 localplayers[MAXSPLITSCREENPLAYERS]; - SINT8 numlocalplayers = 0; - patch_t *AutomapPic; - - // Draw the HUD only when playing in a level. - // hu_stuff needs this, unlike st_stuff. - if (gamestate != GS_LEVEL) - return; - - // Only draw for the first player - if (stplyrnum != 0) - return; - - AutomapPic = minimapinfo.minimap_pic; - - if (AutomapPic == NULL) - { - return; // no pic, just get outta here - } - - minimaptrans = K_getMinimapTrans(); - - // Exit early if it wouldn't draw anyway. - if (minimaptrans == -1) - return; - - drawinfo_t info; - K_getMinimapDrawinfo(&info); - x = info.x - (AutomapPic->width/2); - y = info.y - (AutomapPic->height/2); - splitflags = info.flags; - - splitflags |= minimaptrans; - - if (encoremode) - V_DrawScaledPatch(x+AutomapPic->width, y, splitflags|V_FLIP, AutomapPic); - else - V_DrawScaledPatch(x, y, splitflags, AutomapPic); - - if (!(splitscreen == 2)) - { - splitflags &= ~minimaptrans; - splitflags |= V_HUDTRANSHALF; - } - - // let offsets transfer to the heads, too! - if (encoremode) - x += AutomapPic->leftoffset; - else - x -= AutomapPic->leftoffset; - y -= AutomapPic->topoffset; - - // initialize - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - localplayers[i] = -1; - - // Player's tiny icons on the Automap. (drawn opposite direction so player 1 is drawn last in splitscreen) - if (ghosts) - { - demoghost *g = ghosts; - while (g) - { - K_drawKartMinimapHead(g->mo, x, y, splitflags); - g = g->next; - } - - if (!stplyr->mo || stplyr->spectator) // do we need the latter..? - return; - - localplayers[numlocalplayers++] = stplyr-players; - } - else - { - for (i = MAXPLAYERS-1; i >= 0; i--) - { - if (!playeringame[i]) - continue; - - if (!players[i].mo || players[i].spectator) - continue; - - if (P_IsDisplayPlayer(&players[i])) - { - // Draw display players on top of everything else - localplayers[numlocalplayers++] = i; - continue; - } - - // Now we know it's not a display player, handle non-local player exceptions. - if (G_BattleGametype() && players[i].kartstuff[k_bumper] <= 0) - continue; - - if (players[i].kartstuff[k_hyudorotimer] > 0) - { - if (!((players[i].kartstuff[k_hyudorotimer] < 1*TICRATE/2 - || players[i].kartstuff[k_hyudorotimer] > hyudorotime-(1*TICRATE/2)) - && !(leveltime & 1))) - continue; - } - - K_drawKartMinimapHead(players[i].mo, x, y, splitflags); - } - } - - // draw our local players here, opaque. - splitflags &= ~V_HUDTRANSHALF; - splitflags |= V_HUDTRANS; - - const SINT8 icondotradius = (cv_minihead.value && !cv_showminimapnames.value) ? 8 : 10; - patch_t* minipatch; - INT32 rot; - INT32 blending; - - for (i = 0; i < numlocalplayers; i++) - { - if (localplayers[i] == -1) - continue; // this doesn't interest us - - mobj_t *mobj = players[localplayers[i]].mo; - - // dont draw for no contestants - boolean playertimedout = (mobj->health <= 0 && players[localplayers[i]].pflags & PF_TIMEOVER); - - if (cv_showminimapangle.value && (minidoticon || minilighticon) && !playertimedout) - { - UINT8 *colormap; - drawinfo_t dims; - fixed_t interpx, interpy; - fixed_t xoff = 0, yoff = 0; - blending = 0; - - angle_t ang = R_InterpolateAngle(mobj->old_angle, mobj->angle); - - if (encoremode) - ang = ANGLE_180 - ang; - - if (mobj->colorized) - colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE); - else - colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal); - - interpx = lerp(mobj->old_x, mobj->x); - interpy = lerp(mobj->old_y, mobj->y); - - minipatch = kp_minimapdot; - - dims.x = 0; - dims.y = 0; - - if (cv_showminimapangle.value == MINIANGLE_DOT) - { - xoff = FixedMul(FCOS(ang), icondotradius); - yoff = -FixedMul(FSIN(ang), icondotradius); - } - else if (cv_showminimapangle.value == MINIANGLE_LIGHT) - { - rot = R_GetRollAngle(ang); - minipatch = W_CachePatchNameRotated("MMAPHDLT", rot, PU_PATCH); - - blending = B_ADD; - xoff = yoff = 0; - - dims.x = 48; - dims.y = 24; - } - - K_drawKartMinimapIcon( - interpx, - interpy, - x + xoff, - y + yoff, - splitflags, - blending, - minipatch, - colormap, - &dims, - false - ); - } - - // draw the minimap head after the nonsense above - K_drawKartMinimapHead(mobj, x, y, splitflags); - } -} - -#undef lerp - -static void K_drawKartStartCountdown(void) -{ - INT32 pnum = 0, splitflags = K_calcSplitFlags(0); // 3 - - if (leveltime >= starttime-(2*TICRATE)) // 2 - pnum++; - if (leveltime >= starttime-TICRATE) // 1 - pnum++; - if (leveltime >= starttime) // GO! - pnum++; - if ((leveltime % (2*5)) / 5) // blink - pnum += 4; - if (splitscreen) // splitscreen - pnum += 8; - - V_DrawScaledPatch(STCD_X - (kp_startcountdown[pnum]->width/2), STCD_Y - (kp_startcountdown[pnum]->height/2), splitflags, kp_startcountdown[pnum]); -} - -static void K_drawKartFinish(void) -{ - INT32 pnum = 0, splitflags = K_calcSplitFlags(0); - - if (!stplyr->kartstuff[k_cardanimation] || stplyr->kartstuff[k_cardanimation] >= 2*TICRATE) - return; - - if ((stplyr->kartstuff[k_cardanimation] % (2*5)) / 5) // blink - pnum = 1; - - if (splitscreen > 1) // 3/4p, stationary FIN - { - pnum += 2; - V_DrawScaledPatch(STCD_X - (kp_racefinish[pnum]->width/2), STCD_Y - (kp_racefinish[pnum]->height/2), splitflags, kp_racefinish[pnum]); - return; - } - - //else -- 1/2p, scrolling FINISH - { - INT32 x, xval; - - if (splitscreen) // wide splitscreen - pnum += 4; - - x = ((vid.width<width<kartstuff[k_cardanimation])< x ? xval : x))/TICRATE; - - if (splitscreen && stplyrnum == 1) - x = -x; - - V_DrawFixedPatch(x + (STCD_X<>1), - (STCD_Y<height<<(FRACBITS-1)), - FRACUNIT, - splitflags, kp_racefinish[pnum], NULL); - } -} - -static void K_drawBattleFullscreen(void) -{ - INT32 cardanim = stplyr->kartstuff[k_cardanimation] << FRACBITS; - - // fill in the fractional bits - if (cardanim && cardanim != 164*FRACUNIT) - { - INT32 frac = R_GetHudUncap() * ((164 - stplyr->kartstuff[k_cardanimation])/8 + 1); - if (stplyr->exiting) - cardanim += frac; - else - cardanim += stplyr->kartstuff[k_comebacktimer] < 6*TICRATE ? -frac : frac; - } - - INT32 x = BASEVIDWIDTH/2; - INT32 y = (-64*FRACUNIT) + cardanim; // card animation goes from 0 to 164, 164 is the middle of the screen - INT32 splitflags = V_SNAPTOTOP; // I don't feel like properly supporting non-green resolutions, so you can have a misuse of SNAPTO instead - fixed_t scale = FRACUNIT; - boolean drawcomebacktimer = true; // lazy hack because it's cleaner in the long run. - - if (!LUA_HudEnabled(hud_battlecomebacktimer)) - drawcomebacktimer = false; - - if (splitscreen) - { - if ((splitscreen == 1 && stplyrnum == 1) || (splitscreen > 1 && stplyrnum & 2)) - { - y = (232*FRACUNIT) - (cardanim/2); - splitflags = V_SNAPTOBOTTOM; - } - else - y = (-32*FRACUNIT) + (cardanim/2); - - if (splitscreen > 1) - { - scale /= 2; - - if (stplyrnum & 1) - x = 3*BASEVIDWIDTH/4; - else - x = BASEVIDWIDTH/4; - } - else - { - if (stplyr->exiting) - { - if (stplyrnum == 1) - x = BASEVIDWIDTH-96; - else - x = 96; - } - else - scale /= 2; - } - } - - if (stplyr->exiting) - { - if (stplyrnum == 0) - V_DrawFadeScreen(0xFF00, 16); - if (stplyr->exiting < 6*TICRATE && !stplyr->spectator) - { - if (stplyr->kartstuff[k_position] == 1) - V_DrawFixedPatch(x<kartstuff[k_bumper] <= 0 && stplyr->kartstuff[k_comebacktimer] && comeback && !stplyr->spectator && drawcomebacktimer) - { - UINT16 t = stplyr->kartstuff[k_comebacktimer]/(10*TICRATE); - INT32 txoff, adjust = (splitscreen > 1) ? 4 : 6; // normal string is 8, kart string is 12, half of that for ease - INT32 ty = (BASEVIDHEIGHT/2)+66; - - txoff = adjust; - - while (t) - { - txoff += adjust; - t /= 10; - } - - if (splitscreen) - { - if (splitscreen > 1) - ty = (BASEVIDHEIGHT/4)+33; - if ((splitscreen == 1 && stplyrnum == 1) || (splitscreen > 1 && stplyrnum & 2)) - ty += (BASEVIDHEIGHT/2); - } - else - V_DrawFadeScreen(0xFF00, 16); - - if (!comebackshowninfo) - V_DrawFixedPatch(x< 1) - V_DrawString(x-txoff, ty, 0, va("%d", stplyr->kartstuff[k_comebacktimer]/TICRATE)); - else - { - if (K_UseColorHud()) // Colourized hud - { - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawFixedPatch(x<kartstuff[k_comebacktimer]/TICRATE)); - } - } - - if (netgame && !stplyr->spectator && timeinmap > 113) // FREE PLAY? - { - UINT8 i; - - // check to see if there's anyone else at all - for (i = 0; i < MAXPLAYERS; i++) - { - if (i == displayplayers[0]) - continue; - if (playeringame[i] && !stplyr->spectator) - return; - } - - if (LUA_HudEnabled(hud_freeplay)) - K_drawKartFreePlay(leveltime); - } -} - -static void K_drawKartFirstPerson(void) -{ - static INT32 pnum[4], turn[4], drift[4]; - INT32 pn = 0, tn = 0, dr = 0; - INT32 target = 0, splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM); - INT32 x = BASEVIDWIDTH/2, y = BASEVIDHEIGHT; - fixed_t scale; - UINT8 *colmap = NULL; - ticcmd_t *cmd = &stplyr->cmd; - - if (stplyr->spectator || !stplyr->mo || (stplyr->mo->flags2 & MF2_DONTDRAW)) - return; - - pn = pnum[stplyrnum]; - tn = turn[stplyrnum]; - dr = drift[stplyrnum]; - - if (splitscreen) - { - y >>= 1; - if (splitscreen > 1) - x >>= 1; - } - - { - if (stplyr->speed < (20*stplyr->mo->scale) && (leveltime & 1) && !splitscreen) - y++; - // the following isn't EXPLICITLY right, it just gets the result we want, but i'm too lazy to look up the right way to do it - if (stplyr->mo->flags2 & MF2_SHADOW) - splitflags |= FF_TRANS80; - else if (stplyr->mo->frame & FF_TRANSMASK) - splitflags |= (stplyr->mo->frame & FF_TRANSMASK); - } - - if (cmd->driftturn > 400) // strong left turn - target = 2; - else if (cmd->driftturn < -400) // strong right turn - target = -2; - else if (cmd->driftturn > 0) // weak left turn - target = 1; - else if (cmd->driftturn < 0) // weak right turn - target = -1; - else // forward - target = 0; - - if (encoremode) - target = -target; - - if (pn < target) - pn++; - else if (pn > target) - pn--; - - if (pn < 0) - splitflags |= V_FLIP; // right turn - - target = abs(pn); - if (target > 2) - target = 2; - - x <<= FRACBITS; - y <<= FRACBITS; - - if (tn != cmd->driftturn/50) - tn -= (tn - (cmd->driftturn/50))/8; - - if (dr != stplyr->kartstuff[k_drift]*16) - dr -= (dr - (stplyr->kartstuff[k_drift]*16))/8; - - if (splitscreen == 1) - { - scale = (2*FRACUNIT)/3; - y += FRACUNIT/(vid.dupx < vid.dupy ? vid.dupx : vid.dupy); // correct a one-pixel gap on the screen view (not the basevid view) - } - else if (splitscreen) - scale = FRACUNIT/2; - else - scale = FRACUNIT; - - if (stplyr->mo) - { - INT32 dsone = K_GetKartDriftSparkValue(stplyr); - INT32 dstwo = dsone*2; - INT32 dsthree = dstwo*2; - -#ifndef DONTLIKETOASTERSFPTWEAKS - { - const angle_t ang = R_PointToAngle2(0, 0, stplyr->rmomx, stplyr->rmomy) - stplyr->frameangle; - // yes, the following is correct. no, you do not need to swap the x and y. - fixed_t xoffs = -P_ReturnThrustY(stplyr->mo, ang, (BASEVIDWIDTH<<(FRACBITS-2))/2); - fixed_t yoffs = -(P_ReturnThrustX(stplyr->mo, ang, 4*FRACUNIT) - 4*FRACUNIT); - - if (splitscreen) - xoffs = FixedMul(xoffs, scale); - - xoffs -= (tn)*scale; - xoffs -= (dr)*scale; - - if (stplyr->frameangle == stplyr->mo->angle) - { - const fixed_t mag = FixedDiv(stplyr->speed, 10*stplyr->mo->scale); - - if (mag < FRACUNIT) - { - xoffs = FixedMul(xoffs, mag); - if (!splitscreen) - yoffs = FixedMul(yoffs, mag); - } - } - - if (stplyr->mo->momz > 0) // TO-DO: Draw more of the kart so we can remove this if! - yoffs += stplyr->mo->momz/3; - - if (encoremode) - x -= xoffs; - else - x += xoffs; - if (!splitscreen) - y += yoffs; - } - - // drift sparks! - if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dsthree)) - colmap = R_GetTranslationColormap(TC_RAINBOW, (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))), GTC_CACHE); - else if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dstwo)) - colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_KETCHUP, GTC_CACHE); - else if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dsone)) - colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_SAPPHIRE, GTC_CACHE); - else -#endif - // invincibility/grow/shrink! - if (stplyr->mo->colorized && stplyr->mo->color) - colmap = R_GetTranslationColormap(TC_RAINBOW, stplyr->mo->color, GTC_CACHE); - } - - V_DrawFixedPatch(x, y, scale, splitflags, kp_fpview[target], colmap); - - pnum[stplyrnum] = pn; - turn[stplyrnum] = tn; - drift[stplyrnum] = dr; -} - -// doesn't need to ever support 4p -static void K_drawInput(void) -{ - INT32 offs, col; - static INT32 pn = 0; - - if (!cv_showinput.value || (timeinmap <= 105)) // dont bother - return; - - INT32 target = 0, splitflags = (V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS); - INT32 x = (BASEVIDWIDTH - 32 + cv_wheel_xoffset.value)*FRACUNIT, y = (BASEVIDHEIGHT - 24 + cv_wheel_yoffset.value)*FRACUNIT; - - const UINT8 hudcolor = K_GetHudColor(); - const INT32 accent1 = splitflags|colortranslations[hudcolor][5]; - const INT32 accent2 = splitflags|colortranslations[hudcolor][9]; - const UINT8 *hudcolormap = R_GetTranslationColormap(0, hudcolor, GTC_CACHE); - - const ticcmd_t *cmd = &stplyr->cmd; - - if (timeinmap < 113) - { - INT32 count = ((INT32)(timeinmap) - 105); - INT32 frac = count > 0 && count < 6 ? R_GetHudUncap() << (FRACBITS - count - 11) : 0; - - offs = 64*FRACUNIT; - while (count-- > 0) - offs >>= 1; - x += (offs < FRACUNIT ? 0 : offs) - frac; - } - -#define BUTTW 8 -#define BUTTH 11 - -#define drawbutt(xoffs, butt, symb)\ - if (cmd->buttons & butt)\ - {\ - offs = 2*FRACUNIT;\ - col = accent1;\ - }\ - else\ - {\ - offs = 0;\ - col = accent2;\ - V_DrawFill((x + xoffs*FRACUNIT)>>FRACBITS, (y + BUTTH*FRACUNIT)>>FRACBITS, BUTTW-1, 2, splitflags|31);\ - }\ - V_DrawFill((x + xoffs*FRACUNIT)>>FRACBITS, (y+offs)>>FRACBITS, BUTTW-1, BUTTH, col);\ - V_DrawFixedPatch(x + FRACUNIT + xoffs*FRACUNIT, y + offs + FRACUNIT, FRACUNIT, splitflags, tny_font[symb-HU_FONTSTART], NULL) - - drawbutt(-2*BUTTW, BT_ACCELERATE, 'A'); - drawbutt( -BUTTW, BT_BRAKE, 'B'); - drawbutt( 0, BT_DRIFT, 'D'); - drawbutt( BUTTW, BT_ATTACK, 'I'); - -#undef drawbutt - -#undef BUTTW -#undef BUTTH - - y -= FRACUNIT; - - if (cv_showinput.value == 2 || cv_showinput.value == 3) - { - INT32 axis; - INT32 hudforward = 0; // for the stick input display :chaosleep: - UINT8 *shadowcolormap = NULL; - const INT32 joyx = x>>FRACBITS; - const INT32 joyy = y>>FRACBITS; - static const INT32 joyxoffs = -8; - static const INT32 joyyoffs = -24; - const boolean usejoysprite = (cv_showinput.value == 3 && joystickicon); - - // O backing - if (usejoysprite) - { - shadowcolormap = R_GetTranslationColormap(0, SKINCOLOR_BLACK, GTC_CACHE); - V_DrawMappedPatch(joyx+joyxoffs, joyy+joyyoffs-1, splitflags, joybacking, hudcolormap); - } - else - { - V_DrawFill(joyx+joyxoffs, joyy+joyyoffs-1, 16, 16, splitflags|accent2); - V_DrawFill(joyx+joyxoffs, joyy+joyyoffs+15, 16, 1, splitflags|31); - } - - // time for pain and suffering - // kart does not have anything we can get analogue joystick y axis values from - // during normal gameplay, so replicate shit here - - // this is horrid but we cant get actual input in replays so uhh - if (demo.playback || !P_IsLocalPlayer(stplyr)) // yeah........... - { - hudforward = stplyr->kartstuff[k_throwdir] * KART_FULLTURN; - } - else - { - const boolean analogjoystickmove = cv_usejoystick[stplyrnum].value && !Joystick[stplyrnum].bGamepadStyle; - const boolean gamepadjoystickmove = cv_usejoystick[stplyrnum].value && Joystick[stplyrnum].bGamepadStyle; - const UINT8 ssplayer = stplyrnum+1; - - axis = JoyAxis(AXISAIM, ssplayer); - - if (analogjoystickmove && axis != 0) - { - // JOYAXISRANGE is supposed to be 1023 (divide by 1024) - hudforward -= ((axis * KART_FULLTURN) / (JOYAXISRANGE-1)); - } - else - { - if (InputDown(gc_aimforward, ssplayer) || (gamepadjoystickmove && axis < 0)) - { - hudforward += KART_FULLTURN; - } - if (InputDown(gc_aimbackward, ssplayer) || (gamepadjoystickmove && axis > 0)) - { - hudforward-= KART_FULLTURN; - } - } - - hudforward = CLAMP(hudforward, -KART_FULLTURN, KART_FULLTURN); - } - - if (cmd->driftturn || hudforward) - { - INT16 turning = encoremode ? -cmd->driftturn : cmd->driftturn; - - if (usejoysprite) - { - V_DrawMappedPatch(joyx+joyxoffs+3-turning/80, joyy+joyyoffs+2-hudforward/80, splitflags, joyknob, shadowcolormap); - V_DrawMappedPatch(joyx+joyxoffs+3-turning/64, joyy+joyyoffs+1-hudforward/64, splitflags, joyknob, hudcolormap); - } - else - { - // joystick hole - V_DrawFill(joyx+joyxoffs+5, joyy+joyyoffs+4, 6, 6, splitflags|accent1); - // joystick top and back - V_DrawFill(joyx+joyxoffs+3-turning/80, joyy+joyyoffs+2-hudforward/80, 10, 10, splitflags|31); - V_DrawFill(joyx+joyxoffs+3-turning/64, joyy+joyyoffs+1-hudforward/64, 10, 10, splitflags|accent1); - } - } - else - { - if (usejoysprite) - { - V_DrawMappedPatch(joyx+joyxoffs+3, joyy+joyyoffs+8, splitflags, joyshadow, shadowcolormap); - V_DrawMappedPatch(joyx+joyxoffs+3, joyy+joyyoffs+1, splitflags, joyknob, hudcolormap); - } - else - { - V_DrawFill(joyx+joyxoffs+3, joyy+joyyoffs+11, 10, 1, splitflags|accent2); - V_DrawFill(joyx+joyxoffs+3, joyy+joyyoffs+1, 10, 10,splitflags|accent1); - } - } - } - else - { - if (!cmd->driftturn) // no turn - target = 0; - else // turning of multiple strengths! - { - target = ((abs(cmd->driftturn) - 1)/125)+1; - if (target > 4) - target = 4; - if (cmd->driftturn < 0) - target = -target; - } - - if (pn != target) - { - if (abs(pn - target) == 1) - pn = target; - else if (pn < target) - pn += 2; - else //if (pn > target) - pn -= 2; - } - - if (pn < 0) - { - splitflags |= V_FLIP; // right turn - x -= FRACUNIT; - } - - target = abs(pn); - if (target > 4) - target = 4; - - V_DrawFixedPatch(x, y, FRACUNIT, splitflags, kp_inputwheel[target], hudcolormap); - } -} - -static void K_drawChallengerScreen(void) -{ - // This is an insanely complicated animation. - static const UINT8 anim[52] = { - 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13, // frame 1-14, 2 tics: HERE COMES A NEW slides in - 14,14,14,14,14,14, // frame 15, 6 tics: pause on the W - 15,16,17,18, // frame 16-19, 1 tic: CHALLENGER approaches screen - 19,20,19,20,19,20,19,20,19,20, // frame 20-21, 1 tic, 5 alternating: all text vibrates from impact - 21,22,23,24 // frame 22-25, 1 tic: CHALLENGER turns gold - }; - const UINT8 offset = min(52-1, (3*TICRATE)-mapreset); - - V_DrawFadeScreen(0xFF00, 16); // Fade out - V_DrawScaledPatch(0, 0, 0, kp_challenger[anim[offset]]); -} - -static void K_drawLapStartAnim(void) -{ - // This is an EVEN MORE insanely complicated animation. - const UINT8 progress = 80-stplyr->kartstuff[k_lapanimation]; - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - INT32 vflags = V_SNAPTOTOP|V_HUDTRANS; - - fixed_t slideout = max(0, 32*(((progress - 76)*FRACUNIT) + R_GetHudUncap())); - fixed_t slidein = max(0, 32*(((stplyr->kartstuff[k_lapanimation] - 76)*FRACUNIT) - R_GetHudUncap())); - - // First, draw the emblem and hand - INT32 emblemx = (BASEVIDWIDTH << (FRACBITS - 1)) + slidein; - INT32 y = 48*FRACUNIT - slideout; - - V_DrawFixedPatch(emblemx, y, FRACUNIT, vflags, kp_lapanim_emblem[modeattacking ? 1 : 0], colormap); - - INT32 hand = stplyr->kartstuff[k_laphand]; - if (hand >= 1 && hand <= 3) - { - y += 4*FRACUNIT - abs((int)(leveltime % 8)*FRACUNIT + R_GetHudUncap() - 4*FRACUNIT); - V_DrawFixedPatch(emblemx, y, FRACUNIT, vflags, kp_lapanim_hand[hand - 1], NULL); - } - - // Then the text - INT32 leftx = 82*FRACUNIT - slideout; - INT32 rightx = 188*FRACUNIT + slideout; - y = 30*FRACUNIT; - - if (stplyr->laps == (UINT8)(cv_numlaps.value - 1)) - { - // FINAL - V_DrawFixedPatch(leftx - 20*FRACUNIT, y, FRACUNIT, vflags, kp_lapanim_final[min(progress/2, 10)], NULL); - - // LAP - if (progress/2 - 12 >= 0) - V_DrawFixedPatch(rightx, y, FRACUNIT, vflags, kp_lapanim_lap[min(progress/2 - 12, 6)], NULL); - } - else - { - // LAP - V_DrawFixedPatch(leftx, y, FRACUNIT, vflags, kp_lapanim_lap[min(progress/2, 6)], NULL); - - char *lapnum = va("%02d", stplyr->laps + 1); - for (int i = 0; i < (int)strlen(lapnum); i++) - { - int digit = lapnum[i] - '0'; - int frame = min(2, progress/2 - 8 - (i*2)); - if (frame >= 0) - V_DrawFixedPatch(rightx + (i*20*FRACUNIT), y, FRACUNIT, vflags, kp_lapanim_number[digit][frame], NULL); - } - } -} - -void K_drawKartFreePlay(UINT32 flashtime) -{ - // no splitscreen support because it's not FREE PLAY if you have more than one player in-game - - if (!cv_showfreeplay.value) - return; - - if ((flashtime % TICRATE) < TICRATE/2) - return; - - V_DrawKartString((BASEVIDWIDTH - (LAPS_X+1)) - (12*9), // mirror the laps thingy - LAPS_Y+3, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, "FREE PLAY"); -} - -static void K_drawDistributionDebugger(void) -{ - patch_t *items[NUMKARTRESULTS] = { - kp_sadface[1], - kp_sneaker[1], - kp_rocketsneaker[1], - kp_invincibility[7], - kp_banana[1], - kp_eggman[1], - kp_orbinaut[4], - kp_jawz[1], - kp_mine[1], - kp_ballhog[1], - kp_selfpropelledbomb[1], - kp_grow[1], - kp_shrink[1], - kp_thundershield[1], - kp_hyudoro[1], - kp_pogospring[1], - kp_kitchensink[1], - - kp_sneaker[1], - kp_banana[1], - kp_banana[1], - kp_orbinaut[4], - kp_orbinaut[4], - kp_jawz[1] - }; - INT32 useodds = 0; - INT32 pingame = 0, bestbumper = 0; - INT32 i; - INT32 x = -9, y = -9; - boolean dontforcespb = false; - boolean spbrush = false; - - if (stplyrnum != 0) // only for p1 - return; - - // The only code duplication from the Kart, just to avoid the actual item function from calculating pingame twice - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].spectator) - continue; - pingame++; - if (players[i].exiting) - dontforcespb = true; - if (players[i].kartstuff[k_bumper] > bestbumper) - bestbumper = players[i].kartstuff[k_bumper]; - } - - if (G_RaceGametype()) - spbrush = (spbplace != -1 && stplyr->kartstuff[k_position] == spbplace+1); - - useodds = K_FindUseodds(stplyr, 0, pingame, bestbumper, spbrush, dontforcespb); - - for (i = 1; i < NUMKARTRESULTS; i++) - { - const INT32 itemodds = K_KartGetItemOdds(useodds, i, 0, spbrush); - if (itemodds <= 0) - continue; - - V_DrawScaledPatch(x, y, V_HUDTRANS|V_SNAPTOTOP, items[i]); - V_DrawThinString(x+11, y+31, V_HUDTRANS|V_SNAPTOTOP, va("%d", itemodds)); - - // Display amount for multi-items - if (i >= NUMKARTITEMS) - { - INT32 amount; - switch (i) - { - case KRITEM_TENFOLDBANANA: - amount = 10; - break; - case KRITEM_QUADORBINAUT: - amount = 4; - break; - case KRITEM_DUALJAWZ: - amount = 2; - break; - default: - amount = 3; - break; - } - V_DrawString(x+24, y+31, V_ALLOWLOWERCASE|V_HUDTRANS|V_SNAPTOTOP, va("x%d", amount)); - } - - x += 32; - if (x >= 297) - { - x = -9; - y += 32; - } - } - - V_DrawString(0, 0, V_HUDTRANS|V_SNAPTOTOP, va("USEODDS %d", useodds)); -} - -static void K_drawCheckpointDebugger(void) -{ - if (stplyrnum != 0) // only for p1 - return; - - if (stplyr->starpostnum >= (numstarposts - (numstarposts/2))) - V_DrawString(8, 184, 0, va("Checkpoint: %d / %d (Can finish)", stplyr->starpostnum, numstarposts)); - else - V_DrawString(8, 184, 0, va("Checkpoint: %d / %d (Skip: %d)", stplyr->starpostnum, numstarposts, ((numstarposts/2) + stplyr->starpostnum))); - V_DrawString(8, 192, 0, va("Waypoint dist: Prev %d, Next %d", stplyr->kartstuff[k_prevcheck], stplyr->kartstuff[k_nextcheck])); -} - -// determines if gametype info (laps/bumpers) should be hidden -static boolean K_DisableGametypeInfo(void) -{ - if (!LUA_HudEnabled(hud_gametypeinfo)) - { - return true; - } - -#ifdef ROTSPRITE - if (splitscreen || (!cv_kartspeedometer.value)) - { - // don't need to run checks if we're in splitscreen, or not using the speedometer - return false; - } - - const UINT8 speedostyle = K_GetSpeedometerStyle(); - - if (G_RaceGametype()) - { - if (speedostyle == SPEEDO_DIAL) - return true; - } - else if (G_BattleGametype()) - { - if ((cv_battlespeedo.value) && (speedostyle == SPEEDO_DIAL)) - return true; - } -#endif - - return false; -} - - -void K_drawKartHUD(void) -{ - boolean isfreeplay = false; - boolean battlefullscreen = false; - boolean freecam = camera[stplyrnum].freecam; //disable some hud elements w/ freecam - boolean gameinfovisible = false; - - // Define the X and Y for each drawn object - // This is handled by console/menu values - K_initKartHUD(); - - // Draw that fun first person HUD! Drawn ASAP so it looks more "real". - if (!camera[stplyrnum].chase && !freecam) - K_drawKartFirstPerson(); - - // Draw full screen stuff that turns off the rest of the HUD - if (mapreset && stplyrnum == 0) - { - K_drawChallengerScreen(); - return; - } - - battlefullscreen = ((G_BattleGametype()) - && (stplyr->exiting - || (stplyr->kartstuff[k_bumper] <= 0 - && stplyr->kartstuff[k_comebacktimer] - && comeback - && stplyr->playerstate == PST_LIVE))); - - if (!demo.title && (!battlefullscreen || splitscreen)) - { - // Draw the CHECK indicator before the other items, so it's overlapped by everything else - - if (LUA_HudEnabled(hud_check)) // delete lua when? - { - if (cv_kartcheck.value && !splitscreen && !players[displayplayers[0]].exiting && !freecam) - K_drawKartPlayerCheck(); - } - - // Draw WANTED status - if (G_BattleGametype()) - { - if (LUA_HudEnabled(hud_wanted)) - K_drawKartWanted(); - } - - if (cv_kartminimap.value) - { - if (LUA_HudEnabled(hud_minimap)) - K_drawKartMinimap(); - } - } - - if (battlefullscreen && !freecam) - { - if (LUA_HudEnabled(hud_battlefullscreen)) - K_drawBattleFullscreen(); - return; - } - - // Draw the item window - if (LUA_HudEnabled(hud_item) && !freecam) - K_drawKartItem(); - - if (cv_driftgauge.value && !modeattacking) - { - if (LUA_HudEnabled(hud_driftgauge)) - K_drawDriftGauge(); - } - - if (cv_nametag.value) - { - if (LUA_HudEnabled(hud_nametags)) - K_drawNameTags(); - } - - // If not splitscreen, draw... - if (!splitscreen && !demo.title) - { - tic_t realtime = stplyr->realtime; - - if (cv_showlaptimes.value - && stplyr->kartstuff[k_lapanimation] - && !stplyr->exiting - && stplyr->laptime[LAP_LAST] != 0 - && !midgamejoin) // due to vanilla compat, we cannot synch this oh well - { - if ((stplyr->kartstuff[k_lapanimation] / 5) & 1) - { - realtime = stplyr->laptime[LAP_LAST]; - } - else - { - realtime = UINT32_MAX; - } - } - - // Draw the timestamp - if (LUA_HudEnabled(hud_time)) - K_drawKartTimestamp(realtime, TIME_X, TIME_Y, gamemap, 0); - - if (!modeattacking) - { - // The top-four faces on the left - //if (LUA_HudEnabled(hud_minirankings)) - isfreeplay = K_drawKartPositionFaces(); - } - } - - if (!stplyr->spectator && !freecam) // Bottom of the screen elements, don't need in spectate mode - { - // get gametype info visibility ahead of time - gameinfovisible = (!K_DisableGametypeInfo()); - - if (!(splitscreen || demo.title)) - { - if (LUA_HudEnabled(hud_inputdisplay)) - K_drawInput(); - } - - if (!demo.title && cv_showstats.value) - { - if (LUA_HudEnabled(hud_statdisplay)) - K_drawKartStats(); - } - - if (demo.title) // Draw title logo instead in demo.titles - { - INT32 x = (BASEVIDWIDTH - 32)*FRACUNIT, y = 128*FRACUNIT, offs; - INT32 logoflags = V_SNAPTORIGHT|V_SNAPTOBOTTOM; - - if (splitscreen == 3) - { - x = BASEVIDWIDTH/2 + 10; - y = BASEVIDHEIGHT/2 - 30; - } - - if (timeinmap < 113) - { - INT32 count = ((INT32)(timeinmap) - 104); - INT32 frac = count > 0 ? R_GetHudUncap() << max(0, FRACBITS - count - 9) : 0; - - offs = 256*FRACUNIT; - while (count-- > 0) - offs >>= 1; - x += offs - frac; - } - - V_DrawSciencePatch(x - (54*FRACUNIT), y, logoflags, W_CachePatchName("TTKBANNR", PU_PATCH), FRACUNIT/4); - V_DrawSciencePatch(x - (54*FRACUNIT), y + (25*FRACUNIT), logoflags, W_CachePatchName("TTKART", PU_PATCH), FRACUNIT/4); - } - else if (G_RaceGametype()) // Race-only elements - { - // Draw the lap counter - if (gameinfovisible) - K_drawKartLaps(); - - if (!splitscreen) - { - // Draw the speedometer - // TODO: Make a better speedometer. << done :p - if (LUA_HudEnabled(hud_speedometer)) - K_drawKartSpeedometer(); - } - - if (isfreeplay) - ; - else if (!modeattacking) - { - // Draw the numerical position - if (LUA_HudEnabled(hud_position)) - K_DrawKartPositionNum(stplyr->kartstuff[k_position]); - } - } - else if (G_BattleGametype()) // Battle-only - { - // Draw the hits left! - if (gameinfovisible) - K_drawKartBumpersOrKarma(); - - if ((!splitscreen) && cv_battlespeedo.value) - { - // Draw the speedometer but in battle - // TODO: Make a better speedometer. << done :p - if (LUA_HudEnabled(hud_speedometer)) - K_drawKartSpeedometer(); - } - } - } - - // Draw the countdowns after everything else. - if (leveltime >= starttime-(3*TICRATE) - && leveltime < starttime+TICRATE) - K_drawKartStartCountdown(); - else if (racecountdown && (!splitscreen || !stplyr->exiting)) - { - char *countstr = va("%d", racecountdown/TICRATE); - - // Eeeh dunno if would be better to add another variable instead of LAPS_Y but this works too - int yoff = cv_dnft_yoffset.value - cv_laps_yoffset.value; - int xoff = cv_dnft_xoffset.value; - - if (splitscreen > 1) - V_DrawCenteredString(BASEVIDWIDTH/4+xoff, LAPS_Y+1+yoff, K_calcSplitFlags(V_SNAPTOBOTTOM), countstr); - else - { - INT32 karlen = strlen(countstr)*6; // half of 12 - V_DrawKartString((BASEVIDWIDTH/2)-karlen+xoff, LAPS_Y+3+yoff, K_calcSplitFlags(V_SNAPTOBOTTOM), countstr); - } - } - - // Race overlays - if (G_RaceGametype() && !freecam) - { - if (stplyr->exiting) - K_drawKartFinish(); - else if (stplyr->kartstuff[k_lapanimation] && !splitscreen && cv_showlapemblem.value) - K_drawLapStartAnim(); - } - - if (modeattacking || freecam) // everything after here is MP and debug only - return; - - if (G_BattleGametype() && !splitscreen && (stplyr->kartstuff[k_yougotem] % 2)) // * YOU GOT EM * - V_DrawScaledPatch(BASEVIDWIDTH/2 - (kp_yougotem->width/2), 32, V_HUDTRANS, kp_yougotem); - - // Draw FREE PLAY. - if (isfreeplay && !stplyr->spectator && timeinmap > 113) - { - if (LUA_HudEnabled(hud_freeplay)) - K_drawKartFreePlay(leveltime); - } - - if (cv_kartdebugdistribution.value) - K_drawDistributionDebugger(); - - if (cv_kartdebugcheckpoint.value) - K_drawCheckpointDebugger(); - - if (cv_kartdebugdirector.value) - K_DrawDirectorDebugger(); - - if (cv_kartdebugnodes.value) - { - UINT8 p; - for (p = 0; p < MAXPLAYERS; p++) - V_DrawString(8, 64+(8*p), V_YELLOWMAP, va("%d - %d (%dl)", p, playernode[p], players[p].cmd.latency)); - } - - if (cv_kartdebugcolorize.value && stplyr->mo && stplyr->mo->skin) - { - INT32 x = 0, y = 0; - UINT8 c; - - for (c = 1; c < MAXSKINCOLORS; c++) - { - UINT8 *cm = R_GetTranslationColormap(TC_RAINBOW, c, GTC_CACHE); - V_DrawFixedPatch(x<>1, 0, facewantprefix[stplyr->skin], cm); - - x += 16; - if (x > BASEVIDWIDTH-16) - { - x = 0; - y += 16; - } - } - } -} - -//} diff --git a/src/k_kart.h b/src/k_kart.h index b10989618..012cd48ac 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -22,9 +22,6 @@ extern const UINT8 KartColor_Opposite[MAXSKINCOLORS*2]; void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor); void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, boolean local); UINT8 K_GetKartColorByName(const char *name); -UINT8 K_GetHudColor(void); -boolean K_UseColorHud(void); -boolean K_UseHighResPortraits(void); void K_RegisterServerKartStuff(void); void K_RegisterClientKartStuff(void); @@ -33,30 +30,11 @@ extern consvar_t cv_coloredspeedlines, cv_coloredsneakertrail; extern consvar_t cv_bananajitter; extern consvar_t cv_bananthrowroll; extern consvar_t cv_airsparks; -extern consvar_t cv_colorizedhud, cv_colorizeditembox, cv_colorizedhudcolor; -extern consvar_t cv_darkitembox; -extern consvar_t cv_biglaps; -extern consvar_t cv_highresportrait; -extern consvar_t cv_stat_xoffset, cv_stat_yoffset; -extern consvar_t cv_showstats; -extern consvar_t cv_fancyroulette; -extern consvar_t cv_showlaptimes; -extern consvar_t cv_battlespeedo; -extern consvar_t cv_multiitemicon; -extern consvar_t cv_huditemamount; - -#define NUMSPEEDOSTUFF 8 -extern CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; -#define NUMDGAUGESTUFF 6 -extern CV_PossibleValue_t driftgaugestyle_cons_t[NUMDGAUGESTUFF]; -#define NUMINPUTDISPLAYSTUFF 5 -extern CV_PossibleValue_t inputdisplay_cons_t[NUMINPUTDISPLAYSTUFF]; -#define NUMMINIMAPDOTSTUFF 5 -extern CV_PossibleValue_t minimapdot_cons_t[NUMMINIMAPDOTSTUFF]; - boolean K_IsPlayerLosing(player_t *player); boolean K_IsPlayerWanted(player_t *player); +INT32 K_KartGetItemOdds(UINT8 pos, SINT8 item, fixed_t mashed, boolean spbrush); +INT32 K_FindUseodds(player_t *player, fixed_t mashed, INT32 pingame, INT32 bestbumper, boolean spbrush, boolean dontforcespb); void K_KartBouncing(mobj_t *mobj1, mobj_t *mobj2, boolean bounce, boolean solid); void K_FlipFromObject(mobj_t *mo, mobj_t *master); void K_MatchGenericExtraFlags(mobj_t *mo, mobj_t *master); @@ -115,27 +93,6 @@ void K_PlayOvertakeSound(mobj_t *source); void K_PlayHitEmSound(mobj_t *source, mobj_t *victim); void K_PlayPowerGloatSound(mobj_t *source); -const char *K_GetItemPatch(UINT8 item, boolean tiny); -INT32 K_calcSplitFlags(INT32 snapflags); -void K_LoadKartHUDGraphics(void); -void K_drawKartHUD(void); -void K_drawKartFreePlay(UINT32 flashtime); -void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UINT8 mode); - -typedef struct -{ - INT32 x; - INT32 y; - INT32 flags; -} drawinfo_t; - -patch_t *K_getItemBoxPatch(boolean small, boolean dark); -patch_t *K_getItemMulPatch(boolean small); -void K_getItemBoxDrawinfo(drawinfo_t *out); -INT32 K_getMinimapTrans(void); -void K_getLapsDrawinfo(drawinfo_t *out); -void K_getMinimapDrawinfo(drawinfo_t *out); - #ifdef __cplusplus } // extern "C" #endif diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 3e4ab9da0..059df924c 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -25,6 +25,7 @@ #include "hu_stuff.h" // HU_AddChatText #include "console.h" #include "k_kart.h" // SRB2Kart +#include "k_hud.h" // SRB2Kart #include "d_netcmd.h" // IsPlayerAdmin #include "d_main.h" diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index ff10a34c1..98120cebf 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -24,6 +24,7 @@ #include "w_wad.h" #include "z_zone.h" #include "k_kart.h" +#include "k_hud.h" // SRB2kart #include "lua_script.h" #include "lua_libs.h" diff --git a/src/m_menu.c b/src/m_menu.c index 2b79379f1..bccd6aecc 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -70,6 +70,7 @@ #include "st_stuff.h" #include "i_sound.h" #include "k_kart.h" // SRB2kart +#include "k_hud.h" // SRB2kart #include "k_stats.h" // SRB2kart #include "d_player.h" // KITEM_ constants diff --git a/src/st_stuff.c b/src/st_stuff.c index 7e4dd8840..16a45ea59 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -34,6 +34,7 @@ #include "i_time.h" #include "k_kart.h" // SRB2kart +#include "k_hud.h" //random index #include "m_random.h" diff --git a/src/w_wad.c b/src/w_wad.c index 15d968b87..6490f561d 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -65,6 +65,7 @@ #include "st_stuff.h" #include "m_misc.h" // M_MapNumber #include "p_setup.h" // P_PartialAddFile mayb +#include "k_hud.h" #ifdef HWRENDER #include "r_data.h" diff --git a/src/y_inter.c b/src/y_inter.c index 28d256c8b..068115f4f 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -40,6 +40,7 @@ #include "m_random.h" // M_RandomKey #include "g_input.h" // PLAYER1INPUTDOWN #include "k_kart.h" // colortranslations +#include "k_hud.h" #include "console.h" // cons_menuhighlight #include "lua_hook.h" // IntermissionThinker hook #include "lua_hud.h" // intermission hud hook From 6c94e0c9bf9832004b7313331fb4a1251134d779 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 18:29:45 +0200 Subject: [PATCH 38/43] conflict moment --- src/k_hud.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index 6c0488aae..17f8c1e8d 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -1956,18 +1956,12 @@ static void K_DrawKartPositionNum(INT32 num) INT32 W = kp_positionnum[0][0]->width; fixed_t scale = FRACUNIT; patch_t *localpatch = kp_positionnum[0][0]; - INT32 addOrSub = B_SUBTRACT; INT32 fx = 0, fy = 0, fflags = 0; const INT32 xoffs = wheeloffs ? -48 : 0; boolean flipdraw = false; // flip the order we draw it in for MORE splitscreen bs. fun. boolean flipvdraw = false; // used only for 2p splitscreen so overtaking doesn't make 1P's position fly off the screen. boolean overtake = false; - if ((mapheaderinfo[gamemap - 1]->levelflags & LF_SUBTRACTNUM) == LF_SUBTRACTNUM) - { - addOrSub = B_ADD; - } - if ((cv_posanim.value && stplyr->kartstuff[k_positiondelay]) || stplyr->exiting) { scale *= 2; @@ -2024,12 +2018,14 @@ static void K_DrawKartPositionNum(INT32 num) } // Special case for 0 - if (num <= 0) + if (!num) { - V_DrawBlendingFixedPatch(fx<= 0); // This function does not draw negative numbers + // Draw the number while (num) { @@ -2039,31 +2035,23 @@ static void K_DrawKartPositionNum(INT32 num) } else if (stplyr->laps+1 >= cv_numlaps.value || stplyr->exiting) // Check for the final lap, or won { - boolean useRedNums = K_IsPlayerLosing(stplyr); - - if (addOrSub == B_SUBTRACT) - { - // Subtracting RED will look BLUE, and vice versa. - useRedNums = !useRedNums; - } - // Alternate frame every three frames - switch ((leveltime % 9) / 3) + switch (leveltime % 9) { - case 0: - if (useRedNums == true) + case 1: case 2: case 3: + if (K_IsPlayerLosing(stplyr)) localpatch = kp_positionnum[num % 10][4]; else localpatch = kp_positionnum[num % 10][1]; break; - case 1: - if (useRedNums == true) + case 4: case 5: case 6: + if (K_IsPlayerLosing(stplyr)) localpatch = kp_positionnum[num % 10][5]; else localpatch = kp_positionnum[num % 10][2]; break; - case 2: - if (useRedNums == true) + case 7: case 8: case 9: + if (K_IsPlayerLosing(stplyr)) localpatch = kp_positionnum[num % 10][6]; else localpatch = kp_positionnum[num % 10][3]; @@ -2078,7 +2066,7 @@ static void K_DrawKartPositionNum(INT32 num) localpatch = kp_positionnum[num % 10][0]; } - V_DrawBlendingFixedPatch((fx<width*scale/2) : 0), (fy<height*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL, addOrSub); + V_DrawFixedPatch((fx<width*scale/2) : 0), (fy<height*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL); // ^ if we overtake as p1 or p3 in splitscren, we shift it so that it doesn't go off screen. // ^ if we overtake as p1 in 2p splits, shift vertically so that this doesn't happen either. From 5ca12bb421ecb2708b2e357c6bb2f235ace693e8 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 18:48:46 +0200 Subject: [PATCH 39/43] split replay stuff into g_demo --- src/Sourcefile | 1 + src/g_demo.c | 4063 ++++++++++++++++++++++++++++++++++++++++++ src/g_demo.h | 190 ++ src/g_game.c | 4005 ----------------------------------------- src/g_game.h | 165 +- src/sdl/i_system.cpp | 1 + 6 files changed, 4256 insertions(+), 4169 deletions(-) create mode 100644 src/g_demo.c create mode 100644 src/g_demo.h diff --git a/src/Sourcefile b/src/Sourcefile index b85cbf060..f3cc487c1 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -13,6 +13,7 @@ f_finale.c f_wipe.c filesrch.c g_game.c +g_demo.c g_input.c hu_stuff.c i_tcp.c diff --git a/src/g_demo.c b/src/g_demo.c new file mode 100644 index 000000000..a83cfa438 --- /dev/null +++ b/src/g_demo.c @@ -0,0 +1,4063 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2020 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file g_demo.c +/// \brief Demo recording and playback + +#include "doomdef.h" +#include "console.h" +#include "d_main.h" +#include "d_clisrv.h" +#include "d_player.h" +#include "f_finale.h" +#include "filesrch.h" // for refreshdirmenu +#include "p_setup.h" +#include "p_saveg.h" +#include "i_time.h" +#include "i_system.h" +#include "am_map.h" +#include "m_random.h" +#include "p_local.h" +#include "r_draw.h" +#include "r_main.h" +#include "s_sound.h" +#include "g_game.h" +#include "m_cheat.h" +#include "m_misc.h" +#include "m_menu.h" +#include "m_argv.h" +#include "hu_stuff.h" +#include "st_stuff.h" +#include "z_zone.h" +#include "i_video.h" +#include "byteptr.h" +#include "i_joy.h" +#include "r_local.h" +#include "r_things.h" +#include "y_inter.h" +#include "v_video.h" +#include "dehacked.h" // get_number (for ghost thok) +#include "lua_script.h" // LUA_ArchiveDemo and LUA_UnArchiveDemo +#include "lua_hook.h" +#include "lua_libs.h" // gL (Lua state) +#include "b_bot.h" +#include "m_cond.h" // condition sets +#include "md5.h" // demo checksums +#include "k_director.h" // SRB2kart +#include "k_kart.h" // SRB2kart +#include "k_stats.h" // SRB2kart +#include "r_fps.h" // frame interpolation/uncapped + +#ifdef HAVE_DISCORDRPC +#include "discord.h" +#endif + +// for replay dates +#include +#include + +// menu demo things +UINT8 numDemos = 0; //3; -- i'm FED UP of losing my skincolour to a broken demo. change this back when we make new ones +UINT32 demoDelayTime = 15*TICRATE; +UINT32 demoIdleTime = 3*TICRATE; + +static tic_t demostarttime; // for comparative timing purposes + +//@TODO put these all in a struct for namespacing purposes? +static char demoname[128]; +savebuffer_t demobuf; +static UINT8 *demotime_p, *demoinfo_p; +static UINT8 *demoend; +static UINT8 demoflags; +static boolean demosynced = true; // console warning message + +struct demovars_s demo; + +boolean metalrecording; // recording as metal sonic +mobj_t *metalplayback; +static UINT8 *metalbuffer = NULL; +static UINT8 *metal_p; +static UINT16 metalversion; + +// extra data stuff (events registered this frame while recording) +static struct { + UINT8 flags; // EZT flags + + // EZT_COLOR + UINT8 color, lastcolor; + + // EZT_SCALE + fixed_t scale, lastscale; + + // EZT_KART + INT32 kartitem, kartamount, kartbumpers; + + UINT8 desyncframes; // Don't try to resync unless we've been off for two frames, to monkeypatch a few trouble spots + + // EZT_HIT + UINT16 hits; + mobj_t **hitlist; +} ghostext[MAXPLAYERS]; + +// Your naming conventions are stupid and useless. +// There is no conflict here. +demoghost *ghosts = NULL; + +static CV_PossibleValue_t recordmultiplayerdemos_cons_t[] = {{0, "Disabled"}, {1, "Manual Save"}, {2, "Auto Save"}, {0, NULL}}; +consvar_t cv_recordmultiplayerdemos = {"netdemo_record", "Manual Save", CV_SAVE, recordmultiplayerdemos_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t netdemosyncquality_cons_t[] = {{1, "MIN"}, {35, "MAX"}, {0, NULL}}; +consvar_t cv_netdemosyncquality = {"netdemo_syncquality", "1", CV_SAVE, netdemosyncquality_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// Units are MiB. +static CV_PossibleValue_t maxdemosize_cons_t[] = {{10, "MIN"}, {100, "MAX"}, {0, NULL}}; +consvar_t cv_maxdemosize = {"maxdemosize", "10", CV_SAVE, maxdemosize_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t demochangemap_cons_t[] = {{0, "Disabled"}, {1, "Diff Map"}, {2, "Always"}, {0, NULL}}; +consvar_t cv_demochangemap = {"netdemo_savemapchange", "Disabled", CV_SAVE, demochangemap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t demodateformat_cons_t[] = {{0, "Automatic"}, {1, "EU"}, {2, "US"}, {0, NULL}}; +consvar_t cv_demodateformat = {"netdemo_dateformat", "Automatic", CV_SAVE, demodateformat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +#define DEMOVERSION 0x0002 +#define DEMOHEADER "\xF0" "KartReplay" "\x0F" + +#define DF_GHOST 0x01 // This demo contains ghost data too! +#define DF_RECORDATTACK 0x02 // This demo is from record attack and contains its final completion time! +#define DF_NIGHTSATTACK 0x04 // This demo is from NiGHTS attack and contains its time left, score, and mares! +#define DF_ATTACKMASK 0x06 // This demo is from ??? attack and contains ??? + +#define DF_LUAVARS 0x20 // this demo contains extra lua vars; this is mostly used for backwards compability + +#define DF_ATTACKSHIFT 1 +#define DF_ENCORE 0x40 +#define DF_MULTIPLAYER 0x80 // This demo was recorded in multiplayer mode! + +#ifdef DEMO_COMPAT_100 +#define DF_FILELIST 0x08 // This demo contains an extra files list +#define DF_GAMETYPEMASK 0x30 +#define DF_GAMESHIFT 4 +#endif + +#define DEMO_SPECTATOR 0x40 + +// For demos +#define ZT_FWD 0x01 +#define ZT_SIDE 0x02 +#define ZT_ANGLE 0x04 +#define ZT_BUTTONS 0x08 +#define ZT_AIMING 0x10 +#define ZT_DRIFT 0x20 +#define ZT_LATENCY 0x40 +#define DEMOMARKER 0x80 // demoend + +UINT8 demo_extradata[MAXPLAYERS]; +UINT8 demo_writerng; // 0=no, 1=yes, 2=yes but on a timeout +static ticcmd_t oldcmd[MAXPLAYERS]; + +#define DW_END 0xFF // End of extradata block +#define DW_RNG 0xFE // Check RNG seed! + +#define DW_EXTRASTUFF 0xFE // Numbers below this are reserved for writing player slot data + +// Below consts are only used for demo extrainfo sections +#define DW_STANDING 0x00 + +// For Metal Sonic and time attack ghosts +#define GZT_XYZ 0x01 +#define GZT_MOMXY 0x02 +#define GZT_MOMZ 0x04 +#define GZT_ANGLE 0x08 +// Not used for Metal Sonic +#define GZT_SPRITE 0x10 // Animation frame +#define GZT_EXTRA 0x20 +#define GZT_NIGHTS 0x40 // NiGHTS Mode stuff! + +// GZT_EXTRA flags +#define EZT_THOK 0x01 // Spawned a thok object +#define EZT_SPIN 0x02 // Because one type of thok object apparently wasn't enough +#define EZT_REV 0x03 // And two types wasn't enough either yet +#define EZT_THOKMASK 0x03 +#define EZT_COLOR 0x04 // Changed color (Super transformation, Mario fireflowers/invulnerability, etc.) +#define EZT_FLIP 0x08 // Reversed gravity +#define EZT_SCALE 0x10 // Changed size +#define EZT_HIT 0x20 // Damaged a mobj +#define EZT_SPRITE 0x40 // Changed sprite set completely out of PLAY (NiGHTS, SOCs, whatever) +#define EZT_KART 0x80 // SRB2Kart: Changed current held item/quantity and bumpers for battle + +static mobj_t oldmetal, oldghost[MAXPLAYERS]; + +static void G_ResetDemoPlayback(char *pdemoname); + +void G_SaveMetal(UINT8 **buffer) +{ + I_Assert(buffer != NULL && *buffer != NULL); + + WRITEUINT32(*buffer, metal_p - metalbuffer); +} + +void G_LoadMetal(UINT8 **buffer) +{ + I_Assert(buffer != NULL && *buffer != NULL); + + G_DoPlayMetal(); + metal_p = metalbuffer + READUINT32(*buffer); +} + +ticcmd_t *G_CopyTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n) +{ + return M_Memcpy(dest, src, n*sizeof(*src)); +} + +ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n) +{ + size_t i; + for (i = 0; i < n; i++) + { + dest[i].forwardmove = src[i].forwardmove; + dest[i].sidemove = src[i].sidemove; + dest[i].angleturn = SHORT(src[i].angleturn); + dest[i].aiming = (INT16)SHORT(src[i].aiming); + dest[i].buttons = (UINT16)SHORT(src[i].buttons); + dest[i].driftturn = (INT16)SHORT(src[i].driftturn); + dest[i].latency = (INT16)SHORT(src[i].latency); + } + return dest; +} + +// Finds a skin with the closest stats if the expected skin doesn't exist. +static INT32 GetSkinNumClosestToStats(UINT8 kartspeed, UINT8 kartweight) +{ + INT32 i, closest_skin = 0; + UINT8 closest_stats = UINT8_MAX, stat_diff; + + for (i = 0; i < numskins; i++) + { + stat_diff = abs(skins[i].kartspeed - kartspeed) + abs(skins[i].kartweight - kartweight); + if (stat_diff < closest_stats) + { + closest_stats = stat_diff; + closest_skin = i; + } + } + + return closest_skin; +} + +static void FindClosestSkinForStats(UINT32 p, UINT8 kartspeed, UINT8 kartweight) +{ + INT32 closest_skin = GetSkinNumClosestToStats(kartspeed, kartweight); + + //CONS_Printf("Using %s instead...\n", skins[closest_skin].name); + SetPlayerSkinByNum(p, closest_skin); +} + +void G_ReadDemoExtraData(void) +{ + INT32 p, extradata, i; + char name[17]; + + if (leveltime > starttime) + { + rewind_t *rewind = CL_SaveRewindPoint(demobuf.p - demobuf.buffer); + if (rewind) + { + memcpy(rewind->oldcmd, oldcmd, sizeof (oldcmd)); + memcpy(rewind->oldghost, oldghost, sizeof (oldghost)); + } + } + + memset(name, '\0', 17); + + p = READUINT8(demobuf.p); + + while (p < DW_EXTRASTUFF) + { + extradata = READUINT8(demobuf.p); + + if (extradata & DXD_RESPAWN) + { + if (players[p].mo) + P_DamageMobj(players[p].mo, NULL, NULL, DMG_INSTAKILL); // Is this how this should work..? + } + if (extradata & DXD_SKIN) + { + UINT8 kartspeed, kartweight; + + // Skin + M_Memcpy(name, demobuf.p, 16); + demobuf.p += 16; + SetPlayerSkin(p, name); + + kartspeed = READUINT8(demobuf.p); + kartweight = READUINT8(demobuf.p); + + if (stricmp(skins[players[p].skin].name, name) != 0) + FindClosestSkinForStats(p, kartspeed, kartweight); + + players[p].kartspeed = kartspeed; + players[p].kartweight = kartweight; + } + if (extradata & DXD_COLOR) + { + // Color + M_Memcpy(name, demobuf.p, 16); + demobuf.p += 16; + for (i = 0; i < MAXSKINCOLORS; i++) + if (!stricmp(KartColor_Names[i], name)) // SRB2kart + { + players[p].skincolor = i; + if (players[p].mo) + players[p].mo->color = i; + break; + } + } + if (extradata & DXD_NAME) + { + // Name + M_Memcpy(player_names[p],demobuf.p,16); + demobuf.p += 16; + } + if (extradata & DXD_PLAYSTATE) + { + extradata = READUINT8(demobuf.p); + + switch (extradata) { + case DXD_PST_PLAYING: + players[p].pflags |= PF_WANTSTOJOIN; // fuck you + break; + + case DXD_PST_SPECTATING: + players[p].pflags &= ~PF_WANTSTOJOIN; // double-fuck you + if (!playeringame[p]) + { + CL_ClearPlayer(p); + playeringame[p] = true; + G_AddPlayer(p); + players[p].spectator = true; + + // There's likely an off-by-one error in timing recording or playback of joins. This hacks around it so I don't have to find out where that is. \o/ + if (oldcmd[p].forwardmove) + P_RandomByte(); + } + else + { + players[p].spectator = true; + if (players[p].mo) + P_DamageMobj(players[p].mo, NULL, NULL, DMG_INSTAKILL); + else + players[p].playerstate = PST_REBORN; + } + break; + + case DXD_PST_LEFT: + CL_RemovePlayer(p, 0); + break; + } + + G_ResetViews(); + + // maybe these are necessary? + if (G_BattleGametype()) + K_CheckBumpers(); // SRB2Kart + else if (G_RaceGametype()) + P_CheckRacers(); // also SRB2Kart + } + + + p = READUINT8(demobuf.p); + } + + while (p != DW_END) + { + UINT32 rng; + UINT32 checkrng; + + switch (p) + { + case DW_RNG: + rng = READUINT32(demobuf.p); + checkrng = P_GetRandSeed(); + if (checkrng != rng) + { + if (demosynced) + { + CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced (RNG)!\n")); + CONS_Printf("expected rng %d got %d\n", rng, checkrng); + } + demosynced = false; + + P_SetRandSeed(rng); + } + } + + p = READUINT8(demobuf.p); + } + + if (!(demoflags & DF_GHOST) && *demobuf.p == DEMOMARKER) + { + // end of demo data stream + G_CheckDemoStatus(); + return; + } +} + +void G_WriteDemoExtraData(void) +{ + INT32 i; + char name[17]; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (demo_extradata[i]) + { + WRITEUINT8(demobuf.p, i); + WRITEUINT8(demobuf.p, demo_extradata[i]); + + //if (demo_extradata[i] & DXD_RESPAWN) has no extra data + if (demo_extradata[i] & DXD_SKIN) + { + // Skin + memset(name, 0, 16); + strncpy(name, skins[players[i].skin].name, 16); + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; + + WRITEUINT8(demobuf.p, skins[players[i].skin].kartspeed); + WRITEUINT8(demobuf.p, skins[players[i].skin].kartweight); + } + if (demo_extradata[i] & DXD_COLOR) + { + // Color + memset(name, 0, 16); + strncpy(name, KartColor_Names[players[i].skincolor], 16); + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; + } + if (demo_extradata[i] & DXD_NAME) + { + // Name + memset(name, 0, 16); + memcpy(name, player_names[i], 15); // Keeping 1 null byte for safety, sorry players with name containing more than 15 characters + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; + } + if (demo_extradata[i] & DXD_PLAYSTATE) + { + demo_writerng = 1; + if (!playeringame[i]) + WRITEUINT8(demobuf.p, DXD_PST_LEFT); + else if ( + players[i].spectator && + !(players[i].pflags & PF_WANTSTOJOIN) // <= fuck you specifically + ) + WRITEUINT8(demobuf.p, DXD_PST_SPECTATING); + else + WRITEUINT8(demobuf.p, DXD_PST_PLAYING); + } + } + + demo_extradata[i] = 0; + } + + // May not be necessary, but might as well play it safe... + if ((leveltime & 255) == 128) + demo_writerng = 1; + + { + static UINT8 timeout = 0; + + if (timeout) timeout--; + + if (demo_writerng == 1 || (demo_writerng == 2 && timeout == 0)) + { + demo_writerng = 0; + timeout = 16; + WRITEUINT8(demobuf.p, DW_RNG); + WRITEUINT32(demobuf.p, P_GetRandSeed()); + } + } + + WRITEUINT8(demobuf.p, DW_END); +} + +void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum) +{ + UINT8 ziptic; + + if (!demobuf.p || !demo.deferstart) + return; + ziptic = READUINT8(demobuf.p); + + if (ziptic & ZT_FWD) + oldcmd[playernum].forwardmove = READSINT8(demobuf.p); + if (ziptic & ZT_SIDE) + oldcmd[playernum].sidemove = READSINT8(demobuf.p); + if (ziptic & ZT_ANGLE) + oldcmd[playernum].angleturn = READINT16(demobuf.p); + if (ziptic & ZT_BUTTONS) + oldcmd[playernum].buttons = READUINT16(demobuf.p); + if (ziptic & ZT_AIMING) + oldcmd[playernum].aiming = READINT16(demobuf.p); + if (ziptic & ZT_DRIFT) + oldcmd[playernum].driftturn = READINT16(demobuf.p); + if (ziptic & ZT_LATENCY) + oldcmd[playernum].latency = READUINT8(demobuf.p); + + G_CopyTiccmd(cmd, &oldcmd[playernum], 1); + + // SRB2kart: Copy-pasted from ticcmd building, removes that crappy demo cam + if (((players[displayplayers[0]].mo && players[displayplayers[0]].speed > 0) // Moving + || (leveltime > starttime && (cmd->buttons & BT_ACCELERATE && cmd->buttons & BT_BRAKE)) // Rubber-burn turn + || (players[displayplayers[0]].kartstuff[k_respawn]) // Respawning + || (players[displayplayers[0]].spectator || objectplacing)) // Not a physical player + && !(players[displayplayers[0]].kartstuff[k_spinouttimer] && players[displayplayers[0]].kartstuff[k_sneakertimer])) // Spinning and boosting cancels out spinout + localangle[0] += (cmd->angleturn<<16); + + if (!(demoflags & DF_GHOST) && *demobuf.p == DEMOMARKER) + { + // end of demo data stream + G_CheckDemoStatus(); + return; + } +} + +void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum) +{ + char ziptic = 0; + UINT8 *ziptic_p; + + if (!demobuf.p) + return; + + ziptic_p = demobuf.p++; // the ziptic, written at the end of this function + + if (cmd->forwardmove != oldcmd[playernum].forwardmove) + { + WRITEUINT8(demobuf.p,cmd->forwardmove); + oldcmd[playernum].forwardmove = cmd->forwardmove; + ziptic |= ZT_FWD; + } + + if (cmd->sidemove != oldcmd[playernum].sidemove) + { + WRITEUINT8(demobuf.p,cmd->sidemove); + oldcmd[playernum].sidemove = cmd->sidemove; + ziptic |= ZT_SIDE; + } + + if (cmd->angleturn != oldcmd[playernum].angleturn) + { + WRITEINT16(demobuf.p,cmd->angleturn); + oldcmd[playernum].angleturn = cmd->angleturn; + ziptic |= ZT_ANGLE; + } + + if (cmd->buttons != oldcmd[playernum].buttons) + { + WRITEUINT16(demobuf.p,cmd->buttons); + oldcmd[playernum].buttons = cmd->buttons; + ziptic |= ZT_BUTTONS; + } + + if (cmd->aiming != oldcmd[playernum].aiming) + { + WRITEINT16(demobuf.p,cmd->aiming); + oldcmd[playernum].aiming = cmd->aiming; + ziptic |= ZT_AIMING; + } + + if (cmd->driftturn != oldcmd[playernum].driftturn) + { + WRITEINT16(demobuf.p,cmd->driftturn); + oldcmd[playernum].driftturn = cmd->driftturn; + ziptic |= ZT_DRIFT; + } + + if (cmd->latency != oldcmd[playernum].latency) + { + WRITEUINT8(demobuf.p,cmd->latency); + oldcmd[playernum].latency = cmd->latency; + ziptic |= ZT_LATENCY; + } + + *ziptic_p = ziptic; + + // attention here for the ticcmd size! + // latest demos with mouse aiming byte in ticcmd + if (!(demoflags & DF_GHOST) && ziptic_p > demoend - 9) + { + G_CheckDemoStatus(); // no more space + return; + } +} + +void G_GhostAddThok(INT32 playernum) +{ + if (!demo.recording || !(demoflags & DF_GHOST)) + return; + + ghostext[playernum].flags = (ghostext[playernum].flags & ~EZT_THOKMASK) | EZT_THOK; +} + +void G_GhostAddSpin(INT32 playernum) +{ + if (!demo.recording || !(demoflags & DF_GHOST)) + return; + + ghostext[playernum].flags = (ghostext[playernum].flags & ~EZT_THOKMASK) | EZT_SPIN; +} + +void G_GhostAddRev(INT32 playernum) +{ + if (!demo.recording || !(demoflags & DF_GHOST)) + return; + + ghostext[playernum].flags = (ghostext[playernum].flags & ~EZT_THOKMASK) | EZT_REV; +} + +void G_GhostAddFlip(INT32 playernum) +{ + if (!demo.recording || !(demoflags & DF_GHOST)) + return; + + ghostext[playernum].flags |= EZT_FLIP; +} + +void G_GhostAddColor(INT32 playernum, ghostcolor_t color) +{ + if (!demo.recording || !(demoflags & DF_GHOST)) + return; + + if (ghostext[playernum].lastcolor == (UINT8)color) + { + ghostext[playernum].flags &= ~EZT_COLOR; + return; + } + + ghostext[playernum].flags |= EZT_COLOR; + ghostext[playernum].color = (UINT8)color; +} + +void G_GhostAddScale(INT32 playernum, fixed_t scale) +{ + if (!demo.recording || !(demoflags & DF_GHOST)) + return; + + if (ghostext[playernum].lastscale == scale) + { + ghostext[playernum].flags &= ~EZT_SCALE; + return; + } + + ghostext[playernum].flags |= EZT_SCALE; + ghostext[playernum].scale = scale; +} + +void G_GhostAddHit(INT32 playernum, mobj_t *victim) +{ + if (!demo.recording || !(demoflags & DF_GHOST)) + return; + + ghostext[playernum].flags |= EZT_HIT; + ghostext[playernum].hits++; + ghostext[playernum].hitlist = Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_LEVEL, &ghostext[playernum].hitlist); + P_SetTarget(ghostext[playernum].hitlist + (ghostext[playernum].hits-1), victim); +} + +void G_WriteAllGhostTics(void) +{ + if (!demobuf.p) + return; + + UINT8 *save_demo_p = demobuf.p; +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } + + boolean toobig = false; + INT32 i, counter = leveltime; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + continue; + + if (P_MobjWasRemoved(players[i].mo)) + continue; + + counter++; + + if (multiplayer && ((counter % cv_netdemosyncquality.value) != 0)) // Only write 1 in this many ghost datas per tic to cut down on multiplayer replay size. + continue; + + if (((ghostext[i].flags && (ghostext[i].flags & EZT_HIT)) || ghostext[i].hits) + && !ghostext[i].hitlist) // hitlist might be freed during resynch, beware PU_LEVEL! + { + ghostext[i].hits = 0; + continue; + } + + CHECKSPACE(1); + + WRITEUINT8(demobuf.p, i); + G_WriteGhostTic(players[i].mo, i); + + // attention here for the ticcmd size! + // latest demos with mouse aiming byte in ticcmd + if (demobuf.p >= demoend - (13 + 9 + 9)) + { + toobig = true; + break; + } + } + + CHECKSPACE(1); + WRITEUINT8(demobuf.p, 0xFF); + + if (toobig) + { + G_CheckDemoStatus(); // no more space + return; + } + +#undef CHECKSPACE +} + +void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) +{ + char ziptic = 0; + UINT8 *ziptic_p; + UINT32 i; + UINT8 sprite; + UINT8 frame; + + if (!demobuf.p) + return; + + UINT8 *save_demo_p = demobuf.p; +#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } + + if (!(demoflags & DF_GHOST)) + return; // No ghost data to write. + + if (ghost->player && ghost->player->pflags & PF_NIGHTSMODE && ghost->tracer) + { + // We're talking about the NiGHTS thing, not the normal platforming thing! + ziptic |= GZT_NIGHTS; + ghost = ghost->tracer; + } + + ziptic_p = demobuf.p++; // the ziptic, written at the end of this function + +#define MAXMOM (0x7FFF<<8) + + // GZT_XYZ is only useful if you've moved 256 FRACUNITS or more in a single tic. + if (abs(ghost->x-oldghost[playernum].x) > MAXMOM + || abs(ghost->y-oldghost[playernum].y) > MAXMOM + || abs(ghost->z-oldghost[playernum].z) > MAXMOM + || ((UINT8)(leveltime & 255) > 0 && (UINT8)(leveltime & 255) <= (UINT8)cv_netdemosyncquality.value)) // Hack to enable slightly nicer resyncing + { + oldghost[playernum].x = ghost->x; + oldghost[playernum].y = ghost->y; + oldghost[playernum].z = ghost->z; + ziptic |= GZT_XYZ; + + CHECKSPACE(sizeof(fixed_t)*3); + WRITEFIXED(demobuf.p, oldghost[playernum].x); + WRITEFIXED(demobuf.p, oldghost[playernum].y); + WRITEFIXED(demobuf.p, oldghost[playernum].z); + } + else + { + // For moving normally: + // Store one full byte of movement, plus one byte of fractional movement. + INT16 momx = (INT16)((ghost->x-oldghost[playernum].x + (1<<4))>>8); + INT16 momy = (INT16)((ghost->y-oldghost[playernum].y + (1<<4))>>8); + + if (momx != oldghost[playernum].momx + || momy != oldghost[playernum].momy) + { + oldghost[playernum].momx = momx; + oldghost[playernum].momy = momy; + ziptic |= GZT_MOMXY; + + CHECKSPACE(4); + + WRITEINT16(demobuf.p, momx); + WRITEINT16(demobuf.p, momy); + } + + momx = (INT16)((ghost->z-oldghost[playernum].z + (1<<4))>>8); + + if (momx != oldghost[playernum].momz) + { + oldghost[playernum].momz = momx; + ziptic |= GZT_MOMZ; + + CHECKSPACE(2); + + WRITEINT16(demobuf.p, momx); + } + + // This SHOULD set oldghost.x/y/z to match ghost->x/y/z + // but it keeps the fractional loss of one byte, + // so it will hopefully be made up for in future tics. + oldghost[playernum].x += oldghost[playernum].momx<<8; + oldghost[playernum].y += oldghost[playernum].momy<<8; + oldghost[playernum].z += oldghost[playernum].momz<<8; + } + +#undef MAXMOM + + // Only store the 8 most relevant bits of angle + // because exact values aren't too easy to discern to begin with when only 8 angles have different sprites + // and it does not affect this mode of movement at all anyway. + if (ghost->angle>>24 != oldghost[playernum].angle) + { + oldghost[playernum].angle = ghost->angle>>24; + ziptic |= GZT_ANGLE; + + CHECKSPACE(1); + + WRITEUINT8(demobuf.p, oldghost[playernum].angle); + } + + // Store the sprite frame. + frame = ghost->frame & 0xFF; + if (frame != oldghost[playernum].frame) + { + oldghost[playernum].frame = frame; + ziptic |= GZT_SPRITE; + + CHECKSPACE(1); + + WRITEUINT8(demobuf.p, oldghost[playernum].frame); + } + + // Check for sprite set changes + sprite = ghost->sprite; + if (sprite != oldghost[playernum].sprite) + { + oldghost[playernum].sprite = sprite; + ghostext[playernum].flags |= EZT_SPRITE; + } + + if (ghost->player) + { + if ( + ghostext[playernum].kartitem != ghost->player->kartstuff[k_itemtype] || + ghostext[playernum].kartamount != ghost->player->kartstuff[k_itemamount] || + ghostext[playernum].kartbumpers != ghost->player->kartstuff[k_bumper] + ) + { + ghostext[playernum].flags |= EZT_KART; + ghostext[playernum].kartitem = ghost->player->kartstuff[k_itemtype]; + ghostext[playernum].kartamount = ghost->player->kartstuff[k_itemamount]; + ghostext[playernum].kartbumpers = ghost->player->kartstuff[k_bumper]; + + } + } + + if (ghostext[playernum].color == ghostext[playernum].lastcolor) + ghostext[playernum].flags &= ~EZT_COLOR; + + if (ghostext[playernum].scale == ghostext[playernum].lastscale) + ghostext[playernum].flags &= ~EZT_SCALE; + + if (ghostext[playernum].flags) + { + ziptic |= GZT_EXTRA; + WRITEUINT8(demobuf.p, ghostext[playernum].flags); + + if (ghostext[playernum].flags & EZT_COLOR) + { + CHECKSPACE(1); + WRITEUINT8(demobuf.p, ghostext[playernum].color); + ghostext[playernum].lastcolor = ghostext[playernum].color; + } + + if (ghostext[playernum].flags & EZT_SCALE) + { + CHECKSPACE(sizeof(fixed_t)); + WRITEFIXED(demobuf.p, ghostext[playernum].scale); + ghostext[playernum].lastscale = ghostext[playernum].scale; + } + + if (ghostext[playernum].flags & EZT_HIT) + { + CHECKSPACE(2); + WRITEUINT16(demobuf.p, ghostext[playernum].hits); + + for (i = 0; i < ghostext[playernum].hits; i++) + { + mobj_t *mo = ghostext[playernum].hitlist[i]; + + CHECKSPACE(4+4+2+sizeof(fixed_t)*3+sizeof(angle_t)); + + WRITEUINT32(demobuf.p, UINT32_MAX); // reserved for some method of determining exactly which mobj this is. (mobjnum doesn't work here.) + WRITEUINT32(demobuf.p, mo->type); + WRITEUINT16(demobuf.p, (UINT16)mo->health); + WRITEFIXED(demobuf.p, mo->x); + WRITEFIXED(demobuf.p, mo->y); + WRITEFIXED(demobuf.p, mo->z); + WRITEANGLE(demobuf.p, mo->angle); + P_SetTarget(ghostext[playernum].hitlist+i, NULL); + } + + ghostext[playernum].hits = 0; + } + + if (ghostext[playernum].flags & EZT_SPRITE) + { + CHECKSPACE(1); + WRITEUINT8(demobuf.p, sprite); + } + + if (ghostext[playernum].flags & EZT_KART) + { + CHECKSPACE(12); + WRITEINT32(demobuf.p, ghostext[playernum].kartitem); + WRITEINT32(demobuf.p, ghostext[playernum].kartamount); + WRITEINT32(demobuf.p, ghostext[playernum].kartbumpers); + } + + ghostext[playernum].flags = 0; + } + + *ziptic_p = ziptic; +#undef CHECKSPACE +} + +void G_ConsAllGhostTics(void) +{ + UINT8 p; + + if (!demobuf.p || !demo.deferstart) + return; + + p = READUINT8(demobuf.p); + + while (p != 0xFF) + { + G_ConsGhostTic(p); + p = READUINT8(demobuf.p); + } + + if (*demobuf.p == DEMOMARKER) + { + // end of demo data stream + G_CheckDemoStatus(); + return; + } +} + +// Uses ghost data to do consistency checks on your position. +// This fixes desynchronising demos when fighting eggman. +void G_ConsGhostTic(INT32 playernum) +{ + UINT8 ziptic; + fixed_t px,py,pz,gx,gy,gz; + mobj_t *testmo; + fixed_t syncleeway; + boolean nightsfail = false; + + if (!(demoflags & DF_GHOST)) + return; // No ghost data to use. + + testmo = players[playernum].mo; + + // Grab ghost data. + ziptic = READUINT8(demobuf.p); + + if (ziptic & GZT_XYZ) + { + oldghost[playernum].x = READFIXED(demobuf.p); + oldghost[playernum].y = READFIXED(demobuf.p); + oldghost[playernum].z = READFIXED(demobuf.p); + syncleeway = 0; + } + else + { + if (ziptic & GZT_MOMXY) + { + oldghost[playernum].momx = READINT16(demobuf.p)<<8; + oldghost[playernum].momy = READINT16(demobuf.p)<<8; + } + + if (ziptic & GZT_MOMZ) + oldghost[playernum].momz = READINT16(demobuf.p)<<8; + + oldghost[playernum].x += oldghost[playernum].momx; + oldghost[playernum].y += oldghost[playernum].momy; + oldghost[playernum].z += oldghost[playernum].momz; + syncleeway = FRACUNIT; + } + + if (ziptic & GZT_ANGLE) + demobuf.p++; + + if (ziptic & GZT_SPRITE) + demobuf.p++; + + if (ziptic & GZT_NIGHTS) + { + if (!testmo || !testmo->player || !(testmo->player->pflags & PF_NIGHTSMODE) || !testmo->tracer) + nightsfail = true; + else + testmo = testmo->tracer; + } + + if (ziptic & GZT_EXTRA) + { // But wait, there's more! + ziptic = READUINT8(demobuf.p); + if (ziptic & EZT_COLOR) + demobuf.p++; + + if (ziptic & EZT_SCALE) + demobuf.p += sizeof(fixed_t); + + if (ziptic & EZT_HIT) + { // Resync mob damage. + UINT16 i, count = READUINT16(demobuf.p); + thinker_t *th; + mobj_t *mobj; + + UINT32 type; + UINT16 health; + fixed_t x; + fixed_t y; + fixed_t z; + + for (i = 0; i < count; i++) + { + demobuf.p += 4; // reserved. + type = READUINT32(demobuf.p); + health = READUINT16(demobuf.p); + x = READFIXED(demobuf.p); + y = READFIXED(demobuf.p); + z = READFIXED(demobuf.p); + demobuf.p += sizeof(angle_t); // angle, unnecessary for cons. + + mobj = NULL; + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + mobj = (mobj_t *)th; + if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) + break; + mobj = NULL; // wasn't this one, keep searching. + } + + if (mobj && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! + { + if (demosynced) + { + CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced (health)!\n")); + CONS_Printf("expected health %d got %d\n", health, mobj->health); + } + + demosynced = false; + P_DamageMobj(mobj, players[0].mo, players[0].mo, 1); + } + } + } + + if (ziptic & EZT_SPRITE) + demobuf.p++; + + if (ziptic & EZT_KART) + { + ghostext[playernum].kartitem = READINT32(demobuf.p); + ghostext[playernum].kartamount = READINT32(demobuf.p); + ghostext[playernum].kartbumpers = READINT32(demobuf.p); + } + } + + if (testmo) + { + // Re-synchronise + px = testmo->x; + py = testmo->y; + pz = testmo->z; + gx = oldghost[playernum].x; + gy = oldghost[playernum].y; + gz = oldghost[playernum].z; + + if (nightsfail || abs(px-gx) > syncleeway || abs(py-gy) > syncleeway || abs(pz-gz) > syncleeway) + { + ghostext[playernum].desyncframes++; + + if (ghostext[playernum].desyncframes >= 2) + { + if (demosynced) + CONS_Alert(CONS_WARNING, "Demo playback has desynced (player %s)!\n", player_names[playernum]); + demosynced = false; + + P_UnsetThingPosition(testmo); + testmo->x = oldghost[playernum].x; + testmo->y = oldghost[playernum].y; + P_SetThingPosition(testmo); + testmo->z = oldghost[playernum].z; + + if (abs(testmo->z - testmo->floorz) < 4*FRACUNIT) + testmo->z = testmo->floorz; // Sync players to the ground when they're likely supposed to be there... + + ghostext[playernum].desyncframes = 2; + } + } + else + ghostext[playernum].desyncframes = 0; + + if ( +#ifdef DEMO_COMPAT_100 + demo.version != 0x0001 && +#endif + ( + players[playernum].kartstuff[k_itemtype] != ghostext[playernum].kartitem || + players[playernum].kartstuff[k_itemamount] != ghostext[playernum].kartamount || + players[playernum].kartstuff[k_bumper] != ghostext[playernum].kartbumpers + ) + ) + { + if (demosynced) + { + CONS_Alert(CONS_WARNING, "Demo playback has desynced (item/bumpers)!(player %s)!\n", player_names[playernum]); + CONS_Printf("expected item type %d got %d\n", ghostext[playernum].kartitem, players[playernum].kartstuff[k_itemtype]); + CONS_Printf("expected item amount %d got %d\n", ghostext[playernum].kartamount, players[playernum].kartstuff[k_itemamount]); + } + demosynced = false; + + players[playernum].kartstuff[k_itemtype] = ghostext[playernum].kartitem; + players[playernum].kartstuff[k_itemamount] = ghostext[playernum].kartamount; + players[playernum].kartstuff[k_bumper] = ghostext[playernum].kartbumpers; + } + } + + if (*demobuf.p == DEMOMARKER) + { + // end of demo data stream + G_CheckDemoStatus(); + return; + } +} + +void G_GhostTicker(void) +{ + demoghost *g,*p; + + for (g = ghosts, p = NULL; g; g = g->next) + { + // Skip normal demo data. + UINT8 ziptic = READUINT8(g->p); + +#ifdef DEMO_COMPAT_100 + if (g->version != 0x0001) + { +#endif + while (ziptic != DW_END) // Get rid of extradata stuff + { + if (ziptic == 0) // Only support player 0 info for now + { + ziptic = READUINT8(g->p); + if (ziptic & DXD_SKIN) + g->p += 18; // We _could_ read this info, but it shouldn't change anything in record attack... + if (ziptic & DXD_COLOR) + g->p += 16; // Same tbh + if (ziptic & DXD_NAME) + g->p += 16; // yea + if (ziptic & DXD_PLAYSTATE && READUINT8(g->p) != DXD_PST_PLAYING) + I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this + } + else if (ziptic == DW_RNG) + g->p += 4; // RNG seed + else + I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this + + ziptic = READUINT8(g->p); + } + + ziptic = READUINT8(g->p); // Back to actual ziptic stuff +#ifdef DEMO_COMPAT_100 + } +#endif + + if (ziptic & ZT_FWD) + g->p++; + if (ziptic & ZT_SIDE) + g->p++; + if (ziptic & ZT_ANGLE) + g->p += 2; + if (ziptic & ZT_BUTTONS) + g->p += 2; + if (ziptic & ZT_AIMING) + g->p += 2; + if (ziptic & ZT_DRIFT) + g->p += 2; + if (ziptic & ZT_LATENCY) + g->p += 1; + + // Grab ghost data. + ziptic = READUINT8(g->p); + +#ifdef DEMO_COMPAT_100 + if (g->version != 0x0001) + { +#endif + if (ziptic == 0xFF) + goto skippedghosttic; // Didn't write ghost info this frame + else if (ziptic != 0) + I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this + ziptic = READUINT8(g->p); +#ifdef DEMO_COMPAT_100 + } +#endif + if (ziptic & GZT_XYZ) + { + g->oldmo.x = READFIXED(g->p); + g->oldmo.y = READFIXED(g->p); + g->oldmo.z = READFIXED(g->p); + } + else + { + if (ziptic & GZT_MOMXY) + { + g->oldmo.momx = READINT16(g->p)<<8; + g->oldmo.momy = READINT16(g->p)<<8; + } + if (ziptic & GZT_MOMZ) + g->oldmo.momz = READINT16(g->p)<<8; + g->oldmo.x += g->oldmo.momx; + g->oldmo.y += g->oldmo.momy; + g->oldmo.z += g->oldmo.momz; + } + if (ziptic & GZT_ANGLE) + g->oldmo.angle = READUINT8(g->p)<<24; + if (ziptic & GZT_SPRITE) + g->oldmo.frame = READUINT8(g->p); + + // Update ghost + P_UnsetThingPosition(g->mo); + g->mo->x = g->oldmo.x; + g->mo->y = g->oldmo.y; + g->mo->z = g->oldmo.z; + P_SetThingPosition(g->mo); + g->mo->angle = g->oldmo.angle; + g->mo->frame = g->oldmo.frame | tr_trans30<p); + if (ziptic & EZT_COLOR) + { + g->color = READUINT8(g->p); + switch(g->color) + { + default: + case GHC_NORMAL: // Go back to skin color + g->mo->color = g->oldmo.color; + break; + // Handled below + case GHC_SUPER: + case GHC_INVINCIBLE: + break; + case GHC_FIREFLOWER: // Fireflower + g->mo->color = SKINCOLOR_WHITE; + break; + } + } + if (ziptic & EZT_FLIP) + g->mo->eflags ^= MFE_VERTICALFLIP; + if (ziptic & EZT_SCALE) + { + g->mo->destscale = READFIXED(g->p); + if (g->mo->destscale != g->mo->scale) + P_SetScale(g->mo, g->mo->destscale); + } + if (ziptic & EZT_THOKMASK) + { // Let's only spawn ONE of these per frame, thanks. + mobj_t *mobj; + INT32 type = -1; + if (g->mo->skin) + { + switch (ziptic & EZT_THOKMASK) + { + case EZT_THOK: + type = (UINT32)mobjinfo[MT_PLAYER].painchance; + break; + case EZT_SPIN: + type = (UINT32)mobjinfo[MT_PLAYER].damage; + break; + case EZT_REV: + type = (UINT32)mobjinfo[MT_PLAYER].raisestate; + break; + } + } + if (type != -1) + { + if (type == MT_GHOST) + { + mobj = P_SpawnGhostMobj(g->mo); // does a large portion of the work for us + mobj->frame = (mobj->frame & ~FF_FRAMEMASK)|tr_trans60<mo->x, g->mo->y, g->mo->z - FixedDiv(FixedMul(g->mo->info->height, g->mo->scale) - g->mo->height,3*FRACUNIT), MT_THOK); + mobj->sprite = states[mobjinfo[type].spawnstate].sprite; + mobj->frame = (states[mobjinfo[type].spawnstate].frame & FF_FRAMEMASK) | tr_trans60<tics = -1; // nope. + mobj->color = g->mo->color; + if (g->mo->eflags & MFE_VERTICALFLIP) + { + mobj->flags2 |= MF2_OBJECTFLIP; + mobj->eflags |= MFE_VERTICALFLIP; + } + P_SetScale(mobj, g->mo->scale); + mobj->destscale = g->mo->scale; + } + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_UnsetThingPosition(mobj); + mobj->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... + P_SetThingPosition(mobj); + mobj->fuse = 8; + P_SetTarget(&mobj->target, g->mo); + } + } + if (ziptic & EZT_HIT) + { // Spawn hit poofs for killing things! + UINT16 i, count = READUINT16(g->p), health; + //UINT32 type; + fixed_t x,y,z; + angle_t angle; + mobj_t *poof; + for (i = 0; i < count; i++) + { + g->p += 4; // reserved + g->p += 4; // backwards compat., type used to be here + health = READUINT16(g->p); + x = READFIXED(g->p); + y = READFIXED(g->p); + z = READFIXED(g->p); + angle = READANGLE(g->p); + if (health != 0 || i >= 4) // only spawn for the first 4 hits per frame, to prevent ghosts from splode-spamming too bad. + continue; + poof = P_SpawnMobj(x, y, z, MT_GHOST); + poof->angle = angle; + poof->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... + poof->health = 0; + P_SetMobjStateNF(poof, S_XPLD1); + } + } + if (ziptic & EZT_SPRITE) + g->mo->sprite = READUINT8(g->p); + if (ziptic & EZT_KART) + g->p += 12; // kartitem, kartamount, kartbumpers + } + +#ifdef DEMO_COMPAT_100 + if (g->version != 0x0001) + { +#endif + if (READUINT8(g->p) != 0xFF) // Make sure there isn't other ghost data here. + I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this +#ifdef DEMO_COMPAT_100 + } +#endif + +skippedghosttic: + // Tick ghost colors (Super and Mario Invincibility flashing) + switch(g->color) + { + case GHC_SUPER: // Super Sonic (P_DoSuperStuff) + g->mo->color = SKINCOLOR_SUPER1; + g->mo->color += abs( ( (signed)( (unsigned)leveltime >> 1 ) % 9) - 4); + break; + case GHC_INVINCIBLE: // Mario invincibility (P_CheckInvincibilityTimer) + g->mo->color = (UINT8)(leveltime % MAXSKINCOLORS); + break; + default: + break; + } + + // Demo ends after ghost data. + if (*g->p == DEMOMARKER) + { + g->mo->momx = g->mo->momy = g->mo->momz = 0; + if (p) + p->next = g->next; + else + ghosts = g->next; + Z_Free(g); + continue; + } + p = g; + } +} + +// Demo rewinding functions +typedef struct rewindinfo_s { + tic_t leveltime; + + struct { + boolean ingame; + player_t player; + mobj_t mobj; + } playerinfo[MAXPLAYERS]; + + struct rewindinfo_s *prev; +} rewindinfo_t; + +static tic_t currentrewindnum; +static rewindinfo_t *rewindhead = NULL; // Reverse chronological order + +void G_InitDemoRewind(void) +{ + CL_ClearRewinds(); + + while (rewindhead) + { + rewindinfo_t *p = rewindhead->prev; + Z_Free(rewindhead); + rewindhead = p; + } + + currentrewindnum = 0; +} + +void G_StoreRewindInfo(void) +{ + static UINT8 timetolog = 8; + rewindinfo_t *info; + size_t i; + + if (timetolog-- > 0) + return; + timetolog = 8; + + info = Z_Calloc(sizeof(rewindinfo_t), PU_STATIC, NULL); + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + { + info->playerinfo[i].ingame = false; + continue; + } + + info->playerinfo[i].ingame = true; + memcpy(&info->playerinfo[i].player, &players[i], sizeof(player_t)); + if (players[i].mo) + memcpy(&info->playerinfo[i].mobj, players[i].mo, sizeof(mobj_t)); + } + + info->leveltime = leveltime; + info->prev = rewindhead; + rewindhead = info; +} + +void G_PreviewRewind(tic_t previewtime) +{ + SINT8 i; + size_t j; + fixed_t tweenvalue = 0; + rewindinfo_t *info = rewindhead, *next_info = rewindhead; + + if (!info) + return; + + while (info->leveltime > previewtime && info->prev) + { + next_info = info; + info = info->prev; + } + if (info != next_info) + tweenvalue = FixedDiv(previewtime - info->leveltime, next_info->leveltime - info->leveltime); + + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + { + if (info->playerinfo[i].player.mo) + { + //@TODO spawn temp object to act as a player display + } + + continue; + } + + if (!info->playerinfo[i].ingame || !info->playerinfo[i].player.mo) + { + if (players[i].mo) + players[i].mo->flags2 |= MF2_DONTDRAW; + + continue; + } + + if (!players[i].mo) + continue; //@TODO spawn temp object to act as a player display + + players[i].mo->flags2 &= ~MF2_DONTDRAW; + + P_UnsetThingPosition(players[i].mo); +#define TWEEN(pr) info->playerinfo[i].mobj.pr + FixedMul((INT32) (next_info->playerinfo[i].mobj.pr - info->playerinfo[i].mobj.pr), tweenvalue) + players[i].mo->x = TWEEN(x); + players[i].mo->y = TWEEN(y); + players[i].mo->z = TWEEN(z); + players[i].mo->angle = TWEEN(angle); +#undef TWEEN + P_SetThingPosition(players[i].mo); + + players[i].frameangle = info->playerinfo[i].player.frameangle + FixedMul((INT32) (next_info->playerinfo[i].player.frameangle - info->playerinfo[i].player.frameangle), tweenvalue); + + players[i].mo->sprite = info->playerinfo[i].mobj.sprite; + players[i].mo->frame = info->playerinfo[i].mobj.frame; + + players[i].realtime = info->playerinfo[i].player.realtime; + for (j = 0; j < NUMKARTSTUFF; j++) + players[i].kartstuff[j] = info->playerinfo[i].player.kartstuff[j]; + } + + for (i = splitscreen; i >= 0; i--) + P_ResetCamera(&players[displayplayers[i]], &camera[i]); +} + +void G_ConfirmRewind(tic_t rewindtime) +{ + SINT8 i; + tic_t j; + boolean oldmenuactive = menuactive, oldsounddisabled = sound_disabled; + + INT32 olddp1 = displayplayers[0], olddp2 = displayplayers[1], olddp3 = displayplayers[2], olddp4 = displayplayers[3]; + UINT8 oldss = splitscreen; + + menuactive = false; // Prevent loops + + CV_StealthSetValue(&cv_renderview, 0); + + if (rewindtime <= starttime) + { + demo.rewinding = false; + G_DoPlayDemo(NULL); // Restart the current demo + } + else + { + rewind_t *rewind; + sound_disabled = true; // Prevent sound spam + demo.rewinding = true; + + rewind = CL_RewindToTime(rewindtime); + + if (rewind) + { + demobuf.p = demobuf.buffer + rewind->demopos; + memcpy(oldcmd, rewind->oldcmd, sizeof (oldcmd)); + memcpy(oldghost, rewind->oldghost, sizeof (oldghost)); + paused = false; + } + else + { + demo.rewinding = true; + G_DoPlayDemo(NULL); // Restart the current demo + } + } + + for (j = 0; j < rewindtime && leveltime < rewindtime; j++) + { + G_Ticker((j % NEWTICRATERATIO) == 0); + } + + demo.rewinding = false; + menuactive = oldmenuactive; // Bring the menu back up + sound_disabled = oldsounddisabled; // Re-enable SFX + + wipegamestate = gamestate; // No fading back in! + + COM_BufInsertText("renderview on\n"); + + splitscreen = oldss; + displayplayers[0] = olddp1; + displayplayers[1] = olddp2; + displayplayers[2] = olddp3; + displayplayers[3] = olddp4; + R_ExecuteSetViewSize(); + G_ResetViews(); + + for (i = splitscreen; i >= 0; i--) + P_ResetCamera(&players[displayplayers[i]], &camera[i]); +} + +void G_ReadMetalTic(mobj_t *metal) +{ + UINT8 ziptic; + UINT16 speed; + UINT8 statetype; + + if (!metal_p) + return; + ziptic = READUINT8(metal_p); + + // Read changes from the tic + if (ziptic & GZT_XYZ) + { + oldmetal.x = READFIXED(metal_p); + oldmetal.y = READFIXED(metal_p); + oldmetal.z = READFIXED(metal_p); + P_MoveOrigin(metal, oldmetal.x, oldmetal.y, oldmetal.z); + oldmetal.x = metal->x; + oldmetal.y = metal->y; + oldmetal.z = metal->z; + } + else + { + if (ziptic & GZT_MOMXY) + { + oldmetal.momx = READINT16(metal_p)<<8; + oldmetal.momy = READINT16(metal_p)<<8; + } + if (ziptic & GZT_MOMZ) + oldmetal.momz = READINT16(metal_p)<<8; + oldmetal.x += oldmetal.momx; + oldmetal.y += oldmetal.momy; + oldmetal.z += oldmetal.momz; + } + if (ziptic & GZT_ANGLE) + oldmetal.angle = READUINT8(metal_p)<<24; + if (ziptic & GZT_SPRITE) + metal_p++; // Currently unused. (Metal Sonic figures out what he's doing his own damn self.) + + // Set movement, position, and angle + // oldmetal contains where you're supposed to be. + metal->momx = oldmetal.momx; + metal->momy = oldmetal.momy; + metal->momz = oldmetal.momz; + P_UnsetThingPosition(metal); + metal->x = oldmetal.x; + metal->y = oldmetal.y; + metal->z = oldmetal.z; + P_SetThingPosition(metal); + metal->angle = oldmetal.angle; + + if (ziptic & GZT_EXTRA) + { // But wait, there's more! + ziptic = READUINT8(metal_p); + if (ziptic & EZT_FLIP) + metal->eflags ^= MFE_VERTICALFLIP; + if (ziptic & EZT_SCALE) + { + metal->destscale = READFIXED(metal_p); + if (metal->destscale != metal->scale) + P_SetScale(metal, metal->destscale); + } + } + + // Calculates player's speed based on distance-of-a-line formula + speed = FixedDiv(P_AproxDistance(oldmetal.momx, oldmetal.momy), metal->scale)>>FRACBITS; + + // Use speed to decide an appropriate state + if (speed > 20) // default skin runspeed + statetype = 2; + else if (speed > 1) // stopspeed + statetype = 1; + else + statetype = 0; + + // Set state + if (statetype != metal->threshold) + { + switch (statetype) + { + case 2: // run + P_SetMobjState(metal,metal->info->meleestate); + break; + case 1: // walk + P_SetMobjState(metal,metal->info->seestate); + break; + default: // stand + P_SetMobjState(metal,metal->info->spawnstate); + break; + } + metal->threshold = statetype; + } + + // TODO: Modify state durations based on movement speed, similar to players? + + if (*metal_p == DEMOMARKER) + { + // end of demo data stream + G_StopMetalDemo(); + return; + } +} + +void G_WriteMetalTic(mobj_t *metal) +{ + UINT8 ziptic = 0; + UINT8 *ziptic_p; + + if (!demobuf.p) // demobuf.p will be NULL until the race start linedef executor is triggered! + return; + + ziptic_p = demobuf.p++; // the ziptic, written at the end of this function + + #define MAXMOM (0xFFFF<<8) + + // GZT_XYZ is only useful if you've moved 256 FRACUNITS or more in a single tic. + if (abs(metal->x-oldmetal.x) > MAXMOM + || abs(metal->y-oldmetal.y) > MAXMOM + || abs(metal->z-oldmetal.z) > MAXMOM) + { + oldmetal.x = metal->x; + oldmetal.y = metal->y; + oldmetal.z = metal->z; + WRITEFIXED(demobuf.p,oldmetal.x); + WRITEFIXED(demobuf.p,oldmetal.y); + WRITEFIXED(demobuf.p,oldmetal.z); + ziptic |= GZT_XYZ; + } + else + { + // For moving normally: + // Store one full byte of movement, plus one byte of fractional movement. + INT16 momx = (INT16)((metal->x-oldmetal.x)>>8); + INT16 momy = (INT16)((metal->y-oldmetal.y)>>8); + if (momx != oldmetal.momx + || momy != oldmetal.momy) + { + oldmetal.momx = momx; + oldmetal.momy = momy; + WRITEINT16(demobuf.p,momx); + WRITEINT16(demobuf.p,momy); + ziptic |= GZT_MOMXY; + } + momx = (INT16)((metal->z-oldmetal.z)>>8); + if (momx != oldmetal.momz) + { + oldmetal.momz = momx; + WRITEINT16(demobuf.p,momx); + ziptic |= GZT_MOMZ; + } + + // This SHOULD set oldmetal.x/y/z to match metal->x/y/z + // but it keeps the fractional loss of one byte, + // so it will hopefully be made up for in future tics. + oldmetal.x += oldmetal.momx<<8; + oldmetal.y += oldmetal.momy<<8; + oldmetal.z += oldmetal.momz<<8; + } + + #undef MAXMOM + + // Only store the 8 most relevant bits of angle + // because exact values aren't too easy to discern to begin with when only 8 angles have different sprites + // and it does not affect movement at all anyway. + if (metal->angle>>24 != oldmetal.angle) + { + oldmetal.angle = metal->angle>>24; + WRITEUINT8(demobuf.p,oldmetal.angle); + ziptic |= GZT_ANGLE; + } + + // Metal Sonic does not need our state changes. + // ... currently. + + { + UINT8 *exttic_p = NULL; + UINT8 exttic = 0; + if ((metal->eflags & MFE_VERTICALFLIP) != (oldmetal.eflags & MFE_VERTICALFLIP)) + { + if (!exttic_p) + exttic_p = demobuf.p++; + exttic |= EZT_FLIP; + oldmetal.eflags ^= MFE_VERTICALFLIP; + } + if (metal->scale != oldmetal.scale) + { + if (!exttic_p) + exttic_p = demobuf.p++; + exttic |= EZT_SCALE; + WRITEFIXED(demobuf.p,metal->scale); + oldmetal.scale = metal->scale; + } + if (exttic_p) + { + *exttic_p = exttic; + ziptic |= GZT_EXTRA; + } + } + + *ziptic_p = ziptic; + + // attention here for the ticcmd size! + // latest demos with mouse aiming byte in ticcmd + if (demobuf.p >= demoend - 32) + { + G_StopMetalRecording(); // no more space + return; + } +} + +// +// G_RecordDemo +// +void G_RecordDemo(const char *name) +{ + INT32 maxsize; + + demobuf.p = NULL; + G_ResetDemoRecording(); + demoend = NULL; + + if (cv_recordmultiplayerdemos.value) + { + CONS_Printf("Recording demo %s.lmp\n", name); + + strcpy(demoname, name); + strcat(demoname, ".lmp"); + + maxsize = cv_maxdemosize.value*1024*1024; + + demobuf.buffer = Z_Malloc(maxsize + 100*1024, PU_STATIC, NULL); + demoend = demobuf.buffer + maxsize; + + if (demobuf.buffer) + demo.recording = true; + else + CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); + } +} + +void G_RecordMetal(void) +{ + INT32 maxsize; + maxsize = cv_maxdemosize.value*1024*1024; + if (demobuf.buffer) + Z_Free(demobuf.buffer); + demobuf.p = NULL; + metalrecording = false; + demobuf.buffer = Z_Malloc(maxsize + 100*1024, PU_STATIC, NULL); + demoend = demobuf.buffer + maxsize; + + if (demobuf.buffer) + metalrecording = true; + else + CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); +} + +void G_BeginRecording(void) +{ + UINT8 i, p; + char name[17]; + player_t *player = &players[consoleplayer]; + + char *filename; + UINT8 totalfiles; + UINT8 *m; + + if (!cv_recordmultiplayerdemos.value) + { + G_ResetDemoRecording(); + return; + } + + if (demobuf.buffer == NULL) + { + CONS_Alert(CONS_ERROR, "No demo buffer allocated\n"); + G_ResetDemoRecording(); + return; + } + + if (demobuf.p) + { + G_ResetDemoRecording(); + return; + } + + memset(name,0,sizeof(name)); + + demobuf.p = demobuf.buffer; + demoflags = DF_GHOST|(multiplayer ? DF_MULTIPLAYER : (modeattacking<important) + { + nameonly(( filename = va("%s", wadfiles[i]->filename) )); + WRITESTRINGL(demobuf.p, filename, MAX_WADPATH); + WRITEMEM(demobuf.p, wadfiles[i]->md5sum, 16); + + totalfiles++; + } + + WRITEUINT8(m, totalfiles); + + switch ((demoflags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) + { + case ATTACKING_NONE: // 0 + break; + case ATTACKING_RECORD: // 1 + demotime_p = demobuf.p; + WRITEUINT32(demobuf.p,UINT32_MAX); // time + WRITEUINT32(demobuf.p,UINT32_MAX); // lap + break; + default: // 3 + break; + } + + WRITEUINT32(demobuf.p, P_GetInitSeed()); + + // Reserved for extrainfo location from start of file + demoinfo_p = demobuf.p; + WRITEUINT32(demobuf.p, 0); + + // Save netvars + CV_SaveNetVars(&demobuf.p, true); + + // Now store some info for each in-game player + for (p = 0; p < MAXPLAYERS; p++) + { + if (!playeringame[p]) + continue; + + player = &players[p]; + + WRITEUINT8(demobuf.p, p | (player->spectator ? DEMO_SPECTATOR : 0)); + + // Name + memset(name, 0, 16); + memcpy(name, player_names[p], 15); + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; + + // Skin + memset(name, 0, 16); + strncpy(name, skins[player->skin].name, 16); + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; + + // Color + memset(name, 0, 16); + strncpy(name, KartColor_Names[player->skincolor], 16); + M_Memcpy(demobuf.p,name,16); + demobuf.p += 16; + + // Score, since Kart uses this to determine where you start on the map + WRITEUINT32(demobuf.p, player->score); + + // Kart speed and weight + WRITEUINT8(demobuf.p, skins[player->skin].kartspeed); + WRITEUINT8(demobuf.p, skins[player->skin].kartweight); + } + + WRITEUINT8(demobuf.p, 0xFF); // Denote the end of the player listing + + // player lua vars, always saved even if empty... Unless it's record attack. + if (demoflags & DF_LUAVARS) + LUA_Archive(&demobuf, false); + + memset(&oldcmd,0,sizeof(oldcmd)); + memset(&oldghost,0,sizeof(oldghost)); + memset(&ghostext,0,sizeof(ghostext)); + + for (i = 0; i < MAXPLAYERS; i++) + { + ghostext[i].lastcolor = ghostext[i].color = GHC_NORMAL; + ghostext[i].lastscale = ghostext[i].scale = FRACUNIT; + + if (players[i].mo) + { + oldghost[i].x = players[i].mo->x; + oldghost[i].y = players[i].mo->y; + oldghost[i].z = players[i].mo->z; + oldghost[i].angle = players[i].mo->angle; + + // preticker started us gravity flipped + if (players[i].mo->eflags & MFE_VERTICALFLIP) + ghostext[i].flags |= EZT_FLIP; + } + } +} + +void G_BeginMetal(void) +{ + mobj_t *mo = players[consoleplayer].mo; + + if (demobuf.buffer == NULL) + { + CONS_Alert(CONS_ERROR, "No metal demo buffer allocated\n"); + metalrecording = false; + return; + } + + if (demobuf.p) + { + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; + metalrecording = false; + return; + } + + demobuf.p = demobuf.buffer; + + // Write header. + M_Memcpy(demobuf.p, DEMOHEADER, 12); demobuf.p += 12; + WRITEUINT8(demobuf.p,VERSION); + WRITEUINT8(demobuf.p,SUBVERSION); + WRITEUINT16(demobuf.p,DEMOVERSION); + + // demo checksum + demobuf.p += 16; + + M_Memcpy(demobuf.p, "METL", 4); demobuf.p += 4; + + // Set up our memory. + memset(&oldmetal,0,sizeof(oldmetal)); + oldmetal.x = mo->x; + oldmetal.y = mo->y; + oldmetal.z = mo->z; + oldmetal.angle = mo->angle; +} + +void G_WriteStanding(UINT8 ranking, char *name, INT32 skinnum, UINT8 color, UINT32 val) +{ + char temp[17]; + + if (!demobuf.p) + return; + + if (demoinfo_p && *(UINT32 *)demoinfo_p == 0 && demobuf.buffer != NULL) + { + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker + *(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer; + } + + WRITEUINT8(demobuf.p, DW_STANDING); + WRITEUINT8(demobuf.p, ranking); + + // Name + memset(temp, 0, 16); + strncpy(temp, name, 16); + M_Memcpy(demobuf.p,temp,16); + demobuf.p += 16; + + // Skin + memset(temp, 0, 16); + strncpy(temp, skins[skinnum].name, 16); + M_Memcpy(demobuf.p,temp,16); + demobuf.p += 16; + + // Color + memset(temp, 0, 16); + strncpy(temp, KartColor_Names[color], 16); + M_Memcpy(demobuf.p,temp,16); + demobuf.p += 16; + + // Score/time/whatever + WRITEUINT32(demobuf.p, val); +} + +void G_SetDemoTime(UINT32 ptime, UINT32 plap) +{ + if (!demo.recording || !demotime_p) + return; + if (demoflags & DF_RECORDATTACK) + { + WRITEUINT32(demotime_p, ptime); + WRITEUINT32(demotime_p, plap); + demotime_p = NULL; + } +} + +static void G_LoadDemoExtraFiles(UINT8 **pp) +{ + UINT8 totalfiles; + char filename[MAX_WADPATH]; + UINT8 md5sum[16]; + filestatus_t ncs = FS_NOTFOUND; + boolean toomany = false; + boolean alreadyloaded; + UINT8 i, j; + + totalfiles = READUINT8((*pp)); + for (i = 0; i < totalfiles; ++i) + { + if (toomany) + SKIPSTRING((*pp)); + else + { + strlcpy(filename, (char *)(*pp), sizeof filename); + SKIPSTRING((*pp)); + } + READMEM((*pp), md5sum, 16); + + if (!toomany) + { + alreadyloaded = false; + + for (j = 0; j < numwadfiles; ++j) + { + if (memcmp(md5sum, wadfiles[j]->md5sum, 16) == 0) + { + alreadyloaded = true; + break; + } + } + + if (alreadyloaded) + continue; + + if (numwadfiles >= MAX_WADFILES) + toomany = true; + else + ncs = findfile(filename, md5sum, false); + + if (toomany) + { + CONS_Alert(CONS_WARNING, M_GetText("Too many files loaded to add anymore for demo playback\n")); + if (!CON_Ready()) + M_StartMessage(M_GetText("There are too many files loaded to add this demo's addons.\n\nDemo playback may desync.\n\nPress ESC\n"), NULL, MM_NOTHING); + } + else if (ncs != FS_FOUND) + { + if (ncs == FS_NOTFOUND) + CONS_Alert(CONS_NOTICE, M_GetText("You do not have a copy of %s\n"), filename); + else if (ncs == FS_MD5SUMBAD) + CONS_Alert(CONS_NOTICE, M_GetText("Checksum mismatch on %s\n"), filename); + else + CONS_Alert(CONS_NOTICE, M_GetText("Unknown error finding file %s\n"), filename); + + if (!CON_Ready()) + M_StartMessage(M_GetText("There were errors trying to add this demo's addons. Check the console for more information.\n\nDemo playback may desync.\n\nPress ESC\n"), NULL, MM_NOTHING); + } + else + { + P_PartialAddWadFile(filename, false); + } + } + } + + if (P_PartialAddGetStage() >= 0) + P_MultiSetupWadFiles(true); // in case any partial adds were done +} + +static void G_SkipDemoExtraFiles(UINT8 **pp) +{ + UINT8 totalfiles; + UINT8 i; + + totalfiles = READUINT8((*pp)); + for (i = 0; i < totalfiles; ++i) + { + SKIPSTRING((*pp));// file name + (*pp) += 16;// md5 + } +} + +// G_CheckDemoExtraFiles: checks if our loaded WAD list matches the demo's. +// Enabling quick prevents filesystem checks to see if needed files are available to load. +static UINT8 G_CheckDemoExtraFiles(UINT8 **pp, boolean quick) +{ + UINT8 totalfiles, filesloaded, nmusfilecount; + char filename[MAX_WADPATH]; + UINT8 md5sum[16]; + boolean toomany = false; + boolean alreadyloaded; + UINT8 i, j; + UINT8 error = 0; + + totalfiles = READUINT8((*pp)); + filesloaded = 0; + for (i = 0; i < totalfiles; ++i) + { + if (toomany) + SKIPSTRING((*pp)); + else + { + strlcpy(filename, (char *)(*pp), sizeof filename); + SKIPSTRING((*pp)); + } + READMEM((*pp), md5sum, 16); + + if (!toomany) + { + alreadyloaded = false; + nmusfilecount = 0; + + for (j = 0; j < numwadfiles; ++j) + { + if (wadfiles[j]->important && j > mainwads) + nmusfilecount++; + else + continue; + + if (memcmp(md5sum, wadfiles[j]->md5sum, 16) == 0) + { + alreadyloaded = true; + + if (i != nmusfilecount-1 && error < DFILE_ERROR_OUTOFORDER) + error |= DFILE_ERROR_OUTOFORDER; + + break; + } + } + + if (alreadyloaded) + { + filesloaded++; + continue; + } + + if (numwadfiles >= MAX_WADFILES) + error = DFILE_ERROR_CANNOTLOAD; + else if (!quick && findfile(filename, md5sum, false) != FS_FOUND) + error = DFILE_ERROR_CANNOTLOAD; + else if (error < DFILE_ERROR_INCOMPLETEOUTOFORDER) + error |= DFILE_ERROR_NOTLOADED; + } else + error = DFILE_ERROR_CANNOTLOAD; + } + + // Get final file count + nmusfilecount = 0; + + for (j = 0; j < numwadfiles; ++j) + if (wadfiles[j]->important && j > mainwads) + nmusfilecount++; + + if (!error && filesloaded < nmusfilecount) + error = DFILE_ERROR_EXTRAFILES; + + return error; +} + +// Returns bitfield: +// 1 == new demo has lower time +// 2 == new demo has higher score +// 4 == new demo has higher rings +UINT8 G_CmpDemoTime(char *oldname, char *newname) +{ + UINT8 *buffer,*p; + UINT8 flags; + UINT32 oldtime, newtime, oldlap, newlap; + UINT16 oldversion; + size_t bufsize ATTRUNUSED; + UINT8 c; + UINT16 s ATTRUNUSED; + UINT8 aflags = 0; + + // load the new file + FIL_DefaultExtension(newname, ".lmp"); + bufsize = FIL_ReadFile(newname, &buffer); + I_Assert(bufsize != 0); + p = buffer; + + // read demo header + I_Assert(!memcmp(p, DEMOHEADER, 12)); + p += 12; // DEMOHEADER + c = READUINT8(p); // VERSION + I_Assert(c == VERSION); + c = READUINT8(p); // SUBVERSION + I_Assert(c == SUBVERSION); + s = READUINT16(p); + I_Assert(s == DEMOVERSION); + p += 64; // full demo title + p += 16; // demo checksum + I_Assert(!memcmp(p, "PLAY", 4)); + p += 4; // PLAY + p += 2; // gamemap + p += 16; // map md5 + flags = READUINT8(p); // demoflags + p++; // gametype + G_SkipDemoExtraFiles(&p); + + aflags = flags & (DF_RECORDATTACK|DF_NIGHTSATTACK); + I_Assert(aflags); + if (flags & DF_RECORDATTACK) + { + newtime = READUINT32(p); + newlap = READUINT32(p); + } + else // appease compiler + return 0; + + Z_Free(buffer); + + // load old file + FIL_DefaultExtension(oldname, ".lmp"); + if (!FIL_ReadFile(oldname, &buffer)) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), oldname); + return UINT8_MAX; + } + p = buffer; + + // read demo header + if (memcmp(p, DEMOHEADER, 12)) + { + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } p += 12; // DEMOHEADER + p++; // VERSION + p++; // SUBVERSION + oldversion = READUINT16(p); + switch(oldversion) // demoversion + { + case DEMOVERSION: // latest always supported + p += 64; // full demo title + break; +#ifdef DEMO_COMPAT_100 + case 0x0001: + // Old replays gotta go :] + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' outdated version. It will be overwritten. Nyeheheh.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; +#endif + // too old, cannot support. + default: + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } + p += 16; // demo checksum + if (memcmp(p, "PLAY", 4)) + { + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } p += 4; // "PLAY" + p += 2; // gamemap + p += 16; // mapmd5 + flags = READUINT8(p); + p++; // gametype + G_SkipDemoExtraFiles(&p); + if (!(flags & aflags)) + { + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' not from same game mode. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } + if (flags & DF_RECORDATTACK) + { + oldtime = READUINT32(p); + oldlap = READUINT32(p); + } + else // appease compiler + return UINT8_MAX; + + Z_Free(buffer); + + c = 0; + if (newtime < oldtime + || (newtime == oldtime && (newlap < oldlap))) + c |= 1; // Better time + if (newlap < oldlap + || (newlap == oldlap && newtime < oldtime)) + c |= 1<<1; // Better lap time + return c; +} + +void G_LoadDemoInfo(menudemo_t *pdemo) +{ + UINT8 *infobuffer, *info_p, *extrainfo_p; + UINT8 version, subversion, pdemoflags; + UINT16 pdemoversion, count; + + if (!FIL_ReadFile(pdemo->filepath, &infobuffer)) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), pdemo->filepath); + pdemo->type = MD_INVALID; + sprintf(pdemo->title, "INVALID REPLAY"); + + return; + } + + info_p = infobuffer; + + if (memcmp(info_p, DEMOHEADER, 12)) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemo->filepath); + pdemo->type = MD_INVALID; + sprintf(pdemo->title, "INVALID REPLAY"); + Z_Free(infobuffer); + return; + } + + pdemo->type = MD_LOADED; + + info_p += 12; // DEMOHEADER + + version = READUINT8(info_p); + subversion = READUINT8(info_p); + pdemoversion = READUINT16(info_p); + + memset(pdemo->version, 0, sizeof(pdemo->version)); + snprintf(pdemo->version, sizeof(pdemo->version), "v%d.%d", version, subversion); + + switch(pdemoversion) + { + case DEMOVERSION: // latest always supported + // demo title + M_Memcpy(pdemo->title, info_p, 64); + info_p += 64; + + break; +#ifdef DEMO_COMPAT_100 + case 0x0001: + pdemo->type = MD_OUTDATED; + sprintf(pdemo->title, "Legacy Replay"); + break; +#endif + // too old, cannot support. + default: + CONS_Alert(CONS_ERROR, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemo->filepath); + pdemo->type = MD_INVALID; + sprintf(pdemo->title, "INVALID REPLAY"); + Z_Free(infobuffer); + return; + } + + if (version != VERSION || subversion != SUBVERSION) + pdemo->type = MD_OUTDATED; + + info_p += 16; // demo checksum + if (memcmp(info_p, "PLAY", 4)) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is the wrong type of recording and cannot be played.\n"), pdemo->filepath); + pdemo->type = MD_INVALID; + sprintf(pdemo->title, "INVALID REPLAY"); + Z_Free(infobuffer); + return; + } + info_p += 4; // "PLAY" + pdemo->map = READINT16(info_p); + info_p += 16; // mapmd5 + + pdemoflags = READUINT8(info_p); + + // temp? + if (!(pdemoflags & DF_MULTIPLAYER)) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is not a multiplayer replay and can't be listed on this menu fully yet.\n"), pdemo->filepath); + Z_Free(infobuffer); + return; + } +#ifdef DEMO_COMPAT_100 + else if (pdemoversion == 0x0001) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is a legacy multiplayer replay and cannot be played.\n"), pdemo->filepath); + pdemo->type = MD_INVALID; + sprintf(pdemo->title, "INVALID REPLAY"); + Z_Free(infobuffer); + return; + } +#endif + + pdemo->gametype = READUINT8(info_p); + + pdemo->addonstatus = G_CheckDemoExtraFiles(&info_p, true); + info_p += 4; // RNG seed + + extrainfo_p = infobuffer + READUINT32(info_p); + + // Pared down version of CV_LoadNetVars to find the kart speed + pdemo->kartspeed = 1; // Default to normal speed + count = READUINT16(info_p); + while (count--) + { + UINT16 netid; + char *svalue; + + netid = READUINT16(info_p); + svalue = (char *)info_p; + SKIPSTRING(info_p); + info_p++; // stealth + + if (netid == cv_kartspeed.netid) + { + UINT8 j; + for (j = 0; kartspeed_cons_t[j].strvalue; j++) + if (!stricmp(kartspeed_cons_t[j].strvalue, svalue)) + pdemo->kartspeed = kartspeed_cons_t[j].value; + } + else if (netid == cv_basenumlaps.netid && pdemo->gametype == GT_RACE) + pdemo->numlaps = atoi(svalue); + } + + if (pdemoflags & DF_ENCORE) + pdemo->kartspeed |= DF_ENCORE; + + // Read standings! + count = 0; + + while (READUINT8(extrainfo_p) == DW_STANDING) // Assume standings are always first in the extrainfo + { + INT32 i; + char temp[16]; + + pdemo->standings[count].ranking = READUINT8(extrainfo_p); + + // Name + M_Memcpy(pdemo->standings[count].name, extrainfo_p, 16); + extrainfo_p += 16; + + // Skin + M_Memcpy(temp,extrainfo_p,16); + extrainfo_p += 16; + pdemo->standings[count].skin = UINT8_MAX; + for (i = 0; i < numskins; i++) + if (stricmp(skins[i].name, temp) == 0) + { + pdemo->standings[count].skin = i; + break; + } + + // Color + M_Memcpy(temp,extrainfo_p,16); + extrainfo_p += 16; + for (i = 0; i < MAXSKINCOLORS; i++) + if (!stricmp(KartColor_Names[i],temp)) // SRB2kart + { + pdemo->standings[count].color = i; + break; + } + + // Score/time/whatever + pdemo->standings[count].timeorscore = READUINT32(extrainfo_p); + + count++; + + if (count >= MAXPLAYERS) + break; //@TODO still cycle through the rest of these if extra demo data is ever used + } + + // I think that's everything we need? + Z_Free(infobuffer); +} + +#if defined (_WIN32) +// return the file creation time +// useful for demos that were renamed +static long G_GetCreationTime(char *filepath) +{ + struct stat fileinfo; + + if (stat(filepath, &fileinfo) == 0) + return fileinfo.st_ctime; + + return 0; +} +#endif + +static char *G_GetDemoDate(menudemo_t *pdemo) +{ + char *datetime; + datetime = malloc(sizeof(pdemo->date)); // mallocma balls + + // no mallocma balls... :c + if (!datetime) + { + return NULL; + } + + time_t file_time = 0; + + // get le filepath + char *filename; + filename = strdup(pdemo->filepath); + +#if defined (_WIN32) + if (!filename) + { + // if we cant get a filename try just getting the file create time + file_time = G_GetCreationTime(pdemo->filepath); + goto skipfilenametime; + } +#else + if (!filename) + { + free(datetime); + return NULL; + } +#endif + + // get the actual filename Zzz... + nameonly(filename); + + // convert it to long Zzz.... + file_time = strtol(filename, NULL, 10); + free(filename); // dont need this anymore a + +#if defined (_WIN32) +skipfilenametime: +#endif + + // then throw it into localtime to get an actual human readable format lmao + struct tm *tm_buf = NULL; + tm_buf = localtime(&file_time); + + // cant believe we ended up in 1970 + if (tm_buf == NULL || tm_buf->tm_year <= 110) + { +#if defined (_WIN32) + // uh ohh, we got an invalid time + // try one more time getting the creation time + file_time = G_GetCreationTime(pdemo->filepath); + tm_buf = localtime(&file_time); + + if (tm_buf == NULL || tm_buf->tm_year <= 110) + { + free(datetime); + return NULL; + } + + goto gotcreationtime; +#else + free(datetime); + return NULL; +#endif + } + +#if defined (_WIN32) +gotcreationtime: +#endif + + const char *format; + + // US ppl are special (: + if (cv_demodateformat.value == 2) + format = "%m.%d.%Y"; + else if (cv_demodateformat.value == 1) + format = "%d.%m.%Y"; + else + format = strstr(setlocale(LC_TIME, NULL), "en_US") ? "%m.%d.%Y" : "%d.%m.%Y"; + + strftime(datetime, sizeof(pdemo->date), format, tm_buf); + + return datetime; +} + +void G_LoadDemoTitle(menudemo_t *pdemo) +{ + UINT8 infobuffer[96], *info_p; + UINT16 pdemoversion; + size_t count; + + FILE *handle = fopen(pdemo->filepath, "rb"); + + if (!handle) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), pdemo->filepath); + sprintf(pdemo->title, "INVALID REPLAY"); + return; + } + + count = fread(infobuffer, 1, 96, handle); + fclose(handle); + info_p = infobuffer; + + // First check isn't too accurate technically, but well, valid replays should be larger than that anyway + if (count < 96 || memcmp(info_p, DEMOHEADER, 12)) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemo->filepath); + sprintf(pdemo->title, "INVALID REPLAY"); + return; + } + + info_p += 12; // DEMOHEADER + + READUINT8(info_p); + READUINT8(info_p); + pdemoversion = READUINT16(info_p); + + memset(pdemo->date, 0, sizeof(pdemo->date)); + + switch(pdemoversion) + { + case DEMOVERSION: // latest always supported + // demo title + M_Memcpy(pdemo->title, info_p, 64); + + // demo date + char *demodate; + demodate = G_GetDemoDate(pdemo); + if (demodate) + strncpy(pdemo->date, demodate, sizeof(pdemo->date)); + free(demodate); + break; +#ifdef DEMO_COMPAT_100 + case 0x0001: + sprintf(pdemo->title, "Legacy Replay"); + break; +#endif + // too old, cannot support. + default: + CONS_Alert(CONS_ERROR, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemo->filepath); + sprintf(pdemo->title, "INVALID REPLAY"); + } +} + +// +// G_PlayDemo +// +void G_DeferedPlayDemo(const char *name) +{ + COM_BufAddText("playdemo \""); + COM_BufAddText(name); + COM_BufAddText("\" -addfiles\n"); +} + +// +// Start a demo from a .LMP file or from a wad resource +// +#define SKIPERRORS +void G_DoPlayDemo(char *defdemoname) +{ + UINT8 i, p; + lumpnum_t l; + char skin[17],color[17],*n,*pdemoname; + UINT8 version,subversion; + UINT32 randseed; + char msg[1024]; +#if defined(SKIPERRORS) && !defined(DEVELOP) + boolean skiperrors = false; +#endif + boolean spectator; + UINT8 slots[MAXPLAYERS], kartspeed[MAXPLAYERS], kartweight[MAXPLAYERS], numslots = 0; + + G_InitDemoRewind(); + + skin[16] = '\0'; + color[16] = '\0'; + + // No demo name means we're restarting the current demo + if (defdemoname == NULL) + { + demobuf.p = demobuf.buffer; + pdemoname = ZZ_Alloc(1); // Easier than adding checks for this everywhere it's freed + } + else + { + n = defdemoname+strlen(defdemoname); + while (*n != '/' && *n != '\\' && n != defdemoname) + n--; + if (n != defdemoname) + n++; + pdemoname = ZZ_Alloc(strlen(n)+1); + strcpy(pdemoname,n); + + M_SetPlaybackMenuPointer(); + + // Internal if no extension, external if one exists + if (FIL_CheckExtension(defdemoname)) + { + //FIL_DefaultExtension(defdemoname, ".lmp"); + if (!FIL_ReadFile(defdemoname, &demobuf.buffer)) + { + snprintf(msg, 1024, M_GetText("Failed to read file '%s'.\n"), defdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + gameaction = ga_nothing; + M_StartMessage(msg, NULL, MM_NOTHING); + return; + } + demobuf.p = demobuf.buffer; + } + // load demo resource from WAD + else if ((l = W_CheckNumForName(defdemoname)) == LUMPERROR) + { + snprintf(msg, 1024, M_GetText("Failed to read lump '%s'.\n"), defdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + gameaction = ga_nothing; + M_StartMessage(msg, NULL, MM_NOTHING); + return; + } + else // it's an internal demo + { + demobuf.buffer = demobuf.p = W_CacheLumpNum(l, PU_STATIC); +#if defined(SKIPERRORS) && !defined(DEVELOP) + skiperrors = true; // SRB2Kart: Don't print warnings for staff ghosts, since they'll inevitably happen when we make bugfixes/changes... +#endif + } + } + + // read demo header + gameaction = ga_nothing; + demo.playback = true; + if (memcmp(demobuf.p, DEMOHEADER, 12)) + { + snprintf(msg, 1024, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + demobuf.p += 12; // DEMOHEADER + + version = READUINT8(demobuf.p); + subversion = READUINT8(demobuf.p); + demo.version = READUINT16(demobuf.p); + switch(demo.version) + { + case DEMOVERSION: // latest always supported + // demo title + M_Memcpy(demo.titlename, demobuf.p, 64); + demobuf.p += 64; + + break; +#ifdef DEMO_COMPAT_100 + case 0x0001: + break; +#endif + // too old, cannot support. + default: + snprintf(msg, 1024, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + demobuf.p += 16; // demo checksum + if (memcmp(demobuf.p, "PLAY", 4)) + { + snprintf(msg, 1024, M_GetText("%s is the wrong type of recording and cannot be played.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + demobuf.p += 4; // "PLAY" + gamemap = READINT16(demobuf.p); + demobuf.p += 16; // mapmd5 + + demoflags = READUINT8(demobuf.p); +#ifdef DEMO_COMPAT_100 + if (demo.version == 0x0001) + { + if (demoflags & DF_MULTIPLAYER) + { + snprintf(msg, 1024, M_GetText("%s is an alpha multiplayer replay and cannot be played.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + } + else + { +#endif + gametype = READUINT8(demobuf.p); + + if (demo.title) // Titledemos should always play and ought to always be compatible with whatever wadlist is running. + G_SkipDemoExtraFiles(&demobuf.p); + else if (demo.loadfiles) + G_LoadDemoExtraFiles(&demobuf.p); + else if (demo.ignorefiles) + G_SkipDemoExtraFiles(&demobuf.p); + else + { + UINT8 error = G_CheckDemoExtraFiles(&demobuf.p, false); + + if (error) + { + switch (error) + { + case DFILE_ERROR_NOTLOADED: + snprintf(msg, 1024, + M_GetText("Required files for this demo are not loaded.\n\nUse\n\"playdemo %s -addfiles\"\nto load them and play the demo.\n"), + pdemoname); + break; + + case DFILE_ERROR_OUTOFORDER: + snprintf(msg, 1024, + M_GetText("Required files for this demo are loaded out of order.\n\nUse\n\"playdemo %s -force\"\nto play the demo anyway.\n"), + pdemoname); + break; + + case DFILE_ERROR_INCOMPLETEOUTOFORDER: + snprintf(msg, 1024, + M_GetText("Required files for this demo are not loaded, and some are out of order.\n\nUse\n\"playdemo %s -addfiles\"\nto load needed files and play the demo.\n"), + pdemoname); + break; + + case DFILE_ERROR_CANNOTLOAD: + snprintf(msg, 1024, + M_GetText("Required files for this demo cannot be loaded.\n\nUse\n\"playdemo %s -force\"\nto play the demo anyway.\n"), + pdemoname); + break; + + case DFILE_ERROR_EXTRAFILES: + snprintf(msg, 1024, + M_GetText("You have additional files loaded beyond the demo's file list.\n\nUse\n\"playdemo %s -force\"\nto play the demo anyway.\n"), + pdemoname); + break; + } + + CONS_Alert(CONS_ERROR, "%s", msg); + if (!CON_Ready()) // In the console they'll just see the notice there! No point pulling them out. + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + } +#ifdef DEMO_COMPAT_100 + } +#endif + + modeattacking = (demoflags & DF_ATTACKMASK)>>DF_ATTACKSHIFT; + multiplayer = !!(demoflags & DF_MULTIPLAYER); + CON_ToggleOff(); + + hu_demotime = UINT32_MAX; + hu_demolap = UINT32_MAX; + + switch (modeattacking) + { + case ATTACKING_NONE: // 0 + break; + case ATTACKING_RECORD: // 1 + hu_demotime = READUINT32(demobuf.p); + hu_demolap = READUINT32(demobuf.p); + break; + default: // 3 + modeattacking = ATTACKING_NONE; + break; + } + + // Random seed + randseed = READUINT32(demobuf.p); +#ifdef DEMO_COMPAT_100 + if (demo.version != 0x0001) +#endif + demobuf.p += 4; // Extrainfo location + +#ifdef DEMO_COMPAT_100 + if (demo.version == 0x0001) + { + // Player name + M_Memcpy(player_names[0],demobuf.p,16); + demobuf.p += 16; + + // Skin + M_Memcpy(skin,demobuf.p,16); + demobuf.p += 16; + + // Color + M_Memcpy(color,demobuf.p,16); + demobuf.p += 16; + + demobuf.p += 5; // Backwards compat - some stats + // SRB2kart + kartspeed[0] = READUINT8(demobuf.p); + kartweight[0] = READUINT8(demobuf.p); + // + demobuf.p += 9; // Backwards compat - more stats + + // Skin not loaded? + if (!SetPlayerSkin(0, skin)) + { + snprintf(msg, 1024, M_GetText("%s features a character that is not currently loaded.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + + // ...*map* not loaded? + if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1] || !(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) + { + snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + + // Set color + for (i = 0; i < MAXSKINCOLORS; i++) + if (!stricmp(KartColor_Names[i],color)) // SRB2kart + { + players[0].skincolor = i; + break; + } + + // net var data + CV_LoadNetVars(&demobuf.p); + + // Sigh ... it's an empty demo. + if (*demobuf.p == DEMOMARKER) + { + snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + + Z_Free(pdemoname); + + memset(&oldcmd,0,sizeof(oldcmd)); + memset(&oldghost,0,sizeof(oldghost)); + memset(&ghostext,0,sizeof(ghostext)); + + CONS_Alert(CONS_WARNING, M_GetText("Demo version does not match game version. Desyncs may occur.\n")); + + // console warning messages +#if defined(SKIPERRORS) && !defined(DEVELOP) + demosynced = (!skiperrors); +#else + demosynced = true; +#endif + + // didn't start recording right away. + demo.deferstart = false; + + consoleplayer = 0; + memset(displayplayers, 0, sizeof(displayplayers)); + memset(playeringame, 0, sizeof(playeringame)); + playeringame[0] = true; + + goto post_compat; + } +#endif + + // net var data + CV_LoadNetVars(&demobuf.p); + + // Sigh ... it's an empty demo. + if (*demobuf.p == DEMOMARKER) + { + snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + + Z_Free(pdemoname); + + memset(&oldcmd,0,sizeof(oldcmd)); + memset(&oldghost,0,sizeof(oldghost)); + memset(&ghostext,0,sizeof(ghostext)); + +#if defined(SKIPERRORS) && !defined(DEVELOP) + if ((VERSION != version || SUBVERSION != subversion) && !skiperrors) +#else + if (VERSION != version || SUBVERSION != subversion) +#endif + CONS_Alert(CONS_WARNING, M_GetText("Demo version does not match game version. Desyncs may occur.\n")); + + // console warning messages +#if defined(SKIPERRORS) && !defined(DEVELOP) + demosynced = (!skiperrors); +#else + demosynced = true; +#endif + + // didn't start recording right away. + demo.deferstart = false; + + //LUA_HookInt(gamemap, HOOK(MapChange)); + + consoleplayer = 0; + memset(playeringame, 0, sizeof(playeringame)); + memset(displayplayers, 0, sizeof(displayplayers)); + memset(camera, 0, sizeof(camera)); // reset freecam + + // Load players that were in-game when the map started + p = READUINT8(demobuf.p); + + while (p != 0xFF) + { + spectator = false; + if (p & DEMO_SPECTATOR) + { + spectator = true; + p &= ~DEMO_SPECTATOR; + + if (modeattacking) + { + snprintf(msg, 1024, M_GetText("%s is a Record Attack replay with spectators, and is thus invalid.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + } + slots[numslots] = p; numslots++; + + if (modeattacking && numslots > 1) + { + snprintf(msg, 1024, M_GetText("%s is a Record Attack replay with multiple players, and is thus invalid.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + G_ResetDemoPlayback(pdemoname); + return; + } + + if (!playeringame[displayplayers[0]] || players[displayplayers[0]].spectator) + displayplayers[0] = consoleplayer = serverplayer = p; + + playeringame[p] = true; + players[p].spectator = spectator; + + // Name + M_Memcpy(player_names[p],demobuf.p,16); + demobuf.p += 16; + + // Skin + M_Memcpy(skin,demobuf.p,16); + demobuf.p += 16; + SetPlayerSkin(p, skin); + + // Color + M_Memcpy(color,demobuf.p,16); + demobuf.p += 16; + for (i = 0; i < MAXSKINCOLORS; i++) + if (!stricmp(KartColor_Names[i],color)) // SRB2kart + { + players[p].skincolor = i; + break; + } + + // Score, since Kart uses this to determine where you start on the map + players[p].score = READUINT32(demobuf.p); + + // Kart stats, temporarily + kartspeed[p] = READUINT8(demobuf.p); + kartweight[p] = READUINT8(demobuf.p); + + if (stricmp(skins[players[p].skin].name, skin) != 0) + FindClosestSkinForStats(p, kartspeed[p], kartweight[p]); + + // Look for the next player + p = READUINT8(demobuf.p); + } + + // end of player read (the 0xFF marker) + // so this is where we are to read our lua variables (if possible!) + if (demoflags & DF_LUAVARS) // again, used for compability, lua shit will be saved to replays regardless of if it's even been loaded + { + if (!gL) // No Lua state! ...I guess we'll just start one... + LUA_ClearState(); + + // No modeattacking check, DF_LUAVARS won't be present here. + LUA_UnArchive(&demobuf, false); + } + + splitscreen = 0; + + if (demo.title) + { + splitscreen = M_RandomKey(6)-1; + splitscreen = min(min(3, numslots-1), splitscreen); // Bias toward 1p and 4p views + + for (p = 0; p <= splitscreen; p++) + G_ResetView(p+1, slots[M_RandomKey(numslots)], false); + } + + R_ExecuteSetViewSize(); + +#ifdef DEMO_COMPAT_100 +post_compat: +#endif + + P_SetRandSeed(randseed); + G_InitNew(demoflags & DF_ENCORE, G_BuildMapName(gamemap), true, true); // Doesn't matter whether you reset or not here, given changes to resetplayer. + + for (i = 0; i < MAXPLAYERS; i++) + { + if (players[i].mo) + { + players[i].mo->color = players[i].skincolor; + oldghost[i].x = players[i].mo->x; + oldghost[i].y = players[i].mo->y; + oldghost[i].z = players[i].mo->z; + } + + // Set saved attribute values + // No cheat checking here, because even if they ARE wrong... + // it would only break the replay if we clipped them. + players[i].kartspeed = kartspeed[i]; + players[i].kartweight = kartweight[i]; + } + + if (cv_director.value) + CV_SetValue(&cv_director, 0); + + demo.deferstart = true; +} +#undef SKIPERRORS + +void G_AddGhost(char *defdemoname) +{ + INT32 i; + lumpnum_t l; + char name[17],skin[17],color[17],*n,*pdemoname,md5[16]; + demoghost *gh; + UINT8 flags; + UINT8 *buffer,*p; + mapthing_t *mthing; + UINT16 count, ghostversion; + skin_t *ghskin = &skins[0]; + UINT8 kartspeed = UINT8_MAX, kartweight = UINT8_MAX; + + name[16] = '\0'; + skin[16] = '\0'; + color[16] = '\0'; + + n = defdemoname+strlen(defdemoname); + while (*n != '/' && *n != '\\' && n != defdemoname) + n--; + if (n != defdemoname) + n++; + pdemoname = ZZ_Alloc(strlen(n)+1); + strcpy(pdemoname,n); + + // Internal if no extension, external if one exists + if (FIL_CheckExtension(defdemoname)) + { + //FIL_DefaultExtension(defdemoname, ".lmp"); + if (!FIL_ReadFileTag(defdemoname, &buffer, PU_LEVEL)) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), defdemoname); + Z_Free(pdemoname); + return; + } + p = buffer; + } + // load demo resource from WAD + else if ((l = W_CheckNumForName(defdemoname)) == LUMPERROR) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read lump '%s'.\n"), defdemoname); + Z_Free(pdemoname); + return; + } + else // it's an internal demo + buffer = p = W_CacheLumpNum(l, PU_LEVEL); + + // read demo header + if (memcmp(p, DEMOHEADER, 12)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Not a SRB2Kart replay.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + + p += 12; // DEMOHEADER + p++; // VERSION + p++; // SUBVERSION + + ghostversion = READUINT16(p); + switch(ghostversion) + { + case DEMOVERSION: // latest always supported + p += 64; // title + break; +#ifdef DEMO_COMPAT_100 + case 0x0001: + break; +#endif + // too old, cannot support. + default: + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Demo version incompatible.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + + M_Memcpy(md5, p, 16); p += 16; // demo checksum + for (gh = ghosts; gh; gh = gh->next) + if (!memcmp(md5, gh->checksum, 16)) // another ghost in the game already has this checksum? + { // Don't add another one, then! + CONS_Debug(DBG_SETUP, "Rejecting duplicate ghost %s (MD5 was matched)\n", pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + + if (memcmp(p, "PLAY", 4)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Demo format unacceptable.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + + p += 4; // "PLAY" + p += 2; // gamemap + p += 16; // mapmd5 (possibly check for consistency?) + + flags = READUINT8(p); + + if (!(flags & DF_GHOST)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: No ghost data in this demo.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + +#ifdef DEMO_COMPAT_100 + if (ghostversion != 0x0001) +#endif + p++; // gametype + +#ifdef DEMO_COMPAT_100 + if (ghostversion != 0x0001) +#endif + G_SkipDemoExtraFiles(&p); // Don't wanna modify the file list for ghosts. + switch ((flags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) + { + case ATTACKING_NONE: // 0 + break; + case ATTACKING_RECORD: // 1 + p += 8; // demo time, lap + break; + default: // 3 + break; + } + + p += 4; // random seed + +#ifdef DEMO_COMPAT_100 + if (ghostversion == 0x0001) + { + // Player name (TODO: Display this somehow if it doesn't match cv_playername!) + M_Memcpy(name, p,16); + p += 16; + + // Skin + M_Memcpy(skin, p,16); + p += 16; + + // Color + M_Memcpy(color, p,16); + p += 16; + + // Ghosts do not have a player structure to put this in. + p++; // charability + p++; // charability2 + p++; // actionspd + p++; // mindash + p++; // maxdash + // SRB2kart + p++; // kartspeed + p++; // kartweight + // + p++; // normalspeed + p++; // runspeed + p++; // thrustfactor + p++; // accelstart + p++; // acceleration + p += 4; // jumpfactor + } + else +#endif + p += 4; // Extra data location reference + + // net var data + count = READUINT16(p); + while (count--) + { + p += 2; + SKIPSTRING(p); + p++; + } + + if (*p == DEMOMARKER) + { + CONS_Alert(CONS_NOTICE, M_GetText("Failed to add ghost %s: Replay is empty.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + +#ifdef DEMO_COMPAT_100 + if (ghostversion != 0x0001) + { +#endif + if (READUINT8(p) != 0) + { + CONS_Alert(CONS_NOTICE, M_GetText("Failed to add ghost %s: Invalid player slot.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + + // Player name (TODO: Display this somehow if it doesn't match cv_playername!) + M_Memcpy(name, p, 16); + p += 16; + + // Skin + M_Memcpy(skin, p, 16); + p += 16; + + // Color + M_Memcpy(color, p, 16); + p += 16; + + p += 4; // score + + kartspeed = READUINT8(p); + kartweight = READUINT8(p); + + if (READUINT8(p) != 0xFF) + { + CONS_Alert(CONS_NOTICE, M_GetText("Failed to add ghost %s: Invalid player slot.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } +#ifdef DEMO_COMPAT_100 + } +#endif + + for (i = 0; i < numskins; i++) + if (!stricmp(skins[i].name,skin)) + { + ghskin = &skins[i]; + break; + } + + if (i == numskins) + { + if (kartspeed != UINT8_MAX && kartweight != UINT8_MAX) + ghskin = &skins[GetSkinNumClosestToStats(kartspeed, kartweight)]; + + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Invalid character. Falling back to %s.\n"), pdemoname, ghskin->name); + } + + gh = Z_Calloc(sizeof(demoghost), PU_LEVEL, NULL); + gh->next = ghosts; + gh->buffer = buffer; + M_Memcpy(gh->checksum, md5, 16); + gh->p = p; + + ghosts = gh; + + gh->version = ghostversion; + mthing = playerstarts[0]; + I_Assert(mthing); + { // A bit more complex than P_SpawnPlayer because ghosts aren't solid and won't just push themselves out of the ceiling. + fixed_t z,f,c; + gh->mo = P_SpawnMobj(mthing->x << FRACBITS, mthing->y << FRACBITS, 0, MT_GHOST); + gh->mo->angle = FixedAngle(mthing->angle*FRACUNIT); + f = gh->mo->floorz; + c = gh->mo->ceilingz - mobjinfo[MT_PLAYER].height; + if (!!(mthing->options & MTF_AMBUSH) ^ !!(mthing->options & MTF_OBJECTFLIP)) + { + z = c; + if (mthing->options >> ZSHIFT) + z -= ((mthing->options >> ZSHIFT) << FRACBITS); + if (z < f) + z = f; + } + else + { + z = f; + if (mthing->options >> ZSHIFT) + z += ((mthing->options >> ZSHIFT) << FRACBITS); + if (z > c) + z = c; + } + gh->mo->z = z; + } + gh->mo->state = states+S_KART_STND1; // SRB2kart - was S_PLAY_STND + gh->mo->sprite = gh->mo->state->sprite; + gh->mo->frame = (gh->mo->state->frame & FF_FRAMEMASK) | tr_trans20<mo->tics = -1; + + gh->oldmo.x = gh->mo->x; + gh->oldmo.y = gh->mo->y; + gh->oldmo.z = gh->mo->z; + + // Set skin + gh->mo->skin = gh->oldmo.skin = ghskin; + + // Set color + gh->mo->color = ((skin_t*)gh->mo->skin)->prefcolor; + for (i = 0; i < MAXSKINCOLORS; i++) + if (!stricmp(KartColor_Names[i],color)) // SRB2kart + { + gh->mo->color = (UINT8)i; + break; + } + gh->oldmo.color = gh->mo->color; + + CONS_Printf(M_GetText("Added ghost %s from %s\n"), name, pdemoname); + Z_Free(pdemoname); +} + +// A simplified version of G_AddGhost... +void G_UpdateStaffGhostName(lumpnum_t l) +{ + UINT8 *buffer,*p; + UINT16 ghostversion; + UINT8 flags; + + buffer = p = W_CacheLumpNum(l, PU_CACHE); + + // read demo header + if (memcmp(p, DEMOHEADER, 12)) + { + goto fail; + } + + p += 12; // DEMOHEADER + p++; // VERSION + p++; // SUBVERSION + + ghostversion = READUINT16(p); + switch(ghostversion) + { + case DEMOVERSION: // latest always supported + p += 64; // full demo title + break; + +#ifdef DEMO_COMPAT_100 + case 0x0001: + break; +#endif + + // too old, cannot support. + default: + goto fail; + } + + p += 16; // demo checksum + + if (memcmp(p, "PLAY", 4)) + { + goto fail; + } + + p += 4; // "PLAY" + p += 2; // gamemap + p += 16; // mapmd5 (possibly check for consistency?) + + flags = READUINT8(p); + if (!(flags & DF_GHOST)) + { + goto fail; // we don't NEED to do it here, but whatever + } + +#ifdef DEMO_COMPAT_100 + if (ghostversion != 0x0001) +#endif + p++; // Gametype + +#ifdef DEMO_COMPAT_100 + if (ghostversion != 0x0001) +#endif + G_SkipDemoExtraFiles(&p); + + switch ((flags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) + { + case ATTACKING_NONE: // 0 + break; + case ATTACKING_RECORD: // 1 + p += 8; // demo time, lap + break; + default: // 3 + break; + } + + p += 4; // random seed + + +#ifdef DEMO_COMPAT_100 + if (ghostversion == 0x0001) + { + // Player name + M_Memcpy(dummystaffname, p,16); + dummystaffname[16] = '\0'; + goto fail; // Not really a failure but whatever + } +#endif + + p += 4; // Extrainfo location marker + + // Ehhhh don't need ghostversion here (?) so I'll reuse the var here + ghostversion = READUINT16(p); + while (ghostversion--) + { + p += 2; + SKIPSTRING(p); + p++; // stealth + } + + // Assert first player is in and then read name + if (READUINT8(p) != 0) + goto fail; + M_Memcpy(dummystaffname, p,16); + dummystaffname[16] = '\0'; + + // Ok, no longer any reason to care, bye +fail: + Z_Free(buffer); + return; +} + +// +// G_TimeDemo +// NOTE: name is a full filename for external demos +// +static INT32 restorecv_vidwait; + +void G_TimeDemo(const char *name) +{ + nodrawers = M_CheckParm("-nodraw"); + noblit = M_CheckParm("-noblit"); + restorecv_vidwait = cv_vidwait.value; + if (cv_vidwait.value) + CV_Set(&cv_vidwait, "0"); + demo.timing = true; + singletics = true; + framecount = 0; + demostarttime = I_GetTime(); + G_DeferedPlayDemo(name); +} + +void G_DoPlayMetal(void) +{ + lumpnum_t l; + mobj_t *mo = NULL; + thinker_t *th; + + // it's an internal demo + if ((l = W_CheckNumForName(va("%sMS",G_BuildMapName(gamemap)))) == LUMPERROR) + { + CONS_Alert(CONS_WARNING, M_GetText("No bot recording for this map.\n")); + return; + } + else + metalbuffer = metal_p = W_CacheLumpNum(l, PU_STATIC); + + // find metal sonic + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + mo = (mobj_t *)th; + if (mo->type == MT_METALSONIC_RACE) + break; + } + if (!mo) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to find bot entity.\n")); + Z_Free(metalbuffer); + return; + } + + // read demo header + metal_p += 12; // DEMOHEADER + metal_p++; // VERSION + metal_p++; // SUBVERSION + metalversion = READUINT16(metal_p); + switch(metalversion) + { + case DEMOVERSION: // latest always supported + break; +#ifdef DEMO_COMPAT_100 + case 0x0001: + I_Error("You need to implement demo compat here, doofus! %s:%d", __FILE__, __LINE__); +#endif + // too old, cannot support. + default: + CONS_Alert(CONS_WARNING, M_GetText("Failed to load bot recording for this map, format version incompatible.\n")); + Z_Free(metalbuffer); + return; + } + metal_p += 16; // demo checksum + if (memcmp(metal_p, "METL", 4)) + { + CONS_Alert(CONS_WARNING, M_GetText("Failed to load bot recording for this map, wasn't recorded in Metal format.\n")); + Z_Free(metalbuffer); + return; + } metal_p += 4; // "METL" + + // read initial tic + memset(&oldmetal,0,sizeof(oldmetal)); + oldmetal.x = mo->x; + oldmetal.y = mo->y; + oldmetal.z = mo->z; + oldmetal.angle = mo->angle; + metalplayback = mo; +} + +void G_DoneLevelLoad(void) +{ + CONS_Printf(M_GetText("Loaded level in %f sec\n"), (double)(I_GetTime() - demostarttime) / TICRATE); + framecount = 0; + demostarttime = I_GetTime(); +} + +/* +=================== += += G_CheckDemoStatus += += Called after a death or level completion to allow demos to be cleaned up += Returns true if a new demo loop action will take place +=================== +*/ + +// Stops metal sonic's demo. Separate from other functions because metal + replays can coexist +void G_StopMetalDemo(void) +{ + // Metal Sonic finishing doesn't end the game, dammit. + Z_Free(metalbuffer); + metalbuffer = NULL; + metalplayback = NULL; + metal_p = NULL; +} + +// Stops metal sonic recording. +ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) +{ + boolean saved = false; + if (demobuf.p && demobuf.buffer != NULL) + { + UINT8 *p = demobuf.buffer+16; // checksum position +#ifdef NOMD5 + UINT8 i; + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker + for (i = 0; i < 16; i++, p++) + *p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. +#else + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker + md5_buffer((char *)p+16, demobuf.p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file. +#endif + saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuf.buffer, demobuf.p - demobuf.buffer); // finally output the file. + } + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; + metalrecording = false; + if (saved) + I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap)); + I_Error("Failed to save demo!"); +} + +// reset engine variable set for the demos +// called from stopdemo command, map command, and g_checkdemoStatus. +void G_StopDemo(void) +{ + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; + demo.playback = false; + if (demo.title) + modeattacking = ATTACKING_NONE; + demo.title = false; + demo.timing = false; + singletics = false; + + UINT8 i; + for (i = 0; i < MAXSPLITSCREENPLAYERS; ++i) + { + camera[i].freecam = false; + camera[i].localangle = 0; + camera[i].localaiming = 0; + } + + CV_SetValue(&cv_playbackspeed, 1); + demo.rewinding = false; + CL_ClearRewinds(); + + if (gamestate == GS_LEVEL && rendermode != render_none) + { + V_SetPaletteLump("PLAYPAL"); // Reset the palette + R_ReInitColormaps(0, LUMPERROR); + } + if (gamestate == GS_INTERMISSION) + Y_EndIntermission(); // cleanup + if (gamestate == GS_VOTING) + Y_EndVote(); + + M_ClearMenus(true); + + G_SetGamestate(GS_NULL); + wipegamestate = GS_NULL; + SV_StopServer(); + SV_ResetServer(); +} + +// Stops timing a demo. +static void G_StopTimingDemo(void) +{ + INT32 demotime; + double f1, f2; + demotime = I_GetTime() - demostarttime; + if (!demotime) + return; + G_StopDemo(); + demo.timing = false; + f1 = (double)demotime; + f2 = (double)framecount*TICRATE; + + CONS_Printf(M_GetText("timed %u gametics in %d realtics - %u frames\n%f seconds, %f avg fps\n"), + leveltime, demotime, (UINT32)framecount, f1/TICRATE, f2/f1); + + if (restorecv_vidwait != cv_vidwait.value) + CV_SetValue(&cv_vidwait, restorecv_vidwait); + + D_StartTitle(); +} + + +boolean G_CheckDemoStatus(void) +{ + while (ghosts) + { + demoghost *next = ghosts->next; + Z_Free(ghosts); + ghosts = next; + } + ghosts = NULL; + + // DO NOT end metal sonic demos here + + if (demo.timing) + { + G_StopTimingDemo(); + return true; + } + + if (demo.playback) + { + if (demo.quitafterplaying) + I_Quit(); + + if (multiplayer && !demo.title) + { + G_ExitLevel(); + } + else if (modeattacking && !demo.title) // nooo dont crash our titledemos + { + G_StopDemo(); + M_EndModeAttackRun(); + } + else + { + G_StopDemo(); + D_StartTitle(); + } + + return true; + } + + if (!demo.recording) + return false; + + if (modeattacking || demo.savemode != DSM_NOTSAVING) + { + G_SaveDemo(); + return true; + } + + G_ResetDemoRecording(); + + return false; +} + +void G_ResetDemoRecording(void) +{ + if (demobuf.buffer) + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; + demo.recording = false; +} + +static void G_ResetDemoPlayback(char *pdemoname) +{ + if (pdemoname) + Z_Free(pdemoname); + if (demobuf.buffer) + Z_Free(demobuf.buffer); + demobuf.buffer = NULL; + demo.playback = false; + if (demo.title) + modeattacking = ATTACKING_NONE; + demo.title = false; +} + +void G_SaveDemo(void) +{ + if (!demobuf.p) + { + CONS_Alert(CONS_ERROR, "Failed to save Demo. No Demo pointer exists!\n"); + // reset the demo buffer + G_ResetDemoRecording(); + return; + } + + if (demobuf.buffer == NULL) + { + CONS_Alert(CONS_ERROR, "Failed to save Demo. No Demo buffer allocated!\n"); + // reset the demo buffer + G_ResetDemoRecording(); + return; + } + + UINT8 *p = demobuf.buffer+16; // after version + UINT32 length; + + // Ensure extrainfo pointer is always available, even if no info is present. + if (demoinfo_p && *(UINT32 *)demoinfo_p == 0) + { + WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker + *(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer; + } + WRITEUINT8(demobuf.p, DW_END); // Mark end of demo extra data. + + M_Memcpy(p, demo.titlename, 64); // Write demo title here + p += 64; + + if (multiplayer) + { + // Change the demo's name to be a slug of the title + char demo_slug[128]; + char *writepoint; + size_t i, strindex = 0; + boolean dash = true; + + for (i = 0; demo.titlename[i] && i < 127; i++) + { + if ((demo.titlename[i] >= 'a' && demo.titlename[i] <= 'z') || + (demo.titlename[i] >= '0' && demo.titlename[i] <= '9')) + { + demo_slug[strindex] = demo.titlename[i]; + strindex++; + dash = false; + } + else if (demo.titlename[i] >= 'A' && demo.titlename[i] <= 'Z') + { + demo_slug[strindex] = demo.titlename[i] + 'a' - 'A'; + strindex++; + dash = false; + } + else if (!dash) + { + demo_slug[strindex] = '-'; + strindex++; + dash = true; + } + } + + demo_slug[strindex] = 0; + if (dash) demo_slug[strindex-1] = 0; + + writepoint = strstr(demoname, "-") + 1; + demo_slug[128 - (writepoint - demoname) - 4] = 0; + sprintf(writepoint, "%s.lmp", demo_slug); + } + + length = *(UINT32 *)demoinfo_p; + WRITEUINT32(demoinfo_p, length); +#ifdef NOMD5 + for (UINT8 k = 0; k < 16; k++, p++) + *p = M_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. +#else + // Make a checksum of everything after the checksum in the file up to the end of the standard data. Extrainfo is freely modifiable. + md5_buffer((char *)p+16, (demobuf.buffer + length) - (p+16), p); +#endif + + + if (FIL_WriteFile(va(pandf, srb2home, demoname), demobuf.buffer, demobuf.p - demobuf.buffer)) // finally output the file. + demo.savemode = DSM_SAVED; + + G_ResetDemoRecording(); + + if (modeattacking != ATTACKING_RECORD) + { + if (demo.savemode == DSM_SAVED) + CONS_Printf(M_GetText("Demo %s recorded\n"), demoname); + else + CONS_Alert(CONS_WARNING, M_GetText("Demo %s not saved\n"), demoname); + } +} + +boolean G_DemoTitleResponder(event_t *ev) +{ + INT32 ch; + + if (ev->type != ev_keydown) + return false; + + ch = (INT32)ev->data1; + + // Only ESC and non-keyboard keys abort connection + if (ch == KEY_ESCAPE) + { + demo.savemode = (cv_recordmultiplayerdemos.value == 2) ? DSM_WILLAUTOSAVE : DSM_NOTSAVING; + return true; + } + + if (ch == KEY_ENTER || ch >= KEY_MOUSE1) + { + demo.savemode = DSM_WILLSAVE; + return true; + } + + M_TextInputHandle(&demo.titlenameinput, ch); + + return true; +} diff --git a/src/g_demo.h b/src/g_demo.h new file mode 100644 index 000000000..6bfaa0a2c --- /dev/null +++ b/src/g_demo.h @@ -0,0 +1,190 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2020 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file g_demo.h +/// \brief Demo recording and playback + +#ifndef __G_DEMO__ +#define __G_DEMO__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "doomdef.h" +#include "doomstat.h" +#include "d_event.h" +#include "p_saveg.h" +#include "m_textinput.h" + +extern savebuffer_t demobuf; + +// demoplaying back and demo recording +extern consvar_t cv_recordmultiplayerdemos, cv_netdemosyncquality, cv_maxdemosize, cv_demochangemap; +extern consvar_t cv_demodateformat; + +// Publicly-accessible demo vars +struct demovars_s { + char titlename[65]; + textinput_t titlenameinput; + boolean recording, playback, timing; + UINT16 version; // Current file format of the demo being played + boolean title; // Title Screen demo can be cancelled by any key + boolean rewinding; // Rewind in progress + + boolean loadfiles, ignorefiles; // Demo file loading options + boolean fromtitle; // SRB2Kart: Don't stop the music + boolean inreplayhut; // Go back to replayhut after demos + boolean quitafterplaying; // quit after playing a demo from cmdline + boolean deferstart; // don't start playing demo right away + + tic_t savebutton; // Used to determine when the local player can choose to save the replay while the race is still going + enum { + DSM_NOTSAVING, + DSM_WILLAUTOSAVE, + DSM_TITLEENTRY, + DSM_WILLSAVE, + DSM_SAVED + } savemode; +}; + +extern struct demovars_s demo; + +typedef enum { + MD_NOTLOADED, + MD_LOADED, + MD_SUBDIR, + MD_OUTDATED, + MD_INVALID +} menudemotype_e; + +typedef struct menudemo_s { + char filepath[256]; + menudemotype_e type; + + char title[65]; // Null-terminated for string prints + char date[11]; // date when replay was recorded + char version[12]; // combined version and subversion + UINT16 map; + UINT8 addonstatus; // What do we need to do addon-wise to play this demo? + UINT8 gametype; + UINT8 kartspeed; // Add OR DF_ENCORE for encore mode, idk + UINT8 numlaps; + + struct { + UINT8 ranking; + char name[17]; + UINT8 skin, color; + UINT32 timeorscore; + } standings[MAXPLAYERS]; +} menudemo_t; + +extern mobj_t *metalplayback; + +// Only called by startup code. +void G_RecordDemo(const char *name); +void G_RecordMetal(void); +void G_BeginRecording(void); +void G_BeginMetal(void); + +// Only called by shutdown code. +void G_WriteStanding(UINT8 ranking, char *name, INT32 skinnum, UINT8 color, UINT32 val); +void G_SetDemoTime(UINT32 ptime, UINT32 plap); +UINT8 G_CmpDemoTime(char *oldname, char *newname); + +void G_LoadDemoInfo(menudemo_t *pdemo); +void G_LoadDemoTitle(menudemo_t *pdemo); // For use in replay search feature +void G_DeferedPlayDemo(const char *demo); + +typedef enum +{ + GHC_NORMAL = 0, + GHC_SUPER, + GHC_FIREFLOWER, + GHC_INVINCIBLE +} ghostcolor_t; + +extern UINT8 demo_extradata[MAXPLAYERS]; +extern UINT8 demo_writerng; +#define DXD_RESPAWN 0x01 // "respawn" command in console +#define DXD_SKIN 0x02 // skin changed +#define DXD_NAME 0x04 // name changed +#define DXD_COLOR 0x08 // color changed +#define DXD_PLAYSTATE 0x10 // state changed between playing, spectating, or not in-game + +#define DXD_PST_PLAYING 0x01 +#define DXD_PST_SPECTATING 0x02 +#define DXD_PST_LEFT 0x03 + +// Record/playback tics +void G_ReadDemoExtraData(void); +void G_WriteDemoExtraData(void); +void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum); +void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum); +void G_GhostAddThok(INT32 playernum); +void G_GhostAddSpin(INT32 playernum); +void G_GhostAddRev(INT32 playernum); +void G_GhostAddColor(INT32 playernum, ghostcolor_t color); +void G_GhostAddFlip(INT32 playernum); +void G_GhostAddScale(INT32 playernum, fixed_t scale); +void G_GhostAddHit(INT32 playernum, mobj_t *victim); +void G_WriteAllGhostTics(void); +void G_WriteGhostTic(mobj_t *ghost, INT32 playernum); +void G_ConsAllGhostTics(void); +void G_ConsGhostTic(INT32 playernum); +void G_GhostTicker(void); + +void G_InitDemoRewind(void); +void G_StoreRewindInfo(void); +void G_PreviewRewind(tic_t previewtime); +void G_ConfirmRewind(tic_t rewindtime); + +void G_ReadMetalTic(mobj_t *metal); +void G_WriteMetalTic(mobj_t *metal); +void G_SaveMetal(UINT8 **buffer); +void G_LoadMetal(UINT8 **buffer); + +// Your naming conventions are stupid and useless. +// There is no conflict here. +typedef struct demoghost { + UINT8 checksum[16]; + UINT8 *buffer, *p, color; + UINT16 version; + mobj_t oldmo, *mo; + struct demoghost *next; +} demoghost; +extern demoghost *ghosts; + +// G_CheckDemoExtraFiles: checks if our loaded WAD list matches the demo's. +#define DFILE_ERROR_NOTLOADED 0x01 // Files are not loaded, but can be without a restart. +#define DFILE_ERROR_OUTOFORDER 0x02 // Files are loaded, but out of order. +#define DFILE_ERROR_INCOMPLETEOUTOFORDER 0x03 // Some files are loaded out of order, but others are not. +#define DFILE_ERROR_CANNOTLOAD 0x04 // Files are missing and cannot be loaded. +#define DFILE_ERROR_EXTRAFILES 0x05 // Extra files outside of the replay's file list are loaded. + +void G_ResetDemoRecording(void); +void G_DoPlayDemo(char *defdemoname); +void G_TimeDemo(const char *name); +void G_AddGhost(char *defdemoname); +void G_UpdateStaffGhostName(lumpnum_t l); +void G_DoPlayMetal(void); +void G_DoneLevelLoad(void); +void G_StopMetalDemo(void); +ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void); +void G_StopDemo(void); +boolean G_CheckDemoStatus(void); +void G_SaveDemo(void); +boolean G_DemoTitleResponder(event_t *ev); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __G_DEMO__ diff --git a/src/g_game.c b/src/g_game.c index b7b18fcb7..bc500a973 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -59,10 +59,6 @@ #include "discord.h" #endif -// for replay dates -#include -#include - gameaction_t gameaction; gamestate_t gamestate = GS_NULL; UINT8 ultimatemode = false; @@ -87,8 +83,6 @@ static void G_DoContinued(void); static void G_DoWorldDone(void); static void G_DoStartVote(void); -static void G_ResetDemoPlayback(char *pdemoname); - music_t mapmusic; INT16 gamemap = 1; @@ -108,14 +102,8 @@ UINT8 modeattacking = ATTACKING_NONE; boolean imcontinuing = false; boolean runemeraldmanager = false; -// menu demo things -UINT8 numDemos = 0; //3; -- i'm FED UP of losing my skincolour to a broken demo. change this back when we make new ones -UINT32 demoDelayTime = 15*TICRATE; -UINT32 demoIdleTime = 3*TICRATE; - boolean nodrawers; // for comparative timing purposes boolean noblit; // for comparative timing purposes -static tic_t demostarttime; // for comparative timing purposes boolean netgame; // only true if packets are broadcast boolean multiplayer; @@ -290,64 +278,8 @@ UINT32 timesBeaten; UINT32 timesBeatenWithEmeralds; //UINT32 timesBeatenUltimate; -//@TODO put these all in a struct for namespacing purposes? -static char demoname[128]; -savebuffer_t demobuf; -static UINT8 *demotime_p, *demoinfo_p; -static UINT8 *demoend; -static UINT8 demoflags; -static boolean demosynced = true; // console warning message - -struct demovars_s demo; - -boolean metalrecording; // recording as metal sonic -mobj_t *metalplayback; -static UINT8 *metalbuffer = NULL; -static UINT8 *metal_p; -static UINT16 metalversion; - -// extra data stuff (events registered this frame while recording) -static struct { - UINT8 flags; // EZT flags - - // EZT_COLOR - UINT8 color, lastcolor; - - // EZT_SCALE - fixed_t scale, lastscale; - - // EZT_KART - INT32 kartitem, kartamount, kartbumpers; - - UINT8 desyncframes; // Don't try to resync unless we've been off for two frames, to monkeypatch a few trouble spots - - // EZT_HIT - UINT16 hits; - mobj_t **hitlist; -} ghostext[MAXPLAYERS]; - -// Your naming conventions are stupid and useless. -// There is no conflict here. -demoghost *ghosts = NULL; - INT16 prevmap, nextmap; -static CV_PossibleValue_t recordmultiplayerdemos_cons_t[] = {{0, "Disabled"}, {1, "Manual Save"}, {2, "Auto Save"}, {0, NULL}}; -consvar_t cv_recordmultiplayerdemos = {"netdemo_record", "Manual Save", CV_SAVE, recordmultiplayerdemos_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -static CV_PossibleValue_t netdemosyncquality_cons_t[] = {{1, "MIN"}, {35, "MAX"}, {0, NULL}}; -consvar_t cv_netdemosyncquality = {"netdemo_syncquality", "1", CV_SAVE, netdemosyncquality_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -// Units are MiB. -static CV_PossibleValue_t maxdemosize_cons_t[] = {{10, "MIN"}, {100, "MAX"}, {0, NULL}}; -consvar_t cv_maxdemosize = {"maxdemosize", "10", CV_SAVE, maxdemosize_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -static CV_PossibleValue_t demochangemap_cons_t[] = {{0, "Disabled"}, {1, "Diff Map"}, {2, "Always"}, {0, NULL}}; -consvar_t cv_demochangemap = {"netdemo_savemapchange", "Disabled", CV_SAVE, demochangemap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - -static CV_PossibleValue_t demodateformat_cons_t[] = {{0, "Automatic"}, {1, "EU"}, {2, "US"}, {0, NULL}}; -consvar_t cv_demodateformat = {"netdemo_dateformat", "Automatic", CV_SAVE, demodateformat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - // Analog Control void SendWeaponPref(void); void SendWeaponPref2(void); @@ -4290,3943 +4222,6 @@ INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep) return newmapnum; } -// -// DEMO RECORDING -// - -#define DEMOVERSION 0x0002 -#define DEMOHEADER "\xF0" "KartReplay" "\x0F" - -#define DF_GHOST 0x01 // This demo contains ghost data too! -#define DF_RECORDATTACK 0x02 // This demo is from record attack and contains its final completion time! -#define DF_NIGHTSATTACK 0x04 // This demo is from NiGHTS attack and contains its time left, score, and mares! -#define DF_ATTACKMASK 0x06 // This demo is from ??? attack and contains ??? - -#define DF_LUAVARS 0x20 // this demo contains extra lua vars; this is mostly used for backwards compability - -#define DF_ATTACKSHIFT 1 -#define DF_ENCORE 0x40 -#define DF_MULTIPLAYER 0x80 // This demo was recorded in multiplayer mode! - -#ifdef DEMO_COMPAT_100 -#define DF_FILELIST 0x08 // This demo contains an extra files list -#define DF_GAMETYPEMASK 0x30 -#define DF_GAMESHIFT 4 -#endif - -#define DEMO_SPECTATOR 0x40 - -// For demos -#define ZT_FWD 0x01 -#define ZT_SIDE 0x02 -#define ZT_ANGLE 0x04 -#define ZT_BUTTONS 0x08 -#define ZT_AIMING 0x10 -#define ZT_DRIFT 0x20 -#define ZT_LATENCY 0x40 -#define DEMOMARKER 0x80 // demoend - -UINT8 demo_extradata[MAXPLAYERS]; -UINT8 demo_writerng; // 0=no, 1=yes, 2=yes but on a timeout -static ticcmd_t oldcmd[MAXPLAYERS]; - -#define DW_END 0xFF // End of extradata block -#define DW_RNG 0xFE // Check RNG seed! - -#define DW_EXTRASTUFF 0xFE // Numbers below this are reserved for writing player slot data - -// Below consts are only used for demo extrainfo sections -#define DW_STANDING 0x00 - -// For Metal Sonic and time attack ghosts -#define GZT_XYZ 0x01 -#define GZT_MOMXY 0x02 -#define GZT_MOMZ 0x04 -#define GZT_ANGLE 0x08 -// Not used for Metal Sonic -#define GZT_SPRITE 0x10 // Animation frame -#define GZT_EXTRA 0x20 -#define GZT_NIGHTS 0x40 // NiGHTS Mode stuff! - -// GZT_EXTRA flags -#define EZT_THOK 0x01 // Spawned a thok object -#define EZT_SPIN 0x02 // Because one type of thok object apparently wasn't enough -#define EZT_REV 0x03 // And two types wasn't enough either yet -#define EZT_THOKMASK 0x03 -#define EZT_COLOR 0x04 // Changed color (Super transformation, Mario fireflowers/invulnerability, etc.) -#define EZT_FLIP 0x08 // Reversed gravity -#define EZT_SCALE 0x10 // Changed size -#define EZT_HIT 0x20 // Damaged a mobj -#define EZT_SPRITE 0x40 // Changed sprite set completely out of PLAY (NiGHTS, SOCs, whatever) -#define EZT_KART 0x80 // SRB2Kart: Changed current held item/quantity and bumpers for battle - -static mobj_t oldmetal, oldghost[MAXPLAYERS]; - -void G_SaveMetal(UINT8 **buffer) -{ - I_Assert(buffer != NULL && *buffer != NULL); - - WRITEUINT32(*buffer, metal_p - metalbuffer); -} - -void G_LoadMetal(UINT8 **buffer) -{ - I_Assert(buffer != NULL && *buffer != NULL); - - G_DoPlayMetal(); - metal_p = metalbuffer + READUINT32(*buffer); -} - -ticcmd_t *G_CopyTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n) -{ - return M_Memcpy(dest, src, n*sizeof(*src)); -} - -ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n) -{ - size_t i; - for (i = 0; i < n; i++) - { - dest[i].forwardmove = src[i].forwardmove; - dest[i].sidemove = src[i].sidemove; - dest[i].angleturn = SHORT(src[i].angleturn); - dest[i].aiming = (INT16)SHORT(src[i].aiming); - dest[i].buttons = (UINT16)SHORT(src[i].buttons); - dest[i].driftturn = (INT16)SHORT(src[i].driftturn); - dest[i].latency = (INT16)SHORT(src[i].latency); - } - return dest; -} - -// Finds a skin with the closest stats if the expected skin doesn't exist. -static INT32 GetSkinNumClosestToStats(UINT8 kartspeed, UINT8 kartweight) -{ - INT32 i, closest_skin = 0; - UINT8 closest_stats = UINT8_MAX, stat_diff; - - for (i = 0; i < numskins; i++) - { - stat_diff = abs(skins[i].kartspeed - kartspeed) + abs(skins[i].kartweight - kartweight); - if (stat_diff < closest_stats) - { - closest_stats = stat_diff; - closest_skin = i; - } - } - - return closest_skin; -} - -static void FindClosestSkinForStats(UINT32 p, UINT8 kartspeed, UINT8 kartweight) -{ - INT32 closest_skin = GetSkinNumClosestToStats(kartspeed, kartweight); - - //CONS_Printf("Using %s instead...\n", skins[closest_skin].name); - SetPlayerSkinByNum(p, closest_skin); -} - -void G_ReadDemoExtraData(void) -{ - INT32 p, extradata, i; - char name[17]; - - if (leveltime > starttime) - { - rewind_t *rewind = CL_SaveRewindPoint(demobuf.p - demobuf.buffer); - if (rewind) - { - memcpy(rewind->oldcmd, oldcmd, sizeof (oldcmd)); - memcpy(rewind->oldghost, oldghost, sizeof (oldghost)); - } - } - - memset(name, '\0', 17); - - p = READUINT8(demobuf.p); - - while (p < DW_EXTRASTUFF) - { - extradata = READUINT8(demobuf.p); - - if (extradata & DXD_RESPAWN) - { - if (players[p].mo) - P_DamageMobj(players[p].mo, NULL, NULL, DMG_INSTAKILL); // Is this how this should work..? - } - if (extradata & DXD_SKIN) - { - UINT8 kartspeed, kartweight; - - // Skin - M_Memcpy(name, demobuf.p, 16); - demobuf.p += 16; - SetPlayerSkin(p, name); - - kartspeed = READUINT8(demobuf.p); - kartweight = READUINT8(demobuf.p); - - if (stricmp(skins[players[p].skin].name, name) != 0) - FindClosestSkinForStats(p, kartspeed, kartweight); - - players[p].kartspeed = kartspeed; - players[p].kartweight = kartweight; - } - if (extradata & DXD_COLOR) - { - // Color - M_Memcpy(name, demobuf.p, 16); - demobuf.p += 16; - for (i = 0; i < MAXSKINCOLORS; i++) - if (!stricmp(KartColor_Names[i], name)) // SRB2kart - { - players[p].skincolor = i; - if (players[p].mo) - players[p].mo->color = i; - break; - } - } - if (extradata & DXD_NAME) - { - // Name - M_Memcpy(player_names[p],demobuf.p,16); - demobuf.p += 16; - } - if (extradata & DXD_PLAYSTATE) - { - extradata = READUINT8(demobuf.p); - - switch (extradata) { - case DXD_PST_PLAYING: - players[p].pflags |= PF_WANTSTOJOIN; // fuck you - break; - - case DXD_PST_SPECTATING: - players[p].pflags &= ~PF_WANTSTOJOIN; // double-fuck you - if (!playeringame[p]) - { - CL_ClearPlayer(p); - playeringame[p] = true; - G_AddPlayer(p); - players[p].spectator = true; - - // There's likely an off-by-one error in timing recording or playback of joins. This hacks around it so I don't have to find out where that is. \o/ - if (oldcmd[p].forwardmove) - P_RandomByte(); - } - else - { - players[p].spectator = true; - if (players[p].mo) - P_DamageMobj(players[p].mo, NULL, NULL, DMG_INSTAKILL); - else - players[p].playerstate = PST_REBORN; - } - break; - - case DXD_PST_LEFT: - CL_RemovePlayer(p, 0); - break; - } - - G_ResetViews(); - - // maybe these are necessary? - if (G_BattleGametype()) - K_CheckBumpers(); // SRB2Kart - else if (G_RaceGametype()) - P_CheckRacers(); // also SRB2Kart - } - - - p = READUINT8(demobuf.p); - } - - while (p != DW_END) - { - UINT32 rng; - UINT32 checkrng; - - switch (p) - { - case DW_RNG: - rng = READUINT32(demobuf.p); - checkrng = P_GetRandSeed(); - if (checkrng != rng) - { - if (demosynced) - { - CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced (RNG)!\n")); - CONS_Printf("expected rng %d got %d\n", rng, checkrng); - } - demosynced = false; - - P_SetRandSeed(rng); - } - } - - p = READUINT8(demobuf.p); - } - - if (!(demoflags & DF_GHOST) && *demobuf.p == DEMOMARKER) - { - // end of demo data stream - G_CheckDemoStatus(); - return; - } -} - -void G_WriteDemoExtraData(void) -{ - INT32 i; - char name[17]; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (demo_extradata[i]) - { - WRITEUINT8(demobuf.p, i); - WRITEUINT8(demobuf.p, demo_extradata[i]); - - //if (demo_extradata[i] & DXD_RESPAWN) has no extra data - if (demo_extradata[i] & DXD_SKIN) - { - // Skin - memset(name, 0, 16); - strncpy(name, skins[players[i].skin].name, 16); - M_Memcpy(demobuf.p,name,16); - demobuf.p += 16; - - WRITEUINT8(demobuf.p, skins[players[i].skin].kartspeed); - WRITEUINT8(demobuf.p, skins[players[i].skin].kartweight); - } - if (demo_extradata[i] & DXD_COLOR) - { - // Color - memset(name, 0, 16); - strncpy(name, KartColor_Names[players[i].skincolor], 16); - M_Memcpy(demobuf.p,name,16); - demobuf.p += 16; - } - if (demo_extradata[i] & DXD_NAME) - { - // Name - memset(name, 0, 16); - memcpy(name, player_names[i], 15); // Keeping 1 null byte for safety, sorry players with name containing more than 15 characters - M_Memcpy(demobuf.p,name,16); - demobuf.p += 16; - } - if (demo_extradata[i] & DXD_PLAYSTATE) - { - demo_writerng = 1; - if (!playeringame[i]) - WRITEUINT8(demobuf.p, DXD_PST_LEFT); - else if ( - players[i].spectator && - !(players[i].pflags & PF_WANTSTOJOIN) // <= fuck you specifically - ) - WRITEUINT8(demobuf.p, DXD_PST_SPECTATING); - else - WRITEUINT8(demobuf.p, DXD_PST_PLAYING); - } - } - - demo_extradata[i] = 0; - } - - // May not be necessary, but might as well play it safe... - if ((leveltime & 255) == 128) - demo_writerng = 1; - - { - static UINT8 timeout = 0; - - if (timeout) timeout--; - - if (demo_writerng == 1 || (demo_writerng == 2 && timeout == 0)) - { - demo_writerng = 0; - timeout = 16; - WRITEUINT8(demobuf.p, DW_RNG); - WRITEUINT32(demobuf.p, P_GetRandSeed()); - } - } - - WRITEUINT8(demobuf.p, DW_END); -} - -void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum) -{ - UINT8 ziptic; - - if (!demobuf.p || !demo.deferstart) - return; - ziptic = READUINT8(demobuf.p); - - if (ziptic & ZT_FWD) - oldcmd[playernum].forwardmove = READSINT8(demobuf.p); - if (ziptic & ZT_SIDE) - oldcmd[playernum].sidemove = READSINT8(demobuf.p); - if (ziptic & ZT_ANGLE) - oldcmd[playernum].angleturn = READINT16(demobuf.p); - if (ziptic & ZT_BUTTONS) - oldcmd[playernum].buttons = READUINT16(demobuf.p); - if (ziptic & ZT_AIMING) - oldcmd[playernum].aiming = READINT16(demobuf.p); - if (ziptic & ZT_DRIFT) - oldcmd[playernum].driftturn = READINT16(demobuf.p); - if (ziptic & ZT_LATENCY) - oldcmd[playernum].latency = READUINT8(demobuf.p); - - G_CopyTiccmd(cmd, &oldcmd[playernum], 1); - - // SRB2kart: Copy-pasted from ticcmd building, removes that crappy demo cam - if (((players[displayplayers[0]].mo && players[displayplayers[0]].speed > 0) // Moving - || (leveltime > starttime && (cmd->buttons & BT_ACCELERATE && cmd->buttons & BT_BRAKE)) // Rubber-burn turn - || (players[displayplayers[0]].kartstuff[k_respawn]) // Respawning - || (players[displayplayers[0]].spectator || objectplacing)) // Not a physical player - && !(players[displayplayers[0]].kartstuff[k_spinouttimer] && players[displayplayers[0]].kartstuff[k_sneakertimer])) // Spinning and boosting cancels out spinout - localangle[0] += (cmd->angleturn<<16); - - if (!(demoflags & DF_GHOST) && *demobuf.p == DEMOMARKER) - { - // end of demo data stream - G_CheckDemoStatus(); - return; - } -} - -void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum) -{ - char ziptic = 0; - UINT8 *ziptic_p; - - if (!demobuf.p) - return; - - ziptic_p = demobuf.p++; // the ziptic, written at the end of this function - - if (cmd->forwardmove != oldcmd[playernum].forwardmove) - { - WRITEUINT8(demobuf.p,cmd->forwardmove); - oldcmd[playernum].forwardmove = cmd->forwardmove; - ziptic |= ZT_FWD; - } - - if (cmd->sidemove != oldcmd[playernum].sidemove) - { - WRITEUINT8(demobuf.p,cmd->sidemove); - oldcmd[playernum].sidemove = cmd->sidemove; - ziptic |= ZT_SIDE; - } - - if (cmd->angleturn != oldcmd[playernum].angleturn) - { - WRITEINT16(demobuf.p,cmd->angleturn); - oldcmd[playernum].angleturn = cmd->angleturn; - ziptic |= ZT_ANGLE; - } - - if (cmd->buttons != oldcmd[playernum].buttons) - { - WRITEUINT16(demobuf.p,cmd->buttons); - oldcmd[playernum].buttons = cmd->buttons; - ziptic |= ZT_BUTTONS; - } - - if (cmd->aiming != oldcmd[playernum].aiming) - { - WRITEINT16(demobuf.p,cmd->aiming); - oldcmd[playernum].aiming = cmd->aiming; - ziptic |= ZT_AIMING; - } - - if (cmd->driftturn != oldcmd[playernum].driftturn) - { - WRITEINT16(demobuf.p,cmd->driftturn); - oldcmd[playernum].driftturn = cmd->driftturn; - ziptic |= ZT_DRIFT; - } - - if (cmd->latency != oldcmd[playernum].latency) - { - WRITEUINT8(demobuf.p,cmd->latency); - oldcmd[playernum].latency = cmd->latency; - ziptic |= ZT_LATENCY; - } - - *ziptic_p = ziptic; - - // attention here for the ticcmd size! - // latest demos with mouse aiming byte in ticcmd - if (!(demoflags & DF_GHOST) && ziptic_p > demoend - 9) - { - G_CheckDemoStatus(); // no more space - return; - } -} - -void G_GhostAddThok(INT32 playernum) -{ - if (!demo.recording || !(demoflags & DF_GHOST)) - return; - - ghostext[playernum].flags = (ghostext[playernum].flags & ~EZT_THOKMASK) | EZT_THOK; -} - -void G_GhostAddSpin(INT32 playernum) -{ - if (!demo.recording || !(demoflags & DF_GHOST)) - return; - - ghostext[playernum].flags = (ghostext[playernum].flags & ~EZT_THOKMASK) | EZT_SPIN; -} - -void G_GhostAddRev(INT32 playernum) -{ - if (!demo.recording || !(demoflags & DF_GHOST)) - return; - - ghostext[playernum].flags = (ghostext[playernum].flags & ~EZT_THOKMASK) | EZT_REV; -} - -void G_GhostAddFlip(INT32 playernum) -{ - if (!demo.recording || !(demoflags & DF_GHOST)) - return; - - ghostext[playernum].flags |= EZT_FLIP; -} - -void G_GhostAddColor(INT32 playernum, ghostcolor_t color) -{ - if (!demo.recording || !(demoflags & DF_GHOST)) - return; - - if (ghostext[playernum].lastcolor == (UINT8)color) - { - ghostext[playernum].flags &= ~EZT_COLOR; - return; - } - - ghostext[playernum].flags |= EZT_COLOR; - ghostext[playernum].color = (UINT8)color; -} - -void G_GhostAddScale(INT32 playernum, fixed_t scale) -{ - if (!demo.recording || !(demoflags & DF_GHOST)) - return; - - if (ghostext[playernum].lastscale == scale) - { - ghostext[playernum].flags &= ~EZT_SCALE; - return; - } - - ghostext[playernum].flags |= EZT_SCALE; - ghostext[playernum].scale = scale; -} - -void G_GhostAddHit(INT32 playernum, mobj_t *victim) -{ - if (!demo.recording || !(demoflags & DF_GHOST)) - return; - - ghostext[playernum].flags |= EZT_HIT; - ghostext[playernum].hits++; - ghostext[playernum].hitlist = Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_LEVEL, &ghostext[playernum].hitlist); - P_SetTarget(ghostext[playernum].hitlist + (ghostext[playernum].hits-1), victim); -} - -void G_WriteAllGhostTics(void) -{ - if (!demobuf.p) - return; - - UINT8 *save_demo_p = demobuf.p; -#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } - - boolean toobig = false; - INT32 i, counter = leveltime; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].spectator) - continue; - - if (P_MobjWasRemoved(players[i].mo)) - continue; - - counter++; - - if (multiplayer && ((counter % cv_netdemosyncquality.value) != 0)) // Only write 1 in this many ghost datas per tic to cut down on multiplayer replay size. - continue; - - if (((ghostext[i].flags && (ghostext[i].flags & EZT_HIT)) || ghostext[i].hits) - && !ghostext[i].hitlist) // hitlist might be freed during resynch, beware PU_LEVEL! - { - ghostext[i].hits = 0; - continue; - } - - CHECKSPACE(1); - - WRITEUINT8(demobuf.p, i); - G_WriteGhostTic(players[i].mo, i); - - // attention here for the ticcmd size! - // latest demos with mouse aiming byte in ticcmd - if (demobuf.p >= demoend - (13 + 9 + 9)) - { - toobig = true; - break; - } - } - - CHECKSPACE(1); - WRITEUINT8(demobuf.p, 0xFF); - - if (toobig) - { - G_CheckDemoStatus(); // no more space - return; - } - -#undef CHECKSPACE -} - -void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) -{ - char ziptic = 0; - UINT8 *ziptic_p; - UINT32 i; - UINT8 sprite; - UINT8 frame; - - if (!demobuf.p) - return; - - UINT8 *save_demo_p = demobuf.p; -#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; } - - if (!(demoflags & DF_GHOST)) - return; // No ghost data to write. - - if (ghost->player && ghost->player->pflags & PF_NIGHTSMODE && ghost->tracer) - { - // We're talking about the NiGHTS thing, not the normal platforming thing! - ziptic |= GZT_NIGHTS; - ghost = ghost->tracer; - } - - ziptic_p = demobuf.p++; // the ziptic, written at the end of this function - -#define MAXMOM (0x7FFF<<8) - - // GZT_XYZ is only useful if you've moved 256 FRACUNITS or more in a single tic. - if (abs(ghost->x-oldghost[playernum].x) > MAXMOM - || abs(ghost->y-oldghost[playernum].y) > MAXMOM - || abs(ghost->z-oldghost[playernum].z) > MAXMOM - || ((UINT8)(leveltime & 255) > 0 && (UINT8)(leveltime & 255) <= (UINT8)cv_netdemosyncquality.value)) // Hack to enable slightly nicer resyncing - { - oldghost[playernum].x = ghost->x; - oldghost[playernum].y = ghost->y; - oldghost[playernum].z = ghost->z; - ziptic |= GZT_XYZ; - - CHECKSPACE(sizeof(fixed_t)*3); - WRITEFIXED(demobuf.p, oldghost[playernum].x); - WRITEFIXED(demobuf.p, oldghost[playernum].y); - WRITEFIXED(demobuf.p, oldghost[playernum].z); - } - else - { - // For moving normally: - // Store one full byte of movement, plus one byte of fractional movement. - INT16 momx = (INT16)((ghost->x-oldghost[playernum].x + (1<<4))>>8); - INT16 momy = (INT16)((ghost->y-oldghost[playernum].y + (1<<4))>>8); - - if (momx != oldghost[playernum].momx - || momy != oldghost[playernum].momy) - { - oldghost[playernum].momx = momx; - oldghost[playernum].momy = momy; - ziptic |= GZT_MOMXY; - - CHECKSPACE(4); - - WRITEINT16(demobuf.p, momx); - WRITEINT16(demobuf.p, momy); - } - - momx = (INT16)((ghost->z-oldghost[playernum].z + (1<<4))>>8); - - if (momx != oldghost[playernum].momz) - { - oldghost[playernum].momz = momx; - ziptic |= GZT_MOMZ; - - CHECKSPACE(2); - - WRITEINT16(demobuf.p, momx); - } - - // This SHOULD set oldghost.x/y/z to match ghost->x/y/z - // but it keeps the fractional loss of one byte, - // so it will hopefully be made up for in future tics. - oldghost[playernum].x += oldghost[playernum].momx<<8; - oldghost[playernum].y += oldghost[playernum].momy<<8; - oldghost[playernum].z += oldghost[playernum].momz<<8; - } - -#undef MAXMOM - - // Only store the 8 most relevant bits of angle - // because exact values aren't too easy to discern to begin with when only 8 angles have different sprites - // and it does not affect this mode of movement at all anyway. - if (ghost->angle>>24 != oldghost[playernum].angle) - { - oldghost[playernum].angle = ghost->angle>>24; - ziptic |= GZT_ANGLE; - - CHECKSPACE(1); - - WRITEUINT8(demobuf.p, oldghost[playernum].angle); - } - - // Store the sprite frame. - frame = ghost->frame & 0xFF; - if (frame != oldghost[playernum].frame) - { - oldghost[playernum].frame = frame; - ziptic |= GZT_SPRITE; - - CHECKSPACE(1); - - WRITEUINT8(demobuf.p, oldghost[playernum].frame); - } - - // Check for sprite set changes - sprite = ghost->sprite; - if (sprite != oldghost[playernum].sprite) - { - oldghost[playernum].sprite = sprite; - ghostext[playernum].flags |= EZT_SPRITE; - } - - if (ghost->player) - { - if ( - ghostext[playernum].kartitem != ghost->player->kartstuff[k_itemtype] || - ghostext[playernum].kartamount != ghost->player->kartstuff[k_itemamount] || - ghostext[playernum].kartbumpers != ghost->player->kartstuff[k_bumper] - ) - { - ghostext[playernum].flags |= EZT_KART; - ghostext[playernum].kartitem = ghost->player->kartstuff[k_itemtype]; - ghostext[playernum].kartamount = ghost->player->kartstuff[k_itemamount]; - ghostext[playernum].kartbumpers = ghost->player->kartstuff[k_bumper]; - - } - } - - if (ghostext[playernum].color == ghostext[playernum].lastcolor) - ghostext[playernum].flags &= ~EZT_COLOR; - - if (ghostext[playernum].scale == ghostext[playernum].lastscale) - ghostext[playernum].flags &= ~EZT_SCALE; - - if (ghostext[playernum].flags) - { - ziptic |= GZT_EXTRA; - WRITEUINT8(demobuf.p, ghostext[playernum].flags); - - if (ghostext[playernum].flags & EZT_COLOR) - { - CHECKSPACE(1); - WRITEUINT8(demobuf.p, ghostext[playernum].color); - ghostext[playernum].lastcolor = ghostext[playernum].color; - } - - if (ghostext[playernum].flags & EZT_SCALE) - { - CHECKSPACE(sizeof(fixed_t)); - WRITEFIXED(demobuf.p, ghostext[playernum].scale); - ghostext[playernum].lastscale = ghostext[playernum].scale; - } - - if (ghostext[playernum].flags & EZT_HIT) - { - CHECKSPACE(2); - WRITEUINT16(demobuf.p, ghostext[playernum].hits); - - for (i = 0; i < ghostext[playernum].hits; i++) - { - mobj_t *mo = ghostext[playernum].hitlist[i]; - - CHECKSPACE(4+4+2+sizeof(fixed_t)*3+sizeof(angle_t)); - - WRITEUINT32(demobuf.p, UINT32_MAX); // reserved for some method of determining exactly which mobj this is. (mobjnum doesn't work here.) - WRITEUINT32(demobuf.p, mo->type); - WRITEUINT16(demobuf.p, (UINT16)mo->health); - WRITEFIXED(demobuf.p, mo->x); - WRITEFIXED(demobuf.p, mo->y); - WRITEFIXED(demobuf.p, mo->z); - WRITEANGLE(demobuf.p, mo->angle); - P_SetTarget(ghostext[playernum].hitlist+i, NULL); - } - - ghostext[playernum].hits = 0; - } - - if (ghostext[playernum].flags & EZT_SPRITE) - { - CHECKSPACE(1); - WRITEUINT8(demobuf.p, sprite); - } - - if (ghostext[playernum].flags & EZT_KART) - { - CHECKSPACE(12); - WRITEINT32(demobuf.p, ghostext[playernum].kartitem); - WRITEINT32(demobuf.p, ghostext[playernum].kartamount); - WRITEINT32(demobuf.p, ghostext[playernum].kartbumpers); - } - - ghostext[playernum].flags = 0; - } - - *ziptic_p = ziptic; -#undef CHECKSPACE -} - -void G_ConsAllGhostTics(void) -{ - UINT8 p; - - if (!demobuf.p || !demo.deferstart) - return; - - p = READUINT8(demobuf.p); - - while (p != 0xFF) - { - G_ConsGhostTic(p); - p = READUINT8(demobuf.p); - } - - if (*demobuf.p == DEMOMARKER) - { - // end of demo data stream - G_CheckDemoStatus(); - return; - } -} - -// Uses ghost data to do consistency checks on your position. -// This fixes desynchronising demos when fighting eggman. -void G_ConsGhostTic(INT32 playernum) -{ - UINT8 ziptic; - fixed_t px,py,pz,gx,gy,gz; - mobj_t *testmo; - fixed_t syncleeway; - boolean nightsfail = false; - - if (!(demoflags & DF_GHOST)) - return; // No ghost data to use. - - testmo = players[playernum].mo; - - // Grab ghost data. - ziptic = READUINT8(demobuf.p); - - if (ziptic & GZT_XYZ) - { - oldghost[playernum].x = READFIXED(demobuf.p); - oldghost[playernum].y = READFIXED(demobuf.p); - oldghost[playernum].z = READFIXED(demobuf.p); - syncleeway = 0; - } - else - { - if (ziptic & GZT_MOMXY) - { - oldghost[playernum].momx = READINT16(demobuf.p)<<8; - oldghost[playernum].momy = READINT16(demobuf.p)<<8; - } - - if (ziptic & GZT_MOMZ) - oldghost[playernum].momz = READINT16(demobuf.p)<<8; - - oldghost[playernum].x += oldghost[playernum].momx; - oldghost[playernum].y += oldghost[playernum].momy; - oldghost[playernum].z += oldghost[playernum].momz; - syncleeway = FRACUNIT; - } - - if (ziptic & GZT_ANGLE) - demobuf.p++; - - if (ziptic & GZT_SPRITE) - demobuf.p++; - - if (ziptic & GZT_NIGHTS) - { - if (!testmo || !testmo->player || !(testmo->player->pflags & PF_NIGHTSMODE) || !testmo->tracer) - nightsfail = true; - else - testmo = testmo->tracer; - } - - if (ziptic & GZT_EXTRA) - { // But wait, there's more! - ziptic = READUINT8(demobuf.p); - if (ziptic & EZT_COLOR) - demobuf.p++; - - if (ziptic & EZT_SCALE) - demobuf.p += sizeof(fixed_t); - - if (ziptic & EZT_HIT) - { // Resync mob damage. - UINT16 i, count = READUINT16(demobuf.p); - thinker_t *th; - mobj_t *mobj; - - UINT32 type; - UINT16 health; - fixed_t x; - fixed_t y; - fixed_t z; - - for (i = 0; i < count; i++) - { - demobuf.p += 4; // reserved. - type = READUINT32(demobuf.p); - health = READUINT16(demobuf.p); - x = READFIXED(demobuf.p); - y = READFIXED(demobuf.p); - z = READFIXED(demobuf.p); - demobuf.p += sizeof(angle_t); // angle, unnecessary for cons. - - mobj = NULL; - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - mobj = (mobj_t *)th; - if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) - break; - mobj = NULL; // wasn't this one, keep searching. - } - - if (mobj && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! - { - if (demosynced) - { - CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced (health)!\n")); - CONS_Printf("expected health %d got %d\n", health, mobj->health); - } - - demosynced = false; - P_DamageMobj(mobj, players[0].mo, players[0].mo, 1); - } - } - } - - if (ziptic & EZT_SPRITE) - demobuf.p++; - - if (ziptic & EZT_KART) - { - ghostext[playernum].kartitem = READINT32(demobuf.p); - ghostext[playernum].kartamount = READINT32(demobuf.p); - ghostext[playernum].kartbumpers = READINT32(demobuf.p); - } - } - - if (testmo) - { - // Re-synchronise - px = testmo->x; - py = testmo->y; - pz = testmo->z; - gx = oldghost[playernum].x; - gy = oldghost[playernum].y; - gz = oldghost[playernum].z; - - if (nightsfail || abs(px-gx) > syncleeway || abs(py-gy) > syncleeway || abs(pz-gz) > syncleeway) - { - ghostext[playernum].desyncframes++; - - if (ghostext[playernum].desyncframes >= 2) - { - if (demosynced) - CONS_Alert(CONS_WARNING, "Demo playback has desynced (player %s)!\n", player_names[playernum]); - demosynced = false; - - P_UnsetThingPosition(testmo); - testmo->x = oldghost[playernum].x; - testmo->y = oldghost[playernum].y; - P_SetThingPosition(testmo); - testmo->z = oldghost[playernum].z; - - if (abs(testmo->z - testmo->floorz) < 4*FRACUNIT) - testmo->z = testmo->floorz; // Sync players to the ground when they're likely supposed to be there... - - ghostext[playernum].desyncframes = 2; - } - } - else - ghostext[playernum].desyncframes = 0; - - if ( -#ifdef DEMO_COMPAT_100 - demo.version != 0x0001 && -#endif - ( - players[playernum].kartstuff[k_itemtype] != ghostext[playernum].kartitem || - players[playernum].kartstuff[k_itemamount] != ghostext[playernum].kartamount || - players[playernum].kartstuff[k_bumper] != ghostext[playernum].kartbumpers - ) - ) - { - if (demosynced) - { - CONS_Alert(CONS_WARNING, "Demo playback has desynced (item/bumpers)!(player %s)!\n", player_names[playernum]); - CONS_Printf("expected item type %d got %d\n", ghostext[playernum].kartitem, players[playernum].kartstuff[k_itemtype]); - CONS_Printf("expected item amount %d got %d\n", ghostext[playernum].kartamount, players[playernum].kartstuff[k_itemamount]); - } - demosynced = false; - - players[playernum].kartstuff[k_itemtype] = ghostext[playernum].kartitem; - players[playernum].kartstuff[k_itemamount] = ghostext[playernum].kartamount; - players[playernum].kartstuff[k_bumper] = ghostext[playernum].kartbumpers; - } - } - - if (*demobuf.p == DEMOMARKER) - { - // end of demo data stream - G_CheckDemoStatus(); - return; - } -} - -void G_GhostTicker(void) -{ - demoghost *g,*p; - - for (g = ghosts, p = NULL; g; g = g->next) - { - // Skip normal demo data. - UINT8 ziptic = READUINT8(g->p); - -#ifdef DEMO_COMPAT_100 - if (g->version != 0x0001) - { -#endif - while (ziptic != DW_END) // Get rid of extradata stuff - { - if (ziptic == 0) // Only support player 0 info for now - { - ziptic = READUINT8(g->p); - if (ziptic & DXD_SKIN) - g->p += 18; // We _could_ read this info, but it shouldn't change anything in record attack... - if (ziptic & DXD_COLOR) - g->p += 16; // Same tbh - if (ziptic & DXD_NAME) - g->p += 16; // yea - if (ziptic & DXD_PLAYSTATE && READUINT8(g->p) != DXD_PST_PLAYING) - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this - } - else if (ziptic == DW_RNG) - g->p += 4; // RNG seed - else - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this - - ziptic = READUINT8(g->p); - } - - ziptic = READUINT8(g->p); // Back to actual ziptic stuff -#ifdef DEMO_COMPAT_100 - } -#endif - - if (ziptic & ZT_FWD) - g->p++; - if (ziptic & ZT_SIDE) - g->p++; - if (ziptic & ZT_ANGLE) - g->p += 2; - if (ziptic & ZT_BUTTONS) - g->p += 2; - if (ziptic & ZT_AIMING) - g->p += 2; - if (ziptic & ZT_DRIFT) - g->p += 2; - if (ziptic & ZT_LATENCY) - g->p += 1; - - // Grab ghost data. - ziptic = READUINT8(g->p); - -#ifdef DEMO_COMPAT_100 - if (g->version != 0x0001) - { -#endif - if (ziptic == 0xFF) - goto skippedghosttic; // Didn't write ghost info this frame - else if (ziptic != 0) - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this - ziptic = READUINT8(g->p); -#ifdef DEMO_COMPAT_100 - } -#endif - if (ziptic & GZT_XYZ) - { - g->oldmo.x = READFIXED(g->p); - g->oldmo.y = READFIXED(g->p); - g->oldmo.z = READFIXED(g->p); - } - else - { - if (ziptic & GZT_MOMXY) - { - g->oldmo.momx = READINT16(g->p)<<8; - g->oldmo.momy = READINT16(g->p)<<8; - } - if (ziptic & GZT_MOMZ) - g->oldmo.momz = READINT16(g->p)<<8; - g->oldmo.x += g->oldmo.momx; - g->oldmo.y += g->oldmo.momy; - g->oldmo.z += g->oldmo.momz; - } - if (ziptic & GZT_ANGLE) - g->oldmo.angle = READUINT8(g->p)<<24; - if (ziptic & GZT_SPRITE) - g->oldmo.frame = READUINT8(g->p); - - // Update ghost - P_UnsetThingPosition(g->mo); - g->mo->x = g->oldmo.x; - g->mo->y = g->oldmo.y; - g->mo->z = g->oldmo.z; - P_SetThingPosition(g->mo); - g->mo->angle = g->oldmo.angle; - g->mo->frame = g->oldmo.frame | tr_trans30<p); - if (ziptic & EZT_COLOR) - { - g->color = READUINT8(g->p); - switch(g->color) - { - default: - case GHC_NORMAL: // Go back to skin color - g->mo->color = g->oldmo.color; - break; - // Handled below - case GHC_SUPER: - case GHC_INVINCIBLE: - break; - case GHC_FIREFLOWER: // Fireflower - g->mo->color = SKINCOLOR_WHITE; - break; - } - } - if (ziptic & EZT_FLIP) - g->mo->eflags ^= MFE_VERTICALFLIP; - if (ziptic & EZT_SCALE) - { - g->mo->destscale = READFIXED(g->p); - if (g->mo->destscale != g->mo->scale) - P_SetScale(g->mo, g->mo->destscale); - } - if (ziptic & EZT_THOKMASK) - { // Let's only spawn ONE of these per frame, thanks. - mobj_t *mobj; - INT32 type = -1; - if (g->mo->skin) - { - switch (ziptic & EZT_THOKMASK) - { - case EZT_THOK: - type = (UINT32)mobjinfo[MT_PLAYER].painchance; - break; - case EZT_SPIN: - type = (UINT32)mobjinfo[MT_PLAYER].damage; - break; - case EZT_REV: - type = (UINT32)mobjinfo[MT_PLAYER].raisestate; - break; - } - } - if (type != -1) - { - if (type == MT_GHOST) - { - mobj = P_SpawnGhostMobj(g->mo); // does a large portion of the work for us - mobj->frame = (mobj->frame & ~FF_FRAMEMASK)|tr_trans60<mo->x, g->mo->y, g->mo->z - FixedDiv(FixedMul(g->mo->info->height, g->mo->scale) - g->mo->height,3*FRACUNIT), MT_THOK); - mobj->sprite = states[mobjinfo[type].spawnstate].sprite; - mobj->frame = (states[mobjinfo[type].spawnstate].frame & FF_FRAMEMASK) | tr_trans60<tics = -1; // nope. - mobj->color = g->mo->color; - if (g->mo->eflags & MFE_VERTICALFLIP) - { - mobj->flags2 |= MF2_OBJECTFLIP; - mobj->eflags |= MFE_VERTICALFLIP; - } - P_SetScale(mobj, g->mo->scale); - mobj->destscale = g->mo->scale; - } - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_UnsetThingPosition(mobj); - mobj->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... - P_SetThingPosition(mobj); - mobj->fuse = 8; - P_SetTarget(&mobj->target, g->mo); - } - } - if (ziptic & EZT_HIT) - { // Spawn hit poofs for killing things! - UINT16 i, count = READUINT16(g->p), health; - //UINT32 type; - fixed_t x,y,z; - angle_t angle; - mobj_t *poof; - for (i = 0; i < count; i++) - { - g->p += 4; // reserved - g->p += 4; // backwards compat., type used to be here - health = READUINT16(g->p); - x = READFIXED(g->p); - y = READFIXED(g->p); - z = READFIXED(g->p); - angle = READANGLE(g->p); - if (health != 0 || i >= 4) // only spawn for the first 4 hits per frame, to prevent ghosts from splode-spamming too bad. - continue; - poof = P_SpawnMobj(x, y, z, MT_GHOST); - poof->angle = angle; - poof->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... - poof->health = 0; - P_SetMobjStateNF(poof, S_XPLD1); - } - } - if (ziptic & EZT_SPRITE) - g->mo->sprite = READUINT8(g->p); - if (ziptic & EZT_KART) - g->p += 12; // kartitem, kartamount, kartbumpers - } - -#ifdef DEMO_COMPAT_100 - if (g->version != 0x0001) - { -#endif - if (READUINT8(g->p) != 0xFF) // Make sure there isn't other ghost data here. - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this -#ifdef DEMO_COMPAT_100 - } -#endif - -skippedghosttic: - // Tick ghost colors (Super and Mario Invincibility flashing) - switch(g->color) - { - case GHC_SUPER: // Super Sonic (P_DoSuperStuff) - g->mo->color = SKINCOLOR_SUPER1; - g->mo->color += abs( ( (signed)( (unsigned)leveltime >> 1 ) % 9) - 4); - break; - case GHC_INVINCIBLE: // Mario invincibility (P_CheckInvincibilityTimer) - g->mo->color = (UINT8)(leveltime % MAXSKINCOLORS); - break; - default: - break; - } - - // Demo ends after ghost data. - if (*g->p == DEMOMARKER) - { - g->mo->momx = g->mo->momy = g->mo->momz = 0; - if (p) - p->next = g->next; - else - ghosts = g->next; - Z_Free(g); - continue; - } - p = g; - } -} - -// Demo rewinding functions -typedef struct rewindinfo_s { - tic_t leveltime; - - struct { - boolean ingame; - player_t player; - mobj_t mobj; - } playerinfo[MAXPLAYERS]; - - struct rewindinfo_s *prev; -} rewindinfo_t; - -static tic_t currentrewindnum; -static rewindinfo_t *rewindhead = NULL; // Reverse chronological order - -void G_InitDemoRewind(void) -{ - CL_ClearRewinds(); - - while (rewindhead) - { - rewindinfo_t *p = rewindhead->prev; - Z_Free(rewindhead); - rewindhead = p; - } - - currentrewindnum = 0; -} - -void G_StoreRewindInfo(void) -{ - static UINT8 timetolog = 8; - rewindinfo_t *info; - size_t i; - - if (timetolog-- > 0) - return; - timetolog = 8; - - info = Z_Calloc(sizeof(rewindinfo_t), PU_STATIC, NULL); - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].spectator) - { - info->playerinfo[i].ingame = false; - continue; - } - - info->playerinfo[i].ingame = true; - memcpy(&info->playerinfo[i].player, &players[i], sizeof(player_t)); - if (players[i].mo) - memcpy(&info->playerinfo[i].mobj, players[i].mo, sizeof(mobj_t)); - } - - info->leveltime = leveltime; - info->prev = rewindhead; - rewindhead = info; -} - -void G_PreviewRewind(tic_t previewtime) -{ - SINT8 i; - size_t j; - fixed_t tweenvalue = 0; - rewindinfo_t *info = rewindhead, *next_info = rewindhead; - - if (!info) - return; - - while (info->leveltime > previewtime && info->prev) - { - next_info = info; - info = info->prev; - } - if (info != next_info) - tweenvalue = FixedDiv(previewtime - info->leveltime, next_info->leveltime - info->leveltime); - - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].spectator) - { - if (info->playerinfo[i].player.mo) - { - //@TODO spawn temp object to act as a player display - } - - continue; - } - - if (!info->playerinfo[i].ingame || !info->playerinfo[i].player.mo) - { - if (players[i].mo) - players[i].mo->flags2 |= MF2_DONTDRAW; - - continue; - } - - if (!players[i].mo) - continue; //@TODO spawn temp object to act as a player display - - players[i].mo->flags2 &= ~MF2_DONTDRAW; - - P_UnsetThingPosition(players[i].mo); -#define TWEEN(pr) info->playerinfo[i].mobj.pr + FixedMul((INT32) (next_info->playerinfo[i].mobj.pr - info->playerinfo[i].mobj.pr), tweenvalue) - players[i].mo->x = TWEEN(x); - players[i].mo->y = TWEEN(y); - players[i].mo->z = TWEEN(z); - players[i].mo->angle = TWEEN(angle); -#undef TWEEN - P_SetThingPosition(players[i].mo); - - players[i].frameangle = info->playerinfo[i].player.frameangle + FixedMul((INT32) (next_info->playerinfo[i].player.frameangle - info->playerinfo[i].player.frameangle), tweenvalue); - - players[i].mo->sprite = info->playerinfo[i].mobj.sprite; - players[i].mo->frame = info->playerinfo[i].mobj.frame; - - players[i].realtime = info->playerinfo[i].player.realtime; - for (j = 0; j < NUMKARTSTUFF; j++) - players[i].kartstuff[j] = info->playerinfo[i].player.kartstuff[j]; - } - - for (i = splitscreen; i >= 0; i--) - P_ResetCamera(&players[displayplayers[i]], &camera[i]); -} - -void G_ConfirmRewind(tic_t rewindtime) -{ - SINT8 i; - tic_t j; - boolean oldmenuactive = menuactive, oldsounddisabled = sound_disabled; - - INT32 olddp1 = displayplayers[0], olddp2 = displayplayers[1], olddp3 = displayplayers[2], olddp4 = displayplayers[3]; - UINT8 oldss = splitscreen; - - menuactive = false; // Prevent loops - - CV_StealthSetValue(&cv_renderview, 0); - - if (rewindtime <= starttime) - { - demo.rewinding = false; - G_DoPlayDemo(NULL); // Restart the current demo - } - else - { - rewind_t *rewind; - sound_disabled = true; // Prevent sound spam - demo.rewinding = true; - - rewind = CL_RewindToTime(rewindtime); - - if (rewind) - { - demobuf.p = demobuf.buffer + rewind->demopos; - memcpy(oldcmd, rewind->oldcmd, sizeof (oldcmd)); - memcpy(oldghost, rewind->oldghost, sizeof (oldghost)); - paused = false; - } - else - { - demo.rewinding = true; - G_DoPlayDemo(NULL); // Restart the current demo - } - } - - for (j = 0; j < rewindtime && leveltime < rewindtime; j++) - { - G_Ticker((j % NEWTICRATERATIO) == 0); - } - - demo.rewinding = false; - menuactive = oldmenuactive; // Bring the menu back up - sound_disabled = oldsounddisabled; // Re-enable SFX - - wipegamestate = gamestate; // No fading back in! - - COM_BufInsertText("renderview on\n"); - - splitscreen = oldss; - displayplayers[0] = olddp1; - displayplayers[1] = olddp2; - displayplayers[2] = olddp3; - displayplayers[3] = olddp4; - R_ExecuteSetViewSize(); - G_ResetViews(); - - for (i = splitscreen; i >= 0; i--) - P_ResetCamera(&players[displayplayers[i]], &camera[i]); -} - -void G_ReadMetalTic(mobj_t *metal) -{ - UINT8 ziptic; - UINT16 speed; - UINT8 statetype; - - if (!metal_p) - return; - ziptic = READUINT8(metal_p); - - // Read changes from the tic - if (ziptic & GZT_XYZ) - { - oldmetal.x = READFIXED(metal_p); - oldmetal.y = READFIXED(metal_p); - oldmetal.z = READFIXED(metal_p); - P_MoveOrigin(metal, oldmetal.x, oldmetal.y, oldmetal.z); - oldmetal.x = metal->x; - oldmetal.y = metal->y; - oldmetal.z = metal->z; - } - else - { - if (ziptic & GZT_MOMXY) - { - oldmetal.momx = READINT16(metal_p)<<8; - oldmetal.momy = READINT16(metal_p)<<8; - } - if (ziptic & GZT_MOMZ) - oldmetal.momz = READINT16(metal_p)<<8; - oldmetal.x += oldmetal.momx; - oldmetal.y += oldmetal.momy; - oldmetal.z += oldmetal.momz; - } - if (ziptic & GZT_ANGLE) - oldmetal.angle = READUINT8(metal_p)<<24; - if (ziptic & GZT_SPRITE) - metal_p++; // Currently unused. (Metal Sonic figures out what he's doing his own damn self.) - - // Set movement, position, and angle - // oldmetal contains where you're supposed to be. - metal->momx = oldmetal.momx; - metal->momy = oldmetal.momy; - metal->momz = oldmetal.momz; - P_UnsetThingPosition(metal); - metal->x = oldmetal.x; - metal->y = oldmetal.y; - metal->z = oldmetal.z; - P_SetThingPosition(metal); - metal->angle = oldmetal.angle; - - if (ziptic & GZT_EXTRA) - { // But wait, there's more! - ziptic = READUINT8(metal_p); - if (ziptic & EZT_FLIP) - metal->eflags ^= MFE_VERTICALFLIP; - if (ziptic & EZT_SCALE) - { - metal->destscale = READFIXED(metal_p); - if (metal->destscale != metal->scale) - P_SetScale(metal, metal->destscale); - } - } - - // Calculates player's speed based on distance-of-a-line formula - speed = FixedDiv(P_AproxDistance(oldmetal.momx, oldmetal.momy), metal->scale)>>FRACBITS; - - // Use speed to decide an appropriate state - if (speed > 20) // default skin runspeed - statetype = 2; - else if (speed > 1) // stopspeed - statetype = 1; - else - statetype = 0; - - // Set state - if (statetype != metal->threshold) - { - switch (statetype) - { - case 2: // run - P_SetMobjState(metal,metal->info->meleestate); - break; - case 1: // walk - P_SetMobjState(metal,metal->info->seestate); - break; - default: // stand - P_SetMobjState(metal,metal->info->spawnstate); - break; - } - metal->threshold = statetype; - } - - // TODO: Modify state durations based on movement speed, similar to players? - - if (*metal_p == DEMOMARKER) - { - // end of demo data stream - G_StopMetalDemo(); - return; - } -} - -void G_WriteMetalTic(mobj_t *metal) -{ - UINT8 ziptic = 0; - UINT8 *ziptic_p; - - if (!demobuf.p) // demobuf.p will be NULL until the race start linedef executor is triggered! - return; - - ziptic_p = demobuf.p++; // the ziptic, written at the end of this function - - #define MAXMOM (0xFFFF<<8) - - // GZT_XYZ is only useful if you've moved 256 FRACUNITS or more in a single tic. - if (abs(metal->x-oldmetal.x) > MAXMOM - || abs(metal->y-oldmetal.y) > MAXMOM - || abs(metal->z-oldmetal.z) > MAXMOM) - { - oldmetal.x = metal->x; - oldmetal.y = metal->y; - oldmetal.z = metal->z; - WRITEFIXED(demobuf.p,oldmetal.x); - WRITEFIXED(demobuf.p,oldmetal.y); - WRITEFIXED(demobuf.p,oldmetal.z); - ziptic |= GZT_XYZ; - } - else - { - // For moving normally: - // Store one full byte of movement, plus one byte of fractional movement. - INT16 momx = (INT16)((metal->x-oldmetal.x)>>8); - INT16 momy = (INT16)((metal->y-oldmetal.y)>>8); - if (momx != oldmetal.momx - || momy != oldmetal.momy) - { - oldmetal.momx = momx; - oldmetal.momy = momy; - WRITEINT16(demobuf.p,momx); - WRITEINT16(demobuf.p,momy); - ziptic |= GZT_MOMXY; - } - momx = (INT16)((metal->z-oldmetal.z)>>8); - if (momx != oldmetal.momz) - { - oldmetal.momz = momx; - WRITEINT16(demobuf.p,momx); - ziptic |= GZT_MOMZ; - } - - // This SHOULD set oldmetal.x/y/z to match metal->x/y/z - // but it keeps the fractional loss of one byte, - // so it will hopefully be made up for in future tics. - oldmetal.x += oldmetal.momx<<8; - oldmetal.y += oldmetal.momy<<8; - oldmetal.z += oldmetal.momz<<8; - } - - #undef MAXMOM - - // Only store the 8 most relevant bits of angle - // because exact values aren't too easy to discern to begin with when only 8 angles have different sprites - // and it does not affect movement at all anyway. - if (metal->angle>>24 != oldmetal.angle) - { - oldmetal.angle = metal->angle>>24; - WRITEUINT8(demobuf.p,oldmetal.angle); - ziptic |= GZT_ANGLE; - } - - // Metal Sonic does not need our state changes. - // ... currently. - - { - UINT8 *exttic_p = NULL; - UINT8 exttic = 0; - if ((metal->eflags & MFE_VERTICALFLIP) != (oldmetal.eflags & MFE_VERTICALFLIP)) - { - if (!exttic_p) - exttic_p = demobuf.p++; - exttic |= EZT_FLIP; - oldmetal.eflags ^= MFE_VERTICALFLIP; - } - if (metal->scale != oldmetal.scale) - { - if (!exttic_p) - exttic_p = demobuf.p++; - exttic |= EZT_SCALE; - WRITEFIXED(demobuf.p,metal->scale); - oldmetal.scale = metal->scale; - } - if (exttic_p) - { - *exttic_p = exttic; - ziptic |= GZT_EXTRA; - } - } - - *ziptic_p = ziptic; - - // attention here for the ticcmd size! - // latest demos with mouse aiming byte in ticcmd - if (demobuf.p >= demoend - 32) - { - G_StopMetalRecording(); // no more space - return; - } -} - -// -// G_RecordDemo -// -void G_RecordDemo(const char *name) -{ - INT32 maxsize; - - demobuf.p = NULL; - G_ResetDemoRecording(); - demoend = NULL; - - if (cv_recordmultiplayerdemos.value) - { - CONS_Printf("Recording demo %s.lmp\n", name); - - strcpy(demoname, name); - strcat(demoname, ".lmp"); - - maxsize = cv_maxdemosize.value*1024*1024; - - demobuf.buffer = Z_Malloc(maxsize + 100*1024, PU_STATIC, NULL); - demoend = demobuf.buffer + maxsize; - - if (demobuf.buffer) - demo.recording = true; - else - CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); - } -} - -void G_RecordMetal(void) -{ - INT32 maxsize; - maxsize = cv_maxdemosize.value*1024*1024; - if (demobuf.buffer) - Z_Free(demobuf.buffer); - demobuf.p = NULL; - metalrecording = false; - demobuf.buffer = Z_Malloc(maxsize + 100*1024, PU_STATIC, NULL); - demoend = demobuf.buffer + maxsize; - - if (demobuf.buffer) - metalrecording = true; - else - CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); -} - -void G_BeginRecording(void) -{ - UINT8 i, p; - char name[17]; - player_t *player = &players[consoleplayer]; - - char *filename; - UINT8 totalfiles; - UINT8 *m; - - if (!cv_recordmultiplayerdemos.value) - { - G_ResetDemoRecording(); - return; - } - - if (demobuf.buffer == NULL) - { - CONS_Alert(CONS_ERROR, "No demo buffer allocated\n"); - G_ResetDemoRecording(); - return; - } - - if (demobuf.p) - { - G_ResetDemoRecording(); - return; - } - - memset(name,0,sizeof(name)); - - demobuf.p = demobuf.buffer; - demoflags = DF_GHOST|(multiplayer ? DF_MULTIPLAYER : (modeattacking<important) - { - nameonly(( filename = va("%s", wadfiles[i]->filename) )); - WRITESTRINGL(demobuf.p, filename, MAX_WADPATH); - WRITEMEM(demobuf.p, wadfiles[i]->md5sum, 16); - - totalfiles++; - } - - WRITEUINT8(m, totalfiles); - - switch ((demoflags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) - { - case ATTACKING_NONE: // 0 - break; - case ATTACKING_RECORD: // 1 - demotime_p = demobuf.p; - WRITEUINT32(demobuf.p,UINT32_MAX); // time - WRITEUINT32(demobuf.p,UINT32_MAX); // lap - break; - default: // 3 - break; - } - - WRITEUINT32(demobuf.p, P_GetInitSeed()); - - // Reserved for extrainfo location from start of file - demoinfo_p = demobuf.p; - WRITEUINT32(demobuf.p, 0); - - // Save netvars - CV_SaveNetVars(&demobuf.p, true); - - // Now store some info for each in-game player - for (p = 0; p < MAXPLAYERS; p++) { - if (playeringame[p]) { - player = &players[p]; - - WRITEUINT8(demobuf.p, p | (player->spectator ? DEMO_SPECTATOR : 0)); - - // Name - memset(name, 0, 16); - memcpy(name, player_names[p], 15); - M_Memcpy(demobuf.p,name,16); - demobuf.p += 16; - - // Skin - memset(name, 0, 16); - strncpy(name, skins[player->skin].name, 16); - M_Memcpy(demobuf.p,name,16); - demobuf.p += 16; - - // Color - memset(name, 0, 16); - strncpy(name, KartColor_Names[player->skincolor], 16); - M_Memcpy(demobuf.p,name,16); - demobuf.p += 16; - - // Score, since Kart uses this to determine where you start on the map - WRITEUINT32(demobuf.p, player->score); - - // Kart speed and weight - WRITEUINT8(demobuf.p, skins[player->skin].kartspeed); - WRITEUINT8(demobuf.p, skins[player->skin].kartweight); - - } - } - - WRITEUINT8(demobuf.p, 0xFF); // Denote the end of the player listing - - // player lua vars, always saved even if empty... Unless it's record attack. - if (demoflags & DF_LUAVARS) - LUA_Archive(&demobuf, false); - - memset(&oldcmd,0,sizeof(oldcmd)); - memset(&oldghost,0,sizeof(oldghost)); - memset(&ghostext,0,sizeof(ghostext)); - - for (i = 0; i < MAXPLAYERS; i++) - { - ghostext[i].lastcolor = ghostext[i].color = GHC_NORMAL; - ghostext[i].lastscale = ghostext[i].scale = FRACUNIT; - - if (players[i].mo) - { - oldghost[i].x = players[i].mo->x; - oldghost[i].y = players[i].mo->y; - oldghost[i].z = players[i].mo->z; - oldghost[i].angle = players[i].mo->angle; - - // preticker started us gravity flipped - if (players[i].mo->eflags & MFE_VERTICALFLIP) - ghostext[i].flags |= EZT_FLIP; - } - } -} - -void G_BeginMetal(void) -{ - mobj_t *mo = players[consoleplayer].mo; - - if (demobuf.buffer == NULL) - { - CONS_Alert(CONS_ERROR, "No metal demo buffer allocated\n"); - metalrecording = false; - return; - } - - if (demobuf.p) - { - Z_Free(demobuf.buffer); - demobuf.buffer = NULL; - metalrecording = false; - return; - } - - demobuf.p = demobuf.buffer; - - // Write header. - M_Memcpy(demobuf.p, DEMOHEADER, 12); demobuf.p += 12; - WRITEUINT8(demobuf.p,VERSION); - WRITEUINT8(demobuf.p,SUBVERSION); - WRITEUINT16(demobuf.p,DEMOVERSION); - - // demo checksum - demobuf.p += 16; - - M_Memcpy(demobuf.p, "METL", 4); demobuf.p += 4; - - // Set up our memory. - memset(&oldmetal,0,sizeof(oldmetal)); - oldmetal.x = mo->x; - oldmetal.y = mo->y; - oldmetal.z = mo->z; - oldmetal.angle = mo->angle; -} - -void G_WriteStanding(UINT8 ranking, char *name, INT32 skinnum, UINT8 color, UINT32 val) -{ - char temp[17]; - - if (!demobuf.p) - return; - - if (demoinfo_p && *(UINT32 *)demoinfo_p == 0 && demobuf.buffer != NULL) - { - WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker - *(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer; - } - - WRITEUINT8(demobuf.p, DW_STANDING); - WRITEUINT8(demobuf.p, ranking); - - // Name - memset(temp, 0, 16); - strncpy(temp, name, 16); - M_Memcpy(demobuf.p,temp,16); - demobuf.p += 16; - - // Skin - memset(temp, 0, 16); - strncpy(temp, skins[skinnum].name, 16); - M_Memcpy(demobuf.p,temp,16); - demobuf.p += 16; - - // Color - memset(temp, 0, 16); - strncpy(temp, KartColor_Names[color], 16); - M_Memcpy(demobuf.p,temp,16); - demobuf.p += 16; - - // Score/time/whatever - WRITEUINT32(demobuf.p, val); -} - -void G_SetDemoTime(UINT32 ptime, UINT32 plap) -{ - if (!demo.recording || !demotime_p) - return; - if (demoflags & DF_RECORDATTACK) - { - WRITEUINT32(demotime_p, ptime); - WRITEUINT32(demotime_p, plap); - demotime_p = NULL; - } -} - -static void G_LoadDemoExtraFiles(UINT8 **pp) -{ - UINT8 totalfiles; - char filename[MAX_WADPATH]; - UINT8 md5sum[16]; - filestatus_t ncs = FS_NOTFOUND; - boolean toomany = false; - boolean alreadyloaded; - UINT8 i, j; - - totalfiles = READUINT8((*pp)); - for (i = 0; i < totalfiles; ++i) - { - if (toomany) - SKIPSTRING((*pp)); - else - { - strlcpy(filename, (char *)(*pp), sizeof filename); - SKIPSTRING((*pp)); - } - READMEM((*pp), md5sum, 16); - - if (!toomany) - { - alreadyloaded = false; - - for (j = 0; j < numwadfiles; ++j) - { - if (memcmp(md5sum, wadfiles[j]->md5sum, 16) == 0) - { - alreadyloaded = true; - break; - } - } - - if (alreadyloaded) - continue; - - if (numwadfiles >= MAX_WADFILES) - toomany = true; - else - ncs = findfile(filename, md5sum, false); - - if (toomany) - { - CONS_Alert(CONS_WARNING, M_GetText("Too many files loaded to add anymore for demo playback\n")); - if (!CON_Ready()) - M_StartMessage(M_GetText("There are too many files loaded to add this demo's addons.\n\nDemo playback may desync.\n\nPress ESC\n"), NULL, MM_NOTHING); - } - else if (ncs != FS_FOUND) - { - if (ncs == FS_NOTFOUND) - CONS_Alert(CONS_NOTICE, M_GetText("You do not have a copy of %s\n"), filename); - else if (ncs == FS_MD5SUMBAD) - CONS_Alert(CONS_NOTICE, M_GetText("Checksum mismatch on %s\n"), filename); - else - CONS_Alert(CONS_NOTICE, M_GetText("Unknown error finding file %s\n"), filename); - - if (!CON_Ready()) - M_StartMessage(M_GetText("There were errors trying to add this demo's addons. Check the console for more information.\n\nDemo playback may desync.\n\nPress ESC\n"), NULL, MM_NOTHING); - } - else - { - P_PartialAddWadFile(filename, false); - } - } - } - - if (P_PartialAddGetStage() >= 0) - P_MultiSetupWadFiles(true); // in case any partial adds were done -} - -static void G_SkipDemoExtraFiles(UINT8 **pp) -{ - UINT8 totalfiles; - UINT8 i; - - totalfiles = READUINT8((*pp)); - for (i = 0; i < totalfiles; ++i) - { - SKIPSTRING((*pp));// file name - (*pp) += 16;// md5 - } -} - -// G_CheckDemoExtraFiles: checks if our loaded WAD list matches the demo's. -// Enabling quick prevents filesystem checks to see if needed files are available to load. -static UINT8 G_CheckDemoExtraFiles(UINT8 **pp, boolean quick) -{ - UINT8 totalfiles, filesloaded, nmusfilecount; - char filename[MAX_WADPATH]; - UINT8 md5sum[16]; - boolean toomany = false; - boolean alreadyloaded; - UINT8 i, j; - UINT8 error = 0; - - totalfiles = READUINT8((*pp)); - filesloaded = 0; - for (i = 0; i < totalfiles; ++i) - { - if (toomany) - SKIPSTRING((*pp)); - else - { - strlcpy(filename, (char *)(*pp), sizeof filename); - SKIPSTRING((*pp)); - } - READMEM((*pp), md5sum, 16); - - if (!toomany) - { - alreadyloaded = false; - nmusfilecount = 0; - - for (j = 0; j < numwadfiles; ++j) - { - if (wadfiles[j]->important && j > mainwads) - nmusfilecount++; - else - continue; - - if (memcmp(md5sum, wadfiles[j]->md5sum, 16) == 0) - { - alreadyloaded = true; - - if (i != nmusfilecount-1 && error < DFILE_ERROR_OUTOFORDER) - error |= DFILE_ERROR_OUTOFORDER; - - break; - } - } - - if (alreadyloaded) - { - filesloaded++; - continue; - } - - if (numwadfiles >= MAX_WADFILES) - error = DFILE_ERROR_CANNOTLOAD; - else if (!quick && findfile(filename, md5sum, false) != FS_FOUND) - error = DFILE_ERROR_CANNOTLOAD; - else if (error < DFILE_ERROR_INCOMPLETEOUTOFORDER) - error |= DFILE_ERROR_NOTLOADED; - } else - error = DFILE_ERROR_CANNOTLOAD; - } - - // Get final file count - nmusfilecount = 0; - - for (j = 0; j < numwadfiles; ++j) - if (wadfiles[j]->important && j > mainwads) - nmusfilecount++; - - if (!error && filesloaded < nmusfilecount) - error = DFILE_ERROR_EXTRAFILES; - - return error; -} - -// Returns bitfield: -// 1 == new demo has lower time -// 2 == new demo has higher score -// 4 == new demo has higher rings -UINT8 G_CmpDemoTime(char *oldname, char *newname) -{ - UINT8 *buffer,*p; - UINT8 flags; - UINT32 oldtime, newtime, oldlap, newlap; - UINT16 oldversion; - size_t bufsize ATTRUNUSED; - UINT8 c; - UINT16 s ATTRUNUSED; - UINT8 aflags = 0; - - // load the new file - FIL_DefaultExtension(newname, ".lmp"); - bufsize = FIL_ReadFile(newname, &buffer); - I_Assert(bufsize != 0); - p = buffer; - - // read demo header - I_Assert(!memcmp(p, DEMOHEADER, 12)); - p += 12; // DEMOHEADER - c = READUINT8(p); // VERSION - I_Assert(c == VERSION); - c = READUINT8(p); // SUBVERSION - I_Assert(c == SUBVERSION); - s = READUINT16(p); - I_Assert(s == DEMOVERSION); - p += 64; // full demo title - p += 16; // demo checksum - I_Assert(!memcmp(p, "PLAY", 4)); - p += 4; // PLAY - p += 2; // gamemap - p += 16; // map md5 - flags = READUINT8(p); // demoflags - p++; // gametype - G_SkipDemoExtraFiles(&p); - - aflags = flags & (DF_RECORDATTACK|DF_NIGHTSATTACK); - I_Assert(aflags); - if (flags & DF_RECORDATTACK) - { - newtime = READUINT32(p); - newlap = READUINT32(p); - } - else // appease compiler - return 0; - - Z_Free(buffer); - - // load old file - FIL_DefaultExtension(oldname, ".lmp"); - if (!FIL_ReadFile(oldname, &buffer)) - { - CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), oldname); - return UINT8_MAX; - } - p = buffer; - - // read demo header - if (memcmp(p, DEMOHEADER, 12)) - { - CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); - Z_Free(buffer); - return UINT8_MAX; - } p += 12; // DEMOHEADER - p++; // VERSION - p++; // SUBVERSION - oldversion = READUINT16(p); - switch(oldversion) // demoversion - { - case DEMOVERSION: // latest always supported - p += 64; // full demo title - break; -#ifdef DEMO_COMPAT_100 - case 0x0001: - // Old replays gotta go :] - CONS_Alert(CONS_NOTICE, M_GetText("File '%s' outdated version. It will be overwritten. Nyeheheh.\n"), oldname); - Z_Free(buffer); - return UINT8_MAX; -#endif - // too old, cannot support. - default: - CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); - Z_Free(buffer); - return UINT8_MAX; - } - p += 16; // demo checksum - if (memcmp(p, "PLAY", 4)) - { - CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); - Z_Free(buffer); - return UINT8_MAX; - } p += 4; // "PLAY" - p += 2; // gamemap - p += 16; // mapmd5 - flags = READUINT8(p); - p++; // gametype - G_SkipDemoExtraFiles(&p); - if (!(flags & aflags)) - { - CONS_Alert(CONS_NOTICE, M_GetText("File '%s' not from same game mode. It will be overwritten.\n"), oldname); - Z_Free(buffer); - return UINT8_MAX; - } - if (flags & DF_RECORDATTACK) - { - oldtime = READUINT32(p); - oldlap = READUINT32(p); - } - else // appease compiler - return UINT8_MAX; - - Z_Free(buffer); - - c = 0; - if (newtime < oldtime - || (newtime == oldtime && (newlap < oldlap))) - c |= 1; // Better time - if (newlap < oldlap - || (newlap == oldlap && newtime < oldtime)) - c |= 1<<1; // Better lap time - return c; -} - -void G_LoadDemoInfo(menudemo_t *pdemo) -{ - UINT8 *infobuffer, *info_p, *extrainfo_p; - UINT8 version, subversion, pdemoflags; - UINT16 pdemoversion, count; - - if (!FIL_ReadFile(pdemo->filepath, &infobuffer)) - { - CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), pdemo->filepath); - pdemo->type = MD_INVALID; - sprintf(pdemo->title, "INVALID REPLAY"); - - return; - } - - info_p = infobuffer; - - if (memcmp(info_p, DEMOHEADER, 12)) - { - CONS_Alert(CONS_ERROR, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemo->filepath); - pdemo->type = MD_INVALID; - sprintf(pdemo->title, "INVALID REPLAY"); - Z_Free(infobuffer); - return; - } - - pdemo->type = MD_LOADED; - - info_p += 12; // DEMOHEADER - - version = READUINT8(info_p); - subversion = READUINT8(info_p); - pdemoversion = READUINT16(info_p); - - memset(pdemo->version, 0, sizeof(pdemo->version)); - snprintf(pdemo->version, sizeof(pdemo->version), "v%d.%d", version, subversion); - - switch(pdemoversion) - { - case DEMOVERSION: // latest always supported - // demo title - M_Memcpy(pdemo->title, info_p, 64); - info_p += 64; - - break; -#ifdef DEMO_COMPAT_100 - case 0x0001: - pdemo->type = MD_OUTDATED; - sprintf(pdemo->title, "Legacy Replay"); - break; -#endif - // too old, cannot support. - default: - CONS_Alert(CONS_ERROR, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemo->filepath); - pdemo->type = MD_INVALID; - sprintf(pdemo->title, "INVALID REPLAY"); - Z_Free(infobuffer); - return; - } - - if (version != VERSION || subversion != SUBVERSION) - pdemo->type = MD_OUTDATED; - - info_p += 16; // demo checksum - if (memcmp(info_p, "PLAY", 4)) - { - CONS_Alert(CONS_ERROR, M_GetText("%s is the wrong type of recording and cannot be played.\n"), pdemo->filepath); - pdemo->type = MD_INVALID; - sprintf(pdemo->title, "INVALID REPLAY"); - Z_Free(infobuffer); - return; - } - info_p += 4; // "PLAY" - pdemo->map = READINT16(info_p); - info_p += 16; // mapmd5 - - pdemoflags = READUINT8(info_p); - - // temp? - if (!(pdemoflags & DF_MULTIPLAYER)) - { - CONS_Alert(CONS_ERROR, M_GetText("%s is not a multiplayer replay and can't be listed on this menu fully yet.\n"), pdemo->filepath); - Z_Free(infobuffer); - return; - } -#ifdef DEMO_COMPAT_100 - else if (pdemoversion == 0x0001) - { - CONS_Alert(CONS_ERROR, M_GetText("%s is a legacy multiplayer replay and cannot be played.\n"), pdemo->filepath); - pdemo->type = MD_INVALID; - sprintf(pdemo->title, "INVALID REPLAY"); - Z_Free(infobuffer); - return; - } -#endif - - pdemo->gametype = READUINT8(info_p); - - pdemo->addonstatus = G_CheckDemoExtraFiles(&info_p, true); - info_p += 4; // RNG seed - - extrainfo_p = infobuffer + READUINT32(info_p); - - // Pared down version of CV_LoadNetVars to find the kart speed - pdemo->kartspeed = 1; // Default to normal speed - count = READUINT16(info_p); - while (count--) - { - UINT16 netid; - char *svalue; - - netid = READUINT16(info_p); - svalue = (char *)info_p; - SKIPSTRING(info_p); - info_p++; // stealth - - if (netid == cv_kartspeed.netid) - { - UINT8 j; - for (j = 0; kartspeed_cons_t[j].strvalue; j++) - if (!stricmp(kartspeed_cons_t[j].strvalue, svalue)) - pdemo->kartspeed = kartspeed_cons_t[j].value; - } - else if (netid == cv_basenumlaps.netid && pdemo->gametype == GT_RACE) - pdemo->numlaps = atoi(svalue); - } - - if (pdemoflags & DF_ENCORE) - pdemo->kartspeed |= DF_ENCORE; - - // Read standings! - count = 0; - - while (READUINT8(extrainfo_p) == DW_STANDING) // Assume standings are always first in the extrainfo - { - INT32 i; - char temp[16]; - - pdemo->standings[count].ranking = READUINT8(extrainfo_p); - - // Name - M_Memcpy(pdemo->standings[count].name, extrainfo_p, 16); - extrainfo_p += 16; - - // Skin - M_Memcpy(temp,extrainfo_p,16); - extrainfo_p += 16; - pdemo->standings[count].skin = UINT8_MAX; - for (i = 0; i < numskins; i++) - if (stricmp(skins[i].name, temp) == 0) - { - pdemo->standings[count].skin = i; - break; - } - - // Color - M_Memcpy(temp,extrainfo_p,16); - extrainfo_p += 16; - for (i = 0; i < MAXSKINCOLORS; i++) - if (!stricmp(KartColor_Names[i],temp)) // SRB2kart - { - pdemo->standings[count].color = i; - break; - } - - // Score/time/whatever - pdemo->standings[count].timeorscore = READUINT32(extrainfo_p); - - count++; - - if (count >= MAXPLAYERS) - break; //@TODO still cycle through the rest of these if extra demo data is ever used - } - - // I think that's everything we need? - Z_Free(infobuffer); -} - -#if defined (_WIN32) -// return the file creation time -// useful for demos that were renamed -static long G_GetCreationTime(char *filepath) -{ - struct stat fileinfo; - - if (stat(filepath, &fileinfo) == 0) - return fileinfo.st_ctime; - - return 0; -} -#endif - -static char *G_GetDemoDate(menudemo_t *pdemo) -{ - char *datetime; - datetime = malloc(sizeof(pdemo->date)); // mallocma balls - - // no mallocma balls... :c - if (!datetime) - { - return NULL; - } - - time_t file_time = 0; - - // get le filepath - char *filename; - filename = strdup(pdemo->filepath); - -#if defined (_WIN32) - if (!filename) - { - // if we cant get a filename try just getting the file create time - file_time = G_GetCreationTime(pdemo->filepath); - goto skipfilenametime; - } -#else - if (!filename) - { - free(datetime); - return NULL; - } -#endif - - // get the actual filename Zzz... - nameonly(filename); - - // convert it to long Zzz.... - file_time = strtol(filename, NULL, 10); - free(filename); // dont need this anymore a - -#if defined (_WIN32) -skipfilenametime: -#endif - - // then throw it into localtime to get an actual human readable format lmao - struct tm *tm_buf = NULL; - tm_buf = localtime(&file_time); - - // cant believe we ended up in 1970 - if (tm_buf == NULL || tm_buf->tm_year <= 110) - { -#if defined (_WIN32) - // uh ohh, we got an invalid time - // try one more time getting the creation time - file_time = G_GetCreationTime(pdemo->filepath); - tm_buf = localtime(&file_time); - - if (tm_buf == NULL || tm_buf->tm_year <= 110) - { - free(datetime); - return NULL; - } - - goto gotcreationtime; -#else - free(datetime); - return NULL; -#endif - } - -#if defined (_WIN32) -gotcreationtime: -#endif - - const char *format; - - // US ppl are special (: - if (cv_demodateformat.value == 2) - format = "%m.%d.%Y"; - else if (cv_demodateformat.value == 1) - format = "%d.%m.%Y"; - else - format = strstr(setlocale(LC_TIME, NULL), "en_US") ? "%m.%d.%Y" : "%d.%m.%Y"; - - strftime(datetime, sizeof(pdemo->date), format, tm_buf); - - return datetime; -} - -void G_LoadDemoTitle(menudemo_t *pdemo) -{ - UINT8 infobuffer[96], *info_p; - UINT16 pdemoversion; - size_t count; - - FILE *handle = fopen(pdemo->filepath, "rb"); - - if (!handle) - { - CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), pdemo->filepath); - sprintf(pdemo->title, "INVALID REPLAY"); - return; - } - - count = fread(infobuffer, 1, 96, handle); - fclose(handle); - info_p = infobuffer; - - // First check isn't too accurate technically, but well, valid replays should be larger than that anyway - if (count < 96 || memcmp(info_p, DEMOHEADER, 12)) - { - CONS_Alert(CONS_ERROR, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemo->filepath); - sprintf(pdemo->title, "INVALID REPLAY"); - return; - } - - info_p += 12; // DEMOHEADER - - READUINT8(info_p); - READUINT8(info_p); - pdemoversion = READUINT16(info_p); - - memset(pdemo->date, 0, sizeof(pdemo->date)); - - switch(pdemoversion) - { - case DEMOVERSION: // latest always supported - // demo title - M_Memcpy(pdemo->title, info_p, 64); - - // demo date - char *demodate; - demodate = G_GetDemoDate(pdemo); - if (demodate) - strncpy(pdemo->date, demodate, sizeof(pdemo->date)); - free(demodate); - break; -#ifdef DEMO_COMPAT_100 - case 0x0001: - sprintf(pdemo->title, "Legacy Replay"); - break; -#endif - // too old, cannot support. - default: - CONS_Alert(CONS_ERROR, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemo->filepath); - sprintf(pdemo->title, "INVALID REPLAY"); - } -} - -// -// G_PlayDemo -// -void G_DeferedPlayDemo(const char *name) -{ - COM_BufAddText("playdemo \""); - COM_BufAddText(name); - COM_BufAddText("\" -addfiles\n"); -} - -// -// Start a demo from a .LMP file or from a wad resource -// -#define SKIPERRORS -void G_DoPlayDemo(char *defdemoname) -{ - UINT8 i, p; - lumpnum_t l; - char skin[17],color[17],*n,*pdemoname; - UINT8 version,subversion; - UINT32 randseed; - char msg[1024]; -#if defined(SKIPERRORS) && !defined(DEVELOP) - boolean skiperrors = false; -#endif - boolean spectator; - UINT8 slots[MAXPLAYERS], kartspeed[MAXPLAYERS], kartweight[MAXPLAYERS], numslots = 0; - - G_InitDemoRewind(); - - skin[16] = '\0'; - color[16] = '\0'; - - // No demo name means we're restarting the current demo - if (defdemoname == NULL) - { - demobuf.p = demobuf.buffer; - pdemoname = ZZ_Alloc(1); // Easier than adding checks for this everywhere it's freed - } - else - { - n = defdemoname+strlen(defdemoname); - while (*n != '/' && *n != '\\' && n != defdemoname) - n--; - if (n != defdemoname) - n++; - pdemoname = ZZ_Alloc(strlen(n)+1); - strcpy(pdemoname,n); - - M_SetPlaybackMenuPointer(); - - // Internal if no extension, external if one exists - if (FIL_CheckExtension(defdemoname)) - { - //FIL_DefaultExtension(defdemoname, ".lmp"); - if (!FIL_ReadFile(defdemoname, &demobuf.buffer)) - { - snprintf(msg, 1024, M_GetText("Failed to read file '%s'.\n"), defdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - gameaction = ga_nothing; - M_StartMessage(msg, NULL, MM_NOTHING); - return; - } - demobuf.p = demobuf.buffer; - } - // load demo resource from WAD - else if ((l = W_CheckNumForName(defdemoname)) == LUMPERROR) - { - snprintf(msg, 1024, M_GetText("Failed to read lump '%s'.\n"), defdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - gameaction = ga_nothing; - M_StartMessage(msg, NULL, MM_NOTHING); - return; - } - else // it's an internal demo - { - demobuf.buffer = demobuf.p = W_CacheLumpNum(l, PU_STATIC); -#if defined(SKIPERRORS) && !defined(DEVELOP) - skiperrors = true; // SRB2Kart: Don't print warnings for staff ghosts, since they'll inevitably happen when we make bugfixes/changes... -#endif - } - } - - // read demo header - gameaction = ga_nothing; - demo.playback = true; - if (memcmp(demobuf.p, DEMOHEADER, 12)) - { - snprintf(msg, 1024, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - demobuf.p += 12; // DEMOHEADER - - version = READUINT8(demobuf.p); - subversion = READUINT8(demobuf.p); - demo.version = READUINT16(demobuf.p); - switch(demo.version) - { - case DEMOVERSION: // latest always supported - // demo title - M_Memcpy(demo.titlename, demobuf.p, 64); - demobuf.p += 64; - - break; -#ifdef DEMO_COMPAT_100 - case 0x0001: - break; -#endif - // too old, cannot support. - default: - snprintf(msg, 1024, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - demobuf.p += 16; // demo checksum - if (memcmp(demobuf.p, "PLAY", 4)) - { - snprintf(msg, 1024, M_GetText("%s is the wrong type of recording and cannot be played.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - demobuf.p += 4; // "PLAY" - gamemap = READINT16(demobuf.p); - demobuf.p += 16; // mapmd5 - - demoflags = READUINT8(demobuf.p); -#ifdef DEMO_COMPAT_100 - if (demo.version == 0x0001) - { - if (demoflags & DF_MULTIPLAYER) - { - snprintf(msg, 1024, M_GetText("%s is an alpha multiplayer replay and cannot be played.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - } - else - { -#endif - gametype = READUINT8(demobuf.p); - - if (demo.title) // Titledemos should always play and ought to always be compatible with whatever wadlist is running. - G_SkipDemoExtraFiles(&demobuf.p); - else if (demo.loadfiles) - G_LoadDemoExtraFiles(&demobuf.p); - else if (demo.ignorefiles) - G_SkipDemoExtraFiles(&demobuf.p); - else - { - UINT8 error = G_CheckDemoExtraFiles(&demobuf.p, false); - - if (error) - { - switch (error) - { - case DFILE_ERROR_NOTLOADED: - snprintf(msg, 1024, - M_GetText("Required files for this demo are not loaded.\n\nUse\n\"playdemo %s -addfiles\"\nto load them and play the demo.\n"), - pdemoname); - break; - - case DFILE_ERROR_OUTOFORDER: - snprintf(msg, 1024, - M_GetText("Required files for this demo are loaded out of order.\n\nUse\n\"playdemo %s -force\"\nto play the demo anyway.\n"), - pdemoname); - break; - - case DFILE_ERROR_INCOMPLETEOUTOFORDER: - snprintf(msg, 1024, - M_GetText("Required files for this demo are not loaded, and some are out of order.\n\nUse\n\"playdemo %s -addfiles\"\nto load needed files and play the demo.\n"), - pdemoname); - break; - - case DFILE_ERROR_CANNOTLOAD: - snprintf(msg, 1024, - M_GetText("Required files for this demo cannot be loaded.\n\nUse\n\"playdemo %s -force\"\nto play the demo anyway.\n"), - pdemoname); - break; - - case DFILE_ERROR_EXTRAFILES: - snprintf(msg, 1024, - M_GetText("You have additional files loaded beyond the demo's file list.\n\nUse\n\"playdemo %s -force\"\nto play the demo anyway.\n"), - pdemoname); - break; - } - - CONS_Alert(CONS_ERROR, "%s", msg); - if (!CON_Ready()) // In the console they'll just see the notice there! No point pulling them out. - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - } -#ifdef DEMO_COMPAT_100 - } -#endif - - modeattacking = (demoflags & DF_ATTACKMASK)>>DF_ATTACKSHIFT; - multiplayer = !!(demoflags & DF_MULTIPLAYER); - CON_ToggleOff(); - - hu_demotime = UINT32_MAX; - hu_demolap = UINT32_MAX; - - switch (modeattacking) - { - case ATTACKING_NONE: // 0 - break; - case ATTACKING_RECORD: // 1 - hu_demotime = READUINT32(demobuf.p); - hu_demolap = READUINT32(demobuf.p); - break; - default: // 3 - modeattacking = ATTACKING_NONE; - break; - } - - // Random seed - randseed = READUINT32(demobuf.p); -#ifdef DEMO_COMPAT_100 - if (demo.version != 0x0001) -#endif - demobuf.p += 4; // Extrainfo location - -#ifdef DEMO_COMPAT_100 - if (demo.version == 0x0001) - { - // Player name - M_Memcpy(player_names[0],demobuf.p,16); - demobuf.p += 16; - - // Skin - M_Memcpy(skin,demobuf.p,16); - demobuf.p += 16; - - // Color - M_Memcpy(color,demobuf.p,16); - demobuf.p += 16; - - demobuf.p += 5; // Backwards compat - some stats - // SRB2kart - kartspeed[0] = READUINT8(demobuf.p); - kartweight[0] = READUINT8(demobuf.p); - // - demobuf.p += 9; // Backwards compat - more stats - - // Skin not loaded? - if (!SetPlayerSkin(0, skin)) - { - snprintf(msg, 1024, M_GetText("%s features a character that is not currently loaded.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - - // ...*map* not loaded? - if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1] || !(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) - { - snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - - // Set color - for (i = 0; i < MAXSKINCOLORS; i++) - if (!stricmp(KartColor_Names[i],color)) // SRB2kart - { - players[0].skincolor = i; - break; - } - - // net var data - CV_LoadNetVars(&demobuf.p); - - // Sigh ... it's an empty demo. - if (*demobuf.p == DEMOMARKER) - { - snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - - Z_Free(pdemoname); - - memset(&oldcmd,0,sizeof(oldcmd)); - memset(&oldghost,0,sizeof(oldghost)); - memset(&ghostext,0,sizeof(ghostext)); - - CONS_Alert(CONS_WARNING, M_GetText("Demo version does not match game version. Desyncs may occur.\n")); - - // console warning messages -#if defined(SKIPERRORS) && !defined(DEVELOP) - demosynced = (!skiperrors); -#else - demosynced = true; -#endif - - // didn't start recording right away. - demo.deferstart = false; - - consoleplayer = 0; - memset(displayplayers, 0, sizeof(displayplayers)); - memset(playeringame, 0, sizeof(playeringame)); - playeringame[0] = true; - - goto post_compat; - } -#endif - - // net var data - CV_LoadNetVars(&demobuf.p); - - // Sigh ... it's an empty demo. - if (*demobuf.p == DEMOMARKER) - { - snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - - Z_Free(pdemoname); - - memset(&oldcmd,0,sizeof(oldcmd)); - memset(&oldghost,0,sizeof(oldghost)); - memset(&ghostext,0,sizeof(ghostext)); - -#if defined(SKIPERRORS) && !defined(DEVELOP) - if ((VERSION != version || SUBVERSION != subversion) && !skiperrors) -#else - if (VERSION != version || SUBVERSION != subversion) -#endif - CONS_Alert(CONS_WARNING, M_GetText("Demo version does not match game version. Desyncs may occur.\n")); - - // console warning messages -#if defined(SKIPERRORS) && !defined(DEVELOP) - demosynced = (!skiperrors); -#else - demosynced = true; -#endif - - // didn't start recording right away. - demo.deferstart = false; - - //LUA_HookInt(gamemap, HOOK(MapChange)); - - consoleplayer = 0; - memset(playeringame,0,sizeof(playeringame)); - memset(displayplayers,0,sizeof(displayplayers)); - memset(camera,0,sizeof(camera)); // reset freecam - - // Load players that were in-game when the map started - p = READUINT8(demobuf.p); - - while (p != 0xFF) - { - spectator = false; - if (p & DEMO_SPECTATOR) - { - spectator = true; - p &= ~DEMO_SPECTATOR; - - if (modeattacking) - { - snprintf(msg, 1024, M_GetText("%s is a Record Attack replay with spectators, and is thus invalid.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - } - slots[numslots] = p; numslots++; - - if (modeattacking && numslots > 1) - { - snprintf(msg, 1024, M_GetText("%s is a Record Attack replay with multiple players, and is thus invalid.\n"), pdemoname); - CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); - G_ResetDemoPlayback(pdemoname); - return; - } - - if (!playeringame[displayplayers[0]] || players[displayplayers[0]].spectator) - displayplayers[0] = consoleplayer = serverplayer = p; - - playeringame[p] = true; - players[p].spectator = spectator; - - // Name - M_Memcpy(player_names[p],demobuf.p,16); - demobuf.p += 16; - - // Skin - M_Memcpy(skin,demobuf.p,16); - demobuf.p += 16; - SetPlayerSkin(p, skin); - - // Color - M_Memcpy(color,demobuf.p,16); - demobuf.p += 16; - for (i = 0; i < MAXSKINCOLORS; i++) - if (!stricmp(KartColor_Names[i],color)) // SRB2kart - { - players[p].skincolor = i; - break; - } - - // Score, since Kart uses this to determine where you start on the map - players[p].score = READUINT32(demobuf.p); - - // Kart stats, temporarily - kartspeed[p] = READUINT8(demobuf.p); - kartweight[p] = READUINT8(demobuf.p); - - if (stricmp(skins[players[p].skin].name, skin) != 0) - FindClosestSkinForStats(p, kartspeed[p], kartweight[p]); - - // Look for the next player - p = READUINT8(demobuf.p); - } - - // end of player read (the 0xFF marker) - // so this is where we are to read our lua variables (if possible!) - if (demoflags & DF_LUAVARS) // again, used for compability, lua shit will be saved to replays regardless of if it's even been loaded - { - if (!gL) // No Lua state! ...I guess we'll just start one... - LUA_ClearState(); - - // No modeattacking check, DF_LUAVARS won't be present here. - LUA_UnArchive(&demobuf, false); - } - - splitscreen = 0; - - if (demo.title) - { - splitscreen = M_RandomKey(6)-1; - splitscreen = min(min(3, numslots-1), splitscreen); // Bias toward 1p and 4p views - - for (p = 0; p <= splitscreen; p++) - G_ResetView(p+1, slots[M_RandomKey(numslots)], false); - } - - R_ExecuteSetViewSize(); - -#ifdef DEMO_COMPAT_100 -post_compat: -#endif - - P_SetRandSeed(randseed); - G_InitNew(demoflags & DF_ENCORE, G_BuildMapName(gamemap), true, true); // Doesn't matter whether you reset or not here, given changes to resetplayer. - - for (i = 0; i < MAXPLAYERS; i++) - { - if (players[i].mo) - { - players[i].mo->color = players[i].skincolor; - oldghost[i].x = players[i].mo->x; - oldghost[i].y = players[i].mo->y; - oldghost[i].z = players[i].mo->z; - } - - // Set saved attribute values - // No cheat checking here, because even if they ARE wrong... - // it would only break the replay if we clipped them. - players[i].kartspeed = kartspeed[i]; - players[i].kartweight = kartweight[i]; - } - - if (cv_director.value) - CV_SetValue(&cv_director, 0); - - demo.deferstart = true; -} -#undef SKIPERRORS - -void G_AddGhost(char *defdemoname) -{ - INT32 i; - lumpnum_t l; - char name[17],skin[17],color[17],*n,*pdemoname,md5[16]; - demoghost *gh; - UINT8 flags; - UINT8 *buffer,*p; - mapthing_t *mthing; - UINT16 count, ghostversion; - skin_t *ghskin = &skins[0]; - UINT8 kartspeed = UINT8_MAX, kartweight = UINT8_MAX; - - name[16] = '\0'; - skin[16] = '\0'; - color[16] = '\0'; - - n = defdemoname+strlen(defdemoname); - while (*n != '/' && *n != '\\' && n != defdemoname) - n--; - if (n != defdemoname) - n++; - pdemoname = ZZ_Alloc(strlen(n)+1); - strcpy(pdemoname,n); - - // Internal if no extension, external if one exists - if (FIL_CheckExtension(defdemoname)) - { - //FIL_DefaultExtension(defdemoname, ".lmp"); - if (!FIL_ReadFileTag(defdemoname, &buffer, PU_LEVEL)) - { - CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), defdemoname); - Z_Free(pdemoname); - return; - } - p = buffer; - } - // load demo resource from WAD - else if ((l = W_CheckNumForName(defdemoname)) == LUMPERROR) - { - CONS_Alert(CONS_ERROR, M_GetText("Failed to read lump '%s'.\n"), defdemoname); - Z_Free(pdemoname); - return; - } - else // it's an internal demo - buffer = p = W_CacheLumpNum(l, PU_LEVEL); - - // read demo header - if (memcmp(p, DEMOHEADER, 12)) - { - CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Not a SRB2Kart replay.\n"), pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } - - p += 12; // DEMOHEADER - p++; // VERSION - p++; // SUBVERSION - - ghostversion = READUINT16(p); - switch(ghostversion) - { - case DEMOVERSION: // latest always supported - p += 64; // title - break; -#ifdef DEMO_COMPAT_100 - case 0x0001: - break; -#endif - // too old, cannot support. - default: - CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Demo version incompatible.\n"), pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } - - M_Memcpy(md5, p, 16); p += 16; // demo checksum - for (gh = ghosts; gh; gh = gh->next) - if (!memcmp(md5, gh->checksum, 16)) // another ghost in the game already has this checksum? - { // Don't add another one, then! - CONS_Debug(DBG_SETUP, "Rejecting duplicate ghost %s (MD5 was matched)\n", pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } - - if (memcmp(p, "PLAY", 4)) - { - CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Demo format unacceptable.\n"), pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } - - p += 4; // "PLAY" - p += 2; // gamemap - p += 16; // mapmd5 (possibly check for consistency?) - - flags = READUINT8(p); - - if (!(flags & DF_GHOST)) - { - CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: No ghost data in this demo.\n"), pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } - -#ifdef DEMO_COMPAT_100 - if (ghostversion != 0x0001) -#endif - p++; // gametype - -#ifdef DEMO_COMPAT_100 - if (ghostversion != 0x0001) -#endif - G_SkipDemoExtraFiles(&p); // Don't wanna modify the file list for ghosts. - switch ((flags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) - { - case ATTACKING_NONE: // 0 - break; - case ATTACKING_RECORD: // 1 - p += 8; // demo time, lap - break; - default: // 3 - break; - } - - p += 4; // random seed - -#ifdef DEMO_COMPAT_100 - if (ghostversion == 0x0001) - { - // Player name (TODO: Display this somehow if it doesn't match cv_playername!) - M_Memcpy(name, p,16); - p += 16; - - // Skin - M_Memcpy(skin, p,16); - p += 16; - - // Color - M_Memcpy(color, p,16); - p += 16; - - // Ghosts do not have a player structure to put this in. - p++; // charability - p++; // charability2 - p++; // actionspd - p++; // mindash - p++; // maxdash - // SRB2kart - p++; // kartspeed - p++; // kartweight - // - p++; // normalspeed - p++; // runspeed - p++; // thrustfactor - p++; // accelstart - p++; // acceleration - p += 4; // jumpfactor - } - else -#endif - p += 4; // Extra data location reference - - // net var data - count = READUINT16(p); - while (count--) - { - p += 2; - SKIPSTRING(p); - p++; - } - - if (*p == DEMOMARKER) - { - CONS_Alert(CONS_NOTICE, M_GetText("Failed to add ghost %s: Replay is empty.\n"), pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } - -#ifdef DEMO_COMPAT_100 - if (ghostversion != 0x0001) - { -#endif - if (READUINT8(p) != 0) - { - CONS_Alert(CONS_NOTICE, M_GetText("Failed to add ghost %s: Invalid player slot.\n"), pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } - - // Player name (TODO: Display this somehow if it doesn't match cv_playername!) - M_Memcpy(name, p, 16); - p += 16; - - // Skin - M_Memcpy(skin, p, 16); - p += 16; - - // Color - M_Memcpy(color, p, 16); - p += 16; - - p += 4; // score - - kartspeed = READUINT8(p); - kartweight = READUINT8(p); - - if (READUINT8(p) != 0xFF) - { - CONS_Alert(CONS_NOTICE, M_GetText("Failed to add ghost %s: Invalid player slot.\n"), pdemoname); - Z_Free(pdemoname); - Z_Free(buffer); - return; - } -#ifdef DEMO_COMPAT_100 - } -#endif - - for (i = 0; i < numskins; i++) - if (!stricmp(skins[i].name,skin)) - { - ghskin = &skins[i]; - break; - } - - if (i == numskins) - { - if (kartspeed != UINT8_MAX && kartweight != UINT8_MAX) - ghskin = &skins[GetSkinNumClosestToStats(kartspeed, kartweight)]; - - CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Invalid character. Falling back to %s.\n"), pdemoname, ghskin->name); - } - - gh = Z_Calloc(sizeof(demoghost), PU_LEVEL, NULL); - gh->next = ghosts; - gh->buffer = buffer; - M_Memcpy(gh->checksum, md5, 16); - gh->p = p; - - ghosts = gh; - - gh->version = ghostversion; - mthing = playerstarts[0]; - I_Assert(mthing); - { // A bit more complex than P_SpawnPlayer because ghosts aren't solid and won't just push themselves out of the ceiling. - fixed_t z,f,c; - gh->mo = P_SpawnMobj(mthing->x << FRACBITS, mthing->y << FRACBITS, 0, MT_GHOST); - gh->mo->angle = FixedAngle(mthing->angle*FRACUNIT); - f = gh->mo->floorz; - c = gh->mo->ceilingz - mobjinfo[MT_PLAYER].height; - if (!!(mthing->options & MTF_AMBUSH) ^ !!(mthing->options & MTF_OBJECTFLIP)) - { - z = c; - if (mthing->options >> ZSHIFT) - z -= ((mthing->options >> ZSHIFT) << FRACBITS); - if (z < f) - z = f; - } - else - { - z = f; - if (mthing->options >> ZSHIFT) - z += ((mthing->options >> ZSHIFT) << FRACBITS); - if (z > c) - z = c; - } - gh->mo->z = z; - } - gh->mo->state = states+S_KART_STND1; // SRB2kart - was S_PLAY_STND - gh->mo->sprite = gh->mo->state->sprite; - gh->mo->frame = (gh->mo->state->frame & FF_FRAMEMASK) | tr_trans20<mo->tics = -1; - - gh->oldmo.x = gh->mo->x; - gh->oldmo.y = gh->mo->y; - gh->oldmo.z = gh->mo->z; - - // Set skin - gh->mo->skin = gh->oldmo.skin = ghskin; - - // Set color - gh->mo->color = ((skin_t*)gh->mo->skin)->prefcolor; - for (i = 0; i < MAXSKINCOLORS; i++) - if (!stricmp(KartColor_Names[i],color)) // SRB2kart - { - gh->mo->color = (UINT8)i; - break; - } - gh->oldmo.color = gh->mo->color; - - CONS_Printf(M_GetText("Added ghost %s from %s\n"), name, pdemoname); - Z_Free(pdemoname); -} - -// A simplified version of G_AddGhost... -void G_UpdateStaffGhostName(lumpnum_t l) -{ - UINT8 *buffer,*p; - UINT16 ghostversion; - UINT8 flags; - - buffer = p = W_CacheLumpNum(l, PU_CACHE); - - // read demo header - if (memcmp(p, DEMOHEADER, 12)) - { - goto fail; - } - - p += 12; // DEMOHEADER - p++; // VERSION - p++; // SUBVERSION - - ghostversion = READUINT16(p); - switch(ghostversion) - { - case DEMOVERSION: // latest always supported - p += 64; // full demo title - break; - -#ifdef DEMO_COMPAT_100 - case 0x0001: - break; -#endif - - // too old, cannot support. - default: - goto fail; - } - - p += 16; // demo checksum - - if (memcmp(p, "PLAY", 4)) - { - goto fail; - } - - p += 4; // "PLAY" - p += 2; // gamemap - p += 16; // mapmd5 (possibly check for consistency?) - - flags = READUINT8(p); - if (!(flags & DF_GHOST)) - { - goto fail; // we don't NEED to do it here, but whatever - } - -#ifdef DEMO_COMPAT_100 - if (ghostversion != 0x0001) -#endif - p++; // Gametype - -#ifdef DEMO_COMPAT_100 - if (ghostversion != 0x0001) -#endif - G_SkipDemoExtraFiles(&p); - - switch ((flags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) - { - case ATTACKING_NONE: // 0 - break; - case ATTACKING_RECORD: // 1 - p += 8; // demo time, lap - break; - default: // 3 - break; - } - - p += 4; // random seed - - -#ifdef DEMO_COMPAT_100 - if (ghostversion == 0x0001) - { - // Player name - M_Memcpy(dummystaffname, p,16); - dummystaffname[16] = '\0'; - goto fail; // Not really a failure but whatever - } -#endif - - p += 4; // Extrainfo location marker - - // Ehhhh don't need ghostversion here (?) so I'll reuse the var here - ghostversion = READUINT16(p); - while (ghostversion--) - { - p += 2; - SKIPSTRING(p); - p++; // stealth - } - - // Assert first player is in and then read name - if (READUINT8(p) != 0) - goto fail; - M_Memcpy(dummystaffname, p,16); - dummystaffname[16] = '\0'; - - // Ok, no longer any reason to care, bye -fail: - Z_Free(buffer); - return; -} - -// -// G_TimeDemo -// NOTE: name is a full filename for external demos -// -static INT32 restorecv_vidwait; - -void G_TimeDemo(const char *name) -{ - nodrawers = M_CheckParm("-nodraw"); - noblit = M_CheckParm("-noblit"); - restorecv_vidwait = cv_vidwait.value; - if (cv_vidwait.value) - CV_Set(&cv_vidwait, "0"); - demo.timing = true; - singletics = true; - framecount = 0; - demostarttime = I_GetTime(); - G_DeferedPlayDemo(name); -} - -void G_DoPlayMetal(void) -{ - lumpnum_t l; - mobj_t *mo = NULL; - thinker_t *th; - - // it's an internal demo - if ((l = W_CheckNumForName(va("%sMS",G_BuildMapName(gamemap)))) == LUMPERROR) - { - CONS_Alert(CONS_WARNING, M_GetText("No bot recording for this map.\n")); - return; - } - else - metalbuffer = metal_p = W_CacheLumpNum(l, PU_STATIC); - - // find metal sonic - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mo = (mobj_t *)th; - if (mo->type == MT_METALSONIC_RACE) - break; - } - if (!mo) - { - CONS_Alert(CONS_ERROR, M_GetText("Failed to find bot entity.\n")); - Z_Free(metalbuffer); - return; - } - - // read demo header - metal_p += 12; // DEMOHEADER - metal_p++; // VERSION - metal_p++; // SUBVERSION - metalversion = READUINT16(metal_p); - switch(metalversion) - { - case DEMOVERSION: // latest always supported - break; -#ifdef DEMO_COMPAT_100 - case 0x0001: - I_Error("You need to implement demo compat here, doofus! %s:%d", __FILE__, __LINE__); -#endif - // too old, cannot support. - default: - CONS_Alert(CONS_WARNING, M_GetText("Failed to load bot recording for this map, format version incompatible.\n")); - Z_Free(metalbuffer); - return; - } - metal_p += 16; // demo checksum - if (memcmp(metal_p, "METL", 4)) - { - CONS_Alert(CONS_WARNING, M_GetText("Failed to load bot recording for this map, wasn't recorded in Metal format.\n")); - Z_Free(metalbuffer); - return; - } metal_p += 4; // "METL" - - // read initial tic - memset(&oldmetal,0,sizeof(oldmetal)); - oldmetal.x = mo->x; - oldmetal.y = mo->y; - oldmetal.z = mo->z; - oldmetal.angle = mo->angle; - metalplayback = mo; -} - -void G_DoneLevelLoad(void) -{ - CONS_Printf(M_GetText("Loaded level in %f sec\n"), (double)(I_GetTime() - demostarttime) / TICRATE); - framecount = 0; - demostarttime = I_GetTime(); -} - -/* -=================== -= -= G_CheckDemoStatus -= -= Called after a death or level completion to allow demos to be cleaned up -= Returns true if a new demo loop action will take place -=================== -*/ - -// Stops metal sonic's demo. Separate from other functions because metal + replays can coexist -void G_StopMetalDemo(void) -{ - // Metal Sonic finishing doesn't end the game, dammit. - Z_Free(metalbuffer); - metalbuffer = NULL; - metalplayback = NULL; - metal_p = NULL; -} - -// Stops metal sonic recording. -ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) -{ - boolean saved = false; - if (demobuf.p && demobuf.buffer != NULL) - { - UINT8 *p = demobuf.buffer+16; // checksum position -#ifdef NOMD5 - UINT8 i; - WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker - for (i = 0; i < 16; i++, p++) - *p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. -#else - WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker - md5_buffer((char *)p+16, demobuf.p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file. -#endif - saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuf.buffer, demobuf.p - demobuf.buffer); // finally output the file. - } - Z_Free(demobuf.buffer); - demobuf.buffer = NULL; - metalrecording = false; - if (saved) - I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap)); - I_Error("Failed to save demo!"); -} - -// reset engine variable set for the demos -// called from stopdemo command, map command, and g_checkdemoStatus. -void G_StopDemo(void) -{ - Z_Free(demobuf.buffer); - demobuf.buffer = NULL; - demo.playback = false; - if (demo.title) - modeattacking = ATTACKING_NONE; - demo.title = false; - demo.timing = false; - singletics = false; - - UINT8 i; - for (i = 0; i < MAXSPLITSCREENPLAYERS; ++i) - { - camera[i].freecam = false; - camera[i].localangle = 0; - camera[i].localaiming = 0; - } - - CV_SetValue(&cv_playbackspeed, 1); - demo.rewinding = false; - CL_ClearRewinds(); - - if (gamestate == GS_LEVEL && rendermode != render_none) - { - V_SetPaletteLump("PLAYPAL"); // Reset the palette - R_ReInitColormaps(0, LUMPERROR); - } - if (gamestate == GS_INTERMISSION) - Y_EndIntermission(); // cleanup - if (gamestate == GS_VOTING) - Y_EndVote(); - - M_ClearMenus(true); - - G_SetGamestate(GS_NULL); - wipegamestate = GS_NULL; - SV_StopServer(); - SV_ResetServer(); -} - -// Stops timing a demo. -static void G_StopTimingDemo(void) -{ - INT32 demotime; - double f1, f2; - demotime = I_GetTime() - demostarttime; - if (!demotime) - return; - G_StopDemo(); - demo.timing = false; - f1 = (double)demotime; - f2 = (double)framecount*TICRATE; - - CONS_Printf(M_GetText("timed %u gametics in %d realtics - %u frames\n%f seconds, %f avg fps\n"), - leveltime, demotime, (UINT32)framecount, f1/TICRATE, f2/f1); - - if (restorecv_vidwait != cv_vidwait.value) - CV_SetValue(&cv_vidwait, restorecv_vidwait); - - D_StartTitle(); -} - - -boolean G_CheckDemoStatus(void) -{ - while (ghosts) - { - demoghost *next = ghosts->next; - Z_Free(ghosts); - ghosts = next; - } - ghosts = NULL; - - // DO NOT end metal sonic demos here - - if (demo.timing) - { - G_StopTimingDemo(); - return true; - } - - if (demo.playback) - { - if (demo.quitafterplaying) - I_Quit(); - - if (multiplayer && !demo.title) - { - G_ExitLevel(); - } - else if (modeattacking && !demo.title) // nooo dont crash our titledemos - { - G_StopDemo(); - M_EndModeAttackRun(); - } - else - { - G_StopDemo(); - D_StartTitle(); - } - - return true; - } - - if (!demo.recording) - return false; - - if (modeattacking || demo.savemode != DSM_NOTSAVING) - { - G_SaveDemo(); - return true; - } - - G_ResetDemoRecording(); - - return false; -} - -void G_ResetDemoRecording(void) -{ - if (demobuf.buffer) - Z_Free(demobuf.buffer); - demobuf.buffer = NULL; - demo.recording = false; -} - -static void G_ResetDemoPlayback(char *pdemoname) -{ - if (pdemoname) - Z_Free(pdemoname); - if (demobuf.buffer) - Z_Free(demobuf.buffer); - demobuf.buffer = NULL; - demo.playback = false; - if (demo.title) - modeattacking = ATTACKING_NONE; - demo.title = false; -} - -void G_SaveDemo(void) -{ - if (!demobuf.p) - { - CONS_Alert(CONS_ERROR, "Failed to save Demo. No Demo pointer exists!\n"); - // reset the demo buffer - G_ResetDemoRecording(); - return; - } - - if (demobuf.buffer == NULL) - { - CONS_Alert(CONS_ERROR, "Failed to save Demo. No Demo buffer allocated!\n"); - // reset the demo buffer - G_ResetDemoRecording(); - return; - } - - UINT8 *p = demobuf.buffer+16; // after version - UINT32 length; - - // Ensure extrainfo pointer is always available, even if no info is present. - if (demoinfo_p && *(UINT32 *)demoinfo_p == 0) - { - WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker - *(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer; - } - WRITEUINT8(demobuf.p, DW_END); // Mark end of demo extra data. - - M_Memcpy(p, demo.titlename, 64); // Write demo title here - p += 64; - - if (multiplayer) - { - // Change the demo's name to be a slug of the title - char demo_slug[128]; - char *writepoint; - size_t i, strindex = 0; - boolean dash = true; - - for (i = 0; demo.titlename[i] && i < 127; i++) - { - if ((demo.titlename[i] >= 'a' && demo.titlename[i] <= 'z') || - (demo.titlename[i] >= '0' && demo.titlename[i] <= '9')) - { - demo_slug[strindex] = demo.titlename[i]; - strindex++; - dash = false; - } - else if (demo.titlename[i] >= 'A' && demo.titlename[i] <= 'Z') - { - demo_slug[strindex] = demo.titlename[i] + 'a' - 'A'; - strindex++; - dash = false; - } - else if (!dash) - { - demo_slug[strindex] = '-'; - strindex++; - dash = true; - } - } - - demo_slug[strindex] = 0; - if (dash) demo_slug[strindex-1] = 0; - - writepoint = strstr(demoname, "-") + 1; - demo_slug[128 - (writepoint - demoname) - 4] = 0; - sprintf(writepoint, "%s.lmp", demo_slug); - } - - length = *(UINT32 *)demoinfo_p; - WRITEUINT32(demoinfo_p, length); -#ifdef NOMD5 - for (UINT8 k = 0; k < 16; k++, p++) - *p = M_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. -#else - // Make a checksum of everything after the checksum in the file up to the end of the standard data. Extrainfo is freely modifiable. - md5_buffer((char *)p+16, (demobuf.buffer + length) - (p+16), p); -#endif - - - if (FIL_WriteFile(va(pandf, srb2home, demoname), demobuf.buffer, demobuf.p - demobuf.buffer)) // finally output the file. - demo.savemode = DSM_SAVED; - - G_ResetDemoRecording(); - - if (modeattacking != ATTACKING_RECORD) - { - if (demo.savemode == DSM_SAVED) - CONS_Printf(M_GetText("Demo %s recorded\n"), demoname); - else - CONS_Alert(CONS_WARNING, M_GetText("Demo %s not saved\n"), demoname); - } -} - -boolean G_DemoTitleResponder(event_t *ev) -{ - INT32 ch; - - if (ev->type != ev_keydown) - return false; - - ch = (INT32)ev->data1; - - // Only ESC and non-keyboard keys abort connection - if (ch == KEY_ESCAPE) - { - demo.savemode = (cv_recordmultiplayerdemos.value == 2) ? DSM_WILLAUTOSAVE : DSM_NOTSAVING; - return true; - } - - if (ch == KEY_ENTER || ch >= KEY_MOUSE1) - { - demo.savemode = DSM_WILLSAVE; - return true; - } - - M_TextInputHandle(&demo.titlenameinput, ch); - - return true; -} - // // G_SetGamestate // diff --git a/src/g_game.h b/src/g_game.h index e59ba0609..9d8b74144 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -21,6 +21,7 @@ extern "C" { #include "doomdef.h" #include "doomstat.h" #include "d_event.h" +#include "g_demo.h" #include "p_saveg.h" #include "m_textinput.h" @@ -38,75 +39,6 @@ extern INT32 player_name_changes[MAXPLAYERS]; extern player_t players[MAXPLAYERS]; extern boolean playeringame[MAXPLAYERS]; -extern savebuffer_t demobuf; - -// ====================================== -// DEMO playback/recording related stuff. -// ====================================== - -// demoplaying back and demo recording -extern consvar_t cv_recordmultiplayerdemos, cv_netdemosyncquality, cv_maxdemosize, cv_demochangemap; -extern consvar_t cv_demodateformat; - -// Publicly-accessible demo vars -struct demovars_s { - char titlename[65]; - textinput_t titlenameinput; - boolean recording, playback, timing; - UINT16 version; // Current file format of the demo being played - boolean title; // Title Screen demo can be cancelled by any key - boolean rewinding; // Rewind in progress - - boolean loadfiles, ignorefiles; // Demo file loading options - boolean fromtitle; // SRB2Kart: Don't stop the music - boolean inreplayhut; // Go back to replayhut after demos - boolean quitafterplaying; // quit after playing a demo from cmdline - boolean deferstart; // don't start playing demo right away - - tic_t savebutton; // Used to determine when the local player can choose to save the replay while the race is still going - enum { - DSM_NOTSAVING, - DSM_WILLAUTOSAVE, - DSM_TITLEENTRY, - DSM_WILLSAVE, - DSM_SAVED - } savemode; -}; - -extern struct demovars_s demo; - -typedef enum { - MD_NOTLOADED, - MD_LOADED, - MD_SUBDIR, - MD_OUTDATED, - MD_INVALID -} menudemotype_e; - -typedef struct menudemo_s { - char filepath[256]; - menudemotype_e type; - - char title[65]; // Null-terminated for string prints - char date[11]; // date when replay was recorded - char version[12]; // combined version and subversion - UINT16 map; - UINT8 addonstatus; // What do we need to do addon-wise to play this demo? - UINT8 gametype; - UINT8 kartspeed; // Add OR DF_ENCORE for encore mode, idk - UINT8 numlaps; - - struct { - UINT8 ranking; - char name[17]; - UINT8 skin, color; - UINT32 timeorscore; - } standings[MAXPLAYERS]; -} menudemo_t; - - -extern mobj_t *metalplayback; - // gametic at level start extern tic_t levelstarttic; @@ -290,10 +222,6 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost); void G_DeferedInitNew(boolean pencoremode, const char *mapname, INT32 pickedchar, UINT8 ssplayers, boolean FLS); -void G_LoadDemoInfo(menudemo_t *pdemo); -void G_LoadDemoTitle(menudemo_t *pdemo); // For use in replay search feature -void G_DeferedPlayDemo(const char *demo); - // Can be called by the startup code or M_Responder, calls P_SetupLevel. void G_LoadGame(UINT32 slot, INT16 mapoverride); @@ -301,97 +229,6 @@ void G_SaveGameData(boolean force); void G_SaveGame(UINT32 slot); -// Only called by startup code. -void G_RecordDemo(const char *name); -void G_RecordMetal(void); -void G_BeginRecording(void); -void G_BeginMetal(void); - -// Only called by shutdown code. -void G_WriteStanding(UINT8 ranking, char *name, INT32 skinnum, UINT8 color, UINT32 val); -void G_SetDemoTime(UINT32 ptime, UINT32 plap); -UINT8 G_CmpDemoTime(char *oldname, char *newname); - -typedef enum -{ - GHC_NORMAL = 0, - GHC_SUPER, - GHC_FIREFLOWER, - GHC_INVINCIBLE -} ghostcolor_t; - -extern UINT8 demo_extradata[MAXPLAYERS]; -extern UINT8 demo_writerng; -#define DXD_RESPAWN 0x01 // "respawn" command in console -#define DXD_SKIN 0x02 // skin changed -#define DXD_NAME 0x04 // name changed -#define DXD_COLOR 0x08 // color changed -#define DXD_PLAYSTATE 0x10 // state changed between playing, spectating, or not in-game - -#define DXD_PST_PLAYING 0x01 -#define DXD_PST_SPECTATING 0x02 -#define DXD_PST_LEFT 0x03 - -// Record/playback tics -void G_ReadDemoExtraData(void); -void G_WriteDemoExtraData(void); -void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum); -void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum); -void G_GhostAddThok(INT32 playernum); -void G_GhostAddSpin(INT32 playernum); -void G_GhostAddRev(INT32 playernum); -void G_GhostAddColor(INT32 playernum, ghostcolor_t color); -void G_GhostAddFlip(INT32 playernum); -void G_GhostAddScale(INT32 playernum, fixed_t scale); -void G_GhostAddHit(INT32 playernum, mobj_t *victim); -void G_WriteAllGhostTics(void); -void G_WriteGhostTic(mobj_t *ghost, INT32 playernum); -void G_ConsAllGhostTics(void); -void G_ConsGhostTic(INT32 playernum); -void G_GhostTicker(void); - -void G_InitDemoRewind(void); -void G_StoreRewindInfo(void); -void G_PreviewRewind(tic_t previewtime); -void G_ConfirmRewind(tic_t rewindtime); - -void G_ReadMetalTic(mobj_t *metal); -void G_WriteMetalTic(mobj_t *metal); -void G_SaveMetal(UINT8 **buffer); -void G_LoadMetal(UINT8 **buffer); - -// Your naming conventions are stupid and useless. -// There is no conflict here. -typedef struct demoghost { - UINT8 checksum[16]; - UINT8 *buffer, *p, color; - UINT16 version; - mobj_t oldmo, *mo; - struct demoghost *next; -} demoghost; -extern demoghost *ghosts; - -// G_CheckDemoExtraFiles: checks if our loaded WAD list matches the demo's. -#define DFILE_ERROR_NOTLOADED 0x01 // Files are not loaded, but can be without a restart. -#define DFILE_ERROR_OUTOFORDER 0x02 // Files are loaded, but out of order. -#define DFILE_ERROR_INCOMPLETEOUTOFORDER 0x03 // Some files are loaded out of order, but others are not. -#define DFILE_ERROR_CANNOTLOAD 0x04 // Files are missing and cannot be loaded. -#define DFILE_ERROR_EXTRAFILES 0x05 // Extra files outside of the replay's file list are loaded. - -void G_ResetDemoRecording(void); -void G_DoPlayDemo(char *defdemoname); -void G_TimeDemo(const char *name); -void G_AddGhost(char *defdemoname); -void G_UpdateStaffGhostName(lumpnum_t l); -void G_DoPlayMetal(void); -void G_DoneLevelLoad(void); -void G_StopMetalDemo(void); -ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void); -void G_StopDemo(void); -boolean G_CheckDemoStatus(void); -void G_SaveDemo(void); -boolean G_DemoTitleResponder(event_t *ev); - #define G_GametypeHasTeams() (G_IsGameType(GT_TEAMMATCH) || G_IsGameType(GT_CTF)) #define G_BattleGametype() (G_IsGameType(GT_MATCH)) #define G_RaceGametype() (G_IsGameType(GT_RACE)) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 2d8ae4e70..eea00fb67 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -180,6 +180,7 @@ static char returnWadPath[256]; #include "../screen.h" //vid.WndParent #include "../d_net.h" #include "../g_game.h" +#include "../g_demo.h" #include "../filesrch.h" #include "../z_zone.h" // Z_Free #include "endtxt.h" From 338fbfbeafd8d10d29be173e4e1dd94a2ffb9765 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 18:56:10 +0200 Subject: [PATCH 40/43] whoops those are demo related lol --- src/g_demo.c | 2 ++ src/g_game.c | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index a83cfa438..d9a6cc363 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -68,6 +68,8 @@ UINT8 numDemos = 0; //3; -- i'm FED UP of losing my skincolour to a broken UINT32 demoDelayTime = 15*TICRATE; UINT32 demoIdleTime = 3*TICRATE; +boolean nodrawers; // for comparative timing purposes +boolean noblit; // for comparative timing purposes static tic_t demostarttime; // for comparative timing purposes //@TODO put these all in a struct for namespacing purposes? diff --git a/src/g_game.c b/src/g_game.c index bc500a973..bedec3335 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -102,9 +102,6 @@ UINT8 modeattacking = ATTACKING_NONE; boolean imcontinuing = false; boolean runemeraldmanager = false; -boolean nodrawers; // for comparative timing purposes -boolean noblit; // for comparative timing purposes - boolean netgame; // only true if packets are broadcast boolean multiplayer; boolean playeringame[MAXPLAYERS]; From c479d9d706fd275d0f0c36f46b3234f1aab7499d Mon Sep 17 00:00:00 2001 From: sphere Date: Mon, 3 Jun 2024 13:45:37 +0000 Subject: [PATCH 41/43] Merge branch 'allowdesync' into 'next' Add a console variable that will allow individual demos to desync.... See merge request STJr/SRB2!2361 --- src/d_netcmd.c | 2 ++ src/g_demo.c | 15 ++++++++++----- src/g_demo.h | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 310bac2b9..8a4e12ebf 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1048,7 +1048,9 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_verticallook[i]); } + CV_RegisterVar(&cv_resyncdemo); CV_RegisterVar(&cv_demodateformat); + CV_RegisterVar(&cv_showspecstuff); // ingame object placing diff --git a/src/g_demo.c b/src/g_demo.c index d9a6cc363..820ef45fb 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -88,6 +88,8 @@ static UINT8 *metalbuffer = NULL; static UINT8 *metal_p; static UINT16 metalversion; +consvar_t cv_resyncdemo = {"resyncdemo", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + // extra data stuff (events registered this frame while recording) static struct { UINT8 flags; // EZT flags @@ -1102,11 +1104,14 @@ void G_ConsGhostTic(INT32 playernum) CONS_Alert(CONS_WARNING, "Demo playback has desynced (player %s)!\n", player_names[playernum]); demosynced = false; - P_UnsetThingPosition(testmo); - testmo->x = oldghost[playernum].x; - testmo->y = oldghost[playernum].y; - P_SetThingPosition(testmo); - testmo->z = oldghost[playernum].z; + if (cv_resyncdemo.value) + { + P_UnsetThingPosition(testmo); + testmo->x = oldghost[playernum].x; + testmo->y = oldghost[playernum].y; + P_SetThingPosition(testmo); + testmo->z = oldghost[playernum].z; + } if (abs(testmo->z - testmo->floorz) < 4*FRACUNIT) testmo->z = testmo->floorz; // Sync players to the ground when they're likely supposed to be there... diff --git a/src/g_demo.h b/src/g_demo.h index 6bfaa0a2c..de1495e91 100644 --- a/src/g_demo.h +++ b/src/g_demo.h @@ -29,6 +29,7 @@ extern savebuffer_t demobuf; // demoplaying back and demo recording extern consvar_t cv_recordmultiplayerdemos, cv_netdemosyncquality, cv_maxdemosize, cv_demochangemap; extern consvar_t cv_demodateformat; +extern consvar_t cv_resyncdemo; // Publicly-accessible demo vars struct demovars_s { From 07e1ca40a40246bfbf92aea0c7fb361075421a85 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 17:35:02 +0200 Subject: [PATCH 42/43] oop dont need those --- src/Makefile.d/features.mk | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Makefile.d/features.mk b/src/Makefile.d/features.mk index ca789dbee..71624241f 100644 --- a/src/Makefile.d/features.mk +++ b/src/Makefile.d/features.mk @@ -69,7 +69,6 @@ opts+=-DHAVE_MINIUPNPC endif ifndef NOLIBBACKTRACE -$(eval $(call Propogate_flags,LIBBACKTRACE)) libs+=-lbacktrace opts+=-DHAVE_LIBBACKTRACE endif @@ -82,7 +81,6 @@ endif endif ifdef HAVE_DISCORDRPC -$(eval $(call Propogate_flags,DISCORDRPC)) libs+=-ldiscord-rpc opts+=-DUSE_STUN sources+=discord.c stun.c From 962eb531ff680ff06198405aeea99875817ed8c6 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 16:27:13 +0200 Subject: [PATCH 43/43] clamp the sprite lightlevel stuff + ensure proper type cast this is a mess lets hope this doesent change how the game looks lel --- src/hardware/hw_main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index f266cf64f..e938d1867 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3757,7 +3757,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) continue; if (!lightset) - lightlevel = std::min(static_cast(*list[i-1].lightlevel), 255); + lightlevel = static_cast(CLAMP(*list[i-1].lightlevel, 0, 255)); colormap = list[i-1].extra_colormap; break; @@ -3776,7 +3776,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) { if (!lightset) { - lightlevel = std::min(static_cast(*list[i].lightlevel), 255); + lightlevel = static_cast(CLAMP(*list[i].lightlevel, 0, 255)); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); } @@ -3984,7 +3984,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) if (!lightset) { - lightlevel = std::min(static_cast(sector->lightlevel), 255); + lightlevel = static_cast(CLAMP(sector->lightlevel, 0, 255)); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); } @@ -4090,7 +4090,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = std::min(static_cast(*sector->lightlist[light].lightlevel), 255); + lightlevel = static_cast(CLAMP(*sector->lightlist[light].lightlevel, 0, 255)); if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4098,7 +4098,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = std::min(static_cast(sector->lightlevel), 255); + lightlevel = static_cast(CLAMP(sector->lightlevel, 0, 255)); if (sector->extra_colormap) colormap = sector->extra_colormap;