diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ad418ae96..7c16ad754 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -90,9 +90,12 @@ char motd[254], server_context[8]; // Message of the Day, Unique Context (even w plrinfo playerinfo[MAXPLAYERS]; SINT8 joinnode = 0; // used for CL_VIEWSERVER +boolean player_muted[MAXPLAYERS] = {0}; + // Server specific vars UINT8 playernode[MAXPLAYERS]; + // Minimum timeout for sending the savegame // The actual timeout will be longer depending on the savegame length tic_t jointimeout = (3*TICRATE); @@ -3393,6 +3396,8 @@ void CL_Reset(void) #endif G_ResetAllDeviceRumbles(); + memset(player_muted, 0, sizeof(player_muted)); + // D_StartTitle should get done now, but the calling function will handle it } @@ -3413,31 +3418,12 @@ static void Command_GetPlayerNum(void) SINT8 nametonum(const char *name) { - INT32 playernum, i; + INT32 playernum = D_LookupPlayer(name); - if (!strcmp(name, "0")) - return 0; + if (playernum == -1) + CONS_Printf(M_GetText("There is no player named \"%s\"\n"), name); - playernum = (SINT8)atoi(name); - - if (playernum < 0 || playernum >= MAXPLAYERS) - return -1; - - if (playernum) - { - if (playeringame[playernum]) - return (SINT8)playernum; - else - return -1; - } - - for (i = 0; i < MAXPLAYERS; i++) - if (playeringame[i] && !stricmp(player_names[i], name)) - return (SINT8)i; - - CONS_Printf(M_GetText("There is no player named \"%s\"\n"), name); - - return -1; + return playernum; } /** Lists all players and their player numbers. diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 979e06693..4b967e670 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -670,6 +670,8 @@ SINT8 nametonum(const char *name); extern char motd[254], server_context[8]; extern UINT8 playernode[MAXPLAYERS]; +extern boolean player_muted[MAXPLAYERS]; + INT32 D_NumPlayers(void); void D_ResetTiccmds(void); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 2b02285bf..c358c3b2c 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1029,6 +1029,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_scr_height); CV_RegisterVar(&cv_parallelsoftware); + CV_RegisterVar(&cv_paralleldrawmasked); CV_RegisterVar(&cv_soundtest); @@ -2085,7 +2086,7 @@ static void Command_ResetCamera_f(void) } /* Consider replacing nametonum with this */ -static INT32 LookupPlayer(const char *s) +INT32 D_LookupPlayer(const char *s) { INT32 playernum; @@ -2101,8 +2102,7 @@ static INT32 LookupPlayer(const char *s) for (playernum = 0; playernum < MAXPLAYERS; ++playernum) { /* Match name case-insensitively: fully, or partially the start. */ - if (playeringame[playernum]) - if (strnicmp(player_names[playernum], s, strlen(s)) == 0) + if (playeringame[playernum] && (strnicmp(player_names[playernum], s, strlen(s)) == 0)) { return playernum; } @@ -2217,7 +2217,7 @@ static void Command_View_f(void) } else { - if (( playernum = LookupPlayer(COM_Argv(1)) ) == -1) + if (( playernum = D_LookupPlayer(COM_Argv(1)) ) == -1) { CONS_Alert(CONS_WARNING, "There is no player by that name!\n"); return; diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 657686af4..1078de5d2 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -323,6 +323,7 @@ void ClearAdminPlayers(void); void RemoveAdminPlayer(INT32 playernum); void ItemFinder_OnChange(void); void D_SetPassword(const char *pw); +INT32 D_LookupPlayer(const char *s); // used for the player setup menu UINT8 CanChangeSkin(INT32 playernum); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 5bc277e70..e21219083 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -689,7 +689,7 @@ typedef enum gluniform_leveltime, gluniform_scr_resolution, - + gluniform_max, } gluniform_t; @@ -1729,6 +1729,114 @@ static void GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) } } +#define PADDING_CHECK(offset, alphaCheck) { from = to + (offset); if ((alphaCheck)) from = NULL; else goto foundFrom; } + +static void PadRGBABitmap(RGBA_t *tex, UINT16 w, UINT16 h) +{ + INT32 i; + boolean notLeft, notRight, notTop, notBottom; + RGBA_t *to = tex - 1, *from; + + for (i = 0; i < w * h; i++) + { + to++; + if (to->rgba != 0) + continue; + from = NULL; + + notLeft = i % w != 0; + notRight = i % w != w - 1; + notTop = i / w != 0; + notBottom = i / w != h - 1; + + if (notRight) PADDING_CHECK(1, from->s.alpha == 0) // Check +X + if (notBottom) PADDING_CHECK(w, from->s.alpha == 0) // Check +Y + if (notLeft) PADDING_CHECK(-1, from->s.alpha == 0) // Check -X + if (notTop) PADDING_CHECK(-w, from->s.alpha == 0) // Check -Y + if (notRight && notBottom) PADDING_CHECK(1 + w, from->s.alpha == 0) // Check +X+Y + if (notLeft && notBottom) PADDING_CHECK(-1 + w, from->s.alpha == 0) // Check -X+Y + if (notLeft && notTop) PADDING_CHECK(-1 - w, from->s.alpha == 0) // Check -X-Y + if (notRight && notTop) PADDING_CHECK(1 - w, from->s.alpha == 0) // Check +X-Y + +foundFrom: + if (from != NULL) + { + *to = *from; + to->s.alpha = 0; + } + } +} + +#undef PADDING_CHECK + +static void GenerateMipmaps(INT32 w, INT32 h, RGBA_t *tex, INT32 maxLOD) +{ + if (tex == NULL) + { + GL_MSG_Warning("GenerateMipmaps: attempted to generate mipmaps without texture data"); + return; + } + + RGBA_t samplePoint[4]; + boolean padTexture; + INT32 pointsSampled = 0; + INT32 m, j, i, p; + UINT16 sumR, sumG, sumB, sumA; + + for (m = 0; m < maxLOD; m++) + { + if (w <= 1 || h <= 1) + return; + + padTexture = false; + + for (j = 0; j < h / 2; j++) + { + for (i = 0; i < w / 2; i++) + { + samplePoint[0] = tex[w*j*2 + i*2]; + samplePoint[1] = tex[w*j*2 + i*2+1]; + samplePoint[2] = tex[w*(j*2+1) + i*2]; + samplePoint[3] = tex[w*(j*2+1) + i*2+1]; + + pointsSampled = sumR = sumG = sumB = sumA = 0; + + for (p = 0; p < 4; p++) + { + if (samplePoint[p].s.alpha == 0) + continue; + sumR += samplePoint[p].s.red; + sumG += samplePoint[p].s.green; + sumB += samplePoint[p].s.blue; + sumA += samplePoint[p].s.alpha; + pointsSampled++; + } + + if (pointsSampled > 0) + { + tex[(w/2)*j+i].s.red = sumR / pointsSampled; + tex[(w/2)*j+i].s.green = sumG / pointsSampled; + tex[(w/2)*j+i].s.blue = sumB / pointsSampled; + tex[(w/2)*j+i].s.alpha = sumA / pointsSampled; + } + else + { + tex[(w/2)*j+i].rgba = 0; + padTexture = true; + } + } + } + + w /= 2; + h /= 2; + + if (padTexture) + PadRGBABitmap(tex, w, h); + + pglTexSubImage2D(GL_TEXTURE_2D, m + 1, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, tex); + } +} + // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ @@ -1737,6 +1845,7 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) // Upload a texture GLuint num = pTexInfo->downloaded; boolean update = true; + const boolean applyPadding = mag_filter == GL_LINEAR || min_filter == GL_LINEAR; INT32 w = pTexInfo->width, h = pTexInfo->height; INT32 i, j; @@ -1795,15 +1904,32 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) pImgData++; } } + + if (applyPadding) + PadRGBABitmap(tex, w, h); + break; case GL_TEXFMT_RGBA: // Directly upload the texture data without any kind of conversion. ptex = pImgData; + + // However, it does need to be copied to a buffer for generating mipmaps and padding + if (MipMap || applyPadding) + { + GL_AllocTextureBuffer(pTexInfo); + tex = textureBuffer; + memcpy(tex, ptex, w * h * 4); + ptex = tex; + + if (applyPadding) + PadRGBABitmap(tex, w, h); + } + break; case GL_TEXFMT_ALPHA_INTENSITY_88: GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; - texformat = GL_LUMINANCE_ALPHA; + texformat = GL_RGBA; for (idx = 0, j = 0; j < h; j++) { @@ -1821,7 +1947,7 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) case GL_TEXFMT_ALPHA_8: // Used for fade masks GL_AllocTextureBuffer(pTexInfo); ptex = tex = textureBuffer; - texformat = GL_ALPHA; + texformat = GL_RGBA; memset(&tex->s, 255, sizeof(byteColor_t)*w*h); // 255 because the fade mask is modulated with the screen texture, so alpha affects it while the colours don't @@ -1857,8 +1983,6 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) if (MipMap && !transparent) // No mipmaps on transparent stuff { - int maxlod = (texformat == GL_LUMINANCE_ALPHA || texformat == GL_ALPHA) ? 4 : 5; - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); if (update) @@ -1868,7 +1992,8 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) // Control the mipmap level of detail pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, maxlod); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); + GenerateMipmaps(w, h, tex, 5); } else { @@ -1892,7 +2017,6 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_filter); } - // -----------------+ // SetTexture : The mipmap becomes the current texture source // -----------------+ @@ -2734,7 +2858,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics poly.green = byte2float[Surface->PolyColor.s.green]; poly.blue = byte2float[Surface->PolyColor.s.blue]; poly.alpha = byte2float[Surface->PolyColor.s.alpha]; - + pglColor4ubv((GLubyte*)&Surface->PolyColor.s); GL_SetBlend(((poly.alpha < 1) ? Surface->PolyFlags : (PF_Masked|PF_Occlude))|PF_Modulated); @@ -2748,7 +2872,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics fade.green = byte2float[Surface->FadeColor.s.green]; fade.blue = byte2float[Surface->FadeColor.s.blue]; fade.alpha = byte2float[Surface->FadeColor.s.alpha]; - + if (Surface->LightTableId && Surface->LightTableId != lt_downloaded) { pglActiveTexture(GL_TEXTURE2); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f052207fb..e63fa012a 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -705,7 +705,7 @@ static void Command_Sayto_f(void) return; } - target = nametonum(COM_Argv(1)); + target = D_LookupPlayer(COM_Argv(1)); if (target == -1) { CONS_Alert(CONS_NOTICE, M_GetText("No player with that name!\n")); @@ -953,6 +953,9 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) else stop_spamming[playernum] = 4; // you can hold off for 4 tics, can you? + if (player_muted[playernum]) + spam_eatmsg = 1; // Let lua know we're skipping this message + // run the lua hook even if we were supposed to eat the msg, netgame consistency goes first. if (LUA_HookPlayerMsg(playernum, target, flags, msg, spam_eatmsg)) @@ -1184,6 +1187,23 @@ static boolean HU_clearChatSpaces(void) return nothingbutspaces; } +static void DoMute(const char *name) +{ + INT32 pnum = D_LookupPlayer(name); + + if (pnum < 0) + { + HU_AddChatText("\x85""ERROR: \x80Player not found.", false); + return; + } + + player_muted[pnum] = !player_muted[pnum]; + + HU_AddChatText(va("Player '%s' has been %smuted.", player_names[pnum], player_muted[pnum] ? "" : "un"), false); + if (player_muted[pnum]) + HU_AddChatText("Use same command to unmute them.", false); +} + static void HU_SendChatMessage(void) { char buf[2 + HU_MAXMSGLEN + 1]; @@ -1210,7 +1230,19 @@ static void HU_SendChatMessage(void) return; } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + size_t len = strlen(msg); + + if (len >= 5 && strnicmp(msg, "/mute", 5) == 0) // Used /mute + { + if (len > 6) + DoMute(msg+6); + else + HU_AddChatText("\x82NOTICE: \x80Usage: /mute ", false); + + return; + } + + if (len > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if nodenum[1] is a space. char *nodenum = (char*) malloc(3); diff --git a/src/k_hud.c b/src/k_hud.c index dcd85cc27..c3b49bd3b 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -96,9 +96,9 @@ consvar_t cv_showminimapnames = {"showminimapnames", "Off", CV_SAVE, CV_OnOff, N CV_PossibleValue_t minimapdot_cons_t[NUMMINIMAPDOTSTUFF]; consvar_t cv_showminimapangle = {"showminimapangle", "Off", CV_SAVE, minimapdot_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_posanim = {"postitionanimation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_smallposnum = {"smallpositionnumber", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_smoothposition = {"smoothposition", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t posanim_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Smooth"}, {0, NULL}}; +consvar_t cv_posanim = {"postitionanimation", "On", CV_SAVE, posanim_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_smallposnum = {"smallpositionnumber", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showlapemblem = {"showlapemblem", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -211,7 +211,6 @@ void K_RegisterKartHudStuff(void) CV_RegisterVar(&cv_posanim); CV_RegisterVar(&cv_smallposnum); - CV_RegisterVar(&cv_smoothposition); CV_RegisterVar(&cv_fancyroulette); @@ -1970,9 +1969,15 @@ static void K_DrawKartPositionNum(INT32 num) if ((cv_posanim.value && stplyr->kartstuff[k_positiondelay]) || stplyr->exiting) { - const UINT8 delay = (stplyr->exiting) ? POS_DELAY_TIME : stplyr->kartstuff[k_positiondelay]; - const fixed_t add = (scale * 3) >> ((splitscreen == 1) ? 1 : 2); - scale = cv_smoothposition.value ? scale + min((add * (delay * delay)) / (POS_DELAY_TIME * POS_DELAY_TIME), add) : scale*2; + if (cv_posanim.value == 2) + { + const UINT8 delay = (stplyr->exiting) ? POS_DELAY_TIME : stplyr->kartstuff[k_positiondelay]; + const fixed_t add = (scale * 3) >> ((splitscreen == 1) ? 1 : 2); + scale = (scale + min((add * (delay * delay)) / (POS_DELAY_TIME * POS_DELAY_TIME), add)); + } + else + scale *= 2; + overtake = true; // this is used for splitscreen stuff in conjunction with flipdraw. } diff --git a/src/m_menu.c b/src/m_menu.c index f21a649f1..a4894b4b8 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6872,6 +6872,32 @@ static void M_HutCheckReplays(size_t maxnum) } } +static int ReplayListSortComparator(const void *entry1, const void *entry2) +{ + const menudemo_t *demo1 = (const menudemo_t*)entry1; + const menudemo_t *demo2 = (const menudemo_t*)entry2; + + char filepath1[sizeof(demo1->filepath)]; + char filepath2[sizeof(demo2->filepath)]; + + // First check for directories, they always should be at the top + if (demo1->type == MD_SUBDIR && demo2->type != MD_SUBDIR) + return -1; + else if (demo2->type == MD_SUBDIR && demo1->type != MD_SUBDIR) + return 1; + else if (demo1->type == MD_SUBDIR && demo2->type == MD_SUBDIR) + return 0; + + memcpy(filepath1, demo1->filepath, sizeof(filepath1)); + memcpy(filepath2, demo2->filepath, sizeof(filepath2)); + + nameonly(filepath1); + nameonly(filepath2); + + // Comparing in opposite order to move new replays to the top + return strncmp(filepath2, filepath1, sizeof(filepath1)); +} + static void PrepReplayList(boolean reset) { size_t i; @@ -6915,6 +6941,8 @@ static void PrepReplayList(boolean reset) } } + qs22j(demolist_all, sizedirmenu, sizeof(menudemo_t), ReplayListSortComparator); + Unlock_search_state(); LoadReplayNames(); diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 482b7c57f..0e81a4198 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -199,9 +199,9 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, UINT8 i = R_GetViewNumber(); if (viewplayer == &players[displayplayers[i]] && camera[i].chase) - heightsec = R_PointInSubsector(camera[i].x, camera[i].y)->sector->heightsec; - else if (i > splitscreen && viewmobj) - heightsec = R_PointInSubsector(pviewmobj->x, pviewmobj->y)->sector->heightsec; + heightsec = camera->subsector->sector->heightsec; + else if (viewmobj) + heightsec = pviewmobj->subsector->sector->heightsec; else return sec; diff --git a/src/r_data.c b/src/r_data.c index b41b24e2d..8fbcaaef8 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -103,7 +103,7 @@ static UINT32 **texturecolumnofs; // column offset lookup table for each texture UINT8 **texturecache; // graphics data for each generated full-size texture // texture width is a power of 2, so it can easily repeat along sidedefs using a simple mask -INT32 *texturewidthmask; +static INT32 *texturewidthmask; fixed_t *textureheight; // needed for texture pegging @@ -474,11 +474,28 @@ UINT8 *R_GetColumn(fixed_t tex, INT32 col) { UINT8 *data; - col &= texturewidthmask[tex]; data = texturecache[tex]; + if (texturewidthmask[tex]) + col &= texturewidthmask[tex]; // set by load textures + else + { + const INT16 texwidth = textures[tex]->width; + + // Odd width texture, cannot just mask. + // Sometime gets colnum = -1 or = width, even without tiling. + // Test LostCiv, Map 20, crates. + col = ( col < 0 ) ? + texwidth - (((-col - 1) % texwidth) + 1) + : col % texwidth; + } + if (!data) + { + // This must be here because cache can be freed by other operations. + // To prevent must lock individual texture cache on every draw. data = R_GenerateTexture(tex); + } return data + LONG(texturecolumnofs[tex][col]); } diff --git a/src/r_data.h b/src/r_data.h index 8c74b5a95..6a336bc07 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -56,7 +56,6 @@ typedef struct UINT8 type; // TEXTURETYPE_ INT16 width, height; boolean holes; - // All the patches[patchcount] are drawn back to front into the cached texture. INT16 patchcount; texpatch_t patches[0]; @@ -66,9 +65,6 @@ typedef struct extern texture_t **textures; extern UINT8 **texturecache; // graphics data for each generated full-size texture -// texture width is a power of 2, so it can easily repeat along sidedefs using a simple mask -extern INT32 *texturewidthmask; - extern fixed_t *textureheight; // needed for texture pegging UINT32 ASTBlendPixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alpha); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index cf7878184..a8ed71008 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -46,10 +46,23 @@ enum DrawSpanType DS_RIPPLE = 0x0008, }; +template +static constexpr UINT8 R_GetSpanTranslated(drawspandata_t* ds, UINT8 col) +{ + if constexpr (Type & DrawSpanType::DS_COLORMAP) + { + return ds->translation[col]; + } + else + { + return col; + } +} + template static constexpr UINT8 R_GetSpanTranslucent(drawspandata_t* ds, UINT8 *dsrc, const UINT8 *colormap, UINT8 col) { - col = colormap[col]; + col = colormap[R_GetSpanTranslated(ds, col)]; if constexpr (Type & DrawSpanType::DS_TRANSMAP) { diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 653353a2b..499e302ac 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -247,9 +247,7 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 ds->bgofs = -y; } - pindex = distance >> LIGHTZSHIFT; - if (pindex >= MAXLIGHTZ) - pindex = MAXLIGHTZ - 1; + pindex = std::min(distance >> LIGHTZSHIFT, MAXLIGHTZ - 1); ds->colormap = ds->planezlight[pindex]; @@ -352,8 +350,8 @@ void R_ClearPlanes(void) angle = (viewangle-ANGLE_90)>>ANGLETOFINESHIFT; // scale will be unit scale at SCREENWIDTH/2 distance - basexscale = FixedDiv (FINECOSINE(angle), centerxfrac); - baseyscale = -FixedDiv (FINESINE(angle), centerxfrac); + basexscale = FixedDiv (FINECOSINE(angle), centerxfrac); + baseyscale = -FixedDiv (FINESINE(angle), centerxfrac); } static visplane_t *new_visplane(unsigned hash) @@ -442,26 +440,20 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, } } - // This appears to fix the Nimbus Ruins sky bug. - if (picnum == skyflatnum && pfloor) - { - height = 0; // all skies map together - lightlevel = 0; - } - else if (slope != NULL && P_ApplyLightOffset(lightlevel >> LIGHTSEGSHIFT, lighting_sector)) - { - if (reverseLight) - { - lightlevel -= slope->lightOffset * 8; - } - else - { - lightlevel += slope->lightOffset * 8; - } - } - if (!pfloor) { + if (slope != NULL && P_ApplyLightOffset(lightlevel >> LIGHTSEGSHIFT, lighting_sector)) + { + if (reverseLight) + { + lightlevel -= slope->lightOffset * 8; + } + else + { + lightlevel += slope->lightOffset * 8; + } + } + hash = visplane_hash(picnum, lightlevel, height); for (check = visplanes[hash]; check; check = check->next) @@ -485,6 +477,13 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, } else { + // This appears to fix the Nimbus Ruins sky bug. + if (picnum == skyflatnum) + { + height = 0; // all skies map together + lightlevel = 0; + } + hash = MAXVISPLANES - 1; } @@ -592,6 +591,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) memset(pl->top, 0xff, sizeof(*pl->top) * viewwidth); memset(pl->bottom, 0x00, sizeof(*pl->bottom) * viewwidth); } + return pl; } @@ -628,14 +628,13 @@ static void R_MakeSpans(void (*mapfunc)(drawspandata_t* ds, void(*spanfunc)(draw if (b2 >= vidheight) b2 = vidheight-1; if (x-1 >= vid.width) x = vid.width; - drawspandata_t dc_copy = *ds; - #ifdef HAVE_THREADS // We want to draw N spans per subtask to ensure the work is // coarse enough to not be too slow due to task scheduling overhead. // To safely do this, we need to copy part of spanstart to a local. // This is essentially loop unrolling across threads. constexpr const int kSpanTaskGranularity = 8; + drawspandata_t ds_copy = *ds; while (t1 < t2 && t1 <= b1) { INT32 spanstartcopy[kSpanTaskGranularity] = {0}; @@ -652,7 +651,7 @@ static void R_MakeSpans(void (*mapfunc)(drawspandata_t* ds, void(*spanfunc)(draw auto task = [=]() mutable -> void { for (int i = 0; i < taskspans; i++) { - mapfunc(&dc_copy, localspanfunc, t1 + i, spanstartcopy[i], x - 1, false); + mapfunc(&ds_copy, localspanfunc, t1 + i, spanstartcopy[i], x - 1, false); } }; if (allow_parallel) @@ -681,7 +680,7 @@ static void R_MakeSpans(void (*mapfunc)(drawspandata_t* ds, void(*spanfunc)(draw auto task = [=]() mutable -> void { for (int i = 0; i < taskspans; i++) { - mapfunc(&dc_copy, localspanfunc, b1 - i, spanstartcopy[i], x - 1, false); + mapfunc(&ds_copy, localspanfunc, b1 - i, spanstartcopy[i], x - 1, false); } }; if (allow_parallel) @@ -699,12 +698,12 @@ static void R_MakeSpans(void (*mapfunc)(drawspandata_t* ds, void(*spanfunc)(draw while (t1 < t2 && t1 <= b1) { - mapfunc(&dc_copy, localspanfunc, t1, spanstart[t1], x - 1, false); + mapfunc(ds, localspanfunc, t1, spanstart[t1], x - 1, false); t1++; } while (b1 > b2 && b1 >= t1) { - mapfunc(&dc_copy, localspanfunc, b1, spanstart[b1], x - 1, false); + mapfunc(ds, localspanfunc, b1, spanstart[b1], x - 1, false); b1--; } #endif @@ -1020,13 +1019,12 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle size_t size; INT32 spanfunctype = BASEDRAWFUNC; ffloor_t *rover; + levelflat_t *levelflat; void (*mapfunc)(drawspandata_t*, void(*)(drawspandata_t*), INT32, INT32, INT32, boolean) = R_MapPlane; - if (!(pl->minx <= pl->maxx)) + if (pl->minx > pl->maxx) return; - R_UpdatePlaneRipple(ds); - // sky flat if (pl->picnum == skyflatnum) { @@ -1039,6 +1037,8 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle return; } + R_UpdatePlaneRipple(ds); + ds->planeripple.active = false; R_SetSpanFunc(BASEDRAWFUNC); @@ -1175,16 +1175,17 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle else light = (pl->lightlevel >> LIGHTSEGSHIFT); } - // Don't mess with angle on slopes! We'll handle this ourselves later - if (!pl->slope && viewangle != pl->viewangle+pl->plangle) - { - viewangle = pl->viewangle+pl->plangle; - } - ds->currentplane = pl; - ds->source = (UINT8 *)W_CacheLumpNum(levelflats[pl->picnum].lumpnum, PU_STATIC); // Stay here until Z_ChangeTag - size = W_LumpLength(levelflats[pl->picnum].lumpnum); + levelflat = &levelflats[pl->picnum]; + + // Get the texture + ds->source = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_STATIC); // Stay here until Z_ChangeTag + + if (ds->source == NULL) + return; + + size = W_LumpLength(levelflat->lumpnum); switch (size) { @@ -1235,11 +1236,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle ds->xoffs = pl->xoffs; ds->yoffs = pl->yoffs; - if (light >= LIGHTLEVELS) - light = LIGHTLEVELS-1; - - if (light < 0) - light = 0; + light = CLAMP(light, 0, LIGHTLEVELS-1); if (pl->slope) { @@ -1292,6 +1289,12 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle } else { + // Don't mess with angle on slopes! We'll handle this ourselves later + if (viewangle != pl->viewangle + pl->plangle) + { + viewangle = pl->viewangle + pl->plangle; + } + ds->planeheight = abs(pl->height - pl->viewz); ds->planezlight = zlight[light]; } @@ -1299,10 +1302,8 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle R_SetSpanFunc(spanfunctype); // set the maximum value for unsigned - pl->top[pl->maxx+1] = 0xffff; - pl->top[pl->minx-1] = 0xffff; - pl->bottom[pl->maxx+1] = 0x0000; - pl->bottom[pl->minx-1] = 0x0000; + pl->top[pl->maxx+1] = pl->top[pl->minx-1] = 0xffff; + pl->bottom[pl->maxx+1] = pl->bottom[pl->minx-1] = 0x0000; stop = pl->maxx + 1; @@ -1403,6 +1404,7 @@ void R_PlaneBounds(visplane_t *plane) if (plane->bottom[i] > low) low = plane->bottom[i]; } + plane->high = hi; plane->low = low; } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 452d1eb8e..6bc139a2d 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -306,8 +306,10 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 else dc->texturemid -= (textureheight[texnum])*times; + const INT16 colnum = maskedtexturecol[dc->x]; + // calculate lighting - if (maskedtexturecol[dc->x] != INT16_MAX) + if (colnum != INT16_MAX) { // Check for overflows first if (R_OverflowTest(dc)) @@ -337,7 +339,7 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 dc->iscale = 0xffffffffu / (unsigned)spryscale; // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum, maskedtexturecol[dc->x]) - 3); + col = (column_t *)((UINT8 *)R_GetColumn(texnum, colnum) - 3); auto set_light_vars = [&](INT32 k) { @@ -434,7 +436,7 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 dc->iscale = 0xffffffffu / (unsigned)spryscale; // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum, maskedtexturecol[dc->x]) - 3); + col = (column_t *)((UINT8 *)R_GetColumn(texnum, colnum) - 3); colfunc_2s(dc, col); } @@ -1190,6 +1192,7 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) INT32 bottom; INT32 i; + // Loop over width for (; rw_x < rw_stopx; rw_x++) { // mark floor / ceiling areas @@ -1563,6 +1566,7 @@ static void R_MarkSegBounds(void) INT32 top, bottom; INT16 topclip, bottomclip; + // Loop over width for (; rw_x < rw_stopx; rw_x++) { // mark floor / ceiling areas diff --git a/src/r_things.cpp b/src/r_things.cpp index 8f99384c8..542b271a7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2970,8 +2970,21 @@ static void R_DrawMaskedList(drawnode_t* head) { drawspandata_t ds = {}; next = r2->prev; - // Force disable multithreading since it is usually slower because of waiting for each plane to render - R_DrawSinglePlane(&ds, r2->plane, false); + boolean parallel = cv_parallelsoftware.value && cv_paralleldrawmasked.value; +#ifdef HAVE_THREADS + srb2::ThreadPool::Sema tp_sema; + if (parallel) + srb2::g_main_threadpool->begin_sema(); +#endif + R_DrawSinglePlane(&ds, r2->plane, parallel); +#ifdef HAVE_THREADS + if (parallel) + { + tp_sema = srb2::g_main_threadpool->end_sema(); + srb2::g_main_threadpool->notify_sema(tp_sema); + srb2::g_main_threadpool->wait_sema(tp_sema); + } +#endif R_DoneWithNode(r2); r2 = next; } diff --git a/src/screen.c b/src/screen.c index 40e932442..eb6c2bc82 100644 --- a/src/screen.c +++ b/src/screen.c @@ -49,6 +49,7 @@ consvar_t cv_vhseffect = {"vhspause", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NU consvar_t cv_shittyscreen = {"televisionsignal", "Okay", CV_NOSHOWHELP, shittyscreen_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_parallelsoftware = {"parallelsoftware", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_paralleldrawmasked = {"paralleldrawmasked", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t votescale_cons_t[] = {{0, "Vanilla"}, {1, "Adaptive"}, {2, "VerticalFill"}, {3, "HorizontalFill"}, {0, NULL}}; consvar_t cv_votebgscaling = {"votebgscaling", "Adaptive", CV_SAVE, votescale_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/screen.h b/src/screen.h index c0a2799c1..38483b28d 100644 --- a/src/screen.h +++ b/src/screen.h @@ -88,6 +88,7 @@ extern UINT8 *scr_borderpatch; // patch used to fill the view borders extern consvar_t cv_scr_width, cv_scr_height, cv_renderview, cv_fullscreen, cv_vhseffect, cv_shittyscreen; extern consvar_t cv_parallelsoftware; +extern consvar_t cv_paralleldrawmasked; extern consvar_t cv_highreshudscale; // wait for page flipping to end or not