From d9a556c2e1eb8459c67cd4c1a56460a6ad150c66 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 13 Jul 2023 16:51:27 +0300 Subject: [PATCH] v5.4 --- src/Makefile | 1 + src/console.c | 15 +- src/d_clisrv.c | 14 +- src/d_main.c | 27 +- src/d_netcmd.c | 15 + src/d_netcmd.h | 4 + src/d_netfil.c | 21 +- src/doomdef.h | 4 +- src/hardware/hw_drv.h | 2 +- src/hardware/hw_glob.h | 3 - src/hardware/hw_main.c | 329 +++++++----- src/hardware/hw_main.h | 21 +- src/hardware/r_opengl/r_opengl.c | 13 +- src/k_kart.c | 18 +- src/lua_hooklib.c | 65 ++- src/m_menu.c | 4 + src/m_perfstats.c | 856 +++++++++++++++++++++++++++++++ src/m_perfstats.h | 61 +++ src/p_map.c | 4 + src/p_tick.c | 10 + src/r_bsp.c | 14 +- src/r_main.c | 56 +- src/r_main.h | 24 + src/r_plane.c | 8 +- src/r_plane.h | 5 + src/r_segs.c | 188 +++++-- src/r_things.c | 17 +- src/screen.c | 48 +- src/sdl/i_video.c | 5 + src/z_zone.h | 2 + 30 files changed, 1563 insertions(+), 291 deletions(-) create mode 100644 src/m_perfstats.c create mode 100644 src/m_perfstats.h diff --git a/src/Makefile b/src/Makefile index def78a582..6227daa44 100644 --- a/src/Makefile +++ b/src/Makefile @@ -564,6 +564,7 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/m_fixed.o \ $(OBJDIR)/m_menu.o \ $(OBJDIR)/m_misc.o \ + $(OBJDIR)/m_perfstats.o \ $(OBJDIR)/m_random.o \ $(OBJDIR)/m_queue.o \ $(OBJDIR)/info.o \ diff --git a/src/console.c b/src/console.c index 11a7961e8..f3e56aae8 100644 --- a/src/console.c +++ b/src/console.c @@ -709,14 +709,6 @@ void CON_Ticker(void) con_tick++; con_tick &= 7; - // if the menu is open then close the console. - if (menuactive && con_destlines) - { - consoletoggle = false; - con_destlines = 0; - CON_ClearHUD(); - } - // console key was pushed if (consoletoggle) { @@ -933,7 +925,7 @@ boolean CON_Responder(event_t *ev) // check other keys only if console prompt is active if (!consoleready && key < NUMINPUTS) // metzgermeister: boundary check!! { - if (bindtable[key]) + if (!menuactive && bindtable[key]) { COM_BufAddText(bindtable[key]); COM_BufAddText("\n"); @@ -1776,7 +1768,12 @@ void CON_Drawer(void) } if (con_recalc) + { CON_RecalcSize(); + + if (con_curlines <= 0) + CON_ClearHUD(); + } if (con_curlines > 0) CON_DrawConsole(); diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f3834f472..213c0eea1 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -48,6 +48,7 @@ #include "lua_hook.h" #include "k_kart.h" #include "s_sound.h" // sfx_syfail +#include "m_perfstats.h" #ifdef CLIENT_LOADINGSCREEN // cl loading screen @@ -3879,7 +3880,7 @@ consvar_t cv_maxsend = {"maxsend", "MAX", CV_SAVE, maxsend_cons_t, NULL, 0, NULL consvar_t cv_noticedownload = {"noticedownload", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // Speed of file downloading (in packets per tic) -static CV_PossibleValue_t downloadspeed_cons_t[] = {{0, "MIN"}, {32, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t downloadspeed_cons_t[] = {{1, "MIN"}, {300, "MAX"}, {0, NULL}}; consvar_t cv_downloadspeed = {"downloadspeed", "MAX", CV_SAVE, downloadspeed_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static void Got_AddPlayer(UINT8 **p, INT32 playernum); @@ -5977,12 +5978,23 @@ boolean TryRunTics(tic_t realtics) // run the count * tics while (neededtic > gametic) { + boolean update_stats = !(paused || P_AutoPause()); + DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); + + if (update_stats) + PS_START_TIMING(ps_tictime); G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; consistancy[gametic%TICQUEUE] = Consistancy(); + + if (update_stats) + { + PS_STOP_TIMING(ps_tictime); + PS_UpdateTickStats(); + } // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) diff --git a/src/d_main.c b/src/d_main.c index 97bf12c72..109aee851 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -78,6 +78,7 @@ int snprintf(char *str, size_t n, const char *fmt, ...); #include "keys.h" #include "filesrch.h" // refreshdirmenu #include "d_protocol.h" +#include "m_perfstats.h" #ifdef CMAKECONFIG #include "config.h" @@ -437,6 +438,8 @@ static void D_Display(void) // draw the view directly if (cv_renderview.value && !automapactive) { + PS_START_TIMING(ps_rendercalltime); + R_ApplyLevelInterpolators(R_UsingFrameInterpolation() ? rendertimefrac : FRACUNIT); for (i = 0; i <= splitscreen; i++) @@ -516,6 +519,8 @@ static void D_Display(void) } R_RestoreLevelInterpolators(); + + PS_STOP_TIMING(ps_rendercalltime); } if (lastdraw) @@ -528,9 +533,14 @@ static void D_Display(void) lastdraw = false; } + PS_START_TIMING(ps_uitime); ST_Drawer(); HU_Drawer(); } + else + { + PS_START_TIMING(ps_uitime); + } // change gamma if needed // (GS_LEVEL handles this already due to level-specific palettes) @@ -558,18 +568,18 @@ static void D_Display(void) // vid size change is now finished if it was on... vid.recalc = 0; - // FIXME: draw either console or menu, not the two - if (gamestate != GS_TIMEATTACK) - CON_Drawer(); - #ifdef HAVE_THREADS I_lock_mutex(&m_menu_mutex); #endif - M_Drawer(); // menu is drawn even on top of everything + M_Drawer(); // menu is drawn even on top of everything... #ifdef HAVE_THREADS I_unlock_mutex(m_menu_mutex); #endif // focus lost moved to M_Drawer + + PS_STOP_TIMING(ps_uitime); + + CON_Drawer(); // Ha, i LIED! // // wipe update @@ -620,8 +630,15 @@ static void D_Display(void) if (cv_shittyscreen.value) V_DrawVhsEffect(cv_shittyscreen.value == 2); + + if (cv_perfstats.value) + { + M_DrawPerfStats(); + } + PS_START_TIMING(ps_swaptime); I_FinishUpdate(); // page flip or blit buffer + PS_STOP_TIMING(ps_swaptime); } } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 343c0f15f..2a278f1a2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -49,6 +49,7 @@ #include "m_anigif.h" #include "k_kart.h" // SRB2kart #include "y_inter.h" +#include "m_perfstats.h" #ifdef NETGAME_DEVMODE #define CV_RESTRICT CV_NETVAR @@ -483,6 +484,16 @@ consvar_t cv_mute = {"mute", "Off", CV_NETVAR|CV_CALL, CV_OnOff, Mute_OnChange, consvar_t cv_sleep = {"cpusleep", "1", CV_SAVE, sleeping_cons_t, NULL, -1, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t perfstats_cons_t[] = { + {0, "Off"}, {1, "Rendering"}, {2, "Logic"}, {3, "ThinkFrame"}, {0, NULL}}; +consvar_t cv_perfstats = {"perfstats", "Off", CV_CALL, perfstats_cons_t, PS_PerfStats_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t ps_samplesize_cons_t[] = { + {1, "MIN"}, {1000, "MAX"}, {0, NULL}}; +consvar_t cv_ps_samplesize = {"ps_samplesize", "1", CV_CALL, ps_samplesize_cons_t, PS_SampleSize_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t ps_descriptor_cons_t[] = { + {1, "Average"}, {2, "SD"}, {3, "Minimum"}, {4, "Maximum"}, {0, NULL}}; +consvar_t cv_ps_descriptor = {"ps_descriptor", "Average", 0, ps_descriptor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_showtrackaddon = {"showtrackaddon", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t skinselectmenu_t[] = {{SKINMENUTYPE_SCROLL, "Scoll"}, {SKINMENUTYPE_2D, "2d"}, {SKINMENUTYPE_GRID, "Grid"}, {0, NULL}}; @@ -1031,6 +1042,10 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_soundtest); + CV_RegisterVar(&cv_perfstats); + CV_RegisterVar(&cv_ps_samplesize); + CV_RegisterVar(&cv_ps_descriptor); + CV_RegisterVar(&cv_invincmusicfade); CV_RegisterVar(&cv_growmusicfade); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 35d7e3004..dd246e80e 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -156,6 +156,10 @@ extern consvar_t cv_skipmapcheck; extern consvar_t cv_sleep; +extern consvar_t cv_perfstats; +extern consvar_t cv_ps_samplesize; +extern consvar_t cv_ps_descriptor; + extern consvar_t cv_showtrackaddon; typedef enum diff --git a/src/d_netfil.c b/src/d_netfil.c index 881b7b5b2..c23197ed8 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -804,8 +804,6 @@ static void SV_EndFileSend(INT32 node) filestosend--; } -#define PACKETPERTIC net_bandwidth/(TICRATE*software_MAXPACKETLENGTH) - /** Handles file transmission * * \todo Use an acknowledging method more adapted to file transmission @@ -825,24 +823,7 @@ void SV_FileSendTicker(void) if (!filestosend) // No file to send return; - if (cv_downloadspeed.value) // New (and experimental) behavior - { - packetsent = cv_downloadspeed.value; - // Don't send more packets than we have free acks -#ifndef NONET - maxpacketsent = Net_GetFreeAcks(false) - 5; // Let 5 extra acks just in case -#else - maxpacketsent = 1; -#endif - if (packetsent > maxpacketsent && maxpacketsent > 0) // Send at least one packet - packetsent = maxpacketsent; - } - else // Old behavior - { - packetsent = PACKETPERTIC; - if (!packetsent) - packetsent = 1; - } + packetsent = cv_downloadspeed.value; netbuffer->packettype = PT_FILEFRAGMENT; diff --git a/src/doomdef.h b/src/doomdef.h index 5161318c9..31412b105 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -149,8 +149,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v5.3 " -#define VERSIONSTRINGW L"Saturn v5.3" +#define VERSIONSTRING "Saturn v5.4 " +#define VERSIONSTRINGW L"Saturn v5.4" // 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! diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 1f831229e..b28681c42 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -75,7 +75,7 @@ EXPORT void HWRAPI(LoadCustomShader) (int number, char *shader, size_t size, boo EXPORT void HWRAPI(InitCustomShaders) (void); EXPORT void HWRAPI(StartBatching) (void); -EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors); +EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors); // ========================================================================== // HWR DRIVER OBJECT, FOR CLIENT PROGRAM diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 4146fa1da..3663f3f68 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -25,9 +25,6 @@ // equivalent of the software renderer's vissprites typedef struct gr_vissprite_s { - // Doubly linked list - struct gr_vissprite_s *prev; - struct gr_vissprite_s *next; float x1, x2; float z1, z2; float gz, gzt; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 96104d20b..c765150fc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -164,6 +164,23 @@ static sector_t *gr_backsector; boolean gr_shadersavailable = true; +// Performance stats +ps_metric_t ps_hw_nodesorttime = {0}; +ps_metric_t ps_hw_nodedrawtime = {0}; +ps_metric_t ps_hw_spritesorttime = {0}; +ps_metric_t ps_hw_spritedrawtime = {0}; + +// Performance stats for batching +ps_metric_t ps_hw_numpolys = {0}; +ps_metric_t ps_hw_numverts = {0}; +ps_metric_t ps_hw_numcalls = {0}; +ps_metric_t ps_hw_numshaders = {0}; +ps_metric_t ps_hw_numtextures = {0}; +ps_metric_t ps_hw_numpolyflags = {0}; +ps_metric_t ps_hw_numcolors = {0}; +ps_metric_t ps_hw_batchsorttime = {0}; +ps_metric_t ps_hw_batchdrawtime = {0}; + // ========================================================================== // View position // ========================================================================== @@ -828,7 +845,7 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend // // HWR_SplitWall // -void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor) +void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags) { /* SoM: split up and light walls according to the lightlist. This may also include leaving out parts @@ -863,6 +880,9 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa pegt = wallVerts[3].t; pegb = wallVerts[0].t; pegmul = (pegb - pegt) / (top - bot); + + if (fpclassify(pegmul) == FP_NAN) + pegmul = 0.0; #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; @@ -872,6 +892,9 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa endpegmul = (endpegb - endpegt) / (endtop - endbot); #endif + if (fpclassify(endpegmul) == FP_NAN) + endpegmul = 0.0; + for (i = 0; i < sector->numlights; i++) { #ifdef ESLOPE @@ -981,24 +1004,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif -#ifdef ESLOPE - if (endbheight >= endtop) -#endif - if (bheight >= top) - continue; + // Found a break + bot = min(max(bheight, realbot), top); + endbot = min(max(endbheight, endrealbot), endtop); - //Found a break; - bot = bheight; - - if (bot < realbot) - bot = realbot; - -#ifdef ESLOPE - endbot = endbheight; - - if (endbot < endrealbot) - endbot = endrealbot; -#endif Surf->PolyColor.s.alpha = alpha; #ifdef ESLOPE @@ -1022,11 +1031,11 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #endif if (cutflag & FF_FOG) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture, true, lightnum, colormap); + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); else - HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); + HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); top = bot; #ifdef ESLOPE @@ -1065,11 +1074,11 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #endif if (cutflag & FF_FOG) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture, true, lightnum, colormap); + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); else - HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); + HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); } // skywall list system for fixing portal issues by postponing skywall rendering (and using stencil buffer for them) @@ -1305,7 +1314,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE SLOPEPARAMS(gr_backsector->c_slope, worldhigh, worldhighslope, gr_backsector->ceilingheight) SLOPEPARAMS(gr_backsector->f_slope, worldlow, worldlowslope, gr_backsector->floorheight) -#undef SLOPEPARAMS #else worldhigh = gr_backsector->ceilingheight; worldlow = gr_backsector->floorheight; @@ -1502,7 +1510,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif if (!gl_drawing_stencil && gr_frontsector->numlights) - HWR_SplitWall(gr_frontsector, wallVerts, gr_toptexture, &Surf, FF_CUTLEVEL, NULL); + HWR_SplitWall(gr_frontsector, wallVerts, gr_toptexture, &Surf, FF_CUTLEVEL, NULL, 0); else if (!gl_drawing_stencil && grTex->mipmap.flags & TF_TRANSPARENT) HWR_AddTransparentWall(wallVerts, &Surf, gr_toptexture, PF_Environment, false, lightnum, colormap); else @@ -1584,7 +1592,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif if (!gl_drawing_stencil && gr_frontsector->numlights) - HWR_SplitWall(gr_frontsector, wallVerts, gr_bottomtexture, &Surf, FF_CUTLEVEL, NULL); + HWR_SplitWall(gr_frontsector, wallVerts, gr_bottomtexture, &Surf, FF_CUTLEVEL, NULL, 0); else if (!gl_drawing_stencil && grTex->mipmap.flags & TF_TRANSPARENT) HWR_AddTransparentWall(wallVerts, &Surf, gr_bottomtexture, PF_Environment, false, lightnum, colormap); else @@ -1593,10 +1601,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); if (gr_midtexture || gr_portal == GRPORTAL_STENCIL || gr_portal == GRPORTAL_DEPTH || gl_drawing_stencil) { - FBITFIELD blendmode; sector_t *front, *back; - fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; - fixed_t texturevpeg = 0; INT32 repeats; if (gr_linedef->frontsector->heightsec != -1) @@ -1631,6 +1636,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else repeats = 1; + + fixed_t midtexheight = textureheight[gr_midtexture] * repeats; + fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; + fixed_t popentopslope, popenbottomslope, polytopslope, polybottomslope, lowcutslope, highcutslope; // SoM: a little note: This code re-arranging will // fix the bug in Nimrod map02. popentop and popenbottom @@ -1645,8 +1654,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // From CB if (gr_curline->polyseg) { - popentop = back->ceilingheight; - popenbottom = back->floorheight; + popentop = popentopslope = back->ceilingheight; + popenbottom = popenbottomslope = back->floorheight; } else #endif @@ -1654,10 +1663,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); -#else - popentop = min(front->ceilingheight, back->ceilingheight); - popenbottom = max(front->floorheight, back->floorheight); -#endif + + popentopslope = min(worldtopslope, worldhighslope); + popenbottomslope = max(worldbottomslope, worldlowslope); } #ifdef ESLOPE @@ -1666,12 +1674,16 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) { polybottom = max(front->floorheight, back->floorheight) + gr_sidedef->rowoffset; - polytop = polybottom + textureheight[gr_midtexture]*repeats; + polybottomslope = polybottom; + polytop = polybottom + midtexheight; + polytopslope = polytop; } else { polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; - polybottom = polytop - textureheight[gr_midtexture]*repeats; + polytopslope = polytop; + polybottom = polytop - midtexheight; + polybottomslope = polybottom; } } else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) @@ -1680,13 +1692,19 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif { polybottom = popenbottom + gr_sidedef->rowoffset; - polytop = polybottom + textureheight[gr_midtexture]*repeats; + polytop = polybottom + midtexheight; + polybottomslope = popenbottomslope + gr_sidedef->rowoffset; + polytopslope = polybottomslope + midtexheight; } else { polytop = popentop + gr_sidedef->rowoffset; polybottom = polytop - textureheight[gr_midtexture]*repeats; + polybottom = polytop - midtexheight; + polytopslope = popentopslope + gr_sidedef->rowoffset; + polybottomslope = polytopslope - midtexheight; } + // CB #ifdef POLYOBJECTS // NOTE: With polyobjects, whenever you need to check the properties of the polyobject sector it belongs to, @@ -1695,6 +1713,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { lowcut = polybottom; highcut = polytop; + lowcutslope = polybottomslope; + highcutslope = polytopslope; } #endif else @@ -1702,83 +1722,50 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // The cut-off values of a linedef can always be constant, since every line has an absoulute front and or back sector lowcut = popenbottom; highcut = popentop; + lowcutslope = popenbottomslope; + highcutslope = popentopslope; } h = min(highcut, polytop); l = max(polybottom, lowcut); + hS = min(highcutslope, polytopslope); + lS = max(polybottomslope, lowcutslope); + + // PEGGING + fixed_t texturevpeg, texturevpegslope; + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) { - // PEGGING -#ifdef ESLOPE - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) -#else - if (gr_linedef->flags & ML_DONTPEGBOTTOM) -#endif - texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; - else - texturevpeg = polytop - h; - - grTex = HWR_GetTexture(gr_midtexture); - - wallVerts[3].t = wallVerts[2].t = texturevpeg * grTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; - wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; - wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + texturevpeg = midtexheight - h + polybottom; + texturevpegslope = midtexheight - hS + polybottomslope; } + else + { + texturevpeg = polytop - h; + texturevpegslope = polytopslope - hS; + } + + grTex = HWR_GetTexture(gr_midtexture); + + wallVerts[3].t = texturevpeg * grTex->scaleY; + wallVerts[0].t = (h - l + texturevpeg) * grTex->scaleY; + wallVerts[2].t = texturevpegslope * grTex->scaleY; + wallVerts[1].t = (hS - lS + texturevpegslope) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; // set top/bottom coords // Take the texture peg into account, rather than changing the offsets past // where the polygon might not be. - wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); - wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); - -#ifdef ESLOPE - // Correct to account for slopes - { - fixed_t midtextureslant; - - if (gr_linedef->flags & ML_EFFECT2) - midtextureslant = 0; - else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - midtextureslant = worldlow < worldbottom - ? worldbottomslope-worldbottom - : worldlowslope-worldlow; - else - midtextureslant = worldtop < worldhigh - ? worldtopslope-worldtop - : worldhighslope-worldhigh; - - polytop += midtextureslant; - polybottom += midtextureslant; - - highcut += worldtop < worldhigh - ? worldtopslope-worldtop - : worldhighslope-worldhigh; - lowcut += worldlow < worldbottom - ? worldbottomslope-worldbottom - : worldlowslope-worldlow; - - // Texture stuff - h = min(highcut, polytop); - l = max(polybottom, lowcut); - - { - // PEGGING - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; - else - texturevpeg = polytop - h; - wallVerts[2].t = texturevpeg * grTex->scaleY; - wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; - } - - wallVerts[2].y = FIXED_TO_FLOAT(h); - wallVerts[1].y = FIXED_TO_FLOAT(l); - } + wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = FIXED_TO_FLOAT(l); + wallVerts[2].y = FIXED_TO_FLOAT(hS); + wallVerts[1].y = FIXED_TO_FLOAT(lS); #endif // set alpha for transparent walls (new boom and legacy linedef types) - // ooops ! this do not work at all because render order we should render it in backtofront order + FBITFIELD blendmode; + switch (gr_linedef->special) { case 900: @@ -1845,13 +1832,17 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } #endif + // Render midtextures on two-sided lines with a z-buffer offset. + // This will cause the midtexture appear on top, if a FOF overlaps with it. + blendmode |= PF_Decal; + if (!gl_drawing_stencil && gr_frontsector->numlights) { if (!(blendmode & PF_Masked)) - HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL); + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL, PF_Decal); else { - HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL); + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, PF_Decal); } } else if (!gl_drawing_stencil && !(blendmode & PF_Masked)) @@ -1916,7 +1907,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif if (gr_frontsector->numlights) - HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL); + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, 0); // I don't think that solid walls can use translucent linedef types... else { @@ -1980,23 +1971,31 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!gl_drawing_stencil && gr_frontsector && gr_backsector && gr_frontsector->tag != gr_backsector->tag && (gr_backsector->ffloors || gr_frontsector->ffloors)) { ffloor_t * rover; - fixed_t highcut = 0, lowcut = 0; + fixed_t highcut = 0, lowcut = 0; + fixed_t lowcutslope, highcutslope; + + // Used for height comparisons and etc across FOFs and slopes + fixed_t high1, highslope1, low1, lowslope1; INT32 texnum; line_t * newline = NULL; // Multi-Property FOF - ///TODO add slope support (fixing cutoffs, proper wall clipping) - maybe just disable highcut/lowcut if either sector or FOF has a slope - /// to allow fun plane intersecting in OGL? But then people would abuse that and make software look bad. :C - highcut = gr_frontsector->ceilingheight < gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; - lowcut = gr_frontsector->floorheight > gr_backsector->floorheight ? gr_frontsector->floorheight : gr_backsector->floorheight; - + lowcut = max(worldbottom, worldlow); + highcut = min(worldtop, worldhigh); + lowcutslope = max(worldbottomslope, worldlowslope); + highcutslope = min(worldtopslope, worldhighslope); + if (gr_backsector->ffloors) { for (rover = gr_backsector->ffloors; rover; rover = rover->next) { if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || (rover->flags & FF_INVERTSIDES)) continue; - if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) + + if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); @@ -2013,10 +2012,17 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom hS = *rover->t_slope ? P_GetZAt(*rover->t_slope, v2x, v2y) : *rover->topheight; l = *rover->b_slope ? P_GetZAt(*rover->b_slope, v1x, v1y) : *rover->bottomheight; lS = *rover->b_slope ? P_GetZAt(*rover->b_slope, v2x, v2y) : *rover->bottomheight; - if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) - h = hS = highcut; - if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) - l = lS = lowcut; + // Adjust the heights so the FOF does not overlap with top and bottom textures. + if (h >= highcut && hS >= highcutslope) + { + h = highcut; + hS = highcutslope; + } + if (l <= lowcut && lS <= lowcutslope) + { + l = lowcut; + lS = lowcutslope; + } //Hurdler: HW code starts here //FIXME: check if peging is correct // set top/bottom coords @@ -2122,7 +2128,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom 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, &Surf, rover->flags, rover); + HWR_SplitWall(gr_frontsector, wallVerts, 0, &Surf, rover->flags, rover, 0); else HWR_AddTransparentWall(wallVerts, &Surf, 0, blendmode, true, lightnum, colormap); } @@ -2137,7 +2143,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } if (gr_frontsector->numlights) - HWR_SplitWall(gr_frontsector, wallVerts, texnum, &Surf, rover->flags, rover); + HWR_SplitWall(gr_frontsector, wallVerts, texnum, &Surf, rover->flags, rover, 0); else { if (blendmode != PF_Masked) @@ -2155,7 +2161,11 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_ALLSIDES)) continue; - if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) + + if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); @@ -2171,10 +2181,17 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom hS = *rover->t_slope ? P_GetZAt(*rover->t_slope, v2x, v2y) : *rover->topheight; l = *rover->b_slope ? P_GetZAt(*rover->b_slope, v1x, v1y) : *rover->bottomheight; lS = *rover->b_slope ? P_GetZAt(*rover->b_slope, v2x, v2y) : *rover->bottomheight; - if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) - h = hS = highcut; - if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) - l = lS = lowcut; + // Adjust the heights so the FOF does not overlap with top and bottom textures. + if (h >= highcut && hS >= highcutslope) + { + h = highcut; + hS = highcutslope; + } + if (l <= lowcut && lS <= lowcutslope) + { + l = lowcut; + lS = lowcutslope; + } //Hurdler: HW code starts here //FIXME: check if peging is correct // set top/bottom coords @@ -2234,7 +2251,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom 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, &Surf, rover->flags, rover); + HWR_SplitWall(gr_backsector, wallVerts, 0, &Surf, rover->flags, rover, 0); else HWR_AddTransparentWall(wallVerts, &Surf, 0, blendmode, true, lightnum, colormap); } @@ -2249,7 +2266,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } if (gr_backsector->numlights) - HWR_SplitWall(gr_backsector, wallVerts, texnum, &Surf, rover->flags, rover); + HWR_SplitWall(gr_backsector, wallVerts, texnum, &Surf, rover->flags, rover, 0); else { if (blendmode != PF_Masked) @@ -2261,6 +2278,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } } } + +#undef SLOPEPARAMS //Hurdler: end of 3d-floors test } @@ -2428,8 +2447,8 @@ void HWR_AddLine(seg_t *line) v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngleEx(viewx, viewy, v1x, v1y); - angle2 = R_PointToAngleEx(viewx, viewy, v2x, v2y); + angle1 = R_PointToAngle64(v1x, v1y); + angle2 = R_PointToAngle64(v2x, v2y); // do an extra culling check when rendering portals // check if any line vertex is on the viewable side of the portal target line @@ -2726,8 +2745,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngleEx(viewx, viewy, px1, py1); - angle2 = R_PointToAngleEx(viewx, viewy, px2, py2); + angle1 = R_PointToAngle64(px1, py1); + angle2 = R_PointToAngle64(px2, py2); return gld_clipper_SafeCheckRange(angle2, angle1); } @@ -3312,6 +3331,9 @@ void HWR_Subsector(size_t num) ++numpolys; po = (polyobj_t *)(po->link.next); } + + // for performance stats + ps_numpolyobjects.value.i += numpolys; // Sort polyobjects R_SortPolyObjects(sub); @@ -3432,6 +3454,8 @@ void HWR_RenderBSPNode(INT32 bspnum) // Decide which side the view point is on INT32 side; + + ps_numbspcalls.value.i++; // Found a subsector? if (bspnum & NF_SUBSECTOR) @@ -4371,12 +4395,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) HWR_Lighting(&Surf, lightlevel, colormap); } - if (spr->mobj->flags2 & MF2_SHADOW) - { - Surf.PolyColor.s.alpha = 0x40; - blend = PF_Translucent; - } - else if (spr->mobj->frame & FF_TRANSMASK) + if (spr->mobj->frame & FF_TRANSMASK) blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); else { @@ -4616,6 +4635,8 @@ void HWR_RenderDrawNodes(void) // However, in reality we shouldn't be re-copying and shifting all this information // that is already lying around. This should all be in some sort of linked list or lists. sortindex = Z_Calloc(sizeof(size_t) * (numplanes + numpolyplanes + numwalls), PU_STATIC, NULL); + + PS_START_TIMING(ps_hw_nodesorttime); for (i = 0; i < numplanes; i++, p++) { @@ -4634,6 +4655,8 @@ void HWR_RenderDrawNodes(void) sortnode[p].wall = &wallinfo[i]; sortindex[p] = p; } + + ps_numdrawnodes.value.i = p; // p is the number of stuff to sort @@ -4676,6 +4699,10 @@ void HWR_RenderDrawNodes(void) run_start++; } } + + PS_STOP_TIMING(ps_hw_nodesorttime); + + PS_START_TIMING(ps_hw_nodedrawtime); // Okay! Let's draw it all! Woo! HWD.pfnSetTransform(&atransform); @@ -4711,6 +4738,8 @@ void HWR_RenderDrawNodes(void) sortnode[sortindex[i]].wall->lightlevel, sortnode[sortindex[i]].wall->wallcolormap); } } + + PS_STOP_TIMING(ps_hw_nodedrawtime); numwalls = 0; numplanes = 0; @@ -5676,14 +5705,25 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * validcount++; if (cv_grbatching.value) HWD.pfnStartBatching(); + + ps_numbspcalls.value.i = 0; + ps_numpolyobjects.value.i = 0; + PS_START_TIMING(ps_bsptime); + if (!rootportal && portallist.base && !skybox)// if portals have been drawn in the main view, then render skywalls differently gr_collect_skywalls = true; + + // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); + + PS_STOP_TIMING(ps_bsptime); + if (cv_grbatching.value) { - int dummy = 0;// the vars in RenderBatches are meant for render stats. But we don't have that stuff in this branch - // so that stuff could be removed... - HWD.pfnRenderBatches(&dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy); + HWD.pfnRenderBatches(&ps_hw_batchsorttime.value.p, &ps_hw_batchdrawtime.value.p, + &ps_hw_numpolys.value.i, &ps_hw_numverts.value.i, &ps_hw_numcalls.value.i, + &ps_hw_numshaders.value.i, &ps_hw_numtextures.value.i, &ps_hw_numpolyflags.value.i, + &ps_hw_numcolors.value.i); } if (skyWallVertexArraySize)// if there are skywalls to draw using the alternate method { @@ -5873,8 +5913,19 @@ void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, play // Render the BSP from the new viewpoint. portalcullsector = gr_portalcullsectors[portalnum]; HWR_RenderBSPNode((INT32)numnodes - 1); + + // Draw MD2 and sprites + ps_numsprites.value.i = gr_visspritecount; + PS_START_TIMING(ps_hw_spritesorttime); HWR_SortVisSprites(); + PS_STOP_TIMING(ps_hw_spritesorttime); + PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); + PS_STOP_TIMING(ps_hw_spritedrawtime); + + ps_numdrawnodes.value.i = 0; + ps_hw_nodesorttime.value.p = 0; + ps_hw_nodedrawtime.value.p = 0; if (numplanes || numpolyplanes || numwalls) // Render FOFs and translucent walls after everything HWR_RenderDrawNodes(); } @@ -5903,12 +5954,14 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) return; // Render the skybox if there is one. + PS_START_TIMING(ps_skyboxtime); drewsky = false; if (skybox) { R_SkyboxFrame(player); HWR_RenderFrame(viewnumber, player, true); } + PS_STOP_TIMING(ps_skyboxtime); R_SetupFrame(player, false); // This can stay false because it is only used to set viewsky in r_main.c, which isn't used here framecount++; // for timedemo diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 7245d6f98..efa61b2fd 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -29,6 +29,7 @@ #include "../am_map.h" #include "../d_player.h" #include "../r_defs.h" +#include "../m_perfstats.h" #define GLENCORE @@ -42,6 +43,23 @@ extern float gr_basewindowcenterx, gr_basewindowcentery; extern FTransform atransform; +// Performance stats +extern ps_metric_t ps_hw_nodesorttime; +extern ps_metric_t ps_hw_nodedrawtime; +extern ps_metric_t ps_hw_spritesorttime; +extern ps_metric_t ps_hw_spritedrawtime; + +// Performance stats for batching +extern ps_metric_t ps_hw_numpolys; +extern ps_metric_t ps_hw_numverts; +extern ps_metric_t ps_hw_numcalls; +extern ps_metric_t ps_hw_numshaders; +extern ps_metric_t ps_hw_numtextures; +extern ps_metric_t ps_hw_numpolyflags; +extern ps_metric_t ps_hw_numcolors; +extern ps_metric_t ps_hw_batchsorttime; +extern ps_metric_t ps_hw_batchdrawtime; + // hw_draw.c void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option); void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap); @@ -102,7 +120,7 @@ void HWR_ProcessSeg(void); // Sort of like GLWall::Process in GZDoom void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blendmode, INT32 lightlevel, extracolormap_t *wallcolormap); void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo * pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); -void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor); +void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags); void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf); void HWR_DrawSkyBackground(float fpov); @@ -151,6 +169,7 @@ extern consvar_t cv_grsolvetjoin; extern consvar_t cv_grspritebillboarding; extern consvar_t cv_grfakecontrast; extern consvar_t cv_grfallbackplayermodel; +extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grportals; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b546071cd..a12962008 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -27,6 +27,7 @@ #include "r_vbo.h" #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) +#include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) // Eeeeh not sure is this right way, but it works extern consvar_t cv_grusecustomshaders; @@ -1922,7 +1923,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) } // the parameters for this functions (numPolys etc.) are used to return rendering stats -EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors) +EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors) { int finalVertexWritePos = 0;// position in finalVertexArray int finalIndexWritePos = 0;// position in finalVertexIndexArray @@ -1946,7 +1947,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall gl_batching = false;// no longer collecting batches if (!polygonArraySize) { - *sNumPolys = *sNumCalls = *sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 0; + *sSortTime = *sDrawTime = *sNumPolys = *sNumCalls = *sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 0; return;// nothing to draw } // init stats vars @@ -1961,12 +1962,12 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall // sort polygons //CONS_Printf("qsort polys\n"); - //*sSortTime = I_GetTimeMicros(); + *sSortTime = I_GetPreciseTime(); if (gl_allowshaders) qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons); else qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders); - //*sSortTime = I_GetTimeMicros() - *sSortTime; + *sSortTime = I_GetPreciseTime() - *sSortTime; //CONS_Printf("sort done\n"); // sort order // 1. shader @@ -1975,7 +1976,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall // 4. colors + light level // not sure about order of last 2, or if it even matters - //*sDrawTime = I_GetTimeMicros(); + *sDrawTime = I_GetPreciseTime(); currentShader = polygonArray[polygonIndexArray[0]].shader; currentTexture = polygonArray[polygonIndexArray[0]].texNum; @@ -2262,7 +2263,7 @@ EXPORT void HWRAPI(RenderBatches) (int *sNumPolys, int *sNumVerts, int *sNumCall polygonArraySize = 0; unsortedVertexArraySize = 0; - //*sDrawTime = I_GetTimeMicros() - *sDrawTime; + *sDrawTime = I_GetPreciseTime() - *sDrawTime; } // -----------------+ diff --git a/src/k_kart.c b/src/k_kart.c index 8e498ed84..7390a9c06 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7127,17 +7127,17 @@ static void K_initKartHUD(void) // Single Screen (defaults) // Item Window - ITEM_X = 5; // 5 - ITEM_Y = 5; // 5 + ITEM_X = 2; // 5 + ITEM_Y = 2; // 5 // Level Timer - TIME_X = BASEVIDWIDTH - 148; // 172 - TIME_Y = 9; // 9 + TIME_X = BASEVIDWIDTH - 142; // 172 + TIME_Y = 2; // 9 // Level Laps - LAPS_X = 9; // 9 - LAPS_Y = BASEVIDHEIGHT - 29; // 171 + LAPS_X = 2; // 9 + LAPS_Y = BASEVIDHEIGHT - 23; // 171 // Speedometer - SPDM_X = 9; // 9 - SPDM_Y = BASEVIDHEIGHT - 45; // 155 + SPDM_X = 1; // 9 + SPDM_Y = BASEVIDHEIGHT - 38; // 155 // Position Number POSI_X = BASEVIDWIDTH - 9; // 268 POSI_Y = BASEVIDHEIGHT - 9; // 138 @@ -7150,7 +7150,7 @@ static void K_initKartHUD(void) // CHECK graphic CHEK_Y = BASEVIDHEIGHT; // 200 // Minimap - MINI_X = BASEVIDWIDTH - 50; // 270 + MINI_X = BASEVIDWIDTH - 40; // 270 MINI_Y = (BASEVIDHEIGHT/2)-16; // 84 // Battle WANTED poster WANT_X = BASEVIDWIDTH - 55; // 270 diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 9720929ed..d5cb18432 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -18,6 +18,7 @@ #include "r_things.h" #include "b_bot.h" #include "z_zone.h" +#include "m_perfstats.h" #include "lua_script.h" #include "lua_libs.h" @@ -259,6 +260,9 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which) return false; I_Assert(mo->type < NUMMOBJTYPES); + + if (!(mobjhooks[MT_NULL] || mobjhooks[mo->type])) + return false; lua_settop(gL, 0); @@ -266,6 +270,7 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which) for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == which) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) LUA_PushUserdata(gL, mo, META_MOBJ); lua_pushfstring(gL, FMT_HOOKID, hookp->id); @@ -286,6 +291,7 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which) for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next) if (hookp->type == which) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) LUA_PushUserdata(gL, mo, META_MOBJ); lua_pushfstring(gL, FMT_HOOKID, hookp->id); @@ -319,6 +325,7 @@ boolean LUAh_PlayerHook(player_t *plr, enum hook which) for (hookp = playerhooks; hookp; hookp = hookp->next) if (hookp->type == which) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) LUA_PushUserdata(gL, plr, META_PLAYER); lua_pushfstring(gL, FMT_HOOKID, hookp->id); @@ -433,12 +440,17 @@ void LUAh_PreThinkFrame(void) void LUAh_ThinkFrame(void) { hook_p hookp; + // variables used by perf stats + int hook_index = 0; + precise_t time_taken = 0; if (!gL || !(hooksAvailable[hook_ThinkFrame/8] & (1<<(hook_ThinkFrame%8)))) return; for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_ThinkFrame) { + if (cv_perfstats.value == 3) + time_taken = I_GetPreciseTime(); lua_pushfstring(gL, FMT_HOOKID, hookp->id); lua_gettable(gL, LUA_REGISTRYINDEX); if (lua_pcall(gL, 0, 0, 0)) { @@ -447,6 +459,17 @@ void LUAh_ThinkFrame(void) lua_pop(gL, 1); hookp->error = true; } + if (cv_perfstats.value == 3) + { + lua_Debug ar; + time_taken = I_GetPreciseTime() - time_taken; + // we need the function, let's just retrieve it again + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_getinfo(gL, ">S", &ar); + PS_SetThinkFrameHookInfo(hook_index, time_taken, ar.short_src); + hook_index++; + } } } @@ -525,6 +548,9 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which) return 0; I_Assert(thing1->type < NUMMOBJTYPES); + + if (!(mobjcollidehooks[MT_NULL] || mobjcollidehooks[thing1->type])) + return 0; lua_settop(gL, 0); @@ -532,6 +558,7 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which) for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == which) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, thing1, META_MOBJ); @@ -561,6 +588,7 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which) for (hookp = mobjcollidehooks[thing1->type]; hookp; hookp = hookp->next) if (hookp->type == which) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, thing1, META_MOBJ); @@ -600,12 +628,16 @@ boolean LUAh_MobjThinker(mobj_t *mo) return false; I_Assert(mo->type < NUMMOBJTYPES); + + if (!(mobjthinkerhooks[MT_NULL] || mobjthinkerhooks[mo->type])) + return false; lua_settop(gL, 0); // Look for all generic mobj thinker hooks for (hookp = mobjthinkerhooks[MT_NULL]; hookp; hookp = hookp->next) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) LUA_PushUserdata(gL, mo, META_MOBJ); lua_pushfstring(gL, FMT_HOOKID, hookp->id); @@ -625,6 +657,7 @@ boolean LUAh_MobjThinker(mobj_t *mo) for (hookp = mobjthinkerhooks[mo->type]; hookp; hookp = hookp->next) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) LUA_PushUserdata(gL, mo, META_MOBJ); lua_pushfstring(gL, FMT_HOOKID, hookp->id); @@ -652,9 +685,12 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher) hook_p hookp; boolean hooked = false; if (!gL || !(hooksAvailable[hook_TouchSpecial/8] & (1<<(hook_TouchSpecial%8)))) - return 0; + return false; I_Assert(special->type < NUMMOBJTYPES); + + if (!(mobjhooks[MT_NULL] || mobjhooks[special->type])) + return false; lua_settop(gL, 0); @@ -662,6 +698,7 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher) for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == hook_TouchSpecial) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, special, META_MOBJ); @@ -686,6 +723,7 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher) for (hookp = mobjhooks[special->type]; hookp; hookp = hookp->next) if (hookp->type == hook_TouchSpecial) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, special, META_MOBJ); @@ -720,6 +758,9 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 return 0; I_Assert(target->type < NUMMOBJTYPES); + + if (!(mobjhooks[MT_NULL] || mobjhooks[target->type])) + return 0; lua_settop(gL, 0); @@ -727,6 +768,7 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldDamage) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, target, META_MOBJ); @@ -760,6 +802,7 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldDamage) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, target, META_MOBJ); @@ -800,9 +843,12 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 hook_p hookp; boolean hooked = false; if (!gL || !(hooksAvailable[hook_MobjDamage/8] & (1<<(hook_MobjDamage%8)))) - return 0; + return false; I_Assert(target->type < NUMMOBJTYPES); + + if (!(mobjhooks[MT_NULL] || mobjhooks[target->type])) + return false; lua_settop(gL, 0); @@ -810,6 +856,7 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == hook_MobjDamage) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, target, META_MOBJ); @@ -838,6 +885,7 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next) if (hookp->type == hook_MobjDamage) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, target, META_MOBJ); @@ -873,9 +921,12 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source) hook_p hookp; boolean hooked = false; if (!gL || !(hooksAvailable[hook_MobjDeath/8] & (1<<(hook_MobjDeath%8)))) - return 0; + return false; I_Assert(target->type < NUMMOBJTYPES); + + if (!(mobjhooks[MT_NULL] || mobjhooks[target->type])) + return false; lua_settop(gL, 0); @@ -909,6 +960,7 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source) for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next) if (hookp->type == hook_MobjDeath) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, target, META_MOBJ); @@ -1089,6 +1141,7 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector) for (hookp = linedefexecutorhooks; hookp; hookp = hookp->next) if (!strcmp(hookp->s.funcname, line->text)) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, line, META_LINE); @@ -1338,6 +1391,7 @@ UINT8 LUAh_ShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldSpin) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -1385,6 +1439,7 @@ UINT8 LUAh_ShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldExplode) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -1432,6 +1487,7 @@ UINT8 LUAh_ShouldSquish(player_t *player, mobj_t *inflictor, mobj_t *source) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldSquish) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -1479,6 +1535,7 @@ boolean LUAh_PlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerSpin) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -1520,6 +1577,7 @@ boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerSquish) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -1561,6 +1619,7 @@ boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerExplode) { + ps_lua_mobjhooks.value.i++; if (lua_gettop(gL) == 0) { LUA_PushUserdata(gL, player, META_PLAYER); diff --git a/src/m_menu.c b/src/m_menu.c index a5bd9e6a2..6cda6876a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2703,6 +2703,9 @@ boolean M_Responder(event_t *ev) || gamestate == GS_INTRO || gamestate == GS_CUTSCENE || gamestate == GS_GAMEEND || gamestate == GS_CREDITS || gamestate == GS_EVALUATION) return false; + + if (CON_Ready() && gamestate != GS_WAITINGPLAYERS) + return false; if (noFurtherInput) { @@ -3202,6 +3205,7 @@ boolean M_Responder(event_t *ev) return false; default: + CON_Responder(ev); break; } diff --git a/src/m_perfstats.c b/src/m_perfstats.c new file mode 100644 index 000000000..be04cc94f --- /dev/null +++ b/src/m_perfstats.c @@ -0,0 +1,856 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020-2023 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file m_perfstats.c +/// \brief Performance measurement tools. + +#include "m_perfstats.h" +#include "v_video.h" +#include "i_video.h" +#include "d_netcmd.h" +#include "r_main.h" +#include "i_system.h" +#include "z_zone.h" +#include "p_local.h" +#include "r_fps.h" + +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + +struct perfstatrow; + +typedef struct perfstatrow perfstatrow_t; + +struct perfstatrow { + const char * lores_label; + const char * hires_label; + ps_metric_t * metric; + UINT8 flags; +}; + +// perfstatrow_t flags + +#define PS_TIME 1 // metric measures time (uses precise_t instead of INT32) +#define PS_LEVEL 2 // metric is valid only when a level is active +#define PS_SW 4 // metric is valid only in software mode +#define PS_HW 8 // metric is valid only in opengl mode +#define PS_BATCHING 16 // metric is valid only when opengl batching is active +#define PS_HIDE_ZERO 32 // hide metric if its value is zero + +static ps_metric_t ps_frametime = {0}; + +ps_metric_t ps_tictime = {0}; + +ps_metric_t ps_playerthink_time = {0}; +ps_metric_t ps_thinkertime = {0}; + +//ps_metric_t ps_thlist_times[NUM_THINKERLISTS]; + +static ps_metric_t ps_thinkercount = {0}; +static ps_metric_t ps_mobjcount = {0}; +static ps_metric_t ps_regularcount = {0}; +static ps_metric_t ps_scenerycount = {0}; +static ps_metric_t ps_nothinkcount = {0}; +static ps_metric_t ps_otherthcount = {0}; +static ps_metric_t ps_precipcount = {0}; +static ps_metric_t ps_removecount = {0}; + +ps_metric_t ps_checkposition_calls = {0}; + +ps_metric_t ps_lua_thinkframe_time = {0}; +ps_metric_t ps_lua_mobjhooks = {0}; + +ps_metric_t ps_otherlogictime = {0}; + +// Columns for perfstats pages. + +// Position on screen is determined separately in the drawing functions. + +// New columns must also be added to the drawing and update functions. +// Drawing functions: PS_DrawRenderStats, PS_DrawGameLogicStats, etc. +// Update functions: +// - PS_UpdateFrameStats for frame-dependent values +// - PS_UpdateTickStats for tick-dependent values + +// Rendering stats columns + +perfstatrow_t rendertime_rows[] = { + {"frmtime", "Frame time: ", &ps_frametime, PS_TIME}, + {"drwtime", "3d rendering: ", &ps_rendercalltime, PS_TIME|PS_LEVEL}, + +#ifdef HWRENDER + {" skybox ", " Skybox render: ", &ps_skyboxtime, PS_TIME|PS_LEVEL|PS_HW}, + {" bsptime", " RenderBSPNode: ", &ps_bsptime, PS_TIME|PS_LEVEL|PS_HW}, + {" batsort", " Batch sort: ", &ps_hw_batchsorttime, PS_TIME|PS_LEVEL|PS_HW|PS_BATCHING}, + {" batdraw", " Batch render: ", &ps_hw_batchdrawtime, PS_TIME|PS_LEVEL|PS_HW|PS_BATCHING}, + {" sprsort", " Sprite sort: ", &ps_hw_spritesorttime, PS_TIME|PS_LEVEL|PS_HW}, + {" sprdraw", " Sprite render: ", &ps_hw_spritedrawtime, PS_TIME|PS_LEVEL|PS_HW}, + {" nodesrt", " Drwnode sort: ", &ps_hw_nodesorttime, PS_TIME|PS_LEVEL|PS_HW}, + {" nodedrw", " Drwnode render:", &ps_hw_nodedrawtime, PS_TIME|PS_LEVEL|PS_HW}, + {" other ", " Other: ", &ps_otherrendertime, PS_TIME|PS_LEVEL|PS_HW}, +#endif + + {" skybox ", " Skybox render: ", &ps_skyboxtime, PS_TIME|PS_LEVEL|PS_SW}, + {" bsptime", " RenderBSPNode: ", &ps_bsptime, PS_TIME|PS_LEVEL|PS_SW}, + {" sprclip", " R_ClipSprites: ", &ps_sw_spritecliptime, PS_TIME|PS_LEVEL|PS_SW}, + {" portals", " Portals: ", &ps_sw_portaltime, PS_TIME|PS_LEVEL|PS_SW}, + {" planes ", " R_DrawPlanes: ", &ps_sw_planetime, PS_TIME|PS_LEVEL|PS_SW}, + {" masked ", " R_DrawMasked: ", &ps_sw_maskedtime, PS_TIME|PS_LEVEL|PS_SW}, + {" other ", " Other: ", &ps_otherrendertime, PS_TIME|PS_LEVEL|PS_SW}, + + {"ui ", "UI render: ", &ps_uitime, PS_TIME}, + {"finupdt", "I_FinishUpdate:", &ps_swaptime, PS_TIME}, + {0} +}; + +perfstatrow_t gamelogicbrief_row[] = { + {"logic ", "Game logic: ", &ps_tictime, PS_TIME}, + {0} +}; + +perfstatrow_t commoncounter_rows[] = { + {"bspcall", "BSP calls: ", &ps_numbspcalls, 0}, + {"sprites", "Sprites: ", &ps_numsprites, 0}, + {"drwnode", "Drawnodes: ", &ps_numdrawnodes, 0}, + {"plyobjs", "Polyobjects: ", &ps_numpolyobjects, 0}, + {0} +}; + +/*perfstatrow_t interpolation_rows[] = { + {"intpfrc", "Interp frac: ", &ps_interp_frac, PS_TIME}, + {"intplag", "Interp lag: ", &ps_interp_lag, PS_TIME}, + {0} +};*/ + +#ifdef HWRENDER +perfstatrow_t batchcount_rows[] = { + {"polygon", "Polygons: ", &ps_hw_numpolys, 0}, + {"vertex ", "Vertices: ", &ps_hw_numverts, 0}, + {0} +}; + +perfstatrow_t batchcalls_rows[] = { + {"drwcall", "Draw calls:", &ps_hw_numcalls, 0}, + {"shaders", "Shaders: ", &ps_hw_numshaders, 0}, + {"texture", "Textures: ", &ps_hw_numtextures, 0}, + {"polyflg", "Polyflags: ", &ps_hw_numpolyflags, 0}, + {"colors ", "Colors: ", &ps_hw_numcolors, 0}, + {0} +}; +#endif + +// Game logic stats columns + +perfstatrow_t gamelogic_rows[] = { + {"logic ", "Game logic: ", &ps_tictime, PS_TIME}, + {" plrthnk", " P_PlayerThink: ", &ps_playerthink_time, PS_TIME|PS_LEVEL}, + {" thnkers", " P_RunThinkers: ", &ps_thinkertime, PS_TIME|PS_LEVEL}, +/* {" plyobjs", " Polyobjects: ", &ps_thlist_times[THINK_POLYOBJ], PS_TIME|PS_LEVEL}, + {" main ", " Main: ", &ps_thlist_times[THINK_MAIN], PS_TIME|PS_LEVEL}, + {" mobjs ", " Mobjs: ", &ps_thlist_times[THINK_MOBJ], PS_TIME|PS_LEVEL}, + {" dynslop", " Dynamic slopes: ", &ps_thlist_times[THINK_DYNSLOPE], PS_TIME|PS_LEVEL}, + {" precip ", " Precipitation: ", &ps_thlist_times[THINK_PRECIP], PS_TIME|PS_LEVEL},*/ + {" lthinkf", " LUAh_ThinkFrame:", &ps_lua_thinkframe_time, PS_TIME|PS_LEVEL}, + {" other ", " Other: ", &ps_otherlogictime, PS_TIME|PS_LEVEL}, + {0} +}; + +perfstatrow_t thinkercount_rows[] = { + {"thnkers", "Thinkers: ", &ps_thinkercount, PS_LEVEL}, + {" mobjs ", " Mobjs: ", &ps_mobjcount, PS_LEVEL}, + {" regular", " Regular: ", &ps_regularcount, PS_LEVEL}, + {" scenery", " Scenery: ", &ps_scenerycount, PS_LEVEL}, + {" nothink", " Nothink: ", &ps_nothinkcount, PS_HIDE_ZERO|PS_LEVEL}, + {" other ", " Other: ", &ps_otherthcount, PS_LEVEL}, + {" precip ", " Precipitation: ", &ps_precipcount, PS_LEVEL}, + {" remove ", " Pending removal:", &ps_removecount, PS_LEVEL}, + {0} +}; + +perfstatrow_t misc_calls_rows[] = { + {"lmhook", "Lua mobj hooks: ", &ps_lua_mobjhooks, PS_LEVEL}, + {"chkpos", "P_CheckPosition:", &ps_checkposition_calls, PS_LEVEL}, + {0} +}; + +// Sample collection status for averaging. +// Maximum of these two is shown to user if nonzero to tell that +// the reported averages are not correct yet. +int ps_frame_samples_left = 0; +int ps_tick_samples_left = 0; +// History writing positions for frame and tick based metrics +int ps_frame_index = 0; +int ps_tick_index = 0; + +// dynamically allocated resizeable array for thinkframe hook stats +ps_hookinfo_t *thinkframe_hooks = NULL; +int thinkframe_hooks_length = 0; +int thinkframe_hooks_capacity = 16; + +void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) +{ + if (!thinkframe_hooks) + { + // array needs to be initialized + thinkframe_hooks = Z_Calloc(sizeof(ps_hookinfo_t) * thinkframe_hooks_capacity, PU_STATIC, NULL); + } + if (index >= thinkframe_hooks_capacity) + { + // array needs more space, realloc with double size + int new_capacity = thinkframe_hooks_capacity * 2; + thinkframe_hooks = Z_Realloc(thinkframe_hooks, + sizeof(ps_hookinfo_t) * new_capacity, PU_STATIC, NULL); + // initialize new memory with zeros so the pointers in the structs are null + memset(&thinkframe_hooks[thinkframe_hooks_capacity], 0, + sizeof(ps_hookinfo_t) * thinkframe_hooks_capacity); + thinkframe_hooks_capacity = new_capacity; + } + thinkframe_hooks[index].time_taken.value.p = time_taken; + memcpy(thinkframe_hooks[index].short_src, short_src, LUA_IDSIZE * sizeof(char)); + // since the values are set sequentially from begin to end, the last call should leave + // the correct value to this variable + thinkframe_hooks_length = index + 1; +} + +static boolean PS_HighResolution(void) +{ + return (vid.width >= 640 && vid.height >= 400); +} + +static boolean PS_IsLevelActive(void) +{ + return gamestate == GS_LEVEL; +} + +// Is the row valid in the current context? +static boolean PS_IsRowValid(perfstatrow_t *row) +{ + return !((row->flags & PS_LEVEL && !PS_IsLevelActive()) + || (row->flags & PS_SW && rendermode != render_soft) + || (row->flags & PS_HW && rendermode != render_opengl) +#ifdef HWRENDER + || (row->flags & PS_BATCHING && !cv_grbatching.value) +#endif + ); +} + +// Should the row be visible on the screen? +static boolean PS_IsRowVisible(perfstatrow_t *row) +{ + boolean value_is_zero; + + if (row->flags & PS_TIME) + value_is_zero = row->metric->value.p == 0; + else + value_is_zero = row->metric->value.i == 0; + + return !(!PS_IsRowValid(row) || + (row->flags & PS_HIDE_ZERO && value_is_zero)); +} + +static INT32 PS_GetMetricAverage(ps_metric_t *metric, boolean time_metric) +{ + char* history_read_pos = metric->history; // char* used for pointer arithmetic + INT64 sum = 0; + int i; + int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); + + for (i = 0; i < cv_ps_samplesize.value; i++) + { + if (time_metric) + sum += (*((precise_t*)history_read_pos)) / (I_GetPrecisePrecision() / 1000000); + else + sum += *((INT32*)history_read_pos); + history_read_pos += value_size; + } + + return sum / cv_ps_samplesize.value; +} + +static INT32 PS_GetMetricMinOrMax(ps_metric_t *metric, boolean time_metric, boolean get_max) +{ + char* history_read_pos = metric->history; // char* used for pointer arithmetic + INT32 found_value = get_max ? INT32_MIN : INT32_MAX; + int i; + int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); + + for (i = 0; i < cv_ps_samplesize.value; i++) + { + INT32 value; + if (time_metric) + value = (*((precise_t*)history_read_pos)) / (I_GetPrecisePrecision() / 1000000); + else + value = *((INT32*)history_read_pos); + + if ((get_max && value > found_value) || + (!get_max && value < found_value)) + { + found_value = value; + } + history_read_pos += value_size; + } + + return found_value; +} + +// Calculates the standard deviation for metric. +static INT32 PS_GetMetricSD(ps_metric_t *metric, boolean time_metric) +{ + char* history_read_pos = metric->history; // char* used for pointer arithmetic + INT64 sum = 0; + int i; + int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); + INT32 avg = PS_GetMetricAverage(metric, time_metric); + + for (i = 0; i < cv_ps_samplesize.value; i++) + { + INT64 value; + if (time_metric) + value = (*((precise_t*)history_read_pos)) / (I_GetPrecisePrecision() / 1000000); + else + value = *((INT32*)history_read_pos); + + value -= avg; + sum += value * value; + + history_read_pos += value_size; + } + + return round(sqrt(sum / cv_ps_samplesize.value)); +} + +// Returns the value to show on screen for metric. +static INT32 PS_GetMetricScreenValue(ps_metric_t *metric, boolean time_metric) +{ + if (cv_ps_samplesize.value > 1 && metric->history) + { + if (cv_ps_descriptor.value == 1) + return PS_GetMetricAverage(metric, time_metric); + else if (cv_ps_descriptor.value == 2) + return PS_GetMetricSD(metric, time_metric); + else if (cv_ps_descriptor.value == 3) + return PS_GetMetricMinOrMax(metric, time_metric, false); + else + return PS_GetMetricMinOrMax(metric, time_metric, true); + } + else + { + if (time_metric) + return (metric->value.p) / (I_GetPrecisePrecision() / 1000000); + else + return metric->value.i; + } +} + +static int PS_DrawPerfRows(int x, int y, int color, perfstatrow_t *rows) +{ + const boolean hires = PS_HighResolution(); + INT32 draw_flags = V_MONOSPACE | color; + perfstatrow_t * row; + int draw_y = y; + + if (hires) + draw_flags |= V_ALLOWLOWERCASE; + + for (row = rows; row->lores_label; ++row) + { + const char *label; + INT32 value; + char *final_str; + + if (!PS_IsRowVisible(row)) + continue; + + label = hires ? row->hires_label : row->lores_label; + value = PS_GetMetricScreenValue(row->metric, !!(row->flags & PS_TIME)); + final_str = va("%s %d", label, value); + + if (hires) + { + V_DrawSmallString(x, draw_y, draw_flags, final_str); + draw_y += 5; + } + else + { + V_DrawThinString(x, draw_y, draw_flags, final_str); + draw_y += 8; + } + } + + return draw_y; +} + +static void PS_UpdateMetricHistory(ps_metric_t *metric, boolean time_metric, boolean frame_metric, boolean set_user) +{ + int index = frame_metric ? ps_frame_index : ps_tick_index; + + if (!metric->history) + { + // allocate history table + int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); + void** memory_user = set_user ? &metric->history : NULL; + + metric->history = Z_Calloc(value_size * cv_ps_samplesize.value, PU_PERFSTATS, + memory_user); + + // reset "samples left" counter since this history table needs to be filled + if (frame_metric) + ps_frame_samples_left = cv_ps_samplesize.value; + else + ps_tick_samples_left = cv_ps_samplesize.value; + } + + if (time_metric) + { + precise_t *history = (precise_t*)metric->history; + history[index] = metric->value.p; + } + else + { + INT32 *history = (INT32*)metric->history; + history[index] = metric->value.i; + } +} + +static void PS_UpdateRowHistories(perfstatrow_t *rows, boolean frame_metric) +{ + perfstatrow_t *row; + for (row = rows; row->lores_label; row++) + { + if (PS_IsRowValid(row)) + PS_UpdateMetricHistory(row->metric, !!(row->flags & PS_TIME), frame_metric, true); + } +} + +// Update all metrics that are calculated on every frame. +static void PS_UpdateFrameStats(void) +{ + // update frame time + precise_t currenttime = I_GetPreciseTime(); + ps_frametime.value.p = currenttime - ps_prevframetime; + ps_prevframetime = currenttime; + + // update 3d rendering stats + if (PS_IsLevelActive()) + { + // Remember to update this calculation when adding more 3d rendering stats! + ps_otherrendertime.value.p = ps_rendercalltime.value.p - ps_bsptime.value.p; + +#ifdef HWRENDER + if (rendermode == render_opengl) + { + ps_otherrendertime.value.p -= + ps_skyboxtime.value.p + + ps_hw_nodesorttime.value.p + + ps_hw_nodedrawtime.value.p + + ps_hw_spritesorttime.value.p + + ps_hw_spritedrawtime.value.p; + + if (cv_grbatching.value) + { + ps_otherrendertime.value.p -= + ps_hw_batchsorttime.value.p + + ps_hw_batchdrawtime.value.p; + } + } + else +#endif + { + ps_otherrendertime.value.p -= + ps_skyboxtime.value.p + + ps_sw_spritecliptime.value.p + + ps_sw_portaltime.value.p + + ps_sw_planetime.value.p + + ps_sw_maskedtime.value.p; + } + } + + if (cv_ps_samplesize.value > 1) + { + PS_UpdateRowHistories(rendertime_rows, true); + if (PS_IsLevelActive()) + PS_UpdateRowHistories(commoncounter_rows, true); + + /*if (R_UsingFrameInterpolation()) + PS_UpdateRowHistories(interpolation_rows, true);*/ + +#ifdef HWRENDER + if (rendermode == render_opengl && cv_grbatching.value) + { + PS_UpdateRowHistories(batchcount_rows, true); + PS_UpdateRowHistories(batchcalls_rows, true); + } +#endif + + ps_frame_index++; + if (ps_frame_index >= cv_ps_samplesize.value) + ps_frame_index = 0; + if (ps_frame_samples_left) + ps_frame_samples_left--; + } +} + +// Update thinker counters by iterating the thinker lists. +static void PS_CountThinkers(void) +{ + thinker_t *thinker; + + ps_thinkercount.value.i = 0; + ps_mobjcount.value.i = 0; + ps_regularcount.value.i = 0; + ps_scenerycount.value.i = 0; + ps_nothinkcount.value.i = 0; + ps_otherthcount.value.i = 0; + ps_precipcount.value.i = 0; + ps_removecount.value.i = 0; + for (thinker = thinkercap.next; thinker != &thinkercap; thinker = thinker->next) + { + ps_thinkercount.value.i++; + if (thinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + ps_removecount.value.i++; + else if (thinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj_t *mobj = (mobj_t*)thinker; + ps_mobjcount.value.i++; + if (mobj->flags & MF_NOTHINK) + ps_nothinkcount.value.i++; + else if (mobj->flags & MF_SCENERY) + ps_scenerycount.value.i++; + else + ps_regularcount.value.i++; + } + else if (thinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) + ps_precipcount.value.i++; + else + ps_otherthcount.value.i++; + } + /*for (i = 0; i < NUM_THINKERLISTS; i++) + { + for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) + { + ps_thinkercount.value.i++; + if (thinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + ps_removecount.value.i++; + else if (i == THINK_POLYOBJ) + ps_polythcount.value.i++; + else if (i == THINK_MAIN) + ps_mainthcount.value.i++; + else if (i == THINK_MOBJ) + { + if (thinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj_t *mobj = (mobj_t*)thinker; + ps_mobjcount.value.i++; + if (mobj->flags & MF_NOTHINK) + ps_nothinkcount.value.i++; + else if (mobj->flags & MF_SCENERY) + ps_scenerycount.value.i++; + else + ps_regularcount.value.i++; + } + } + else if (i == THINK_DYNSLOPE) + ps_dynslopethcount.value.i++; + else if (i == THINK_PRECIP) + ps_precipcount.value.i++; + } + }*/ +} + +// Update all metrics that are calculated on every tick. +void PS_UpdateTickStats(void) +{ + if (cv_perfstats.value == 1 && cv_ps_samplesize.value > 1) + { + PS_UpdateRowHistories(gamelogicbrief_row, false); + } + if (cv_perfstats.value == 2) + { + if (PS_IsLevelActive()) + { + ps_otherlogictime.value.p = + ps_tictime.value.p - + ps_playerthink_time.value.p - + ps_thinkertime.value.p - + ps_lua_thinkframe_time.value.p; + + PS_CountThinkers(); + } + + if (cv_ps_samplesize.value > 1) + { + PS_UpdateRowHistories(gamelogic_rows, false); + PS_UpdateRowHistories(thinkercount_rows, false); + PS_UpdateRowHistories(misc_calls_rows, false); + } + } + if (cv_perfstats.value == 3 && cv_ps_samplesize.value > 1 && PS_IsLevelActive()) + { + int i; + for (i = 0; i < thinkframe_hooks_length; i++) + { + PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false, false); + } + } + if (cv_perfstats.value && cv_ps_samplesize.value > 1) + { + ps_tick_index++; + if (ps_tick_index >= cv_ps_samplesize.value) + ps_tick_index = 0; + if (ps_tick_samples_left) + ps_tick_samples_left--; + } +} + +static void PS_DrawDescriptorHeader(void) +{ + if (cv_ps_samplesize.value > 1) + { + const char* descriptor_names[] = { + "average", + "standard deviation", + "minimum", + "maximum" + }; + const boolean hires = PS_HighResolution(); + char* str; + INT32 flags = V_MONOSPACE | V_ALLOWLOWERCASE; + int samples_left = max(ps_frame_samples_left, ps_tick_samples_left); + int x, y; + + if (cv_perfstats.value == 3) + { + x = 2; + y = 0; + } + else + { + x = 20; + y = hires ? 5 : 2; + } + + if (samples_left) + { + str = va("Samples needed for correct results: %d", samples_left); + flags |= V_REDMAP; + } + else + { + str = va("Showing the %s of %d samples.", + descriptor_names[cv_ps_descriptor.value - 1], cv_ps_samplesize.value); + flags |= V_GREENMAP; + } + + if (hires) + V_DrawSmallString(x, y, flags, str); + else + V_DrawThinString(x, y, flags, str); + } +} + +static void PS_DrawRenderStats(void) +{ + const boolean hires = PS_HighResolution(); + const int half_row = hires ? 5 : 4; + int x, y = 10; //, cy = 10; + + PS_DrawDescriptorHeader(); + + y = PS_DrawPerfRows(20, 10, V_YELLOWMAP, rendertime_rows); + + PS_DrawPerfRows(20, y + half_row, V_GRAYMAP, gamelogicbrief_row); + + if (PS_IsLevelActive()) + { + x = hires ? 115 : 90; + /*cy = */PS_DrawPerfRows(x, 10, V_BLUEMAP, commoncounter_rows);// + half_row; + +#ifdef HWRENDER + if (rendermode == render_opengl && cv_grbatching.value) + { + x = hires ? 200 : 155; + y = PS_DrawPerfRows(x, 10, V_PURPLEMAP, batchcount_rows); + + x = hires ? 200 : 220; + y = hires ? y + half_row : 10; + PS_DrawPerfRows(x, y, V_PURPLEMAP, batchcalls_rows); + } +#endif + } + + /*if (R_UsingFrameInterpolation()) + { + x = hires ? 115 : 90; + PS_DrawPerfRows(x, cy, V_ROSYMAP, interpolation_rows); + }*/ +} + +static void PS_DrawGameLogicStats(void) +{ + const boolean hires = PS_HighResolution(); + int x, y; + + PS_DrawDescriptorHeader(); + + PS_DrawPerfRows(20, 10, V_YELLOWMAP, gamelogic_rows); + + x = hires ? 115 : 90; + PS_DrawPerfRows(x, 10, V_BLUEMAP, thinkercount_rows); + + if (hires) + V_DrawSmallString(212, 10, V_MONOSPACE | V_ALLOWLOWERCASE | V_PURPLEMAP, "Calls:"); + + x = hires ? 216 : 170; + y = hires ? 15 : 10; + PS_DrawPerfRows(x, y, V_PURPLEMAP, misc_calls_rows); +} + +static void PS_DrawThinkFrameStats(void) +{ + char s[100]; + int i; + // text writing position + int x = 2; + int y = 4; + UINT32 text_color; + char tempbuffer[LUA_IDSIZE]; + char last_mod_name[LUA_IDSIZE]; + last_mod_name[0] = '\0'; + + PS_DrawDescriptorHeader(); + + for (i = 0; i < thinkframe_hooks_length; i++) + { + +#define NEXT_ROW() \ +y += 4; \ +if (y > 192) \ +{ \ + y = 4; \ + x += 106; \ + if (x > 214) \ + break; \ +} + + char* str = thinkframe_hooks[i].short_src; + char* tempstr = tempbuffer; + int len = (int)strlen(str); + char* str_ptr; + if (strcmp(".lua", str + len - 4) == 0) + { + str[len-4] = '\0'; // remove .lua at end + len -= 4; + } + // we locate the wad/pk3 name in the string and compare it to + // what we found on the previous iteration. + // if the name has changed, print it out on the screen + strcpy(tempstr, str); + str_ptr = strrchr(tempstr, '|'); + if (str_ptr) + { + *str_ptr = '\0'; + str = str_ptr + 1; // this is the name of the hook without the mod file name + str_ptr = strrchr(tempstr, PATHSEP[0]); + if (str_ptr) + tempstr = str_ptr + 1; + // tempstr should now point to the mod name, (wad/pk3) possibly truncated + if (strcmp(tempstr, last_mod_name) != 0) + { + strcpy(last_mod_name, tempstr); + len = (int)strlen(tempstr); + if (len > 25) + tempstr += len - 25; + snprintf(s, sizeof s - 1, "%s", tempstr); + V_DrawSmallString(x, y, V_MONOSPACE | V_ALLOWLOWERCASE | V_GRAYMAP, s); + NEXT_ROW() + } + text_color = V_YELLOWMAP; + } + else + { + // probably a standalone lua file + // cut off the folder if it's there + str_ptr = strrchr(tempstr, PATHSEP[0]); + if (str_ptr) + str = str_ptr + 1; + text_color = 0; // white + } + len = (int)strlen(str); + if (len > 20) + str += len - 20; + snprintf(s, sizeof s - 1, "%20s: %d", str, + PS_GetMetricScreenValue(&thinkframe_hooks[i].time_taken, true)); + V_DrawSmallString(x, y, V_MONOSPACE | V_ALLOWLOWERCASE | text_color, s); + NEXT_ROW() + +#undef NEXT_ROW + + } +} + +void M_DrawPerfStats(void) +{ + if (cv_perfstats.value == 1) // rendering + { + PS_UpdateFrameStats(); + PS_DrawRenderStats(); + } + else if (cv_perfstats.value == 2) // logic + { + // PS_UpdateTickStats is called in TryRunTics, since otherwise it would miss + // tics when frame skips happen + PS_DrawGameLogicStats(); + } + else if (cv_perfstats.value == 3) // lua thinkframe + { + if (!PS_IsLevelActive()) + return; + if (!PS_HighResolution()) + { + // Low resolutions can't really use V_DrawSmallString that is used by thinkframe stats. + // A low-res version using V_DrawThinString could be implemented, + // but it would have much less space for information. + V_DrawThinString(80, 92, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "Perfstats 3 is not available"); + V_DrawThinString(80, 100, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "for resolutions below 640x400."); + } + else + { + PS_DrawThinkFrameStats(); + } + } +} + +// remove and unallocate history from all metrics +static void PS_ClearHistory(void) +{ + int i; + + Z_FreeTags(PU_PERFSTATS, PU_PERFSTATS); + // thinkframe hook metric history pointers need to be cleared manually + for (i = 0; i < thinkframe_hooks_length; i++) + { + thinkframe_hooks[i].time_taken.history = NULL; + } + + ps_frame_index = ps_tick_index = 0; + // PS_UpdateMetricHistory will set these correctly when it runs + ps_frame_samples_left = ps_tick_samples_left = 0; +} + +void PS_PerfStats_OnChange(void) +{ + if (cv_perfstats.value && cv_ps_samplesize.value > 1) + PS_ClearHistory(); +} + +void PS_SampleSize_OnChange(void) +{ + if (cv_ps_samplesize.value > 1) + PS_ClearHistory(); +} diff --git a/src/m_perfstats.h b/src/m_perfstats.h new file mode 100644 index 000000000..6934f85f9 --- /dev/null +++ b/src/m_perfstats.h @@ -0,0 +1,61 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020-2023 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file m_perfstats.h +/// \brief Performance measurement tools. + +#ifndef __M_PERFSTATS_H__ +#define __M_PERFSTATS_H__ + +#include "doomdef.h" +#include "lua_script.h" +#include "p_local.h" +#include "i_system.h" // I_GetPreciseTime + +typedef struct +{ + union { + precise_t p; + INT32 i; + } value; + void *history; +} ps_metric_t; + +typedef struct +{ + ps_metric_t time_taken; + char short_src[LUA_IDSIZE]; +} ps_hookinfo_t; + +#define PS_START_TIMING(metric) metric.value.p = I_GetPreciseTime() +#define PS_STOP_TIMING(metric) metric.value.p = I_GetPreciseTime() - metric.value.p + +extern ps_metric_t ps_tictime; + +extern ps_metric_t ps_playerthink_time; +extern ps_metric_t ps_thinkertime; + +extern ps_metric_t ps_thlist_times[]; + +extern ps_metric_t ps_checkposition_calls; + +extern ps_metric_t ps_lua_thinkframe_time; +extern ps_metric_t ps_lua_mobjhooks; + +extern ps_metric_t ps_otherlogictime; + +void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src); + +void PS_UpdateTickStats(void); + +void M_DrawPerfStats(void); + +void PS_PerfStats_OnChange(void); +void PS_SampleSize_OnChange(void); + +#endif diff --git a/src/p_map.c b/src/p_map.c index c7647da6e..abca82eb0 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -38,6 +38,8 @@ #include "lua_hook.h" +#include "m_perfstats.h" // ps_checkposition_calls + fixed_t tmbbox[4]; mobj_t *tmthing; static INT32 tmflags; @@ -2026,6 +2028,8 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) INT32 xl, xh, yl, yh, bx, by; subsector_t *newsubsec; boolean blockval = true; + + ps_checkposition_calls.value.i++; I_Assert(thing != NULL); #ifdef PARANOIA diff --git a/src/p_tick.c b/src/p_tick.c index 4075fba47..38900db9f 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -27,6 +27,7 @@ #include "r_main.h" #include "r_fps.h" #include "i_video.h" // rendermode +#include "m_perfstats.h" // Object place #include "m_cheat.h" @@ -656,14 +657,19 @@ void P_Ticker(boolean run) } #endif } + + ps_lua_mobjhooks.value.i = 0; + ps_checkposition_calls.value.i = 0; #ifdef HAVE_BLUA LUAh_PreThinkFrame(); #endif + PS_START_TIMING(ps_playerthink_time); for (i = 0; i < MAXPLAYERS; i++) if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo)) P_PlayerThink(&players[i]); + PS_STOP_TIMING(ps_playerthink_time); } // Keep track of how long they've been playing! @@ -678,7 +684,9 @@ void P_Ticker(boolean run) if (run) { + PS_START_TIMING(ps_thinkertime); P_RunThinkers(); + PS_STOP_TIMING(ps_thinkertime); // Run any "after all the other thinkers" stuff for (i = 0; i < MAXPLAYERS; i++) @@ -686,7 +694,9 @@ void P_Ticker(boolean run) P_PlayerAfterThink(&players[i]); #ifdef HAVE_BLUA + PS_START_TIMING(ps_lua_thinkframe_time); LUAh_ThinkFrame(); + PS_STOP_TIMING(ps_lua_thinkframe_time); #endif } diff --git a/src/r_bsp.c b/src/r_bsp.c index 9a906a5f1..2de30d2ab 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -410,8 +410,8 @@ static void R_AddLine(seg_t *line) return; // big room fix - angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); curline = line; // Clip to view edges. @@ -613,8 +613,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) check = checkcoord[boxpos]; // big room fix - angle1 = R_PointToAngleEx(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngleEx(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; if ((signed)angle1 < (signed)angle2) { @@ -800,6 +800,9 @@ static void R_AddPolyObjects(subsector_t *sub) ++numpolys; po = (polyobj_t *)(po->link.next); } + + // for render stats + ps_numpolyobjects.value.i += numpolys; // sort polyobjects R_SortPolyObjects(sub); @@ -1290,6 +1293,9 @@ void R_RenderBSPNode(INT32 bspnum) { node_t *bsp; INT32 side; + + ps_numbspcalls.value.i++; + while (!(bspnum & NF_SUBSECTOR)) // Found a subsector? { bsp = &nodes[bspnum]; diff --git a/src/r_main.c b/src/r_main.c index 9a73b14a7..9ed8c4107 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -129,6 +129,26 @@ lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; size_t num_extra_colormaps; extracolormap_t extra_colormaps[MAXCOLORMAPS]; +// Performance stats +precise_t ps_prevframetime = 0; +ps_metric_t ps_rendercalltime = {0}; +ps_metric_t ps_otherrendertime = {0}; +ps_metric_t ps_uitime = {0}; +ps_metric_t ps_swaptime = {0}; + +ps_metric_t ps_skyboxtime = {0}; +ps_metric_t ps_bsptime = {0}; + +ps_metric_t ps_sw_spritecliptime = {0}; +ps_metric_t ps_sw_portaltime = {0}; +ps_metric_t ps_sw_planetime = {0}; +ps_metric_t ps_sw_maskedtime = {0}; + +ps_metric_t ps_numbspcalls = {0}; +ps_metric_t ps_numsprites = {0}; +ps_metric_t ps_numdrawnodes = {0}; +ps_metric_t ps_numpolyobjects = {0}; + static CV_PossibleValue_t drawdist_cons_t[] = { /*{256, "256"},*/ {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, @@ -176,6 +196,7 @@ consvar_t cv_flipcam4 = {"flipcam4", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, consvar_t cv_shadow = {"shadow", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shadowoffs = {"offsetshadows", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skybox = {"skybox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ffloorclip = {"ffloorclip", "On", CV_SAVE, CV_OnOff, NULL}; consvar_t cv_soniccd = {"soniccd", "Off", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allowmlook = {"allowmlook", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showhud = {"showhud", "Yes", CV_CALL, CV_YesNo, R_SetViewSize, 0, NULL, NULL, 0, 0, NULL}; @@ -380,6 +401,22 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y) 0; } +angle_t R_PointToAngle64(INT64 x, INT64 y) +{ + return (y -= viewy, (x -= viewx) || y) ? + x >= 0 ? + y >= 0 ? + (x > y) ? tantoangle[SlopeDivEx(y,x)] : // octant 0 + ANGLE_90-tantoangle[SlopeDivEx(x,y)] : // octant 1 + x > (y = -y) ? 0-tantoangle[SlopeDivEx(y,x)] : // octant 8 + ANGLE_270+tantoangle[SlopeDivEx(x,y)] : // octant 7 + y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDivEx(y,x)] : // octant 3 + ANGLE_90 + tantoangle[SlopeDivEx(x,y)] : // octant 2 + (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDivEx(y,x)] : // octant 4 + ANGLE_270-tantoangle[SlopeDivEx(x,y)] : // octant 5 + 0; +} + angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) { return (y -= pviewy, (x -= pviewx) || y) ? @@ -980,7 +1017,7 @@ void R_ExecuteSetViewSize(void) j = viewheight*16; for (i = 0; i < j; i++) { - dy = ((i - viewheight*8)<frontscale); Z_Free(portal); } + PS_STOP_TIMING(ps_sw_portaltime); // END PORTAL RENDERING + PS_START_TIMING(ps_sw_planetime); R_DrawPlanes(); + PS_STOP_TIMING(ps_sw_planetime); #ifdef FLOORSPLATS R_DrawVisibleFloorSplats(); #endif // draw mid texture and sprite // And now 3D floors/sides! + PS_START_TIMING(ps_sw_maskedtime); R_DrawMasked(); + PS_STOP_TIMING(ps_sw_maskedtime); // Check for new console commands. NetUpdate(); @@ -1827,6 +1878,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_shadow); CV_RegisterVar(&cv_shadowoffs); CV_RegisterVar(&cv_skybox); + CV_RegisterVar(&cv_ffloorclip); CV_RegisterVar(&cv_cam_dist); CV_RegisterVar(&cv_cam_still); diff --git a/src/r_main.h b/src/r_main.h index 3c81c6876..70adf1bb5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -16,6 +16,7 @@ #include "d_player.h" #include "r_data.h" +#include "m_perfstats.h" // // POV related. @@ -67,6 +68,7 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); +angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1); fixed_t R_PointToDist(fixed_t x, fixed_t y); @@ -78,6 +80,27 @@ 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); +// Performance stats + +extern precise_t ps_prevframetime;// time when previous frame was rendered +extern ps_metric_t ps_rendercalltime; +extern ps_metric_t ps_otherrendertime; +extern ps_metric_t ps_uitime; +extern ps_metric_t ps_swaptime; + +extern ps_metric_t ps_skyboxtime; +extern ps_metric_t ps_bsptime; + +extern ps_metric_t ps_sw_spritecliptime; +extern ps_metric_t ps_sw_portaltime; +extern ps_metric_t ps_sw_planetime; +extern ps_metric_t ps_sw_maskedtime; + +extern ps_metric_t ps_numbspcalls; +extern ps_metric_t ps_numsprites; +extern ps_metric_t ps_numdrawnodes; +extern ps_metric_t ps_numpolyobjects; + // // REFRESH - the actual rendering functions. // @@ -87,6 +110,7 @@ extern consvar_t cv_homremoval; extern consvar_t cv_chasecam, cv_chasecam2, cv_chasecam3, cv_chasecam4; extern consvar_t cv_flipcam, cv_flipcam2, cv_flipcam3, cv_flipcam4; extern consvar_t cv_shadow, cv_shadowoffs; +extern consvar_t cv_ffloorclip; extern consvar_t cv_translucency; extern consvar_t /*cv_precipdensity,*/ cv_drawdist, /*cv_drawdist_nights,*/ cv_drawdist_precip; extern consvar_t cv_fov; diff --git a/src/r_plane.c b/src/r_plane.c index d3d6a11ee..096b5f0a9 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -452,9 +452,11 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, { if (polyobj->angle != 0) { - angle_t fineshift = polyobj->angle >> ANGLETOFINESHIFT; - xoff -= FixedMul(FINECOSINE(fineshift), polyobj->centerPt.x)+FixedMul(FINESINE(fineshift), polyobj->centerPt.y); - yoff -= FixedMul(FINESINE(fineshift), polyobj->centerPt.x)-FixedMul(FINECOSINE(fineshift), polyobj->centerPt.y); + float ang = ANG2RAD(polyobj->angle); + float x = FixedToFloat(polyobj->centerPt.x); + float y = FixedToFloat(polyobj->centerPt.y); + xoff -= FloatToFixed(x * cos(ang) + y * sin(ang)); + yoff -= FloatToFixed(x * sin(ang) - y * cos(ang)); } else { diff --git a/src/r_plane.h b/src/r_plane.h index 7a069d401..a109aef15 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -18,6 +18,11 @@ #include "r_data.h" #include "p_polyobj.h" +#define VISPLANEHASHBITS 9 +#define VISPLANEHASHMASK ((1<polyobj) + return (pfloor->polyobj->translucency > 0); + + // Polyobjects have no ffloors, and they're handled in the conditional above. + if (pfloor->ffloor != NULL) + return (pfloor->ffloor->flags & FF_TRANSLUCENT); + + return false; +} + // // R_RenderThickSideRange // Renders all the thick sides in the given range. @@ -1207,6 +1229,14 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) #undef CLAMPMIN } +// R_FFloorCanClip +// +// Returns true if a fake floor can clip a column away. +static boolean R_FFloorCanClip(visffloor_t *pfloor) +{ + return (cv_ffloorclip.value && !R_IsFFloorTranslucent(pfloor) && !pfloor->polyobj); +} + // // R_RenderSegLoop // Draws zero, one, or two textures (and possibly a masked @@ -1288,9 +1318,14 @@ static void R_RenderSegLoop (void) floorplane->bottom[rw_x] = (INT16)bottom; } } + + rw_floormarked = false; + rw_ceilingmarked = false; if (numffloors) { + INT16 fftop, ffbottom; + firstseg->frontscale[rw_x] = frontscale[rw_x]; top = ceilingclip[rw_x]+1; // PRBoom bottom = floorclip[rw_x]-1; // PRBoom @@ -1326,8 +1361,30 @@ static void R_RenderSegLoop (void) if (top_w <= bottom_w) { - ffloor[i].plane->top[rw_x] = (INT16)top_w; - ffloor[i].plane->bottom[rw_x] = (INT16)bottom_w; + fftop = (INT16)top_w; + ffbottom = (INT16)bottom_w; + + ffloor[i].plane->top[rw_x] = fftop; + ffloor[i].plane->bottom[rw_x] = ffbottom; + + // Lactozilla: Cull part of the column by the 3D floor if it can't be seen + // "bottom" is the top pixel of the floor column + if (ffbottom >= bottom-1 && R_FFloorCanClip(&ffloor[i])) + { + rw_floormarked = true; + floorclip[rw_x] = fftop; + if (yh > fftop) + yh = fftop; + + if (markfloor && floorplane) + floorplane->top[rw_x] = bottom; + + if (rw_silhouette) + { + (*rw_silhouette) |= SIL_BOTTOM; + (*rw_bsilheight) = INT32_MAX; + } + } } } else if (ffloor[i].height > viewz) @@ -1348,8 +1405,30 @@ static void R_RenderSegLoop (void) if (top_w <= bottom_w) { - ffloor[i].plane->top[rw_x] = (INT16)top_w; - ffloor[i].plane->bottom[rw_x] = (INT16)bottom_w; + fftop = (INT16)top_w; + ffbottom = (INT16)bottom_w; + + ffloor[i].plane->top[rw_x] = fftop; + ffloor[i].plane->bottom[rw_x] = ffbottom; + + // Lactozilla: Cull part of the column by the 3D floor if it can't be seen + // "top" is the height of the ceiling column + if (fftop <= top+1 && R_FFloorCanClip(&ffloor[i])) + { + rw_ceilingmarked = true; + ceilingclip[rw_x] = ffbottom; + if (yl < ffbottom) + yl = ffbottom; + + if (markceiling && ceilingplane) + ceilingplane->bottom[rw_x] = top; + + if (rw_silhouette) + { + (*rw_silhouette) |= SIL_TOP; + (*rw_tsilheight) = INT32_MIN; + } + } } } } @@ -1456,20 +1535,25 @@ static void R_RenderSegLoop (void) // dont draw anything more for this column, since // a midtexture blocks the view - ceilingclip[rw_x] = (INT16)viewheight; - floorclip[rw_x] = -1; + if (!rw_ceilingmarked) + ceilingclip[rw_x] = (INT16)viewheight; + if (!rw_floormarked) + floorclip[rw_x] = -1; } else { // note: don't use min/max macros, since casting from INT32 to INT16 is involved here - if (markceiling) + if (markceiling && (!rw_ceilingmarked)) ceilingclip[rw_x] = (yl >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; - if (markfloor) + if (markfloor && (!rw_floormarked)) floorclip[rw_x] = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; } } else { + INT16 topclip = (yl >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; + INT16 bottomclip = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; + // two sided line if (toptexture) { @@ -1483,7 +1567,10 @@ static void R_RenderSegLoop (void) if (mid >= yl) // back ceiling lower than front ceiling ? { if (yl >= viewheight) // entirely off bottom of screen - ceilingclip[rw_x] = (INT16)viewheight; + { + if (!rw_ceilingmarked) + ceilingclip[rw_x] = (INT16)viewheight; + } else if (mid >= 0) // safe to draw top texture { dc_yl = yl; @@ -1494,14 +1581,14 @@ static void R_RenderSegLoop (void) colfunc(); ceilingclip[rw_x] = (INT16)mid; } - else // entirely off top of screen + else if (!rw_ceilingmarked) // entirely off top of screen ceilingclip[rw_x] = -1; } - else - ceilingclip[rw_x] = (yl >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; + else if (!rw_ceilingmarked) + ceilingclip[rw_x] = topclip; } - else if (markceiling) // no top wall - ceilingclip[rw_x] = (yl >= 0) ? ((yl > viewheight) ? (INT16)viewheight : (INT16)((INT16)yl - 1)) : -1; + else if (markceiling && (!rw_ceilingmarked)) // no top wall + ceilingclip[rw_x] = topclip; if (bottomtexture) { @@ -1516,7 +1603,10 @@ static void R_RenderSegLoop (void) if (mid <= yh) // back floor higher than front floor ? { if (yh < 0) // entirely off top of screen - floorclip[rw_x] = -1; + { + if (!rw_floormarked) + floorclip[rw_x] = -1; + } else if (mid < viewheight) // safe to draw bottom texture { dc_yl = mid; @@ -1528,14 +1618,14 @@ static void R_RenderSegLoop (void) colfunc(); floorclip[rw_x] = (INT16)mid; } - else // entirely off bottom of screen + else if (!rw_floormarked) // entirely off bottom of screen floorclip[rw_x] = (INT16)viewheight; } - else - floorclip[rw_x] = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; + else if (!rw_floormarked) + floorclip[rw_x] = bottomclip; } - else if (markfloor) // no bottom wall - floorclip[rw_x] = (yh < viewheight) ? ((yh < -1) ? -1 : (INT16)((INT16)yh + 1)) : (INT16)viewheight; + else if (markfloor && (!rw_floormarked)) // no bottom wall + floorclip[rw_x] = bottomclip; } if (maskedtexture || numthicksides) @@ -1562,10 +1652,17 @@ static void R_RenderSegLoop (void) } for (i = 0; i < numffloors; i++) + { + if (curline->polyseg && (ffloor[i].polyobj != curline->polyseg)) + continue; ffloor[i].f_frac += ffloor[i].f_step; + } for (i = 0; i < numbackffloors; i++) { + if (curline->polyseg && (ffloor[i].polyobj != curline->polyseg)) + continue; + ffloor[i].f_clip[rw_x] = ffloor[i].c_clip[rw_x] = (INT16)((ffloor[i].b_frac >> HEIGHTBITS) & 0xFFFF); ffloor[i].b_frac += ffloor[i].b_step; } @@ -1730,23 +1827,26 @@ void R_StoreWallRange(INT32 start, INT32 stop) // left temp = xtoviewangle[start]+viewangle; +#define FIXED_TO_DOUBLE(x) (((double)(x)) / ((double)FRACUNIT)) +#define DOUBLE_TO_FIXED(x) (fixed_t)((x) * ((double)FRACUNIT)) + { // Both lines can be written in slope-intercept form, so figure out line intersection - float a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector... - ///TODO: convert to FPU + double a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector... + ///TODO: convert to fixed point - a1 = FIXED_TO_FLOAT(curline->v2->y-curline->v1->y); - b1 = FIXED_TO_FLOAT(curline->v1->x-curline->v2->x); - c1 = a1*FIXED_TO_FLOAT(curline->v1->x) + b1*FIXED_TO_FLOAT(curline->v1->y); + a1 = FIXED_TO_DOUBLE(curline->v2->y-curline->v1->y); + b1 = FIXED_TO_DOUBLE(curline->v1->x-curline->v2->x); + c1 = a1*FIXED_TO_DOUBLE(curline->v1->x) + b1*FIXED_TO_DOUBLE(curline->v1->y); - a2 = -FIXED_TO_FLOAT(FINESINE(temp>>ANGLETOFINESHIFT)); - b2 = FIXED_TO_FLOAT(FINECOSINE(temp>>ANGLETOFINESHIFT)); - c2 = a2*FIXED_TO_FLOAT(viewx) + b2*FIXED_TO_FLOAT(viewy); + a2 = -FIXED_TO_DOUBLE(FINESINE(temp>>ANGLETOFINESHIFT)); + b2 = FIXED_TO_DOUBLE(FINECOSINE(temp>>ANGLETOFINESHIFT)); + c2 = a2*FIXED_TO_DOUBLE(viewx) + b2*FIXED_TO_DOUBLE(viewy); det = a1*b2 - a2*b1; - ds_p->leftpos.x = segleft.x = FLOAT_TO_FIXED((b2*c1 - b1*c2)/det); - ds_p->leftpos.y = segleft.y = FLOAT_TO_FIXED((a1*c2 - a2*c1)/det); + ds_p->leftpos.x = segleft.x = DOUBLE_TO_FIXED((b2*c1 - b1*c2)/det); + ds_p->leftpos.y = segleft.y = DOUBLE_TO_FIXED((a1*c2 - a2*c1)/det); } // right @@ -1754,22 +1854,26 @@ void R_StoreWallRange(INT32 start, INT32 stop) { // Both lines can be written in slope-intercept form, so figure out line intersection - float a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector... - ///TODO: convert to FPU + double a1, b1, c1, a2, b2, c2, det; // 1 is the seg, 2 is the view angle vector... + ///TODO: convert to fixed point - a1 = FIXED_TO_FLOAT(curline->v2->y-curline->v1->y); - b1 = FIXED_TO_FLOAT(curline->v1->x-curline->v2->x); - c1 = a1*FIXED_TO_FLOAT(curline->v1->x) + b1*FIXED_TO_FLOAT(curline->v1->y); + a1 = FIXED_TO_DOUBLE(curline->v2->y-curline->v1->y); + b1 = FIXED_TO_DOUBLE(curline->v1->x-curline->v2->x); + c1 = a1*FIXED_TO_DOUBLE(curline->v1->x) + b1*FIXED_TO_DOUBLE(curline->v1->y); - a2 = -FIXED_TO_FLOAT(FINESINE(temp>>ANGLETOFINESHIFT)); - b2 = FIXED_TO_FLOAT(FINECOSINE(temp>>ANGLETOFINESHIFT)); - c2 = a2*FIXED_TO_FLOAT(viewx) + b2*FIXED_TO_FLOAT(viewy); + a2 = -FIXED_TO_DOUBLE(FINESINE(temp>>ANGLETOFINESHIFT)); + b2 = FIXED_TO_DOUBLE(FINECOSINE(temp>>ANGLETOFINESHIFT)); + c2 = a2*FIXED_TO_DOUBLE(viewx) + b2*FIXED_TO_DOUBLE(viewy); det = a1*b2 - a2*b1; - ds_p->rightpos.x = segright.x = FLOAT_TO_FIXED((b2*c1 - b1*c2)/det); - ds_p->rightpos.y = segright.y = FLOAT_TO_FIXED((a1*c2 - a2*c1)/det); + ds_p->rightpos.x = segright.x = DOUBLE_TO_FIXED((b2*c1 - b1*c2)/det); + ds_p->rightpos.y = segright.y = DOUBLE_TO_FIXED((a1*c2 - a2*c1)/det); } + +#undef FIXED_TO_DOUBLE +#undef DOUBLE_TO_FIXED + } if (frontsector->c_slope) { @@ -2792,6 +2896,10 @@ void R_StoreWallRange(INT32 start, INT32 stop) R_ExpandPlane(ffloor[i].plane, rw_x, rw_stopx - 1); } } + + rw_silhouette = &(ds_p->silhouette); + rw_tsilheight = &(ds_p->tsilheight); + rw_bsilheight = &(ds_p->bsilheight); #ifdef WALLSPLATS if (linedef->splats && cv_splats.value) diff --git a/src/r_things.c b/src/r_things.c index 19cecc30a..11779ded4 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2233,22 +2233,19 @@ static void R_CreateDrawNodes(void) } else planeobjectz = planecameraz = r2->plane->height; - if (rover->mobjflags & MF_NOCLIPHEIGHT) + // bird: if any part of the sprite peeks in front the plane + if (planecameraz < viewz) { - //Objects with NOCLIPHEIGHT can appear halfway in. - if (planecameraz < viewz && rover->pz+(rover->thingheight/2) >= planeobjectz) - continue; - if (planecameraz > viewz && rover->pzt-(rover->thingheight/2) <= planeobjectz) + if (rover->gzt >= planeobjectz) continue; } - else + else if (planecameraz > viewz) { - if (planecameraz < viewz && rover->pz >= planeobjectz) - continue; - if (planecameraz > viewz && rover->pzt <= planeobjectz) + if (rover->gz <= planeobjectz) continue; } + // SoM: NOTE: Because a visplane's shape and scale is not directly // bound to any single linedef, a simple poll of it's frontscale is // not adequate. We must check the entire frontscale array for any @@ -2397,6 +2394,8 @@ static drawnode_t *R_CreateDrawNode(drawnode_t *link) node->thickseg = NULL; node->ffloor = NULL; node->sprite = NULL; + + ps_numdrawnodes.value.i++; return node; } diff --git a/src/screen.c b/src/screen.c index 1dfabf3fd..1d56893b7 100644 --- a/src/screen.c +++ b/src/screen.c @@ -405,11 +405,10 @@ double averageFPS = 0.0f; #define USE_FPS_SAMPLES #ifdef USE_FPS_SAMPLES -#define FPS_SAMPLE_RATE (0.05) // How often to update FPS samples, in seconds -#define NUM_FPS_SAMPLES (16) // Number of samples to store +#define NUM_FPS_SAMPLES (32) // Number of samples to store static double fps_samples[NUM_FPS_SAMPLES]; -static double updateElapsed = 0.0; +static int fps_index; #endif static boolean fps_init = false; @@ -418,6 +417,7 @@ static precise_t fps_enter = 0; void SCR_CalculateFPS(void) { precise_t fps_finish = 0; + int i; double frameElapsed = 0.0; @@ -432,35 +432,13 @@ void SCR_CalculateFPS(void) fps_enter = fps_finish; #ifdef USE_FPS_SAMPLES - updateElapsed += frameElapsed; + fps_samples[fps_index] = frameElapsed / NUM_FPS_SAMPLES; + fps_index = (fps_index + 1) % NUM_FPS_SAMPLES; - if (updateElapsed >= FPS_SAMPLE_RATE) - { - static int sampleIndex = 0; - int i; - - fps_samples[sampleIndex] = frameElapsed; - - sampleIndex++; - if (sampleIndex >= NUM_FPS_SAMPLES) - sampleIndex = 0; - - averageFPS = 0.0; - for (i = 0; i < NUM_FPS_SAMPLES; i++) - { - averageFPS += fps_samples[i]; - } - - if (averageFPS > 0.0) - { - averageFPS = 1.0 / (averageFPS / NUM_FPS_SAMPLES); - } - } - - while (updateElapsed >= FPS_SAMPLE_RATE) - { - updateElapsed -= FPS_SAMPLE_RATE; - } + averageFPS = 0.0; + for (i = 0; i < NUM_FPS_SAMPLES; i++) + averageFPS += fps_samples[i]; + averageFPS = 1.0 / averageFPS; #else // Direct, unsampled counter. averageFPS = 1.0 / frameElapsed; @@ -476,7 +454,7 @@ void SCR_DisplayTicRate(void) double fps = round(averageFPS); // draw "FPS" - V_DrawFixedPatch(306< (benchmark - 5)) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); @@ -499,11 +477,11 @@ void SCR_DisplayTicRate(void) x -= digits * 4; // draw "/" - V_DrawFixedPatch(x< servermaxping)) // only show 2 (warning) if our ping is at a bad level { INT32 dispy = cv_ticrate.value ? 160 : 181; - HU_drawPing(307, dispy, ping, V_SNAPTORIGHT | V_SNAPTOBOTTOM); + HU_drawPing(307, dispy, ping, V_SNAPTORIGHT | V_SNAPTOBOTTOM|V_HUDTRANS); } } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b52a84e45..3713a0a94 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1774,6 +1774,11 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) #ifdef HWRENDER if (rendermode == render_opengl) flags |= SDL_WINDOW_OPENGL; + + // Without a 24-bit depth buffer many visuals are ruined by z-fighting. + // Some GPU drivers may give us a 16-bit depth buffer since the + // default value for SDL_GL_DEPTH_SIZE is 16. + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); #endif // request stencil buffer. If there are problems on weaker hw the bit count could be reduced diff --git a/src/z_zone.h b/src/z_zone.h index 1424a3782..207f772f3 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -36,6 +36,8 @@ #define PU_STATIC 1 // static entire execution time #define PU_LUA 2 // static entire execution time -- used by lua so it doesn't get caught in loops forever +#define PU_PERFSTATS 3 // static between changes to ps_samplesize cvar + #define PU_SOUND 11 // static while playing #define PU_MUSIC 12 // static while playing #define PU_HUDGFX 13 // static until WAD added