From 205bfc02627526e717c1c0b61d6a9ad7d88575c6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 3 Mar 2024 04:53:15 +0100 Subject: [PATCH 01/59] Split R_LoadTextures --- src/r_data.c | 206 ++++++++++++++++++++++++++++----------------------- 1 file changed, 112 insertions(+), 94 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index 772d76925..7d741661e 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -374,21 +374,98 @@ void R_FlushTextureCache(void) int R_CountTexturesInTEXTURESLump(UINT16 wadNum, UINT16 lumpNum); void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *index); -// -// R_LoadTextures -// Initializes the texture list with the textures from the world map. -// #define TX_START "TX_START" #define TX_END "TX_END" -void R_LoadTextures(void) + +static INT32 +Rloadtextures (INT32 i, INT32 w) { - INT32 i, k, w; UINT16 j; + INT32 k; UINT16 texstart, texend, texturesLumpPos; patch_t *patchlump; texpatch_t *patch; texture_t *texture; + // Get the lump numbers for the markers in the WAD, if they exist. + if (W_FileHasFolders(wadfiles[w])) + { + texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); + texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); + while (texturesLumpPos != INT16_MAX) + { + R_ParseTEXTURESLump(w, texturesLumpPos, &i); + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, texturesLumpPos + 1); + } + } + else + { + texstart = W_CheckNumForMarkerStartPwad(TX_START, (UINT16)w, 0); + texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); + if (texturesLumpPos != INT16_MAX) + R_ParseTEXTURESLump(w, texturesLumpPos, &i); + } + + if (!( texstart == INT16_MAX || texend == INT16_MAX )) + { + // Work through each lump between the markers in the WAD. + for (j = 0; j < (texend - texstart); j++) + { + UINT16 wadnum = (UINT16)w; + lumpnum_t lumpnum = texstart + j; + + if (W_FileHasFolders(wadfiles[w])) + { + if (W_IsLumpFolder(wadnum, lumpnum)) // Check if lump is a folder + continue; // If it is then SKIP IT + } + + patchlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); + + //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); + texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); + + // Set texture properties. + M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); + texture->width = SHORT(patchlump->width); + texture->height = SHORT(patchlump->height); + texture->patchcount = 1; + texture->holes = false; + + // Allocate information for the texture's patches. + patch = &texture->patches[0]; + + patch->originx = patch->originy = 0; + patch->wad = (UINT16)w; + patch->lump = texstart + j; + + Z_Free(patchlump); + + k = 1; + while (k << 1 <= texture->width) + k <<= 1; + + texturewidthmask[i] = k - 1; + textureheight[i] = texture->height << FRACBITS; + i++; + } + } + + return i; +} + +// +// R_LoadTextures +// Initializes the texture list with the textures from the world map. +// +void R_LoadTextures(void) +{ + INT32 i, w; + UINT16 j; + UINT16 texstart, texend, texturesLumpPos; + // Free previous memory before numtextures change. if (numtextures) { @@ -410,17 +487,7 @@ void R_LoadTextures(void) // but the alternative is to spend a ton of time checking and re-checking all previous entries just to skip any potentially patched textures. for (w = 0, numtextures = 0; w < numwadfiles; w++) { - if (wadfiles[w]->type == RET_PK3) - { - texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); - texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); - } - else - { - texstart = W_CheckNumForNamePwad(TX_START, (UINT16)w, 0) + 1; - texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); - } - + // Count the textures from TEXTURES lumps texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); while (texturesLumpPos != INT16_MAX) { @@ -428,23 +495,34 @@ void R_LoadTextures(void) texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, texturesLumpPos + 1); } - // Add all the textures between TX_START and TX_END - if (texstart != INT16_MAX && texend != INT16_MAX) + // Count single-patch textures + if (W_FileHasFolders(wadfiles[w])) { - // PK3s have subfolders, so we can't just make a simple sum - if (W_FileHasFolders(wadfiles[w])) + texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); + texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); + } + else + { + texstart = W_CheckNumForMarkerStartPwad(TX_START, (UINT16)w, 0); + texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); + } + + if (texstart == INT16_MAX || texend == INT16_MAX) + continue; + + // PK3s have subfolders, so we can't just make a simple sum + if (W_FileHasFolders(wadfiles[w])) + { + for (j = texstart; j < texend; j++) { - for (j = texstart; j < texend; j++) - { - if (!W_IsLumpFolder((UINT16)w, j)) // Check if lump is a folder; if not, then count it - numtextures++; - } - } - else - { - numtextures += (UINT32)(texend - texstart); + if (!W_IsLumpFolder((UINT16)w, j)) // Check if lump is a folder; if not, then count it + numtextures++; } } + else // Add all the textures between TX_START and TX_END + { + numtextures += (UINT32)(texend - texstart); + } } // If no textures found by this point, bomb out @@ -459,9 +537,9 @@ void R_LoadTextures(void) texturecolumnofs = (void *)((UINT8 *)textures + (numtextures * sizeof(void *))); // Allocate texture referencing cache. texturecache = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 2)); - // Allocate texture width mask table. - texturewidthmask = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 3)); - // Allocate texture height mask table. + // Allocate texture width table. + texturewidthmask = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 3)); + // Allocate texture height table. textureheight = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 4)); // Create translation table for global animation. texturetranslation = Z_Malloc((numtextures + 1) * sizeof(*texturetranslation), PU_STATIC, NULL); @@ -471,67 +549,7 @@ void R_LoadTextures(void) for (i = 0, w = 0; w < numwadfiles; w++) { - // Get the lump numbers for the markers in the WAD, if they exist. - if (wadfiles[w]->type == RET_PK3) - { - texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); - texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); - while (texturesLumpPos != INT16_MAX) - { - R_ParseTEXTURESLump(w, texturesLumpPos, &i); - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, texturesLumpPos + 1); - } - } - else - { - texstart = W_CheckNumForNamePwad(TX_START, (UINT16)w, 0) + 1; - texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); - if (texturesLumpPos != INT16_MAX) - R_ParseTEXTURESLump(w, texturesLumpPos, &i); - } - - if (texstart == INT16_MAX || texend == INT16_MAX) - continue; - - // Work through each lump between the markers in the WAD. - for (j = 0; j < (texend - texstart); j++) - { - if (W_FileHasFolders(wadfiles[w])) - { - if (W_IsLumpFolder(w, texstart + j)) // Check if lump is a folder - continue; // If it is then SKIP IT - } - patchlump = W_CacheLumpNumPwad((UINT16)w, texstart + j, PU_CACHE); - - //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); - texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); - - // Set texture properties. - M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); - texture->width = SHORT(patchlump->width); - texture->height = SHORT(patchlump->height); - texture->patchcount = 1; - texture->holes = false; - - // Allocate information for the texture's patches. - patch = &texture->patches[0]; - - patch->originx = patch->originy = 0; - patch->wad = (UINT16)w; - patch->lump = texstart + j; - - Z_Unlock(patchlump); - - k = 1; - while (k << 1 <= texture->width) - k <<= 1; - - texturewidthmask[i] = k - 1; - textureheight[i] = texture->height << FRACBITS; - i++; - } + i = Rloadtextures(i, w); } #ifdef HWRENDER -- 2.54.0 From c3a71b60b0ee1e9011307779ed604cb2458bee96 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 3 Mar 2024 05:18:37 +0100 Subject: [PATCH 02/59] Do not reload every texture when adding a wad https://git.do.srb2.org/STJr/SRB2/-/merge_requests/1725?commit_id=37add34b9c729b21e624e22d64159073c9258e25 --- src/doomdef.h | 16 ++++ src/p_setup.c | 4 +- src/r_data.c | 219 ++++++++++++++++++++++++++++++++++---------------- src/r_data.h | 2 + src/w_wad.c | 25 ++++-- src/w_wad.h | 1 + 6 files changed, 188 insertions(+), 79 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 208b6cc69..9149a2203 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -516,6 +516,22 @@ extern boolean capslock; // i_system.c, replace getchar() once the keyboard has been appropriated INT32 I_GetKey(void); +/* http://www.cse.yorku.ca/~oz/hash.html */ +static inline +UINT32 quickncasehash (const char *p, size_t n) +{ + size_t i = 0; + UINT32 x = 5381; + + while (i < n && p[i]) + { + x = (x * 33) ^ tolower(p[i]); + i++; + } + + return x; +} + #ifndef min // Double-Check with WATTCP-32's cdefs.h #define min(x, y) (((x) < (y)) ? (x) : (y)) #endif diff --git a/src/p_setup.c b/src/p_setup.c index 9ae36afc9..2435390cb 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3452,6 +3452,8 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!devparm && digmreplaces) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); + R_LoadTexturesPwad(wadnum); + // // search for sprite replacements // @@ -3548,7 +3550,7 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 1) { // Reload all textures, unconditionally for better or worse. - R_LoadTextures(); + //R_LoadTextures(); if (fullsetup) ++partadd_stage; diff --git a/src/r_data.c b/src/r_data.c index 7d741661e..17b5fb743 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -129,6 +129,7 @@ INT16 *hicolormaps; // test a 32k colormap remaps high -> high // Painfully simple texture id cacheing to make maps load faster. :3 static struct { char name[9]; + UINT32 hash; INT32 id; } *tidcache = NULL; static INT32 tidcachelen = 0; @@ -429,6 +430,7 @@ Rloadtextures (INT32 i, INT32 w) // Set texture properties. M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); + texture->hash = quickncasehash(texture->name, 8); texture->width = SHORT(patchlump->width); texture->height = SHORT(patchlump->height); texture->patchcount = 1; @@ -456,27 +458,53 @@ Rloadtextures (INT32 i, INT32 w) return i; } -// -// R_LoadTextures -// Initializes the texture list with the textures from the world map. -// -void R_LoadTextures(void) +static INT32 +count_range +( const char * marker_start, + const char * marker_end, + const char * folder, + UINT16 wadnum) { - INT32 i, w; UINT16 j; - UINT16 texstart, texend, texturesLumpPos; + UINT16 texstart, texend; + INT32 count = 0; - // Free previous memory before numtextures change. - if (numtextures) + // Count flats + if (W_FileHasFolders(wadfiles[wadnum])) { - for (i = 0; i < numtextures; i++) - { - Z_Free(textures[i]); - Z_Free(texturecache[i]); - } - Z_Free(texturetranslation); - Z_Free(textures); + texstart = W_CheckNumForFolderStartPK3(folder, wadnum, 0); + texend = W_CheckNumForFolderEndPK3(folder, wadnum, texstart); } + else + { + texstart = W_CheckNumForMarkerStartPwad(marker_start, wadnum, 0); + texend = W_CheckNumForNamePwad(marker_end, wadnum, texstart); + } + + if (texstart != INT16_MAX && texend != INT16_MAX) + { + // PK3s have subfolders, so we can't just make a simple sum + if (W_FileHasFolders(wadfiles[wadnum])) + { + for (j = texstart; j < texend; j++) + { + if (!W_IsLumpFolder(wadnum, j)) // Check if lump is a folder; if not, then count it + count++; + } + } + else // Add all the textures between markers + { + count += (texend - texstart); + } + } + + return count; +} + +static INT32 R_CountTextures(UINT16 wadnum) +{ + UINT16 texturesLumpPos; + INT32 count = 0; // Load patches and textures. @@ -485,79 +513,125 @@ void R_LoadTextures(void) // the markers. // This system will allocate memory for all duplicate/patched textures even if it never uses them, // but the alternative is to spend a ton of time checking and re-checking all previous entries just to skip any potentially patched textures. - for (w = 0, numtextures = 0; w < numwadfiles; w++) + + // Count the textures from TEXTURES lumps + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", wadnum, 0); + + while (texturesLumpPos != INT16_MAX) { - // Count the textures from TEXTURES lumps - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); - while (texturesLumpPos != INT16_MAX) - { - numtextures += R_CountTexturesInTEXTURESLump((UINT16)w, (UINT16)texturesLumpPos); - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, texturesLumpPos + 1); - } - - // Count single-patch textures - if (W_FileHasFolders(wadfiles[w])) - { - texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); - texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); - } - else - { - texstart = W_CheckNumForMarkerStartPwad(TX_START, (UINT16)w, 0); - texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); - } - - if (texstart == INT16_MAX || texend == INT16_MAX) - continue; - - // PK3s have subfolders, so we can't just make a simple sum - if (W_FileHasFolders(wadfiles[w])) - { - for (j = texstart; j < texend; j++) - { - if (!W_IsLumpFolder((UINT16)w, j)) // Check if lump is a folder; if not, then count it - numtextures++; - } - } - else // Add all the textures between TX_START and TX_END - { - numtextures += (UINT32)(texend - texstart); - } + count += R_CountTexturesInTEXTURESLump(wadnum, texturesLumpPos); + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", wadnum, texturesLumpPos + 1); } - // If no textures found by this point, bomb out - if (!numtextures) - I_Error("No textures detected in any WADs!\n"); + // Count single-patch textures + count += count_range(TX_START, TX_END, "textures/", wadnum); + + return count; +} + +static void +recallocuser +( void * user, + size_t old, + size_t new) +{ + char *p = Z_Realloc(*(void**)user, + new, PU_STATIC, user); + + if (new > old) + memset(&p[old], 0, (new - old)); +} + +static void R_AllocateTextures(INT32 add) +{ + const INT32 newtextures = (numtextures + add); + const size_t newsize = newtextures * sizeof (void*); + const size_t oldsize = numtextures * sizeof (void*); + + INT32 i; // Allocate memory and initialize to 0 for all the textures we are initialising. - // There are actually 5 buffers allocated in one for convenience. - textures = Z_Calloc((numtextures * sizeof(void *)) * 5, PU_STATIC, NULL); + recallocuser(&textures, oldsize, newsize); // Allocate texture column offset table. - texturecolumnofs = (void *)((UINT8 *)textures + (numtextures * sizeof(void *))); + recallocuser(&texturecolumnofs, oldsize, newsize); // Allocate texture referencing cache. - texturecache = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 2)); + recallocuser(&texturecache, oldsize, newsize); // Allocate texture width table. - texturewidthmask = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 3)); + recallocuser(&texturewidthmask, oldsize, newsize); // Allocate texture height table. - textureheight = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 4)); + recallocuser(&textureheight, oldsize, newsize); // Create translation table for global animation. - texturetranslation = Z_Malloc((numtextures + 1) * sizeof(*texturetranslation), PU_STATIC, NULL); + Z_Realloc(texturetranslation, (newtextures + 1) * sizeof(*texturetranslation), PU_STATIC, &texturetranslation); - for (i = 0; i < numtextures; i++) - texturetranslation[i] = i; - - for (i = 0, w = 0; w < numwadfiles; w++) + for (i = 0; i < numtextures; ++i) { - i = Rloadtextures(i, w); + // R_FlushTextureCache relies on the user for + // Z_Free, texturecache has been reallocated so the + // user is now garbage memory. + Z_SetUser(texturecache[i], + (void**)&texturecache[i]); } + while (i < newtextures) + { + texturetranslation[i] = i; + i++; + } +} + +static INT32 R_DefineTextures(INT32 i, UINT16 w) +{ + return Rloadtextures(i, w); +} + +static void R_FinishLoadingTextures(INT32 add) +{ + numtextures += add; + #ifdef HWRENDER if (rendermode == render_opengl) HWR_LoadTextures(numtextures); #endif } +// +// R_LoadTextures +// Initializes the texture list with the textures from the world map. +// +void R_LoadTextures(void) +{ + INT32 i, w; + INT32 newtextures = 0; + + for (w = 0; w < numwadfiles; w++) + { + newtextures += R_CountTextures((UINT16)w); + } + + // If no textures found by this point, bomb out + if (!newtextures) + I_Error("No textures detected in any WADs!\n"); + + R_AllocateTextures(newtextures); + + for (i = 0, w = 0; w < numwadfiles; w++) + { + i = R_DefineTextures(i, w); + } + + R_FinishLoadingTextures(newtextures); +} + +void R_LoadTexturesPwad(UINT16 wadnum) +{ + INT32 newtextures = R_CountTextures(wadnum); + + R_AllocateTextures(newtextures); + R_DefineTextures(numtextures, wadnum); + R_FinishLoadingTextures(newtextures); +} + static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) { char *texturesToken; @@ -796,6 +870,7 @@ static texture_t *R_ParseTexture(boolean 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); M_Memcpy(resultTexture->name, newTextureName, 8); + resultTexture->hash = quickncasehash(newTextureName, 8); resultTexture->width = newTextureWidth; resultTexture->height = newTextureHeight; } @@ -1574,19 +1649,22 @@ void R_ClearTextureNumCache(boolean btell) INT32 R_CheckTextureNumForName(const char *name) { INT32 i; + UINT32 hash; // "NoTexture" marker. if (name[0] == '-') return 0; + hash = quickncasehash(name, 8); + for (i = 0; i < tidcachelen; i++) - if (!strncasecmp(tidcache[i].name, name, 8)) + if (tidcache[i].hash == hash && !strncasecmp(tidcache[i].name, name, 8)) return tidcache[i].id; // Need to parse the list backwards, so textures loaded more recently are used in lieu of ones loaded earlier //for (i = 0; i < numtextures; i++) <- old for (i = (numtextures - 1); i >= 0; i--) // <- new - if (!strncasecmp(textures[i]->name, name, 8)) + if (textures[i]->hash == hash && !strncasecmp(textures[i]->name, name, 8)) { tidcachelen++; Z_Realloc(tidcache, tidcachelen * sizeof(*tidcache), PU_STATIC, &tidcache); @@ -1595,6 +1673,7 @@ INT32 R_CheckTextureNumForName(const char *name) #ifndef ZDEBUG CONS_Debug(DBG_SETUP, "texture #%s: %s\n", sizeu1(tidcachelen), tidcache[tidcachelen-1].name); #endif + tidcache[tidcachelen-1].hash = hash; tidcache[tidcachelen-1].id = i; return i; } diff --git a/src/r_data.h b/src/r_data.h index ec1146322..102bb5314 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -40,6 +40,7 @@ typedef struct { // Keep name for switch changing, etc. char name[8]; + UINT32 hash; INT16 width, height; boolean holes; @@ -63,6 +64,7 @@ extern CV_PossibleValue_t Color_cons_t[]; // Load TEXTURE1/TEXTURE2/PNAMES definitions, create lookup tables void R_LoadTextures(void); +void R_LoadTexturesPwad(UINT16 wadnum); void R_FlushTextureCache(void); INT32 R_GetTextureNum(INT32 texnum); diff --git a/src/w_wad.c b/src/w_wad.c index 86536c03f..2a52c4dd3 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -371,6 +371,7 @@ static lumpinfo_t* ResGetLumpsStandalone (FILE* handle, UINT16* numlumps, const lumpinfo->size = ftell(handle); fseek(handle, 0, SEEK_SET); strlcpy(lumpinfo->name, lumpname, 9); + lumpinfo->hash = quickncasehash(lumpname, 8); // Allocate the lump's full and long name. lumpinfo->fullname = Z_StrDup(lumpname); @@ -462,6 +463,7 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen lump_p->compression = CM_NOCOMPRESSION; memset(lump_p->name, 0x00, 9); strncpy(lump_p->name, fileinfo->name, 8); + lump_p->hash = quickncasehash(lump_p->name, 8); // Allocate the lump's long name. lump_p->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); @@ -636,6 +638,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? strncpy(lump_p->name, trimname, min(8, dotpos - trimname)); + lump_p->hash = quickncasehash(lump_p->name, 8); lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL); strlcpy(lump_p->longname, trimname, dotpos - trimname + 1); @@ -953,6 +956,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { UINT16 i; static char uname[9]; + UINT32 hash; if (!TestValidLump(wad,0)) return INT16_MAX; @@ -960,6 +964,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) memset(uname, 0, sizeof uname); strncpy(uname, name, sizeof(uname)-1); strupr(uname); + hash = quickncasehash(uname, 8); // // scan forward @@ -970,7 +975,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) - if (memcmp(lump_p->name, uname, sizeof(uname) - 1) == 0) + if (lump_p->hash == hash && memcmp(lump_p->name, uname, sizeof(uname) - 1) == 0) return i; } @@ -1178,15 +1183,20 @@ lumpnum_t W_CheckNumForLongName(const char *name) // TODO: Make it search through cache first, maybe...? lumpnum_t W_CheckNumForMap(const char *name) { + UINT32 hash = quickncasehash(name, 8); UINT16 lumpNum, end; UINT32 i; + lumpinfo_t *p; for (i = numwadfiles - 1; i < numwadfiles; i--) { if (wadfiles[i]->type == RET_WAD) { for (lumpNum = 0; lumpNum < wadfiles[i]->numlumps; lumpNum++) - if (!strncmp(name, (wadfiles[i]->lumpinfo + lumpNum)->name, 8)) + { + p = wadfiles[i]->lumpinfo + lumpNum; + if (p->hash == hash && !strncmp(name, p->name, 8)) return (i<<16) + lumpNum; + } } else if (wadfiles[i]->type == RET_PK3) { @@ -1197,12 +1207,11 @@ lumpnum_t W_CheckNumForMap(const char *name) continue; // Now look for the specified map. for (; lumpNum < end; lumpNum++) - if (!strnicmp(name, (wadfiles[i]->lumpinfo + lumpNum)->name, 8)) - { - const char *extension = strrchr(wadfiles[i]->lumpinfo[lumpNum].fullname, '.'); - if (!(extension && stricmp(extension, ".wad"))) - return (i<<16) + lumpNum; - } + { + p = wadfiles[i]->lumpinfo + lumpNum; + if (p->hash == hash && !strnicmp(name, p->name, 8)) + return (i<<16) + lumpNum; + } } } return LUMPERROR; diff --git a/src/w_wad.h b/src/w_wad.h index 84ce9775e..c0f47708e 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -69,6 +69,7 @@ typedef struct unsigned long position; // filelump_t filepos unsigned long disksize; // filelump_t size char name[9]; // filelump_t name[] e.g. "LongEntr" + UINT32 hash; char *longname; // e.g. "LongEntryName" char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension" size_t size; // real (uncompressed) size -- 2.54.0 From 54ee3f2961c746ee9b31934e5ce9b463a9a8bdc3 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 26 Mar 2024 20:40:11 +0300 Subject: [PATCH 03/59] R_LoadTexturesPwad: don't do anything wad has no textures --- src/r_data.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/r_data.c b/src/r_data.c index 17b5fb743..179c88492 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -627,6 +627,9 @@ void R_LoadTexturesPwad(UINT16 wadnum) { INT32 newtextures = R_CountTextures(wadnum); + if (!newtextures) + return; + R_AllocateTextures(newtextures); R_DefineTextures(numtextures, wadnum); R_FinishLoadingTextures(newtextures); -- 2.54.0 From 200d971d35789c1114a671c13c49ebff8d854b47 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:05:48 +0100 Subject: [PATCH 04/59] Toggle to render to screenFBO fixes downsampling from higher resolutions TODO: make this activate automatically if game detects it runs at higher res than desktop res --- src/hardware/hw_defs.h | 1 + src/hardware/hw_main.c | 13 ++ src/hardware/hw_main.h | 1 + src/hardware/r_opengl/r_opengl.c | 213 +++++++++++++++++++++++++++++-- src/hardware/r_opengl/r_opengl.h | 12 ++ src/i_video.h | 2 + src/sdl/i_video.c | 7 + src/sdl/ogl_sdl.c | 44 ++++++- 8 files changed, 278 insertions(+), 15 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index b7c46b2e1..83bb70fde 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -277,6 +277,7 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { + HWD_SET_FRAMEBUFFER, HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 131775c53..3634d1e9d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,6 +69,7 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== +static void CV_grframebuffer_OnChange(void); static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -96,6 +97,8 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_fofzfightfix = {"fofzfightfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -161,6 +164,13 @@ consvar_t cv_grhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL, #define ONLY_IF_GL_LOADED if (vid.glstate != VID_GL_LIBRARY_LOADED) return; +static void CV_grframebuffer_OnChange(void) +{ + ONLY_IF_GL_LOADED + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); + RefreshSDLSurface(); +} + static void CV_filtermode_ONChange(void) { ONLY_IF_GL_LOADED @@ -5936,6 +5946,7 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { + CV_RegisterVar(&cv_grframebuffer); CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -5998,6 +6009,8 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); + + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 3530c2915..4a9b1d434 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -154,6 +154,7 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; +extern consvar_t cv_grframebuffer; extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9fcf90a62..78b34c63f 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -114,6 +114,11 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; +static boolean GLFramebuffer_IsFuncAvailible(void); + + +GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; +GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -426,12 +431,32 @@ typedef void (APIENTRY * PFNglCopyTexImage2D) (GLenum target, GLint level, GLenu static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; -#endif /* 3.0 functions */ -#ifdef GL_VERSION_3_0 typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); static PFNglGenerateMipmap pglGenerateMipmap; + +/* 3.0 functions for framebuffers and renderbuffers */ +typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); +static PFNglGenFramebuffers pglGenFramebuffers; +typedef void (APIENTRY * PFNglBindFramebuffer) (GLenum target, GLuint framebuffer); +static PFNglBindFramebuffer pglBindFramebuffer; +typedef void (APIENTRY * PFNglDeleteFramebuffers) (GLsizei n, GLuint *ids); +static PFNglDeleteFramebuffers pglDeleteFramebuffers; +typedef void (APIENTRY * PFNglFramebufferTexture2D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +static PFNglFramebufferTexture2D pglFramebufferTexture2D; +typedef GLenum (APIENTRY * PFNglCheckFramebufferStatus) (GLenum target); +static PFNglCheckFramebufferStatus pglCheckFramebufferStatus; +typedef void (APIENTRY * PFNglGenRenderbuffers) (GLsizei n, GLuint *renderbuffers); +static PFNglGenRenderbuffers pglGenRenderbuffers; +typedef void (APIENTRY * PFNglBindRenderbuffer) (GLenum target, GLuint renderbuffer); +static PFNglBindRenderbuffer pglBindRenderbuffer; +typedef void (APIENTRY * PFNglDeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers); +static PFNglDeleteRenderbuffers pglDeleteRenderbuffers; +typedef void (APIENTRY * PFNglRenderbufferStorage) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +static PFNglRenderbufferStorage pglRenderbufferStorage; +typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); +static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; #endif /* 1.2 functions for 3D textures */ @@ -717,9 +742,28 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); -#ifdef GL_VERSION_3_0 pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); -#endif + + if (GLFramebuffer_IsFuncAvailible()) + { + pglGenFramebuffers = GetGLFunc("glGenFramebuffers"); + pglBindFramebuffer = GetGLFunc("glBindFramebuffer"); + pglDeleteFramebuffers = GetGLFunc("glDeleteFramebuffers"); + pglFramebufferTexture2D = GetGLFunc("glFramebufferTexture2D"); + pglCheckFramebufferStatus = GetGLFunc("glCheckFramebufferStatus"); + pglGenRenderbuffers = GetGLFunc("glGenRenderbuffers"); + pglBindRenderbuffer = GetGLFunc("glBindRenderbuffer"); + pglDeleteRenderbuffers = GetGLFunc("glDeleteRenderbuffers"); + pglRenderbufferStorage = GetGLFunc("glRenderbufferStorage"); + pglFramebufferRenderbuffer = GetGLFunc("glFramebufferRenderbuffer"); + } +} + +static boolean GLFramebuffer_IsFuncAvailible(void) +{ + return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && + (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && + (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } EXPORT boolean HWRAPI(InitShaders) (void) @@ -897,13 +941,6 @@ void SetModelView(GLint w, GLint h) { //GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); - // The screen textures need to be flushed if the width or height change so that they be remade for the correct size - if (screen_width != w || screen_height != h) - FlushScreenTextures(); - - screen_width = w; - screen_height = h; - pglViewport(0, 0, w, h); pglMatrixMode(GL_PROJECTION); @@ -935,7 +972,7 @@ void SetStates(void) pglEnable(GL_STENCIL_TEST); pglEnable(GL_DEPTH_TEST); // check the depth buffer - pglDepthMask(GL_TRUE); // enable writing to depth buffer + pglDepthMask(GL_TRUE); // enable writing to depth buffer pglClearDepth(1.0f); pglDepthRange(0.0f, 1.0f); pglDepthFunc(GL_LEQUAL); @@ -955,6 +992,151 @@ void SetStates(void) pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) } +void GLFramebuffer_Generate(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Generate the framebuffer + if (FramebufferObject == 0) + pglGenFramebuffers(1, &FramebufferObject); + + if (pglCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) + GLFramebuffer_GenerateAttachments(); +} + +void GLFramebuffer_Delete(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Unbind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, 0); + + if (FramebufferObject) + pglDeleteFramebuffers(1, &FramebufferObject); + + GLFramebuffer_DeleteAttachments(); + FramebufferObject = 0; +} + +void GLFramebuffer_GenerateAttachments(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Bind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject); + + // Generate the framebuffer texture + if (FramebufferTexture == 0) + { + pglGenTextures(1, &FramebufferTexture); + pglBindTexture(GL_TEXTURE_2D, FramebufferTexture); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_width, screen_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + pglBindTexture(GL_TEXTURE_2D, 0); + + // Attach the framebuffer texture to the framebuffer + pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FramebufferTexture, 0); + } + + // Generate the renderbuffer + if (RenderbufferObject == 0) + { + pglGenRenderbuffers(1, &RenderbufferObject); + + pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject); + pglRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, screen_width, screen_height); + pglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RenderbufferObject); + + // Clear the renderbuffer + ClearBuffer(true, true, true, NULL); + + pglBindRenderbuffer(GL_RENDERBUFFER, 0); + } + + // Unbind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, 0); +} + +void GLFramebuffer_DeleteAttachments(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + // Unbind the framebuffer + pglBindFramebuffer(GL_FRAMEBUFFER, 0); + + if (FramebufferTexture) + pglDeleteTextures(1, &FramebufferTexture); + + if (RenderbufferObject) + pglDeleteRenderbuffers(1, &RenderbufferObject); + + FramebufferTexture = 0; + RenderbufferObject = 0; +} + +void GLFramebuffer_Enable(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + if (FramebufferObject == 0) + GLFramebuffer_Generate(); + else if (FramebufferTexture == 0 || RenderbufferObject == 0) + GLFramebuffer_GenerateAttachments(); + + pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject); + pglBindRenderbuffer(GL_RENDERBUFFER, RenderbufferObject); +} + +void GLFramebuffer_Disable(void) +{ + if (!GLFramebuffer_IsFuncAvailible()) + return; + + pglBindFramebuffer(GL_FRAMEBUFFER, 0); + pglBindRenderbuffer(GL_RENDERBUFFER, 0); +} + +// -----------------+ +// DeleteTexture : Deletes a texture from the GPU and frees its data +// -----------------+ +EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) +{ + FTextureInfo *head = TexCacheHead; + + if (!pTexInfo) + return; + else if (pTexInfo->downloaded) + pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); + + while (head) + { + if (head->downloaded == pTexInfo->downloaded) + { + if (head->next) + head->next->prev = head->prev; + else // no next -> tail is being deleted -> update TexCacheTail + TexCacheTail = head->prev; + if (head->prev) + head->prev->next = head->next; + else // no prev -> head is being deleted -> update TexCacheHead + TexCacheHead = head->next; + free(head); + break; + } + + head = head->next; + } + + pTexInfo->downloaded = 0; +} + + // -----------------+ // Flush : flush OpenGL textures // : Clear list of downloaded mipmaps @@ -2140,6 +2322,13 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; + + case HWD_SET_FRAMEBUFFER: + FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; + + if (!GLFramebuffer_IsFuncAvailible()) + FrameBufferEnabled = GL_FALSE; + break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 34b2d3cf7..d8b2a12fc 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -104,6 +104,18 @@ static PFNglEnableClientState pglEnableClientState; #endif #endif +void GLFramebuffer_Generate(void); +void GLFramebuffer_Delete(void); + +void GLFramebuffer_GenerateAttachments(void); +void GLFramebuffer_DeleteAttachments(void); + +void GLFramebuffer_Enable(void); +void GLFramebuffer_Disable(void); + +extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; +extern GLboolean FrameBufferEnabled, RenderToFramebuffer; + // ========================================================================== // GLOBAL // ========================================================================== diff --git a/src/i_video.h b/src/i_video.h index 602522871..2f08e4b1f 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -137,4 +137,6 @@ void I_EndRead(void); UINT32 I_GetRefreshRate(void); +void RefreshSDLSurface(void); + #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a1dd8bef6..4591b6ad6 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -203,6 +203,13 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); +#ifdef HWRENDER +void RefreshSDLSurface(void) +{ + OglSdlSurface(vid.width, vid.height); +} +#endif + static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { static SDL_bool wasfullscreen = SDL_FALSE; diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 00e3896ed..71e7fcdab 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -163,11 +163,35 @@ boolean OglSdlSurface(INT32 w, INT32 h) granisotropicmode_cons_t[1].value = maximumAnisotropy; - SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); + if (cv_vidwait.value) + { + if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync + SDL_GL_SetSwapInterval(1); // normal vsync + } + else + SDL_GL_SetSwapInterval(0); + + //SDL_GL_SetSwapInterval(cv_vidwait.value ? -1 : 0); + + // The screen textures need to be flushed if the width or height change so that they be remade for the correct size + if (screen_width != w || screen_height != h) + { + FlushScreenTextures(); + GLFramebuffer_DeleteAttachments(); + } + + screen_width = (GLint)w; + screen_height = (GLint)h; SetModelView(w, h); SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); + + RenderToFramebuffer = FrameBufferEnabled; + GLFramebuffer_Disable(); + + if (RenderToFramebuffer) + GLFramebuffer_Enable(); HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -187,15 +211,29 @@ void OglSdlFinishUpdate(boolean waitvbl) int sdlw, sdlh; if (oldwaitvbl != waitvbl) { - SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); + if (waitvbl) + { + if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync + SDL_GL_SetSwapInterval(1); // normal vsync + } + else + SDL_GL_SetSwapInterval(0); + //SDL_GL_SetSwapInterval(waitvbl ? -1 : 0); } oldwaitvbl = waitvbl; SDL_GetWindowSize(window, &sdlw, &sdlh); - HWR_MakeScreenFinalTexture(); + + GLFramebuffer_Disable(); + RenderToFramebuffer = FrameBufferEnabled; + HWR_DrawScreenFinalTexture(sdlw, sdlh); + + if (RenderToFramebuffer) + GLFramebuffer_Enable(); + SDL_GL_SwapWindow(window); GClipRect(0, 0, realwidth, realheight, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); -- 2.54.0 From 91a3b288eff25ad58c1fcba29fec93f84d0374e9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:08:09 +0100 Subject: [PATCH 05/59] conflict moment --- src/hardware/r_opengl/r_opengl.c | 38 ++++---------------------------- src/sdl/ogl_sdl.c | 19 ++-------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 78b34c63f..d17c29e04 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -432,9 +432,11 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; +#ifdef GL_VERSION_3_0 /* 3.0 functions */ typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); static PFNglGenerateMipmap pglGenerateMipmap; +#endif /* 3.0 functions for framebuffers and renderbuffers */ typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); @@ -742,7 +744,9 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); +#ifdef GL_VERSION_3_0 pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); +#endif if (GLFramebuffer_IsFuncAvailible()) { @@ -1102,40 +1106,6 @@ void GLFramebuffer_Disable(void) pglBindRenderbuffer(GL_RENDERBUFFER, 0); } -// -----------------+ -// DeleteTexture : Deletes a texture from the GPU and frees its data -// -----------------+ -EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) -{ - FTextureInfo *head = TexCacheHead; - - if (!pTexInfo) - return; - else if (pTexInfo->downloaded) - pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); - - while (head) - { - if (head->downloaded == pTexInfo->downloaded) - { - if (head->next) - head->next->prev = head->prev; - else // no next -> tail is being deleted -> update TexCacheTail - TexCacheTail = head->prev; - if (head->prev) - head->prev->next = head->next; - else // no prev -> head is being deleted -> update TexCacheHead - TexCacheHead = head->next; - free(head); - break; - } - - head = head->next; - } - - pTexInfo->downloaded = 0; -} - // -----------------+ // Flush : flush OpenGL textures diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 71e7fcdab..06fb5df27 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -162,16 +162,8 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; - - if (cv_vidwait.value) - { - if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync - SDL_GL_SetSwapInterval(1); // normal vsync - } - else - SDL_GL_SetSwapInterval(0); - //SDL_GL_SetSwapInterval(cv_vidwait.value ? -1 : 0); + SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) @@ -211,14 +203,7 @@ void OglSdlFinishUpdate(boolean waitvbl) int sdlw, sdlh; if (oldwaitvbl != waitvbl) { - if (waitvbl) - { - if (SDL_GL_SetSwapInterval(-1) != 0) // try async vsync - SDL_GL_SetSwapInterval(1); // normal vsync - } - else - SDL_GL_SetSwapInterval(0); - //SDL_GL_SetSwapInterval(waitvbl ? -1 : 0); + SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); } oldwaitvbl = waitvbl; -- 2.54.0 From a28f025d401e92505a470e441940f293d8a6cfe1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:33:29 +0100 Subject: [PATCH 06/59] Stuff from displaycrap branch to detect downsampling automatically --- src/i_video.h | 2 ++ src/sdl/i_video.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++- src/sdl/ogl_sdl.c | 29 ++++++++-------- 3 files changed, 104 insertions(+), 15 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 2f08e4b1f..098d65cf6 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,4 +139,6 @@ UINT32 I_GetRefreshRate(void); void RefreshSDLSurface(void); +extern boolean downsample; + #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 4591b6ad6..031842874 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -159,6 +159,11 @@ static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; +static boolean displayinit = false; +static int currentDisplayIndex = -1; +static int previousDisplayIndex = -1; +static int numDisplays = -1; + // SDL2 vars SDL_Window *window; SDL_Renderer *renderer; @@ -166,6 +171,12 @@ static SDL_Texture *texture; static SDL_bool havefocus = SDL_TRUE; static const char *fallback_resolution_name = "Fallback"; +static void ScaleQuality_OnChange(void) +{ + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, cv_scalequality.string); + COM_ImmedExecute(va("vid_mode %d", vid.modenum)); // Hack to make it apply without restarting +} + // windowed video modes from which to choose from. static INT32 windowedModes[MAXWINMODES][2] = { @@ -203,7 +214,8 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); -#ifdef HWRENDER +boolean downsample = false; + void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); @@ -769,11 +781,23 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +static void SDL_CheckDisplays(void) +{ + if (!displayinit) + { + numDisplays = SDL_GetNumVideoDisplays(); + displayinit = true; + } + + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); +} + static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; + static SDL_bool windowmoved = SDL_FALSE; switch (evt.event) { @@ -793,6 +817,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; + case SDL_WINDOWEVENT_MOVED: + windowmoved = SDL_TRUE; + break; } if (mousefocus && kbfocus) @@ -832,6 +859,43 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } } + if (windowmoved) + { + SDL_CheckDisplays(); + if (numDisplays > 1) + { + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + if (currentDisplayIndex != previousDisplayIndex) + { + for (int i = 0; i < numDisplays; ++i) + { + if (currentDisplayIndex == i) + { + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + { + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + + if (cv_fullscreen.value == 2) //exclusive + SDLSetMode(curmode.w, curmode.h, true); + else if (cv_fullscreen.value == 1) //borderless sdl thing + SDLSetMode(vid.width, vid.height, true); + else //windowed mode + SDLSetMode(vid.width, vid.height, false); + } + break; // found our current display break outta here + } + } + previousDisplayIndex = currentDisplayIndex; + } + } + } } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) @@ -1908,6 +1972,25 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); + for (int i = 0; i < numDisplays; ++i) + { + if (currentDisplayIndex == i) + { + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + { + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + } + break; // found our current display break outta here + } + } + SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); @@ -2318,6 +2401,9 @@ void I_StartupGraphics(void) // Fury: we do window initialization after GL setup to allow // SDL_GL_LoadLibrary to work well on Windows + //check for display things + SDL_CheckDisplays(); + // Create window //Impl_CreateWindow(USE_FULLSCREEN); //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 06fb5df27..719bd48d1 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -42,6 +42,7 @@ #include "../i_system.h" #include "hwsym_sdl.h" #include "../m_argv.h" +#include "../i_video.h" #ifdef DEBUG_TO_FILE #include @@ -149,22 +150,22 @@ boolean OglSdlSurface(INT32 w, INT32 h) "- GPU vendor has dropped OpenGL support on your GPU and OS. (Old GPU?)\n" "- GPU drivers are missing or broken. You may need to update your drivers."); } + + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) + pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); + else + maximumAnisotropy = 1; + + SetupGLInfo(); + + SetupGLFunc4(); + + granisotropicmode_cons_t[1].value = maximumAnisotropy; } first_init = true; - if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) - pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); - else - maximumAnisotropy = 1; - - SetupGLInfo(); - - SetupGLFunc4(); - - granisotropicmode_cons_t[1].value = maximumAnisotropy; - SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); - + // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) { @@ -182,7 +183,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); - if (RenderToFramebuffer) + if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); HWR_Startup(); @@ -216,7 +217,7 @@ void OglSdlFinishUpdate(boolean waitvbl) HWR_DrawScreenFinalTexture(sdlw, sdlh); - if (RenderToFramebuffer) + if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); SDL_GL_SwapWindow(window); -- 2.54.0 From c7a258f32ff075f1cc86e3ad582b58cce5402b93 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:34:58 +0100 Subject: [PATCH 07/59] clean up --- src/sdl/i_video.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 031842874..f62195ebc 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -171,12 +171,6 @@ static SDL_Texture *texture; static SDL_bool havefocus = SDL_TRUE; static const char *fallback_resolution_name = "Fallback"; -static void ScaleQuality_OnChange(void) -{ - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, cv_scalequality.string); - COM_ImmedExecute(va("vid_mode %d", vid.modenum)); // Hack to make it apply without restarting -} - // windowed video modes from which to choose from. static INT32 windowedModes[MAXWINMODES][2] = { @@ -216,6 +210,7 @@ static void Impl_SetWindowIcon(void); boolean downsample = false; +#ifdef HWRENDER void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); @@ -881,13 +876,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } else downsample = false; - - if (cv_fullscreen.value == 2) //exclusive - SDLSetMode(curmode.w, curmode.h, true); - else if (cv_fullscreen.value == 1) //borderless sdl thing - SDLSetMode(vid.width, vid.height, true); - else //windowed mode - SDLSetMode(vid.width, vid.height, false); } break; // found our current display break outta here } -- 2.54.0 From 23cc0dfc3a37639bd1379759da2652d58f10af78 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:44:32 +0100 Subject: [PATCH 08/59] add some comments cause i WILL forger what this crap even does --- src/sdl/i_video.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f62195ebc..6476e3276 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -778,13 +778,13 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) static void SDL_CheckDisplays(void) { - if (!displayinit) + if (!displayinit) // only do this once, dont think someone ever unplugs or adds a new display during gaming lul { - numDisplays = SDL_GetNumVideoDisplays(); + numDisplays = SDL_GetNumVideoDisplays(); // get all available displays displayinit = true; } - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // this is the current display our game window resides in } static void Impl_HandleWindowEvent(SDL_WindowEvent evt) @@ -859,15 +859,15 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) SDL_CheckDisplays(); if (numDisplays > 1) { - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - if (currentDisplayIndex != previousDisplayIndex) + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // check the display index + if (currentDisplayIndex != previousDisplayIndex) // did the display change from previous index entry? { - for (int i = 0; i < numDisplays; ++i) + for (int i = 0; i < numDisplays; ++i) // go through all detected displays { - if (currentDisplayIndex == i) + if (currentDisplayIndex == i) // found our current display? { SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get info for the current display { if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { @@ -880,7 +880,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; // found our current display break outta here } } - previousDisplayIndex = currentDisplayIndex; + previousDisplayIndex = currentDisplayIndex; // set current display to index } } } @@ -1960,17 +1960,17 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - for (int i = 0; i < numDisplays; ++i) + for (int i = 0; i < numDisplays; ++i) // go through all displays again { - if (currentDisplayIndex == i) + if (currentDisplayIndex == i) // find the current display { SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get the info on current display { if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { downsample = true; - RefreshSDLSurface(); + RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break } else downsample = false; -- 2.54.0 From a779191febc3a967b44d602be45c8c68ce5a267a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 18:45:59 +0100 Subject: [PATCH 09/59] beter --- src/sdl/i_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6476e3276..8772f2da2 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1960,7 +1960,7 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - for (int i = 0; i < numDisplays; ++i) // go through all displays again + for (int i = 0; i < numDisplays; ++i) // go through all displays again cause our vidya mode changed { if (currentDisplayIndex == i) // find the current display { @@ -1975,7 +1975,7 @@ INT32 VID_SetMode(INT32 modeNum) else downsample = false; } - break; // found our current display break outta here + break; // did everything so done lul } } -- 2.54.0 From d7a1cc6702a3ebdd12c5b04d8888996a9cc4c92a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 21:31:45 +0100 Subject: [PATCH 10/59] Read only header bytes when creating textures list --- src/r_data.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index 179c88492..0900ed2c1 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -384,7 +384,7 @@ Rloadtextures (INT32 i, INT32 w) UINT16 j; INT32 k; UINT16 texstart, texend, texturesLumpPos; - patch_t *patchlump; + patch_t patchlump; texpatch_t *patch; texture_t *texture; @@ -422,8 +422,7 @@ Rloadtextures (INT32 i, INT32 w) if (W_IsLumpFolder(wadnum, lumpnum)) // Check if lump is a folder continue; // If it is then SKIP IT } - - patchlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); + W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, 8, 0); // #define PNG_HEADER_SIZE (8) //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); @@ -431,8 +430,8 @@ Rloadtextures (INT32 i, INT32 w) // Set texture properties. M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); texture->hash = quickncasehash(texture->name, 8); - texture->width = SHORT(patchlump->width); - texture->height = SHORT(patchlump->height); + texture->width = SHORT(patchlump.width); + texture->height = SHORT(patchlump.height); texture->patchcount = 1; texture->holes = false; @@ -443,8 +442,6 @@ Rloadtextures (INT32 i, INT32 w) patch->wad = (UINT16)w; patch->lump = texstart + j; - Z_Free(patchlump); - k = 1; while (k << 1 <= texture->width) k <<= 1; -- 2.54.0 From aac74cf93a106ab9352e58175796fdf9a3c3f551 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 6 Apr 2024 01:31:43 +0300 Subject: [PATCH 11/59] Don't call menu drawer in wipes on dedicated servers --- src/f_wipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/f_wipe.c b/src/f_wipe.c index 9909de0f0..da5b9dac1 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -383,7 +383,7 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu) I_OsPolling(); I_UpdateNoBlit(); - if (drawMenu) + if (rendermode != render_none && drawMenu) { #ifdef HAVE_THREADS I_lock_mutex(&m_menu_mutex); -- 2.54.0 From 40c356395a649816741d452dbf030b05d8f3e2b1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 07:02:03 +0200 Subject: [PATCH 12/59] simplify this crap --- src/sdl/i_video.c | 72 +++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 8772f2da2..a6605e701 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -159,10 +159,7 @@ static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; -static boolean displayinit = false; static int currentDisplayIndex = -1; -static int previousDisplayIndex = -1; -static int numDisplays = -1; // SDL2 vars SDL_Window *window; @@ -776,17 +773,6 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } -static void SDL_CheckDisplays(void) -{ - if (!displayinit) // only do this once, dont think someone ever unplugs or adds a new display during gaming lul - { - numDisplays = SDL_GetNumVideoDisplays(); // get all available displays - displayinit = true; - } - - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // this is the current display our game window resides in -} - static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; @@ -856,32 +842,23 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (windowmoved) { - SDL_CheckDisplays(); - if (numDisplays > 1) + if (cv_grframebuffer.value) { - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // check the display index - if (currentDisplayIndex != previousDisplayIndex) // did the display change from previous index entry? + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - for (int i = 0; i < numDisplays; ++i) // go through all detected displays + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { - if (currentDisplayIndex == i) // found our current display? - { - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get info for the current display - { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); - } - else - downsample = false; - } - break; // found our current display break outta here - } + downsample = true; + RefreshSDLSurface(); } - previousDisplayIndex = currentDisplayIndex; // set current display to index + else + downsample = false; } + else + downsample = false; // couldnt get display info so turn the thing off } } } @@ -1960,23 +1937,21 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - for (int i = 0; i < numDisplays; ++i) // go through all displays again cause our vidya mode changed + if (cv_grframebuffer.value) { - if (currentDisplayIndex == i) // find the current display + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) // get the info on current display + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break - } - else - downsample = false; + downsample = true; + RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break } - break; // did everything so done lul + else + downsample = false; } + else + downsample = false; } SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); @@ -2389,9 +2364,6 @@ void I_StartupGraphics(void) // Fury: we do window initialization after GL setup to allow // SDL_GL_LoadLibrary to work well on Windows - //check for display things - SDL_CheckDisplays(); - // Create window //Impl_CreateWindow(USE_FULLSCREEN); //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); -- 2.54.0 From 955f73d9e80892a242c4484c98c2a5208a66f52e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:24:46 +0200 Subject: [PATCH 13/59] throw stuff into own function, also check on game start --- src/i_video.h | 2 ++ src/sdl/i_video.c | 67 ++++++++++++++++++++++------------------------- src/sdl/ogl_sdl.c | 2 ++ 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 098d65cf6..0c2bfc4e4 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,6 +139,8 @@ UINT32 I_GetRefreshRate(void); void RefreshSDLSurface(void); + +void I_DownSample(void); extern boolean downsample; #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a6605e701..a175a2534 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -159,8 +159,6 @@ static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; -static int currentDisplayIndex = -1; - // SDL2 vars SDL_Window *window; SDL_Renderer *renderer; @@ -773,6 +771,35 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +void I_DownSample(void) +{ + if (!cv_grframebuffer.value) + { + downsample = false; + return; + } + + int currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) + { + CONS_Printf(" Width: %d\n", curmode.w); + CONS_Printf(" Height: %d\n", curmode.h); + CONS_Printf(" Refresh Rate: %d Hz\n", curmode.refresh_rate); + CONS_Printf(" Display Index: %d\n", currentDisplayIndex); + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + } + else + downsample = false; // couldnt get display info so turn the thing off +} + static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; @@ -842,24 +869,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (windowmoved) { - if (cv_grframebuffer.value) - { - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) - { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); - } - else - downsample = false; - } - else - downsample = false; // couldnt get display info so turn the thing off - } + I_DownSample(); } } @@ -1937,22 +1947,7 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); - if (cv_grframebuffer.value) - { - SDL_DisplayMode curmode; - if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) - { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge - { - downsample = true; - RefreshSDLSurface(); // refresh crap so our fbo and screentextures dont break - } - else - downsample = false; - } - else - downsample = false; - } + I_DownSample(); SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 719bd48d1..ff37435c8 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -161,6 +161,8 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; + + I_DownSample(); } first_init = true; -- 2.54.0 From 64f10c36fa40ce98164eb419ee04555f118266c9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:29:08 +0200 Subject: [PATCH 14/59] should throw that into onchange oops --- src/sdl/i_video.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a175a2534..5772de21e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -208,6 +208,7 @@ boolean downsample = false; #ifdef HWRENDER void RefreshSDLSurface(void) { + I_DownSample(); OglSdlSurface(vid.width, vid.height); } #endif -- 2.54.0 From 94340e66342949d80370d71979839bb2c5e17726 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:32:06 +0200 Subject: [PATCH 15/59] forgor to remove those Zzz... --- src/sdl/i_video.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5772de21e..8a0ca0e51 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -785,10 +785,6 @@ void I_DownSample(void) SDL_DisplayMode curmode; if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - CONS_Printf(" Width: %d\n", curmode.w); - CONS_Printf(" Height: %d\n", curmode.h); - CONS_Printf(" Refresh Rate: %d Hz\n", curmode.refresh_rate); - CONS_Printf(" Display Index: %d\n", currentDisplayIndex); if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge { downsample = true; -- 2.54.0 From 1391e556d6e3c0e34f512d75744780812968542e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:40:35 +0200 Subject: [PATCH 16/59] that wasnt the onchange im sleepy --- src/hardware/hw_main.c | 1 + src/sdl/i_video.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3634d1e9d..b9b9ba6be 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -168,6 +168,7 @@ static void CV_grframebuffer_OnChange(void) { ONLY_IF_GL_LOADED HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); + I_DownSample(); RefreshSDLSurface(); } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 8a0ca0e51..62073fe78 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -208,7 +208,6 @@ boolean downsample = false; #ifdef HWRENDER void RefreshSDLSurface(void) { - I_DownSample(); OglSdlSurface(vid.width, vid.height); } #endif @@ -781,8 +780,8 @@ void I_DownSample(void) } int currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge -- 2.54.0 From 1df6c4d4da7e2f2a70d2078d1329a44646bc455c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:47:37 +0200 Subject: [PATCH 17/59] move this to first init too --- src/sdl/ogl_sdl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index a65a708ee..1d30da827 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -150,7 +150,12 @@ boolean OglSdlSurface(INT32 w, INT32 h) "- GPU vendor has dropped OpenGL support on your GPU and OS. (Old GPU?)\n" "- GPU drivers are missing or broken. You may need to update your drivers."); } - + + if (majorGL == 1 && minorGL <= 3) // GL_GENERATE_MIPMAP is unavailible for OGL 1.3 and below + supportMipMap = false; + else + supportMipMap = true; + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); else @@ -175,11 +180,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) GLFramebuffer_DeleteAttachments(); } - if (majorGL == 1 && minorGL <= 3) // GL_GENERATE_MIPMAP is unavailible for OGL 1.3 and below - supportMipMap = false; - else - supportMipMap = true; - screen_width = (GLint)w; screen_height = (GLint)h; -- 2.54.0 From 6a3987c8f786862fdb5569bd405806c29c8789c5 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 17:57:55 +0200 Subject: [PATCH 18/59] fix ifdefs --- src/hardware/hw_defs.h | 2 ++ src/hardware/hw_main.c | 28 +++++++++++++++++++--------- src/hardware/hw_main.h | 2 ++ src/hardware/r_opengl/r_opengl.c | 15 ++++++++++----- src/hardware/r_opengl/r_opengl.h | 2 ++ src/i_video.h | 4 ++++ src/sdl/i_video.c | 25 +++++++++++++++++++++++-- src/sdl/ogl_sdl.c | 18 ++++++++++++++---- 8 files changed, 76 insertions(+), 20 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 85b6b58a2..e57bbb0af 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -287,7 +287,9 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { +#ifdef GL_VERSION_3_0 HWD_SET_FRAMEBUFFER, +#endif HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ebd8c417d..4acdaf61c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,7 +69,9 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== +#ifdef GL_VERSION_3_0 static void CV_grframebuffer_OnChange(void); +#endif static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -97,7 +99,9 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +#ifdef GL_VERSION_3_0 consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -165,14 +169,6 @@ consvar_t cv_grhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL, #define ONLY_IF_GL_LOADED if (vid.glstate != VID_GL_LIBRARY_LOADED) return; -static void CV_grframebuffer_OnChange(void) -{ - ONLY_IF_GL_LOADED - HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); - I_DownSample(); - RefreshSDLSurface(); -} - static void CV_filtermode_ONChange(void) { ONLY_IF_GL_LOADED @@ -219,6 +215,16 @@ static void CV_grpalettedepth_OnChange(void) HWR_SetPalette(pLocalPalette); } +#ifdef GL_VERSION_3_0 +static void CV_grframebuffer_OnChange(void) +{ + ONLY_IF_GL_LOADED + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); + I_DownSample(); + RefreshSDLSurface(); +} +#endif + // // Sets the shader state. // @@ -5947,7 +5953,9 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { +#ifdef GL_VERSION_3_0 CV_RegisterVar(&cv_grframebuffer); +#endif CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -6010,8 +6018,10 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); - + +#ifdef GL_VERSION_3_0 HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); +#endif if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 8cc80a34e..0c1b6a958 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -152,7 +152,9 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; +#ifdef GL_VERSION_3_0 extern consvar_t cv_grframebuffer; +#endif extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 8811be798..872d50c4e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -119,11 +119,12 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; +#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void); - GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; +#endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -457,6 +458,7 @@ static PFNglRenderbufferStorage pglRenderbufferStorage; typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; #endif +#endif //!STATIC_OPENGL /* 1.2 functions for 3D textures */ typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); @@ -740,6 +742,7 @@ void SetupGLFunc4(void) pglUniform2fv = GetGLFunc("glUniform2fv"); pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); + #ifdef GL_VERSION_3_0 if (GLFramebuffer_IsFuncAvailible()) { @@ -757,12 +760,14 @@ void SetupGLFunc4(void) #endif } +#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void) { return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } +#endif EXPORT boolean HWRAPI(InitShaders) (void) { @@ -1023,7 +1028,7 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) pTexInfo->downloaded = 0; } - +#ifdef GL_VERSION_3_0 void GLFramebuffer_Generate(void) { if (!GLFramebuffer_IsFuncAvailible()) @@ -1133,7 +1138,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } - +#endif // -----------------+ // Flush : flush OpenGL textures @@ -2310,14 +2315,14 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; - +#ifdef GL_VERSION_3_0 case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; if (!GLFramebuffer_IsFuncAvailible()) FrameBufferEnabled = GL_FALSE; break; - +#endif case HWD_SET_TEXTUREFILTERMODE: switch (Value) { diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index c481e7abd..303f95301 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -104,6 +104,7 @@ static PFNglEnableClientState pglEnableClientState; #endif #endif +#ifdef GL_VERSION_3_0 void GLFramebuffer_Generate(void); void GLFramebuffer_Delete(void); @@ -115,6 +116,7 @@ void GLFramebuffer_Disable(void); extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; extern GLboolean FrameBufferEnabled, RenderToFramebuffer; +#endif // ========================================================================== // GLOBAL diff --git a/src/i_video.h b/src/i_video.h index e81922bc8..8f9eaae38 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,8 +139,12 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 void RefreshSDLSurface(void); void I_DownSample(void); extern boolean downsample; +#endif +#endif #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 774e75f23..f58cfcac7 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -215,14 +215,15 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); -boolean downsample = false; - #ifdef HWRENDER +#ifdef GL_VERSION_3_0 +boolean downsample = false; void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); } #endif +#endif static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { @@ -745,6 +746,8 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 void I_DownSample(void) { if (!cv_grframebuffer.value) @@ -769,13 +772,19 @@ void I_DownSample(void) else downsample = false; // couldnt get display info so turn the thing off } +#endif +#endif static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 static SDL_bool windowmoved = SDL_FALSE; +#endif +#endif switch (evt.event) { @@ -795,9 +804,13 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 case SDL_WINDOWEVENT_MOVED: windowmoved = SDL_TRUE; break; +#endif +#endif } if (mousefocus && kbfocus) @@ -837,10 +850,14 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } } +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 if (windowmoved) { I_DownSample(); } +#endif +#endif } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) @@ -1919,7 +1936,11 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); +#ifdef HWRENDER +#ifdef GL_VERSION_3_0 I_DownSample(); +#endif +#endif SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 1d30da827..45ae7d135 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -166,8 +166,10 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; - + +#ifdef GL_VERSION_3_0 I_DownSample(); +#endif } first_init = true; @@ -177,7 +179,9 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (screen_width != w || screen_height != h) { FlushScreenTextures(); +#ifdef GL_VERSION_3_0 GLFramebuffer_DeleteAttachments(); +#endif } screen_width = (GLint)w; @@ -186,12 +190,14 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetModelView(w, h); SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); - + +#ifdef GL_VERSION_3_0 RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -218,14 +224,18 @@ void OglSdlFinishUpdate(boolean waitvbl) SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); - + +#ifdef GL_VERSION_3_0 GLFramebuffer_Disable(); RenderToFramebuffer = FrameBufferEnabled; +#endif HWR_DrawScreenFinalTexture(sdlw, sdlh); - + +#ifdef GL_VERSION_3_0 if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif SDL_GL_SwapWindow(window); -- 2.54.0 From 4a1523da573bb1fb8daca0051c79f87c8a206904 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 18:15:29 +0200 Subject: [PATCH 19/59] Zzz... --- src/i_video.h | 2 -- src/sdl/i_video.c | 12 ------------ 2 files changed, 14 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 8f9eaae38..76a06be91 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -140,11 +140,9 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); #ifdef HWRENDER -#ifdef GL_VERSION_3_0 void RefreshSDLSurface(void); void I_DownSample(void); extern boolean downsample; #endif -#endif #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f58cfcac7..c415a063a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -216,14 +216,12 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static void Impl_SetWindowIcon(void); #ifdef HWRENDER -#ifdef GL_VERSION_3_0 boolean downsample = false; void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); } #endif -#endif static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { @@ -747,7 +745,6 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) } #ifdef HWRENDER -#ifdef GL_VERSION_3_0 void I_DownSample(void) { if (!cv_grframebuffer.value) @@ -773,7 +770,6 @@ void I_DownSample(void) downsample = false; // couldnt get display info so turn the thing off } #endif -#endif static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { @@ -781,9 +777,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; #ifdef HWRENDER -#ifdef GL_VERSION_3_0 static SDL_bool windowmoved = SDL_FALSE; -#endif #endif switch (evt.event) @@ -805,11 +799,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) case SDL_WINDOWEVENT_MAXIMIZED: break; #ifdef HWRENDER -#ifdef GL_VERSION_3_0 case SDL_WINDOWEVENT_MOVED: windowmoved = SDL_TRUE; break; -#endif #endif } @@ -851,13 +843,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } #ifdef HWRENDER -#ifdef GL_VERSION_3_0 if (windowmoved) { I_DownSample(); } #endif -#endif } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) @@ -1937,9 +1927,7 @@ INT32 VID_SetMode(INT32 modeNum) //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); #ifdef HWRENDER -#ifdef GL_VERSION_3_0 I_DownSample(); -#endif #endif SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); -- 2.54.0 From 9e104a8632ecdafbe687a0734b7dce91867d4e01 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Apr 2024 18:18:47 +0200 Subject: [PATCH 20/59] ok dont use this at all then --- src/hardware/hw_defs.h | 2 -- src/hardware/hw_main.c | 12 +----------- src/hardware/hw_main.h | 2 -- src/hardware/r_opengl/r_opengl.c | 12 ------------ src/sdl/ogl_sdl.c | 10 ---------- 5 files changed, 1 insertion(+), 37 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index e57bbb0af..85b6b58a2 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -287,9 +287,7 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { -#ifdef GL_VERSION_3_0 HWD_SET_FRAMEBUFFER, -#endif HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4acdaf61c..b1a960870 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,9 +69,7 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== -#ifdef GL_VERSION_3_0 static void CV_grframebuffer_OnChange(void); -#endif static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -99,9 +97,7 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -#ifdef GL_VERSION_3_0 consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; -#endif consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -215,7 +211,6 @@ static void CV_grpalettedepth_OnChange(void) HWR_SetPalette(pLocalPalette); } -#ifdef GL_VERSION_3_0 static void CV_grframebuffer_OnChange(void) { ONLY_IF_GL_LOADED @@ -223,7 +218,6 @@ static void CV_grframebuffer_OnChange(void) I_DownSample(); RefreshSDLSurface(); } -#endif // // Sets the shader state. @@ -5953,9 +5947,7 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { -#ifdef GL_VERSION_3_0 CV_RegisterVar(&cv_grframebuffer); -#endif CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -6018,10 +6010,8 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); - -#ifdef GL_VERSION_3_0 + HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); -#endif if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 0c1b6a958..8cc80a34e 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -152,9 +152,7 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; -#ifdef GL_VERSION_3_0 extern consvar_t cv_grframebuffer; -#endif extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 872d50c4e..85ca35641 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -119,12 +119,10 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; -#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void); GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; -#endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -435,7 +433,6 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; -#ifdef GL_VERSION_3_0 /* 3.0 functions for framebuffers and renderbuffers */ typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); static PFNglGenFramebuffers pglGenFramebuffers; @@ -457,7 +454,6 @@ typedef void (APIENTRY * PFNglRenderbufferStorage) (GLenum target, GLenum intern static PFNglRenderbufferStorage pglRenderbufferStorage; typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; -#endif #endif //!STATIC_OPENGL /* 1.2 functions for 3D textures */ @@ -743,7 +739,6 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); -#ifdef GL_VERSION_3_0 if (GLFramebuffer_IsFuncAvailible()) { pglGenFramebuffers = GetGLFunc("glGenFramebuffers"); @@ -757,17 +752,14 @@ void SetupGLFunc4(void) pglRenderbufferStorage = GetGLFunc("glRenderbufferStorage"); pglFramebufferRenderbuffer = GetGLFunc("glFramebufferRenderbuffer"); } -#endif } -#ifdef GL_VERSION_3_0 static boolean GLFramebuffer_IsFuncAvailible(void) { return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } -#endif EXPORT boolean HWRAPI(InitShaders) (void) { @@ -1028,7 +1020,6 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) pTexInfo->downloaded = 0; } -#ifdef GL_VERSION_3_0 void GLFramebuffer_Generate(void) { if (!GLFramebuffer_IsFuncAvailible()) @@ -1138,7 +1129,6 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } -#endif // -----------------+ // Flush : flush OpenGL textures @@ -2315,14 +2305,12 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; -#ifdef GL_VERSION_3_0 case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; if (!GLFramebuffer_IsFuncAvailible()) FrameBufferEnabled = GL_FALSE; break; -#endif case HWD_SET_TEXTUREFILTERMODE: switch (Value) { diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 45ae7d135..dc8b479e7 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -167,9 +167,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) granisotropicmode_cons_t[1].value = maximumAnisotropy; -#ifdef GL_VERSION_3_0 I_DownSample(); -#endif } first_init = true; @@ -179,9 +177,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (screen_width != w || screen_height != h) { FlushScreenTextures(); -#ifdef GL_VERSION_3_0 GLFramebuffer_DeleteAttachments(); -#endif } screen_width = (GLint)w; @@ -191,13 +187,11 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); -#ifdef GL_VERSION_3_0 RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); -#endif HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -225,17 +219,13 @@ void OglSdlFinishUpdate(boolean waitvbl) SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); -#ifdef GL_VERSION_3_0 GLFramebuffer_Disable(); RenderToFramebuffer = FrameBufferEnabled; -#endif HWR_DrawScreenFinalTexture(sdlw, sdlh); -#ifdef GL_VERSION_3_0 if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); -#endif SDL_GL_SwapWindow(window); -- 2.54.0 From af265d017d761d3b23a4ae7b5f913d623399c463 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Apr 2024 18:55:55 +0300 Subject: [PATCH 21/59] Fix potential negative array index in V_ThinStringWidth --- src/v_video.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/v_video.c b/src/v_video.c index c56711f20..7b9383f06 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2944,6 +2944,9 @@ INT32 V_ThinStringWidth(const char *string, INT32 option) if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 continue; + if (c < HU_FONTSTART) + continue; + if (!lowercase || !tny_font[c-HU_FONTSTART]) c = toupper(c); c -= HU_FONTSTART; -- 2.54.0 From 7cd6a031cd46f57ae5feb9325db252381298901e Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Apr 2024 19:12:14 +0300 Subject: [PATCH 22/59] Fix compilation warning regarding calloc and sizeof --- src/apng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apng.c b/src/apng.c index 694b3d1e8..711024ee3 100644 --- a/src/apng.c +++ b/src/apng.c @@ -71,7 +71,7 @@ apng_create_info_struct (png_structp pngp) { apng_infop ainfop; (void)pngp; - if (( ainfop = calloc(sizeof (apng_info),1) )) + if (( ainfop = calloc(1, sizeof (apng_info)) )) { apng_set_write_fn(pngp, ainfop, 0, 0, 0, 0, 0); apng_set_set_acTL_fn(pngp, ainfop, 0); -- 2.54.0 From c92ef4d757ef22bb1c9f1f497a13b90292da56ba Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 12 Apr 2024 20:41:10 +0200 Subject: [PATCH 23/59] fix software crash Zzz... --- src/sdl/i_video.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c415a063a..4597871b8 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -219,7 +219,8 @@ static void Impl_SetWindowIcon(void); boolean downsample = false; void RefreshSDLSurface(void) { - OglSdlSurface(vid.width, vid.height); + if (rendermode == render_opengl) + OglSdlSurface(vid.width, vid.height); } #endif @@ -747,7 +748,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) #ifdef HWRENDER void I_DownSample(void) { - if (!cv_grframebuffer.value) + if (!cv_grframebuffer.value || !rendermode == render_opengl) { downsample = false; return; @@ -843,7 +844,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } #ifdef HWRENDER - if (windowmoved) + if (windowmoved && rendermode == render_opengl) { I_DownSample(); } @@ -1927,7 +1928,8 @@ INT32 VID_SetMode(INT32 modeNum) //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); #ifdef HWRENDER - I_DownSample(); + if (rendermode == render_opengl) + I_DownSample(); #endif SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); -- 2.54.0 From dacfe376e124823defe2031e7f317f9ec8de11f8 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 12 Apr 2024 21:55:45 +0200 Subject: [PATCH 24/59] smth smth paranthesis --- src/sdl/i_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 4597871b8..ef6f743d1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -748,7 +748,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) #ifdef HWRENDER void I_DownSample(void) { - if (!cv_grframebuffer.value || !rendermode == render_opengl) + if (!cv_grframebuffer.value || !(rendermode == render_opengl)) { downsample = false; return; -- 2.54.0 From 45d73a2ad66c70d2802f7ac5c33b112e1822e978 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 13 Apr 2024 18:40:00 +0200 Subject: [PATCH 25/59] add qs22j to cmakelist --- src/CMakeLists.txt | 1084 ++++++++++++++++++++++---------------------- 1 file changed, 543 insertions(+), 541 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2fda45979..ca94f1b95 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,541 +1,543 @@ -# SRB2 Core - -# Core sources -set(SRB2_CORE_SOURCES - am_map.c - b_bot.c - command.c - comptime.c - console.c - d_clisrv.c - d_main.c - d_net.c - d_netcmd.c - d_netfil.c - d_protocol.c - dehacked.c - f_finale.c - f_wipe.c - filesrch.c - g_game.c - g_input.c - hu_stuff.c - i_tcp.c - info.c - lzf.c - m_aatree.c - m_anigif.c - m_argv.c - m_bbox.c - m_cheat.c - m_cond.c - m_fixed.c - m_menu.c - m_misc.c - m_perfstats.c - m_queue.c - m_random.c - md5.c - mserv.c - http-mserv.c - s_sound.c - screen.c - sounds.c - st_stuff.c - #string.c - tables.c - v_video.c - w_wad.c - y_inter.c - z_zone.c -) - -set(SRB2_CORE_HEADERS - am_map.h - b_bot.h - byteptr.h - command.h - console.h - d_clisrv.h - d_event.h - d_main.h - d_net.h - d_netcmd.h - d_netfil.h - d_player.h - d_protocol.h - d_think.h - d_ticcmd.h - dehacked.h - doomdata.h - doomdef.h - doomstat.h - doomtype.h - endian.h - f_finale.h - fastcmp.h - filesrch.h - g_game.h - g_input.h - g_state.h - hu_stuff.h - i_joy.h - i_net.h - i_sound.h - i_system.h - i_tcp.h - i_time.h - i_video.h - info.h - keys.h - lzf.h - m_aatree.h - m_anigif.h - m_argv.h - m_bbox.h - m_cheat.h - m_cond.h - m_dllist.h - m_fixed.h - m_menu.h - m_misc.h - m_queue.h - m_perfstats.h - m_random.h - m_swap.h - md5.h - mserv.h - s_sound.h - screen.h - sounds.h - st_stuff.h - tables.h - v_video.h - w_wad.h - y_inter.h - z_zone.h - - config.h.in -) - -set(SRB2_CORE_RENDER_SOURCES - r_bsp.c - r_data.c - r_draw.c - r_fps.c - r_main.c - r_patch.c - r_plane.c - r_segs.c - r_sky.c - r_splats.c - r_things.c - - r_bsp.h - r_data.h - r_defs.h - r_draw.h - r_fps.h - r_local.h - r_main.h - r_patch - r_plane.h - r_segs.h - r_sky.h - r_splats.h - r_state.h - r_things.h -) - -set(SRB2_CORE_GAME_SOURCES - p_ceilng.c - p_enemy.c - p_floor.c - p_inter.c - p_lights.c - p_map.c - p_maputl.c - p_mobj.c - p_polyobj.c - p_saveg.c - p_setup.c - p_sight.c - p_slopes.c - p_spec.c - p_telept.c - p_tick.c - p_user.c - k_kart.c - i_time.c - - p_local.h - p_maputl.h - p_mobj.h - p_polyobj.h - p_pspr.h - p_saveg.h - p_setup.h - p_slopes.h - p_spec.h - p_tick.h - k_kart.h -) - -if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) -endif() - -prepend_sources(SRB2_CORE_SOURCES) -prepend_sources(SRB2_CORE_HEADERS) -prepend_sources(SRB2_CORE_RENDER_SOURCES) -prepend_sources(SRB2_CORE_GAME_SOURCES) - -set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/config.h) -source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) -source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) -source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) - -### Configuration -set(SRB2_CONFIG_HAVE_BLUA ON CACHE BOOL - "Enable Lua interpreter support") -set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL - "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") -set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL - "Enable zlib support.") -set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL - "Enable GME support.") -set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL - "Enable OpenMPT support.") -set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL - "Enable Discord rich presence support.") -set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL - "Enable curl support, used for downloading files via HTTP.") -set(SRB2_CONFIG_HWRENDER ON CACHE BOOL - "Enable hardware rendering through OpenGL.") -set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL - "Use statically linked OpenGL. NOT RECOMMENDED.") - -### use internal libraries? -if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only - set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL - "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") -endif() - -if(${SRB2_CONFIG_HAVE_BLUA}) - add_definitions(-DHAVE_BLUA) - set(SRB2_LUA_SOURCES - lua_baselib.c - lua_blockmaplib.c - lua_consolelib.c - lua_hooklib.c - lua_hudlib.c - lua_hudlib_drawlist.c - lua_infolib.c - lua_maplib.c - lua_mathlib.c - lua_mobjlib.c - lua_playerlib.c - lua_script.c - lua_skinlib.c - lua_thinkerlib.c - lua_udatalib.c - lua_glib.c - ) - set(SRB2_LUA_HEADERS - lua_hook.h - lua_hud.h - lua_hudlib_drawlist.h - lua_libs.h - lua_script.h - lua_udatalib.h - lua_glib.h - ) - - prepend_sources(SRB2_LUA_SOURCES) - prepend_sources(SRB2_LUA_HEADERS) - - source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) - - set(SRB2_BLUA_SOURCES - blua/lapi.c - blua/lauxlib.c - blua/lbaselib.c - blua/ldblib.c - blua/lcode.c - blua/ldebug.c - blua/ldo.c - blua/ldump.c - blua/lfunc.c - blua/lgc.c - blua/linit.c - blua/liolib.c - blua/llex.c - blua/lmem.c - blua/lobject.c - blua/lopcodes.c - blua/lparser.c - blua/lstate.c - blua/lstring.c - blua/lstrlib.c - blua/ltable.c - blua/ltablib.c - blua/ltm.c - blua/lundump.c - blua/lvm.c - blua/lzio.c - ) - set(SRB2_BLUA_HEADERS - blua/lapi.h - blua/lauxlib.h - blua/lcode.h - blua/ldebug.h - blua/ldo.h - blua/lfunc.h - blua/lgc.h - blua/llex.h - blua/llimits.h - blua/lmem.h - blua/lobject.h - blua/lopcodes.h - blua/lparser.h - blua/lstate.h - blua/lstring.h - blua/ltable.h - blua/ltm.h - blua/lua.h - blua/luaconf.h - blua/lualib.h - blua/lundump.h - blua/lvm.h - blua/lzio.h - ) - - prepend_sources(SRB2_BLUA_SOURCES) - prepend_sources(SRB2_BLUA_HEADERS) - - source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) -endif() - -if(${SRB2_CONFIG_HAVE_GME}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(GME_FOUND ON) - set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") - else() # 32-bit - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme") - endif() - else() - find_package(GME) - endif() - if(${GME_FOUND}) - set(SRB2_HAVE_GME ON) - add_definitions(-DHAVE_LIBGME) - else() - message(WARNING "You have specified that GME is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_DISCORDRPC}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(DISCORDRPC_FOUND ON) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/lib -ldiscord-rpc") - else() # 32-bit - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/lib -ldiscord-rpc") - endif() - else() - find_package(DiscordRPC) - endif() - if(${DISCORDRPC_FOUND}) - set(SRB2_HAVE_DISCORDRPC ON) - add_definitions(-DHAVE_DISCORDRPC) - add_definitions(-DUSE_STUN) - set(SRB2_DISCORDRPC_SOURCES discord.c stun.c) - set(SRB2_DISCORDRPC_HEADERS discord.h stun.h) - prepend_sources(SRB2_DISCORDRPC_SOURCES) - prepend_sources(SRB2_DISCORDRPC_HEADERS) - source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) - else() - message(WARNING "You have specified that Discord Rich Presence is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_OPENMPT}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(OPENMPT_FOUND ON) - set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") - else() # 32-bit - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") - endif() - else() - find_package(OPENMPT) - endif() - if(${OPENMPT_FOUND}) - set(SRB2_HAVE_OPENMPT ON) - add_definitions(-DHAVE_OPENMPT) - else() - message(WARNING "You have specified that OpenMPT is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_ZLIB}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(ZLIB_FOUND ON) - set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") - else() # 32-bit - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") - endif() - else() - find_package(ZLIB) - endif() - if(${ZLIB_FOUND}) - set(SRB2_HAVE_ZLIB ON) - add_definitions(-DHAVE_ZLIB) - else() - message(WARNING "You have specified that ZLIB is available but it was not found. SRB2Kart may not compile correctly.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) - if (${ZLIB_FOUND}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(PNG_FOUND ON) - set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") - else() # 32-bit - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") - endif() - else() - find_package(PNG) - endif() - if(${PNG_FOUND}) - set(SRB2_HAVE_PNG ON) - add_definitions(-DHAVE_PNG) - add_definitions(-D_LARGEFILE64_SOURCE) - set(SRB2_PNG_SOURCES apng.c) - set(SRB2_PNG_HEADERS apng.h) - prepend_sources(SRB2_PNG_SOURCES) - prepend_sources(SRB2_PNG_HEADERS) - source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} - ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) - else() - message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") - endif() - endif() -endif() - -if(${SRB2_CONFIG_HAVE_CURL}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(CURL_FOUND ON) - set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl") - else() # 32-bit - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl") - endif() - else() - find_package(CURL) - endif() - if(${CURL_FOUND}) - set(SRB2_HAVE_CURL ON) - add_definitions(-DHAVE_CURL) - else() - message(WARNING "You have specified that CURL is available but it was not found. SRB2Kart may not compile correctly.") - endif() -endif() - -if(${SRB2_CONFIG_HWRENDER}) - add_definitions(-DHWRENDER) - set(SRB2_HWRENDER_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c - ) - - set (SRB2_HWRENDER_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h - ) - - set(SRB2_R_OPENGL_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.c - ) - - set(SRB2_R_OPENGL_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h - ) - -endif() - -if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) - find_package(OpenGL) - if(${OPENGL_FOUND}) - add_definitions(-DHWRENDER) - add_definitions(-DSTATIC_OPENGL) - else() - message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") - endif() -endif() - - -# Targets - -# Compatibility flag with later versions of GCC -# We should really fix our code to not need this -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) -endif() - -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) -endif() - -add_definitions(-DCMAKECONFIG) - -#add_library(SRB2Core STATIC -# ${SRB2_CORE_SOURCES} -# ${SRB2_CORE_HEADERS} -# ${SRB2_CORE_RENDER_SOURCES} -# ${SRB2_CORE_GAME_SOURCES} -# ${SRB2_LUA_SOURCES} -# ${SRB2_LUA_HEADERS} -# ${SRB2_BLUA_SOURCES} -# ${SRB2_BLUA_HEADERS} -#) - -add_subdirectory(sdl) - -if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) - message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") -endif() +# SRB2 Core + +# Core sources +set(SRB2_CORE_SOURCES + am_map.c + b_bot.c + command.c + comptime.c + console.c + d_clisrv.c + d_main.c + d_net.c + d_netcmd.c + d_netfil.c + d_protocol.c + dehacked.c + f_finale.c + f_wipe.c + filesrch.c + g_game.c + g_input.c + hu_stuff.c + i_tcp.c + info.c + lzf.c + m_aatree.c + m_anigif.c + m_argv.c + m_bbox.c + m_cheat.c + m_cond.c + m_fixed.c + m_menu.c + m_misc.c + m_perfstats.c + m_queue.c + m_random.c + md5.c + mserv.c + http-mserv.c + qs22j.c + s_sound.c + screen.c + sounds.c + st_stuff.c + #string.c + tables.c + v_video.c + w_wad.c + y_inter.c + z_zone.c +) + +set(SRB2_CORE_HEADERS + am_map.h + b_bot.h + byteptr.h + command.h + console.h + d_clisrv.h + d_event.h + d_main.h + d_net.h + d_netcmd.h + d_netfil.h + d_player.h + d_protocol.h + d_think.h + d_ticcmd.h + dehacked.h + doomdata.h + doomdef.h + doomstat.h + doomtype.h + endian.h + f_finale.h + fastcmp.h + filesrch.h + g_game.h + g_input.h + g_state.h + hu_stuff.h + i_joy.h + i_net.h + i_sound.h + i_system.h + i_tcp.h + i_time.h + i_video.h + info.h + keys.h + lzf.h + m_aatree.h + m_anigif.h + m_argv.h + m_bbox.h + m_cheat.h + m_cond.h + m_dllist.h + m_fixed.h + m_menu.h + m_misc.h + m_queue.h + m_perfstats.h + m_random.h + m_swap.h + md5.h + mserv.h + qs22j.h + s_sound.h + screen.h + sounds.h + st_stuff.h + tables.h + v_video.h + w_wad.h + y_inter.h + z_zone.h + + config.h.in +) + +set(SRB2_CORE_RENDER_SOURCES + r_bsp.c + r_data.c + r_draw.c + r_fps.c + r_main.c + r_patch.c + r_plane.c + r_segs.c + r_sky.c + r_splats.c + r_things.c + + r_bsp.h + r_data.h + r_defs.h + r_draw.h + r_fps.h + r_local.h + r_main.h + r_patch + r_plane.h + r_segs.h + r_sky.h + r_splats.h + r_state.h + r_things.h +) + +set(SRB2_CORE_GAME_SOURCES + p_ceilng.c + p_enemy.c + p_floor.c + p_inter.c + p_lights.c + p_map.c + p_maputl.c + p_mobj.c + p_polyobj.c + p_saveg.c + p_setup.c + p_sight.c + p_slopes.c + p_spec.c + p_telept.c + p_tick.c + p_user.c + k_kart.c + i_time.c + + p_local.h + p_maputl.h + p_mobj.h + p_polyobj.h + p_pspr.h + p_saveg.h + p_setup.h + p_slopes.h + p_spec.h + p_tick.h + k_kart.h +) + +if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) +endif() + +prepend_sources(SRB2_CORE_SOURCES) +prepend_sources(SRB2_CORE_HEADERS) +prepend_sources(SRB2_CORE_RENDER_SOURCES) +prepend_sources(SRB2_CORE_GAME_SOURCES) + +set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/config.h) +source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) +source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) +source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) + +### Configuration +set(SRB2_CONFIG_HAVE_BLUA ON CACHE BOOL + "Enable Lua interpreter support") +set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL + "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") +set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL + "Enable zlib support.") +set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL + "Enable GME support.") +set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL + "Enable OpenMPT support.") +set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL + "Enable Discord rich presence support.") +set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL + "Enable curl support, used for downloading files via HTTP.") +set(SRB2_CONFIG_HWRENDER ON CACHE BOOL + "Enable hardware rendering through OpenGL.") +set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL + "Use statically linked OpenGL. NOT RECOMMENDED.") + +### use internal libraries? +if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only + set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL + "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") +endif() + +if(${SRB2_CONFIG_HAVE_BLUA}) + add_definitions(-DHAVE_BLUA) + set(SRB2_LUA_SOURCES + lua_baselib.c + lua_blockmaplib.c + lua_consolelib.c + lua_hooklib.c + lua_hudlib.c + lua_hudlib_drawlist.c + lua_infolib.c + lua_maplib.c + lua_mathlib.c + lua_mobjlib.c + lua_playerlib.c + lua_script.c + lua_skinlib.c + lua_thinkerlib.c + lua_udatalib.c + lua_glib.c + ) + set(SRB2_LUA_HEADERS + lua_hook.h + lua_hud.h + lua_hudlib_drawlist.h + lua_libs.h + lua_script.h + lua_udatalib.h + lua_glib.h + ) + + prepend_sources(SRB2_LUA_SOURCES) + prepend_sources(SRB2_LUA_HEADERS) + + source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) + + set(SRB2_BLUA_SOURCES + blua/lapi.c + blua/lauxlib.c + blua/lbaselib.c + blua/ldblib.c + blua/lcode.c + blua/ldebug.c + blua/ldo.c + blua/ldump.c + blua/lfunc.c + blua/lgc.c + blua/linit.c + blua/liolib.c + blua/llex.c + blua/lmem.c + blua/lobject.c + blua/lopcodes.c + blua/lparser.c + blua/lstate.c + blua/lstring.c + blua/lstrlib.c + blua/ltable.c + blua/ltablib.c + blua/ltm.c + blua/lundump.c + blua/lvm.c + blua/lzio.c + ) + set(SRB2_BLUA_HEADERS + blua/lapi.h + blua/lauxlib.h + blua/lcode.h + blua/ldebug.h + blua/ldo.h + blua/lfunc.h + blua/lgc.h + blua/llex.h + blua/llimits.h + blua/lmem.h + blua/lobject.h + blua/lopcodes.h + blua/lparser.h + blua/lstate.h + blua/lstring.h + blua/ltable.h + blua/ltm.h + blua/lua.h + blua/luaconf.h + blua/lualib.h + blua/lundump.h + blua/lvm.h + blua/lzio.h + ) + + prepend_sources(SRB2_BLUA_SOURCES) + prepend_sources(SRB2_BLUA_HEADERS) + + source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) +endif() + +if(${SRB2_CONFIG_HAVE_GME}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(GME_FOUND ON) + set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") + else() # 32-bit + set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme") + endif() + else() + find_package(GME) + endif() + if(${GME_FOUND}) + set(SRB2_HAVE_GME ON) + add_definitions(-DHAVE_LIBGME) + else() + message(WARNING "You have specified that GME is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_DISCORDRPC}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(DISCORDRPC_FOUND ON) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/include) + set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/lib -ldiscord-rpc") + else() # 32-bit + set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/include) + set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/lib -ldiscord-rpc") + endif() + else() + find_package(DiscordRPC) + endif() + if(${DISCORDRPC_FOUND}) + set(SRB2_HAVE_DISCORDRPC ON) + add_definitions(-DHAVE_DISCORDRPC) + add_definitions(-DUSE_STUN) + set(SRB2_DISCORDRPC_SOURCES discord.c stun.c) + set(SRB2_DISCORDRPC_HEADERS discord.h stun.h) + prepend_sources(SRB2_DISCORDRPC_SOURCES) + prepend_sources(SRB2_DISCORDRPC_HEADERS) + source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) + else() + message(WARNING "You have specified that Discord Rich Presence is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_OPENMPT}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(OPENMPT_FOUND ON) + set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") + else() # 32-bit + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") + endif() + else() + find_package(OPENMPT) + endif() + if(${OPENMPT_FOUND}) + set(SRB2_HAVE_OPENMPT ON) + add_definitions(-DHAVE_OPENMPT) + else() + message(WARNING "You have specified that OpenMPT is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_ZLIB}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(ZLIB_FOUND ON) + set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") + else() # 32-bit + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") + endif() + else() + find_package(ZLIB) + endif() + if(${ZLIB_FOUND}) + set(SRB2_HAVE_ZLIB ON) + add_definitions(-DHAVE_ZLIB) + else() + message(WARNING "You have specified that ZLIB is available but it was not found. SRB2Kart may not compile correctly.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) + if (${ZLIB_FOUND}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(PNG_FOUND ON) + set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") + else() # 32-bit + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") + endif() + else() + find_package(PNG) + endif() + if(${PNG_FOUND}) + set(SRB2_HAVE_PNG ON) + add_definitions(-DHAVE_PNG) + add_definitions(-D_LARGEFILE64_SOURCE) + set(SRB2_PNG_SOURCES apng.c) + set(SRB2_PNG_HEADERS apng.h) + prepend_sources(SRB2_PNG_SOURCES) + prepend_sources(SRB2_PNG_HEADERS) + source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} + ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) + else() + message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") + endif() + endif() +endif() + +if(${SRB2_CONFIG_HAVE_CURL}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(CURL_FOUND ON) + set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl") + else() # 32-bit + set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl") + endif() + else() + find_package(CURL) + endif() + if(${CURL_FOUND}) + set(SRB2_HAVE_CURL ON) + add_definitions(-DHAVE_CURL) + else() + message(WARNING "You have specified that CURL is available but it was not found. SRB2Kart may not compile correctly.") + endif() +endif() + +if(${SRB2_CONFIG_HWRENDER}) + add_definitions(-DHWRENDER) + set(SRB2_HWRENDER_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c + ) + + set (SRB2_HWRENDER_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h + ) + + set(SRB2_R_OPENGL_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.c + ) + + set(SRB2_R_OPENGL_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h + ) + +endif() + +if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) + find_package(OpenGL) + if(${OPENGL_FOUND}) + add_definitions(-DHWRENDER) + add_definitions(-DSTATIC_OPENGL) + else() + message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") + endif() +endif() + + +# Targets + +# Compatibility flag with later versions of GCC +# We should really fix our code to not need this +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) +endif() + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) +endif() + +add_definitions(-DCMAKECONFIG) + +#add_library(SRB2Core STATIC +# ${SRB2_CORE_SOURCES} +# ${SRB2_CORE_HEADERS} +# ${SRB2_CORE_RENDER_SOURCES} +# ${SRB2_CORE_GAME_SOURCES} +# ${SRB2_LUA_SOURCES} +# ${SRB2_LUA_HEADERS} +# ${SRB2_BLUA_SOURCES} +# ${SRB2_BLUA_HEADERS} +#) + +add_subdirectory(sdl) + +if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) + message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") +endif() -- 2.54.0 From 36e06e5d6b147c4b77585bc6947d721c9c949bbc Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 13 Apr 2024 21:55:22 +0300 Subject: [PATCH 26/59] Fix possible buffer overflow in 'va' function --- src/m_misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_misc.c b/src/m_misc.c index 97dcbed84..7d0ce6bfc 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1589,7 +1589,7 @@ char *va(const char *format, ...) static char string[1024]; va_start(argptr, format); - vsprintf(string, format, argptr); + vsnprintf(string, 1024, format, argptr); va_end(argptr); return string; -- 2.54.0 From 2ccf91fbfc155c644f8c8667b5475bc7bdd3b833 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Apr 2024 03:52:21 +0200 Subject: [PATCH 27/59] Make FixedRem less laggy by just using the modulo operator. --- src/m_fixed.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/m_fixed.h b/src/m_fixed.h index 4e4c79c65..d67777162 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -121,14 +121,7 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedDiv(fixed_t a, fixed_t b) */ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedRem(fixed_t x, fixed_t y) { - const boolean n = x < 0; - x = abs(x); - while (x >= y) - x -= y; - if (n) - return -x; - else - return x; + return x % y; } /** \brief The FixedSqrt function -- 2.54.0 From 463dccab8b077547ba959d6e3a4b4eb1ac7d4410 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Apr 2024 04:22:29 +0200 Subject: [PATCH 28/59] some smol fixes --- src/dehacked.c | 2 +- src/g_game.c | 7 +++++-- src/p_mobj.c | 2 +- src/p_polyobj.c | 6 +++--- src/v_video.c | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 8c1ba8e4d..486584fa5 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -334,7 +334,7 @@ static void readPlayer(MYFILE *f, INT32 num) // It works down here, though. { INT32 numline = 0; - for (i = 0; i < MAXLINELEN-1; i++) + for (i = 0; (size_t)i < sizeof(description[num].notes)-1; i++) { if (numline < 20 && description[num].notes[i] == '\n') numline++; diff --git a/src/g_game.c b/src/g_game.c index d7ac0e8ff..4161c6ca7 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5897,7 +5897,7 @@ void G_GhostTicker(void) if (ziptic & EZT_THOKMASK) { // Let's only spawn ONE of these per frame, thanks. mobj_t *mobj; - INT32 type = -1; + UINT32 type = MT_NULL; if (g->mo->skin) { switch (ziptic & EZT_THOKMASK) @@ -6221,7 +6221,10 @@ void G_ReadMetalTic(mobj_t *metal) // Read changes from the tic if (ziptic & GZT_XYZ) { - P_MoveOrigin(metal, READFIXED(metal_p), READFIXED(metal_p), READFIXED(metal_p)); + 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; diff --git a/src/p_mobj.c b/src/p_mobj.c index cbc08c02c..67d5b695b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1329,7 +1329,7 @@ void P_XYMovement(mobj_t *mo) fixed_t oldx, oldy; // reducing bobbing/momentum on ice when up against walls boolean moved; pslope_t *oldslope = NULL; - vector3_t slopemom; + vector3_t slopemom = {0,0,0}; fixed_t predictedz = 0; I_Assert(mo != NULL); diff --git a/src/p_polyobj.c b/src/p_polyobj.c index fa98ad9a5..9a3376595 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1206,7 +1206,7 @@ static boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y) // http://www.inversereality.org/tutorials/graphics%20programming/2dtransformations.html // It is, of course, just a vector-matrix multiplication. // -static inline void Polyobj_rotatePoint(vertex_t *v, const vertex_t *c, angle_t ang) +static inline void Polyobj_rotatePoint(vertex_t *v, const vector2_t *c, angle_t ang) { vertex_t tmp = *v; @@ -1267,7 +1267,7 @@ static void Polyobj_rotateLine(line_t *ld) // // Causes objects resting on top of the rotating polyobject to 'ride' with its movement. // -static void Polyobj_rotateThings(polyobj_t *po, vertex_t origin, angle_t delta, UINT8 turnthings) +static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, UINT8 turnthings) { static INT32 pomovecount = 10000; INT32 x, y; @@ -1367,7 +1367,7 @@ static boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings) { size_t i; angle_t angle; - vertex_t origin; + vector2_t origin; INT32 hitflags = 0; // don't move bad polyobjects diff --git a/src/v_video.c b/src/v_video.c index 7b9383f06..4ea028cc3 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3370,7 +3370,7 @@ void V_Init(void) #ifdef DEBUG CONS_Debug(DBG_RENDER, "V_Init done:\n"); - for (i = 0; i < NUMSCREENS+1; i++) + for (i = 0; i < NUMSCREENS; i++) CONS_Debug(DBG_RENDER, " screens[%d] = %x\n", i, screens[i]); #endif } -- 2.54.0 From 9317ccd0be92a7f3d9b6cbda758cf93c0d77d945 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Apr 2024 06:22:44 +0200 Subject: [PATCH 29/59] more things -Fix a division by zero in BCZ2 Metal Sonic's routine -Fix a bug where adding the same mod multiple times counted towards the mod limit and other thigns --- src/p_mobj.c | 11 +++++------ src/r_data.c | 13 +++++++++++-- src/w_wad.c | 6 ++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 67d5b695b..94226face 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4978,18 +4978,17 @@ static void P_Boss9Thinker(mobj_t *mobj) mobj->angle -= InvAngle(angle)/8; // Spawn energy particles - for (spawner = mobj->hnext; spawner; spawner = spawner->hnext) { + for (spawner = mobj->hnext; spawner; spawner = spawner->hnext) + { dist = P_AproxDistance(spawner->x - mobj->x, spawner->y - mobj->y); if (P_RandomRange(1,(dist>>FRACBITS)/16) == 1) break; } - if (spawner) { + if (spawner && dist) + { mobj_t *missile = P_SpawnMissile(spawner, mobj, MT_MSGATHER); missile->momz = FixedDiv(missile->momz, 7*FRACUNIT/4); - if (dist == 0) - missile->fuse = 0; - else - missile->fuse = (dist/P_AproxDistance(missile->momx, missile->momy)); + missile->fuse = (dist/P_AproxDistance(missile->momx, missile->momy)); if (missile->fuse > mobj->fuse) P_RemoveMobj(missile); } diff --git a/src/r_data.c b/src/r_data.c index 772d76925..69b0ce1ac 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1088,6 +1088,7 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) { char colormap[9] = "COLORMAP"; lumpnum_t lump; + const lumpnum_t basecolormaplump = W_GetNumForName(colormap); if (num > 0 && num <= 10000) snprintf(colormap, 8, "CLM%04u", num-1); @@ -1095,8 +1096,16 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) // Load in the light tables, now 64k aligned for smokie... lump = W_GetNumForName(colormap); if (lump == LUMPERROR) - lump = W_GetNumForName("COLORMAP"); - W_ReadLump(lump, colormaps); + lump = basecolormaplump; + else + { + if (W_LumpLength(lump) != W_LumpLength(basecolormaplump)) + { + CONS_Alert(CONS_WARNING, "%s lump size does not match COLORMAP, results may be unexpected.\n", colormap); + } + } + + W_ReadLumpHeader(lump, colormaps, W_LumpLength(basecolormaplump), 0U); // Encore mode. if (newencoremap != LUMPERROR) diff --git a/src/w_wad.c b/src/w_wad.c index 86536c03f..103e12998 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -186,9 +186,9 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors) if (filenamebuf != *filename) { // avoid overlap strncpy(filenamebuf, *filename, MAX_WADPATH); + filenamebuf[MAX_WADPATH - 1] = '\0'; + *filename = filenamebuf; } - filenamebuf[MAX_WADPATH - 1] = '\0'; - *filename = filenamebuf; // open wad file if ((handle = fopen_utf8(*filename, "rb")) == NULL) @@ -755,6 +755,8 @@ UINT16 W_InitFile(const char *filename, boolean local) if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) { CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); + if (important) + packetsizetally -= nameonlylength(filename) + 22; if (handle) fclose(handle); return INT16_MAX; -- 2.54.0 From a238b19c750e41d4e544c454415110f9eb8ddb3b Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Apr 2024 05:08:47 +0200 Subject: [PATCH 30/59] z --- src/w_wad.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 103e12998..cd2968494 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -755,8 +755,6 @@ UINT16 W_InitFile(const char *filename, boolean local) if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) { CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); - if (important) - packetsizetally -= nameonlylength(filename) + 22; if (handle) fclose(handle); return INT16_MAX; -- 2.54.0 From bcf2b3bab2f63ddbcad2179e4fba3a7a070d4ea2 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Apr 2024 06:21:58 +0200 Subject: [PATCH 31/59] disable palette rendering if screentextures aint enabled --- src/hardware/hw_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ff7f2a207..dc2af869e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -177,6 +177,8 @@ static void CV_anisotropic_ONChange(void) static void CV_screentextures_ONChange(void) { ONLY_IF_GL_LOADED + if (cv_grscreentextures.value != 3) + CV_Set(&cv_grpaletterendering, "Off"); HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); } -- 2.54.0 From ea0cc41d04919a9831937a873adc8a369ace9a94 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 20 Apr 2024 10:30:21 +0300 Subject: [PATCH 32/59] For MIN/MAX value of cvar, convert it to float before saving for CV_FLOAT variables --- src/command.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index 37e120d52..b7e1e01de 100644 --- a/src/command.c +++ b/src/command.c @@ -2132,7 +2132,12 @@ void CV_SaveVariables(FILE *f) // Silly hack for Min/Max vars if (!strcmp(cvar->string, "MAX") || !strcmp(cvar->string, "MIN")) - sprintf(stringtowrite, "%d", cvar->value); + { + if (cvar->flags & CV_FLOAT) + sprintf(stringtowrite, "%f", FixedToFloat(cvar->value)); + else + sprintf(stringtowrite, "%d", cvar->value); + } else strcpy(stringtowrite, cvar->string); -- 2.54.0 From 2147951a167b9b1e4c56069751c9224a4d2aedd8 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 20 Apr 2024 11:41:17 +0300 Subject: [PATCH 33/59] Add IT_CV_BIGFLOAT to use bigger increment for some CV_FLOAT cvars (added only to fov atm) --- src/m_menu.c | 12 ++++++++---- src/m_menu.h | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index b672357a1..2dcab703f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1339,9 +1339,9 @@ static menuitem_t OP_VideoOptionsMenu[] = {IT_SUBMENU|IT_STRING, NULL, "Advanced Color Settings...", &OP_ColorOptionsDef, 50}, - {IT_STRING | IT_CVAR, NULL, "Draw Distance", &cv_drawdist, 65}, - {IT_STRING | IT_CVAR, NULL, "Weather Draw Distance",&cv_drawdist_precip, 75}, - {IT_STRING | IT_CVAR, NULL, "Field of View", &cv_fov, 95}, + {IT_STRING | IT_CVAR, NULL, "Draw Distance", &cv_drawdist, 65}, + {IT_STRING | IT_CVAR, NULL, "Weather Draw Distance",&cv_drawdist_precip, 75}, + {IT_STRING | IT_CVAR | IT_CV_BIGFLOAT, NULL, "Field of View", &cv_fov, 95}, {IT_STRING | IT_CVAR, NULL, "Show FPS", &cv_ticrate, 105}, {IT_STRING | IT_CVAR, NULL, "Vertical Sync", &cv_vidwait, 115}, @@ -3305,7 +3305,11 @@ static void M_ChangeCvar(INT32 choice) else if (cv->flags & CV_FLOAT) { char s[20]; - sprintf(s,"%f",FIXED_TO_FLOAT(cv->value)+(choice)*(1.0f/16.0f)); + float increment; + + increment = (currentMenu->menuitems[itemOn].status & IT_CV_BIGFLOAT) ? 0.5 : (1.f/16); + + sprintf(s,"%f",FIXED_TO_FLOAT(cv->value)+(choice)*increment); CV_Set(cv,s); } else diff --git a/src/m_menu.h b/src/m_menu.h index bb504642d..bba8d3db3 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -129,6 +129,10 @@ extern boolean menu_text_input; #define IT_CV_NOMOD 2048 #define IT_CV_INVISSLIDER 2560 +// For cv_float's, will use 1/2 as increment instead of 1/16 +// Not sure if i should add it to cvartype, since its more a flag than type +#define IT_CV_BIGFLOAT 4096 + //call/submenu specific // There used to be a lot more here but ... // A lot of them became redundant with the advent of the Pause menu, so they were removed -- 2.54.0 From d0c50006bc8cb1b6530791bba25439d8d0ff8021 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 20 Apr 2024 22:36:23 +0200 Subject: [PATCH 34/59] some stuff from ceepeepeecheck --- src/d_net.c | 6 ++++++ src/d_netcmd.c | 6 +----- src/dehacked.c | 6 +++++- src/g_game.c | 2 +- src/hardware/hw_main.c | 10 +++++++--- src/hu_stuff.c | 11 +++++++++-- src/i_tcp.c | 3 +++ src/p_user.c | 17 +++++++---------- src/y_inter.c | 2 +- 9 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/d_net.c b/src/d_net.c index 1b4550d35..6b45e009d 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1445,6 +1445,12 @@ void Command_Ping_f(void) pingv[pingc].ms = ms; pingc++; } + else + { + pingv[pingc].num = 0; + pingv[pingc].f = 0; + pingv[pingc].ms = 0; + } } if (f_width < 10) f_width = 1; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b85e3a0ea..1e46da57f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2659,13 +2659,9 @@ void D_ModifyClientVote(SINT8 voted, UINT8 splitplayer) { char buf[2]; char *p = buf; - UINT8 player = consoleplayer; - - if (splitplayer > 0) - player = displayplayers[splitplayer]; WRITESINT8(p, voted); - WRITEUINT8(p, player); + WRITEUINT8(p, splitplayer); SendNetXCmd(XD_MODIFYVOTE, &buf, 2); } diff --git a/src/dehacked.c b/src/dehacked.c index 486584fa5..8b181a563 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8940,7 +8940,11 @@ static char *lua_enumlib_sprintf_upper(char **buf, int* size, const char *format if (length > *size) { void *ptr = realloc(*buf, length+1); - if (!ptr) return NULL; + if (!ptr) + { + va_end(va); + return NULL; + } *buf = ptr; *size = length+1; diff --git a/src/g_game.c b/src/g_game.c index 4161c6ca7..d692863e9 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -8377,7 +8377,7 @@ void G_SaveDemo(void) size_t i, strindex = 0; boolean dash = true; - for (i = 0; demo.titlename[i] && i < 127; i++) + for (i = 0; i < 127 && demo.titlename[i]; i++) { if ((demo.titlename[i] >= 'a' && demo.titlename[i] <= 'z') || (demo.titlename[i] >= '0' && demo.titlename[i] <= '9')) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index dc2af869e..3ff6b1044 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4908,11 +4908,11 @@ void HWR_ProjectSprite(mobj_t *thing) size_t lumpoff; unsigned rot; UINT8 flip; - boolean mirrored = thing->mirrored; - boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + boolean mirrored; + boolean hflip; angle_t ang, camang; - const boolean papersprite = (thing->frame & FF_PAPERSPRITE); + boolean papersprite; INT32 heightsec, phs; INT32 dist = -1; @@ -4931,6 +4931,10 @@ void HWR_ProjectSprite(mobj_t *thing) if (!thing) return; + mirrored = thing->mirrored; + hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + papersprite = (thing->frame & FF_PAPERSPRITE); + if (cv_grmaxinterpdist.value) dist = R_QuickCamDist(thing->x, thing->y); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 4224b992c..cd0f42a9c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -531,7 +531,8 @@ static void HU_removeChatText_Log(void) free(chat_log[0]); size_t i; - for(i=0;imo->ceilingz - player->mo->floorz < player->mo->height) && !(player->mo->flags & MF_NOCLIP)) { - if (player->mo->ceilingz - player->mo->floorz < player->mo->height) + if ((netgame || multiplayer) && player->spectator) + P_DamageMobj(player->mo, NULL, NULL, 42000); // Respawn crushed spectators + else { - if ((netgame || multiplayer) && player->spectator) - P_DamageMobj(player->mo, NULL, NULL, 42000); // Respawn crushed spectators - else - { - K_SquishPlayer(player, NULL, NULL); // SRB2kart - we don't kill when squished, we squish when squished. - } - - if (player->playerstate == PST_DEAD) - return; + K_SquishPlayer(player, NULL, NULL); // SRB2kart - we don't kill when squished, we squish when squished. } + + if (player->playerstate == PST_DEAD) + return; } #ifdef HWRENDER diff --git a/src/y_inter.c b/src/y_inter.c index 0520b4730..807332c9d 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1486,7 +1486,7 @@ void Y_VoteTicker(void) if ((InputDown(gc_accelerate, i+1) || JoyAxis(AXISMOVE, i+1) > 0) && !pressed) { - D_ModifyClientVote(voteclient.playerinfo[i].selection, i); + D_ModifyClientVote(voteclient.playerinfo[i].selection, p); pressed = true; } } -- 2.54.0 From 38d5ee5ae74d0a60dd60291d320ae4b0a16aab42 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 20 Apr 2024 22:52:22 +0200 Subject: [PATCH 35/59] a --- src/i_tcp.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 6d0cf8f71..81c221d27 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -896,10 +896,7 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen socklen_t len = sizeof(sin); if (s == (SOCKET_TYPE)ERRSOCKET) - { - close(s); return (SOCKET_TYPE)ERRSOCKET; - } #ifdef USE_WINSOCK { // Alam_GBC: disable the new UDP connection reset behavior for Win2k and up #ifdef USE_WINSOCK2 -- 2.54.0 From b4dfebac582077b02228430238f56bc4a11cfd2f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 22 Apr 2024 05:24:49 +0200 Subject: [PATCH 36/59] fix some visual issues with fofs --- src/hardware/hw_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3ff6b1044..1d77b76cb 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3296,7 +3296,7 @@ static void HWR_Subsector(size_t num) centerHeight = P_GetFFloorBottomZAt(rover, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); if (centerHeight <= locCeilingHeight && centerHeight >= locFloorHeight && - ((viewz < bottomCullHeight && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) || + ((viewz < bottomCullHeight && !(rover->flags & FF_INVERTPLANES)) || (viewz > bottomCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) { if (rover->flags & FF_FOG) @@ -3340,7 +3340,7 @@ static void HWR_Subsector(size_t num) if (centerHeight >= locFloorHeight && centerHeight <= locCeilingHeight && - ((viewz > topCullHeight && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) || + ((viewz > topCullHeight && !(rover->flags & FF_INVERTPLANES)) || (viewz < topCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) { if (rover->flags & FF_FOG) -- 2.54.0 From 836890968c899f1034cae299f6b057ed7acd4006 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 23 Apr 2024 09:06:51 +0200 Subject: [PATCH 37/59] Revert "Merge pull request #121 from Indev450/texload" This reverts commit b6a5c5b7205fb4353b7360eb3e14fa9c4d0d5d0d, reversing changes made to bcf2b3bab2f63ddbcad2179e4fba3a7a070d4ea2. --- src/doomdef.h | 16 --- src/p_setup.c | 4 +- src/r_data.c | 321 ++++++++++++++++++-------------------------------- src/r_data.h | 2 - src/w_wad.c | 25 ++-- src/w_wad.h | 1 - 6 files changed, 121 insertions(+), 248 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 1af046e24..d1bbe04e0 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -516,22 +516,6 @@ extern boolean capslock; // i_system.c, replace getchar() once the keyboard has been appropriated INT32 I_GetKey(void); -/* http://www.cse.yorku.ca/~oz/hash.html */ -static inline -UINT32 quickncasehash (const char *p, size_t n) -{ - size_t i = 0; - UINT32 x = 5381; - - while (i < n && p[i]) - { - x = (x * 33) ^ tolower(p[i]); - i++; - } - - return x; -} - #ifndef min // Double-Check with WATTCP-32's cdefs.h #define min(x, y) (((x) < (y)) ? (x) : (y)) #endif diff --git a/src/p_setup.c b/src/p_setup.c index 2435390cb..9ae36afc9 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3452,8 +3452,6 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!devparm && digmreplaces) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); - R_LoadTexturesPwad(wadnum); - // // search for sprite replacements // @@ -3550,7 +3548,7 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 1) { // Reload all textures, unconditionally for better or worse. - //R_LoadTextures(); + R_LoadTextures(); if (fullsetup) ++partadd_stage; diff --git a/src/r_data.c b/src/r_data.c index a65709d9a..69b0ce1ac 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -129,7 +129,6 @@ INT16 *hicolormaps; // test a 32k colormap remaps high -> high // Painfully simple texture id cacheing to make maps load faster. :3 static struct { char name[9]; - UINT32 hash; INT32 id; } *tidcache = NULL; static INT32 tidcachelen = 0; @@ -375,63 +374,144 @@ void R_FlushTextureCache(void) int R_CountTexturesInTEXTURESLump(UINT16 wadNum, UINT16 lumpNum); void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *index); +// +// R_LoadTextures +// Initializes the texture list with the textures from the world map. +// #define TX_START "TX_START" #define TX_END "TX_END" - -static INT32 -Rloadtextures (INT32 i, INT32 w) +void R_LoadTextures(void) { + INT32 i, k, w; UINT16 j; - INT32 k; UINT16 texstart, texend, texturesLumpPos; - patch_t patchlump; + patch_t *patchlump; texpatch_t *patch; texture_t *texture; - // Get the lump numbers for the markers in the WAD, if they exist. - if (W_FileHasFolders(wadfiles[w])) + // Free previous memory before numtextures change. + if (numtextures) { - texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); - texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); + for (i = 0; i < numtextures; i++) + { + Z_Free(textures[i]); + Z_Free(texturecache[i]); + } + Z_Free(texturetranslation); + Z_Free(textures); + } + + // Load patches and textures. + + // Get the number of textures to check. + // NOTE: Make SURE the system does not process + // the markers. + // This system will allocate memory for all duplicate/patched textures even if it never uses them, + // but the alternative is to spend a ton of time checking and re-checking all previous entries just to skip any potentially patched textures. + for (w = 0, numtextures = 0; w < numwadfiles; w++) + { + if (wadfiles[w]->type == RET_PK3) + { + texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); + texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); + } + else + { + texstart = W_CheckNumForNamePwad(TX_START, (UINT16)w, 0) + 1; + texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); + } + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); while (texturesLumpPos != INT16_MAX) { - R_ParseTEXTURESLump(w, texturesLumpPos, &i); + numtextures += R_CountTexturesInTEXTURESLump((UINT16)w, (UINT16)texturesLumpPos); texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, texturesLumpPos + 1); } - } - else - { - texstart = W_CheckNumForMarkerStartPwad(TX_START, (UINT16)w, 0); - texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); - if (texturesLumpPos != INT16_MAX) - R_ParseTEXTURESLump(w, texturesLumpPos, &i); + + // Add all the textures between TX_START and TX_END + if (texstart != INT16_MAX && texend != INT16_MAX) + { + // PK3s have subfolders, so we can't just make a simple sum + if (W_FileHasFolders(wadfiles[w])) + { + for (j = texstart; j < texend; j++) + { + if (!W_IsLumpFolder((UINT16)w, j)) // Check if lump is a folder; if not, then count it + numtextures++; + } + } + else + { + numtextures += (UINT32)(texend - texstart); + } + } } - if (!( texstart == INT16_MAX || texend == INT16_MAX )) + // If no textures found by this point, bomb out + if (!numtextures) + I_Error("No textures detected in any WADs!\n"); + + // Allocate memory and initialize to 0 for all the textures we are initialising. + // There are actually 5 buffers allocated in one for convenience. + textures = Z_Calloc((numtextures * sizeof(void *)) * 5, PU_STATIC, NULL); + + // Allocate texture column offset table. + texturecolumnofs = (void *)((UINT8 *)textures + (numtextures * sizeof(void *))); + // Allocate texture referencing cache. + texturecache = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 2)); + // Allocate texture width mask table. + texturewidthmask = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 3)); + // Allocate texture height mask table. + textureheight = (void *)((UINT8 *)textures + ((numtextures * sizeof(void *)) * 4)); + // Create translation table for global animation. + texturetranslation = Z_Malloc((numtextures + 1) * sizeof(*texturetranslation), PU_STATIC, NULL); + + for (i = 0; i < numtextures; i++) + texturetranslation[i] = i; + + for (i = 0, w = 0; w < numwadfiles; w++) { + // Get the lump numbers for the markers in the WAD, if they exist. + if (wadfiles[w]->type == RET_PK3) + { + texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); + texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); + while (texturesLumpPos != INT16_MAX) + { + R_ParseTEXTURESLump(w, texturesLumpPos, &i); + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, texturesLumpPos + 1); + } + } + else + { + texstart = W_CheckNumForNamePwad(TX_START, (UINT16)w, 0) + 1; + texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); + texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); + if (texturesLumpPos != INT16_MAX) + R_ParseTEXTURESLump(w, texturesLumpPos, &i); + } + + if (texstart == INT16_MAX || texend == INT16_MAX) + continue; + // Work through each lump between the markers in the WAD. for (j = 0; j < (texend - texstart); j++) { - UINT16 wadnum = (UINT16)w; - lumpnum_t lumpnum = texstart + j; - if (W_FileHasFolders(wadfiles[w])) { - if (W_IsLumpFolder(wadnum, lumpnum)) // Check if lump is a folder + if (W_IsLumpFolder(w, texstart + j)) // Check if lump is a folder continue; // If it is then SKIP IT } - W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, 8, 0); // #define PNG_HEADER_SIZE (8) + patchlump = W_CacheLumpNumPwad((UINT16)w, texstart + j, PU_CACHE); //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); // Set texture properties. M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); - texture->hash = quickncasehash(texture->name, 8); - texture->width = SHORT(patchlump.width); - texture->height = SHORT(patchlump.height); + texture->width = SHORT(patchlump->width); + texture->height = SHORT(patchlump->height); texture->patchcount = 1; texture->holes = false; @@ -442,6 +522,8 @@ Rloadtextures (INT32 i, INT32 w) patch->wad = (UINT16)w; patch->lump = texstart + j; + Z_Unlock(patchlump); + k = 1; while (k << 1 <= texture->width) k <<= 1; @@ -452,186 +534,12 @@ Rloadtextures (INT32 i, INT32 w) } } - return i; -} - -static INT32 -count_range -( const char * marker_start, - const char * marker_end, - const char * folder, - UINT16 wadnum) -{ - UINT16 j; - UINT16 texstart, texend; - INT32 count = 0; - - // Count flats - if (W_FileHasFolders(wadfiles[wadnum])) - { - texstart = W_CheckNumForFolderStartPK3(folder, wadnum, 0); - texend = W_CheckNumForFolderEndPK3(folder, wadnum, texstart); - } - else - { - texstart = W_CheckNumForMarkerStartPwad(marker_start, wadnum, 0); - texend = W_CheckNumForNamePwad(marker_end, wadnum, texstart); - } - - if (texstart != INT16_MAX && texend != INT16_MAX) - { - // PK3s have subfolders, so we can't just make a simple sum - if (W_FileHasFolders(wadfiles[wadnum])) - { - for (j = texstart; j < texend; j++) - { - if (!W_IsLumpFolder(wadnum, j)) // Check if lump is a folder; if not, then count it - count++; - } - } - else // Add all the textures between markers - { - count += (texend - texstart); - } - } - - return count; -} - -static INT32 R_CountTextures(UINT16 wadnum) -{ - UINT16 texturesLumpPos; - INT32 count = 0; - - // Load patches and textures. - - // Get the number of textures to check. - // NOTE: Make SURE the system does not process - // the markers. - // This system will allocate memory for all duplicate/patched textures even if it never uses them, - // but the alternative is to spend a ton of time checking and re-checking all previous entries just to skip any potentially patched textures. - - // Count the textures from TEXTURES lumps - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", wadnum, 0); - - while (texturesLumpPos != INT16_MAX) - { - count += R_CountTexturesInTEXTURESLump(wadnum, texturesLumpPos); - texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", wadnum, texturesLumpPos + 1); - } - - // Count single-patch textures - count += count_range(TX_START, TX_END, "textures/", wadnum); - - return count; -} - -static void -recallocuser -( void * user, - size_t old, - size_t new) -{ - char *p = Z_Realloc(*(void**)user, - new, PU_STATIC, user); - - if (new > old) - memset(&p[old], 0, (new - old)); -} - -static void R_AllocateTextures(INT32 add) -{ - const INT32 newtextures = (numtextures + add); - const size_t newsize = newtextures * sizeof (void*); - const size_t oldsize = numtextures * sizeof (void*); - - INT32 i; - - // Allocate memory and initialize to 0 for all the textures we are initialising. - recallocuser(&textures, oldsize, newsize); - - // Allocate texture column offset table. - recallocuser(&texturecolumnofs, oldsize, newsize); - // Allocate texture referencing cache. - recallocuser(&texturecache, oldsize, newsize); - // Allocate texture width table. - recallocuser(&texturewidthmask, oldsize, newsize); - // Allocate texture height table. - recallocuser(&textureheight, oldsize, newsize); - // Create translation table for global animation. - Z_Realloc(texturetranslation, (newtextures + 1) * sizeof(*texturetranslation), PU_STATIC, &texturetranslation); - - for (i = 0; i < numtextures; ++i) - { - // R_FlushTextureCache relies on the user for - // Z_Free, texturecache has been reallocated so the - // user is now garbage memory. - Z_SetUser(texturecache[i], - (void**)&texturecache[i]); - } - - while (i < newtextures) - { - texturetranslation[i] = i; - i++; - } -} - -static INT32 R_DefineTextures(INT32 i, UINT16 w) -{ - return Rloadtextures(i, w); -} - -static void R_FinishLoadingTextures(INT32 add) -{ - numtextures += add; - #ifdef HWRENDER if (rendermode == render_opengl) HWR_LoadTextures(numtextures); #endif } -// -// R_LoadTextures -// Initializes the texture list with the textures from the world map. -// -void R_LoadTextures(void) -{ - INT32 i, w; - INT32 newtextures = 0; - - for (w = 0; w < numwadfiles; w++) - { - newtextures += R_CountTextures((UINT16)w); - } - - // If no textures found by this point, bomb out - if (!newtextures) - I_Error("No textures detected in any WADs!\n"); - - R_AllocateTextures(newtextures); - - for (i = 0, w = 0; w < numwadfiles; w++) - { - i = R_DefineTextures(i, w); - } - - R_FinishLoadingTextures(newtextures); -} - -void R_LoadTexturesPwad(UINT16 wadnum) -{ - INT32 newtextures = R_CountTextures(wadnum); - - if (!newtextures) - return; - - R_AllocateTextures(newtextures); - R_DefineTextures(numtextures, wadnum); - R_FinishLoadingTextures(newtextures); -} - static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) { char *texturesToken; @@ -870,7 +778,6 @@ static texture_t *R_ParseTexture(boolean 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); M_Memcpy(resultTexture->name, newTextureName, 8); - resultTexture->hash = quickncasehash(newTextureName, 8); resultTexture->width = newTextureWidth; resultTexture->height = newTextureHeight; } @@ -1658,22 +1565,19 @@ void R_ClearTextureNumCache(boolean btell) INT32 R_CheckTextureNumForName(const char *name) { INT32 i; - UINT32 hash; // "NoTexture" marker. if (name[0] == '-') return 0; - hash = quickncasehash(name, 8); - for (i = 0; i < tidcachelen; i++) - if (tidcache[i].hash == hash && !strncasecmp(tidcache[i].name, name, 8)) + if (!strncasecmp(tidcache[i].name, name, 8)) return tidcache[i].id; // Need to parse the list backwards, so textures loaded more recently are used in lieu of ones loaded earlier //for (i = 0; i < numtextures; i++) <- old for (i = (numtextures - 1); i >= 0; i--) // <- new - if (textures[i]->hash == hash && !strncasecmp(textures[i]->name, name, 8)) + if (!strncasecmp(textures[i]->name, name, 8)) { tidcachelen++; Z_Realloc(tidcache, tidcachelen * sizeof(*tidcache), PU_STATIC, &tidcache); @@ -1682,7 +1586,6 @@ INT32 R_CheckTextureNumForName(const char *name) #ifndef ZDEBUG CONS_Debug(DBG_SETUP, "texture #%s: %s\n", sizeu1(tidcachelen), tidcache[tidcachelen-1].name); #endif - tidcache[tidcachelen-1].hash = hash; tidcache[tidcachelen-1].id = i; return i; } diff --git a/src/r_data.h b/src/r_data.h index 102bb5314..ec1146322 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -40,7 +40,6 @@ typedef struct { // Keep name for switch changing, etc. char name[8]; - UINT32 hash; INT16 width, height; boolean holes; @@ -64,7 +63,6 @@ extern CV_PossibleValue_t Color_cons_t[]; // Load TEXTURE1/TEXTURE2/PNAMES definitions, create lookup tables void R_LoadTextures(void); -void R_LoadTexturesPwad(UINT16 wadnum); void R_FlushTextureCache(void); INT32 R_GetTextureNum(INT32 texnum); diff --git a/src/w_wad.c b/src/w_wad.c index 486359d21..cd2968494 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -371,7 +371,6 @@ static lumpinfo_t* ResGetLumpsStandalone (FILE* handle, UINT16* numlumps, const lumpinfo->size = ftell(handle); fseek(handle, 0, SEEK_SET); strlcpy(lumpinfo->name, lumpname, 9); - lumpinfo->hash = quickncasehash(lumpname, 8); // Allocate the lump's full and long name. lumpinfo->fullname = Z_StrDup(lumpname); @@ -463,7 +462,6 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen lump_p->compression = CM_NOCOMPRESSION; memset(lump_p->name, 0x00, 9); strncpy(lump_p->name, fileinfo->name, 8); - lump_p->hash = quickncasehash(lump_p->name, 8); // Allocate the lump's long name. lump_p->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); @@ -638,7 +636,6 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? strncpy(lump_p->name, trimname, min(8, dotpos - trimname)); - lump_p->hash = quickncasehash(lump_p->name, 8); lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL); strlcpy(lump_p->longname, trimname, dotpos - trimname + 1); @@ -956,7 +953,6 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { UINT16 i; static char uname[9]; - UINT32 hash; if (!TestValidLump(wad,0)) return INT16_MAX; @@ -964,7 +960,6 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) memset(uname, 0, sizeof uname); strncpy(uname, name, sizeof(uname)-1); strupr(uname); - hash = quickncasehash(uname, 8); // // scan forward @@ -975,7 +970,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) - if (lump_p->hash == hash && memcmp(lump_p->name, uname, sizeof(uname) - 1) == 0) + if (memcmp(lump_p->name, uname, sizeof(uname) - 1) == 0) return i; } @@ -1183,20 +1178,15 @@ lumpnum_t W_CheckNumForLongName(const char *name) // TODO: Make it search through cache first, maybe...? lumpnum_t W_CheckNumForMap(const char *name) { - UINT32 hash = quickncasehash(name, 8); UINT16 lumpNum, end; UINT32 i; - lumpinfo_t *p; for (i = numwadfiles - 1; i < numwadfiles; i--) { if (wadfiles[i]->type == RET_WAD) { for (lumpNum = 0; lumpNum < wadfiles[i]->numlumps; lumpNum++) - { - p = wadfiles[i]->lumpinfo + lumpNum; - if (p->hash == hash && !strncmp(name, p->name, 8)) + if (!strncmp(name, (wadfiles[i]->lumpinfo + lumpNum)->name, 8)) return (i<<16) + lumpNum; - } } else if (wadfiles[i]->type == RET_PK3) { @@ -1207,11 +1197,12 @@ lumpnum_t W_CheckNumForMap(const char *name) continue; // Now look for the specified map. for (; lumpNum < end; lumpNum++) - { - p = wadfiles[i]->lumpinfo + lumpNum; - if (p->hash == hash && !strnicmp(name, p->name, 8)) - return (i<<16) + lumpNum; - } + if (!strnicmp(name, (wadfiles[i]->lumpinfo + lumpNum)->name, 8)) + { + const char *extension = strrchr(wadfiles[i]->lumpinfo[lumpNum].fullname, '.'); + if (!(extension && stricmp(extension, ".wad"))) + return (i<<16) + lumpNum; + } } } return LUMPERROR; diff --git a/src/w_wad.h b/src/w_wad.h index c0f47708e..84ce9775e 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -69,7 +69,6 @@ typedef struct unsigned long position; // filelump_t filepos unsigned long disksize; // filelump_t size char name[9]; // filelump_t name[] e.g. "LongEntr" - UINT32 hash; char *longname; // e.g. "LongEntryName" char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension" size_t size; // real (uncompressed) size -- 2.54.0 From 3acdcb09f194ad181ddc66d99f469145e80f5b3e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 24 Apr 2024 10:59:09 +0200 Subject: [PATCH 38/59] inline those --- src/qs22j.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qs22j.c b/src/qs22j.c index 53277521e..16dc217bd 100644 --- a/src/qs22j.c +++ b/src/qs22j.c @@ -41,33 +41,33 @@ typedef void *pref_typ; #define COMP(a, b) ((*compar)((void *)(a), (void *)(b))) -static void swapbytes(void *a0, void *b0, size_t n) +static inline void swapbytes(void *a0, void *b0, size_t n) { char *a = a0, *b = b0, t; do {ASWAP(*a, *b, t); a++; b++;} while (--n); } -static void swapdword(void *a0, void *b0, size_t n) +static inline void swapdword(void *a0, void *b0, size_t n) { DWORD *a = a0, *b = b0, t; ASWAP(*a, *b, t); (void)n; } -static void swapdwords(void *a0, void *b0, size_t n) +static inline void swapdwords(void *a0, void *b0, size_t n) { DWORD *a = a0, *b = b0, t; do {ASWAP(*a, *b, t); a++; b++;} while (n -= sizeof(DWORD)); } -static void swapword(void *a0, void *b0, size_t n) +static inline void swapword(void *a0, void *b0, size_t n) { WORD *a = a0, *b = b0, t; ASWAP(*a, *b, t); (void)n; } -static void swapwords(void *a0, void *b0, size_t n) +static inline void swapwords(void *a0, void *b0, size_t n) { WORD *a = a0, *b = b0, t; do {ASWAP(*a, *b, t); a++; b++;} while (n -= sizeof(WORD)); @@ -75,7 +75,7 @@ static void swapwords(void *a0, void *b0, size_t n) typedef void (*swapf_typ)(void *, void *, size_t); -static char *med3(char *a, char *b, char *c, int (*compar)(const void *, const void *)) +static inline char *med3(char *a, char *b, char *c, int (*compar)(const void *, const void *)) { return COMP(a, b) < 0 ? (COMP(b, c) < 0 ? b : COMP(a, c) < 0 ? c : a) : -- 2.54.0 From 62fa60e39952974ac479e9dc3a88ee7f5da89c04 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 25 Apr 2024 17:08:02 +0200 Subject: [PATCH 39/59] fix rare precip crash --- src/p_mobj.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 94226face..c8c9a26b2 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10146,6 +10146,9 @@ void P_SpawnPrecipitation(void) //for (j = 0; j < cv_precipdensity.value; ++j) -- density is 1 for kart always { + INT32 floorz; + INT32 ceilingz; + x = ((cv_lessprecip.value ? basex*1.5 : basex) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); y = ((cv_lessprecip.value ? basey*1.5 : basey) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); @@ -10179,8 +10182,19 @@ void P_SpawnPrecipitation(void) else // everything else. rainmo = P_SpawnRainMobj(x, y, height, MT_RAIN); - // Randomly assign a height, now that floorz is set. - rainmo->z = M_RandomRange(rainmo->floorz>>FRACBITS, rainmo->ceilingz>>FRACBITS)<floorz >> FRACBITS; + ceilingz = rainmo->ceilingz >> FRACBITS; + + if (floorz < ceilingz) + { + // Randomly assign a height, now that floorz is set. + rainmo->z = M_RandomRange(floorz, ceilingz) << FRACBITS; + } + else + { + // ...except if the floor is above the ceiling. + rainmo->z = ceilingz << FRACBITS; + } } } -- 2.54.0 From 641cd6b8db2a289d99f715848ef7c88f14a5ee62 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Apr 2024 20:32:52 +0200 Subject: [PATCH 40/59] use bigfloat for driftgauge offset too --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2dcab703f..f4ce5cf38 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2351,7 +2351,7 @@ static menuitem_t OP_DriftGaugeMenu[] = {IT_HEADER, NULL, "Driftgauge", NULL, 0}, {IT_STRING | IT_CVAR, NULL, "Driftgauge", &cv_driftgauge, 20}, {IT_STRING | IT_CVAR, NULL, "Driftgauge Transparency", &cv_driftgaugetrans, 30}, - {IT_STRING | IT_CVAR, NULL, "Driftgauge Offset", &cv_driftgaugeofs, 40}, + {IT_STRING | IT_CVAR | IT_CV_BIGFLOAT, NULL, "Driftgauge Offset", &cv_driftgaugeofs, 40}, {IT_STRING | IT_CVAR, NULL, "Driftgauge Style", &cv_driftgaugestyle, 50}, }; -- 2.54.0 From 75ed11a8b6e4baf14239080aa09697fca6d01ec4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Apr 2024 10:12:58 +0200 Subject: [PATCH 41/59] simplify SOFTLIGHT alot also should make sure it gets applied everywhere lul --- src/hardware/hw_main.c | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 1d77b76cb..5d73a42ed 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -496,6 +496,8 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col poly_color.s.blue = (UINT8)blue; } + light_level = SOFTLIGHT(light_level); + // Clamp the light level, since it can sometimes go out of the 0-255 range from animations light_level = min(max(light_level, cv_secbright.value), 255); @@ -1111,7 +1113,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (HWR_ShouldUsePaletteRendering()) { - lightnum = SOFTLIGHT(pfloor->master->frontsector->lightlevel); + lightnum = pfloor->master->frontsector->lightlevel; colormap = pfloor->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); }else{ @@ -1123,7 +1125,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (HWR_ShouldUsePaletteRendering()) { - lightnum = SOFTLIGHT(*list[i].lightlevel); + lightnum = *list[i].lightlevel; colormap = list[i].extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); }else{ @@ -1498,7 +1500,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = SOFTLIGHT(gr_frontsector->lightlevel); + lightnum = gr_frontsector->lightlevel; colormap = gr_frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); } @@ -2229,7 +2231,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = SOFTLIGHT(rover->master->frontsector->lightlevel); + lightnum = rover->master->frontsector->lightlevel; colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -2237,7 +2239,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom colormap = rover->master->frontsector->extra_colormap; } - Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(SOFTLIGHT(rover->master->frontsector->lightlevel), rover->master->frontsector->extra_colormap); + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); if (gr_frontsector->numlights) HWR_SplitWall(gr_frontsector, wallVerts, 0, false, &Surf, rover->flags, rover, 0); @@ -2368,7 +2370,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = SOFTLIGHT(rover->master->frontsector->lightlevel); + lightnum = rover->master->frontsector->lightlevel; colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -2376,7 +2378,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom colormap = rover->master->frontsector->extra_colormap; } - Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(SOFTLIGHT(rover->master->frontsector->lightlevel), rover->master->frontsector->extra_colormap); + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); if (gr_backsector->numlights) HWR_SplitWall(gr_backsector, wallVerts, 0, false, &Surf, rover->flags, rover, 0); @@ -3053,13 +3055,13 @@ void HWR_AddPolyObjectPlanes(void) FSurfaceInfo Surf; FBITFIELD blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(levelflats[polyobjsector->floorpic].lumpnum, po_ptrs[i], false, polyobjsector->floorheight, - SOFTLIGHT(polyobjsector->lightlevel), Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); + polyobjsector->lightlevel, Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); } else { HWR_GetFlat(levelflats[polyobjsector->floorpic].lumpnum, R_NoEncore(polyobjsector, false)); HWR_RenderPolyObjectPlane(po_ptrs[i], false, polyobjsector->floorheight, PF_Occlude, - SOFTLIGHT(polyobjsector->lightlevel), levelflats[polyobjsector->floorpic].lumpnum, + polyobjsector->lightlevel, levelflats[polyobjsector->floorpic].lumpnum, polyobjsector, 255, NULL); } } @@ -3075,13 +3077,13 @@ void HWR_AddPolyObjectPlanes(void) memset(&Surf, 0x00, sizeof(Surf)); blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(levelflats[polyobjsector->ceilingpic].lumpnum, po_ptrs[i], true, polyobjsector->ceilingheight, - SOFTLIGHT(polyobjsector->lightlevel), Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); + polyobjsector->lightlevel, Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); } else { HWR_GetFlat(levelflats[polyobjsector->ceilingpic].lumpnum, R_NoEncore(polyobjsector, true)); HWR_RenderPolyObjectPlane(po_ptrs[i], true, polyobjsector->ceilingheight, PF_Occlude, - SOFTLIGHT(polyobjsector->lightlevel), levelflats[polyobjsector->ceilingpic].lumpnum, + polyobjsector->lightlevel, levelflats[polyobjsector->ceilingpic].lumpnum, polyobjsector, 255, NULL); } } @@ -3223,12 +3225,12 @@ static void HWR_Subsector(size_t num) light = R_GetPlaneLight(gr_frontsector, locFloorHeight, false); if (gr_frontsector->floorlightsec == -1) - floorlightlevel = SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel); + floorlightlevel = *gr_frontsector->lightlist[light].lightlevel; floorcolormap = gr_frontsector->lightlist[light].extra_colormap; light = R_GetPlaneLight(gr_frontsector, locCeilingHeight, false); if (gr_frontsector->ceilinglightsec == -1) - ceilinglightlevel = SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel); + ceilinglightlevel = *gr_frontsector->lightlist[light].lightlevel; ceilingcolormap = gr_frontsector->lightlist[light].extra_colormap; } @@ -3305,13 +3307,13 @@ static void HWR_Subsector(size_t num) light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < bottomCullHeight ? true : false); - alpha = HWR_FogBlockAlpha(SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), rover->master->frontsector->extra_colormap); + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); HWR_AddTransparentFloor(0, &extrasubsectors[num], false, *rover->bottomheight, - SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), + *gr_frontsector->lightlist[light].lightlevel, alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } @@ -3322,7 +3324,7 @@ static void HWR_Subsector(size_t num) &extrasubsectors[num], false, *rover->bottomheight, - SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), + *gr_frontsector->lightlist[light].lightlevel, max(0, min(rover->alpha, 255)), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } @@ -3330,7 +3332,7 @@ static void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->bottompic].lumpnum, R_NoEncore(gr_frontsector, false)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < bottomCullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), levelflats[*rover->bottompic].lumpnum, + HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -3349,13 +3351,13 @@ static void HWR_Subsector(size_t num) light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < topCullHeight ? true : false); - alpha = HWR_FogBlockAlpha(SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), rover->master->frontsector->extra_colormap); + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); HWR_AddTransparentFloor(0, &extrasubsectors[num], true, *rover->topheight, - SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), + *gr_frontsector->lightlist[light].lightlevel, alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } @@ -3366,7 +3368,7 @@ static void HWR_Subsector(size_t num) &extrasubsectors[num], true, *rover->topheight, - SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), + *gr_frontsector->lightlist[light].lightlevel, max(0, min(rover->alpha, 255)), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } @@ -3374,7 +3376,7 @@ static void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->toppic].lumpnum, R_NoEncore(gr_frontsector, true)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < topCullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), levelflats[*rover->toppic].lumpnum, + HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -3998,7 +4000,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) alpha = Surf.PolyColor.s.alpha; // Start with the lightlevel and colormap from the top of the sprite - lightlevel = SOFTLIGHT(*list[sector->numlights - 1].lightlevel); + lightlevel = *list[sector->numlights - 1].lightlevel; colormap = list[sector->numlights - 1].extra_colormap; i = 0; @@ -4013,7 +4015,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (h <= temp) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i-1].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i-1].lightlevel); + lightlevel = *list[i-1].lightlevel > 255 ? 255 : *list[i-1].lightlevel; colormap = list[i-1].extra_colormap; break; } @@ -4028,7 +4030,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (!(list[i].flags & FF_NOSHADE) && (list[i].flags & FF_CUTSPRITES)) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i].lightlevel); + lightlevel = *list[i].lightlevel > 255 ? 255 : *list[i].lightlevel; colormap = list[i].extra_colormap; } @@ -4247,7 +4249,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) extracolormap_t *colormap = sector->extra_colormap; if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel > 255 ? 255 : SOFTLIGHT(sector->lightlevel); + lightlevel = sector->lightlevel > 255 ? 255 : sector->lightlevel; HWR_Lighting(&Surf, lightlevel, colormap); } @@ -4348,7 +4350,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_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 = *sector->lightlist[light].lightlevel > 255 ? 255 : SOFTLIGHT(*sector->lightlist[light].lightlevel); + lightlevel = *sector->lightlist[light].lightlevel > 255 ? 255 : *sector->lightlist[light].lightlevel; if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4356,7 +4358,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel > 255 ? 255 : SOFTLIGHT(sector->lightlevel); + lightlevel = sector->lightlevel > 255 ? 255 : sector->lightlevel; if (sector->extra_colormap) colormap = sector->extra_colormap; @@ -4418,8 +4420,6 @@ static int CompareVisSprites(const void *p1, const void *p2) return -1; } -#undef SOFTLIGHT - static void HWR_SortVisSprites(void) { UINT32 i; -- 2.54.0 From 22166ceccb536ce2dbeeb67a36360b71f851667a Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 May 2024 20:46:20 +0200 Subject: [PATCH 42/59] fix precip overflow --- src/p_mobj.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index c8c9a26b2..608d9e821 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10283,7 +10283,8 @@ void P_PrecipitationEffects(void) volume = 255; // Sky above? We get it full blast. else { - fixed_t x, y, yl, yh, xl, xh; + /* GCC is optimizing away y >= yl, FUCK YOU */ + volatile fixed_t x, y, yl, yh, xl, xh; fixed_t closedist, newdist; // Essentially check in a 1024 unit radius of the player for an outdoor area. @@ -10292,8 +10293,8 @@ void P_PrecipitationEffects(void) xl = players[displayplayers[0]].mo->x - 1024*FRACUNIT; xh = players[displayplayers[0]].mo->x + 1024*FRACUNIT; closedist = 2048*FRACUNIT; - for (y = yl; y <= yh; y += FRACUNIT*64) - for (x = xl; x <= xh; x += FRACUNIT*64) + for (y = yl; y >= yl && y <= yh; y += FRACUNIT*64) + for (x = xl; x >= xl && x <= xh; x += FRACUNIT*64) { if (R_PointInSubsector(x, y)->sector->ceilingpic == skyflatnum) // Found the outdoors! { -- 2.54.0 From 13249f7ad4273f167e628c2e9e1bfd9317667bc6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 May 2024 20:49:51 +0200 Subject: [PATCH 43/59] fix potential crash in ogl vissprite sorting --- src/hardware/hw_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5d73a42ed..5bb5ff370 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4406,8 +4406,9 @@ static int CompareVisSprites(const void *p1, const void *p2) // make transparent sprites last // "boolean to int" - int transparency1 = (spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK); - int transparency2 = (spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK); + 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); + idiff = transparency1 - transparency2; if (idiff != 0) return idiff; -- 2.54.0 From e19f6f6656409b6a487dbb6f761ff3bc90daea33 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 May 2024 20:52:06 +0200 Subject: [PATCH 44/59] fix some interpolation issues minus P_spec change since that aint netsafe --- src/g_game.c | 2 ++ src/p_telept.c | 6 +++++- src/p_tick.c | 8 +++++++- src/p_user.c | 1 - src/r_fps.c | 13 +++++++++++-- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index d692863e9..e8d91f95c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2117,6 +2117,8 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) { camerap = &camera[viewnum-1]; P_ResetCamera(&players[(*displayplayerp)], camerap); + + R_ResetViewInterpolation(viewnum); } if (viewnum > splits) diff --git a/src/p_telept.c b/src/p_telept.c index 7c9da2269..9229079c9 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -82,8 +82,12 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, // move chasecam at new player location for (i = 0; i <= splitscreen; i++) { - if (thing->player == &players[displayplayers[i]] && camera[i].chase) + if (thing->player != &players[displayplayers[i]]) + continue; + if (camera[i].chase) P_ResetCamera(thing->player, &camera[i]); + R_ResetViewInterpolation(i + 1); + break; } // don't run in place after a teleport diff --git a/src/p_tick.c b/src/p_tick.c index 183c42a4b..6416142ce 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -581,6 +581,13 @@ void P_Ticker(boolean run) if (playeringame[i]) ++players[i].jointime; + if (run) + { + // Update old view state BEFORE ticking so resetting + // the old interpolation state from game logic works. + R_UpdateViewInterpolation(); + } + if (objectplacing) { if (OP_FreezeObjectplace()) @@ -827,7 +834,6 @@ void P_Ticker(boolean run) if (run) { R_UpdateLevelInterpolators(); - R_UpdateViewInterpolation(); // Hack: ensure newview is assigned every tic. // Ensures view interpolation is T-1 to T in poor network conditions diff --git a/src/p_user.c b/src/p_user.c index 75f5b37cb..6b076a132 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3959,7 +3959,6 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall { P_MoveChaseCamera(player, thiscam, false); R_ResetViewInterpolation(num + 1); - R_ResetViewInterpolation(num + 1); } return (x == thiscam->x && y == thiscam->y && z == thiscam->z && angle == thiscam->aiming); diff --git a/src/r_fps.c b/src/r_fps.c index 44518ea4d..91044b42e 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -23,6 +23,8 @@ #include "r_state.h" #include "z_zone.h" #include "console.h" // con_startup_loadprogress +#include "i_time.h" + #ifdef HWRENDER #include "hardware/hw_main.h" // for cv_grshearing #endif @@ -80,6 +82,7 @@ static viewvars_t skyview_old[MAXSPLITSCREENPLAYERS]; static viewvars_t skyview_new[MAXSPLITSCREENPLAYERS]; static viewvars_t *oldview = &pview_old[0]; +static tic_t last_view_update; static int oldview_invalid[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; viewvars_t *newview = &pview_new[0]; @@ -200,21 +203,27 @@ void R_UpdateViewInterpolation(void) if (oldview_invalid[i]) oldview_invalid[i]--; } + + last_view_update = I_GetTime(); } void R_ResetViewInterpolation(UINT8 p) { + // Wait an extra tic if the interpolation state hasn't + // updated yet. + int t = last_view_update == I_GetTime() ? 1 : 2; + if (p == 0) { UINT8 i; for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - oldview_invalid[i]++; + oldview_invalid[i] = t; } } else { - oldview_invalid[p - 1]++; + oldview_invalid[p - 1] = t; } } -- 2.54.0 From 169e7cd462d6d96bf3d10db96b9af3d9178cca82 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 May 2024 21:52:48 +0200 Subject: [PATCH 45/59] Render precip through blockmap instead of during BSP from RR --- src/hardware/hw_main.c | 60 ++++++++++++++++++++++++------------ src/p_local.h | 1 + src/p_maputl.c | 70 ++++++++++++++++++++++++------------------ src/p_mobj.h | 12 ++++---- src/p_setup.c | 45 ++++++++------------------- src/r_defs.h | 1 - src/r_main.c | 31 ++++++++++++++++++- src/r_main.h | 1 + src/r_things.c | 40 ++++++++++++++++++------ src/r_things.h | 1 + src/tables.h | 5 +++ 11 files changed, 168 insertions(+), 99 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5bb5ff370..4f5475a67 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -265,6 +265,8 @@ ps_metric_t ps_hw_numcolors = {0}; ps_metric_t ps_hw_batchsorttime = {0}; ps_metric_t ps_hw_batchdrawtime = {0}; +static void HWR_AddPrecipitationSprites(void); + // ========================================================================== // View position // ========================================================================== @@ -4749,8 +4751,7 @@ void HWR_DrawSprites(void) void HWR_AddSprites(sector_t *sec) { mobj_t *thing; - precipmobj_t *precipthing; - fixed_t approx_dist, limit_dist, precip_limit_dist; + fixed_t approx_dist, limit_dist; INT32 splitflags; boolean split_drawsprite; // drawing with splitscreen flags @@ -4772,13 +4773,9 @@ void HWR_AddSprites(sector_t *sec) limit_dist = min(current_bsp_culling_distance, cv_drawdist.value << FRACBITS); else limit_dist = current_bsp_culling_distance; - precip_limit_dist = min(current_bsp_culling_distance, cv_drawdist_precip.value << FRACBITS); } else - { limit_dist = cv_drawdist.value << FRACBITS; - precip_limit_dist = cv_drawdist_precip.value << FRACBITS; - } // Handle all things in sector. // If a limit exists, handle things a tiny bit different. @@ -4786,7 +4783,6 @@ void HWR_AddSprites(sector_t *sec) { for (thing = sec->thinglist; thing; thing = thing->snext) { - split_drawsprite = false; if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW) @@ -4831,7 +4827,6 @@ void HWR_AddSprites(sector_t *sec) // Draw everything in sector, no checks for (thing = sec->thinglist; thing; thing = thing->snext) { - split_drawsprite = false; if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW) @@ -4866,21 +4861,46 @@ void HWR_AddSprites(sector_t *sec) HWR_ProjectSprite(thing); } } +} + +// -------------------------------------------------------------------------- +// HWR_AddPrecipitationSprites +// This renders through the blockmap instead of BSP to avoid +// iterating a huge amount of precipitation sprites in sectors +// that are beyond drawdist. +// -------------------------------------------------------------------------- +static void HWR_AddPrecipitationSprites(void) +{ + //const fixed_t drawdist = cv_drawdist_precip.value * mapobjectscale; + fixed_t drawdist; + + INT32 xl, xh, yl, yh, bx, by; + precipmobj_t *th; + + if (current_bsp_culling_distance) + drawdist = min(current_bsp_culling_distance, cv_drawdist_precip.value * mapobjectscale); + else + drawdist = cv_drawdist_precip.value * mapobjectscale; // No to infinite precipitation draw distance. - if (precip_limit_dist) + if (drawdist == 0) { - for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext) + return; + } + + R_GetRenderBlockMapDimensions(drawdist, &xl, &xh, &yl, &yh); + + for (bx = xl; bx <= xh; bx++) + { + for (by = yl; by <= yh; by++) { - if (precipthing->precipflags & PCF_INVISIBLE) - continue; + for (th = precipblocklinks[(by * bmapwidth) + bx]; th; th = th->bnext) + { + if (th->precipflags & PCF_INVISIBLE) + continue; - approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); - - if (approx_dist > precip_limit_dist) - continue; - - HWR_ProjectPrecipitationSprite(precipthing); + HWR_ProjectPrecipitationSprite(th); + } } } } @@ -5708,6 +5728,8 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe if (cv_grbatching.value) HWR_StartBatching(); + HWR_AddPrecipitationSprites(); + ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; PS_START_TIMING(ps_bsptime); @@ -5727,7 +5749,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe gr_portal = oldgl_portal_state; PS_STOP_TIMING(ps_bsptime); - + if (cv_grbatching.value) HWR_RenderBatches(); diff --git a/src/p_local.h b/src/p_local.h index dc473b648..e1a07526a 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -387,6 +387,7 @@ extern INT32 bmapheight; // in mapblocks extern fixed_t bmaporgx; extern fixed_t bmaporgy; // origin of block map extern mobj_t **blocklinks; // for thing chains +extern precipmobj_t **precipblocklinks; // special blockmap for precip rendering // // P_INTER diff --git a/src/p_maputl.c b/src/p_maputl.c index c680931d0..3c91dc922 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -754,15 +754,45 @@ void P_UnsetThingPosition(mobj_t *thing) void P_UnsetPrecipThingPosition(precipmobj_t *thing) { - precipmobj_t **sprev = thing->sprev; - precipmobj_t *snext = thing->snext; - if ((*sprev = snext) != NULL) // unlink from sector list - snext->sprev = sprev; + precipmobj_t **bprev = thing->bprev; + precipmobj_t *bnext = thing->bnext; + + if (bprev && (*bprev = bnext) != NULL) // unlink from block map + bnext->bprev = bprev; precipsector_list = thing->touching_sectorlist; thing->touching_sectorlist = NULL; //to be restored by P_SetPrecipThingPosition } +static void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap) +{ + const INT32 blockx = (unsigned)(thing->x - bmaporgx) >> MAPBLOCKSHIFT; + const INT32 blocky = (unsigned)(thing->y - bmaporgy) >> MAPBLOCKSHIFT; + + if (blockx >= 0 && blockx < bmapwidth + && blocky >= 0 && blocky < bmapheight) + { + // killough 8/11/98: simpler scheme using + // pointer-to-pointer prev pointers -- + // allows head nodes to be treated like everything else + + mobj_t **link = &bmap[(blocky * bmapwidth) + blockx]; + mobj_t *bnext = *link; + + thing->bnext = bnext; + + if (bnext != NULL) + bnext->bprev = &thing->bnext; + + thing->bprev = link; + *link = thing; + } + else // thing is off the map + { + thing->bnext = NULL, thing->bprev = NULL; + } +} + // // P_SetThingPosition // Links a thing into both a block and a subsector @@ -819,24 +849,7 @@ void P_SetThingPosition(mobj_t *thing) if (!(thing->flags & MF_NOBLOCKMAP)) { // inert things don't need to be in blockmap - const INT32 blockx = (unsigned)(thing->x - bmaporgx)>>MAPBLOCKSHIFT; - const INT32 blocky = (unsigned)(thing->y - bmaporgy)>>MAPBLOCKSHIFT; - if (blockx >= 0 && blockx < bmapwidth - && blocky >= 0 && blocky < bmapheight) - { - // killough 8/11/98: simpler scheme using - // pointer-to-pointer prev pointers -- - // allows head nodes to be treated like everything else - - mobj_t **link = &blocklinks[blocky*bmapwidth + blockx]; - mobj_t *bnext = *link; - if ((thing->bnext = bnext) != NULL) - bnext->bprev = &thing->bnext; - thing->bprev = link; - *link = thing; - } - else // thing is off the map - thing->bnext = NULL, thing->bprev = NULL; + P_LinkToBlockMap(thing, blocklinks); } // Allows you to 'step' on a new linedef exec when the previous @@ -891,18 +904,15 @@ void P_SetUnderlayPosition(mobj_t *thing) void P_SetPrecipitationThingPosition(precipmobj_t *thing) { - subsector_t *ss = thing->subsector = R_PointInSubsector(thing->x, thing->y); - - precipmobj_t **link = &ss->sector->preciplist; - precipmobj_t *snext = *link; - if ((thing->snext = snext) != NULL) - snext->sprev = &thing->snext; - thing->sprev = link; - *link = thing; + thing->subsector = R_PointInSubsector(thing->x, thing->y); P_CreatePrecipSecNodeList(thing, thing->x, thing->y); thing->touching_sectorlist = precipsector_list; // Attach to Thing's precipmobj_t precipsector_list = NULL; // clear for next time + + // NOTE: this works because bnext/bprev are at the same + // offsets in precipmobj_t and mobj_t + P_LinkToBlockMap((mobj_t*)thing, (mobj_t**)precipblocklinks); } // diff --git a/src/p_mobj.h b/src/p_mobj.h index 5d26f9b44..a824edc6a 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -279,8 +279,8 @@ typedef struct mobj_s fixed_t old_x2, old_y2, old_z2; // More list: links in sector (if needed) - struct mobj_s *snext; - struct mobj_s **sprev; // killough 8/11/98: change to ptr-to-ptr + struct mobj_s *bnext; + struct mobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr // More drawing info: to determine current sprite. angle_t angle, pitch, roll; // orientation @@ -338,8 +338,8 @@ typedef struct mobj_s // Interaction info, by BLOCKMAP. // Links in blocks (if needed). - struct mobj_s *bnext; - struct mobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr + struct mobj_s *snext; + struct mobj_s **sprev; // killough 8/11/98: change to ptr-to-ptr // Additional pointers for NiGHTS hoops struct mobj_s *hnext; @@ -432,8 +432,8 @@ typedef struct precipmobj_s fixed_t old_x2, old_y2, old_z2; // More list: links in sector (if needed) - struct precipmobj_s *snext; - struct precipmobj_s **sprev; // killough 8/11/98: change to ptr-to-ptr + struct precipmobj_s *bnext; + struct precipmobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr // More drawing info: to determine current sprite. angle_t angle, pitch, roll; // orientation diff --git a/src/p_setup.c b/src/p_setup.c index 9ae36afc9..c99326116 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -127,6 +127,7 @@ INT32 *blockmaplump; // Big blockmap fixed_t bmaporgx, bmaporgy; // for thing chains mobj_t **blocklinks; +precipmobj_t **precipblocklinks; // REJECT // For fast sight rejection. @@ -714,7 +715,7 @@ static void P_LoadRawSectors(UINT8 *data, size_t i) ss->thinglist = NULL; ss->touching_thinglist = NULL; - ss->preciplist = NULL; + ss->touching_preciplist = NULL; ss->floordata = NULL; @@ -1948,6 +1949,9 @@ static void P_CreateBlockMap(void) // haleyjd 2/22/06: setup polyobject blockmap count = sizeof(*polyblocklinks) * bmapwidth * bmapheight; polyblocklinks = Z_Calloc(count, PU_LEVEL, NULL); + + count = sizeof (*precipblocklinks)* bmapwidth*bmapheight; + precipblocklinks = Z_Calloc(count, PU_LEVEL, NULL); } } @@ -1982,10 +1986,6 @@ static void P_ReadBlockMapLump(INT16 *wadblockmaplump, size_t count) // this should return false. static boolean P_LoadBlockMap(lumpnum_t lumpnum) { -#if 0 - (void)lumpnum; - return false; -#else size_t count; const char *lumpname = W_CheckNameForNum(lumpnum); @@ -2023,27 +2023,11 @@ static boolean P_LoadBlockMap(lumpnum_t lumpnum) // haleyjd 2/22/06: setup polyobject blockmap count = sizeof(*polyblocklinks) * bmapwidth * bmapheight; polyblocklinks = Z_Calloc(count, PU_LEVEL, NULL); + + count = sizeof (*precipblocklinks)* bmapwidth*bmapheight; + precipblocklinks = Z_Calloc(count, PU_LEVEL, NULL); + return true; -/* Original - blockmaplump = W_CacheLumpNum(lump, PU_LEVEL); - blockmap = blockmaplump+4; - count = W_LumpLength (lump)/2; - - for (i = 0; i < count; i++) - blockmaplump[i] = SHORT(blockmaplump[i]); - - bmaporgx = blockmaplump[0]<>MAPBLOCKSHIFT; + *xh = (unsigned)(max(viewx, max(vxleft, vxright)) - bmaporgx)>>MAPBLOCKSHIFT; + *yl = (unsigned)(min(viewy, min(vyleft, vyright)) - bmaporgy)>>MAPBLOCKSHIFT; + *yh = (unsigned)(max(viewy, max(vyleft, vyright)) - bmaporgy)>>MAPBLOCKSHIFT; + + if (*xh >= bmapwidth) + *xh = bmapwidth - 1; + + if (*yh >= bmapheight) + *yh = bmapheight - 1; + + BMBOUNDFIX(*xl, *xh, *yl, *yh); +} + // // R_InitTextureMapping // @@ -1728,11 +1756,12 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_bsptime); R_RenderBSPNode((INT32)numnodes - 1); PS_STOP_TIMING(ps_bsptime); + R_AddPrecipitationSprites(); PS_START_TIMING(ps_sw_spritecliptime); R_ClipSprites(); PS_STOP_TIMING(ps_sw_spritecliptime); - ps_numsprites.value.i = numvisiblesprites; + //ps_numsprites.value.i = numvisiblesprites; // PORTAL RENDERING PS_START_TIMING(ps_sw_portaltime); diff --git a/src/r_main.h b/src/r_main.h index b3f38e156..56e351138 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -80,6 +80,7 @@ subsector_t *R_PointInSubsector(fixed_t x, fixed_t y); subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph); +void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 *yl, INT32 *yh); // Performance stats extern precise_t ps_prevframetime;// time when previous frame was rendered diff --git a/src/r_things.c b/src/r_things.c index c66ca9f58..dfe05dbdf 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1897,7 +1897,6 @@ weatherthink: void R_AddSprites(sector_t *sec, INT32 lightlevel) { mobj_t *thing; - precipmobj_t *precipthing; // Tails 08-25-2002 INT32 lightnum; fixed_t approx_dist, limit_dist; @@ -2016,21 +2015,42 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) R_ProjectSprite(thing); } } +} + +// R_AddPrecipitationSprites +// This renders through the blockmap instead of BSP to avoid +// iterating a huge amount of precipitation sprites in sectors +// that are beyond drawdist. +// +void R_AddPrecipitationSprites(void) +{ + const fixed_t drawdist = cv_drawdist_precip.value * mapobjectscale; + + INT32 xl, xh, yl, yh, bx, by; + precipmobj_t *th, *next; + + if (drawdist == 0) + { + return; + } + + R_GetRenderBlockMapDimensions(drawdist, &xl, &xh, &yl, &yh); // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off - if ((limit_dist = (fixed_t)cv_drawdist_precip.value << FRACBITS)) + for (bx = xl; bx <= xh; bx++) { - for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext) + for (by = yl; by <= yh; by++) { - if (precipthing->precipflags & PCF_INVISIBLE) - continue; + for (th = precipblocklinks[(by * bmapwidth) + bx]; th; th = next) + { + // Store this beforehand because R_ProjectPrecipitionSprite may free th (see P_PrecipThinker) + next = th->bnext; - approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); + if (th->precipflags & PCF_INVISIBLE) + continue; - if (approx_dist > limit_dist) - continue; - - R_ProjectPrecipitationSprite(precipthing); + R_ProjectPrecipitationSprite(th); + } } } } diff --git a/src/r_things.h b/src/r_things.h index b9e05022e..88e1abdab 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -67,6 +67,7 @@ void R_AddSpriteDefs(UINT16 wadnum); //SoM: 6/5/2000: Light sprites correctly! void R_AddSprites(sector_t *sec, INT32 lightlevel); +void R_AddPrecipitationSprites(void); void R_InitSprites(void); void R_ClearSprites(void); void R_DrawMasked(void); diff --git a/src/tables.h b/src/tables.h index 353bf591f..761a6499e 100644 --- a/src/tables.h +++ b/src/tables.h @@ -24,6 +24,7 @@ #define FINEMASK (FINEANGLES - 1) #define ANGLETOFINESHIFT 19 // 0x100000000 to 0x2000 #define FINEANGLE_C(x) ((FixedAngle((x)*FRACUNIT)>>ANGLETOFINESHIFT) & FINEMASK) // ((x*(ANGLE_45/45))>>ANGLETOFINESHIFT) & FINEMASK +#define ANGLETOFINE(x) (((x)>>ANGLETOFINESHIFT) & FINEMASK) // Effective size is 10240. extern fixed_t finesine[5*FINEANGLES/4]; @@ -121,4 +122,8 @@ void FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z); #define FINECOSINE(n) (finecosine[n]>>(FINE_FRACBITS-FRACBITS)) #define FINETANGENT(n) (finetangent[n]>>(FINE_FRACBITS-FRACBITS)) +// FSIN(ANGLE_90) = FRACUNIT +#define FSIN(n) FINESINE(ANGLETOFINE(n)) +#define FCOS(n) FINECOSINE(ANGLETOFINE(n)) + #endif -- 2.54.0 From d1d00d7ec6ab401d1bcf8edd57cac285c3d8792f Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 May 2024 22:00:22 +0200 Subject: [PATCH 46/59] shut up compiler --- src/hardware/hw_main.c | 4 ++-- src/r_main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4f5475a67..f373706ab 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4408,8 +4408,8 @@ static int CompareVisSprites(const void *p1, const void *p2) // make transparent sprites last // "boolean to int" - 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); + 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); idiff = transparency1 - transparency2; if (idiff != 0) return idiff; diff --git a/src/r_main.c b/src/r_main.c index 10fb24f79..a15258c48 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1761,7 +1761,7 @@ void R_RenderPlayerView(player_t *player) R_ClipSprites(); PS_STOP_TIMING(ps_sw_spritecliptime); - //ps_numsprites.value.i = numvisiblesprites; + ps_numsprites.value.i = numvisiblesprites; // PORTAL RENDERING PS_START_TIMING(ps_sw_portaltime); -- 2.54.0 From 57e72db1f8927111ebbaae092aec006d4bc014d0 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 May 2024 20:48:32 +0200 Subject: [PATCH 47/59] support gcc14 ig --- src/Makefile.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.cfg b/src/Makefile.cfg index c97b4d5a9..a616586c9 100644 --- a/src/Makefile.cfg +++ b/src/Makefile.cfg @@ -12,6 +12,7 @@ # to avoid a false positive with the version detection... SUPPORTED_GCC_VERSIONS:=\ + 141 14\ 132 131 130 13\ 123 122 121 120 12\ 114 113 112 111 110 11\ -- 2.54.0 From 1ab63613a9b685981600db2234d54298150ec3c1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 15 May 2024 16:54:27 +0200 Subject: [PATCH 48/59] forgor this crap --- src/Makefile.cfg | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Makefile.cfg b/src/Makefile.cfg index a616586c9..77779f7d5 100644 --- a/src/Makefile.cfg +++ b/src/Makefile.cfg @@ -24,7 +24,7 @@ SUPPORTED_GCC_VERSIONS:=\ 55 54 53 52 51 50\ 49 48 47 46 45 44 43 42 41 40 -LATEST_GCC_VERSION=13.2 +LATEST_GCC_VERSION=14.1 # gcc or g++ ifdef PREFIX @@ -78,6 +78,14 @@ ifeq (,$(filter GCC%,$(.VARIABLES))) endif endif +ifdef GCC141 +GCC141=1 +endif + +ifdef GCC14 +GCC14=1 +endif + ifdef GCC132 GCC131=1 endif -- 2.54.0 From 39e6668e2041aefd8e07473db9901e18e765a503 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 15 May 2024 17:51:11 +0200 Subject: [PATCH 49/59] change version --- src/doomdef.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index d1bbe04e0..d71aaeb8a 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -127,8 +127,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v6.1 " -#define VERSIONSTRINGW L"Saturn v6.1" +#define VERSIONSTRING "Saturn v6.2 " +#define VERSIONSTRINGW L"Saturn v6.2" // Hey! If you change this, add 1 to the MODVERSION below! Otherwise we can't force updates! // And change CMakeLists.txt (not src/, but in root), for CMake users! // AND appveyor.yml, for the build bots! -- 2.54.0 From af5c3e42013f5e04131ca736cad878127179e848 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 15 May 2024 17:56:58 +0200 Subject: [PATCH 50/59] revert this thing --- src/g_game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index e8d91f95c..8352d0b98 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5899,7 +5899,7 @@ void G_GhostTicker(void) if (ziptic & EZT_THOKMASK) { // Let's only spawn ONE of these per frame, thanks. mobj_t *mobj; - UINT32 type = MT_NULL; + INT32 type = -1; if (g->mo->skin) { switch (ziptic & EZT_THOKMASK) -- 2.54.0 From 978cc57889a7799368c6f660686d74a04007f274 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 22:57:25 +0200 Subject: [PATCH 51/59] Add NOSCREENFBO compiler flag to be able to build without fbo support --- src/CMakeLists.txt | 6 ++++++ src/Makefile | 8 ++++++++ src/hardware/hw_defs.h | 2 ++ src/hardware/hw_main.c | 12 +++++++++++- src/hardware/hw_main.h | 2 ++ src/hardware/r_opengl/r_opengl.c | 13 +++++++++++++ src/hardware/r_opengl/r_opengl.h | 2 +- src/sdl/i_video.c | 12 ++++++------ src/sdl/ogl_sdl.c | 11 ++++++++++- 9 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca94f1b95..74833b216 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -216,6 +216,8 @@ set(SRB2_CONFIG_HWRENDER ON CACHE BOOL "Enable hardware rendering through OpenGL.") set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL "Use statically linked OpenGL. NOT RECOMMENDED.") +set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL + "Enable OpenGL FBO Downsampling support.") ### use internal libraries? if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only @@ -510,6 +512,10 @@ if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) endif() endif() +if(${SRB2_CONFIG_USE_FBO_OGL}) + set(SRB2_USE_FBO_OGL ON) + add_definitions(-DUSE_FBO_OGL) +endif() # Targets diff --git a/src/Makefile b/src/Makefile index bc4eb6f3d..72a083b88 100644 --- a/src/Makefile +++ b/src/Makefile @@ -199,6 +199,10 @@ ifndef NOOPENMPT HAVE_OPENMPT=1 endif +ifndef NOSCREENFBO +USE_FBO_OGL=1 +endif + ifdef MINGW include win32/Makefile.cfg endif #ifdef MINGW @@ -372,6 +376,10 @@ ifdef STATIC LIBS:=-static $(LIBS) endif +ifdef USE_FBO_OGL +OPTS+=-DUSE_FBO_OGL +endif + ifdef HAVE_MINIUPNPC ifdef NONET HAVE_MINIUPNPC='' diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 85b6b58a2..b55c10bb9 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -287,7 +287,9 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { +#ifdef USE_FBO_OGL HWD_SET_FRAMEBUFFER, +#endif HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0e4b22499..b52612582 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,7 +69,9 @@ static boolean gr_palette_rendering_state = false; // Commands and console variables // ========================================================================== +#ifdef USE_FBO_OGL static void CV_grframebuffer_OnChange(void); +#endif static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); @@ -97,7 +99,9 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +#ifdef USE_FBO_OGL consvar_t cv_grframebuffer = {"gr_framebuffer", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, CV_grframebuffer_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -213,6 +217,7 @@ static void CV_grpalettedepth_OnChange(void) HWR_SetPalette(pLocalPalette); } +#ifdef USE_FBO_OGL static void CV_grframebuffer_OnChange(void) { ONLY_IF_GL_LOADED @@ -220,6 +225,7 @@ static void CV_grframebuffer_OnChange(void) I_DownSample(); RefreshSDLSurface(); } +#endif // // Sets the shader state. @@ -5976,7 +5982,9 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { +#ifdef USE_FBO_OGL CV_RegisterVar(&cv_grframebuffer); +#endif CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -6039,8 +6047,10 @@ void HWR_Startup(void) HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); - + +#ifdef USE_FBO_OGL HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); +#endif if (msaa) { diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 8cc80a34e..1c51e2981 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -152,7 +152,9 @@ void HWR_SetShaderState(void); // Console variables extern consvar_t cv_grshaders; +#ifdef USE_FBO_OGL extern consvar_t cv_grframebuffer; +#endif extern consvar_t cv_grfofcut; extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 85ca35641..9a0eac7b5 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -119,10 +119,12 @@ static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; static GLint viewport[4]; +#ifdef USE_FBO_OGL static boolean GLFramebuffer_IsFuncAvailible(void); GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; +#endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels @@ -433,6 +435,7 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; +#ifdef USE_FBO_OGL /* 3.0 functions for framebuffers and renderbuffers */ typedef void (APIENTRY * PFNglGenFramebuffers) (GLsizei n, GLuint *ids); static PFNglGenFramebuffers pglGenFramebuffers; @@ -454,6 +457,8 @@ typedef void (APIENTRY * PFNglRenderbufferStorage) (GLenum target, GLenum intern static PFNglRenderbufferStorage pglRenderbufferStorage; typedef void (APIENTRY * PFNglFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLenum renderbuffer); static PFNglFramebufferRenderbuffer pglFramebufferRenderbuffer; +#endif // USE_FBO_OGL + #endif //!STATIC_OPENGL /* 1.2 functions for 3D textures */ @@ -739,6 +744,7 @@ void SetupGLFunc4(void) pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); +#ifdef USE_FBO_OGL if (GLFramebuffer_IsFuncAvailible()) { pglGenFramebuffers = GetGLFunc("glGenFramebuffers"); @@ -752,14 +758,17 @@ void SetupGLFunc4(void) pglRenderbufferStorage = GetGLFunc("glRenderbufferStorage"); pglFramebufferRenderbuffer = GetGLFunc("glFramebufferRenderbuffer"); } +#endif } +#ifdef USE_FBO_OGL static boolean GLFramebuffer_IsFuncAvailible(void) { return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); } +#endif EXPORT boolean HWRAPI(InitShaders) (void) { @@ -1020,6 +1029,7 @@ EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) pTexInfo->downloaded = 0; } +#ifdef USE_FBO_OGL void GLFramebuffer_Generate(void) { if (!GLFramebuffer_IsFuncAvailible()) @@ -1129,6 +1139,7 @@ void GLFramebuffer_Disable(void) pglBindFramebuffer(GL_FRAMEBUFFER, 0); pglBindRenderbuffer(GL_RENDERBUFFER, 0); } +#endif // -----------------+ // Flush : flush OpenGL textures @@ -2305,12 +2316,14 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_SHADERS: gl_allowshaders = Value; break; +#ifdef USE_FBO_OGL case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; if (!GLFramebuffer_IsFuncAvailible()) FrameBufferEnabled = GL_FALSE; break; +#endif case HWD_SET_TEXTUREFILTERMODE: switch (Value) { diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 303f95301..a4d8819e3 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -104,7 +104,7 @@ static PFNglEnableClientState pglEnableClientState; #endif #endif -#ifdef GL_VERSION_3_0 +#ifdef USE_FBO_OGL void GLFramebuffer_Generate(void); void GLFramebuffer_Delete(void); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ef6f743d1..b898a8e48 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -215,7 +215,7 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); -#ifdef HWRENDER +#ifdef USE_FBO_OGL boolean downsample = false; void RefreshSDLSurface(void) { @@ -745,7 +745,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } -#ifdef HWRENDER +#ifdef USE_FBO_OGL void I_DownSample(void) { if (!cv_grframebuffer.value || !(rendermode == render_opengl)) @@ -777,7 +777,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; -#ifdef HWRENDER +#ifdef USE_FBO_OGL static SDL_bool windowmoved = SDL_FALSE; #endif @@ -799,7 +799,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; -#ifdef HWRENDER +#ifdef USE_FBO_OGL case SDL_WINDOWEVENT_MOVED: windowmoved = SDL_TRUE; break; @@ -843,7 +843,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } } -#ifdef HWRENDER +#ifdef USE_FBO_OGL if (windowmoved && rendermode == render_opengl) { I_DownSample(); @@ -1927,7 +1927,7 @@ INT32 VID_SetMode(INT32 modeNum) } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); -#ifdef HWRENDER +#ifdef USE_FBO_OGL if (rendermode == render_opengl) I_DownSample(); #endif diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index dc8b479e7..edc9cdb6b 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -166,8 +166,9 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); granisotropicmode_cons_t[1].value = maximumAnisotropy; - +#ifdef USE_FBO_OGL I_DownSample(); +#endif } first_init = true; @@ -177,7 +178,9 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (screen_width != w || screen_height != h) { FlushScreenTextures(); +#ifdef USE_FBO_OGL GLFramebuffer_DeleteAttachments(); +#endif } screen_width = (GLint)w; @@ -187,11 +190,13 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetStates(); pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); +#ifdef USE_FBO_OGL RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif HWR_Startup(); textureformatGL = cbpp > 16 ? GL_RGBA : GL_RGB5_A1; @@ -219,13 +224,17 @@ void OglSdlFinishUpdate(boolean waitvbl) SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); +#ifdef USE_FBO_OGL GLFramebuffer_Disable(); RenderToFramebuffer = FrameBufferEnabled; +#endif HWR_DrawScreenFinalTexture(sdlw, sdlh); +#ifdef USE_FBO_OGL if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); +#endif SDL_GL_SwapWindow(window); -- 2.54.0 From eaeb2575f7fcada0129ada3fd8ccbf5391959cc1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:22:30 +0200 Subject: [PATCH 52/59] add stuff to experimental menu --- src/m_menu.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index f4ce5cf38..dfdd26b2d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1458,19 +1458,22 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Skyboxes", &cv_skybox, 70}, - {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 85}, + {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 90}, - {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 95}, - {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 105}, + {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 105}, + {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 115}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 95}, + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 105}, +#ifdef USE_FBO_OGL + {IT_STRING | IT_CVAR, NULL, "FBO Downsampling support", &cv_grframebuffer, 115}, +#endif - {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 105}, + {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 135}, - {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 125}, - {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 135}, - {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 145}, - {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 155}, + {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 155}, + {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 165}, + {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 175}, + {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 185}, #endif }; @@ -1487,6 +1490,9 @@ static const char* OP_ExpTooltips[] = "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", +#ifdef USE_FBO_OGL + "Allows the game to downsample from a higher resolution than your display in OpenGL renderer mode\nrequires a GPU with atleast OpenGL 3.0 support.", +#endif "Change the depth of the Palette in Palette rendering mod\n 16 bits is like software looks ingame\nwhile 24 bits is how software looks in screenshots.", "Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.", @@ -1508,6 +1514,10 @@ enum op_exp_sprclip, #ifdef HWRENDER op_exp_grscrtx, +#ifdef USE_FBO_OGL + op_exp_fbo, +#endif + op_exp_paldepth, op_exp_spltwal, op_exp_pegging, op_exp_fofzfight, @@ -2909,7 +2919,7 @@ menu_t OP_MonitorToggleDef = menu_t OP_OpenGLOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 30); #endif -menu_t OP_ExpOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 20); +menu_t OP_ExpOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 10); menu_t OP_DataOptionsDef = DEFAULTMENUSTYLE("M_DATA", OP_DataOptionsMenu, &OP_MainDef, 60, 30); menu_t OP_ScreenshotOptionsDef = DEFAULTMENUSTYLE("M_SCSHOT", OP_ScreenshotOptionsMenu, &OP_DataOptionsDef, 30, 30); @@ -4468,12 +4478,15 @@ void M_Init(void) { OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_grscrtx].status = IT_DISABLED; +#ifdef USE_FBO_OGL + OP_ExpOptionsMenu[op_exp_fbo].status = IT_DISABLED; +#endif OP_ExpOptionsMenu[op_exp_spltwal].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_pegging].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_fofzfight].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_fofcut].status = IT_DISABLED; } - + if (rendermode == render_opengl) { OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; -- 2.54.0 From 3c8c273e51fb09bbcf3f1e9b67c7b2a098e9a7ac Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:34:27 +0200 Subject: [PATCH 53/59] add ogl version check + grey out in menu + turn it off when not avilible --- src/hardware/r_opengl/r_opengl.c | 16 ++++++++++++++-- src/hardware/r_opengl/r_opengl.h | 1 + src/m_menu.c | 5 +++++ src/sdl/ogl_sdl.c | 8 ++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9a0eac7b5..0ea12a793 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -124,6 +124,8 @@ static boolean GLFramebuffer_IsFuncAvailible(void); GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE; + +boolean supportFBO = false; #endif // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing @@ -764,9 +766,15 @@ void SetupGLFunc4(void) #ifdef USE_FBO_OGL static boolean GLFramebuffer_IsFuncAvailible(void) { + //this stuff needs atleast OGL 3.0 + if (majorGL < 3) + return false; + return((isExtAvailable("GL_ARB_framebuffer_no_attachments",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_object",gl_extensions)) && (isExtAvailable("GL_ARB_framebuffer_sRGB",gl_extensions))); + + return false; } #endif @@ -2319,9 +2327,13 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) #ifdef USE_FBO_OGL case HWD_SET_FRAMEBUFFER: FrameBufferEnabled = Value ? GL_TRUE : GL_FALSE; - - if (!GLFramebuffer_IsFuncAvailible()) + supportFBO = GLFramebuffer_IsFuncAvailible(); + + if (!supportFBO) + { FrameBufferEnabled = GL_FALSE; + CV_Set(&cv_grframebuffer, "Off"); + } break; #endif case HWD_SET_TEXTUREFILTERMODE: diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index a4d8819e3..255969d5a 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -116,6 +116,7 @@ void GLFramebuffer_Disable(void); extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject; extern GLboolean FrameBufferEnabled, RenderToFramebuffer; +extern boolean supportFBO; #endif // ========================================================================== diff --git a/src/m_menu.c b/src/m_menu.c index dfdd26b2d..5c25b209d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -58,6 +58,7 @@ #ifdef HWRENDER #include "hardware/hw_main.h" +#include "hardware/r_opengl/r_opengl.h" #endif #include "d_net.h" @@ -4491,6 +4492,10 @@ void M_Init(void) { OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED; +#ifdef USE_FBO_OGL + if (!supportFBO) + OP_ExpOptionsMenu[op_exp_fbo].status = IT_GRAYEDOUT; +#endif } #endif diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index edc9cdb6b..5bb6b7347 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -151,6 +151,10 @@ boolean OglSdlSurface(INT32 w, INT32 h) "- GPU drivers are missing or broken. You may need to update your drivers."); } + SetupGLInfo(); + + SetupGLFunc4(); + if (majorGL == 1 && minorGL <= 3) // GL_GENERATE_MIPMAP is unavailible for OGL 1.3 and below supportMipMap = false; else @@ -161,10 +165,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) else maximumAnisotropy = 1; - SetupGLInfo(); - - SetupGLFunc4(); - granisotropicmode_cons_t[1].value = maximumAnisotropy; #ifdef USE_FBO_OGL I_DownSample(); -- 2.54.0 From c966b5defbbcca20977641b51f1c94aeb303db04 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:38:04 +0200 Subject: [PATCH 54/59] forgor --- src/i_video.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i_video.h b/src/i_video.h index 76a06be91..c39186d54 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,7 +139,7 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); -#ifdef HWRENDER +#ifdef USE_FBO_OGL void RefreshSDLSurface(void); void I_DownSample(void); extern boolean downsample; -- 2.54.0 From de6511abe0157aab44c98c5b47a3cf2156bb8a98 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:40:28 +0200 Subject: [PATCH 55/59] dont compile with that with NOHW --- src/CMakeLists.txt | 8 +++++--- src/Makefile | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 74833b216..b4bb035af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -512,9 +512,11 @@ if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) endif() endif() -if(${SRB2_CONFIG_USE_FBO_OGL}) - set(SRB2_USE_FBO_OGL ON) - add_definitions(-DUSE_FBO_OGL) +if(${SRB2_CONFIG_HWRENDER}) + if(${SRB2_CONFIG_USE_FBO_OGL}) + set(SRB2_USE_FBO_OGL ON) + add_definitions(-DUSE_FBO_OGL) + endif() endif() # Targets diff --git a/src/Makefile b/src/Makefile index 72a083b88..af8dd67b0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -376,9 +376,11 @@ ifdef STATIC LIBS:=-static $(LIBS) endif +ifndef NOHW ifdef USE_FBO_OGL OPTS+=-DUSE_FBO_OGL endif +endif ifdef HAVE_MINIUPNPC ifdef NONET -- 2.54.0 From c6059064084da72a94b6f3ca2241d1265c4d6f49 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:49:36 +0200 Subject: [PATCH 56/59] some stuffs --- src/sdl/i_video.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b898a8e48..bbeeef03f 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -80,6 +80,7 @@ #ifdef HWRENDER #include "../hardware/hw_main.h" #include "../hardware/hw_drv.h" +#include "../hardware/r_opengl/r_opengl.h" //for supportFBO // For dynamic referencing of HW rendering functions #include "hwsym_sdl.h" #include "ogl_sdl.h" @@ -748,7 +749,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) #ifdef USE_FBO_OGL void I_DownSample(void) { - if (!cv_grframebuffer.value || !(rendermode == render_opengl)) + if (!cv_grframebuffer.value || !(rendermode == render_opengl) || (!supportFBO)) //no sense to do this crap if we cant benefit from it { downsample = false; return; @@ -759,13 +760,13 @@ void I_DownSample(void) if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) == 0) { - if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + if ((vid.width > curmode.w) || (vid.height > curmode.h)) //check if current resolution is higher than current display resolution { downsample = true; RefreshSDLSurface(); } else - downsample = false; + downsample = false; // its not so no need to do crap } else downsample = false; // couldnt get display info so turn the thing off -- 2.54.0 From 6fcea2f98e83d761632748e9e4b4940a963ce255 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 May 2024 23:52:05 +0200 Subject: [PATCH 57/59] RefreshOGLSDLSurface to make it a little more clearer this is ogl only --- src/hardware/hw_main.c | 2 +- src/i_video.h | 2 +- src/sdl/i_video.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b52612582..53f0e8786 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -223,7 +223,7 @@ static void CV_grframebuffer_OnChange(void) ONLY_IF_GL_LOADED HWD.pfnSetSpecialState(HWD_SET_FRAMEBUFFER, cv_grframebuffer.value); I_DownSample(); - RefreshSDLSurface(); + RefreshOGLSDLSurface(); } #endif diff --git a/src/i_video.h b/src/i_video.h index c39186d54..708fde03c 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -140,7 +140,7 @@ UINT32 I_GetRefreshRate(void); boolean I_UseNativeKeyboard(void); #ifdef USE_FBO_OGL -void RefreshSDLSurface(void); +void RefreshOGLSDLSurface(void); void I_DownSample(void); extern boolean downsample; #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index bbeeef03f..f90f5bb18 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -218,7 +218,7 @@ static void Impl_SetWindowIcon(void); #ifdef USE_FBO_OGL boolean downsample = false; -void RefreshSDLSurface(void) +void RefreshOGLSDLSurface(void) { if (rendermode == render_opengl) OglSdlSurface(vid.width, vid.height); @@ -763,7 +763,7 @@ void I_DownSample(void) if ((vid.width > curmode.w) || (vid.height > curmode.h)) //check if current resolution is higher than current display resolution { downsample = true; - RefreshSDLSurface(); + RefreshOGLSDLSurface(); } else downsample = false; // its not so no need to do crap -- 2.54.0 From 9b4e64011b9e1f3b9eda0a4b27e3dcc8401731d4 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 19 May 2024 18:43:12 +0200 Subject: [PATCH 58/59] make this a scroll menu tbh not gonna bother with moving stuff depending on renderer --- src/m_menu.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 5c25b209d..cc7d45d33 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1452,29 +1452,29 @@ static menuitem_t OP_ColorOptionsMenu[] = static menuitem_t OP_ExpOptionsMenu[] = { {IT_HEADER, NULL, "Experimental Options", NULL, 10}, - {IT_STRING|IT_CVAR, NULL, "Interpolation Distance", &cv_grmaxinterpdist, 25}, - {IT_STRING|IT_CVAR, NULL, "Mobj Subsector Interpolation", &cv_mobjssector, 35}, - {IT_STRING | IT_CVAR, NULL, "Weather Interpolation", &cv_precipinterp, 45}, - {IT_STRING | IT_CVAR, NULL, "Less Weather Effects", &cv_lessprecip, 55}, + {IT_STRING|IT_CVAR, NULL, "Interpolation Distance", &cv_grmaxinterpdist, 20}, + {IT_STRING|IT_CVAR, NULL, "Mobj Subsector Interpolation", &cv_mobjssector, 25}, + {IT_STRING | IT_CVAR, NULL, "Weather Interpolation", &cv_precipinterp, 30}, + {IT_STRING | IT_CVAR, NULL, "Less Weather Effects", &cv_lessprecip, 35}, - {IT_STRING | IT_CVAR, NULL, "Skyboxes", &cv_skybox, 70}, + {IT_STRING | IT_CVAR, NULL, "Skyboxes", &cv_skybox, 42}, - {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 90}, + {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 49}, - {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 105}, - {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 115}, + {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 56}, + {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 61}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 105}, + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 68}, #ifdef USE_FBO_OGL - {IT_STRING | IT_CVAR, NULL, "FBO Downsampling support", &cv_grframebuffer, 115}, + {IT_STRING | IT_CVAR, NULL, "FBO Downsampling support", &cv_grframebuffer, 73}, #endif - {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 135}, + {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 80}, - {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 155}, - {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 165}, - {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 175}, - {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 185}, + {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 87}, + {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 92}, + {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 97}, + {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 102}, #endif }; @@ -2920,7 +2920,7 @@ menu_t OP_MonitorToggleDef = menu_t OP_OpenGLOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 30); #endif -menu_t OP_ExpOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 10); +menu_t OP_ExpOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 35); menu_t OP_DataOptionsDef = DEFAULTMENUSTYLE("M_DATA", OP_DataOptionsMenu, &OP_MainDef, 60, 30); menu_t OP_ScreenshotOptionsDef = DEFAULTMENUSTYLE("M_SCSHOT", OP_ScreenshotOptionsMenu, &OP_DataOptionsDef, 30, 30); -- 2.54.0 From 5f36557a18cf848c4dd1c886de938f634aed2534 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 19 May 2024 21:31:05 +0200 Subject: [PATCH 59/59] change version string stuff per define lul --- src/doomdef.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index d71aaeb8a..2b5f93b19 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -127,8 +127,13 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number +#ifndef USE_FBO_OGL #define VERSIONSTRING "Saturn v6.2 " #define VERSIONSTRINGW L"Saturn v6.2" +#else +#define VERSIONSTRING "Saturn v6.2 - FBO " +#define VERSIONSTRINGW L"Saturn v6.2 - FBO" +#endif // Hey! If you change this, add 1 to the MODVERSION below! Otherwise we can't force updates! // And change CMakeLists.txt (not src/, but in root), for CMake users! // AND appveyor.yml, for the build bots! -- 2.54.0