From 1c82c338a58c1d06fc93bf381bd38f546a154bd7 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 27 Nov 2025 18:57:12 +0100 Subject: [PATCH 01/12] sprite gzt is float in opengl render........ --- src/hardware/hw_main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 52250bbe8..05c69b2d4 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -4925,16 +4925,17 @@ static void HWR_ProjectSprite(mobj_t *thing) if (heightsec != -1 && phs != -1) // only clip things which are in special sectors { fixed_t secheight; + const fixed_t fgzt = FloatToFixed(gzt); secheight = P_GetSectorFloorZAt(§ors[heightsec], viewx, viewy); if (viewz < P_GetSectorFloorZAt(§ors[phs], interp.x, interp.y) ? interp.z >= secheight : - gzt < secheight) + fgzt < secheight) return; secheight = P_GetSectorCeilingZAt(§ors[heightsec], viewx, viewy); if (viewz > P_GetSectorCeilingZAt(§ors[phs], interp.x, interp.y) ? - gzt < secheight && viewz >= secheight : + fgzt < secheight && viewz >= secheight : interp.z >= secheight) return; } From c26d2faee98d6d0d0d11a4ae23682ccbc9d26616 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 27 Nov 2025 22:03:05 +0100 Subject: [PATCH 02/12] OpenGL: fixup spherefrustum culling and use it for sprites clips sprites that are out of our view, especially with precip this may lead to significant speedup in certain cases huge thanks to indev for helping with this <3 huge thanks to dsda-doom for the maths needed! --- src/hardware/hw_clip.c | 29 +++---- src/hardware/hw_clip.h | 2 +- src/hardware/hw_main.cpp | 129 ++++++++++++++++++++++++------- src/hardware/r_opengl/r_opengl.c | 2 +- src/hardware/r_opengl/r_opengl.h | 1 + 5 files changed, 115 insertions(+), 48 deletions(-) diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 3365136b3..caa19f565 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -348,34 +348,29 @@ angle_t gld_FrustumAngle(angle_t tiltangle) // gld_FrustumSetup // -static GLdouble viewMatrix[16]; -static GLdouble projMatrix[16]; float frustum[6][4]; #define CALCMATRIX(a, b, c, d, e, f, g, h)\ -(float)(viewMatrix[a] * projMatrix[b] + \ -viewMatrix[c] * projMatrix[d] + \ -viewMatrix[e] * projMatrix[f] + \ -viewMatrix[g] * projMatrix[h]) + (modelMatrix[a] * projMatrix[b] + \ + modelMatrix[c] * projMatrix[d] + \ + modelMatrix[e] * projMatrix[f] + \ + modelMatrix[g] * projMatrix[h]) #define NORMALIZE_PLANE(i)\ -t = (float)sqrt(\ -frustum[i][0] * frustum[i][0] + \ -frustum[i][1] * frustum[i][1] + \ -frustum[i][2] * frustum[i][2]); \ -frustum[i][0] /= t; \ -frustum[i][1] /= t; \ -frustum[i][2] /= t; \ -frustum[i][3] /= t + t = sqrtf(\ + frustum[i][0] * frustum[i][0] + \ + frustum[i][1] * frustum[i][1] + \ + frustum[i][2] * frustum[i][2]); \ + frustum[i][0] /= t; \ + frustum[i][1] /= t; \ + frustum[i][2] /= t; \ + frustum[i][3] /= t void gld_FrustumSetup(void) { float t; float clip[16]; - pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); - pglGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix); - clip[0] = CALCMATRIX(0, 0, 1, 4, 2, 8, 3, 12); clip[1] = CALCMATRIX(0, 1, 1, 5, 2, 9, 3, 13); clip[2] = CALCMATRIX(0, 2, 1, 6, 2, 10, 3, 14); diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index 4299fbaea..232d09c06 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -16,7 +16,7 @@ extern "C" { #include "../tables.h" #include "../doomtype.h" -//#define HAVE_SPHEREFRUSTRUM // enable if you want gld_SphereInFrustum and related code +#define HAVE_SPHEREFRUSTRUM // enable if you want gld_SphereInFrustum and related code boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 05c69b2d4..5294301b7 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -83,6 +83,13 @@ float gl_viewsin = 0.0f, gl_viewcos = 0.0f; static float gl_viewludsin, gl_viewludcos; static angle_t gl_aimingangle; +static float yaw = 0.0f; +static float inv_yaw = 0.0f; +static float cos_inv_yaw = 0.0f; +static float sin_inv_yaw = 0.0f; + +static constexpr float deg2radians = (M_PIf / 180.0f); + seg_t *gl_curline = NULL; side_t *gl_sidedef = NULL; line_t *gl_linedef = NULL; @@ -4645,6 +4652,7 @@ static void HWR_ProjectSprite(mobj_t *thing) float tr_x, tr_y; float tz; float x1, x2; + float y1, y2; float z1, z2; float rightsin, rightcos; float this_scale; @@ -4867,17 +4875,6 @@ static void HWR_ProjectSprite(mobj_t *thing) spr_offset += interp.spritexoffset; spr_topoffset += interp.spriteyoffset; - if (papersprite) - { - rightsin = FixedToFloat(FINESINE(interp.angle >> ANGLETOFINESHIFT)); - rightcos = FixedToFloat(FINECOSINE(interp.angle >> ANGLETOFINESHIFT)); - } - else - { - rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); - rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); - } - spritexscale *= this_scale; spriteyscale *= this_scale; @@ -4894,19 +4891,17 @@ static void HWR_ProjectSprite(mobj_t *thing) x2 = (FixedToFloat(spr_width - spr_offset) * spritexscale); } - z1 = tr_y + x1 * rightsin; - z2 = tr_y - x2 * rightsin; - x1 = tr_x + x1 * rightcos; - x2 = tr_x - x2 * rightcos; + y1 = (FixedToFloat(spr_topoffset) * spriteyscale); + y2 = (FixedToFloat(spr_height - spr_topoffset) * spriteyscale); if (vflip) { - gz = FixedToFloat(interp.z + thing->height) - (FixedToFloat(spr_topoffset) * spriteyscale); + gz = FixedToFloat(interp.z + thing->height) - y1; gzt = gz + (FixedToFloat(spr_height) * spriteyscale); } else { - gzt = FixedToFloat(interp.z) + (FixedToFloat(spr_topoffset) * spriteyscale); + gzt = FixedToFloat(interp.z) + y1; gz = gzt - (FixedToFloat(spr_height) * spriteyscale); } @@ -4916,6 +4911,32 @@ static void HWR_ProjectSprite(mobj_t *thing) return; } + // rest in piece sweet prince + /*if (cv_glshearing.value && !papersprite) + { + // killough 4/9/98: clip things which are out of view due to height + // e6y: fix of hanging decoration disappearing in Batman Doom MAP02 + // centeryfrac -> viewheightfrac + // [kb] add +1 so sprites are shown even with the extended freelook + // lug: attempt to account for freelook properly + const fixed_t fixedtz = FloatToFixed(tz); + if (interp.z > viewz + FixedMul(centeryfrac, fixedtz) || // view center accounted for aspect (i hope) + FloatToFixed(gzt) < viewz + FixedMul((centeryfrac - (viewheight << FRACBITS)), fixedtz)) // view center accounted for aspect but the bottom (OwO) + { + return; + } + }*/ + + if (!gld_SphereInFrustum( + (FixedToFloat(interp.x)) + cos_inv_yaw * (x1 + x2) / 2.0f, + FixedToFloat(interp.z) + (y1 + y2) / 2.0f, + FixedToFloat(interp.y) - sin_inv_yaw * (x1 + x2) / 2.0f, + //1.5 == sqrt(2) + small delta for MF_FOREGROUND + std::max(FixedToFloat(spr_width), FixedToFloat(spr_height)) / 2.0f * 1.5f)) + { + return; + } + heightsec = thing->subsector->sector->heightsec; if (viewplayer && viewplayer->mo && viewplayer->mo->subsector) phs = viewplayer->mo->subsector->sector->heightsec; @@ -4940,6 +4961,24 @@ static void HWR_ProjectSprite(mobj_t *thing) return; } + if (papersprite) + { + rightsin = FixedToFloat(FINESINE(interp.angle >> ANGLETOFINESHIFT)); + rightcos = FixedToFloat(FINECOSINE(interp.angle >> ANGLETOFINESHIFT)); + } + else + { + rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + } + + z1 = tr_y + x1 * rightsin; + z2 = tr_y - x2 * rightsin; + x1 = tr_x + x1 * rightcos; + x2 = tr_x - x2 * rightcos; + //y1 = tr_y + y1 * rightcos; + //y2 = tr_y - y2 * rightcos; + // store information in a vissprite vis = HWR_NewVisSprite(); vis->x1 = x1; @@ -5015,12 +5054,16 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) float tr_x, tr_y; float tz; float x1, x2; + float y1, y2; float z1, z2; + float gz, gzt; float rightsin, rightcos; float this_scale; spritedef_t *sprdef; spriteframe_t *sprframe; size_t lumpoff; + fixed_t spr_width, spr_height; + fixed_t spr_offset, spr_topoffset; unsigned rot = 0; UINT8 flip; @@ -5081,22 +5124,46 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) lumpoff = sprframe->lumpid[0]; flip = sprframe->flip; // Will only be 0x00 or 0xFF - rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); - rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + spr_width = spritecachedinfo[lumpoff].width; + spr_height = spritecachedinfo[lumpoff].height; + spr_offset = spritecachedinfo[lumpoff].offset; + spr_topoffset = spritecachedinfo[lumpoff].topoffset; if (flip) { - x1 = FixedToFloat(spritecachedinfo[lumpoff].width - spritecachedinfo[lumpoff].offset); - x2 = FixedToFloat(spritecachedinfo[lumpoff].offset); + x1 = FixedToFloat(spr_width - spr_offset); + x2 = FixedToFloat(spr_offset); } else { - x1 = FixedToFloat(spritecachedinfo[lumpoff].offset); - x2 = FixedToFloat(spritecachedinfo[lumpoff].width - spritecachedinfo[lumpoff].offset); + x1 = FixedToFloat(spr_offset); + x2 = FixedToFloat(spr_offset); } + y1 = (FixedToFloat(spr_topoffset)); + y2 = (FixedToFloat(spr_height - spr_topoffset)); + x1 *= this_scale; x2 *= this_scale; + y1 *= this_scale; + y2 *= this_scale; + + if (!gld_SphereInFrustum( + (FixedToFloat(interp.x)) + cos_inv_yaw * (x1 + x2) / 2.0f, + FixedToFloat(interp.z) + (y1 + y2) / 2.0f, + FixedToFloat(interp.y) - sin_inv_yaw * (x1 + x2) / 2.0f, + //1.5 == sqrt(2) + small delta for MF_FOREGROUND + std::max(FixedToFloat(spr_width), FixedToFloat(spr_height)) / 2.0f * 1.5f)) + { + return; + } + + // set top/bottom coords + gzt = FixedToFloat(interp.z) + y1; + gz = gzt - (FixedToFloat(spr_height) * this_scale); + + rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); z1 = tr_y + x1 * rightsin; z2 = tr_y - x2 * rightsin; @@ -5125,8 +5192,8 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #endif // set top/bottom coords - vis->gzt = FixedToFloat(interp.z) + (FixedToFloat(spritecachedinfo[lumpoff].topoffset) * this_scale); - vis->gz = vis->gzt - (FixedToFloat(spritecachedinfo[lumpoff].height) * this_scale); + vis->gzt = gzt; + vis->gz = gz; vis->precip = thing; } @@ -5140,11 +5207,10 @@ 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 constexpr float radians = (M_PIf / 180.0f); static constexpr float scale = 10000.0f; - static constexpr float maxSideAngle = 60.0f * radians; + static constexpr float maxSideAngle = 60.0f * deg2radians; - float topAngle = ((float)c / (float)sky->columns * 360.0f) * radians; + float topAngle = ((float)c / (float)sky->columns * 360.0f) * deg2radians; float sideAngle = (maxSideAngle * (float)(sky->rows - r) / (float)sky->rows); float height = sinf(sideAngle); float realRadius = (scale * cosf(sideAngle)); @@ -5383,6 +5449,12 @@ void HWR_SetTransform(float fpov) HWR_SetTransformAiming(&atransform); atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(FINEDEGREE); + yaw = 270.0f - atransform.angley; + inv_yaw = 180.0f - yaw; + const float inv_yaw_radians = inv_yaw * deg2radians; + cos_inv_yaw = cosf(inv_yaw_radians); + sin_inv_yaw = sinf(inv_yaw_radians); + // only needed for sprite billboarding if (cv_glspritebillboarding.value && !cv_glshearing.value) { @@ -5489,7 +5561,6 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); HWR_SetTransform(fpov); - HWR_ClearSprites(); HWR_ClearClipper(); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 5fd9c8537..c69d8c1b1 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -127,7 +127,7 @@ GLuint gl_num_extensions; int majorGL = 0, minorGL = 0; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -static GLfloat modelMatrix[16]; +GLfloat modelMatrix[16]; GLfloat projMatrix[16] = {0}; static GLint viewport[4]; diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index b62c0698c..13ba9f6f5 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -124,6 +124,7 @@ extern GLint maximumAnisotropy; extern boolean supportNPO2tex; extern boolean supportMipMap; +extern GLfloat modelMatrix[16]; extern GLfloat projMatrix[16]; #ifdef __cplusplus From d2d3afc7f4b47d9c77ef877d32686ae1ddacbdb8 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 27 Nov 2025 22:07:55 +0100 Subject: [PATCH 03/12] software: clip sprites that are out of view similar to what the frustum cull does in opengl, clips sprites that are out of view in vertical direction --- src/r_things.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/r_things.cpp b/src/r_things.cpp index e250e877b..489ce8911 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1612,6 +1612,20 @@ static void R_ProjectSprite(mobj_t *thing) return; } + if (!papersprite) + { + // killough 4/9/98: clip things which are out of view due to height + // e6y: fix of hanging decoration disappearing in Batman Doom MAP02 + // centeryfrac -> viewheightfrac + // [kb] add +1 so sprites are shown even with the extended freelook + // lug: attempt to account for freelook properly + if (interp.z > viewz + FixedMul(FixedDiv(centeryfrac, projectiony), tz) || + gzt < viewz + FixedMul(FixedDiv(centeryfrac - (viewheight << FRACBITS), projectiony), tz)) + { + return; + } + } + // killough 3/27/98: exclude things totally separated // from the viewer, by either water or fake ceilings // killough 4/11/98: improve sprite clipping for underwater/fake ceilings @@ -1961,6 +1975,17 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) return; } + // killough 4/9/98: clip things which are out of view due to height + // e6y: fix of hanging decoration disappearing in Batman Doom MAP02 + // centeryfrac -> viewheightfrac + // [kb] add +1 so sprites are shown even with the extended freelook + // lug: attempt to account for freelook properly + if (interp.z > viewz + FixedMul(FixedDiv(centeryfrac, projectiony), tz) || + gzt < viewz + FixedMul(FixedDiv(centeryfrac - (viewheight << FRACBITS), projectiony), tz)) + { + return; + } + // aspect ratio stuff : yscale = FixedDiv(projectiony, tz); From 310e64d8be1cfb9972ef4403f40b1ead9de10c6c Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 28 Nov 2025 16:49:13 +0100 Subject: [PATCH 04/12] OpenGL: add a little more checks during texture free prob not necessary but feels better --- src/hardware/hw_cache.c | 12 ++++++++++-- src/hardware/r_opengl/r_opengl.c | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index ee2f13459..90e666745 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -580,6 +580,9 @@ void HWR_InitMapTextures(void) static void FreeMapTexture(GLMapTexture_t *tex) { + if (!tex) + return; + GL_DeleteTexture(&tex->mipmap); Z_Free(tex->mipmap.data); tex->mipmap.data = NULL; @@ -589,6 +592,12 @@ void HWR_FreeMapTextures(void) { size_t i; + if (!gl_textures) + { + gl_numtextures = 0; + return; + } + for (i = 0; i < gl_numtextures; i++) { FreeMapTexture(&gl_textures[i].normal); @@ -599,8 +608,7 @@ void HWR_FreeMapTextures(void) // now the heap don't have any 'user' pointing to our // texturecache info, we can free it - if (gl_textures) - free(gl_textures); + free(gl_textures); gl_textures = NULL; gl_numtextures = 0; } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index c69d8c1b1..341a1b9fc 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1361,7 +1361,8 @@ void GL_Flush(void) TexCacheTail = TexCacheHead = NULL; //Hurdler: well, TexCacheHead is already NULL tex_downloaded = 0; - free(textureBuffer); + if (textureBuffer) + free(textureBuffer); textureBuffer = NULL; textureBufferSize = 0; } @@ -3301,8 +3302,8 @@ void GL_Framebuffer_Disable(void) // delet our fbo if (framebufferobject.fboobj) pglDeleteFramebuffers(1, &framebufferobject.fboobj); - framebufferobject.fboobj = 0; + GL_Framebuffer_DeleteAttachments(); } #endif From 6b8de308b7682d17742793ba214a3f2374940978 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 28 Nov 2025 16:51:24 +0100 Subject: [PATCH 05/12] HWR_Precache: check against gl_numtextures not numtextures in practice those should mostly be the same but the variable is for gl so --- src/hardware/hw_cache.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 90e666745..6a2f10f18 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -681,7 +681,7 @@ static void HWR_PrecacheLevelTextures(void) size_t i, j, f; INT32 h; - texturepresent = calloc(numtextures, sizeof (*texturepresent)); + texturepresent = calloc(gl_numtextures, sizeof(*texturepresent)); if (texturepresent == NULL) I_Error("%s: Out of memory looking up textures", "HWR_PrecacheLevel"); @@ -712,7 +712,10 @@ static void HWR_PrecacheLevelTextures(void) { const INT32 texnum = sidetex[f]; - if (texnum < 0 || texnum >= numtextures || texturepresent[texnum]) + if (texnum < 0 || texnum >= (signed)gl_numtextures) + continue; + + if (texturepresent[texnum]) continue; #ifdef GLENCORE texturepresent[texnum] = 1|noencoremap; @@ -740,14 +743,16 @@ static void HWR_PrecacheLevelTextures(void) for (h = 1; h < anim->numpics; h++) { + const INT32 animtexnum = anim->basepic+h; + if (texpresent & 1) { - HWR_GetTexture(anim->basepic+h, false); + HWR_GetTexture(animtexnum, false); } #ifdef GLENCORE if (texpresent & 2) { - HWR_GetTexture(anim->basepic+h, true); + HWR_GetTexture(animtexnum, true); } #endif } From 1cdc92a62b8287efa280a11c30ac1ce4b045e355 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 28 Nov 2025 16:52:58 +0100 Subject: [PATCH 06/12] HWR_Precache: lookup for flats that already have been precached yes i used c++ unordered_set here, yes i suck with linked lists, lol maybe speeds this process up a little --- src/hardware/{hw_cache.c => hw_cache.cpp} | 98 +++++++++++++---------- 1 file changed, 56 insertions(+), 42 deletions(-) rename src/hardware/{hw_cache.c => hw_cache.cpp} (91%) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.cpp similarity index 91% rename from src/hardware/hw_cache.c rename to src/hardware/hw_cache.cpp index 6a2f10f18..171b0ba25 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.cpp @@ -15,6 +15,8 @@ #ifdef HWRENDER +#include + #include "hw_main.h" #include "hw_glob.h" #include "hw_gl.h" @@ -36,7 +38,7 @@ INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes INT32 textureformat = GL_TEXFMT_P_8; // use chromakey for hole -RGBA_t mapPalette[256] = {0}; // the palette for the currently loaded level or menu etc. +RGBA_t mapPalette[256] = {}; // the palette for the currently loaded level or menu etc. static void HWR_FreeTextureColormaps(patch_t *patch); @@ -98,8 +100,7 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm position = 0; } - position = ((position * scale_y) + (FRACUNIT/2)) >> FRACBITS; - position = max(position, 0); + position = std::max(((position * scale_y) + (FRACUNIT/2)) >> FRACBITS, 0); if (position + count >= pblockheight) count = pblockheight - position; @@ -163,7 +164,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = static_cast(mipmap->data); INT32 bpp; INT32 blockmodulo; RGBA_t *palette; @@ -213,7 +214,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = static_cast(mipmap->data); INT32 bpp; INT32 blockmodulo; INT32 width, height; @@ -288,8 +289,8 @@ static UINT8 *MakeBlock(GLMipmap_t *glMipmap) UINT16 bu16 = ((0x00 <<8) | HWR_PATCHES_CHROMAKEY_COLORINDEX); INT32 blocksize = (glMipmap->width * glMipmap->height); - bpp = format2bpp(glMipmap->format); - block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(glMipmap->data)); + bpp = format2bpp(glMipmap->format); + block = static_cast(Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(glMipmap->data))); switch (bpp) { @@ -326,7 +327,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe texture = textures[texnum]; gltex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; - gltex->mipmap.format = textureformat; + gltex->mipmap.format = static_cast(textureformat); // hack the Legacy skies.. if (UNLIKELY(memcmp(texture->name, "SKY", 3) == 0 && @@ -345,7 +346,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe colormap += COLORMAP_REMAPOFFSET; #endif - gltex->mipmap.colormap = Z_Calloc(sizeof(*gltex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); + gltex->mipmap.colormap = static_cast(Z_Calloc(sizeof(*gltex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL)); gltex->mipmap.colormap->source = colormap; memcpy(gltex->mipmap.colormap->data, colormap, 256 * sizeof(UINT8)); @@ -378,7 +379,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); + pdata = static_cast(W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL)); realpatch = (softwarepatch_t *)pdata; HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); @@ -414,7 +415,7 @@ void HWR_MakePatch(const patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipma glMipmap->flags = 0; // setup the texture info - glMipmap->format = patchformat; + glMipmap->format = static_cast(patchformat); glPatch->max_s = (float)patch->width / (float)glMipmap->width; glPatch->max_t = (float)patch->height / (float)glMipmap->height; @@ -456,7 +457,7 @@ static void HWR_FreeTextureData(patch_t *patch) if (!patch || !patch->hardware) return; - glPatch = patch->hardware; + glPatch = static_cast(patch->hardware); if (vid.glstate == VID_GL_LIBRARY_LOADED) GL_DeleteTexture(glPatch->mipmap); @@ -472,7 +473,7 @@ void HWR_FreeTexture(patch_t *patch) if (patch->hardware) { - GLPatch_t *glPatch = patch->hardware; + GLPatch_t *glPatch = static_cast(patch->hardware); HWR_FreeTextureColormaps(patch); @@ -498,7 +499,7 @@ static void HWR_FreeTextureColormaps(patch_t *patch) if (!patch) return; - pat = patch->hardware; + pat = static_cast(patch->hardware); if (!pat) return; @@ -615,10 +616,23 @@ void HWR_FreeMapTextures(void) static void HWR_PrecacheLevelFlats(void) { + // lookup for flats that may´ve been already loaded + // too lazy to make a hashtable or smth so unordered set will do :carbuncle: + std::unordered_set flatpresent; lumpnum_t lump; size_t i, j; INT32 k; + auto LoadFlat = [&](lumpnum_t lump, boolean noencoremap) + { + // flat already loaded? + if (flatpresent.count(lump) == 0) + { + HWR_GetFlat(lump, noencoremap); + flatpresent.insert(lump); + } + }; + // special case for encore #ifdef GLENCORE if (encoremap) @@ -635,16 +649,16 @@ static void HWR_PrecacheLevelFlats(void) const INT32 pic = ceiling ? sec->ceilingpic : sec->floorpic; const levelflat_t *levelflat = &levelflats[pic]; - lump = levelflat->lumpnum; - HWR_GetFlat(lump, R_NoEncore(sec, ceiling)); - if (levelflat->speed) // it is an animated flat + LoadFlat(lump, R_NoEncore(sec, ceiling)); + + if (levelflat->speed) // is it an animated flat ? { - for (k = 1; k < levelflat->numpics; k++) + // start from 0, occasionally basenumlump != flat->lumpnum + for (k = 0; k < levelflat->numpics; k++) { - lump = levelflat->baselumpnum + k; - HWR_GetFlat(lump, R_NoEncore(sec, ceiling)); + LoadFlat(levelflat->baselumpnum + k, R_NoEncore(sec, ceiling)); } } } @@ -660,15 +674,15 @@ static void HWR_PrecacheLevelFlats(void) const levelflat_t *levelflat = &levelflats[i]; lump = levelflat->lumpnum; - HWR_GetFlat(lump, false); + LoadFlat(lump, false); - if (!levelflat->speed) // is it an animated flat ? - continue; - - for (k = 1; k < levelflat->numpics; k++) + if (levelflat->speed) // is it an animated flat ? { - lump = levelflat->baselumpnum + k; - HWR_GetFlat(lump, false); + // start from 0, occasionally basenumlump != flat->lumpnum + for (k = 0; k < levelflat->numpics; k++) + { + LoadFlat(levelflat->baselumpnum + k, false); + } } } } @@ -681,7 +695,7 @@ static void HWR_PrecacheLevelTextures(void) size_t i, j, f; INT32 h; - texturepresent = calloc(gl_numtextures, sizeof(*texturepresent)); + texturepresent = static_cast(calloc(gl_numtextures, sizeof(*texturepresent))); if (texturepresent == NULL) I_Error("%s: Out of memory looking up textures", "HWR_PrecacheLevel"); @@ -856,7 +870,7 @@ void HWR_LoadMapTextures(size_t pnumtextures) HWR_FreeMapTextures(); gl_numtextures = pnumtextures; - gl_textures = calloc(gl_numtextures, sizeof(*gl_textures)); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore), see: GLMapTextureSet_t + gl_textures = static_cast(calloc(gl_numtextures, sizeof(*gl_textures))); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore), see: GLMapTextureSet_t if (gl_textures == NULL) I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); @@ -949,7 +963,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) W_ReadLump(flatlumpnum, Z_Malloc(size, PU_HWRCACHE, &glMipmap->data)); #ifdef GLENCORE - flat = glMipmap->data; + flat = static_cast(glMipmap->data); for (steppy = 0; steppy < size; steppy++) { if (flat[steppy] == HWR_PATCHES_CHROMAKEY_COLORINDEX) @@ -993,7 +1007,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) if (!noencoremap && encoremap) colormap += COLORMAP_REMAPOFFSET; #endif - glMipmap->colormap = Z_Calloc(sizeof(*glMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + glMipmap->colormap = static_cast(Z_Calloc(sizeof(*glMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL)); glMipmap->colormap->source = colormap; memcpy(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); } @@ -1017,7 +1031,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) // --------------------+ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) { - GLPatch_t *glPatch = patch->hardware; + GLPatch_t *glPatch = static_cast(patch->hardware); if (!glMipmap->downloaded) { @@ -1038,7 +1052,7 @@ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) // ----------------------+ static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) { - GLPatch_t *grPatch = patch->hardware; + GLPatch_t *grPatch = static_cast(patch->hardware); HWR_MakePatch(patch, grPatch, glMipmap, true); // If hardware does not have the texture, then call GL_SetTexture to upload it @@ -1073,7 +1087,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) if (!patch->hardware) Patch_CreateGL(patch); - glPatch = patch->hardware; + glPatch = static_cast(patch->hardware); // Blatant hack for encore colormapping aside... if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) @@ -1109,12 +1123,12 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) // (it have a liste of mipmap) // this malloc is cleared in HWR_FreeColormapCache // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better - newMipmap = calloc(1, sizeof (*newMipmap)); + newMipmap = static_cast(calloc(1, sizeof (*newMipmap))); if (newMipmap == NULL) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); glMipmap->nextcolormap = newMipmap; - newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + newMipmap->colormap = static_cast(Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL)); newMipmap->colormap->source = colormap; memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); @@ -1137,7 +1151,7 @@ patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) { void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]); Patch_Create(NULL, 0, ptr); - Patch_AllocateHardwarePatch(ptr); + Patch_AllocateHardwarePatch(static_cast(ptr)); } return (patch_t *)(lumpcache[lumpnum]); @@ -1154,7 +1168,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 { INT32 i,j; fixed_t posx, posy, stepx, stepy; - UINT8 *block = mipmap->data; // places the data directly into here + UINT8 *block = static_cast(mipmap->data); // places the data directly into here UINT8 *flat; UINT8 *dest, *src, texel; RGBA_t col; @@ -1310,9 +1324,9 @@ void HWR_SetPalette(RGBA_t *palette) static void HWR_SetPaletteLookup(RGBA_t *palette) { int r, g, b; - UINT8 *lut = Z_Malloc( + UINT8 *lut = static_cast(Z_Malloc( HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*sizeof(UINT8), - PU_STATIC, NULL); + PU_STATIC, NULL)); #define STEP_SIZE (256/HWR_PALETTE_LUT_SIZE) for (b = 0; b < HWR_PALETTE_LUT_SIZE; b++) { @@ -1355,7 +1369,7 @@ void HWR_SetMapPalette(void) if (palsize < 768) // 256 * 3 I_Error("HWR_SetMapPalette: A programmer assumed palette lumps are at least 768 bytes long, but apparently this was a wrong assumption!\n"); - RGB_data = W_CacheLumpNum(lumpnum, PU_CACHE); + RGB_data = static_cast(W_CacheLumpNum(lumpnum, PU_CACHE)); // we got the RGB palette now, but we need it in RGBA format. for (i = 0; i < 256; i++) { @@ -1390,7 +1404,7 @@ static UINT32 HWR_CreateLightTable(UINT8 *lighttable) { UINT32 i, id; RGBA_t *palette = HWR_GetTexturePalette(); - RGBA_t *hw_lighttable = Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL); + RGBA_t *hw_lighttable = static_cast(Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL)); // To make the palette index -> RGBA mapping easier for the shader, // the hardware lighttable is composed of RGBA colors instead of palette indices. From a80d119c582de18bf1511b2de4cf0de3bd83d2b4 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 30 Dec 2022 20:17:26 -0800 Subject: [PATCH 07/12] Rename strcasestr to nongnu_strcasestr, macro strcasestr ifndef _GNU_SOURCE Fix for GCC C++ compiler, which always defines _GNU_SOURCE. --- src/doomtype.h | 8 +++++--- src/strcasestr.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index 8043b7285..ed6248129 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -68,11 +68,13 @@ extern "C" { #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif -#ifndef __cplusplus -char *strcasestr(const char *in, const char *what); -#define stristr strcasestr +char *nongnu_strcasestr(const char *in, const char *what); +#ifndef _GNU_SOURCE +#define strcasestr nongnu_strcasestr #endif +#define stristr strcasestr + #if defined (macintosh) //|| defined (__APPLE__) //skip all boolean/Boolean crap #define true 1 #define false 0 diff --git a/src/strcasestr.c b/src/strcasestr.c index 4ff778bf1..d24a36e54 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -51,7 +51,7 @@ swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp) } char * -strcasestr (const char *s, const char *q) +nongnu_strcasestr (const char *s, const char *q) { size_t qn; From 093602fd6b8cb2b3e4d38fb027620d229f358f69 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 28 Nov 2025 18:37:27 +0100 Subject: [PATCH 08/12] comment out unused dynslope member from levelinterpolator_t struct this wont ever work with our thinkerless dynslopes --- src/r_fps.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_fps.h b/src/r_fps.h index c1447897e..89efc6cfb 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -138,12 +138,12 @@ typedef struct levelinterpolator_s { fixed_t oldcx, oldcy, bakcx, bakcy; angle_t oldangle, bakangle; } polyobj; - struct { + /*struct { pslope_t *slope; vector3_t oldo, bako; vector2_t oldd, bakd; fixed_t oldzdelta, bakzdelta; - } dynslope; + } dynslope;*/ }; } levelinterpolator_t; From c3d6cdd2720246840aa22513f685ef47e28c4d52 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 29 Nov 2025 14:25:55 +0100 Subject: [PATCH 09/12] ensure modelMatrix is initialized --- src/hardware/hw_clip.c | 15 ++++++++++----- src/hardware/r_opengl/r_opengl.c | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index caa19f565..3f9536436 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -166,6 +166,7 @@ static void gld_clipper_RemoveRange(clipnode_t *range) { range->prev->next = range->next; } + if (range->next) { range->next->prev = range->prev; @@ -348,7 +349,7 @@ angle_t gld_FrustumAngle(angle_t tiltangle) // gld_FrustumSetup // -float frustum[6][4]; +static float frustum[6][4]; #define CALCMATRIX(a, b, c, d, e, f, g, h)\ (modelMatrix[a] * projMatrix[b] + \ @@ -361,16 +362,20 @@ float frustum[6][4]; frustum[i][0] * frustum[i][0] + \ frustum[i][1] * frustum[i][1] + \ frustum[i][2] * frustum[i][2]); \ - frustum[i][0] /= t; \ - frustum[i][1] /= t; \ - frustum[i][2] /= t; \ - frustum[i][3] /= t + frustum[i][0] /= t; \ + frustum[i][1] /= t; \ + frustum[i][2] /= t; \ + frustum[i][3] /= t void gld_FrustumSetup(void) { float t; float clip[16]; + // HWR_SetTransform will take care of this! + //pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); + //pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); + clip[0] = CALCMATRIX(0, 0, 1, 4, 2, 8, 3, 12); clip[1] = CALCMATRIX(0, 1, 1, 5, 2, 9, 3, 13); clip[2] = CALCMATRIX(0, 2, 1, 6, 2, 10, 3, 14); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 341a1b9fc..491b903b0 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -127,7 +127,7 @@ GLuint gl_num_extensions; int majorGL = 0, minorGL = 0; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -GLfloat modelMatrix[16]; +GLfloat modelMatrix[16] = {0}; GLfloat projMatrix[16] = {0}; static GLint viewport[4]; From 3769ab74acc1825daafee35c876f95dd3aa29c12 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 29 Nov 2025 19:00:45 +0100 Subject: [PATCH 10/12] m_menu: move onchages back to m_menu, get rid of nextmap onchange hack --- src/m_menu.c | 228 ++++++++++++++++++++++++++++++++++++++++++----- src/m_menu.h | 2 + src/m_menudefs.c | 188 +------------------------------------- src/y_inter.c | 3 +- 4 files changed, 209 insertions(+), 212 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index a4bf51f3d..16656211f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -194,6 +194,11 @@ static INT32 vidm_selected = 0; static INT32 vidm_nummodes; static INT32 vidm_column_size; +#define SETUPM_IP_MAXSIZE ((28-1)*8) +static char setupm_ip[64]; +static textinput_t setupm_input_ip; +static UINT8 setupm_pselect = 1; + // // PROTOTYPES // @@ -371,7 +376,6 @@ static void M_HandleMonitorToggles(INT32 choice); static void M_AddonsRefresh(void); // Consvar onchange functions -static void Nextmap_OnChange(void); static void Newgametype_OnChange(void); static void Dummymenuplayer_OnChange(void); static void Dummystaff_OnChange(void); @@ -581,6 +585,196 @@ static void M_CustomCvarMenu(INT32 choice) M_StartMessage(M_GetText("No custom options were found\n"), NULL, MM_NOTHING); } +// ========================================================================== +// CVAR ONCHANGE EVENTS GO HERE +// ========================================================================== +// (there's only a couple anyway) + +// Nextmap. Used for Time Attack. +void Nextmap_OnChange(void) +{ + char *leveltitle; + UINT8 active; + + // Update the string in the consvar. + Z_Free(cv_nextmap.zstring); + leveltitle = G_BuildMapTitle(cv_nextmap.value); + cv_nextmap.string = cv_nextmap.zstring = leveltitle ? leveltitle : Z_StrDup(G_BuildMapName(cv_nextmap.value)); + + if (currentMenu == &SP_TimeAttackDef) + { + // see also p_setup.c's P_LoadRecordGhosts + const size_t glen = strlen(srb2home)+1+strlen("replay")+1+strlen(timeattackfolder)+1+strlen("MAPXX")+1; + char *gpath = malloc(glen); + INT32 i; + + if (!gpath) + return; + + sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value)); + + CV_StealthSetValue(&cv_dummystaff, 0); + + active = false; + SP_TimeAttackMenu[taguest].status = IT_DISABLED; + SP_TimeAttackMenu[tareplay].status = IT_DISABLED; + + // Check if file exists, if not, disable REPLAY option + for (i = 0; i < 4; i++) + { + SP_ReplayMenu[i].status = IT_DISABLED; + SP_GuestReplayMenu[i].status = IT_DISABLED; + } + SP_ReplayMenu[4].status = IT_DISABLED; + + SP_GhostMenu[3].status = IT_DISABLED; + SP_GhostMenu[4].status = IT_DISABLED; + + if (FIL_FileExists(va("%s-%s-time-best.lmp", gpath, cv_chooseskin.string))) { + SP_ReplayMenu[0].status = IT_WHITESTRING|IT_CALL; + SP_GuestReplayMenu[0].status = IT_WHITESTRING|IT_CALL; + active |= 3; + } + if (FIL_FileExists(va("%s-%s-lap-best.lmp", gpath, cv_chooseskin.string))) { + SP_ReplayMenu[1].status = IT_WHITESTRING|IT_CALL; + SP_GuestReplayMenu[1].status = IT_WHITESTRING|IT_CALL; + active |= 3; + } + if (FIL_FileExists(va("%s-%s-last.lmp", gpath, cv_chooseskin.string))) { + SP_ReplayMenu[2].status = IT_WHITESTRING|IT_CALL; + SP_GuestReplayMenu[2].status = IT_WHITESTRING|IT_CALL; + active |= 3; + } + + if (FIL_FileExists(va("%s-guest.lmp", gpath))) + { + SP_ReplayMenu[3].status = IT_WHITESTRING|IT_CALL; + SP_GuestReplayMenu[3].status = IT_WHITESTRING|IT_CALL; + SP_GhostMenu[3].status = IT_STRING|IT_CVAR; + active |= 3; + } + + CV_SetValue(&cv_dummystaff, 1); + if (cv_dummystaff.value) + { + SP_ReplayMenu[4].status = IT_WHITESTRING|IT_KEYHANDLER; + SP_GhostMenu[4].status = IT_STRING|IT_CVAR; + CV_StealthSetValue(&cv_dummystaff, 1); + active |= 1; + } + + if (active) { + if (active & 1) + SP_TimeAttackMenu[tareplay].status = IT_WHITESTRING|IT_SUBMENU; + if (active & 2) + SP_TimeAttackMenu[taguest].status = IT_WHITESTRING|IT_SUBMENU; + } + else if (itemOn == tareplay) // Reset lastOn so replay isn't still selected when not available. + { + currentMenu->lastOn = itemOn; + itemOn = tastart; + } + + if (mapheaderinfo[cv_nextmap.value-1] && mapheaderinfo[cv_nextmap.value-1]->forcecharacter[0] != '\0') + CV_Set(&cv_chooseskin, mapheaderinfo[cv_nextmap.value-1]->forcecharacter); + + free(gpath); + } +} + +static void Dummymenuplayer_OnChange(void) +{ + if (cv_dummymenuplayer.value < 1) + CV_StealthSetValue(&cv_dummymenuplayer, splitscreen+1); + else if (cv_dummymenuplayer.value > splitscreen+1) + CV_StealthSetValue(&cv_dummymenuplayer, 1); +} + +char dummystaffname[22]; + +static void Dummystaff_OnChange(void) +{ + lumpnum_t l; + + dummystaffname[0] = '\0'; + + if ((l = W_CheckNumForName(va("%sS01",G_BuildMapName(cv_nextmap.value)))) == LUMPERROR) + { + CV_StealthSetValue(&cv_dummystaff, 0); + return; + } + else + { + char *temp = dummystaffname; + UINT8 numstaff = 1; + while (numstaff < 99 && (l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value),numstaff+1))) != LUMPERROR) + numstaff++; + + if (cv_dummystaff.value < 1) + CV_StealthSetValue(&cv_dummystaff, numstaff); + else if (cv_dummystaff.value > numstaff) + CV_StealthSetValue(&cv_dummystaff, 1); + + if ((l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value), cv_dummystaff.value))) == LUMPERROR) + return; // shouldn't happen but might as well check... + + G_UpdateStaffGhostName(l); + + while (*temp) + temp++; + + sprintf(temp, " - %d", cv_dummystaff.value); + } +} + +// Newgametype. Used for gametype changes. +static void Newgametype_OnChange(void) +{ + if (cv_nextmap.value && menuactive) + { + if (!mapheaderinfo[cv_nextmap.value-1]) + P_AllocMapHeader((INT16)(cv_nextmap.value-1)); + + if ((cv_newgametype.value == GT_RACE && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_RACE)) || // SRB2kart + ((cv_newgametype.value == GT_MATCH || cv_newgametype.value == GT_TEAMMATCH) && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_MATCH))) + { + INT32 value = 0; + + switch (cv_newgametype.value) + { + case GT_COOP: + value = TOL_RACE; // SRB2kart + break; + case GT_COMPETITION: + value = TOL_COMPETITION; + break; + case GT_RACE: + value = TOL_RACE; + break; + case GT_MATCH: + case GT_TEAMMATCH: + value = TOL_MATCH; + break; + case GT_TAG: + case GT_HIDEANDSEEK: + value = TOL_TAG; + break; + case GT_CTF: + value = TOL_CTF; + break; + } + + CV_SetValue(&cv_nextmap, M_FindFirstMap(value)); + } + } +} + +static void Splitplayers_OnChange(void) +{ + if (cv_splitplayers.value < setupm_pselect) + setupm_pselect = 1; +} + // current menudef menu_t *currentMenu = &MainDef; @@ -6271,8 +6465,7 @@ static void M_EraseGuest(INT32 choice) remove(rguest); M_SetupNextMenu(&SP_TimeAttackDef); - CV_AddValue(&cv_nextmap, -1); - CV_AddValue(&cv_nextmap, 1); + Nextmap_OnChange(); M_StartMessage(M_GetText("Guest replay data erased.\n"),NULL,MM_NOTHING); } @@ -6293,8 +6486,7 @@ static void M_OverwriteGuest(const char *which) Z_Free(rguest); M_SetupNextMenu(&SP_TimeAttackDef); - CV_AddValue(&cv_nextmap, -1); - CV_AddValue(&cv_nextmap, 1); + Nextmap_OnChange(); M_StartMessage(M_GetText("Guest replay data saved.\n"),NULL,MM_NOTHING); } @@ -6364,8 +6556,7 @@ static void M_ModeAttackEndGame(INT32 choice) modeattacking = ATTACKING_NONE; S_ChangeMusicInternal("racent", true); // Update replay availability. - CV_AddValue(&cv_nextmap, 1); - CV_AddValue(&cv_nextmap, -1); + Nextmap_OnChange(); } // ======== @@ -7357,10 +7548,6 @@ static void M_StartServerMenu(INT32 choice) // CONNECT VIA IP // ============== -#define SETUPM_IP_MAXSIZE ((28-1)*8) -static char setupm_ip[64]; -static textinput_t setupm_input_ip; - void M_Multiplayer(INT32 choice) { (void)choice; @@ -7369,8 +7556,6 @@ void M_Multiplayer(INT32 choice) M_SetupNextMenu(&MP_MainDef); } -static UINT8 setupm_pselect = 1; - // Draw the funky Connect IP menu. Tails 11-19-2002 // So much work for such a little thing! static void M_DrawMPMainMenu(void) @@ -7465,12 +7650,6 @@ Update the maxplayers label... } } -static void Splitplayers_OnChange(void) -{ - if (cv_splitplayers.value < setupm_pselect) - setupm_pselect = 1; -} - static void M_SetupMultiHandler(INT32 choice) { boolean exitmenu = false; // exit to previous menu and send name change @@ -8817,15 +8996,15 @@ static boolean M_QuitMultiPlayerMenu(void) if (!fastcmp(setupm_name, setupm_cvname->string)) { // remove trailing whitespaces - for (l= strlen(setupm_name)-1; + for (l = strlen(setupm_name)-1; (signed)l >= 0 && setupm_name[l] ==' '; l--) setupm_name[l] =0; - COM_BufAddText (va("%s \"%s\"\n",setupm_cvname->name,setupm_name)); + COM_BufAddText(va("%s \"%s\"\n",setupm_cvname->name,setupm_name)); } // you know what? always putting these in the buffer won't hurt anything. - COM_BufAddText (va("%s \"%s\"\n",setupm_cvskin->name,skins[setupm_fakeskin].name)); - COM_BufAddText (va("%s %d\n",setupm_cvcolor->name,setupm_fakecolor)); + COM_BufAddText(va("%s \"%s\"\n",setupm_cvskin->name,skins[setupm_fakeskin].name)); + COM_BufAddText(va("%s %d\n",setupm_cvcolor->name,setupm_fakecolor)); return true; } @@ -9069,7 +9248,6 @@ static void M_AssignJoystick(INT32 choice) break; } #else - switch (setupcontrolplayer) { case 4: @@ -10282,6 +10460,7 @@ void M_QuitResponse(INT32 ch) if (ch != 'y' && ch != KEY_ENTER) return; + if (!(netgame || cv_debug)) { mrand = M_RandomKey(sizeof(quitsounds)/sizeof(INT32)); @@ -10298,6 +10477,7 @@ void M_QuitResponse(INT32 ch) I_UpdateTime(cv_timescale.value); } } + I_Quit(); } diff --git a/src/m_menu.h b/src/m_menu.h index 020c17c96..5ec09debb 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -309,6 +309,8 @@ void M_ResetDemoList(void); void M_ReplayHut(INT32 choice); void M_SetPlaybackMenuPointer(void); +void Nextmap_OnChange(void); + void M_RefreshPauseMenu(void); INT32 HU_GetHighlightColor(void); diff --git a/src/m_menudefs.c b/src/m_menudefs.c index a57141b7c..1ac2a8f50 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -2649,191 +2649,7 @@ menu_t OP_ForkedBirdDef = { menu_t OP_LocalSkinDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_ForkedBirdDef, 30, 60, NULL); - -// ========================================================================== -// CVAR ONCHANGE EVENTS GO HERE -// ========================================================================== -// (there's only a couple anyway) - -// Nextmap. Used for Time Attack. -static void Nextmap_OnChange(void) -{ - char *leveltitle; - UINT8 active; - - // Update the string in the consvar. - Z_Free(cv_nextmap.zstring); - leveltitle = G_BuildMapTitle(cv_nextmap.value); - cv_nextmap.string = cv_nextmap.zstring = leveltitle ? leveltitle : Z_StrDup(G_BuildMapName(cv_nextmap.value)); - - if (currentMenu == &SP_TimeAttackDef) - { - // see also p_setup.c's P_LoadRecordGhosts - const size_t glen = strlen(srb2home)+1+strlen("replay")+1+strlen(timeattackfolder)+1+strlen("MAPXX")+1; - char *gpath = malloc(glen); - INT32 i; - - if (!gpath) - return; - - sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value)); - - CV_StealthSetValue(&cv_dummystaff, 0); - - active = false; - SP_TimeAttackMenu[taguest].status = IT_DISABLED; - SP_TimeAttackMenu[tareplay].status = IT_DISABLED; - - // Check if file exists, if not, disable REPLAY option - for (i = 0; i < 4; i++) - { - SP_ReplayMenu[i].status = IT_DISABLED; - SP_GuestReplayMenu[i].status = IT_DISABLED; - } - SP_ReplayMenu[4].status = IT_DISABLED; - - SP_GhostMenu[3].status = IT_DISABLED; - SP_GhostMenu[4].status = IT_DISABLED; - - if (FIL_FileExists(va("%s-%s-time-best.lmp", gpath, cv_chooseskin.string))) { - SP_ReplayMenu[0].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[0].status = IT_WHITESTRING|IT_CALL; - active |= 3; - } - if (FIL_FileExists(va("%s-%s-lap-best.lmp", gpath, cv_chooseskin.string))) { - SP_ReplayMenu[1].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[1].status = IT_WHITESTRING|IT_CALL; - active |= 3; - } - if (FIL_FileExists(va("%s-%s-last.lmp", gpath, cv_chooseskin.string))) { - SP_ReplayMenu[2].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[2].status = IT_WHITESTRING|IT_CALL; - active |= 3; - } - - if (FIL_FileExists(va("%s-guest.lmp", gpath))) - { - SP_ReplayMenu[3].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[3].status = IT_WHITESTRING|IT_CALL; - SP_GhostMenu[3].status = IT_STRING|IT_CVAR; - active |= 3; - } - - CV_SetValue(&cv_dummystaff, 1); - if (cv_dummystaff.value) - { - SP_ReplayMenu[4].status = IT_WHITESTRING|IT_KEYHANDLER; - SP_GhostMenu[4].status = IT_STRING|IT_CVAR; - CV_StealthSetValue(&cv_dummystaff, 1); - active |= 1; - } - - if (active) { - if (active & 1) - SP_TimeAttackMenu[tareplay].status = IT_WHITESTRING|IT_SUBMENU; - if (active & 2) - SP_TimeAttackMenu[taguest].status = IT_WHITESTRING|IT_SUBMENU; - } - else if (itemOn == tareplay) // Reset lastOn so replay isn't still selected when not available. - { - currentMenu->lastOn = itemOn; - itemOn = tastart; - } - - if (mapheaderinfo[cv_nextmap.value-1] && mapheaderinfo[cv_nextmap.value-1]->forcecharacter[0] != '\0') - CV_Set(&cv_chooseskin, mapheaderinfo[cv_nextmap.value-1]->forcecharacter); - - free(gpath); - } -} - -static void Dummymenuplayer_OnChange(void) -{ - if (cv_dummymenuplayer.value < 1) - CV_StealthSetValue(&cv_dummymenuplayer, splitscreen+1); - else if (cv_dummymenuplayer.value > splitscreen+1) - CV_StealthSetValue(&cv_dummymenuplayer, 1); -} - -char dummystaffname[22]; - -static void Dummystaff_OnChange(void) -{ - lumpnum_t l; - - dummystaffname[0] = '\0'; - - if ((l = W_CheckNumForName(va("%sS01",G_BuildMapName(cv_nextmap.value)))) == LUMPERROR) - { - CV_StealthSetValue(&cv_dummystaff, 0); - return; - } - else - { - char *temp = dummystaffname; - UINT8 numstaff = 1; - while (numstaff < 99 && (l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value),numstaff+1))) != LUMPERROR) - numstaff++; - - if (cv_dummystaff.value < 1) - CV_StealthSetValue(&cv_dummystaff, numstaff); - else if (cv_dummystaff.value > numstaff) - CV_StealthSetValue(&cv_dummystaff, 1); - - if ((l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value), cv_dummystaff.value))) == LUMPERROR) - return; // shouldn't happen but might as well check... - - G_UpdateStaffGhostName(l); - - while (*temp) - temp++; - - sprintf(temp, " - %d", cv_dummystaff.value); - } -} - -// Newgametype. Used for gametype changes. -static void Newgametype_OnChange(void) -{ - if (cv_nextmap.value && menuactive) - { - if (!mapheaderinfo[cv_nextmap.value-1]) - P_AllocMapHeader((INT16)(cv_nextmap.value-1)); - - if ((cv_newgametype.value == GT_RACE && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_RACE)) || // SRB2kart - ((cv_newgametype.value == GT_MATCH || cv_newgametype.value == GT_TEAMMATCH) && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_MATCH))) - { - INT32 value = 0; - - switch (cv_newgametype.value) - { - case GT_COOP: - value = TOL_RACE; // SRB2kart - break; - case GT_COMPETITION: - value = TOL_COMPETITION; - break; - case GT_RACE: - value = TOL_RACE; - break; - case GT_MATCH: - case GT_TEAMMATCH: - value = TOL_MATCH; - break; - case GT_TAG: - case GT_HIDEANDSEEK: - value = TOL_TAG; - break; - case GT_CTF: - value = TOL_CTF; - break; - } - - CV_SetValue(&cv_nextmap, M_FindFirstMap(value)); - } - } -} - +// Onchange functions to show/hide/move things in menus void Screenshot_option_Onchange(void) { OP_ScreenshotOptionsMenu[op_screenshot_folder].status = @@ -2910,7 +2726,7 @@ void Bird_menu_Onchange(void) OP_AdvancedBirdMenu[respawnfadein].status = status; } -//menu code is nice +// menu code is nice void SaturnHud_menu_Onchange(void) { UINT16 status; diff --git a/src/y_inter.c b/src/y_inter.c index 8a105bfa3..868e6021c 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -701,8 +701,7 @@ static void Y_UpdateRecordReplays(void) G_SaveGameData(false); // Update timeattack menu's replay availability. - CV_AddValue(&cv_nextmap, 1); - CV_AddValue(&cv_nextmap, -1); + Nextmap_OnChange(); } // From 3bac722562fc4ca9e39fa4b04e67291e21767104 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 29 Nov 2025 18:59:03 +0100 Subject: [PATCH 11/12] m_menu: cleanup gamepad menu stuff a little --- src/m_menu.c | 41 +++++++++++++++++++---------------------- src/sdl/i_video.c | 8 ++++---- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 16656211f..30de2c113 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9091,24 +9091,20 @@ static void M_DrawJoystick(void) //M_DrawSaveLoadBorder(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i); #ifdef JOYSTICK_HOTPLUG - if (atoi(cv_usejoystick[3].string) > I_NumJoys()) - compareval4 = atoi(cv_usejoystick[3].string); - else + compareval4 = atoi(cv_usejoystick[3].string); + if (compareval4 <= numcontrollers) compareval4 = cv_usejoystick[3].value; - if (atoi(cv_usejoystick[2].string) > I_NumJoys()) - compareval3 = atoi(cv_usejoystick[2].string); - else + compareval3 = atoi(cv_usejoystick[2].string); + if (compareval3 <= numcontrollers) compareval3 = cv_usejoystick[2].value; - if (atoi(cv_usejoystick[1].string) > I_NumJoys()) - compareval2 = atoi(cv_usejoystick[1].string); - else + compareval2 = atoi(cv_usejoystick[1].string); + if (compareval2 <= numcontrollers) compareval2 = cv_usejoystick[1].value; - if (atoi(cv_usejoystick[0].string) > I_NumJoys()) - compareval = atoi(cv_usejoystick[0].string); - else + compareval = atoi(cv_usejoystick[0].string); + if (compareval <= numcontrollers) compareval = cv_usejoystick[0].value; #else compareval4 = cv_usejoystick[3].value; @@ -9131,15 +9127,16 @@ void M_SetupJoystickMenu(INT32 choice) { INT32 i = 0; const char *joyNA = "Unavailable"; - INT32 n = I_NumJoys(); (void)choice; strcpy(joystickInfo[i], "None"); for (i = 1; i < 8; i++) { - if (i <= n && (I_GetJoyName(i)) != NULL) - strncpy(joystickInfo[i], I_GetJoyName(i), 28); + const char *joyname = I_GetJoyName(i); + + if (i <= numcontrollers && joyname != NULL) + strncpy(joystickInfo[i], joyname, 28); else strcpy(joystickInfo[i], joyNA); @@ -9198,28 +9195,28 @@ static void M_Setup4PJoystickMenu(INT32 choice) static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) { INT32 oldchoice, oldstringchoice; - const INT32 numjoys = I_NumJoys(); + const int joynum = atoi(cv_usejoystick[pnum].string); - oldchoice = oldstringchoice = atoi(cv_usejoystick[pnum].string) > numjoys ? atoi(cv_usejoystick[pnum].string) : cv_usejoystick[pnum].value; + oldchoice = oldstringchoice = joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value; CV_SetValue(&cv_usejoystick[pnum], choice); // Just in case last-minute changes were made to cv_usejoystick.value, // update the string too // But don't do this if we're intentionally setting higher than numjoys - if (choice <= numjoys) + if (choice <= numcontrollers) { CV_SetValue(&cv_usejoystick[pnum], cv_usejoystick[pnum].value); - if (oldchoice > numjoys) /* reset this so the comparison is valid*/ + if (oldchoice > numcontrollers) /* reset this so the comparison is valid*/ oldchoice = cv_usejoystick[pnum].value; if (oldchoice != choice) { - if (choice && oldstringchoice > numjoys) // if we did not select "None", we likely selected a used device - CV_SetValue(&cv_usejoystick[pnum], (oldstringchoice > numjoys ? oldstringchoice : oldchoice)); + if (choice && oldstringchoice > numcontrollers) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick[pnum], (oldstringchoice > numcontrollers ? oldstringchoice : oldchoice)); if (oldstringchoice == - (atoi(cv_usejoystick[pnum].string) > numjoys ? atoi(cv_usejoystick[pnum].string) : cv_usejoystick[pnum].value)) + (joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value)) M_StartMessage("This joystick is used by another\n" "player. Reset the joystick\n" "for that player first.\n\n" diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index e765bbb87..1aba4f109 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1014,12 +1014,12 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); + numcontrollers = I_NumJoys(); + // update the menu if (currentMenu == &OP_JoystickSetDef) M_SetupJoystickMenu(0); - numcontrollers = I_NumJoys(); - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { if (JoyInfo[i].dev == newcontroller) @@ -1076,11 +1076,11 @@ static void Impl_HandleControllerRemovedEvent(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); + numcontrollers = I_NumJoys(); + // update the menu if (currentMenu == &OP_JoystickSetDef) M_SetupJoystickMenu(0); - - numcontrollers = I_NumJoys(); } void I_GetEvent(void) From bb9a4a0da0cc67df4f7dbf1a56e641af87bba251 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 30 Nov 2025 00:36:31 +0300 Subject: [PATCH 12/12] Add listemotes command, also fix few emote warnings not printing newlines --- src/m_emotes.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index e45dcff58..515799af3 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -10,6 +10,7 @@ /// \brief Chat emotes handling #include +#include #include #include #include @@ -22,8 +23,11 @@ extern "C" { #include "z_zone.h" #include "hu_stuff.h" #include "v_video.h" +#include "command.h" } +static void Command_ListEmotes_f(void); + consvar_t cv_emotes = {"emotes", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; static std::map emotes; @@ -140,7 +144,7 @@ void M_LoadEmotes(UINT16 wadnum) if (framelumpname.size() > 8) { - CONS_Alert(CONS_WARNING, "EMOTES: Frame %d name is too long. (file %s, line %d)", numframes, wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Frame %d name is too long. (file %s, line %d)\n", numframes, wadfiles[wadnum]->filename, linenum); framelumpname.resize(8); } @@ -155,7 +159,7 @@ void M_LoadEmotes(UINT16 wadnum) if (numframes == 0) { - CONS_Alert(CONS_WARNING, "EMOTES: Expected list of frames. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Expected list of frames. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); } emote->numframes = numframes; @@ -167,12 +171,12 @@ void M_LoadEmotes(UINT16 wadnum) if (emote->timeperframe <= 0) { emote->timeperframe = 1; - CONS_Alert(CONS_WARNING, "EMOTES: Bad value for 'timeperframe'. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Bad value for 'timeperframe'. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); } } else { - CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized field '%s'. (file %s, line %d)", field.c_str(), wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized field '%s'. (file %s, line %d)\n", field.c_str(), wadfiles[wadnum]->filename, linenum); } } else @@ -189,6 +193,8 @@ void M_InitEmotes(void) UINT16 i; for (i = 0; i < numwadfiles; i++) M_LoadEmotes(i); + + COM_AddCommand("listemotes", Command_ListEmotes_f); } emote_t *M_FindEmote(const char *name, int len, int skip) @@ -268,3 +274,37 @@ void M_DrawScaledEmote(fixed_t x, fixed_t y, fixed_t scale, emote_t *emote, INT3 V_DrawFixedPatch(x, y, scale, flags, emotepatch, NULL); } + +static void Command_ListEmotes_f(void) +{ + const int EMOTES_PER_PAGE = 24; + const int NUMPAGES = std::max(emotes.size()/EMOTES_PER_PAGE, 1); + int page = 1; + + if (COM_Argc() > 1) + page = std::atoi(COM_Argv(1)); + + if (page <= 0 || page > NUMPAGES) + { + if (NUMPAGES > 1) + CONS_Printf("Enter page number between 1 and %d\n", NUMPAGES); + else + CONS_Printf("Bad page number, try using this command without arguments\n"); + return; + } + + int i = 0; + for (auto &pair: emotes) + { + ++i; + + if (i <= (page-1)*EMOTES_PER_PAGE) + continue; + if (i > page*EMOTES_PER_PAGE) + break; + + CONS_Printf("%s - :%s:\n", pair.first.c_str(), pair.first.c_str()); + } + + CONS_Printf("Page %d/%d\n", page, NUMPAGES); +}