From 5c14dfa5c8ac7d9ed59e5509d0e2cab089417a96 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 10 Feb 2018 21:32:07 +0300 Subject: [PATCH 01/35] Strobe Implementation v2 --- engine/client/cl_scrn.c | 140 ++++++++++++++++++++++-- engine/client/gl_local.h | 35 +++++- engine/client/gl_rmain.c | 219 ++++++++++++++++++++++++++++++------- engine/client/vid_common.c | 12 +- 4 files changed, 354 insertions(+), 52 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 279d80fb1..0dbc42638 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -57,13 +57,22 @@ void SCR_DrawFPS( void ) static int minfps = 9999; static int maxfps = 0; double newtime; - char fpsstring[64]; + char fpsstring[1024]; //char fpsstring[64]; int offset; - int strobeInterval = r_strobe->integer; //cvar: r_strobe - int eFPS; //Effective FPS (strobing effect) + + char diffBar[2][128]; + char barCounter = 0; + int diffP_NB = (SwapPhaseInfo.pNCounter - SwapPhaseInfo.pBCounter); + int diffN_NB = (SwapPhaseInfo.nNCounter - SwapPhaseInfo.nBCounter); + int diffP = 0, diffN = 0; + qboolean pNeg = false, nNeg = false; + int strobeInterval = r_strobe->integer; // cvar: r_strobe + int eFPS; // Effective FPS (strobing effect) + qboolean strobeDebug = !!r_strobe_debug->integer ? true : false; if( cls.state != ca_active ) return; - if( !cl_showfps->integer || cl.background ) return; + if( (!cl_showfps->integer && !strobeDebug) || cl.background ) return; + switch( cls.scrshot_action ) { @@ -73,13 +82,18 @@ void SCR_DrawFPS( void ) break; default: return; } - + newtime = Sys_DoubleTime(); if( newtime >= nexttime ) { framerate = framecount / (newtime - lasttime); lasttime = newtime; nexttime = max( nexttime + 1, lasttime - 1 ); + + + //Msg("Lasttime: %f . Nexttime: %f . %f\n", lasttime, nexttime, newtime - lasttime); + //Sleep(150); + framecount = 0; } @@ -123,21 +137,131 @@ void SCR_DrawFPS( void ) break; case 1: default: + if (strobeInterval == 0) { - Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); + Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); + } + else if(strobeDebug) + { + Q_snprintf(diffBar[0], sizeof(diffBar[0]), "^3["); + Q_snprintf(diffBar[1], sizeof(diffBar[1]), "^3["); + + if (diffP_NB < 0) + { + pNeg = true; + diffP_NB = abs(diffP_NB); + } + + if (diffN_NB < 0) + { + nNeg = true; + diffN_NB = abs(diffN_NB); + } + + if (SwapPhaseInfo.pCounter != 0) + diffP = round(diffP_NB * 100 / SwapPhaseInfo.pCounter); + + if (SwapPhaseInfo.nCounter != 0) + diffN = round(diffN_NB * 100 / SwapPhaseInfo.nCounter); + + for (barCounter = 0; barCounter <= 20; ++barCounter) + { + if (barCounter == 10) + { + Q_strcat(diffBar[0], "O"); + Q_strcat(diffBar[1], "O"); + } + else if (barCounter < 10) + { + if (pNeg) + { + if (100-(barCounter *10) <= diffP) + Q_strcat(diffBar[0], "^4=^3"); + else + Q_strcat(diffBar[0], "^3=^3"); + } + else + { + Q_strcat(diffBar[0], "^3=^3"); + } + + if (nNeg) + { + if (100 - (barCounter * 10) <= diffN) + Q_strcat(diffBar[1], "^4=^3"); + else + Q_strcat(diffBar[1], "^3=^3"); + } + else + { + Q_strcat(diffBar[1], "^3=^3"); + } + } + else if (barCounter > 10) + { + if (pNeg) + { + Q_strcat(diffBar[0], "^3=^3"); + } + else + { + if (((barCounter - 10) * 10) > diffP) + Q_strcat(diffBar[0], "^3=^3"); + else + Q_strcat(diffBar[0], "^4=^3"); + } + + if (nNeg) + { + Q_strcat(diffBar[1], "^3=^3"); + } + else + { + if (((barCounter - 10) * 10) > diffN) + Q_strcat(diffBar[1], "^3=^3"); + else + Q_strcat(diffBar[1], "^4=^3"); + } + } + } + Q_strcat(diffBar[0], va("] - %4d%%", (pNeg ? -diffP : diffP))); + Q_strcat(diffBar[1], va("] - %4d%%", (nNeg ? -diffN : diffN))); + + Q_snprintf(fpsstring, + sizeof(fpsstring), + "%4i FPS\n%3i eFPS\n\n" \ + "Total Frame Count: %u\n\n" \ + "(+) Phase Frame Count: %u\n" \ + " |-> Normal Frame Count: %u\n" \ + " |-> Black Frame Count: %u\n\n" \ + "(-) Phase Frame Count:%u\n" \ + " |-> Normal Frame Count: %u\n" \ + " |-> Black Frame Count: %u\n\n" \ + "timer.triggered %d\n\n" \ + "^5ANALYSIS:\n^3" \ + "Diff (+): %s\n\nDiff (N): %s\nGeometric Mean: %f\nG/A Difference: %f\nBadness: %f" \ + , curfps \ + , eFPS \ + , SwapPhaseInfo.fCounter \ + , SwapPhaseInfo.pCounter, SwapPhaseInfo.pNCounter, SwapPhaseInfo.pBCounter \ + , SwapPhaseInfo.nCounter, SwapPhaseInfo.nNCounter, SwapPhaseInfo.nBCounter \ + , !!(SwapPhaseInfo.frameInfo & p_inverted) \ + , diffBar[0], diffBar[1], sqrt(diffP * diffN) \ + , (diffP + diffN) / 2 - sqrt(diffP * diffN) \ + , BADNESS(diffP,diffN)); } else { Q_snprintf(fpsstring, sizeof(fpsstring), "%4i FPS\n%3i eFPS", curfps, eFPS); } } - MakeRGBA( color, 255, 255, 255, 255 ); } Con_DrawStringLen( fpsstring, &offset, NULL ); - Con_DrawString( scr_width->integer - offset - 5, 4, fpsstring, color ); + //Con_DrawString( scr_width->integer - offset - 5, 4, fpsstring, color ); + Con_DrawString(scr_width->integer - offset - 75, 4, fpsstring, color); // TODO: Fix alignment for non debug setup! } /* diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index 6dc0ae21a..991e33f09 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -349,6 +349,35 @@ void R_LightForPoint( const vec3_t point, color24 *ambientLight, qboolean invLig int R_CountSurfaceDlights( msurface_t *surf ); int R_CountDlights( void ); + +// +void R_Strobe(void); + +typedef enum { + p_positive = 1, // Phase: Positive + p_inverted = 1 << 1, // Phase: Inverted + f_normal = 1 << 2 // Frame: Normal +}fstate_e; // Frame State + +typedef struct SwapPhaseInfo_s { + unsigned int fCounter; // Frame counter + unsigned int pCounter, pNCounter, pBCounter; // Positive phase counters + unsigned int nCounter, nNCounter, nBCounter; // Negative phase counters + fstate_e frameInfo; // Frame info +}SwapPhaseInfo_t; + +extern SwapPhaseInfo_t SwapPhaseInfo; + +// Experimental 'Badness' algorithm +#define BADNESS(diffP, diffN) \ + -log(((abs(diffP-diffN)+sqrt((100-diffP)*(100-diffN)))/(abs(diffP-diffN)+sqrt(diffP*diffN)))) + +extern convar_t *r_strobe; +extern convar_t *r_strobe_swapinterval; +extern convar_t *r_strobe_debug; +// + + // // gl_rmain.c // @@ -363,7 +392,9 @@ qboolean R_InitRenderAPI( void ); void R_SetupFrustum( void ); void R_FindViewLeaf( void ); void R_DrawFog( void ); -void R_Strobe( void ); + + + #define cmatrix3x4 vec4_t *const #define cmatrix4x4 vec4_t *const @@ -700,8 +731,6 @@ extern convar_t *r_lightmap; extern convar_t *r_fastsky; extern convar_t *r_vbo; extern convar_t *r_bump; -extern convar_t *r_strobe; - extern convar_t *mp_decals; extern convar_t *vid_displayfrequency; diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 67f17b034..ced298186 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -35,6 +35,8 @@ ref_instance_t RI, prevRI; mleaf_t *r_viewleaf, *r_oldviewleaf; mleaf_t *r_viewleaf2, *r_oldviewleaf2; +SwapPhaseInfo_t SwapPhaseInfo; + static int R_RankForRenderMode( cl_entity_t *ent ) { switch( ent->curstate.rendermode ) @@ -1326,84 +1328,221 @@ void R_RenderFrame( const ref_params_t *fd, qboolean drawWorld ) GL_BackendEndFrame(); } -inline static void gl_sBlackFrame( void ) +inline static void gl_GenerateBlackFrame( void ) // Generates partial or full black frame { - if (CL_IsInConsole()) // No strobing on the console + if ( CL_IsInConsole() ) // No strobing on the console { - pglEnable(GL_SCISSOR_TEST); - pglScissor(con_rect.x, (-con_rect.y) - (con_rect.h*1.25), con_rect.w, con_rect.h); // Preview strobe setting on static - pglClearColor(0.0f, 0.0f, 0.0f, 1.0f); - pglClear(GL_COLOR_BUFFER_BIT); - pglDisable(GL_SCISSOR_TEST); + if (!vid_fullscreen->integer) // Disable when not fullscreen due to viewport problems + { + R_Set2DMode(false); + return; + } + pglEnable( GL_SCISSOR_TEST); + pglScissor( con_rect.x, (-con_rect.y) - (con_rect.h*1.25), con_rect.w, con_rect.h ); // Preview strobe setting on static + pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + pglClear( GL_COLOR_BUFFER_BIT); + pglDisable( GL_SCISSOR_TEST); } else { - pglClearColor(0.0f, 0.0f, 0.0f, 1.0f); - pglClear(GL_COLOR_BUFFER_BIT); + pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + pglClear( GL_COLOR_BUFFER_BIT ); } } + + /* =============== R_Strobe -TODO: Consider vsync timings and do not render the supposed black frame at all. +TODO: \ + *Make swapping transition seamless by rendering non-opaque frames. + *Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) =============== */ void R_Strobe( void ) { - static int sCounter = 0; - int getInterval = r_strobe->integer; // Check through modified tag first? - int swapInterval = gl_swapInterval->integer; - if ( (getInterval == 0) || ((swapInterval == 0) && (getInterval != 0)) ) + static int getInterval = 0; + static int swapInterval = 0; + static double recentTime = 0; + static double currentTime = 0; + static double delta = 0; + + if (((getInterval != r_strobe->integer) && (getInterval != 0)) || + /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ + SwapPhaseInfo.fCounter > 87091200) // Reset stats after some time + { + SwapPhaseInfo.pCounter = 0; SwapPhaseInfo.pBCounter = 0; SwapPhaseInfo.pNCounter = 0; + SwapPhaseInfo.nCounter = 0; SwapPhaseInfo.nBCounter = 0; SwapPhaseInfo.nNCounter = 0; + SwapPhaseInfo.fCounter = 0; + SwapPhaseInfo.frameInfo &= ~p_inverted; + } + getInterval = r_strobe->integer; + swapInterval = r_strobe_swapinterval->integer; + + if ((getInterval == 0) || + ((gl_swapInterval->integer == 0) && (getInterval != 0))) { - if (getInterval != 0) //If v-sync is off, turn off strobing + if (!gl_swapInterval->integer) + MsgDev(D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n"); + + if (getInterval != 0) // If v-sync is off, turn off strobing { Cvar_Set("r_strobe", "0"); - MsgDev(D_WARN, "Strobing (Black Frame Replacement) requires V-SYNC not being turned off! (gl_swapInterval != 0) \n"); - Msg("Strobing (Black Frame Insertion) requires Vertical Sync to be enabled!\n"); } - else if (sCounter != 0) - sCounter = 0; + SwapPhaseInfo.fCounter = 0; - // flush any remaining 2D bits R_Set2DMode(false); return; } - - // If interval is positive, insert (replace with) black frames. - // For example result of interval = 3 will be: "black-black-black-normal-black-black-black-normal-black-black-black-normal" - if (getInterval > 0) + + if ((SwapPhaseInfo.fCounter % 2) == 0) // First frame starts with internal positive phase (+) + { + ++SwapPhaseInfo.pCounter; + SwapPhaseInfo.frameInfo |= p_positive; + } + else + { + ++SwapPhaseInfo.nCounter; + SwapPhaseInfo.frameInfo &= ~p_positive; + } + + if (swapInterval < 0) + swapInterval = abs(swapInterval); + + if ((swapInterval != 0) && (getInterval % 2 != 0)) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { - if (sCounter < getInterval) + currentTime = Sys_DoubleTime(); + delta = currentTime - recentTime; + if ((delta >= (double)(swapInterval)) && (delta < (double)(2 * swapInterval))) // Basic timer { - gl_sBlackFrame(); - ++sCounter; + SwapPhaseInfo.frameInfo |= p_inverted; } - else + else if (delta < (double)(swapInterval)) { - sCounter = 0; - R_Set2DMode(false); + SwapPhaseInfo.frameInfo &= ~p_inverted; + } + else //if (delta >= (double)(2 * swapInterval)) + { + recentTime = currentTime; } } - // If interval is negative, the procedure will be the opposite reverse. - // For example result of interval = -4 will be: "normal-normal-normal-normal-black-normal-normal-normal-normal-black" - else + + + // Burnin prevention algorithm will work most effective on r_strobe = 1. Will not work on even intervals. + switch (SwapPhaseInfo.frameInfo & (p_positive | p_inverted)) { - getInterval = abs(getInterval); - if (sCounter < getInterval) + case (p_positive | p_inverted): + if ((abs(getInterval) % 2) == 0) + SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even + else + SwapPhaseInfo.frameInfo &= ~f_normal; + break; + + case(p_positive & ~p_inverted): + if (abs(getInterval) % 2 == 0) + SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even + else { - ++sCounter; - R_Set2DMode(false); + if (abs(getInterval) == 1) + SwapPhaseInfo.frameInfo |= f_normal; + else + SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.pCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //odd } + break; + + case(~p_positive & p_inverted): + if (abs(getInterval) % 2 == 0) + SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even else { - gl_sBlackFrame(); - sCounter = 0; + if (abs(getInterval) == 1) + SwapPhaseInfo.frameInfo |= f_normal; + else + SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.nCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //odd } + break; + + case 0: + if ((abs(getInterval) % 2) == 0) + SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even + else + SwapPhaseInfo.frameInfo &= ~f_normal; + break; + + default: + break; + } + + // Legacy main algorithm (not flag based) - Will be removed soon + /* + if (SwapPhaseInfo.isPositive == true && SwapPhaseInfo.isInverted == false) + { + if (abs(getInterval) % 2 == 0) + SwapPhaseInfo.isNormal = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == 0) ? true : false; //even + else + SwapPhaseInfo.isNormal = (((SwapPhaseInfo.pCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? true : false; //odd + + if (abs(getInterval) == 1) + SwapPhaseInfo.isNormal = true; + } + else if (SwapPhaseInfo.isPositive == true && SwapPhaseInfo.isInverted == true) + { + if ((abs(getInterval) % 2) == 0) + SwapPhaseInfo.isNormal = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? true : false; //even + else + SwapPhaseInfo.isNormal = false; + if (abs(getInterval) == 1) + SwapPhaseInfo.isNormal = false; + } + else if (SwapPhaseInfo.isPositive == false && SwapPhaseInfo.isInverted == false) + { + if ((abs(getInterval) % 2) == 0) + SwapPhaseInfo.isNormal = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? true : false; //even + else + SwapPhaseInfo.isNormal = false; + if (abs(getInterval) == 1) + SwapPhaseInfo.isNormal = false; + } + else if (SwapPhaseInfo.isPositive == false && SwapPhaseInfo.isInverted == true) + { + if (abs(getInterval) % 2 == 0) + SwapPhaseInfo.isNormal = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == 0) ? true : false; //even + else + SwapPhaseInfo.isNormal = (((SwapPhaseInfo.nCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? true : false; //odd + + if (abs(getInterval) == 1) + SwapPhaseInfo.isNormal = true; + } + */ + + if (getInterval < 0) + SwapPhaseInfo.frameInfo ^= f_normal; + + if (SwapPhaseInfo.frameInfo & f_normal) // Show normal + { + if (SwapPhaseInfo.frameInfo & p_positive) + ++SwapPhaseInfo.pNCounter; + else + ++SwapPhaseInfo.nNCounter; + + R_Set2DMode(false); + } + else // Show black + { + if (SwapPhaseInfo.frameInfo & p_positive) + ++SwapPhaseInfo.pBCounter; + else + ++SwapPhaseInfo.nBCounter; + + gl_GenerateBlackFrame(); } + + ++SwapPhaseInfo.fCounter; } + /* =============== R_EndFrame @@ -1413,7 +1552,7 @@ void R_EndFrame( void ) { if (!CL_IsInMenu()) R_Strobe(); - + #ifdef XASH_SDL SDL_GL_SwapWindow( host.hWnd ); #elif defined __ANDROID__ // For direct android backend diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index 80e3fb277..3fa07c063 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -79,6 +79,9 @@ convar_t *r_fastsky; convar_t *r_vbo; convar_t *r_bump; convar_t *r_strobe; +convar_t *r_strobe_swapinterval; +convar_t *r_strobe_debug; + convar_t *mp_decals; convar_t *vid_displayfrequency; @@ -1015,7 +1018,14 @@ register strobe cvar */ static inline void R_initStrobe( void ) { - r_strobe = Cvar_Get("r_strobe", "0", CVAR_ARCHIVE, "black frame insertion interval"); + r_strobe = Cvar_Get("r_strobe", "0", CVAR_ARCHIVE, "black frame replacement interval"); + r_strobe_swapinterval = Cvar_Get("r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval"); + r_strobe_debug = Cvar_Get("r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information"); + + SwapPhaseInfo.pCounter = 0; SwapPhaseInfo.pBCounter = 0; SwapPhaseInfo.pNCounter = 0; + SwapPhaseInfo.pCounter = 0; SwapPhaseInfo.nBCounter = 0; SwapPhaseInfo.nNCounter = 0; + SwapPhaseInfo.fCounter = 0; + SwapPhaseInfo.frameInfo = (p_positive | f_normal); } /* From 5a017983e6bc22cc7aed8ac507012f4bc754d871 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 10 Feb 2018 22:59:34 +0300 Subject: [PATCH 02/35] Brightness reduction calculations --- engine/client/cl_scrn.c | 20 ++++++++++++++++---- engine/client/gl_local.h | 21 ++++++++++++++++++++- engine/client/gl_rmain.c | 2 +- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 0dbc42638..9a1f17628 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -57,7 +57,7 @@ void SCR_DrawFPS( void ) static int minfps = 9999; static int maxfps = 0; double newtime; - char fpsstring[1024]; //char fpsstring[64]; + char fpsstring[2048]; //char fpsstring[64]; int offset; char diffBar[2][128]; @@ -142,7 +142,7 @@ void SCR_DrawFPS( void ) { Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); } - else if(strobeDebug) + else if (strobeDebug) { Q_snprintf(diffBar[0], sizeof(diffBar[0]), "^3["); Q_snprintf(diffBar[1], sizeof(diffBar[1]), "^3["); @@ -176,7 +176,7 @@ void SCR_DrawFPS( void ) { if (pNeg) { - if (100-(barCounter *10) <= diffP) + if (100 - (barCounter * 10) <= diffP) Q_strcat(diffBar[0], "^4=^3"); else Q_strcat(diffBar[0], "^3=^3"); @@ -240,13 +240,25 @@ void SCR_DrawFPS( void ) " |-> Black Frame Count: %u\n\n" \ "timer.triggered %d\n\n" \ "^5ANALYSIS:\n^3" \ - "Diff (+): %s\n\nDiff (N): %s\nGeometric Mean: %f\nG/A Difference: %f\nBadness: %f" \ + "Brightness Reduction:\n" \ + " |->[Linear] Actual Reduction: %3d%%\n" \ + " |->[LOG] Realistic Reduction(400 cd / m2 base) : %3d%%\n" \ + " |->[SQUARE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ + " |->[CUBE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ + "Diff (+): %s\n\nDiff (N): %s\n" \ + "Geometric Mean: %f\n" \ + "G/A Difference: %f\n" \ + "Badness: %f" \ , curfps \ , eFPS \ , SwapPhaseInfo.fCounter \ , SwapPhaseInfo.pCounter, SwapPhaseInfo.pNCounter, SwapPhaseInfo.pBCounter \ , SwapPhaseInfo.nCounter, SwapPhaseInfo.nNCounter, SwapPhaseInfo.nBCounter \ , !!(SwapPhaseInfo.frameInfo & p_inverted) \ + , (int)actualBrightnessReduction(curfps, eFPS) \ + , (int)logBrightnessReduction(400, curfps, eFPS) \ + , squareBrightnessReduction(400, curfps, eFPS) \ + , cubicBrightnessReduction(400, curfps, eFPS) \ , diffBar[0], diffBar[1], sqrt(diffP * diffN) \ , (diffP + diffN) / 2 - sqrt(diffP * diffN) \ , BADNESS(diffP,diffN)); diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index 991e33f09..5bd4512c6 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -350,7 +350,7 @@ int R_CountSurfaceDlights( msurface_t *surf ); int R_CountDlights( void ); -// +// // Move to different file? void R_Strobe(void); typedef enum { @@ -372,6 +372,25 @@ extern SwapPhaseInfo_t SwapPhaseInfo; #define BADNESS(diffP, diffN) \ -log(((abs(diffP-diffN)+sqrt((100-diffP)*(100-diffN)))/(abs(diffP-diffN)+sqrt(diffP*diffN)))) +// Brightness reductions +#define calculatePercentage(x, y) \ + (100 * y / x) + +#define actualBrightnessReduction(fps, efps) \ + ((fps - efps) * 100 / fps) + +#define logBrightnessReduction(base, fps, efps) \ + actualBrightnessReduction( log(base) , log(base * calculatePercentage(fps,efps) / 100) ) + +/* #define log10BrightnessReduction(base, fps, efps) \ + actualBrightnessReduction( log10(base) , log10(base * calculatePercentage(fps,efps) / 100) ) */ + +#define squareBrightnessReduction(base, fps, efps) \ + actualBrightnessReduction( sqrt(base) , sqrt(base * calculatePercentage(fps,efps) / 100) ) + +#define cubicBrightnessReduction(base, fps, efps) \ + actualBrightnessReduction( cbrt(base) , cbrt(base * calculatePercentage(fps,efps) / 100) ) + extern convar_t *r_strobe; extern convar_t *r_strobe_swapinterval; extern convar_t *r_strobe_debug; diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index ced298186..29a918948 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1356,7 +1356,7 @@ inline static void gl_GenerateBlackFrame( void ) // Generates partial or full bl =============== R_Strobe -TODO: \ +TODO: *Make swapping transition seamless by rendering non-opaque frames. *Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) =============== From 511a8fe22d9db98397fd8c63c7bc8f4c7c7873ba Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 10 Feb 2018 23:30:09 +0300 Subject: [PATCH 03/35] PWM Simulation (Debug Mode) Shows PWM stats in debug mode. --- engine/client/cl_scrn.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 9a1f17628..cdb82fbf5 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -228,6 +228,8 @@ void SCR_DrawFPS( void ) Q_strcat(diffBar[0], va("] - %4d%%", (pNeg ? -diffP : diffP))); Q_strcat(diffBar[1], va("] - %4d%%", (nNeg ? -diffN : diffN))); + strobeInterval = r_strobe->integer; + Q_snprintf(fpsstring, sizeof(fpsstring), "%4i FPS\n%3i eFPS\n\n" \ @@ -238,6 +240,9 @@ void SCR_DrawFPS( void ) "(-) Phase Frame Count:%u\n" \ " |-> Normal Frame Count: %u\n" \ " |-> Black Frame Count: %u\n\n" \ + "PWM Simulation:\n" \ + " |->Frequency: %4f Hz\n" \ + " |->Duty Cycle: %4f%%\n" \ "timer.triggered %d\n\n" \ "^5ANALYSIS:\n^3" \ "Brightness Reduction:\n" \ @@ -254,6 +259,8 @@ void SCR_DrawFPS( void ) , SwapPhaseInfo.fCounter \ , SwapPhaseInfo.pCounter, SwapPhaseInfo.pNCounter, SwapPhaseInfo.pBCounter \ , SwapPhaseInfo.nCounter, SwapPhaseInfo.nNCounter, SwapPhaseInfo.nBCounter \ + , (1 / ((1 / (float)(curfps))*(abs(strobeInterval) + 1))) \ + , ((1 / (float)(abs(strobeInterval)+1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1) \ , !!(SwapPhaseInfo.frameInfo & p_inverted) \ , (int)actualBrightnessReduction(curfps, eFPS) \ , (int)logBrightnessReduction(400, curfps, eFPS) \ From faa97ce111cebe8385e9561725fdb96ef0d0bdd4 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 11 Feb 2018 00:53:02 +0300 Subject: [PATCH 04/35] Sync with 8578012e17982a0b7e37b6f2a7c20f64ae48bc22 --- engine/client/cl_scrn.c | 2 +- engine/client/gl_rmain.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index cdb82fbf5..f6e05084c 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -250,7 +250,7 @@ void SCR_DrawFPS( void ) " |->[LOG] Realistic Reduction(400 cd / m2 base) : %3d%%\n" \ " |->[SQUARE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ " |->[CUBE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ - "Diff (+): %s\n\nDiff (N): %s\n" \ + "Diff (+): %s\n\nDiff (-): %s\n" \ "Geometric Mean: %f\n" \ "G/A Difference: %f\n" \ "Badness: %f" \ diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 29a918948..36f4ba7cf 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1368,6 +1368,12 @@ void R_Strobe( void ) static double recentTime = 0; static double currentTime = 0; static double delta = 0; + + if (CL_IsInMenu()) + { + R_Set2DMode(false); + return; + } if (((getInterval != r_strobe->integer) && (getInterval != 0)) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ @@ -1550,8 +1556,7 @@ R_EndFrame */ void R_EndFrame( void ) { - if (!CL_IsInMenu()) - R_Strobe(); + R_Strobe(); #ifdef XASH_SDL SDL_GL_SwapWindow( host.hWnd ); From 1d58b1e46b13d982d22460ee5a5c6f5bfa804732 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 11 Feb 2018 00:59:44 +0300 Subject: [PATCH 05/35] Revert "Sync with 8578012e17982a0b7e37b6f2a7c20f64ae48bc22" This reverts commit faa97ce111cebe8385e9561725fdb96ef0d0bdd4. --- engine/client/cl_scrn.c | 2 +- engine/client/gl_rmain.c | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index f6e05084c..cdb82fbf5 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -250,7 +250,7 @@ void SCR_DrawFPS( void ) " |->[LOG] Realistic Reduction(400 cd / m2 base) : %3d%%\n" \ " |->[SQUARE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ " |->[CUBE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ - "Diff (+): %s\n\nDiff (-): %s\n" \ + "Diff (+): %s\n\nDiff (N): %s\n" \ "Geometric Mean: %f\n" \ "G/A Difference: %f\n" \ "Badness: %f" \ diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 36f4ba7cf..29a918948 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1368,12 +1368,6 @@ void R_Strobe( void ) static double recentTime = 0; static double currentTime = 0; static double delta = 0; - - if (CL_IsInMenu()) - { - R_Set2DMode(false); - return; - } if (((getInterval != r_strobe->integer) && (getInterval != 0)) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ @@ -1556,7 +1550,8 @@ R_EndFrame */ void R_EndFrame( void ) { - R_Strobe(); + if (!CL_IsInMenu()) + R_Strobe(); #ifdef XASH_SDL SDL_GL_SwapWindow( host.hWnd ); From f6a61e807727e989dcd6346a7e3323e13fa1181c Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 11 Feb 2018 01:00:56 +0300 Subject: [PATCH 06/35] Sync with 8578012e17982a0b7e37b6f2a7c20f64ae48bc22 --- engine/client/gl_rmain.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 29a918948..f034f484e 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1550,7 +1550,11 @@ R_EndFrame */ void R_EndFrame( void ) { - if (!CL_IsInMenu()) + if (CL_IsInMenu()) + { + R_Set2DMode(false); + } + else R_Strobe(); #ifdef XASH_SDL From 7739e2d40b1f0dfc4ab050095a2b8e8cb14da5ce Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 11 Feb 2018 01:03:29 +0300 Subject: [PATCH 07/35] Some typo correction --- engine/client/cl_scrn.c | 13 +++++++------ engine/client/gl_rmain.c | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index cdb82fbf5..ee5fedac4 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -59,6 +59,7 @@ void SCR_DrawFPS( void ) double newtime; char fpsstring[2048]; //char fpsstring[64]; int offset; + int curfps; char diffBar[2][128]; char barCounter = 0; @@ -109,7 +110,7 @@ void SCR_DrawFPS( void ) } else { - int curfps = (int)(calc + 0.5f); + curfps = (int)(calc + 0.5f); if( curfps < minfps ) minfps = curfps; if( curfps > maxfps ) maxfps = curfps; @@ -140,7 +141,7 @@ void SCR_DrawFPS( void ) if (strobeInterval == 0) { - Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); + Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); } else if (strobeDebug) { @@ -232,8 +233,8 @@ void SCR_DrawFPS( void ) Q_snprintf(fpsstring, sizeof(fpsstring), - "%4i FPS\n%3i eFPS\n\n" \ - "Total Frame Count: %u\n\n" \ + "%4i FPS\n%3i eFPS\n" \ + "Total Frame Count: %u\n" \ "(+) Phase Frame Count: %u\n" \ " |-> Normal Frame Count: %u\n" \ " |-> Black Frame Count: %u\n\n" \ @@ -243,14 +244,14 @@ void SCR_DrawFPS( void ) "PWM Simulation:\n" \ " |->Frequency: %4f Hz\n" \ " |->Duty Cycle: %4f%%\n" \ - "timer.triggered %d\n\n" \ + "timer.triggered %d\n" \ "^5ANALYSIS:\n^3" \ "Brightness Reduction:\n" \ " |->[Linear] Actual Reduction: %3d%%\n" \ " |->[LOG] Realistic Reduction(400 cd / m2 base) : %3d%%\n" \ " |->[SQUARE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ " |->[CUBE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ - "Diff (+): %s\n\nDiff (N): %s\n" \ + "Diff (+): %s\n\nDiff (-): %s\n" \ "Geometric Mean: %f\n" \ "G/A Difference: %f\n" \ "Badness: %f" \ diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index f034f484e..37d00ddcc 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1551,9 +1551,7 @@ R_EndFrame void R_EndFrame( void ) { if (CL_IsInMenu()) - { R_Set2DMode(false); - } else R_Strobe(); From 9d01da81a8bca630287c2f93a6ee868a4126b11d Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 18 Feb 2018 00:14:54 +0300 Subject: [PATCH 08/35] Refactor & PWM Simulation Updates --- engine/client/cl_scrn.c | 98 ++++++++++++--------- engine/client/console.c | 2 +- engine/client/gl_local.h | 34 +++++--- engine/client/gl_rmain.c | 174 +++++++++++++++++++------------------ engine/client/vid_common.c | 8 +- engine/common/common.h | 12 --- 6 files changed, 171 insertions(+), 157 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index ee5fedac4..47cbd04c2 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -57,24 +57,23 @@ void SCR_DrawFPS( void ) static int minfps = 9999; static int maxfps = 0; double newtime; - char fpsstring[2048]; //char fpsstring[64]; + char fpsstring[2048]; //char fpsstring[64]; // Heap allocation if 2048 too much ? int offset; int curfps; char diffBar[2][128]; - char barCounter = 0; - int diffP_NB = (SwapPhaseInfo.pNCounter - SwapPhaseInfo.pBCounter); - int diffN_NB = (SwapPhaseInfo.nNCounter - SwapPhaseInfo.nBCounter); + char _barCounter = 0; + int diffP_NB = (StrobeInfo.pNCounter - StrobeInfo.pBCounter); + int diffN_NB = (StrobeInfo.nNCounter - StrobeInfo.nBCounter); int diffP = 0, diffN = 0; qboolean pNeg = false, nNeg = false; - int strobeInterval = r_strobe->integer; // cvar: r_strobe + int strobeInterval = r_strobe->integer; int eFPS; // Effective FPS (strobing effect) qboolean strobeDebug = !!r_strobe_debug->integer ? true : false; if( cls.state != ca_active ) return; if( (!cl_showfps->integer && !strobeDebug) || cl.background ) return; - switch( cls.scrshot_action ) { case scrshot_normal: @@ -91,7 +90,6 @@ void SCR_DrawFPS( void ) lasttime = newtime; nexttime = max( nexttime + 1, lasttime - 1 ); - //Msg("Lasttime: %f . Nexttime: %f . %f\n", lasttime, nexttime, newtime - lasttime); //Sleep(150); @@ -120,12 +118,12 @@ void SCR_DrawFPS( void ) if (strobeInterval > 0) { - eFPS = (int)((curfps) / (strobeInterval + 1)); + eFPS = (curfps) / (strobeInterval + 1); } else if (strobeInterval < 0) { strobeInterval = abs(strobeInterval); - eFPS = (int)((curfps * strobeInterval) / (strobeInterval + 1)); + eFPS = (curfps * strobeInterval) / (strobeInterval + 1); } switch( cl_showfps->integer ) @@ -160,24 +158,24 @@ void SCR_DrawFPS( void ) diffN_NB = abs(diffN_NB); } - if (SwapPhaseInfo.pCounter != 0) - diffP = round(diffP_NB * 100 / SwapPhaseInfo.pCounter); + if (StrobeInfo.pCounter != 0) + diffP = round(diffP_NB * 100 / StrobeInfo.pCounter); - if (SwapPhaseInfo.nCounter != 0) - diffN = round(diffN_NB * 100 / SwapPhaseInfo.nCounter); + if (StrobeInfo.nCounter != 0) + diffN = round(diffN_NB * 100 / StrobeInfo.nCounter); - for (barCounter = 0; barCounter <= 20; ++barCounter) + for (_barCounter = 0; _barCounter <= 20; ++_barCounter) { - if (barCounter == 10) + if (_barCounter == 10) { Q_strcat(diffBar[0], "O"); Q_strcat(diffBar[1], "O"); } - else if (barCounter < 10) + else if (_barCounter < 10) { if (pNeg) { - if (100 - (barCounter * 10) <= diffP) + if (100 - (_barCounter * 11) <= diffP) Q_strcat(diffBar[0], "^4=^3"); else Q_strcat(diffBar[0], "^3=^3"); @@ -189,7 +187,7 @@ void SCR_DrawFPS( void ) if (nNeg) { - if (100 - (barCounter * 10) <= diffN) + if (100 - (_barCounter * 11) <= diffN) Q_strcat(diffBar[1], "^4=^3"); else Q_strcat(diffBar[1], "^3=^3"); @@ -199,7 +197,7 @@ void SCR_DrawFPS( void ) Q_strcat(diffBar[1], "^3=^3"); } } - else if (barCounter > 10) + else if (_barCounter > 10) { if (pNeg) { @@ -207,7 +205,7 @@ void SCR_DrawFPS( void ) } else { - if (((barCounter - 10) * 10) > diffP) + if (((_barCounter - 11) * 11) >= diffP) Q_strcat(diffBar[0], "^3=^3"); else Q_strcat(diffBar[0], "^4=^3"); @@ -219,7 +217,7 @@ void SCR_DrawFPS( void ) } else { - if (((barCounter - 10) * 10) > diffN) + if (((_barCounter - 11) * 11) >= diffN) Q_strcat(diffBar[1], "^3=^3"); else Q_strcat(diffBar[1], "^4=^3"); @@ -237,39 +235,48 @@ void SCR_DrawFPS( void ) "Total Frame Count: %u\n" \ "(+) Phase Frame Count: %u\n" \ " |-> Normal Frame Count: %u\n" \ - " |-> Black Frame Count: %u\n\n" \ + " |-> Black Frame Count: %u\n" \ "(-) Phase Frame Count:%u\n" \ " |-> Normal Frame Count: %u\n" \ - " |-> Black Frame Count: %u\n\n" \ + " |-> Black Frame Count: %u\n" \ + "FrameInfo.isInverted: %d\n" \ + "^5ANALYSIS:\n^3" \ "PWM Simulation:\n" \ " |->Frequency: %4f Hz\n" \ " |->Duty Cycle: %4f%%\n" \ - "timer.triggered %d\n" \ - "^5ANALYSIS:\n^3" \ + " |->Current Phase Shift: +%4f msec || -%4f msec\n" \ + " |->Period: %4f msec\n" \ "Brightness Reduction:\n" \ - " |->[Linear] Actual Reduction: %3d%%\n" \ - " |->[LOG] Realistic Reduction(400 cd / m2 base) : %3d%%\n" \ - " |->[SQUARE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ - " |->[CUBE] Realistic Reduction(400 cd / m2 base) : %3f%%\n" \ - "Diff (+): %s\n\nDiff (-): %s\n" \ + " |-> [LINEAR] Actual Reduction: %3d%%\n" \ + " |-> [LOG] Realistic Reduction (400 cd/m2 base) : %3f%%\n" \ + " |-> [SQUARE] Realistic Reduction (400 cd/m2 base) : %3f%%\n" \ + " |-> [CUBE] Realistic Reduction (400 cd/m2 base) : %3f%%\n" \ + "Difference (+): %s\nDifference (-): %s\n" \ "Geometric Mean: %f\n" \ "G/A Difference: %f\n" \ - "Badness: %f" \ + "^5Experimental Functions:\n^3" \ + "[*] Badness: %f\n" \ + "[*] Badness x PWM Period: %f" \ , curfps \ , eFPS \ - , SwapPhaseInfo.fCounter \ - , SwapPhaseInfo.pCounter, SwapPhaseInfo.pNCounter, SwapPhaseInfo.pBCounter \ - , SwapPhaseInfo.nCounter, SwapPhaseInfo.nNCounter, SwapPhaseInfo.nBCounter \ - , (1 / ((1 / (float)(curfps))*(abs(strobeInterval) + 1))) \ - , ((1 / (float)(abs(strobeInterval)+1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1) \ - , !!(SwapPhaseInfo.frameInfo & p_inverted) \ - , (int)actualBrightnessReduction(curfps, eFPS) \ - , (int)logBrightnessReduction(400, curfps, eFPS) \ + , StrobeInfo.fCounter \ + , StrobeInfo.pCounter, StrobeInfo.pNCounter, StrobeInfo.pBCounter \ + , StrobeInfo.nCounter, StrobeInfo.nNCounter, StrobeInfo.nBCounter \ + , !!(StrobeInfo.frameInfo & p_inverted) \ + , (1 / ((1.0f / curfps)*(abs(strobeInterval) + 1))) \ + , ((1.0f / (abs(strobeInterval) + 1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1) \ + , !!(StrobeInfo.frameInfo & p_inverted) ? (1.0f / curfps) * 1000 : 0.0f \ + , !!(StrobeInfo.frameInfo & p_inverted) ? abs(strobeInterval) * (1.0f / curfps) * 1000 : 0.0f \ + , (((1.0f / curfps)*(abs(strobeInterval) + 1)) * 1000) \ + , actualBrightnessReduction(curfps, eFPS) \ + , logBrightnessReduction(400, curfps, eFPS) \ , squareBrightnessReduction(400, curfps, eFPS) \ , cubicBrightnessReduction(400, curfps, eFPS) \ - , diffBar[0], diffBar[1], sqrt(diffP * diffN) \ + , diffBar[0], diffBar[1] \ + , sqrt(diffP * diffN) \ , (diffP + diffN) / 2 - sqrt(diffP * diffN) \ - , BADNESS(diffP,diffN)); + , STROBE_BADNESS(diffP, diffN) \ + , STROBE_BADNESS(diffP, diffN) * ((1.0f / curfps) * (abs(strobeInterval) + 1))); } else { @@ -280,8 +287,13 @@ void SCR_DrawFPS( void ) } Con_DrawStringLen( fpsstring, &offset, NULL ); - //Con_DrawString( scr_width->integer - offset - 5, 4, fpsstring, color ); - Con_DrawString(scr_width->integer - offset - 75, 4, fpsstring, color); // TODO: Fix alignment for non debug setup! + + if (strobeInterval == 0) + Con_DrawString(scr_width->integer - offset - 2, 4, fpsstring, color); + else if (strobeDebug) + Con_DrawString(scr_width->integer - offset - 75, 4, fpsstring, color); + else + Con_DrawString(scr_width->integer - offset - 5, 4, fpsstring, color); } /* diff --git a/engine/client/console.c b/engine/client/console.c index 5a9fe7abb..2a94c938a 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -33,7 +33,7 @@ convar_t *con_fontscale; convar_t *con_fontnum; convar_t *vgui_utf8; -conrect_t con_rect; +_rectf_t con_rect; static int g_codepage = 0; static qboolean g_utf8 = false; diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index 5bd4512c6..02045748e 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -350,7 +350,19 @@ int R_CountSurfaceDlights( msurface_t *surf ); int R_CountDlights( void ); -// // Move to different file? +/// // Move to different file? + +//#define SolidConsoleX 0 +//#define SolidConsoleY (y - scr_width->value * 3 / 4) +//#define SolidConsoleW (scr_width->value) +//#define SolidConsoleH (scr_width->value * 3 / 4) +//extern wrect_t con_rect; //Float - Int incompatibility +typedef struct _rectf_s +{ + float x, y, w, h; +}_rectf_t; +extern _rectf_t con_rect; + void R_Strobe(void); typedef enum { @@ -359,42 +371,42 @@ typedef enum { f_normal = 1 << 2 // Frame: Normal }fstate_e; // Frame State -typedef struct SwapPhaseInfo_s { +typedef struct StrobeInfo_s { unsigned int fCounter; // Frame counter unsigned int pCounter, pNCounter, pBCounter; // Positive phase counters unsigned int nCounter, nNCounter, nBCounter; // Negative phase counters fstate_e frameInfo; // Frame info -}SwapPhaseInfo_t; +}StrobeInfo_t; -extern SwapPhaseInfo_t SwapPhaseInfo; +extern StrobeInfo_t StrobeInfo; -// Experimental 'Badness' algorithm -#define BADNESS(diffP, diffN) \ +// Experimental 'Badness' function +#define STROBE_BADNESS(diffP, diffNs) \ -log(((abs(diffP-diffN)+sqrt((100-diffP)*(100-diffN)))/(abs(diffP-diffN)+sqrt(diffP*diffN)))) // Brightness reductions -#define calculatePercentage(x, y) \ +#define _calculatePercentage(x, y) \ (100 * y / x) #define actualBrightnessReduction(fps, efps) \ ((fps - efps) * 100 / fps) #define logBrightnessReduction(base, fps, efps) \ - actualBrightnessReduction( log(base) , log(base * calculatePercentage(fps,efps) / 100) ) + actualBrightnessReduction( log(base) , log(base * _calculatePercentage(fps,efps) / 100) ) /* #define log10BrightnessReduction(base, fps, efps) \ actualBrightnessReduction( log10(base) , log10(base * calculatePercentage(fps,efps) / 100) ) */ #define squareBrightnessReduction(base, fps, efps) \ - actualBrightnessReduction( sqrt(base) , sqrt(base * calculatePercentage(fps,efps) / 100) ) + actualBrightnessReduction( sqrt(base) , sqrt(base * _calculatePercentage(fps,efps) / 100) ) #define cubicBrightnessReduction(base, fps, efps) \ - actualBrightnessReduction( cbrt(base) , cbrt(base * calculatePercentage(fps,efps) / 100) ) + actualBrightnessReduction( cbrt(base) , cbrt(base * _calculatePercentage(fps,efps) / 100) ) extern convar_t *r_strobe; extern convar_t *r_strobe_swapinterval; extern convar_t *r_strobe_debug; -// +/// // diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 37d00ddcc..9e9accb71 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -35,7 +35,7 @@ ref_instance_t RI, prevRI; mleaf_t *r_viewleaf, *r_oldviewleaf; mleaf_t *r_viewleaf2, *r_oldviewleaf2; -SwapPhaseInfo_t SwapPhaseInfo; +StrobeInfo_t StrobeInfo; static int R_RankForRenderMode( cl_entity_t *ent ) { @@ -1328,7 +1328,7 @@ void R_RenderFrame( const ref_params_t *fd, qboolean drawWorld ) GL_BackendEndFrame(); } -inline static void gl_GenerateBlackFrame( void ) // Generates partial or full black frame +static inline void gl_GenerateBlackFrame( void ) // Generates partial or full black frame { if ( CL_IsInConsole() ) // No strobing on the console { @@ -1337,11 +1337,11 @@ inline static void gl_GenerateBlackFrame( void ) // Generates partial or full bl R_Set2DMode(false); return; } - pglEnable( GL_SCISSOR_TEST); - pglScissor( con_rect.x, (-con_rect.y) - (con_rect.h*1.25), con_rect.w, con_rect.h ); // Preview strobe setting on static + pglEnable( GL_SCISSOR_TEST ); + pglScissor( con_rect.x, (-con_rect.y) - (con_rect.h * 1.25), con_rect.w, con_rect.h ); // Preview strobe setting on static pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); - pglClear( GL_COLOR_BUFFER_BIT); - pglDisable( GL_SCISSOR_TEST); + pglClear( GL_COLOR_BUFFER_BIT ); + pglDisable( GL_SCISSOR_TEST ); } else { @@ -1359,187 +1359,189 @@ R_Strobe TODO: *Make swapping transition seamless by rendering non-opaque frames. *Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) + * (?) Call R_Strobe each frame no matter strobe setting and simulate strobing to keep the phases on track (When on menu, ...) + * (?) Move "Strobe" to seperate files. =============== */ void R_Strobe( void ) { - static int getInterval = 0; + static int strobeInterval = 0; static int swapInterval = 0; static double recentTime = 0; - static double currentTime = 0; - static double delta = 0; + double currentTime = 0; + double _delta = 0; - if (((getInterval != r_strobe->integer) && (getInterval != 0)) || + if (((strobeInterval != r_strobe->integer) && (strobeInterval != 0)) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - SwapPhaseInfo.fCounter > 87091200) // Reset stats after some time + StrobeInfo.fCounter > 87091200) // Reset stats after some time { - SwapPhaseInfo.pCounter = 0; SwapPhaseInfo.pBCounter = 0; SwapPhaseInfo.pNCounter = 0; - SwapPhaseInfo.nCounter = 0; SwapPhaseInfo.nBCounter = 0; SwapPhaseInfo.nNCounter = 0; - SwapPhaseInfo.fCounter = 0; - SwapPhaseInfo.frameInfo &= ~p_inverted; + StrobeInfo.pCounter = 0; StrobeInfo.pBCounter = 0; StrobeInfo.pNCounter = 0; + StrobeInfo.nCounter = 0; StrobeInfo.nBCounter = 0; StrobeInfo.nNCounter = 0; + StrobeInfo.fCounter = 0; + StrobeInfo.frameInfo &= ~p_inverted; } - getInterval = r_strobe->integer; + strobeInterval = r_strobe->integer; swapInterval = r_strobe_swapinterval->integer; - if ((getInterval == 0) || - ((gl_swapInterval->integer == 0) && (getInterval != 0))) + if ((strobeInterval == 0) || + ((gl_swapInterval->integer == 0) && (strobeInterval != 0))) { if (!gl_swapInterval->integer) MsgDev(D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n"); - if (getInterval != 0) // If v-sync is off, turn off strobing + if (strobeInterval != 0) // If v-sync is off, turn off strobing { Cvar_Set("r_strobe", "0"); } - SwapPhaseInfo.fCounter = 0; + StrobeInfo.fCounter = 0; R_Set2DMode(false); return; } - if ((SwapPhaseInfo.fCounter % 2) == 0) // First frame starts with internal positive phase (+) + if ((StrobeInfo.fCounter % 2) == 0) { - ++SwapPhaseInfo.pCounter; - SwapPhaseInfo.frameInfo |= p_positive; + ++StrobeInfo.pCounter; + StrobeInfo.frameInfo |= p_positive; } else { - ++SwapPhaseInfo.nCounter; - SwapPhaseInfo.frameInfo &= ~p_positive; + ++StrobeInfo.nCounter; + StrobeInfo.frameInfo &= ~p_positive; } if (swapInterval < 0) swapInterval = abs(swapInterval); - if ((swapInterval != 0) && (getInterval % 2 != 0)) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ((swapInterval != 0) && (strobeInterval % 2 != 0)) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { currentTime = Sys_DoubleTime(); - delta = currentTime - recentTime; - if ((delta >= (double)(swapInterval)) && (delta < (double)(2 * swapInterval))) // Basic timer + _delta = currentTime - recentTime; + if ((_delta >= (double)(swapInterval)) && (_delta < (double)(2 * swapInterval))) // Basic timer { - SwapPhaseInfo.frameInfo |= p_inverted; + StrobeInfo.frameInfo |= p_inverted; } - else if (delta < (double)(swapInterval)) + else if (_delta < (double)(swapInterval)) { - SwapPhaseInfo.frameInfo &= ~p_inverted; + StrobeInfo.frameInfo &= ~p_inverted; } - else //if (delta >= (double)(2 * swapInterval)) + else //if (_delta >= (double)(2 * swapInterval)) { recentTime = currentTime; } } - - // Burnin prevention algorithm will work most effective on r_strobe = 1. Will not work on even intervals. - switch (SwapPhaseInfo.frameInfo & (p_positive | p_inverted)) + + switch (StrobeInfo.frameInfo & (p_positive | p_inverted)) { case (p_positive | p_inverted): - if ((abs(getInterval) % 2) == 0) - SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even + if ((abs(strobeInterval) % 2) == 0) + StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even else - SwapPhaseInfo.frameInfo &= ~f_normal; + StrobeInfo.frameInfo &= ~f_normal; break; case(p_positive & ~p_inverted): - if (abs(getInterval) % 2 == 0) - SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even + if (abs(strobeInterval) % 2 == 0) + StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even else { - if (abs(getInterval) == 1) - SwapPhaseInfo.frameInfo |= f_normal; + if (abs(strobeInterval) == 1) + StrobeInfo.frameInfo |= f_normal; else - SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.pCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //odd + StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //odd } break; case(~p_positive & p_inverted): - if (abs(getInterval) % 2 == 0) - SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even + if (abs(strobeInterval) % 2 == 0) + StrobeInfo.frameInfo = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even else { - if (abs(getInterval) == 1) - SwapPhaseInfo.frameInfo |= f_normal; + if (abs(strobeInterval) == 1) + StrobeInfo.frameInfo |= f_normal; else - SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.nCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //odd + StrobeInfo.frameInfo = (((StrobeInfo.nCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //odd } break; case 0: - if ((abs(getInterval) % 2) == 0) - SwapPhaseInfo.frameInfo = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? SwapPhaseInfo.frameInfo | f_normal : SwapPhaseInfo.frameInfo & ~f_normal; //even + if ((abs(strobeInterval) % 2) == 0) + StrobeInfo.frameInfo = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even else - SwapPhaseInfo.frameInfo &= ~f_normal; + StrobeInfo.frameInfo &= ~f_normal; break; default: + StrobeInfo.frameInfo = (p_positive | f_normal); break; } - // Legacy main algorithm (not flag based) - Will be removed soon + // Legacy code - Will be removed soon /* - if (SwapPhaseInfo.isPositive == true && SwapPhaseInfo.isInverted == false) + if (StrobeInfo.isPositive == true && StrobeInfo.isInverted == false) { - if (abs(getInterval) % 2 == 0) - SwapPhaseInfo.isNormal = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == 0) ? true : false; //even + if (abs(strobeInterval) % 2 == 0) + StrobeInfo.isNormal = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? true : false; //even else - SwapPhaseInfo.isNormal = (((SwapPhaseInfo.pCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? true : false; //odd + StrobeInfo.isNormal = (((StrobeInfo.pCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? true : false; //odd - if (abs(getInterval) == 1) - SwapPhaseInfo.isNormal = true; + if (abs(strobeInterval) == 1) + StrobeInfo.isNormal = true; } - else if (SwapPhaseInfo.isPositive == true && SwapPhaseInfo.isInverted == true) + else if (StrobeInfo.isPositive == true && StrobeInfo.isInverted == true) { - if ((abs(getInterval) % 2) == 0) - SwapPhaseInfo.isNormal = (((SwapPhaseInfo.pCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? true : false; //even + if ((abs(strobeInterval) % 2) == 0) + StrobeInfo.isNormal = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? true : false; //even else - SwapPhaseInfo.isNormal = false; - if (abs(getInterval) == 1) - SwapPhaseInfo.isNormal = false; + StrobeInfo.isNormal = false; + if (abs(strobeInterval) == 1) + StrobeInfo.isNormal = false; } - else if (SwapPhaseInfo.isPositive == false && SwapPhaseInfo.isInverted == false) + else if (StrobeInfo.isPositive == false && StrobeInfo.isInverted == false) { - if ((abs(getInterval) % 2) == 0) - SwapPhaseInfo.isNormal = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == (abs(getInterval) / 2)) ? true : false; //even + if ((abs(strobeInterval) % 2) == 0) + StrobeInfo.isNormal = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? true : false; //even else - SwapPhaseInfo.isNormal = false; - if (abs(getInterval) == 1) - SwapPhaseInfo.isNormal = false; + StrobeInfo.isNormal = false; + if (abs(strobeInterval) == 1) + StrobeInfo.isNormal = false; } - else if (SwapPhaseInfo.isPositive == false && SwapPhaseInfo.isInverted == true) + else if (StrobeInfo.isPositive == false && StrobeInfo.isInverted == true) { - if (abs(getInterval) % 2 == 0) - SwapPhaseInfo.isNormal = (((SwapPhaseInfo.nCounter - 1) % (abs(getInterval) + 1)) == 0) ? true : false; //even + if (abs(strobeInterval) % 2 == 0) + StrobeInfo.isNormal = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? true : false; //even else - SwapPhaseInfo.isNormal = (((SwapPhaseInfo.nCounter - 1) % ((abs(getInterval) + 1) / 2)) == 0) ? true : false; //odd + StrobeInfo.isNormal = (((StrobeInfo.nCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? true : false; //odd - if (abs(getInterval) == 1) - SwapPhaseInfo.isNormal = true; + if (abs(strobeInterval) == 1) + StrobeInfo.isNormal = true; } */ - if (getInterval < 0) - SwapPhaseInfo.frameInfo ^= f_normal; + if (strobeInterval < 0) + StrobeInfo.frameInfo ^= f_normal; - if (SwapPhaseInfo.frameInfo & f_normal) // Show normal + if (StrobeInfo.frameInfo & f_normal) // Show normal { - if (SwapPhaseInfo.frameInfo & p_positive) - ++SwapPhaseInfo.pNCounter; + if (StrobeInfo.frameInfo & p_positive) + ++StrobeInfo.pNCounter; else - ++SwapPhaseInfo.nNCounter; + ++StrobeInfo.nNCounter; R_Set2DMode(false); } else // Show black { - if (SwapPhaseInfo.frameInfo & p_positive) - ++SwapPhaseInfo.pBCounter; + if (StrobeInfo.frameInfo & p_positive) + ++StrobeInfo.pBCounter; else - ++SwapPhaseInfo.nBCounter; + ++StrobeInfo.nBCounter; gl_GenerateBlackFrame(); } - ++SwapPhaseInfo.fCounter; + ++StrobeInfo.fCounter; } diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index 3fa07c063..5ebf01d6e 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -1022,10 +1022,10 @@ static inline void R_initStrobe( void ) r_strobe_swapinterval = Cvar_Get("r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval"); r_strobe_debug = Cvar_Get("r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information"); - SwapPhaseInfo.pCounter = 0; SwapPhaseInfo.pBCounter = 0; SwapPhaseInfo.pNCounter = 0; - SwapPhaseInfo.pCounter = 0; SwapPhaseInfo.nBCounter = 0; SwapPhaseInfo.nNCounter = 0; - SwapPhaseInfo.fCounter = 0; - SwapPhaseInfo.frameInfo = (p_positive | f_normal); + StrobeInfo.pCounter = 0; StrobeInfo.pBCounter = 0; StrobeInfo.pNCounter = 0; + StrobeInfo.pCounter = 0; StrobeInfo.nBCounter = 0; StrobeInfo.nNCounter = 0; + StrobeInfo.fCounter = 0; + StrobeInfo.frameInfo = (p_positive | f_normal); } /* diff --git a/engine/common/common.h b/engine/common/common.h index 0f31f5925..2a2fce1b8 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -1077,18 +1077,6 @@ void Con_ClearAutoComplete(); // // console.c // - -//#define SolidConsoleX 0 -//#define SolidConsoleY (y - scr_width->value * 3 / 4) -//#define SolidConsoleW (scr_width->value) -//#define SolidConsoleH (scr_width->value * 3 / 4) -//extern wrect_t con_rect; //Float - Int incompatibility -typedef struct conrect_s -{ - float x, y, w, h; -}conrect_t; -extern conrect_t con_rect; - void Con_Clear( void ); extern const char *svc_strings[256]; From 48782bef6e531d18c877bba421b5d5605b366b56 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 18 Feb 2018 01:25:52 +0300 Subject: [PATCH 09/35] MainUI Sync --- mainui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainui b/mainui index 2c35b8ed2..4714b2e7b 160000 --- a/mainui +++ b/mainui @@ -1 +1 @@ -Subproject commit 2c35b8ed2369c50e0be357fc021c11087e946d3c +Subproject commit 4714b2e7b4eaf42a286d63d69355402e6b630945 From 9a89b57acd5676df0102b7a9d6111752cd29ca42 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 18 Feb 2018 19:08:10 +0300 Subject: [PATCH 10/35] Implemented Stability Checker & Refactoring --- engine/client/cl_scrn.c | 141 +++++++++++++++--------------- engine/client/gl_local.h | 38 ++++---- engine/client/gl_rmain.c | 173 ++++++++++++++++++++----------------- engine/client/vid_common.c | 16 ++-- 4 files changed, 198 insertions(+), 170 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 63fbf1706..d61563ed0 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -89,10 +89,6 @@ void SCR_DrawFPS( void ) framerate = framecount / (newtime - lasttime); lasttime = newtime; nexttime = max( nexttime + 1, lasttime - 1 ); - - //Msg("Lasttime: %f . Nexttime: %f . %f\n", lasttime, nexttime, newtime - lasttime); - //Sleep(150); - framecount = 0; } @@ -103,7 +99,7 @@ void SCR_DrawFPS( void ) if( calc < 1.0f ) { - Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i spf", (int)(1.0f / calc + 0.5f)); + Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i spf", (int)(1.0f / calc + 0.5f) ); MakeRGBA( color, 255, 0, 0, 255 ); } else @@ -118,12 +114,12 @@ void SCR_DrawFPS( void ) if( strobeInterval > 0 ) { - eFPS = (curfps) / (strobeInterval + 1); + eFPS = ( curfps ) / ( strobeInterval + 1 ); } else if( strobeInterval < 0 ) { - strobeInterval = abs(strobeInterval); - eFPS = (curfps * strobeInterval) / (strobeInterval + 1); + strobeInterval = abs( strobeInterval ); + eFPS = ( curfps * strobeInterval ) / ( strobeInterval + 1 ); } switch( cl_showfps->integer ) @@ -137,95 +133,95 @@ void SCR_DrawFPS( void ) case 1: default: - if (strobeInterval == 0) + if ( strobeInterval == 0 ) { - Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); + Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i fps", curfps ); } - else if (strobeDebug) + else if ( strobeDebug ) { - Q_snprintf(diffBar[0], sizeof(diffBar[0]), "^3["); - Q_snprintf(diffBar[1], sizeof(diffBar[1]), "^3["); + Q_snprintf( diffBar[0], sizeof( diffBar[0] ), "^3[" ); + Q_snprintf( diffBar[1], sizeof( diffBar[1] ), "^3[" ); - if (diffP_NB < 0) + if ( diffP_NB < 0 ) { pNeg = true; - diffP_NB = abs(diffP_NB); + diffP_NB = abs( diffP_NB ); } - if (diffN_NB < 0) + if ( diffN_NB < 0 ) { nNeg = true; - diffN_NB = abs(diffN_NB); + diffN_NB = abs( diffN_NB ); } - if (StrobeInfo.pCounter != 0) - diffP = round(diffP_NB * 100 / StrobeInfo.pCounter); + if ( StrobeInfo.pCounter != 0 ) + diffP = round( diffP_NB * 100 / StrobeInfo.pCounter ); - if (StrobeInfo.nCounter != 0) - diffN = round(diffN_NB * 100 / StrobeInfo.nCounter); + if ( StrobeInfo.nCounter != 0 ) + diffN = round( diffN_NB * 100 / StrobeInfo.nCounter ); - for (_barCounter = 0; _barCounter <= 20; ++_barCounter) + for ( _barCounter = 0; _barCounter <= 20; ++_barCounter ) { - if (_barCounter == 10) + if ( _barCounter == 10 ) { - Q_strcat(diffBar[0], "O"); - Q_strcat(diffBar[1], "O"); + Q_strcat( diffBar[0], "O" ); + Q_strcat( diffBar[1], "O" ); } - else if (_barCounter < 10) + else if ( _barCounter < 10 ) { - if (pNeg) + if ( pNeg ) { - if (100 - (_barCounter * 11) <= diffP) - Q_strcat(diffBar[0], "^4=^3"); + if ( 100 - ( _barCounter * 11 ) <= diffP ) + Q_strcat( diffBar[0], "^4=^3" ); else - Q_strcat(diffBar[0], "^3=^3"); + Q_strcat( diffBar[0], "^3=" ); } else { - Q_strcat(diffBar[0], "^3=^3"); + Q_strcat( diffBar[0], "^3=" ); } - if (nNeg) + if ( nNeg ) { - if (100 - (_barCounter * 11) <= diffN) - Q_strcat(diffBar[1], "^4=^3"); + if ( 100 - ( _barCounter * 11 ) <= diffN ) + Q_strcat( diffBar[1], "^4=^3" ); else - Q_strcat(diffBar[1], "^3=^3"); + Q_strcat( diffBar[1], "^3=" ); } else { - Q_strcat(diffBar[1], "^3=^3"); + Q_strcat( diffBar[1], "^3=" ); } } - else if (_barCounter > 10) + else if ( _barCounter > 10 ) { - if (pNeg) + if ( pNeg ) { - Q_strcat(diffBar[0], "^3=^3"); + Q_strcat( diffBar[0], "^3=" ); } else { - if (((_barCounter - 11) * 11) >= diffP) - Q_strcat(diffBar[0], "^3=^3"); + if ( ( ( _barCounter - 11 ) * 11 ) >= diffP ) + Q_strcat( diffBar[0], "^3=" ); else - Q_strcat(diffBar[0], "^4=^3"); + Q_strcat( diffBar[0], "^4=^3" ); } - if (nNeg) + if ( nNeg ) { - Q_strcat(diffBar[1], "^3=^3"); + Q_strcat( diffBar[1], "^3=" ); } else { - if (((_barCounter - 11) * 11) >= diffN) - Q_strcat(diffBar[1], "^3=^3"); + if ( ( ( _barCounter - 11) * 11 ) >= diffN ) + Q_strcat( diffBar[1], "^3=" ); else - Q_strcat(diffBar[1], "^4=^3"); + Q_strcat( diffBar[1], "^4=^3" ); } } } - Q_strcat(diffBar[0], va("] - %4d%%", (pNeg ? -diffP : diffP))); - Q_strcat(diffBar[1], va("] - %4d%%", (nNeg ? -diffN : diffN))); + Q_strcat( diffBar[0], va( "] - %4d%%", ( pNeg ? -diffP : diffP ) ) ); + Q_strcat( diffBar[1], va( "] - %4d%%", ( nNeg ? -diffN : diffN ) ) ); strobeInterval = r_strobe->integer; @@ -239,31 +235,34 @@ void SCR_DrawFPS( void ) "(-) Phase Frame Count:%u\n" \ " |-> Normal Frame Count: %u\n" \ " |-> Black Frame Count: %u\n" \ - "FrameInfo.isInverted: %d\n" \ - "^5ANALYSIS:\n^3" \ + "frame.isInverted: %d\n" \ + "^5=====ANALYSIS=====\n^3" \ "PWM Simulation:\n" \ - " |->Frequency: %4f Hz\n" \ - " |->Duty Cycle: %4f%%\n" \ - " |->Current Phase Shift: +%4f msec || -%4f msec\n" \ - " |->Period: %4f msec\n" \ + " |-> Frequency: %d Hz\n" \ + " |-> Duty Cycle: %.2f%%\n" \ + " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" \ + " |-> Period: %.4f msec\n" \ "Brightness Reduction:\n" \ " |-> [LINEAR] Actual Reduction: %3d%%\n" \ - " |-> [LOG] Realistic Reduction (400 cd/m2 base) : %3f%%\n" \ - " |-> [SQUARE] Realistic Reduction (400 cd/m2 base) : %3f%%\n" \ - " |-> [CUBE] Realistic Reduction (400 cd/m2 base) : %3f%%\n" \ + " |-> [LOG] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ + " |-> [SQUARE] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ + " |-> [CUBE] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ "Difference (+): %s\nDifference (-): %s\n" \ - "Geometric Mean: %f\n" \ - "G/A Difference: %f\n" \ - "^5Experimental Functions:\n^3" \ - "[*] Badness: %f\n" \ - "[*] Badness x PWM Period: %f" \ + "Geometric Mean: %.4f\n" \ + "G/A Difference: %.4f\n" \ + "[^7EXPERIMENTAL^3] Badness: %f\n" \ + "[^7EXPERIMENTAL^3] Badness x PWM Period: %f\n" \ + "Stability:\n" \ + " |-> Standard Deviation: %s\n" \ + " |-> Cooldown: %s\n" \ + "^5=====ANALYSIS=====\n^3" \ , curfps \ , eFPS \ , StrobeInfo.fCounter \ , StrobeInfo.pCounter, StrobeInfo.pNCounter, StrobeInfo.pBCounter \ , StrobeInfo.nCounter, StrobeInfo.nNCounter, StrobeInfo.nBCounter \ , !!(StrobeInfo.frameInfo & p_inverted) \ - , (1 / ((1.0f / curfps)*(abs(strobeInterval) + 1))) \ + , (int)round((1 / ((1.0f / curfps)*(abs(strobeInterval) + 1)))) \ , ((1.0f / (abs(strobeInterval) + 1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1) \ , !!(StrobeInfo.frameInfo & p_inverted) ? (1.0f / curfps) * 1000 : 0.0f \ , !!(StrobeInfo.frameInfo & p_inverted) ? abs(strobeInterval) * (1.0f / curfps) * 1000 : 0.0f \ @@ -276,7 +275,9 @@ void SCR_DrawFPS( void ) , sqrt(diffP * diffN) \ , (diffP + diffN) / 2 - sqrt(diffP * diffN) \ , STROBE_BADNESS(diffP, diffN) \ - , STROBE_BADNESS(diffP, diffN) * ((1.0f / curfps) * (abs(strobeInterval) + 1))); + , STROBE_BADNESS(diffP, diffN) * ((1.0f / curfps) * (abs(strobeInterval) + 1)) \ + , (StrobeInfo.deviation > STROBE_DEVIATION_LIMIT) ? (va("^1%.4f^3", StrobeInfo.deviation)) : (va("%.4f", StrobeInfo.deviation)) \ + , ((double)abs(r_strobe_cooldown->integer) - StrobeInfo.cdTimer <= (double)abs(r_strobe_cooldown->integer)) ? (va("^1%.4f secs\n[STROBING DISABLED]^3", (double)abs(r_strobe_cooldown->integer) - StrobeInfo.cdTimer)) : ("0") ); } else { @@ -288,12 +289,12 @@ void SCR_DrawFPS( void ) Con_DrawStringLen( fpsstring, &offset, NULL ); - if (strobeInterval == 0) - Con_DrawString(scr_width->integer - offset - 2, 4, fpsstring, color); - else if (strobeDebug) - Con_DrawString(scr_width->integer - offset - 75, 4, fpsstring, color); + if ( strobeInterval == 0 ) + Con_DrawString( scr_width->integer - offset - 2, 4, fpsstring, color ); + else if ( strobeDebug ) + Con_DrawString( scr_width->integer - offset - 50, 4, fpsstring, color ); else - Con_DrawString(scr_width->integer - offset - 5, 4, fpsstring, color); + Con_DrawString( scr_width->integer - offset - 5, 4, fpsstring, color ); } /* diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index 02045748e..c6641e12c 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -350,8 +350,7 @@ int R_CountSurfaceDlights( msurface_t *surf ); int R_CountDlights( void ); -/// // Move to different file? - +/// // Move to strobe.h ? //#define SolidConsoleX 0 //#define SolidConsoleY (y - scr_width->value * 3 / 4) //#define SolidConsoleW (scr_width->value) @@ -360,52 +359,59 @@ int R_CountDlights( void ); typedef struct _rectf_s { float x, y, w, h; -}_rectf_t; +} _rectf_t; extern _rectf_t con_rect; -void R_Strobe(void); +void R_Strobe( void ); typedef enum { p_positive = 1, // Phase: Positive p_inverted = 1 << 1, // Phase: Inverted f_normal = 1 << 2 // Frame: Normal -}fstate_e; // Frame State +} fstate_e; // Frame State typedef struct StrobeInfo_s { unsigned int fCounter; // Frame counter unsigned int pCounter, pNCounter, pBCounter; // Positive phase counters unsigned int nCounter, nNCounter, nBCounter; // Negative phase counters + double deviation; // Standard deviation + double cdTimer; // Cooldown timer fstate_e frameInfo; // Frame info -}StrobeInfo_t; +} StrobeInfo_t; extern StrobeInfo_t StrobeInfo; +#define STROBE_DEVIATION_LIMIT 2.75 +#define STROBE_DEVIATION_SIZE 60 + // Experimental 'Badness' function -#define STROBE_BADNESS(diffP, diffNs) \ +#define STROBE_BADNESS( diffP, diffNs ) \ -log(((abs(diffP-diffN)+sqrt((100-diffP)*(100-diffN)))/(abs(diffP-diffN)+sqrt(diffP*diffN)))) // Brightness reductions -#define _calculatePercentage(x, y) \ - (100 * y / x) +#define _calculatePercentage( x, y ) \ + ( 100 * y / x ) -#define actualBrightnessReduction(fps, efps) \ - ((fps - efps) * 100 / fps) +#define actualBrightnessReduction( fps, efps ) \ + ( ( fps - efps ) * 100 / fps ) -#define logBrightnessReduction(base, fps, efps) \ +#define logBrightnessReduction( base, fps, efps ) \ actualBrightnessReduction( log(base) , log(base * _calculatePercentage(fps,efps) / 100) ) /* #define log10BrightnessReduction(base, fps, efps) \ actualBrightnessReduction( log10(base) , log10(base * calculatePercentage(fps,efps) / 100) ) */ -#define squareBrightnessReduction(base, fps, efps) \ +#define squareBrightnessReduction( base, fps, efps ) \ actualBrightnessReduction( sqrt(base) , sqrt(base * _calculatePercentage(fps,efps) / 100) ) -#define cubicBrightnessReduction(base, fps, efps) \ +#define cubicBrightnessReduction( base, fps, efps ) \ actualBrightnessReduction( cbrt(base) , cbrt(base * _calculatePercentage(fps,efps) / 100) ) extern convar_t *r_strobe; extern convar_t *r_strobe_swapinterval; extern convar_t *r_strobe_debug; +extern convar_t *r_strobe_cooldown; + /// @@ -424,9 +430,6 @@ void R_SetupFrustum( void ); void R_FindViewLeaf( void ); void R_DrawFog( void ); - - - #define cmatrix3x4 vec4_t *const #define cmatrix4x4 vec4_t *const // @@ -762,6 +765,7 @@ extern convar_t *r_lightmap; extern convar_t *r_fastsky; extern convar_t *r_vbo; extern convar_t *r_bump; + extern convar_t *mp_decals; extern convar_t *vid_displayfrequency; diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 9e9accb71..852f68a0f 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1328,7 +1328,7 @@ void R_RenderFrame( const ref_params_t *fd, qboolean drawWorld ) GL_BackendEndFrame(); } -static inline void gl_GenerateBlackFrame( void ) // Generates partial or full black frame +_inline void GL_GenerateBlackFrame( void ) // Generates partial or full black frame { if ( CL_IsInConsole() ) // No strobing on the console { @@ -1345,61 +1345,122 @@ static inline void gl_GenerateBlackFrame( void ) // Generates partial or full bl } else { + //pglFlush(); // ? pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); pglClear( GL_COLOR_BUFFER_BIT ); } } - +_inline double standard_deviation(double data[], int n) // From the internet +{ + double mean = 0.0, sum_deviation = 0.0; + int i; + for (i = 0; i < n; ++i) + { + mean += data[i]; + } + mean = mean / n; + for (i = 0; i < n; ++i) + sum_deviation += (data[i] - mean)*(data[i] - mean); + return sqrt(sum_deviation / n); +} /* =============== R_Strobe TODO: - *Make swapping transition seamless by rendering non-opaque frames. - *Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) + * (?) Move "Strobe" to separate files. + * Make swapping transition seamless by rendering non-opaque frames. + * Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) * (?) Call R_Strobe each frame no matter strobe setting and simulate strobing to keep the phases on track (When on menu, ...) - * (?) Move "Strobe" to seperate files. =============== */ void R_Strobe( void ) { static int strobeInterval = 0; static int swapInterval = 0; - static double recentTime = 0; - double currentTime = 0; - double _delta = 0; + static double recentTime = 0.0, recentTime2 = 0.0; + double _delta = 0.0, _delta2 = 0.0; + static qboolean cdTriggered = false; + static double delta[STROBE_DEVIATION_SIZE] = { 0.0 }; + static unsigned int fCounterSnapshot = 0; + double currentTime = Sys_DoubleTime(); + + _delta2 = currentTime - recentTime2; + recentTime2 = currentTime; + + if (CL_IsInMenu()) + { + R_Set2DMode(false); + return; + } - if (((strobeInterval != r_strobe->integer) && (strobeInterval != 0)) || + if( StrobeInfo.cdTimer >= 0.0) + StrobeInfo.cdTimer += _delta2; + if (StrobeInfo.fCounter - fCounterSnapshot == 1) + { + delta[StrobeInfo.fCounter % ARRAYSIZE(delta)] = _delta2; + StrobeInfo.deviation = standard_deviation(delta, ARRAYSIZE(delta)) * 1000; + } + fCounterSnapshot = StrobeInfo.fCounter; + + + if (r_strobe_cooldown->integer > 0) + { + if (StrobeInfo.cdTimer > (double)abs(r_strobe_cooldown->integer) && cdTriggered == true) + { + cdTriggered = false; + StrobeInfo.cdTimer = -1.0; + } + + if (StrobeInfo.fCounter > ARRAYSIZE(delta)) + { + if (StrobeInfo.deviation > STROBE_DEVIATION_LIMIT) + { + cdTriggered = true; + StrobeInfo.cdTimer = 0.0; + } + } + } + else + { + cdTriggered = false; + } + + //Msg("Snapshot: %d - Deviation: %f - timer %f - delta %f\n\n", snapshot, standard_deviation(data, 10) * 1000, StrobeInfo.cdTimer, _delta2); + + if ( ((strobeInterval != r_strobe->integer) && (strobeInterval != 0) ) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - StrobeInfo.fCounter > 87091200) // Reset stats after some time + StrobeInfo.fCounter > UINT_MAX - 2U) // Reset stats after some time { StrobeInfo.pCounter = 0; StrobeInfo.pBCounter = 0; StrobeInfo.pNCounter = 0; StrobeInfo.nCounter = 0; StrobeInfo.nBCounter = 0; StrobeInfo.nNCounter = 0; StrobeInfo.fCounter = 0; + StrobeInfo.deviation = 0.0; + Q_memset(delta, 0, ARRAYSIZE(delta)); StrobeInfo.frameInfo &= ~p_inverted; } strobeInterval = r_strobe->integer; swapInterval = r_strobe_swapinterval->integer; - if ((strobeInterval == 0) || - ((gl_swapInterval->integer == 0) && (strobeInterval != 0))) + if ( (strobeInterval == 0) || + ((gl_swapInterval->integer == 0) && (strobeInterval != 0)) ) { - if (!gl_swapInterval->integer) - MsgDev(D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n"); + if ( !gl_swapInterval->integer ) + MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - if (strobeInterval != 0) // If v-sync is off, turn off strobing + if ( strobeInterval != 0 ) // If v-sync is off, turn off strobing { - Cvar_Set("r_strobe", "0"); + Cvar_Set( "r_strobe", "0" ); } StrobeInfo.fCounter = 0; - R_Set2DMode(false); + R_Set2DMode( false ); return; } - if ((StrobeInfo.fCounter % 2) == 0) + if ( ( StrobeInfo.fCounter % 2 ) == 0 ) { ++StrobeInfo.pCounter; StrobeInfo.frameInfo |= p_positive; @@ -1410,18 +1471,17 @@ void R_Strobe( void ) StrobeInfo.frameInfo &= ~p_positive; } - if (swapInterval < 0) - swapInterval = abs(swapInterval); + if ( swapInterval < 0 ) + swapInterval = abs( swapInterval ); - if ((swapInterval != 0) && (strobeInterval % 2 != 0)) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ( ( swapInterval != 0 ) && ( strobeInterval % 2 != 0 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { - currentTime = Sys_DoubleTime(); - _delta = currentTime - recentTime; - if ((_delta >= (double)(swapInterval)) && (_delta < (double)(2 * swapInterval))) // Basic timer + _delta = currentTime - recentTime; // New Currenttime for _delta ? + if ( (_delta >= (double)(swapInterval) ) && ( _delta < (double)(2 * swapInterval) ) ) // Basic timer { StrobeInfo.frameInfo |= p_inverted; } - else if (_delta < (double)(swapInterval)) + else if ( _delta < (double)(swapInterval) ) { StrobeInfo.frameInfo &= ~p_inverted; } @@ -1431,17 +1491,16 @@ void R_Strobe( void ) } } - - switch (StrobeInfo.frameInfo & (p_positive | p_inverted)) + switch ( StrobeInfo.frameInfo & (p_positive | p_inverted) ) { - case (p_positive | p_inverted): + case ( p_positive | p_inverted ): if ((abs(strobeInterval) % 2) == 0) StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even else StrobeInfo.frameInfo &= ~f_normal; break; - case(p_positive & ~p_inverted): + case( p_positive & ~p_inverted ): if (abs(strobeInterval) % 2 == 0) StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even else @@ -1453,7 +1512,7 @@ void R_Strobe( void ) } break; - case(~p_positive & p_inverted): + case( ~p_positive & p_inverted ): if (abs(strobeInterval) % 2 == 0) StrobeInfo.frameInfo = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even else @@ -1477,52 +1536,15 @@ void R_Strobe( void ) break; } - // Legacy code - Will be removed soon - /* - if (StrobeInfo.isPositive == true && StrobeInfo.isInverted == false) - { - if (abs(strobeInterval) % 2 == 0) - StrobeInfo.isNormal = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? true : false; //even - else - StrobeInfo.isNormal = (((StrobeInfo.pCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? true : false; //odd + if ( strobeInterval < 0 ) + StrobeInfo.frameInfo ^= f_normal; - if (abs(strobeInterval) == 1) - StrobeInfo.isNormal = true; - } - else if (StrobeInfo.isPositive == true && StrobeInfo.isInverted == true) - { - if ((abs(strobeInterval) % 2) == 0) - StrobeInfo.isNormal = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? true : false; //even - else - StrobeInfo.isNormal = false; - if (abs(strobeInterval) == 1) - StrobeInfo.isNormal = false; - } - else if (StrobeInfo.isPositive == false && StrobeInfo.isInverted == false) + if ( cdTriggered != false ) { - if ((abs(strobeInterval) % 2) == 0) - StrobeInfo.isNormal = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? true : false; //even - else - StrobeInfo.isNormal = false; - if (abs(strobeInterval) == 1) - StrobeInfo.isNormal = false; + StrobeInfo.frameInfo = f_normal | (StrobeInfo.frameInfo & p_positive); } - else if (StrobeInfo.isPositive == false && StrobeInfo.isInverted == true) - { - if (abs(strobeInterval) % 2 == 0) - StrobeInfo.isNormal = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? true : false; //even - else - StrobeInfo.isNormal = (((StrobeInfo.nCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? true : false; //odd - if (abs(strobeInterval) == 1) - StrobeInfo.isNormal = true; - } - */ - - if (strobeInterval < 0) - StrobeInfo.frameInfo ^= f_normal; - - if (StrobeInfo.frameInfo & f_normal) // Show normal + if ( StrobeInfo.frameInfo & f_normal ) // Show normal { if (StrobeInfo.frameInfo & p_positive) ++StrobeInfo.pNCounter; @@ -1538,7 +1560,7 @@ void R_Strobe( void ) else ++StrobeInfo.nBCounter; - gl_GenerateBlackFrame(); + GL_GenerateBlackFrame(); } ++StrobeInfo.fCounter; @@ -1552,10 +1574,7 @@ R_EndFrame */ void R_EndFrame( void ) { - if (CL_IsInMenu()) - R_Set2DMode(false); - else - R_Strobe(); + R_Strobe(); #ifdef XASH_SDL SDL_GL_SwapWindow( host.hWnd ); diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index 1db6895da..c6ffc7a08 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -78,9 +78,11 @@ convar_t *r_lightmap; convar_t *r_fastsky; convar_t *r_vbo; convar_t *r_bump; + convar_t *r_strobe; convar_t *r_strobe_swapinterval; convar_t *r_strobe_debug; +convar_t *r_strobe_cooldown; convar_t *mp_decals; @@ -1016,15 +1018,18 @@ R_initStrobe register strobe cvar =============== */ -static inline void R_initStrobe( void ) +_inline void R_StrobeInit( void ) { - r_strobe = Cvar_Get("r_strobe", "0", CVAR_ARCHIVE, "black frame replacement interval"); - r_strobe_swapinterval = Cvar_Get("r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval"); - r_strobe_debug = Cvar_Get("r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information"); + r_strobe = Cvar_Get( "r_strobe", "0", CVAR_ARCHIVE, "black frame replacement interval" ); + r_strobe_swapinterval = Cvar_Get( "r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval" ); + r_strobe_debug = Cvar_Get( "r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information" ); + r_strobe_cooldown = Cvar_Get( "r_strobe_cooldown", "3", CVAR_ARCHIVE, "strobe cooldown perios in secs" ); StrobeInfo.pCounter = 0; StrobeInfo.pBCounter = 0; StrobeInfo.pNCounter = 0; StrobeInfo.pCounter = 0; StrobeInfo.nBCounter = 0; StrobeInfo.nNCounter = 0; StrobeInfo.fCounter = 0; + StrobeInfo.deviation = 0.0; + StrobeInfo.cdTimer = 0.0; StrobeInfo.frameInfo = (p_positive | f_normal); } @@ -1068,11 +1073,10 @@ qboolean R_Init( void ) R_InitImages(); R_SpriteInit(); R_StudioInit(); + R_StrobeInit(); R_ClearDecals(); R_ClearScene(); - r_strobe = Cvar_Get("r_strobe", "0", CVAR_ARCHIVE, "black frame insertion interval"); - // initialize screen SCR_Init(); From b2fe83e9336d923f58ef9e00d0c289eebdd19105 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 4 Mar 2018 01:02:14 +0300 Subject: [PATCH 11/35] Complete refactor due to OOP implementation --- common/wrect.h | 7 +- engine/Android.mk | 2 + engine/client/cl_scrn.c | 226 +----- engine/client/cl_view.c | 10 + engine/client/console.c | 2 +- engine/client/gl_local.h | 66 -- engine/client/gl_rmain.c | 251 +------ engine/client/strobe/r_strobe_api.c | 655 ++++++++++++++++++ engine/client/strobe/r_strobe_api.h | 112 +++ .../client/strobe/r_strobe_base_protected_.h | 44 ++ engine/client/strobe/r_strobe_core.c | 331 +++++++++ engine/client/strobe/r_strobe_core.h | 63 ++ .../strobe/r_strobe_template.c.TEMPLATE | 111 +++ .../strobe/r_strobe_template.h.TEMPLATE | 64 ++ engine/client/vid_common.c | 35 +- engine/common/common.h | 4 +- 16 files changed, 1445 insertions(+), 538 deletions(-) create mode 100644 engine/client/strobe/r_strobe_api.c create mode 100644 engine/client/strobe/r_strobe_api.h create mode 100644 engine/client/strobe/r_strobe_base_protected_.h create mode 100644 engine/client/strobe/r_strobe_core.c create mode 100644 engine/client/strobe/r_strobe_core.h create mode 100644 engine/client/strobe/r_strobe_template.c.TEMPLATE create mode 100644 engine/client/strobe/r_strobe_template.h.TEMPLATE diff --git a/common/wrect.h b/common/wrect.h index 8dd2ba2f1..48d6182ad 100644 --- a/common/wrect.h +++ b/common/wrect.h @@ -21,4 +21,9 @@ typedef struct wrect_s int left, right, top, bottom; } wrect_t; -#endif//WRECT_H \ No newline at end of file +typedef struct rectf_s +{ + float x, y, w, h; +} rectf_t; + +#endif //WRECT_H \ No newline at end of file diff --git a/engine/Android.mk b/engine/Android.mk index 62bf69f52..6fe1ff7d9 100644 --- a/engine/Android.mk +++ b/engine/Android.mk @@ -91,6 +91,8 @@ LOCAL_SRC_FILES := \ client/s_stream.c \ client/s_utils.c \ client/s_vox.c \ + client/strobe/r_strobe_api.c \ + client/strobe/r_strobe_core.c \ common/avikit.c \ common/build.c \ common/base_cmd.c \ diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index d61563ed0..d8ede2c9d 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -22,6 +22,8 @@ GNU General Public License for more details. #include "qfont.h" #include "library.h" +#include "strobe/r_strobe_core.h" + convar_t *scr_centertime; convar_t *scr_loading; convar_t *scr_download; @@ -47,7 +49,7 @@ static qboolean scr_init = false; SCR_DrawFPS ============== */ -void SCR_DrawFPS( void ) +void SCR_DrawFPS(void) { float calc; rgba_t color; @@ -57,24 +59,13 @@ void SCR_DrawFPS( void ) static int minfps = 9999; static int maxfps = 0; double newtime; - char fpsstring[2048]; //char fpsstring[64]; // Heap allocation if 2048 too much ? + char fpsstring[64]; int offset; - int curfps; - - char diffBar[2][128]; - char _barCounter = 0; - int diffP_NB = (StrobeInfo.pNCounter - StrobeInfo.pBCounter); - int diffN_NB = (StrobeInfo.nNCounter - StrobeInfo.nBCounter); - int diffP = 0, diffN = 0; - qboolean pNeg = false, nNeg = false; - int strobeInterval = r_strobe->integer; - int eFPS; // Effective FPS (strobing effect) - qboolean strobeDebug = !!r_strobe_debug->integer ? true : false; - if( cls.state != ca_active ) return; - if( (!cl_showfps->integer && !strobeDebug) || cl.background ) return; + if (cls.state != ca_active) return; + if (!cl_showfps->integer || cl.background) return; - switch( cls.scrshot_action ) + switch (cls.scrshot_action) { case scrshot_normal: case scrshot_snapshot: @@ -82,219 +73,54 @@ void SCR_DrawFPS( void ) break; default: return; } - + newtime = Sys_DoubleTime(); - if( newtime >= nexttime ) + if (newtime >= nexttime) { framerate = framecount / (newtime - lasttime); lasttime = newtime; - nexttime = max( nexttime + 1, lasttime - 1 ); + nexttime = max(nexttime + 1, lasttime - 1); framecount = 0; } framecount++; calc = framerate; - if( calc == 0 ) return; + if (calc == 0) return; - if( calc < 1.0f ) + if (calc < 1.0f) { - Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i spf", (int)(1.0f / calc + 0.5f) ); - MakeRGBA( color, 255, 0, 0, 255 ); + Q_snprintf(fpsstring, sizeof(fpsstring), "%4i spf", (int)(1.0f / calc + 0.5f)); + MakeRGBA(color, 255, 0, 0, 255); } else { - curfps = (int)(calc + 0.5f); + int curfps = (int)(calc + 0.5f); - if( curfps < minfps ) minfps = curfps; - if( curfps > maxfps ) maxfps = curfps; + if (curfps < minfps) minfps = curfps; + if (curfps > maxfps) maxfps = curfps; /*if( !avgrate ) avgrate = ( maxfps - minfps ) / 2.0f; - else */avgrate += ( calc - avgrate ) / host.framecount; + else */avgrate += (calc - avgrate) / host.framecount; - if( strobeInterval > 0 ) - { - eFPS = ( curfps ) / ( strobeInterval + 1 ); - } - else if( strobeInterval < 0 ) - { - strobeInterval = abs( strobeInterval ); - eFPS = ( curfps * strobeInterval ) / ( strobeInterval + 1 ); - } - - switch( cl_showfps->integer ) + switch (cl_showfps->integer) { case 3: - Q_snprintf( fpsstring, sizeof( fpsstring ), "fps: ^1%4i min, ^3%4i cur, ^2%4i max | ^3%.2f avg", minfps, curfps, maxfps, avgrate ); + Q_snprintf(fpsstring, sizeof(fpsstring), "fps: ^1%4i min, ^3%4i cur, ^2%4i max | ^3%.2f avg", minfps, curfps, maxfps, avgrate); break; case 2: - Q_snprintf( fpsstring, sizeof( fpsstring ), "fps: ^1%4i min, ^3%4i cur, ^2%4i max", minfps, curfps, maxfps ); + Q_snprintf(fpsstring, sizeof(fpsstring), "fps: ^1%4i min, ^3%4i cur, ^2%4i max", minfps, curfps, maxfps); break; case 1: default: - - if ( strobeInterval == 0 ) - { - Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i fps", curfps ); - } - else if ( strobeDebug ) - { - Q_snprintf( diffBar[0], sizeof( diffBar[0] ), "^3[" ); - Q_snprintf( diffBar[1], sizeof( diffBar[1] ), "^3[" ); - - if ( diffP_NB < 0 ) - { - pNeg = true; - diffP_NB = abs( diffP_NB ); - } - - if ( diffN_NB < 0 ) - { - nNeg = true; - diffN_NB = abs( diffN_NB ); - } - - if ( StrobeInfo.pCounter != 0 ) - diffP = round( diffP_NB * 100 / StrobeInfo.pCounter ); - - if ( StrobeInfo.nCounter != 0 ) - diffN = round( diffN_NB * 100 / StrobeInfo.nCounter ); - - for ( _barCounter = 0; _barCounter <= 20; ++_barCounter ) - { - if ( _barCounter == 10 ) - { - Q_strcat( diffBar[0], "O" ); - Q_strcat( diffBar[1], "O" ); - } - else if ( _barCounter < 10 ) - { - if ( pNeg ) - { - if ( 100 - ( _barCounter * 11 ) <= diffP ) - Q_strcat( diffBar[0], "^4=^3" ); - else - Q_strcat( diffBar[0], "^3=" ); - } - else - { - Q_strcat( diffBar[0], "^3=" ); - } - - if ( nNeg ) - { - if ( 100 - ( _barCounter * 11 ) <= diffN ) - Q_strcat( diffBar[1], "^4=^3" ); - else - Q_strcat( diffBar[1], "^3=" ); - } - else - { - Q_strcat( diffBar[1], "^3=" ); - } - } - else if ( _barCounter > 10 ) - { - if ( pNeg ) - { - Q_strcat( diffBar[0], "^3=" ); - } - else - { - if ( ( ( _barCounter - 11 ) * 11 ) >= diffP ) - Q_strcat( diffBar[0], "^3=" ); - else - Q_strcat( diffBar[0], "^4=^3" ); - } - - if ( nNeg ) - { - Q_strcat( diffBar[1], "^3=" ); - } - else - { - if ( ( ( _barCounter - 11) * 11 ) >= diffN ) - Q_strcat( diffBar[1], "^3=" ); - else - Q_strcat( diffBar[1], "^4=^3" ); - } - } - } - Q_strcat( diffBar[0], va( "] - %4d%%", ( pNeg ? -diffP : diffP ) ) ); - Q_strcat( diffBar[1], va( "] - %4d%%", ( nNeg ? -diffN : diffN ) ) ); - - strobeInterval = r_strobe->integer; - - Q_snprintf(fpsstring, - sizeof(fpsstring), - "%4i FPS\n%3i eFPS\n" \ - "Total Frame Count: %u\n" \ - "(+) Phase Frame Count: %u\n" \ - " |-> Normal Frame Count: %u\n" \ - " |-> Black Frame Count: %u\n" \ - "(-) Phase Frame Count:%u\n" \ - " |-> Normal Frame Count: %u\n" \ - " |-> Black Frame Count: %u\n" \ - "frame.isInverted: %d\n" \ - "^5=====ANALYSIS=====\n^3" \ - "PWM Simulation:\n" \ - " |-> Frequency: %d Hz\n" \ - " |-> Duty Cycle: %.2f%%\n" \ - " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" \ - " |-> Period: %.4f msec\n" \ - "Brightness Reduction:\n" \ - " |-> [LINEAR] Actual Reduction: %3d%%\n" \ - " |-> [LOG] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ - " |-> [SQUARE] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ - " |-> [CUBE] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ - "Difference (+): %s\nDifference (-): %s\n" \ - "Geometric Mean: %.4f\n" \ - "G/A Difference: %.4f\n" \ - "[^7EXPERIMENTAL^3] Badness: %f\n" \ - "[^7EXPERIMENTAL^3] Badness x PWM Period: %f\n" \ - "Stability:\n" \ - " |-> Standard Deviation: %s\n" \ - " |-> Cooldown: %s\n" \ - "^5=====ANALYSIS=====\n^3" \ - , curfps \ - , eFPS \ - , StrobeInfo.fCounter \ - , StrobeInfo.pCounter, StrobeInfo.pNCounter, StrobeInfo.pBCounter \ - , StrobeInfo.nCounter, StrobeInfo.nNCounter, StrobeInfo.nBCounter \ - , !!(StrobeInfo.frameInfo & p_inverted) \ - , (int)round((1 / ((1.0f / curfps)*(abs(strobeInterval) + 1)))) \ - , ((1.0f / (abs(strobeInterval) + 1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1) \ - , !!(StrobeInfo.frameInfo & p_inverted) ? (1.0f / curfps) * 1000 : 0.0f \ - , !!(StrobeInfo.frameInfo & p_inverted) ? abs(strobeInterval) * (1.0f / curfps) * 1000 : 0.0f \ - , (((1.0f / curfps)*(abs(strobeInterval) + 1)) * 1000) \ - , actualBrightnessReduction(curfps, eFPS) \ - , logBrightnessReduction(400, curfps, eFPS) \ - , squareBrightnessReduction(400, curfps, eFPS) \ - , cubicBrightnessReduction(400, curfps, eFPS) \ - , diffBar[0], diffBar[1] \ - , sqrt(diffP * diffN) \ - , (diffP + diffN) / 2 - sqrt(diffP * diffN) \ - , STROBE_BADNESS(diffP, diffN) \ - , STROBE_BADNESS(diffP, diffN) * ((1.0f / curfps) * (abs(strobeInterval) + 1)) \ - , (StrobeInfo.deviation > STROBE_DEVIATION_LIMIT) ? (va("^1%.4f^3", StrobeInfo.deviation)) : (va("%.4f", StrobeInfo.deviation)) \ - , ((double)abs(r_strobe_cooldown->integer) - StrobeInfo.cdTimer <= (double)abs(r_strobe_cooldown->integer)) ? (va("^1%.4f secs\n[STROBING DISABLED]^3", (double)abs(r_strobe_cooldown->integer) - StrobeInfo.cdTimer)) : ("0") ); - } - else - { - Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i FPS\n%3i eFPS", curfps, eFPS ); - } + Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); } - MakeRGBA( color, 255, 255, 255, 255 ); + + MakeRGBA(color, 255, 255, 255, 255); } - Con_DrawStringLen( fpsstring, &offset, NULL ); - - if ( strobeInterval == 0 ) - Con_DrawString( scr_width->integer - offset - 2, 4, fpsstring, color ); - else if ( strobeDebug ) - Con_DrawString( scr_width->integer - offset - 50, 4, fpsstring, color ); - else - Con_DrawString( scr_width->integer - offset - 5, 4, fpsstring, color ); + Con_DrawStringLen(fpsstring, &offset, NULL); + Con_DrawString(scr_width->integer - offset - 2, 4, fpsstring, color); } /* diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index 6e15b32aa..b76a59311 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -21,9 +21,13 @@ GNU General Public License for more details. #include "entity_types.h" #include "gl_local.h" #include "vgui_draw.h" + +#include "strobe/r_strobe_core.h" + #include "touch.h" // IN_TouchDraw( ) #include "joyinput.h" // Joy_DrawOnScreenKeyboard( ) + /* =============== V_SetupRefDef @@ -417,6 +421,12 @@ void V_PostRender( void ) SCR_RSpeeds(); SCR_NetSpeeds(); SCR_DrawFPS(); + +#ifdef STROBE_ENABLED + if (STROBE_CORE) + STROBE_CORE->STROBE_CORE_FUNC_debughandler(&STROBE_CORE); +#endif + SCR_DrawPos(); SCR_DrawNetGraph(); SV_DrawOrthoTriangles(); diff --git a/engine/client/console.c b/engine/client/console.c index ea3fd0002..2c4202d6e 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -33,7 +33,7 @@ convar_t *con_fontscale; convar_t *con_fontnum; convar_t *vgui_utf8; -_rectf_t con_rect; +rectf_t con_rect; static int g_codepage = 0; static qboolean g_utf8 = false; diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index c6641e12c..a235e520a 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -349,72 +349,6 @@ void R_LightForPoint( const vec3_t point, color24 *ambientLight, qboolean invLig int R_CountSurfaceDlights( msurface_t *surf ); int R_CountDlights( void ); - -/// // Move to strobe.h ? -//#define SolidConsoleX 0 -//#define SolidConsoleY (y - scr_width->value * 3 / 4) -//#define SolidConsoleW (scr_width->value) -//#define SolidConsoleH (scr_width->value * 3 / 4) -//extern wrect_t con_rect; //Float - Int incompatibility -typedef struct _rectf_s -{ - float x, y, w, h; -} _rectf_t; -extern _rectf_t con_rect; - -void R_Strobe( void ); - -typedef enum { - p_positive = 1, // Phase: Positive - p_inverted = 1 << 1, // Phase: Inverted - f_normal = 1 << 2 // Frame: Normal -} fstate_e; // Frame State - -typedef struct StrobeInfo_s { - unsigned int fCounter; // Frame counter - unsigned int pCounter, pNCounter, pBCounter; // Positive phase counters - unsigned int nCounter, nNCounter, nBCounter; // Negative phase counters - double deviation; // Standard deviation - double cdTimer; // Cooldown timer - fstate_e frameInfo; // Frame info -} StrobeInfo_t; - -extern StrobeInfo_t StrobeInfo; - -#define STROBE_DEVIATION_LIMIT 2.75 -#define STROBE_DEVIATION_SIZE 60 - -// Experimental 'Badness' function -#define STROBE_BADNESS( diffP, diffNs ) \ - -log(((abs(diffP-diffN)+sqrt((100-diffP)*(100-diffN)))/(abs(diffP-diffN)+sqrt(diffP*diffN)))) - -// Brightness reductions -#define _calculatePercentage( x, y ) \ - ( 100 * y / x ) - -#define actualBrightnessReduction( fps, efps ) \ - ( ( fps - efps ) * 100 / fps ) - -#define logBrightnessReduction( base, fps, efps ) \ - actualBrightnessReduction( log(base) , log(base * _calculatePercentage(fps,efps) / 100) ) - -/* #define log10BrightnessReduction(base, fps, efps) \ - actualBrightnessReduction( log10(base) , log10(base * calculatePercentage(fps,efps) / 100) ) */ - -#define squareBrightnessReduction( base, fps, efps ) \ - actualBrightnessReduction( sqrt(base) , sqrt(base * _calculatePercentage(fps,efps) / 100) ) - -#define cubicBrightnessReduction( base, fps, efps ) \ - actualBrightnessReduction( cbrt(base) , cbrt(base * _calculatePercentage(fps,efps) / 100) ) - -extern convar_t *r_strobe; -extern convar_t *r_strobe_swapinterval; -extern convar_t *r_strobe_debug; -extern convar_t *r_strobe_cooldown; - -/// - - // // gl_rmain.c // diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 852f68a0f..15daf43df 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -24,6 +24,8 @@ GNU General Public License for more details. #include "particledef.h" #include "entity_types.h" +#include "strobe/r_strobe_core.h" + #define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA ) msurface_t *r_debug_surface; @@ -35,8 +37,6 @@ ref_instance_t RI, prevRI; mleaf_t *r_viewleaf, *r_oldviewleaf; mleaf_t *r_viewleaf2, *r_oldviewleaf2; -StrobeInfo_t StrobeInfo; - static int R_RankForRenderMode( cl_entity_t *ent ) { switch( ent->curstate.rendermode ) @@ -1328,245 +1328,6 @@ void R_RenderFrame( const ref_params_t *fd, qboolean drawWorld ) GL_BackendEndFrame(); } -_inline void GL_GenerateBlackFrame( void ) // Generates partial or full black frame -{ - if ( CL_IsInConsole() ) // No strobing on the console - { - if (!vid_fullscreen->integer) // Disable when not fullscreen due to viewport problems - { - R_Set2DMode(false); - return; - } - pglEnable( GL_SCISSOR_TEST ); - pglScissor( con_rect.x, (-con_rect.y) - (con_rect.h * 1.25), con_rect.w, con_rect.h ); // Preview strobe setting on static - pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); - pglClear( GL_COLOR_BUFFER_BIT ); - pglDisable( GL_SCISSOR_TEST ); - } - else - { - //pglFlush(); // ? - pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); - pglClear( GL_COLOR_BUFFER_BIT ); - } -} - -_inline double standard_deviation(double data[], int n) // From the internet -{ - double mean = 0.0, sum_deviation = 0.0; - int i; - for (i = 0; i < n; ++i) - { - mean += data[i]; - } - mean = mean / n; - for (i = 0; i < n; ++i) - sum_deviation += (data[i] - mean)*(data[i] - mean); - return sqrt(sum_deviation / n); -} - -/* -=============== -R_Strobe - -TODO: - * (?) Move "Strobe" to separate files. - * Make swapping transition seamless by rendering non-opaque frames. - * Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) - * (?) Call R_Strobe each frame no matter strobe setting and simulate strobing to keep the phases on track (When on menu, ...) -=============== -*/ -void R_Strobe( void ) -{ - static int strobeInterval = 0; - static int swapInterval = 0; - static double recentTime = 0.0, recentTime2 = 0.0; - double _delta = 0.0, _delta2 = 0.0; - static qboolean cdTriggered = false; - static double delta[STROBE_DEVIATION_SIZE] = { 0.0 }; - static unsigned int fCounterSnapshot = 0; - double currentTime = Sys_DoubleTime(); - - _delta2 = currentTime - recentTime2; - recentTime2 = currentTime; - - if (CL_IsInMenu()) - { - R_Set2DMode(false); - return; - } - - if( StrobeInfo.cdTimer >= 0.0) - StrobeInfo.cdTimer += _delta2; - if (StrobeInfo.fCounter - fCounterSnapshot == 1) - { - delta[StrobeInfo.fCounter % ARRAYSIZE(delta)] = _delta2; - StrobeInfo.deviation = standard_deviation(delta, ARRAYSIZE(delta)) * 1000; - } - fCounterSnapshot = StrobeInfo.fCounter; - - - if (r_strobe_cooldown->integer > 0) - { - if (StrobeInfo.cdTimer > (double)abs(r_strobe_cooldown->integer) && cdTriggered == true) - { - cdTriggered = false; - StrobeInfo.cdTimer = -1.0; - } - - if (StrobeInfo.fCounter > ARRAYSIZE(delta)) - { - if (StrobeInfo.deviation > STROBE_DEVIATION_LIMIT) - { - cdTriggered = true; - StrobeInfo.cdTimer = 0.0; - } - } - } - else - { - cdTriggered = false; - } - - //Msg("Snapshot: %d - Deviation: %f - timer %f - delta %f\n\n", snapshot, standard_deviation(data, 10) * 1000, StrobeInfo.cdTimer, _delta2); - - if ( ((strobeInterval != r_strobe->integer) && (strobeInterval != 0) ) || - /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - StrobeInfo.fCounter > UINT_MAX - 2U) // Reset stats after some time - { - StrobeInfo.pCounter = 0; StrobeInfo.pBCounter = 0; StrobeInfo.pNCounter = 0; - StrobeInfo.nCounter = 0; StrobeInfo.nBCounter = 0; StrobeInfo.nNCounter = 0; - StrobeInfo.fCounter = 0; - StrobeInfo.deviation = 0.0; - Q_memset(delta, 0, ARRAYSIZE(delta)); - StrobeInfo.frameInfo &= ~p_inverted; - } - strobeInterval = r_strobe->integer; - swapInterval = r_strobe_swapinterval->integer; - - if ( (strobeInterval == 0) || - ((gl_swapInterval->integer == 0) && (strobeInterval != 0)) ) - { - if ( !gl_swapInterval->integer ) - MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - - if ( strobeInterval != 0 ) // If v-sync is off, turn off strobing - { - Cvar_Set( "r_strobe", "0" ); - } - StrobeInfo.fCounter = 0; - - R_Set2DMode( false ); - return; - } - - if ( ( StrobeInfo.fCounter % 2 ) == 0 ) - { - ++StrobeInfo.pCounter; - StrobeInfo.frameInfo |= p_positive; - } - else - { - ++StrobeInfo.nCounter; - StrobeInfo.frameInfo &= ~p_positive; - } - - if ( swapInterval < 0 ) - swapInterval = abs( swapInterval ); - - if ( ( swapInterval != 0 ) && ( strobeInterval % 2 != 0 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended - { - _delta = currentTime - recentTime; // New Currenttime for _delta ? - if ( (_delta >= (double)(swapInterval) ) && ( _delta < (double)(2 * swapInterval) ) ) // Basic timer - { - StrobeInfo.frameInfo |= p_inverted; - } - else if ( _delta < (double)(swapInterval) ) - { - StrobeInfo.frameInfo &= ~p_inverted; - } - else //if (_delta >= (double)(2 * swapInterval)) - { - recentTime = currentTime; - } - } - - switch ( StrobeInfo.frameInfo & (p_positive | p_inverted) ) - { - case ( p_positive | p_inverted ): - if ((abs(strobeInterval) % 2) == 0) - StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even - else - StrobeInfo.frameInfo &= ~f_normal; - break; - - case( p_positive & ~p_inverted ): - if (abs(strobeInterval) % 2 == 0) - StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even - else - { - if (abs(strobeInterval) == 1) - StrobeInfo.frameInfo |= f_normal; - else - StrobeInfo.frameInfo = (((StrobeInfo.pCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //odd - } - break; - - case( ~p_positive & p_inverted ): - if (abs(strobeInterval) % 2 == 0) - StrobeInfo.frameInfo = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even - else - { - if (abs(strobeInterval) == 1) - StrobeInfo.frameInfo |= f_normal; - else - StrobeInfo.frameInfo = (((StrobeInfo.nCounter - 1) % ((abs(strobeInterval) + 1) / 2)) == 0) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //odd - } - break; - - case 0: - if ((abs(strobeInterval) % 2) == 0) - StrobeInfo.frameInfo = (((StrobeInfo.nCounter - 1) % (abs(strobeInterval) + 1)) == (abs(strobeInterval) / 2)) ? StrobeInfo.frameInfo | f_normal : StrobeInfo.frameInfo & ~f_normal; //even - else - StrobeInfo.frameInfo &= ~f_normal; - break; - - default: - StrobeInfo.frameInfo = (p_positive | f_normal); - break; - } - - if ( strobeInterval < 0 ) - StrobeInfo.frameInfo ^= f_normal; - - if ( cdTriggered != false ) - { - StrobeInfo.frameInfo = f_normal | (StrobeInfo.frameInfo & p_positive); - } - - if ( StrobeInfo.frameInfo & f_normal ) // Show normal - { - if (StrobeInfo.frameInfo & p_positive) - ++StrobeInfo.pNCounter; - else - ++StrobeInfo.nNCounter; - - R_Set2DMode(false); - } - else // Show black - { - if (StrobeInfo.frameInfo & p_positive) - ++StrobeInfo.pBCounter; - else - ++StrobeInfo.nBCounter; - - GL_GenerateBlackFrame(); - } - - ++StrobeInfo.fCounter; -} - - /* =============== R_EndFrame @@ -1574,7 +1335,13 @@ R_EndFrame */ void R_EndFrame( void ) { - R_Strobe(); +#ifdef STROBE_ENABLED + Strobe_Invoker((void**)(&STROBE_CORE), STROBE_CORE_EXPORTEDFUNC_constructor, STROBE_CORE_EXPORTEDFUNC_main, STROBE_CORE_EXPORTEDFUNC_destructor); +#else + // flush any remaining 2D bits + R_Set2DMode(false); +#endif + #ifdef XASH_SDL SDL_GL_SwapWindow( host.hWnd ); diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c new file mode 100644 index 000000000..834bdd6e7 --- /dev/null +++ b/engine/client/strobe/r_strobe_api.c @@ -0,0 +1,655 @@ +/* +r_strobe.c - Software based strobing implementation + +Copyright (C) 2018 * fuzun + +For information: + https://forums.blurbusters.com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. +*/ + +#if !defined XASH_DEDICATED && !defined STROBE_DISABLED + +#include +#include +#include "r_strobe_api.h" +#include "r_strobe_base_protected_.h" +#include "gl_local.h" +#include "client.h" + + +#define lossCalculator(x, y) (((x) - (y)) * 100.0 / (x)) // x : supposed y : current + +convar_t *r_strobe; +convar_t *r_strobe_swapinterval; +convar_t *r_strobe_debug; +convar_t *r_strobe_cooldown; + +static inline double func_helper_StandardDeviation(const double *data, int n) +{ + double mean = 0.0, sum_deviation = 0.0; + int i; + for (i = 0; i < n; ++i) + { + mean += data[i]; + } + mean = mean / n; + for (i = 0; i < n; ++i) + sum_deviation += (data[i] - mean)*(data[i] - mean); + return sqrt(sum_deviation / n); +} + + +static inline void GL_GenerateBlackFrame(void) // Generates partial or full black frame +{ + if (CL_IsInConsole()) // No strobing on the console + { + if (!vid_fullscreen->integer) // Disable when not fullscreen due to viewport problems + { + R_Set2DMode(false); + return; + } + pglEnable(GL_SCISSOR_TEST); + pglScissor(con_rect.x, (-con_rect.y) - (con_rect.h * 1.25), con_rect.w, con_rect.h); // Preview strobe setting on static + pglClearColor(0.0f, 0.0f, 0.0f, 1.0f); + pglClear(GL_COLOR_BUFFER_BIT); + pglDisable(GL_SCISSOR_TEST); + } + else + { + //pglFlush(); // ? + pglClearColor(0.0f, 0.0f, 0.0f, 1.0f); + pglClear(GL_COLOR_BUFFER_BIT); + } +} + +static inline double func_helper_getCooldown(StrobeAPI_t *self) +{ + if ((double)abs(r_strobe_cooldown->integer) - self->protected->cdTimer <= (double)abs(r_strobe_cooldown->integer)) + { + return ((double)abs(r_strobe_cooldown->integer) - self->protected->cdTimer); + } + else + { + return 0.0; + } +} + +static inline qboolean func_helper_isPhaseInverted(StrobeAPI_t *self) +{ + if (!!(self->protected->frameInfo & p_inverted)) + return true; + else + return false; +} + +static inline qboolean func_helper_isNormal(StrobeAPI_t *self) +{ + if (!!(self->protected->frameInfo & f_normal)) + return true; + else + return false; +} + +static inline qboolean func_helper_isPositive(StrobeAPI_t *self) // ... +{ + if (!!(self->protected->frameInfo & p_positive)) + return true; + else + return false; +} + +static inline double func_helper_effectiveFPS(StrobeAPI_t *self) +{ + int strobeInterval = r_strobe->integer; + double eFPS; + if (strobeInterval > 0) + { + eFPS = (self->get.CurrentFPS(self)) / (strobeInterval + 1); + } + else if (strobeInterval < 0) + { + strobeInterval = abs(strobeInterval); + eFPS = (self->get.CurrentFPS(self) * strobeInterval) / (strobeInterval + 1); + } + else + eFPS = 0.0; + return eFPS; +} + +static inline void func_helper_GenerateDiffBar(StrobeAPI_t *self, char *src, int size, char type) +{ + char _barCounter = 0; + int diff_NB = 0; + int diff = 0; + qboolean Neg = false; + + switch (type) + { + case(0): // Positive Difference + { + diff_NB = (self->protected->pNCounter - self->protected->pBCounter); + + if (self->protected->pCounter != 0) + diff = round(abs(diff_NB) * 100 / self->protected->pCounter); + + break; + } + case(1): // Negative Difference + { + diff_NB = (self->protected->nNCounter - self->protected->nBCounter); + + if (self->protected->nCounter != 0) + diff = round(abs(diff_NB) * 100 / self->protected->nCounter); + + break; + } + case(2): // Difference of difference + { + if (self->protected->nCounter != 0 && self->protected->pCounter != 0) + { + // FIX THE MESS! + int a = (abs(self->protected->pNCounter - self->protected->pBCounter) * 100 / self->protected->pCounter); + int b = (abs(self->protected->nNCounter - self->protected->nBCounter) * 100 / self->protected->nCounter); + int x = ((int)(self->protected->pNCounter - self->protected->pBCounter) > 0); + int y = ((int)(self->protected->nNCounter - self->protected->nBCounter) > 0); + diff = abs((x ? a : (-a)) \ + - ((y ? b : (-b)))); // Min 0 Max 200 + } + break; + } + default: + break; + } + + if (diff_NB < 0) + Neg = true; + + Q_snprintf(src, size, "^3["); + + for (_barCounter = 0; _barCounter <= 20; ++_barCounter) + { + if (_barCounter == 10) + { + Q_strcat(src, "O"); + } + else if (_barCounter < 10) + { + if (type == 2) + { + if (100 - (_barCounter * 11) <= diff / 2) + Q_strcat(src, "^4=^3"); + else + Q_strcat(src, "^3="); + } + else + { + if (Neg) + { + if (100 - (_barCounter * 11) <= diff) + Q_strcat(src, "^4=^3"); + else + Q_strcat(src, "^3="); + } + else + { + Q_strcat(src, "^3="); + } + } + } + else if (_barCounter > 10) + { + if (type == 2) + { + if (((_barCounter - 11) * 11) >= diff / 2) + Q_strcat(src, "^3="); + else + Q_strcat(src, "^4=^3"); + } + else + { + if (Neg) + { + Q_strcat(src, "^3="); + } + else + { + if (((_barCounter - 11) * 11) >= diff) + Q_strcat(src, "^3="); + else + Q_strcat(src, "^4=^3"); + } + } + } + } + if (type == 2) + { + Q_strcat(src, va("] - %4d", diff)); + } + else + { + Q_strcat(src, va("] - %4d%%", (Neg ? -diff : diff))); + } +} + + +static inline int func_pwmsimulation_Frequency(StrobeAPI_t *self) +{ + return (int)round((1 / ((1.0f / self->get.CurrentFPS(self))*(abs(r_strobe->integer) + 1)))); +} + +static inline double func_pwmsimulation_DutyCycle(void) +{ + int strobeInterval = r_strobe->integer; + return (((1.0f / (abs(strobeInterval) + 1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1)); +} + +static inline double func_pwmsimulation_PositivePhaseShift(StrobeAPI_t *self) +{ + return !!(self->protected->frameInfo & p_inverted) ? (1.0f / self->get.CurrentFPS(self)) * 1000 : 0.0f; +} + +static inline double func_pwmsimulation_NegativePhaseShift(StrobeAPI_t *self) +{ + if (!!(self->protected->frameInfo & p_inverted)) + return abs(r_strobe->integer) * (1.0f / self->get.CurrentFPS(self)) * 1000; + else + return 0.0; +} + +static inline double func_pwmsimulation_Period(StrobeAPI_t *self) +{ + return (((1.0f / self->get.CurrentFPS(self))*(abs(r_strobe->integer) + 1)) * 1000); +} + +static inline double func_helper_GeometricMean(double x, double y) +{ + return sqrt(abs(x * y)); + /* + int multiply = (x * y); + if (multiply >= 0) + return sqrt(multiply); + else + return sqrt(abs(multiply)); + */ +} + +static inline double func_helper_ArithmeticMean(double x, double y) +{ + return (x + y) / 2; +} + + +static inline double func_brightnessreduction_ActualBrightnessReduction(StrobeAPI_t *self) +{ + double currentFPS = self->get.CurrentFPS(self); + double effectiveFPS = self->Helpers.effectiveFPS(self); + //return ((currentFPS - effectiveFPS) * 100.0 / currentFPS); + return lossCalculator(currentFPS, effectiveFPS); +} + +static inline double func_brightnessreduction_LogarithmicBrightnessReduction(StrobeAPI_t *self, double base) +{ + + return lossCalculator( log(base), log(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); +} + +static inline double func_brightnessreduction_SquareBrightnessReduction(StrobeAPI_t *self, double base) +{ + return lossCalculator( sqrt(base), sqrt(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); +} + +static inline double func_brightnessreduction_CubeBrightnessReduction(StrobeAPI_t *self, double base) +{ + return lossCalculator( cbrt(base), cbrt(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); +} + +static inline double func_brightnessreduction_OtherBrightnessReduction(StrobeAPI_t *self, double base, double(*reductionFunction)(double)) +{ + return lossCalculator(reductionFunction(base), reductionFunction(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self))); +} + +static inline double func_experimental_Badness_Reducted(StrobeAPI_t *self, qboolean PWMInvolved) +{ + double badness; + int diffP_NB, diffN_NB; + diffP_NB = (self->protected->pNCounter - self->protected->pBCounter); + diffN_NB = (self->protected->nNCounter - self->protected->nBCounter); + double diffP = 0.0, diffN = 0.0; + double Diff; + + if (self->protected->pCounter != 0) + diffP = round(abs(diffP_NB) * 100 / self->protected->pCounter); + + if (self->protected->nCounter != 0) + diffN = round(abs(diffN_NB) * 100 / self->protected->nCounter); + + if (diffP_NB < 0.0) + diffP = -diffP; + if (diffN_NB < 0.0) + diffN = -diffN; + + Diff = fabs(diffP - diffN); + + + if (Diff < 0.0) + Diff = 0.0; + else if (Diff > 200.0) + Diff = 200.0; + + badness = -log((200 - Diff) / (Diff)); + + if (PWMInvolved) + return (badness * func_pwmsimulation_Period(self)); + else + return badness; +} + +static inline double func_experimental_Badness(StrobeAPI_t *self, qboolean PWMInvolved) +{ + int diffP_NB, diffN_NB; + diffP_NB = (self->protected->pNCounter - self->protected->pBCounter); + diffN_NB = (self->protected->nNCounter - self->protected->nBCounter); + + double diffP = 0.0, diffN = 0.0; + + if (self->protected->pCounter != 0) + diffP = round(abs(diffP_NB) * 100 / self->protected->pCounter); + + if (self->protected->nCounter != 0) + diffN = round(abs(diffN_NB) * 100 / self->protected->nCounter); + + + double absoluteDifference = fabs(diffP - diffN); + if (absoluteDifference > 100.0) + absoluteDifference = 100.0; + double badness = \ + -log(((absoluteDifference + func_helper_GeometricMean((100.0 - diffP), (100.0 - diffN))) / (absoluteDifference + func_helper_GeometricMean(diffP, diffN)))); + if (PWMInvolved) + return (badness * func_pwmsimulation_Period(self)); + else + return badness; +} + + + +size_t get_FrameCounter(StrobeAPI_t *self, counterType type) +{ + switch (type) + { + + case(CT_PositiveFrame): + { + return self->protected->pCounter; + break; + } + case(CT_PositiveNormalFrame): + { + return self->protected->pNCounter; + break; + } + case(CT_PositiveBlackFrame): + { + return self->protected->pBCounter; + break; + } + case(CT_NegativeFrame): + { + return self->protected->nCounter; + break; + } + case(CT_NegativeNormalFrame): + { + return self->protected->nNCounter; + break; + } + case(CT_NegativeBlackFrame): + { + return self->protected->nBCounter; + break; + } + case(CT_TotalFrame): + default: + return self->protected->fCounter; + break; + } + return self->protected->fCounter; +} + +double get_Deviation(StrobeAPI_t *self) +{ + return self->protected->deviation; +} + +double get_CooldownTimer(StrobeAPI_t *self) +{ + return self->protected->cdTimer; +} + +double get_currentFPS(StrobeAPI_t *self) +{ + // Copied from SCR_DrawFps + // This way until current fps becomes global!!! + + static double nexttime = 0, lasttime = 0; + static double framerate = 0; + static unsigned int mark = 0; + double newtime; + + newtime = Sys_DoubleTime(); + if (newtime >= nexttime) + { + framerate = (self->protected->fCounter - mark) / (newtime - lasttime); + lasttime = newtime; + nexttime = max(nexttime + 0.5, lasttime - 0.5); // Make Update tick configurable ? + mark = self->protected->fCounter; + } + + return framerate; +} + +static inline void GenerateDebugStatistics(StrobeAPI_t *self, char *src, int size) +{ + char diffBarP[128], diffBarN[128], diffBarT[128]; + + int diffP_NB, diffN_NB; + diffP_NB = (self->protected->pNCounter - self->protected->pBCounter); + diffN_NB = (self->protected->nNCounter - self->protected->nBCounter); + + double diffP = 0.0, diffN = 0.0; + + if (self->protected->pCounter != 0) + diffP = round(abs(diffP_NB) * 100 / self->protected->pCounter); + + if (self->protected->nCounter != 0) + diffN = round(abs(diffN_NB) * 100 / self->protected->nCounter); + + self->Helpers.GenerateDiffBar(self, diffBarP, sizeof(diffBarP),0); + self->Helpers.GenerateDiffBar(self, diffBarN, sizeof(diffBarN), 1); + self->Helpers.GenerateDiffBar(self, diffBarT, sizeof(diffBarT),2); + + double cooldown = self->get.CooldownTimer(self); + + Q_snprintf(src, + size, + "%.2f FPS\n%.2f eFPS\n" \ + "Total Frame Count: %u\n" \ + "(+) Phase Frame Count: %u\n" \ + " |-> Normal Frame Count: %u\n" \ + " |-> Black Frame Count: %u\n" \ + "(-) Phase Frame Count:%u\n" \ + " |-> Normal Frame Count: %u\n" \ + " |-> Black Frame Count: %u\n" \ + ".isPhaseInverted: %d\n" \ + "^5=====ANALYSIS=====\n^3" \ + "PWM Simulation:\n" \ + " |-> Frequency: %d Hz\n" \ + " |-> Duty Cycle: %.2f%%\n" \ + " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" \ + " |-> Period: %.4f msec\n" \ + "Brightness Reduction:\n" \ + " |-> [^7LINEAR^3] Actual Reduction: %3f%%\n" \ + " |-> [^7LOG^3] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ + " |-> [^7SQUARE^3] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ + " |-> [^7CUBE^3] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ + "Difference (+): %s\nDifference (-): %s\nDifference (x): %s\n" /* Diff 3 (Total): |Diff + - Diff -| . Max 200 Min 0*/ \ + "Geometric Mean: %.4f\n" \ + "G/A Difference: %.4f\n" \ + "[^7EXPERIMENTAL^3] Badness: %.4f\n" \ + "[^7EXPERIMENTAL^3] Badness x PWM Period: %.4f\n" \ + "[^7EXPERIMENTAL^3] Badness (Reducted): %.4f\n" \ + "[^7EXPERIMENTAL^3] Badness (Reducted) x PWM Period: %.4f\n" /* Badness -log((200-n)/n) */ \ + "Stability:\n" \ + " |-> Standard Deviation: %.3f\n" \ + " |-> Cooldown: %s\n" \ + "^5=====ANALYSIS=====\n^3" \ + , self->get.CurrentFPS(self) \ + , self->Helpers.effectiveFPS(self) \ + , self->get.FrameCounter(self, CT_TotalFrame) \ + , self->get.FrameCounter(self, CT_PositiveFrame), self->get.FrameCounter(self, CT_PositiveNormalFrame), self->get.FrameCounter(self, CT_PositiveBlackFrame) \ + , self->get.FrameCounter(self, CT_NegativeFrame), self->get.FrameCounter(self, CT_NegativeNormalFrame), self->get.FrameCounter(self, CT_NegativeBlackFrame) \ + , self->Helpers.isPhaseInverted(self) \ + , self->PWM.Frequency(self) \ + , self->PWM.DutyCycle() \ + , self->PWM.PositivePhaseShift(self) \ + , self->PWM.NegativePhaseShift(self) \ + , self->PWM.Period(self) \ + , self->BrightnessReductions.ActualBrightnessReduction(self) + , self->BrightnessReductions.LogarithmicBrightnessReduction(self, 400.0) + , self->BrightnessReductions.SquareBrightnessReduction(self, 400.0) + , self->BrightnessReductions.CubeBrightnessReduction(self, 400.0) + , diffBarP, diffBarN, diffBarT \ + , self->Helpers.GeometricMean(diffP, diffN) \ + , self->Helpers.ArithmeticMean(diffP, diffN) - self->Helpers.GeometricMean(diffP, diffN) + , self->Experimentals.BADNESS(self, false), self->Experimentals.BADNESS(self, true) \ + , self->Experimentals.BADNESS_REDUCTED(self, false), self->Experimentals.BADNESS_REDUCTED(self, true) \ + , self->get.Deviation(self) + , (cooldown > 0.0 && self->protected->cdTriggered ? va("^1 %.2f secs\n[STROBING DISABLED] ^3", (double)r_strobe_cooldown->integer - cooldown) : "0")); + +} + + +static inline void ProcessFrame(StrobeAPI_t *self) +{ + if (self->protected->cdTriggered != 0) + { + self->protected->frameInfo = f_normal | (self->protected->frameInfo & p_positive); + } + + if (self->protected->frameInfo & f_normal) // Show normal + { + if (self->protected->frameInfo & p_positive) + ++self->protected->pNCounter; + else + ++self->protected->nNCounter; + + R_Set2DMode(false); + } + else // Show black + { + if (self->protected->frameInfo & p_positive) + ++self->protected->pBCounter; + else + ++self->protected->nBCounter; + + //GL_GenerateBlackFrame(); + self->GenerateBlackFrame(); + } + + ++self->protected->fCounter; +} + + +void StrobeAPI_constructor(StrobeAPI_t *self) +{ + /*self->protected = (StrobeAPI_protected_t *)malloc(sizeof(StrobeAPI_protected_t)); + self->protected->nCounter = 0; self->protected->pBCounter = 0; self->protected->pNCounter = 0; + self->protected->pCounter = 0; self->protected->nBCounter = 0; self->protected->nNCounter = 0; + self->protected->fCounter = 0; + self->protected->deviation = 0.0; + self->protected->cdTimer = 0.0; + self->protected->cdTriggered = false;*/ + self->protected = (StrobeAPI_protected_t *)calloc(1, sizeof(StrobeAPI_protected_t)); + self->protected->frameInfo = (p_positive | f_normal); + self->Helpers.ArithmeticMean = func_helper_ArithmeticMean; + self->Helpers.effectiveFPS = func_helper_effectiveFPS; + self->Helpers.GenerateDiffBar = func_helper_GenerateDiffBar; + self->Helpers.GeometricMean = func_helper_GeometricMean; + self->get.Cooldown = func_helper_getCooldown; + self->get.CurrentFPS = get_currentFPS; + self->Helpers.isPhaseInverted = func_helper_isPhaseInverted; + self->Helpers.isNormal = func_helper_isNormal; + self->Helpers.isPositive = func_helper_isPositive; + self->Helpers.StandardDeviation = func_helper_StandardDeviation; + self->Experimentals.BADNESS = func_experimental_Badness; + self->Experimentals.BADNESS_REDUCTED = func_experimental_Badness_Reducted; + self->BrightnessReductions.ActualBrightnessReduction = func_brightnessreduction_ActualBrightnessReduction; + self->BrightnessReductions.CubeBrightnessReduction = func_brightnessreduction_CubeBrightnessReduction; + self->BrightnessReductions.LogarithmicBrightnessReduction = func_brightnessreduction_LogarithmicBrightnessReduction; + self->BrightnessReductions.SquareBrightnessReduction = func_brightnessreduction_SquareBrightnessReduction; + self->BrightnessReductions.OtherBrightnessReduction = func_brightnessreduction_OtherBrightnessReduction; + self->PWM.Frequency = func_pwmsimulation_Frequency; + self->PWM.DutyCycle = func_pwmsimulation_DutyCycle; + self->PWM.PositivePhaseShift = func_pwmsimulation_PositivePhaseShift; + self->PWM.NegativePhaseShift = func_pwmsimulation_NegativePhaseShift; + self->PWM.Period = func_pwmsimulation_Period; + self->GenerateBlackFrame = GL_GenerateBlackFrame; + self->ProcessFrame = ProcessFrame; + self->Helpers.GenerateDebugStatistics = GenerateDebugStatistics; + self->get.FrameCounter = get_FrameCounter; + self->get.Deviation = get_Deviation; + self->get.CooldownTimer = get_CooldownTimer; +} + +void StrobeAPI_destructor(StrobeAPI_t *self) +{ + if (self->protected) + { + free(self->protected); + self->protected = NULL; + } +} + + +/* +=============== +R_InitStrobe + +register strobe cvar +=============== +*/ +void R_InitStrobe() +{ + r_strobe = Cvar_Get("r_strobe", "0", CVAR_ARCHIVE, "black frame replacement interval"); + r_strobe_swapinterval = Cvar_Get("r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval"); + r_strobe_debug = Cvar_Get("r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information"); + r_strobe_cooldown = Cvar_Get("r_strobe_cooldown", "3", CVAR_ARCHIVE, "strobe cooldown period in seconds"); +} + +void Strobe_Invoker(void **self, void(*constructor)(void **), void(*main)(void **), void(*destructor)(void **)) +{ + if (r_strobe->integer) + { + if (!(*self)) + constructor(self); + main(self); + } + else + { + if (*self) + destructor(self); + } +} + + +#endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h new file mode 100644 index 000000000..ac4dd4d4d --- /dev/null +++ b/engine/client/strobe/r_strobe_api.h @@ -0,0 +1,112 @@ +/* +r_strobe.c - Software based strobing implementation + +Copyright (C) 2018 * fuzun + +For information: + https://forums.blurbusters.com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. +*/ + +#if !defined R_STROBE_API_H && !defined STROBE_DISABLED +#define R_STROBE_API_H + +#define STROBE_ENABLED // Integrate with cmake? + +#include "common.h" +#include "wrect.h" + +typedef struct StrobeAPI_s StrobeAPI_t; + +typedef enum { + CT_TotalFrame, + CT_PositiveFrame, + CT_PositiveNormalFrame, + CT_PositiveBlackFrame, + CT_NegativeFrame, + CT_NegativeNormalFrame, + CT_NegativeBlackFrame +}counterType; + +typedef struct StrobeAPI_exported_funcs_BRIGHTNESSREDUCTION_s { + double(*ActualBrightnessReduction)(StrobeAPI_t *self); + double(*LogarithmicBrightnessReduction)(StrobeAPI_t *self, double base); + double(*SquareBrightnessReduction)(StrobeAPI_t *self, double base); + double(*CubeBrightnessReduction)(StrobeAPI_t *self, double base); + double(*OtherBrightnessReduction)(StrobeAPI_t *self, double base, double(*reductionFunction)(double)); +} StrobeAPI_exported_funcs_BRIGHTNESSREDUCTION_t; + +typedef struct StrobeAPI_exported_funcs_EXPERIMENTAL_s { + double(*BADNESS)(StrobeAPI_t *self, qboolean PWMInvolved); + double(*BADNESS_REDUCTED)(StrobeAPI_t *self, qboolean PWMInvolved); +} StrobeAPI_exported_funcs_EXPERIMENTAL_t; + +typedef struct StrobeAPI_exported_funcs_PWMSIMULATION_s { + int(*Frequency)(StrobeAPI_t *self); + double(*DutyCycle)(void); + double(*PositivePhaseShift)(StrobeAPI_t *self); + double(*NegativePhaseShift)(StrobeAPI_t *self); + double(*Period)(StrobeAPI_t *self); +} StrobeAPI_exported_funcs_PWMSIMULATION_t; + +typedef struct StrobeAPI_exported_funcs_HELPER_s { + qboolean(*isPhaseInverted)(StrobeAPI_t *self); + qboolean(*isNormal)(StrobeAPI_t *self); + qboolean(*isPositive)(StrobeAPI_t *self); + double(*effectiveFPS)(StrobeAPI_t *self); + void(*GenerateDebugStatistics)(StrobeAPI_t *self, char *src, int size); + void(*GenerateDiffBar)(StrobeAPI_t *self, char *src, int size, char type); + double(*GeometricMean)(double, double); + double(*ArithmeticMean)(double, double); + double(*StandardDeviation)(const double *data, int size); +} StrobeAPI_exported_funcs_HELPER_t; + +typedef struct StrobeAPI_get_s { + size_t(*FrameCounter)(StrobeAPI_t *self, counterType); + double(*Deviation)(StrobeAPI_t *self); + double(*CooldownTimer)(StrobeAPI_t *self); + double(*CurrentFPS)(StrobeAPI_t *self); + double(*Cooldown)(StrobeAPI_t *self); +} StrobeAPI_get_t; + +typedef struct StrobeAPI_protected_s StrobeAPI_protected_t; + +typedef struct StrobeAPI_s { + StrobeAPI_protected_t *protected; // r_strobe_base_protected_.h + StrobeAPI_exported_funcs_EXPERIMENTAL_t Experimentals; + StrobeAPI_exported_funcs_BRIGHTNESSREDUCTION_t BrightnessReductions; + StrobeAPI_exported_funcs_PWMSIMULATION_t PWM; + StrobeAPI_exported_funcs_HELPER_t Helpers; + StrobeAPI_get_t get; + void(*GenerateBlackFrame)(void); + void(*ProcessFrame)(StrobeAPI_t *self); +} StrobeAPI_t; + + +void Strobe_Invoker(void **self, void(*constructor)(void **), void(*main)(void **), void(*destructor)(void **)); // Strobe Invoker + +void StrobeAPI_constructor(StrobeAPI_t *self); +void StrobeAPI_destructor(StrobeAPI_t *self); + +void R_InitStrobe(); + +#define STROBE_DEVIATION_LIMIT 2.75 +#define STROBE_DEVIATION_SIZE 60 + +extern convar_t *r_strobe; +extern convar_t *r_strobe_swapinterval; +extern convar_t *r_strobe_debug; +extern convar_t *r_strobe_cooldown; + + +#endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_base_protected_.h b/engine/client/strobe/r_strobe_base_protected_.h new file mode 100644 index 000000000..6b67c322e --- /dev/null +++ b/engine/client/strobe/r_strobe_base_protected_.h @@ -0,0 +1,44 @@ +/* +r_strobe_base_protected_.h - Software based strobing implementation + +Copyright (C) 2018 - fuzun * github/fuzun + +For information: + https://forums.blurbusters.com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. +*/ + +#if !defined R_STROBE_BASE_PROTECTED_ && !defined STROBE_DISABLED +#define R_STROBE_BASE_PROTECTED_ + +#include "common.h" + +typedef enum { + p_positive = BIT(0), // Phase: Positive + p_inverted = BIT(1), // Phase: Inverted + f_normal = BIT(2) // Frame: Normal +} fstate_e; // Frame State + + +typedef struct StrobeAPI_protected_s { + size_t fCounter; // Frame counter + size_t pCounter, pNCounter, pBCounter; // Positive phase counters + size_t nCounter, nNCounter, nBCounter; // Negative phase counters + double deviation; // deviation + double cdTimer; // Cooldown timer + char cdTriggered; + fstate_e frameInfo; // Frame info +} StrobeAPI_protected_t; // Protected members + + +#endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c new file mode 100644 index 000000000..d88f48df7 --- /dev/null +++ b/engine/client/strobe/r_strobe_core.c @@ -0,0 +1,331 @@ +/* +r_strobe_core.c - Software based strobing implementation + +Copyright (C) 2018 - fuzun * github.com/fuzun + +For information: +https://forums.blurbusters.com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. +*/ + +#if !defined XASH_DEDICATED && !defined STROBE_DISABLED + + +#include +#include +#include "r_strobe_base_protected_.h" +#include "r_strobe_core.h" +#include "gl_local.h" +#include "client.h" + + +STROBE_CORE_t *STROBE_CORE = NULL; + +typedef struct STROBE_CORE_priv_s { + int strobeInterval; // Move to base ? + int swapInterval; + double recentTime, recentTime2; + double delta[STROBE_DEVIATION_SIZE]; + size_t fCounterSnapshot; +}STROBE_CORE_priv_t; + + +/* +=============== +R_Strobe + +TODO: +* Make swapping transition seamless by rendering non-opaque frames. +* Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) +=============== +*/ +static void R_Strobe(STROBE_CORE_THIS_PARAM) +{ + //static int strobeInterval = 0; + //static int swapInterval = 0; + //static double recentTime = 0.0, recentTime2 = 0.0; + double _delta, _delta2; + //static qboolean cdTriggered = false; + //static double delta[STROBE_DEVIATION_SIZE] = { 0.0 }; + //static size_t fCounterSnapshot = 0; + double currentTime = Sys_DoubleTime(); + _delta2 = currentTime - STROBE_CORE_THIS->private->recentTime2; + STROBE_CORE_THIS->private->recentTime2 = currentTime; + + if (CL_IsInMenu()) + { + R_Set2DMode(false); + return; + } + + if (STROBE_CORE_THIS->base.protected->cdTimer >= 0.0 && _delta2 > 0.0) + STROBE_CORE_THIS->base.protected->cdTimer += _delta2; + if (STROBE_CORE_THIS->base.protected->fCounter - STROBE_CORE_THIS->private->fCounterSnapshot == 1) + { + STROBE_CORE_THIS->private->delta[STROBE_CORE_THIS->base.protected->fCounter % ARRAYSIZE(STROBE_CORE_THIS->private->delta)] = _delta2; + STROBE_CORE_THIS->base.protected->deviation = STROBE_CORE_THIS->base.Helpers.StandardDeviation(STROBE_CORE_THIS->private->delta, ARRAYSIZE(STROBE_CORE_THIS->private->delta)) * 1000; + } + STROBE_CORE_THIS->private->fCounterSnapshot = STROBE_CORE_THIS->base.protected->fCounter; + + if (r_strobe_cooldown->integer > 0) + { + if ((STROBE_CORE_THIS->base.protected->cdTimer > (double)abs(r_strobe_cooldown->integer)) && STROBE_CORE_THIS->base.protected->cdTriggered == 1) + { + STROBE_CORE_THIS->base.protected->cdTriggered = 0; + STROBE_CORE_THIS->base.protected->cdTimer = -1.0; + } + + if (STROBE_CORE_THIS->base.protected->fCounter > ARRAYSIZE(STROBE_CORE_THIS->private->delta)) + { + if (STROBE_CORE_THIS->base.protected->deviation > STROBE_DEVIATION_LIMIT) + { + STROBE_CORE_THIS->base.protected->cdTriggered = 1; + STROBE_CORE_THIS->base.protected->cdTimer = 0.0; + } + } + } + else + { + STROBE_CORE_THIS->base.protected->cdTriggered = 0; + } + + //Msg("Snapshot: %d - Deviation: %f - timer %f - delta %f\n\n", snapshot, standard_deviation(data, 10) * 1000, StrobeInfo.cdTimer, _delta2); + + if (((STROBE_CORE_THIS->private->strobeInterval != r_strobe->integer) && (STROBE_CORE_THIS->private->strobeInterval != 0)) || + /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ + STROBE_CORE_THIS->base.protected->fCounter == UINT_MAX) // Reset stats after some time + { + + STROBE_CORE_EXPORTEDFUNC_reinit(&STROBE_CORE_THIS); + R_Strobe(&STROBE_CORE_THIS); + /* + STROBE_CORE_THIS->base.protected->pCounter = 0; STROBE_CORE_THIS->base.protected->pBCounter = 0; STROBE_CORE_THIS->base.protected->pNCounter = 0; + STROBE_CORE_THIS->base.protected->nCounter = 0; STROBE_CORE_THIS->base.protected->nBCounter = 0; STROBE_CORE_THIS->base.protected->nNCounter = 0; + STROBE_CORE_THIS->base.protected->fCounter = 0; + STROBE_CORE_THIS->base.protected->deviation = 0.0; + Q_memset(STROBE_CORE_THIS->private->delta, 0, sizeof(STROBE_CORE_THIS->private->delta)); + + STROBE_CORE_THIS->base.protected->frameInfo &= ~p_inverted; + */ + } + + STROBE_CORE_THIS->private->strobeInterval = r_strobe->integer; + STROBE_CORE_THIS->private->swapInterval = r_strobe_swapinterval->integer; + + if ((STROBE_CORE_THIS->private->strobeInterval == 0) || + ((gl_swapInterval->integer == 0) && (STROBE_CORE_THIS->private->strobeInterval != 0))) + { + if (!gl_swapInterval->integer) + MsgDev(D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n"); + + if (STROBE_CORE_THIS->private->strobeInterval != 0) // If v-sync is off, turn off strobing + { + Cvar_Set("r_strobe", "0"); + } + STROBE_CORE_THIS->base.protected->fCounter = 0; + + R_Set2DMode(false); + return; + } + + if ((STROBE_CORE_THIS->base.protected->fCounter % 2) == 0) + { + ++STROBE_CORE_THIS->base.protected->pCounter; + STROBE_CORE_THIS->base.protected->frameInfo |= p_positive; + } + else + { + ++STROBE_CORE_THIS->base.protected->nCounter; + STROBE_CORE_THIS->base.protected->frameInfo &= ~p_positive; + } + + if (STROBE_CORE_THIS->private->swapInterval < 0) + STROBE_CORE_THIS->private->swapInterval = abs(STROBE_CORE_THIS->private->swapInterval); + + if ((STROBE_CORE_THIS->private->swapInterval != 0) && (STROBE_CORE_THIS->private->strobeInterval % 2 != 0)) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + { + _delta = currentTime - STROBE_CORE_THIS->private->recentTime; // New Currenttime for _delta ? + if ((_delta >= (double)(STROBE_CORE_THIS->private->swapInterval)) && (_delta < (double)(2 * STROBE_CORE_THIS->private->swapInterval))) // Basic timer + { + STROBE_CORE_THIS->base.protected->frameInfo |= p_inverted; + } + else if (_delta < (double)(STROBE_CORE_THIS->private->swapInterval)) + { + STROBE_CORE_THIS->base.protected->frameInfo &= ~p_inverted; + } + else //if (_delta >= (double)(2 * swapInterval)) + { + STROBE_CORE_THIS->private->recentTime = currentTime; + } + } + + switch (STROBE_CORE_THIS->base.protected->frameInfo & (p_positive | p_inverted)) + { + case (p_positive | p_inverted): + if ((abs(STROBE_CORE_THIS->private->strobeInterval) % 2) == 0) + STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->pCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == (abs(STROBE_CORE_THIS->private->strobeInterval) / 2)) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + else + STROBE_CORE_THIS->base.protected->frameInfo &= ~f_normal; + break; + + case(p_positive & ~p_inverted): + if (abs(STROBE_CORE_THIS->private->strobeInterval) % 2 == 0) + STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->pCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + else + { + if (abs(STROBE_CORE_THIS->private->strobeInterval) == 1) + STROBE_CORE_THIS->base.protected->frameInfo |= f_normal; + else + STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->pCounter - 1) % ((abs(STROBE_CORE_THIS->private->strobeInterval) + 1) / 2)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd + } + break; + + case(~p_positive & p_inverted): + if (abs(STROBE_CORE_THIS->private->strobeInterval) % 2 == 0) + STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->nCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + else + { + if (abs(STROBE_CORE_THIS->private->strobeInterval) == 1) + STROBE_CORE_THIS->base.protected->frameInfo |= f_normal; + else + STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->nCounter - 1) % ((abs(STROBE_CORE_THIS->private->strobeInterval) + 1) / 2)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd + } + break; + + case 0: + if ((abs(STROBE_CORE_THIS->private->strobeInterval) % 2) == 0) + STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->nCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == (abs(STROBE_CORE_THIS->private->strobeInterval) / 2)) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + else + STROBE_CORE_THIS->base.protected->frameInfo &= ~f_normal; + break; + + default: + STROBE_CORE_THIS->base.protected->frameInfo = (p_positive | f_normal); + } + + if (STROBE_CORE_THIS->private->strobeInterval < 0) + STROBE_CORE_THIS->base.protected->frameInfo ^= f_normal; + + + + STROBE_CORE_THIS->base.ProcessFrame(&STROBE_CORE_THIS->base); +} + + +static inline void debugDrawer(STROBE_CORE_THIS_PARAM) +{ + rgba_t color; + char debugStr[2048]; // Heap allocation ? + int offsetX, offsetY; + + qboolean strobeDebug = !!r_strobe_debug->integer ? true : false; // Why not just r_strobe_debug->integer ? + + /* + if (!(STROBE_CORE_THIS->base.protected->frameInfo & f_normal && (r_strobe_debug->integer || cl_showfps->integer))) + { + return; + } + */ + + if (cls.state != ca_active) return; + if ((!strobeDebug && !cl_showfps->integer) || cl.background) return; + + switch (cls.scrshot_action) + { + case scrshot_normal: + case scrshot_snapshot: + case scrshot_inactive: + break; + default: return; + } + + if (strobeDebug) + { + STROBE_CORE_THIS->base.Helpers.GenerateDebugStatistics(&STROBE_CORE_THIS->base, debugStr, ARRAYSIZE(debugStr)); + } + else if (cl_showfps->integer) + { + Q_snprintf(debugStr, sizeof(debugStr), "%3d eFPS", (int)round(STROBE_CORE_THIS->base.Helpers.effectiveFPS(&STROBE_CORE_THIS->base))); + } + + MakeRGBA(color, 255, 255, 255, 255); + Con_DrawStringLen(debugStr, &offsetX, &offsetY); + if (strobeDebug) + Con_DrawString(scr_width->integer - offsetX - 50, 4, debugStr, color); + else + Con_DrawString(scr_width->integer - offsetX - 2, offsetY + 8, debugStr, color); + +} + +void STROBE_CORE_EXPORTEDFUNC_constructor(void **STROBE_CORE) +{ + STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + + *instance = (STROBE_CORE_t *)malloc(sizeof(STROBE_CORE_t)); + /*(*instance)->private = (STROBE_CORE_priv_t *)malloc(sizeof(STROBE_CORE_priv_t)); + (*instance)->private->strobeInterval = 0; + (*instance)->private->swapInterval = 0; + (*instance)->private->recentTime = 0.0; + (*instance)->private->recentTime2 = 0.0; + Q_memset((*instance)->private->delta, 0, sizeof((*instance)->private->delta)); + (*instance)->private->fCounterSnapshot = 0;*/ + (*instance)->private = (STROBE_CORE_priv_t *)calloc(1, sizeof(STROBE_CORE_priv_t)); + + (*instance)->STROBE_CORE_FUNC_main = R_Strobe; + (*instance)->STROBE_CORE_FUNC_debughandler = debugDrawer; + + StrobeAPI_constructor(&(*instance)->base); +} + + +void STROBE_CORE_EXPORTEDFUNC_destructor(void **STROBE_CORE) +{ + STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + + if (*instance) // Check anyway + { + StrobeAPI_destructor(&(*instance)->base); + if ((*instance)->private) + { + free((*instance)->private); + (*instance)->private = NULL; + } + free(*instance); + *instance = NULL; + } +} + +void STROBE_CORE_EXPORTEDFUNC_reinit(void **STROBE_CORE) +{ + STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + + if (!(*STROBE_CORE)) + { + STROBE_CORE_EXPORTEDFUNC_destructor(instance); + } + STROBE_CORE_EXPORTEDFUNC_constructor(instance); +} + + +void STROBE_CORE_EXPORTEDFUNC_main(void **STROBE_CORE) +{ + STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + + if (*instance) + { + (*instance)->STROBE_CORE_FUNC_main(instance); + } +} + + +#endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h new file mode 100644 index 000000000..4abf2a543 --- /dev/null +++ b/engine/client/strobe/r_strobe_core.h @@ -0,0 +1,63 @@ +/* +r_strobe_core.h - Software based strobing implementation + +Copyright (C) 2018 - fuzun * github.com/fuzun + +For information: +https://forums.blurbusters.com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. +*/ + +#if !defined R_STROBE_CORE_H && !defined STROBE_DISABLED +#define R_STROBE_CORE_H + +#include "r_strobe_api.h" + +#define STROBE_CORE Strobe_Core +#define _STROBE_CORE_THIS self +#define STROBE_CORE_FUNC_main main +#define STROBE_CORE_FUNC_debughandler debugDrawer + + +#define STROBE_CORE_s STROBE_CORE ## _s +#define STROBE_CORE_t STROBE_CORE ## _t +#define STROBE_CORE_priv_s STROBE_CORE ## _priv_s +#define STROBE_CORE_priv_t STROBE_CORE ## _priv_t +#define STROBE_CORE_THIS (* ## _STROBE_CORE_THIS ## ) +#define STROBE_CORE_THIS_PARAM STROBE_CORE_t ## ** ## _STROBE_CORE_THIS +#define STROBE_CORE_EXPORTEDFUNC_main STROBE_CORE ## _ ## STROBE_CORE_FUNC_main +#define STROBE_CORE_EXPORTEDFUNC_constructor STROBE_CORE ## _constructor +#define STROBE_CORE_EXPORTEDFUNC_destructor STROBE_CORE ## _destructor +#define STROBE_CORE_EXPORTEDFUNC_reinit STROBE_CORE ## _reinit + + +typedef struct STROBE_CORE_s STROBE_CORE_t; +typedef struct STROBE_CORE_priv_s STROBE_CORE_priv_t; + + +typedef struct STROBE_CORE_s { + StrobeAPI_t base; + STROBE_CORE_priv_t *private; + void(*STROBE_CORE_FUNC_main)(STROBE_CORE_THIS_PARAM); + void(*STROBE_CORE_FUNC_debughandler)(STROBE_CORE_THIS_PARAM); +} STROBE_CORE_t; + +extern STROBE_CORE_t *STROBE_CORE; + +void STROBE_CORE_EXPORTEDFUNC_constructor(void **STROBE_CORE); +void STROBE_CORE_EXPORTEDFUNC_destructor(void **STROBE_CORE); +void STROBE_CORE_EXPORTEDFUNC_reinit(void **STROBE_CORE); +void STROBE_CORE_EXPORTEDFUNC_main(void **STROBE_CORE); + + +#endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_template.c.TEMPLATE b/engine/client/strobe/r_strobe_template.c.TEMPLATE new file mode 100644 index 000000000..48e2bffd0 --- /dev/null +++ b/engine/client/strobe/r_strobe_template.c.TEMPLATE @@ -0,0 +1,111 @@ +/* +r_strobe_template.c - Software based strobing implementation + +Copyright (C) 2018 - fuzun * github.com/fuzun + +For information: +https://forums.blurbusters.com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. +*/ + + +#if !defined XASH_DEDICATED && !defined STROBE_DISABLED + + +#include "r_strobe_base_protected_.h" +#include "r_strobe_template.h" +// #include "gl_local.h" +#include "client.h" + + +STROBE_TEMPLATE_t *STROBE_TEMPLATE = NULL; + +typedef struct STROBE_TEMPLATE_priv_s { + // Private members +} STROBE_TEMPLATE_priv_t; + + +void STROBE_TEMPLATE_EXPORTEDFUNC_constructor(void **STROBE_TEMPLATE); +void STROBE_TEMPLATE_EXPORTEDFUNC_destructor(void **STROBE_TEMPLATE); +void STROBE_TEMPLATE_EXPORTEDFUNC_reinit(void **STROBE_TEMPLATE); +void STROBE_TEMPLATE_EXPORTEDFUNC_main(void **STROBE_TEMPLATE); + + + +static void main(STROBE_TEMPLATE_THIS_PARAM) +{ + STROBE_TEMPLATE_THIS->base.protected->frameInfo = (p_positive | f_normal); + STROBE_TEMPLATE_THIS->base.ProcessFrame(&STROBE_TEMPLATE_THIS->base); +} + + +static inline void debugHandler(STROBE_TEMPLATE_THIS_PARAM) +{ + char debugstr[2048]; + STROBE_TEMPLATE_THIS->base.Helpers.GenerateDebugStatistics(&STROBE_TEMPLATE_THIS->base, debugstr, 2048); +} + +void STROBE_TEMPLATE_EXPORTEDFUNC_constructor(void **STROBE_TEMPLATE) +{ + STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; + *instance = (STROBE_TEMPLATE_t *)malloc(sizeof(STROBE_TEMPLATE_t)); + + (*instance)->private = (STROBE_TEMPLATE_priv_t *)malloc(sizeof(STROBE_TEMPLATE_priv_t)); + (*instance)->STROBE_TEMPLATE_FUNC_main = main; + (*instance)->STROBE_TEMPLATE_FUNC_debughandler = debugHandler; + + StrobeAPI_constructor(&(*instance)->base); +} + + +void STROBE_TEMPLATE_EXPORTEDFUNC_destructor(void **STROBE_TEMPLATE) +{ + STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; + + if (*instance) + { + StrobeAPI_destructor(&(*instance)->base); + if ((*instance)->private) + { + free((*instance)->private); + (*instance)->private = NULL; + } + free(*instance); + *instance = NULL; + } +} + +void STROBE_TEMPLATE_EXPORTEDFUNC_reinit(void **STROBE_TEMPLATE) +{ + STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; + + if (!(*STROBE_TEMPLATE)) + { + STROBE_TEMPLATE_EXPORTEDFUNC_destructor(instance); + } + STROBE_TEMPLATE_EXPORTEDFUNC_constructor(instance); +} + + +void STROBE_TEMPLATE_EXPORTEDFUNC_main(void **STROBE_TEMPLATE) +{ + STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; + + if (*instance) + { + (*instance)->STROBE_TEMPLATE_FUNC_main(instance); + } +} + + +#endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_template.h.TEMPLATE b/engine/client/strobe/r_strobe_template.h.TEMPLATE new file mode 100644 index 000000000..179e78f04 --- /dev/null +++ b/engine/client/strobe/r_strobe_template.h.TEMPLATE @@ -0,0 +1,64 @@ +/* +r_strobe_template.h - Software based strobing implementation + +Copyright (C) 2018 - fuzun * github.com/fuzun + +For information: +https://forums.blurbusters.com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. +*/ + +#if !defined R_STROBE_TEMPLATE_H && !defined STROBE_DISABLED +#define R_STROBE_TEMPLATE_H + +#include "r_strobe_api.h" + + +#define STROBE_TEMPLATE Strobe_Example +#define _STROBE_TEMPLATE_THIS self +#define STROBE_TEMPLATE_FUNC_main main +#define STROBE_TEMPLATE_FUNC_debughandler debugHandler + +// ===================== + +#define STROBE_TEMPLATE_s STROBE_TEMPLATE ## _s +#define STROBE_TEMPLATE_t STROBE_TEMPLATE ## _t +#define STROBE_TEMPLATE_priv_s STROBE_TEMPLATE ## _priv_s +#define STROBE_TEMPLATE_priv_t STROBE_TEMPLATE ## _priv_t +#define STROBE_TEMPLATE_THIS (* ## _STROBE_TEMPLATE__THIS ## ) +#define STROBE_TEMPLATE_THIS_PARAM STROBE_TEMPLATE_t ## ** ## _STROBE_TEMPLATE__THIS +#define STROBE_TEMPLATE_EXPORTEDFUNC_main STROBE_TEMPLATE ## _ ## STROBE_TEMPLATE_FUNC_main +#define STROBE_TEMPLATE_EXPORTEDFUNC_constructor STROBE_TEMPLATE ## _constructor +#define STROBE_TEMPLATE_EXPORTEDFUNC_destructor STROBE_TEMPLATE ## _destructor +#define STROBE_TEMPLATE_EXPORTEDFUNC_reinit STROBE_TEMPLATE ## _reinit + +typedef struct STROBE_TEMPLATE_s STROBE_TEMPLATE_t; +typedef struct STROBE_TEMPLATE_priv_s STROBE_TEMPLATE_priv_t; + + +typedef struct STROBE_TEMPLATE_s { + StrobeAPI_t base; + STROBE_TEMPLATE_priv_t *private; + void(*STROBE_TEMPLATE_FUNC_main)(STROBE_TEMPLATE_THIS_PARAM); + void(*STROBE_TEMPLATE_FUNC_debughandler)(STROBE_TEMPLATE_THIS_PARAM); +} STROBE_TEMPLATE_t; + +extern STROBE_TEMPLATE_t *STROBE_TEMPLATE; + +void STROBE_TEMPLATE_EXPORTEDFUNC_constructor(void **STROBE_TEMPLATE); +void STROBE_TEMPLATE_EXPORTEDFUNC_destructor(void **STROBE_TEMPLATE); +void STROBE_TEMPLATE_EXPORTEDFUNC_reinit(void **STROBE_TEMPLATE); +void STROBE_TEMPLATE_EXPORTEDFUNC_main(void **STROBE_TEMPLATE); + + +#endif \ No newline at end of file diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index c6ffc7a08..a0c6955ef 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -23,6 +23,8 @@ GNU General Public License for more details. #include "input.h" #include "gl_vidnt.h" +#include "strobe/r_strobe_core.h" + extern convar_t *renderinfo; convar_t *gl_allow_software; convar_t *gl_extensions; @@ -79,11 +81,6 @@ convar_t *r_fastsky; convar_t *r_vbo; convar_t *r_bump; -convar_t *r_strobe; -convar_t *r_strobe_swapinterval; -convar_t *r_strobe_debug; -convar_t *r_strobe_cooldown; - convar_t *mp_decals; convar_t *vid_displayfrequency; @@ -1011,27 +1008,6 @@ static void R_CheckVBO( void ) r_bump = Cvar_Get( "r_bump", def, flags, "enable bump-mapping (r_vbo required)" ); } -/* -=============== -R_initStrobe - -register strobe cvar -=============== -*/ -_inline void R_StrobeInit( void ) -{ - r_strobe = Cvar_Get( "r_strobe", "0", CVAR_ARCHIVE, "black frame replacement interval" ); - r_strobe_swapinterval = Cvar_Get( "r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval" ); - r_strobe_debug = Cvar_Get( "r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information" ); - r_strobe_cooldown = Cvar_Get( "r_strobe_cooldown", "3", CVAR_ARCHIVE, "strobe cooldown perios in secs" ); - - StrobeInfo.pCounter = 0; StrobeInfo.pBCounter = 0; StrobeInfo.pNCounter = 0; - StrobeInfo.pCounter = 0; StrobeInfo.nBCounter = 0; StrobeInfo.nNCounter = 0; - StrobeInfo.fCounter = 0; - StrobeInfo.deviation = 0.0; - StrobeInfo.cdTimer = 0.0; - StrobeInfo.frameInfo = (p_positive | f_normal); -} /* =============== @@ -1073,7 +1049,12 @@ qboolean R_Init( void ) R_InitImages(); R_SpriteInit(); R_StudioInit(); - R_StrobeInit(); + +#ifdef STROBE_ENABLED + R_InitStrobe(); + //StrobeInfo = new_Strobe(); +#endif + R_ClearDecals(); R_ClearScene(); diff --git a/engine/common/common.h b/engine/common/common.h index 320f89df4..d958bcf19 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -24,7 +24,7 @@ extern "C" { #include "backends.h" #include "defaults.h" -//#include "wrect.h" +#include "wrect.h" // // check if selected backend not allowed @@ -1081,6 +1081,8 @@ void Con_ClearAutoComplete(); // // console.c // +extern rectf_t con_rect; + void Con_Clear( void ); extern const char *svc_strings[256]; From f449716c25b0901f8e50b6d9f2feef476de29719 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 4 Mar 2018 02:01:40 +0300 Subject: [PATCH 12/35] Try to make gcc happy --- engine/client/strobe/r_strobe_api.c | 8 ++++---- engine/client/strobe/r_strobe_core.h | 4 ++-- engine/client/strobe/r_strobe_template.h.TEMPLATE | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 834bdd6e7..d08c713d8 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -383,7 +383,7 @@ static inline double func_experimental_Badness(StrobeAPI_t *self, qboolean PWMIn -size_t get_FrameCounter(StrobeAPI_t *self, counterType type) +static inline size_t get_FrameCounter(StrobeAPI_t *self, counterType type) { switch (type) { @@ -426,17 +426,17 @@ size_t get_FrameCounter(StrobeAPI_t *self, counterType type) return self->protected->fCounter; } -double get_Deviation(StrobeAPI_t *self) +static inline double get_Deviation(StrobeAPI_t *self) { return self->protected->deviation; } -double get_CooldownTimer(StrobeAPI_t *self) +static inline double get_CooldownTimer(StrobeAPI_t *self) { return self->protected->cdTimer; } -double get_currentFPS(StrobeAPI_t *self) +static inline double get_currentFPS(StrobeAPI_t *self) { // Copied from SCR_DrawFps // This way until current fps becomes global!!! diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 4abf2a543..80517605e 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -33,8 +33,8 @@ See the GNU General Public License for more details. #define STROBE_CORE_t STROBE_CORE ## _t #define STROBE_CORE_priv_s STROBE_CORE ## _priv_s #define STROBE_CORE_priv_t STROBE_CORE ## _priv_t -#define STROBE_CORE_THIS (* ## _STROBE_CORE_THIS ## ) -#define STROBE_CORE_THIS_PARAM STROBE_CORE_t ## ** ## _STROBE_CORE_THIS +#define STROBE_CORE_THIS (*_STROBE_CORE_THIS ## ) +#define STROBE_CORE_THIS_PARAM STROBE_CORE_t**_STROBE_CORE_THIS #define STROBE_CORE_EXPORTEDFUNC_main STROBE_CORE ## _ ## STROBE_CORE_FUNC_main #define STROBE_CORE_EXPORTEDFUNC_constructor STROBE_CORE ## _constructor #define STROBE_CORE_EXPORTEDFUNC_destructor STROBE_CORE ## _destructor diff --git a/engine/client/strobe/r_strobe_template.h.TEMPLATE b/engine/client/strobe/r_strobe_template.h.TEMPLATE index 179e78f04..07032f89b 100644 --- a/engine/client/strobe/r_strobe_template.h.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.h.TEMPLATE @@ -35,8 +35,8 @@ See the GNU General Public License for more details. #define STROBE_TEMPLATE_t STROBE_TEMPLATE ## _t #define STROBE_TEMPLATE_priv_s STROBE_TEMPLATE ## _priv_s #define STROBE_TEMPLATE_priv_t STROBE_TEMPLATE ## _priv_t -#define STROBE_TEMPLATE_THIS (* ## _STROBE_TEMPLATE__THIS ## ) -#define STROBE_TEMPLATE_THIS_PARAM STROBE_TEMPLATE_t ## ** ## _STROBE_TEMPLATE__THIS +#define STROBE_TEMPLATE_THIS (*_STROBE_TEMPLATE__THIS ## ) +#define STROBE_TEMPLATE_THIS_PARAM STROBE_TEMPLATE_t**_STROBE_TEMPLATE__THIS #define STROBE_TEMPLATE_EXPORTEDFUNC_main STROBE_TEMPLATE ## _ ## STROBE_TEMPLATE_FUNC_main #define STROBE_TEMPLATE_EXPORTEDFUNC_constructor STROBE_TEMPLATE ## _constructor #define STROBE_TEMPLATE_EXPORTEDFUNC_destructor STROBE_TEMPLATE ## _destructor From d33d3d98544fe20844253e8db34411c435bc73dd Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 4 Mar 2018 02:11:41 +0300 Subject: [PATCH 13/35] Try to make gcc happy #2 --- engine/client/strobe/r_strobe_api.c | 2 +- engine/client/strobe/r_strobe_api.h | 2 +- engine/client/strobe/r_strobe_core.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index d08c713d8..e61b81e2a 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -1,5 +1,5 @@ /* -r_strobe.c - Software based strobing implementation +r_strobe_api.c - Software based strobing implementation Copyright (C) 2018 * fuzun diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index ac4dd4d4d..27e6738a0 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -1,5 +1,5 @@ /* -r_strobe.c - Software based strobing implementation +r_strobe_api.h - Software based strobing implementation Copyright (C) 2018 * fuzun diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 80517605e..caf1a4dc0 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -33,9 +33,9 @@ See the GNU General Public License for more details. #define STROBE_CORE_t STROBE_CORE ## _t #define STROBE_CORE_priv_s STROBE_CORE ## _priv_s #define STROBE_CORE_priv_t STROBE_CORE ## _priv_t -#define STROBE_CORE_THIS (*_STROBE_CORE_THIS ## ) +#define STROBE_CORE_THIS (*_STROBE_CORE_THIS) #define STROBE_CORE_THIS_PARAM STROBE_CORE_t**_STROBE_CORE_THIS -#define STROBE_CORE_EXPORTEDFUNC_main STROBE_CORE ## _ ## STROBE_CORE_FUNC_main +#define STROBE_CORE_EXPORTEDFUNC_main STROBE_CORE ## _STROBE_CORE_FUNC_main #define STROBE_CORE_EXPORTEDFUNC_constructor STROBE_CORE ## _constructor #define STROBE_CORE_EXPORTEDFUNC_destructor STROBE_CORE ## _destructor #define STROBE_CORE_EXPORTEDFUNC_reinit STROBE_CORE ## _reinit From 427c135d92f387a4799146bf27e3522e48c5ef4e Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 4 Mar 2018 02:34:46 +0300 Subject: [PATCH 14/35] Try to make gcc happy #3 --- engine/client/strobe/r_strobe_api.c | 56 ++++++++++++++-------------- engine/client/strobe/r_strobe_core.c | 8 ++-- engine/client/strobe/r_strobe_core.h | 6 ++- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index e61b81e2a..f1d423cd3 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -35,7 +35,7 @@ convar_t *r_strobe_swapinterval; convar_t *r_strobe_debug; convar_t *r_strobe_cooldown; -static inline double func_helper_StandardDeviation(const double *data, int n) +_inline double func_helper_StandardDeviation(const double *data, int n) { double mean = 0.0, sum_deviation = 0.0; int i; @@ -50,7 +50,7 @@ static inline double func_helper_StandardDeviation(const double *data, int n) } -static inline void GL_GenerateBlackFrame(void) // Generates partial or full black frame +_inline void GL_GenerateBlackFrame(void) // Generates partial or full black frame { if (CL_IsInConsole()) // No strobing on the console { @@ -73,7 +73,7 @@ static inline void GL_GenerateBlackFrame(void) // Generates partial or full blac } } -static inline double func_helper_getCooldown(StrobeAPI_t *self) +_inline double func_helper_getCooldown(StrobeAPI_t *self) { if ((double)abs(r_strobe_cooldown->integer) - self->protected->cdTimer <= (double)abs(r_strobe_cooldown->integer)) { @@ -85,7 +85,7 @@ static inline double func_helper_getCooldown(StrobeAPI_t *self) } } -static inline qboolean func_helper_isPhaseInverted(StrobeAPI_t *self) +_inline qboolean func_helper_isPhaseInverted(StrobeAPI_t *self) { if (!!(self->protected->frameInfo & p_inverted)) return true; @@ -93,7 +93,7 @@ static inline qboolean func_helper_isPhaseInverted(StrobeAPI_t *self) return false; } -static inline qboolean func_helper_isNormal(StrobeAPI_t *self) +_inline qboolean func_helper_isNormal(StrobeAPI_t *self) { if (!!(self->protected->frameInfo & f_normal)) return true; @@ -101,7 +101,7 @@ static inline qboolean func_helper_isNormal(StrobeAPI_t *self) return false; } -static inline qboolean func_helper_isPositive(StrobeAPI_t *self) // ... +_inline qboolean func_helper_isPositive(StrobeAPI_t *self) // ... { if (!!(self->protected->frameInfo & p_positive)) return true; @@ -109,7 +109,7 @@ static inline qboolean func_helper_isPositive(StrobeAPI_t *self) // ... return false; } -static inline double func_helper_effectiveFPS(StrobeAPI_t *self) +_inline double func_helper_effectiveFPS(StrobeAPI_t *self) { int strobeInterval = r_strobe->integer; double eFPS; @@ -127,7 +127,7 @@ static inline double func_helper_effectiveFPS(StrobeAPI_t *self) return eFPS; } -static inline void func_helper_GenerateDiffBar(StrobeAPI_t *self, char *src, int size, char type) +_inline void func_helper_GenerateDiffBar(StrobeAPI_t *self, char *src, int size, char type) { char _barCounter = 0; int diff_NB = 0; @@ -243,23 +243,23 @@ static inline void func_helper_GenerateDiffBar(StrobeAPI_t *self, char *src, int } -static inline int func_pwmsimulation_Frequency(StrobeAPI_t *self) +_inline int func_pwmsimulation_Frequency(StrobeAPI_t *self) { return (int)round((1 / ((1.0f / self->get.CurrentFPS(self))*(abs(r_strobe->integer) + 1)))); } -static inline double func_pwmsimulation_DutyCycle(void) +_inline double func_pwmsimulation_DutyCycle(void) { int strobeInterval = r_strobe->integer; return (((1.0f / (abs(strobeInterval) + 1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1)); } -static inline double func_pwmsimulation_PositivePhaseShift(StrobeAPI_t *self) +_inline double func_pwmsimulation_PositivePhaseShift(StrobeAPI_t *self) { return !!(self->protected->frameInfo & p_inverted) ? (1.0f / self->get.CurrentFPS(self)) * 1000 : 0.0f; } -static inline double func_pwmsimulation_NegativePhaseShift(StrobeAPI_t *self) +_inline double func_pwmsimulation_NegativePhaseShift(StrobeAPI_t *self) { if (!!(self->protected->frameInfo & p_inverted)) return abs(r_strobe->integer) * (1.0f / self->get.CurrentFPS(self)) * 1000; @@ -267,12 +267,12 @@ static inline double func_pwmsimulation_NegativePhaseShift(StrobeAPI_t *self) return 0.0; } -static inline double func_pwmsimulation_Period(StrobeAPI_t *self) +_inline double func_pwmsimulation_Period(StrobeAPI_t *self) { return (((1.0f / self->get.CurrentFPS(self))*(abs(r_strobe->integer) + 1)) * 1000); } -static inline double func_helper_GeometricMean(double x, double y) +_inline double func_helper_GeometricMean(double x, double y) { return sqrt(abs(x * y)); /* @@ -284,13 +284,13 @@ static inline double func_helper_GeometricMean(double x, double y) */ } -static inline double func_helper_ArithmeticMean(double x, double y) +_inline double func_helper_ArithmeticMean(double x, double y) { return (x + y) / 2; } -static inline double func_brightnessreduction_ActualBrightnessReduction(StrobeAPI_t *self) +_inline double func_brightnessreduction_ActualBrightnessReduction(StrobeAPI_t *self) { double currentFPS = self->get.CurrentFPS(self); double effectiveFPS = self->Helpers.effectiveFPS(self); @@ -298,28 +298,28 @@ static inline double func_brightnessreduction_ActualBrightnessReduction(StrobeAP return lossCalculator(currentFPS, effectiveFPS); } -static inline double func_brightnessreduction_LogarithmicBrightnessReduction(StrobeAPI_t *self, double base) +_inline double func_brightnessreduction_LogarithmicBrightnessReduction(StrobeAPI_t *self, double base) { return lossCalculator( log(base), log(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); } -static inline double func_brightnessreduction_SquareBrightnessReduction(StrobeAPI_t *self, double base) +_inline double func_brightnessreduction_SquareBrightnessReduction(StrobeAPI_t *self, double base) { return lossCalculator( sqrt(base), sqrt(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); } -static inline double func_brightnessreduction_CubeBrightnessReduction(StrobeAPI_t *self, double base) +_inline double func_brightnessreduction_CubeBrightnessReduction(StrobeAPI_t *self, double base) { return lossCalculator( cbrt(base), cbrt(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); } -static inline double func_brightnessreduction_OtherBrightnessReduction(StrobeAPI_t *self, double base, double(*reductionFunction)(double)) +_inline double func_brightnessreduction_OtherBrightnessReduction(StrobeAPI_t *self, double base, double(*reductionFunction)(double)) { return lossCalculator(reductionFunction(base), reductionFunction(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self))); } -static inline double func_experimental_Badness_Reducted(StrobeAPI_t *self, qboolean PWMInvolved) +_inline double func_experimental_Badness_Reducted(StrobeAPI_t *self, qboolean PWMInvolved) { double badness; int diffP_NB, diffN_NB; @@ -355,7 +355,7 @@ static inline double func_experimental_Badness_Reducted(StrobeAPI_t *self, qbool return badness; } -static inline double func_experimental_Badness(StrobeAPI_t *self, qboolean PWMInvolved) +_inline double func_experimental_Badness(StrobeAPI_t *self, qboolean PWMInvolved) { int diffP_NB, diffN_NB; diffP_NB = (self->protected->pNCounter - self->protected->pBCounter); @@ -383,7 +383,7 @@ static inline double func_experimental_Badness(StrobeAPI_t *self, qboolean PWMIn -static inline size_t get_FrameCounter(StrobeAPI_t *self, counterType type) +_inline size_t get_FrameCounter(StrobeAPI_t *self, counterType type) { switch (type) { @@ -426,17 +426,17 @@ static inline size_t get_FrameCounter(StrobeAPI_t *self, counterType type) return self->protected->fCounter; } -static inline double get_Deviation(StrobeAPI_t *self) +_inline double get_Deviation(StrobeAPI_t *self) { return self->protected->deviation; } -static inline double get_CooldownTimer(StrobeAPI_t *self) +_inline double get_CooldownTimer(StrobeAPI_t *self) { return self->protected->cdTimer; } -static inline double get_currentFPS(StrobeAPI_t *self) +_inline double get_currentFPS(StrobeAPI_t *self) { // Copied from SCR_DrawFps // This way until current fps becomes global!!! @@ -458,7 +458,7 @@ static inline double get_currentFPS(StrobeAPI_t *self) return framerate; } -static inline void GenerateDebugStatistics(StrobeAPI_t *self, char *src, int size) +_inline void GenerateDebugStatistics(StrobeAPI_t *self, char *src, int size) { char diffBarP[128], diffBarN[128], diffBarT[128]; @@ -539,7 +539,7 @@ static inline void GenerateDebugStatistics(StrobeAPI_t *self, char *src, int siz } -static inline void ProcessFrame(StrobeAPI_t *self) +_inline void ProcessFrame(StrobeAPI_t *self) { if (self->protected->cdTriggered != 0) { diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index d88f48df7..30d58870b 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -222,7 +222,7 @@ static void R_Strobe(STROBE_CORE_THIS_PARAM) } -static inline void debugDrawer(STROBE_CORE_THIS_PARAM) +_inline void debugDrawer(STROBE_CORE_THIS_PARAM) { rgba_t color; char debugStr[2048]; // Heap allocation ? @@ -307,13 +307,13 @@ void STROBE_CORE_EXPORTEDFUNC_destructor(void **STROBE_CORE) void STROBE_CORE_EXPORTEDFUNC_reinit(void **STROBE_CORE) { - STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + //STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; if (!(*STROBE_CORE)) { - STROBE_CORE_EXPORTEDFUNC_destructor(instance); + STROBE_CORE_EXPORTEDFUNC_destructor(STROBE_CORE); } - STROBE_CORE_EXPORTEDFUNC_constructor(instance); + STROBE_CORE_EXPORTEDFUNC_constructor(STROBE_CORE); } diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index caf1a4dc0..3d50c6cf1 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -52,12 +52,14 @@ typedef struct STROBE_CORE_s { void(*STROBE_CORE_FUNC_debughandler)(STROBE_CORE_THIS_PARAM); } STROBE_CORE_t; -extern STROBE_CORE_t *STROBE_CORE; - void STROBE_CORE_EXPORTEDFUNC_constructor(void **STROBE_CORE); void STROBE_CORE_EXPORTEDFUNC_destructor(void **STROBE_CORE); void STROBE_CORE_EXPORTEDFUNC_reinit(void **STROBE_CORE); void STROBE_CORE_EXPORTEDFUNC_main(void **STROBE_CORE); +extern STROBE_CORE_t *STROBE_CORE; + + + #endif \ No newline at end of file From ebc5b4989f03b33978cf53ea6be89f057efeb5c1 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sun, 4 Mar 2018 02:57:07 +0300 Subject: [PATCH 15/35] Try to make gcc happy #4 --- engine/client/strobe/r_strobe_core.c | 4 ++-- engine/client/strobe/r_strobe_core.h | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index 30d58870b..fc7bfdc15 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -105,8 +105,8 @@ static void R_Strobe(STROBE_CORE_THIS_PARAM) /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ STROBE_CORE_THIS->base.protected->fCounter == UINT_MAX) // Reset stats after some time { - - STROBE_CORE_EXPORTEDFUNC_reinit(&STROBE_CORE_THIS); + + STROBE_CORE_EXPORTEDFUNC_reinit(*(void***)&_STROBE_CORE_THIS); R_Strobe(&STROBE_CORE_THIS); /* STROBE_CORE_THIS->base.protected->pCounter = 0; STROBE_CORE_THIS->base.protected->pBCounter = 0; STROBE_CORE_THIS->base.protected->pNCounter = 0; diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 3d50c6cf1..3d8d183e7 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -28,7 +28,6 @@ See the GNU General Public License for more details. #define STROBE_CORE_FUNC_main main #define STROBE_CORE_FUNC_debughandler debugDrawer - #define STROBE_CORE_s STROBE_CORE ## _s #define STROBE_CORE_t STROBE_CORE ## _t #define STROBE_CORE_priv_s STROBE_CORE ## _priv_s @@ -40,11 +39,9 @@ See the GNU General Public License for more details. #define STROBE_CORE_EXPORTEDFUNC_destructor STROBE_CORE ## _destructor #define STROBE_CORE_EXPORTEDFUNC_reinit STROBE_CORE ## _reinit - typedef struct STROBE_CORE_s STROBE_CORE_t; typedef struct STROBE_CORE_priv_s STROBE_CORE_priv_t; - typedef struct STROBE_CORE_s { StrobeAPI_t base; STROBE_CORE_priv_t *private; @@ -59,7 +56,4 @@ void STROBE_CORE_EXPORTEDFUNC_main(void **STROBE_CORE); extern STROBE_CORE_t *STROBE_CORE; - - - #endif \ No newline at end of file From fa412c38f922371511483b0b30ba81b7f5cecf02 Mon Sep 17 00:00:00 2001 From: fuzun Date: Fri, 9 Mar 2018 21:39:24 +0300 Subject: [PATCH 16/35] Refactored --- engine/client/cl_view.c | 4 +- engine/client/gl_rmain.c | 5 +- engine/client/strobe/r_strobe_api.c | 645 +++++++++--------- engine/client/strobe/r_strobe_api.h | 155 +++-- .../client/strobe/r_strobe_base_protected_.h | 30 +- engine/client/strobe/r_strobe_core.c | 273 ++++---- engine/client/strobe/r_strobe_core.h | 53 +- .../strobe/r_strobe_template.c.TEMPLATE | 44 +- .../strobe/r_strobe_template.h.TEMPLATE | 22 +- engine/client/vid_common.c | 5 +- 10 files changed, 579 insertions(+), 657 deletions(-) diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index b76a59311..c22c2b2a1 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -423,8 +423,8 @@ void V_PostRender( void ) SCR_DrawFPS(); #ifdef STROBE_ENABLED - if (STROBE_CORE) - STROBE_CORE->STROBE_CORE_FUNC_debughandler(&STROBE_CORE); + if ( STROBE_CORE ) + STROBE_CORE->STROBE_CORE_FUNC_debughandler( &STROBE_CORE ); #endif SCR_DrawPos(); diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index b2befcf6c..0c6ff282f 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1336,12 +1336,11 @@ R_EndFrame void R_EndFrame( void ) { #ifdef STROBE_ENABLED - Strobe_Invoker((void**)(&STROBE_CORE), STROBE_CORE_EXPORTEDFUNC_constructor, STROBE_CORE_EXPORTEDFUNC_main, STROBE_CORE_EXPORTEDFUNC_destructor); + StrobeAPI.Invoker( (void **)( &STROBE_CORE ), STROBE_CORE_EXPORTEDFUNC_constructor, STROBE_CORE_EXPORTEDFUNC_main, STROBE_CORE_EXPORTEDFUNC_destructor ); #else // flush any remaining 2D bits - R_Set2DMode(false); + R_Set2DMode( false ); #endif - #ifdef XASH_SDL SDL_GL_SwapWindow( host.hWnd ); diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index f1d423cd3..fd63a95a3 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -1,10 +1,10 @@ /* r_strobe_api.c - Software based strobing implementation -Copyright (C) 2018 * fuzun +Copyright (C) 2018 - fuzun * github/fuzun For information: - https://forums.blurbusters.com + https://forums.blurbusters.com/viewtopic.php?f=7&t=3815&p=30401 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,64 +20,57 @@ See the GNU General Public License for more details. #if !defined XASH_DEDICATED && !defined STROBE_DISABLED -#include -#include #include "r_strobe_api.h" -#include "r_strobe_base_protected_.h" -#include "gl_local.h" #include "client.h" +#include "gl_local.h" +#include "r_strobe_base_protected_.h" +#define lossCalculator( x, y ) ( ( ( x ) - ( y ) ) * 100.0 / ( x ) ) // x : supposed y : current -#define lossCalculator(x, y) (((x) - (y)) * 100.0 / (x)) // x : supposed y : current - -convar_t *r_strobe; -convar_t *r_strobe_swapinterval; -convar_t *r_strobe_debug; -convar_t *r_strobe_cooldown; +StrobeAPI_EXPORTS_t StrobeAPI; -_inline double func_helper_StandardDeviation(const double *data, int n) +_inline double func_helper_StandardDeviation( const double *data, int n ) { double mean = 0.0, sum_deviation = 0.0; int i; - for (i = 0; i < n; ++i) + for ( i = 0; i < n; ++i ) { mean += data[i]; } mean = mean / n; - for (i = 0; i < n; ++i) - sum_deviation += (data[i] - mean)*(data[i] - mean); - return sqrt(sum_deviation / n); + for ( i = 0; i < n; ++i ) + sum_deviation += ( data[i] - mean ) * ( data[i] - mean ); + return sqrt( sum_deviation / n ); } - -_inline void GL_GenerateBlackFrame(void) // Generates partial or full black frame +_inline void GL_GenerateBlackFrame( void ) // Generates partial or full black frame { - if (CL_IsInConsole()) // No strobing on the console + if ( CL_IsInConsole( ) ) // No strobing on the console { - if (!vid_fullscreen->integer) // Disable when not fullscreen due to viewport problems + if ( !vid_fullscreen->integer ) // Disable when not fullscreen due to viewport problems { - R_Set2DMode(false); + R_Set2DMode( false ); return; } - pglEnable(GL_SCISSOR_TEST); - pglScissor(con_rect.x, (-con_rect.y) - (con_rect.h * 1.25), con_rect.w, con_rect.h); // Preview strobe setting on static - pglClearColor(0.0f, 0.0f, 0.0f, 1.0f); - pglClear(GL_COLOR_BUFFER_BIT); - pglDisable(GL_SCISSOR_TEST); + pglEnable( GL_SCISSOR_TEST ); + pglScissor( con_rect.x, ( -con_rect.y ) - ( con_rect.h * 1.25 ), con_rect.w, con_rect.h ); // Preview strobe setting on static + pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + pglClear( GL_COLOR_BUFFER_BIT ); + pglDisable( GL_SCISSOR_TEST ); } else { //pglFlush(); // ? - pglClearColor(0.0f, 0.0f, 0.0f, 1.0f); - pglClear(GL_COLOR_BUFFER_BIT); + pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + pglClear( GL_COLOR_BUFFER_BIT ); } } -_inline double func_helper_getCooldown(StrobeAPI_t *self) +_inline double func_helper_getCooldown( StrobeAPI_t *self ) { - if ((double)abs(r_strobe_cooldown->integer) - self->protected->cdTimer <= (double)abs(r_strobe_cooldown->integer)) + if ( 0 <= self->protected->cdTimer ) { - return ((double)abs(r_strobe_cooldown->integer) - self->protected->cdTimer); + return ( (double)abs( StrobeAPI.r_strobe_cooldown->integer ) - self->protected->cdTimer ); } else { @@ -85,86 +78,83 @@ _inline double func_helper_getCooldown(StrobeAPI_t *self) } } -_inline qboolean func_helper_isPhaseInverted(StrobeAPI_t *self) +_inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *self ) { - if (!!(self->protected->frameInfo & p_inverted)) + if ( self->protected->frameInfo & p_inverted ) return true; else return false; } -_inline qboolean func_helper_isNormal(StrobeAPI_t *self) +_inline qboolean func_helper_isNormal( StrobeAPI_t *self ) { - if (!!(self->protected->frameInfo & f_normal)) + if ( self->protected->frameInfo & f_normal ) return true; else return false; } -_inline qboolean func_helper_isPositive(StrobeAPI_t *self) // ... +_inline qboolean func_helper_isPositive( StrobeAPI_t *self ) // ... { - if (!!(self->protected->frameInfo & p_positive)) + if ( self->protected->frameInfo & p_positive ) return true; else return false; } -_inline double func_helper_effectiveFPS(StrobeAPI_t *self) +_inline double func_helper_effectiveFPS( StrobeAPI_t *self ) { - int strobeInterval = r_strobe->integer; + int strobeInterval = StrobeAPI.r_strobe->integer; double eFPS; - if (strobeInterval > 0) + if ( strobeInterval > 0 ) { - eFPS = (self->get.CurrentFPS(self)) / (strobeInterval + 1); + eFPS = ( self->Helpers.CurrentFPS( self ) ) / ( strobeInterval + 1 ); } - else if (strobeInterval < 0) + else if ( strobeInterval < 0 ) { - strobeInterval = abs(strobeInterval); - eFPS = (self->get.CurrentFPS(self) * strobeInterval) / (strobeInterval + 1); + strobeInterval = abs( strobeInterval ); + eFPS = ( self->Helpers.CurrentFPS( self ) * strobeInterval ) / ( strobeInterval + 1 ); } else eFPS = 0.0; return eFPS; } -_inline void func_helper_GenerateDiffBar(StrobeAPI_t *self, char *src, int size, char type) +_inline void func_helper_GenerateDiffBar( StrobeAPI_t *self, char *src, int size, char type ) { char _barCounter = 0; - int diff_NB = 0; - int diff = 0; + int diff_NB = 0; + int diff = 0; + int _a, _b; qboolean Neg = false; - switch (type) + switch ( type ) { - case(0): // Positive Difference + case ( 0 ): // Positive Difference { - diff_NB = (self->protected->pNCounter - self->protected->pBCounter); + diff_NB = ( self->protected->pNCounter - self->protected->pBCounter ); - if (self->protected->pCounter != 0) - diff = round(abs(diff_NB) * 100 / self->protected->pCounter); + if ( self->protected->pCounter ) + diff = round( abs( diff_NB ) * 100 / self->protected->pCounter ); break; } - case(1): // Negative Difference + case ( 1 ): // Negative Difference { - diff_NB = (self->protected->nNCounter - self->protected->nBCounter); + diff_NB = ( self->protected->nNCounter - self->protected->nBCounter ); - if (self->protected->nCounter != 0) - diff = round(abs(diff_NB) * 100 / self->protected->nCounter); + if ( self->protected->nCounter ) + diff = round( abs( diff_NB ) * 100 / self->protected->nCounter ); break; } - case(2): // Difference of difference + case ( 2 ): // Difference of difference { - if (self->protected->nCounter != 0 && self->protected->pCounter != 0) + if ( self->protected->nCounter && self->protected->pCounter ) { - // FIX THE MESS! - int a = (abs(self->protected->pNCounter - self->protected->pBCounter) * 100 / self->protected->pCounter); - int b = (abs(self->protected->nNCounter - self->protected->nBCounter) * 100 / self->protected->nCounter); - int x = ((int)(self->protected->pNCounter - self->protected->pBCounter) > 0); - int y = ((int)(self->protected->nNCounter - self->protected->nBCounter) > 0); - diff = abs((x ? a : (-a)) \ - - ((y ? b : (-b)))); // Min 0 Max 200 + _a = ( abs( self->protected->pNCounter - self->protected->pBCounter ) * 100 / self->protected->pCounter ); + _b = ( abs( self->protected->nNCounter - self->protected->nBCounter ) * 100 / self->protected->nCounter ); + diff = abs( ( ( (int)( self->protected->pNCounter - self->protected->pBCounter ) > 0 ) ? _a : ( -_a ) ) - ( ( ( (int)( self->protected->nNCounter - self->protected->nBCounter ) > 0 ) ? _b : ( -_b ) ) ) ); // Min 0 Max 200 } break; } @@ -172,109 +162,108 @@ _inline void func_helper_GenerateDiffBar(StrobeAPI_t *self, char *src, int size, break; } - if (diff_NB < 0) + if ( diff_NB < 0 ) Neg = true; - Q_snprintf(src, size, "^3["); + Q_snprintf( src, size, "^3[" ); - for (_barCounter = 0; _barCounter <= 20; ++_barCounter) + for ( _barCounter = 0; _barCounter <= 20; ++_barCounter ) { - if (_barCounter == 10) + if ( _barCounter == 10 ) { - Q_strcat(src, "O"); + Q_strcat( src, "O" ); } - else if (_barCounter < 10) + else if ( _barCounter < 10 ) { - if (type == 2) + if ( type == 2 ) { - if (100 - (_barCounter * 11) <= diff / 2) - Q_strcat(src, "^4=^3"); + if ( 100 - ( _barCounter * 11 ) <= diff / 2 ) + Q_strcat( src, "^4=^3" ); else - Q_strcat(src, "^3="); + Q_strcat( src, "^3=" ); } else { - if (Neg) + if ( Neg ) { - if (100 - (_barCounter * 11) <= diff) - Q_strcat(src, "^4=^3"); + if ( 100 - ( _barCounter * 11 ) <= diff ) + Q_strcat( src, "^4=^3" ); else - Q_strcat(src, "^3="); + Q_strcat( src, "^3=" ); } else { - Q_strcat(src, "^3="); + Q_strcat( src, "^3=" ); } } } - else if (_barCounter > 10) + else if ( _barCounter > 10 ) { - if (type == 2) + if ( type == 2 ) { - if (((_barCounter - 11) * 11) >= diff / 2) - Q_strcat(src, "^3="); + if ( ( ( _barCounter - 11 ) * 11 ) >= diff / 2 ) + Q_strcat( src, "^3=" ); else - Q_strcat(src, "^4=^3"); + Q_strcat( src, "^4=^3" ); } else { - if (Neg) + if ( Neg ) { - Q_strcat(src, "^3="); + Q_strcat( src, "^3=" ); } else { - if (((_barCounter - 11) * 11) >= diff) - Q_strcat(src, "^3="); + if ( ( ( _barCounter - 11 ) * 11 ) >= diff ) + Q_strcat( src, "^3=" ); else - Q_strcat(src, "^4=^3"); + Q_strcat( src, "^4=^3" ); } } } } - if (type == 2) + if ( type == 2 ) { - Q_strcat(src, va("] - %4d", diff)); + Q_strcat( src, va( "] - %4d", diff ) ); } else { - Q_strcat(src, va("] - %4d%%", (Neg ? -diff : diff))); + Q_strcat( src, va( "] - %4d%%", ( Neg ? -diff : diff ) ) ); } } - -_inline int func_pwmsimulation_Frequency(StrobeAPI_t *self) +_inline int func_pwmsimulation_Frequency( StrobeAPI_t *self ) { - return (int)round((1 / ((1.0f / self->get.CurrentFPS(self))*(abs(r_strobe->integer) + 1)))); + return (int)round( ( 1 / ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) ) ); } -_inline double func_pwmsimulation_DutyCycle(void) +_inline double func_pwmsimulation_DutyCycle( void ) { - int strobeInterval = r_strobe->integer; - return (((1.0f / (abs(strobeInterval) + 1)) * 100) * (strobeInterval < 0 ? -strobeInterval : 1)); + int strobeInterval = StrobeAPI.r_strobe->integer; + return ( ( ( 1.0f / ( abs( strobeInterval ) + 1 ) ) * 100 ) * ( strobeInterval < 0 ? -strobeInterval : 1 ) ); } -_inline double func_pwmsimulation_PositivePhaseShift(StrobeAPI_t *self) +_inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *self ) { - return !!(self->protected->frameInfo & p_inverted) ? (1.0f / self->get.CurrentFPS(self)) * 1000 : 0.0f; + return !!( self->protected->frameInfo & p_inverted ) ? ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000 : 0.0f; } -_inline double func_pwmsimulation_NegativePhaseShift(StrobeAPI_t *self) +_inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *self ) { - if (!!(self->protected->frameInfo & p_inverted)) - return abs(r_strobe->integer) * (1.0f / self->get.CurrentFPS(self)) * 1000; + if ( !!( self->protected->frameInfo & p_inverted ) ) + return abs( StrobeAPI.r_strobe->integer ) * ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; else return 0.0; } -_inline double func_pwmsimulation_Period(StrobeAPI_t *self) +_inline double func_pwmsimulation_Period( StrobeAPI_t *self ) { - return (((1.0f / self->get.CurrentFPS(self))*(abs(r_strobe->integer) + 1)) * 1000); + return ( ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) * 1000 ); } -_inline double func_helper_GeometricMean(double x, double y) +_inline double func_helper_GeometricMean( double x, double y ) { - return sqrt(abs(x * y)); + return sqrt( abs( x * y ) ); /* int multiply = (x * y); if (multiply >= 0) @@ -284,141 +273,134 @@ _inline double func_helper_GeometricMean(double x, double y) */ } -_inline double func_helper_ArithmeticMean(double x, double y) +_inline double func_helper_ArithmeticMean( double x, double y ) { - return (x + y) / 2; + return ( x + y ) / 2; } - -_inline double func_brightnessreduction_ActualBrightnessReduction(StrobeAPI_t *self) +_inline double func_brightnessreduction_ActualBrightnessReduction( StrobeAPI_t *self ) { - double currentFPS = self->get.CurrentFPS(self); - double effectiveFPS = self->Helpers.effectiveFPS(self); + double currentFPS = self->Helpers.CurrentFPS( self ); + double effectiveFPS = self->Helpers.effectiveFPS( self ); //return ((currentFPS - effectiveFPS) * 100.0 / currentFPS); - return lossCalculator(currentFPS, effectiveFPS); + return lossCalculator( currentFPS, effectiveFPS ); } -_inline double func_brightnessreduction_LogarithmicBrightnessReduction(StrobeAPI_t *self, double base) +_inline double func_brightnessreduction_LogarithmicBrightnessReduction( StrobeAPI_t *self, double base ) { - - return lossCalculator( log(base), log(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); + return lossCalculator( log( base ), log( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_SquareBrightnessReduction(StrobeAPI_t *self, double base) +_inline double func_brightnessreduction_SquareBrightnessReduction( StrobeAPI_t *self, double base ) { - return lossCalculator( sqrt(base), sqrt(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); + return lossCalculator( sqrt( base ), sqrt( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_CubeBrightnessReduction(StrobeAPI_t *self, double base) +_inline double func_brightnessreduction_CubeBrightnessReduction( StrobeAPI_t *self, double base ) { - return lossCalculator( cbrt(base), cbrt(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self)) ); + return lossCalculator( cbrt( base ), cbrt( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_OtherBrightnessReduction(StrobeAPI_t *self, double base, double(*reductionFunction)(double)) +_inline double func_brightnessreduction_OtherBrightnessReduction( StrobeAPI_t *self, double base, double ( *reductionFunction )( double ) ) { - return lossCalculator(reductionFunction(base), reductionFunction(base * self->Helpers.effectiveFPS(self) / self->get.CurrentFPS(self))); + return lossCalculator( reductionFunction( base ), reductionFunction( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_experimental_Badness_Reducted(StrobeAPI_t *self, qboolean PWMInvolved) +_inline double func_experimental_Badness_Reducted( StrobeAPI_t *self, qboolean PWMInvolved ) { double badness; int diffP_NB, diffN_NB; - diffP_NB = (self->protected->pNCounter - self->protected->pBCounter); - diffN_NB = (self->protected->nNCounter - self->protected->nBCounter); + diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); + diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); double diffP = 0.0, diffN = 0.0; double Diff; - if (self->protected->pCounter != 0) - diffP = round(abs(diffP_NB) * 100 / self->protected->pCounter); + if ( self->protected->pCounter ) + diffP = round( abs( diffP_NB ) * 100 / self->protected->pCounter ); - if (self->protected->nCounter != 0) - diffN = round(abs(diffN_NB) * 100 / self->protected->nCounter); + if ( self->protected->nCounter ) + diffN = round( abs( diffN_NB ) * 100 / self->protected->nCounter ); - if (diffP_NB < 0.0) + if ( diffP_NB < 0.0 ) diffP = -diffP; - if (diffN_NB < 0.0) + if ( diffN_NB < 0.0 ) diffN = -diffN; - Diff = fabs(diffP - diffN); + Diff = fabs( diffP - diffN ); - - if (Diff < 0.0) + if ( Diff < 0.0 ) Diff = 0.0; - else if (Diff > 200.0) + else if ( Diff > 200.0 ) Diff = 200.0; - - badness = -log((200 - Diff) / (Diff)); - if (PWMInvolved) - return (badness * func_pwmsimulation_Period(self)); + badness = -log( ( 200 - Diff ) / ( Diff ) ); + + if ( PWMInvolved ) + return ( badness * func_pwmsimulation_Period( self ) ); else return badness; } -_inline double func_experimental_Badness(StrobeAPI_t *self, qboolean PWMInvolved) +_inline double func_experimental_Badness( StrobeAPI_t *self, qboolean PWMInvolved ) { int diffP_NB, diffN_NB; - diffP_NB = (self->protected->pNCounter - self->protected->pBCounter); - diffN_NB = (self->protected->nNCounter - self->protected->nBCounter); + diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); + diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); double diffP = 0.0, diffN = 0.0; - - if (self->protected->pCounter != 0) - diffP = round(abs(diffP_NB) * 100 / self->protected->pCounter); - if (self->protected->nCounter != 0) - diffN = round(abs(diffN_NB) * 100 / self->protected->nCounter); + if ( self->protected->pCounter ) + diffP = round( abs( diffP_NB ) * 100 / self->protected->pCounter ); + if ( self->protected->nCounter ) + diffN = round( abs( diffN_NB ) * 100 / self->protected->nCounter ); - double absoluteDifference = fabs(diffP - diffN); - if (absoluteDifference > 100.0) + double absoluteDifference = fabs( diffP - diffN ); + if ( absoluteDifference > 100.0 ) absoluteDifference = 100.0; - double badness = \ - -log(((absoluteDifference + func_helper_GeometricMean((100.0 - diffP), (100.0 - diffN))) / (absoluteDifference + func_helper_GeometricMean(diffP, diffN)))); - if (PWMInvolved) - return (badness * func_pwmsimulation_Period(self)); + double badness = + -log( ( ( absoluteDifference + func_helper_GeometricMean( ( 100.0 - diffP ), ( 100.0 - diffN ) ) ) / ( absoluteDifference + func_helper_GeometricMean( diffP, diffN ) ) ) ); + if ( PWMInvolved ) + return ( badness * func_pwmsimulation_Period( self ) ); else return badness; } - - -_inline size_t get_FrameCounter(StrobeAPI_t *self, counterType type) +_inline size_t get_FrameCounter( StrobeAPI_t *self, STROBE_counterType type ) { - switch (type) + switch ( type ) { - - case(CT_PositiveFrame): + case ( STROBE_CT_PositiveFrame ): { return self->protected->pCounter; break; } - case(CT_PositiveNormalFrame): + case ( STROBE_CT_PositiveNormalFrame ): { return self->protected->pNCounter; break; } - case(CT_PositiveBlackFrame): + case ( STROBE_CT_PositiveBlackFrame ): { return self->protected->pBCounter; break; } - case(CT_NegativeFrame): + case ( STROBE_CT_NegativeFrame ): { return self->protected->nCounter; break; } - case(CT_NegativeNormalFrame): + case ( STROBE_CT_NegativeNormalFrame ): { return self->protected->nNCounter; break; } - case(CT_NegativeBlackFrame): + case ( STROBE_CT_NegativeBlackFrame ): { return self->protected->nBCounter; break; } - case(CT_TotalFrame): + case ( STROBE_CT_TotalFrame ): default: return self->protected->fCounter; break; @@ -426,230 +408,215 @@ _inline size_t get_FrameCounter(StrobeAPI_t *self, counterType type) return self->protected->fCounter; } -_inline double get_Deviation(StrobeAPI_t *self) -{ - return self->protected->deviation; -} - -_inline double get_CooldownTimer(StrobeAPI_t *self) -{ - return self->protected->cdTimer; -} - -_inline double get_currentFPS(StrobeAPI_t *self) +_inline double get_currentFPS( StrobeAPI_t *self ) { // Copied from SCR_DrawFps // This way until current fps becomes global!!! - static double nexttime = 0, lasttime = 0; - static double framerate = 0; + static double nexttime = 0, lasttime = 0; + static double framerate = 0; static unsigned int mark = 0; - double newtime; + double newtime; - newtime = Sys_DoubleTime(); - if (newtime >= nexttime) + newtime = Sys_DoubleTime( ); + if ( newtime >= nexttime ) { - framerate = (self->protected->fCounter - mark) / (newtime - lasttime); - lasttime = newtime; - nexttime = max(nexttime + 0.5, lasttime - 0.5); // Make Update tick configurable ? - mark = self->protected->fCounter; + framerate = ( self->protected->fCounter - mark ) / ( newtime - lasttime ); + lasttime = newtime; + nexttime = max( nexttime + 0.5, lasttime - 0.5 ); // Make Update tick configurable ? + mark = self->protected->fCounter; } - + return framerate; } -_inline void GenerateDebugStatistics(StrobeAPI_t *self, char *src, int size) +_inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) { char diffBarP[128], diffBarN[128], diffBarT[128]; int diffP_NB, diffN_NB; - diffP_NB = (self->protected->pNCounter - self->protected->pBCounter); - diffN_NB = (self->protected->nNCounter - self->protected->nBCounter); + diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); + diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); double diffP = 0.0, diffN = 0.0; - if (self->protected->pCounter != 0) - diffP = round(abs(diffP_NB) * 100 / self->protected->pCounter); - - if (self->protected->nCounter != 0) - diffN = round(abs(diffN_NB) * 100 / self->protected->nCounter); - - self->Helpers.GenerateDiffBar(self, diffBarP, sizeof(diffBarP),0); - self->Helpers.GenerateDiffBar(self, diffBarN, sizeof(diffBarN), 1); - self->Helpers.GenerateDiffBar(self, diffBarT, sizeof(diffBarT),2); - - double cooldown = self->get.CooldownTimer(self); - - Q_snprintf(src, - size, - "%.2f FPS\n%.2f eFPS\n" \ - "Total Frame Count: %u\n" \ - "(+) Phase Frame Count: %u\n" \ - " |-> Normal Frame Count: %u\n" \ - " |-> Black Frame Count: %u\n" \ - "(-) Phase Frame Count:%u\n" \ - " |-> Normal Frame Count: %u\n" \ - " |-> Black Frame Count: %u\n" \ - ".isPhaseInverted: %d\n" \ - "^5=====ANALYSIS=====\n^3" \ - "PWM Simulation:\n" \ - " |-> Frequency: %d Hz\n" \ - " |-> Duty Cycle: %.2f%%\n" \ - " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" \ - " |-> Period: %.4f msec\n" \ - "Brightness Reduction:\n" \ - " |-> [^7LINEAR^3] Actual Reduction: %3f%%\n" \ - " |-> [^7LOG^3] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ - " |-> [^7SQUARE^3] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ - " |-> [^7CUBE^3] Realistic Reduction (400 cd/m2 base) : %.2f%%\n" \ - "Difference (+): %s\nDifference (-): %s\nDifference (x): %s\n" /* Diff 3 (Total): |Diff + - Diff -| . Max 200 Min 0*/ \ - "Geometric Mean: %.4f\n" \ - "G/A Difference: %.4f\n" \ - "[^7EXPERIMENTAL^3] Badness: %.4f\n" \ - "[^7EXPERIMENTAL^3] Badness x PWM Period: %.4f\n" \ - "[^7EXPERIMENTAL^3] Badness (Reducted): %.4f\n" \ - "[^7EXPERIMENTAL^3] Badness (Reducted) x PWM Period: %.4f\n" /* Badness -log((200-n)/n) */ \ - "Stability:\n" \ - " |-> Standard Deviation: %.3f\n" \ - " |-> Cooldown: %s\n" \ - "^5=====ANALYSIS=====\n^3" \ - , self->get.CurrentFPS(self) \ - , self->Helpers.effectiveFPS(self) \ - , self->get.FrameCounter(self, CT_TotalFrame) \ - , self->get.FrameCounter(self, CT_PositiveFrame), self->get.FrameCounter(self, CT_PositiveNormalFrame), self->get.FrameCounter(self, CT_PositiveBlackFrame) \ - , self->get.FrameCounter(self, CT_NegativeFrame), self->get.FrameCounter(self, CT_NegativeNormalFrame), self->get.FrameCounter(self, CT_NegativeBlackFrame) \ - , self->Helpers.isPhaseInverted(self) \ - , self->PWM.Frequency(self) \ - , self->PWM.DutyCycle() \ - , self->PWM.PositivePhaseShift(self) \ - , self->PWM.NegativePhaseShift(self) \ - , self->PWM.Period(self) \ - , self->BrightnessReductions.ActualBrightnessReduction(self) - , self->BrightnessReductions.LogarithmicBrightnessReduction(self, 400.0) - , self->BrightnessReductions.SquareBrightnessReduction(self, 400.0) - , self->BrightnessReductions.CubeBrightnessReduction(self, 400.0) - , diffBarP, diffBarN, diffBarT \ - , self->Helpers.GeometricMean(diffP, diffN) \ - , self->Helpers.ArithmeticMean(diffP, diffN) - self->Helpers.GeometricMean(diffP, diffN) - , self->Experimentals.BADNESS(self, false), self->Experimentals.BADNESS(self, true) \ - , self->Experimentals.BADNESS_REDUCTED(self, false), self->Experimentals.BADNESS_REDUCTED(self, true) \ - , self->get.Deviation(self) - , (cooldown > 0.0 && self->protected->cdTriggered ? va("^1 %.2f secs\n[STROBING DISABLED] ^3", (double)r_strobe_cooldown->integer - cooldown) : "0")); - -} - - -_inline void ProcessFrame(StrobeAPI_t *self) + if ( self->protected->pCounter ) + diffP = round( abs( diffP_NB ) * 100 / self->protected->pCounter ); + + if ( self->protected->nCounter ) + diffN = round( abs( diffN_NB ) * 100 / self->protected->nCounter ); + + self->Helpers.GenerateDiffBar( self, diffBarP, sizeof( diffBarP ), 0 ); + self->Helpers.GenerateDiffBar( self, diffBarN, sizeof( diffBarN ), 1 ); + self->Helpers.GenerateDiffBar( self, diffBarT, sizeof( diffBarT ), 2 ); + + double cooldown = self->protected->cdTimer; + + Q_snprintf( src, + size, + "%.2f FPS\n%.2f eFPS\n" + "Total Frame Count: %u\n" + "(+) Phase Frame Count: %u\n" + " |-> Normal Frame Count: %u\n" + " |-> Black Frame Count: %u\n" + "(-) Phase Frame Count: %u\n" + " |-> Normal Frame Count: %u\n" + " |-> Black Frame Count: %u\n" + ".isPhaseInverted: %d\n" + "^5=====ANALYSIS=====\n^3" + "PWM Simulation:\n" + " |-> Frequency: %d Hz\n" + " |-> Duty Cycle: %.2f%%\n" + " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" + " |-> Period: %.4f msec\n" + "Brightness Reduction:\n" + " |-> [^7LINEAR^3] Actual Reduction: %3f%%\n" + " |-> [^7LOG^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" + " |-> [^7SQUARE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" + " |-> [^7CUBE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" + "Difference (+): %s\nDifference (-): %s\nDifference (+ & -): %s\n" /* Diff 3 (Total): |Diff + - Diff -| . Max 200 Min 0*/ + "Geometric Mean: %.4f\n" + "G/A Difference: %.4f\n" + "[^7EXPERIMENTAL^3] Badness: %.4f\n" + "[^7EXPERIMENTAL^3] Badness x PWM Period: %.4f\n" + "[^7EXPERIMENTAL^3] Badness (Reducted): %.4f\n" + "[^7EXPERIMENTAL^3] Badness (Reducted) x PWM Period: %.4f\n" /* Badness -log((200-n)/n) */ + "Stability:\n" + " |-> Standard Deviation: %.3f\n" + " |-> Cooldown: %s\n" + "^5=====ANALYSIS=====\n^3", + self->Helpers.CurrentFPS( self ), + self->Helpers.effectiveFPS( self ), + self->get.FrameCounter( self, STROBE_CT_TotalFrame ), + self->get.FrameCounter( self, STROBE_CT_PositiveFrame ), + self->get.FrameCounter( self, STROBE_CT_PositiveNormalFrame ), + self->get.FrameCounter( self, STROBE_CT_PositiveBlackFrame ), + self->get.FrameCounter( self, STROBE_CT_NegativeFrame ), + self->get.FrameCounter( self, STROBE_CT_NegativeNormalFrame ), + self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ), + self->Helpers.isPhaseInverted( self ), + self->PWM.Frequency( self ), + self->PWM.DutyCycle( ), + self->PWM.PositivePhaseShift( self ), + self->PWM.NegativePhaseShift( self ), + self->PWM.Period( self ), + self->BrightnessReductions.ActualBrightnessReduction( self ), + self->BrightnessReductions.LogarithmicBrightnessReduction( self, 400.0 ), + self->BrightnessReductions.SquareBrightnessReduction( self, 400.0 ), + self->BrightnessReductions.CubeBrightnessReduction( self, 400.0 ), + diffBarP, + diffBarN, + diffBarT, + self->Helpers.GeometricMean( diffP, diffN ), + self->Helpers.ArithmeticMean( diffP, diffN ) - self->Helpers.GeometricMean( diffP, diffN ), + self->Experimentals.BADNESS( self, false ), + self->Experimentals.BADNESS( self, true ), + self->Experimentals.BADNESS_REDUCTED( self, false ), + self->Experimentals.BADNESS_REDUCTED( self, true ), + self->protected->deviation, + ( cooldown > 0.0 && self->protected->cdTriggered ? va( "^1 %.2f secs\n[STROBING DISABLED] ^3", (double)StrobeAPI.r_strobe_cooldown->integer - cooldown ) : "0" ) ); +} + +_inline void ProcessFrame( StrobeAPI_t *self ) { - if (self->protected->cdTriggered != 0) + if ( self->protected->cdTriggered != false ) { - self->protected->frameInfo = f_normal | (self->protected->frameInfo & p_positive); + self->protected->frameInfo = f_normal | ( self->protected->frameInfo & p_positive ); } - if (self->protected->frameInfo & f_normal) // Show normal + if ( self->protected->frameInfo & f_normal ) // Show normal { - if (self->protected->frameInfo & p_positive) + if ( self->protected->frameInfo & p_positive ) ++self->protected->pNCounter; else ++self->protected->nNCounter; - R_Set2DMode(false); + R_Set2DMode( false ); } else // Show black { - if (self->protected->frameInfo & p_positive) + if ( self->protected->frameInfo & p_positive ) ++self->protected->pBCounter; else ++self->protected->nBCounter; //GL_GenerateBlackFrame(); - self->GenerateBlackFrame(); + self->GenerateBlackFrame( ); } ++self->protected->fCounter; } - -void StrobeAPI_constructor(StrobeAPI_t *self) -{ - /*self->protected = (StrobeAPI_protected_t *)malloc(sizeof(StrobeAPI_protected_t)); - self->protected->nCounter = 0; self->protected->pBCounter = 0; self->protected->pNCounter = 0; - self->protected->pCounter = 0; self->protected->nBCounter = 0; self->protected->nNCounter = 0; - self->protected->fCounter = 0; - self->protected->deviation = 0.0; - self->protected->cdTimer = 0.0; - self->protected->cdTriggered = false;*/ - self->protected = (StrobeAPI_protected_t *)calloc(1, sizeof(StrobeAPI_protected_t)); - self->protected->frameInfo = (p_positive | f_normal); - self->Helpers.ArithmeticMean = func_helper_ArithmeticMean; - self->Helpers.effectiveFPS = func_helper_effectiveFPS; - self->Helpers.GenerateDiffBar = func_helper_GenerateDiffBar; - self->Helpers.GeometricMean = func_helper_GeometricMean; - self->get.Cooldown = func_helper_getCooldown; - self->get.CurrentFPS = get_currentFPS; - self->Helpers.isPhaseInverted = func_helper_isPhaseInverted; - self->Helpers.isNormal = func_helper_isNormal; - self->Helpers.isPositive = func_helper_isPositive; - self->Helpers.StandardDeviation = func_helper_StandardDeviation; - self->Experimentals.BADNESS = func_experimental_Badness; - self->Experimentals.BADNESS_REDUCTED = func_experimental_Badness_Reducted; - self->BrightnessReductions.ActualBrightnessReduction = func_brightnessreduction_ActualBrightnessReduction; - self->BrightnessReductions.CubeBrightnessReduction = func_brightnessreduction_CubeBrightnessReduction; +_inline void StrobeAPI_constructor( StrobeAPI_t *self ) +{ + self->protected = (StrobeAPI_protected_t *)calloc( 1, sizeof( StrobeAPI_protected_t ) ); + if ( self->protected == NULL ) + { + return; // Fix handling! + } + self->protected->frameInfo = ( p_positive | f_normal ); + self->Helpers.ArithmeticMean = func_helper_ArithmeticMean; + self->Helpers.effectiveFPS = func_helper_effectiveFPS; + self->Helpers.GenerateDiffBar = func_helper_GenerateDiffBar; + self->Helpers.GeometricMean = func_helper_GeometricMean; + self->Helpers.Cooldown = func_helper_getCooldown; + self->Helpers.CurrentFPS = get_currentFPS; + self->Helpers.isPhaseInverted = func_helper_isPhaseInverted; + self->Helpers.isNormal = func_helper_isNormal; + self->Helpers.isPositive = func_helper_isPositive; + self->Helpers.StandardDeviation = func_helper_StandardDeviation; + self->Experimentals.BADNESS = func_experimental_Badness; + self->Experimentals.BADNESS_REDUCTED = func_experimental_Badness_Reducted; + self->BrightnessReductions.ActualBrightnessReduction = func_brightnessreduction_ActualBrightnessReduction; + self->BrightnessReductions.CubeBrightnessReduction = func_brightnessreduction_CubeBrightnessReduction; self->BrightnessReductions.LogarithmicBrightnessReduction = func_brightnessreduction_LogarithmicBrightnessReduction; - self->BrightnessReductions.SquareBrightnessReduction = func_brightnessreduction_SquareBrightnessReduction; - self->BrightnessReductions.OtherBrightnessReduction = func_brightnessreduction_OtherBrightnessReduction; - self->PWM.Frequency = func_pwmsimulation_Frequency; - self->PWM.DutyCycle = func_pwmsimulation_DutyCycle; - self->PWM.PositivePhaseShift = func_pwmsimulation_PositivePhaseShift; - self->PWM.NegativePhaseShift = func_pwmsimulation_NegativePhaseShift; - self->PWM.Period = func_pwmsimulation_Period; - self->GenerateBlackFrame = GL_GenerateBlackFrame; - self->ProcessFrame = ProcessFrame; - self->Helpers.GenerateDebugStatistics = GenerateDebugStatistics; - self->get.FrameCounter = get_FrameCounter; - self->get.Deviation = get_Deviation; - self->get.CooldownTimer = get_CooldownTimer; -} - -void StrobeAPI_destructor(StrobeAPI_t *self) + self->BrightnessReductions.SquareBrightnessReduction = func_brightnessreduction_SquareBrightnessReduction; + self->BrightnessReductions.OtherBrightnessReduction = func_brightnessreduction_OtherBrightnessReduction; + self->PWM.Frequency = func_pwmsimulation_Frequency; + self->PWM.DutyCycle = func_pwmsimulation_DutyCycle; + self->PWM.PositivePhaseShift = func_pwmsimulation_PositivePhaseShift; + self->PWM.NegativePhaseShift = func_pwmsimulation_NegativePhaseShift; + self->PWM.Period = func_pwmsimulation_Period; + self->GenerateBlackFrame = GL_GenerateBlackFrame; + self->ProcessFrame = ProcessFrame; + self->Helpers.GenerateDebugStatistics = GenerateDebugStatistics; + self->get.FrameCounter = get_FrameCounter; +} + +_inline void StrobeAPI_destructor( StrobeAPI_t *self ) { - if (self->protected) + if ( self->protected ) { - free(self->protected); + free( self->protected ); self->protected = NULL; } } - -/* -=============== -R_InitStrobe - -register strobe cvar -=============== -*/ -void R_InitStrobe() -{ - r_strobe = Cvar_Get("r_strobe", "0", CVAR_ARCHIVE, "black frame replacement interval"); - r_strobe_swapinterval = Cvar_Get("r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval"); - r_strobe_debug = Cvar_Get("r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information"); - r_strobe_cooldown = Cvar_Get("r_strobe_cooldown", "3", CVAR_ARCHIVE, "strobe cooldown period in seconds"); -} - -void Strobe_Invoker(void **self, void(*constructor)(void **), void(*main)(void **), void(*destructor)(void **)) +_inline void StrobeAPI_Invoker( void **self, void ( *constructor )( void ** ), void ( *main )( void ** ), void ( *destructor )( void ** ) ) { - if (r_strobe->integer) + if ( StrobeAPI.r_strobe->integer ) { - if (!(*self)) - constructor(self); - main(self); + if ( !( *self ) ) + constructor( self ); + main( self ); } else { - if (*self) - destructor(self); + if ( *self ) + destructor( self ); } } +void R_InitStrobeAPI( void ) +{ + StrobeAPI.r_strobe = Cvar_Get( "r_strobe", "0", CVAR_ARCHIVE, "black frame replacement algorithm interval" ); + StrobeAPI.r_strobe_swapinterval = Cvar_Get( "r_strobe_swapinterval", "0", CVAR_ARCHIVE, "swapping phase interval (seconds)" ); + StrobeAPI.r_strobe_debug = Cvar_Get( "r_strobe_debug", "0", CVAR_ARCHIVE, "show strobe debug information" ); + StrobeAPI.r_strobe_cooldown = Cvar_Get( "r_strobe_cooldown", "3", CVAR_ARCHIVE, "strobe cooldown period in seconds" ); + + StrobeAPI.Constructor = StrobeAPI_constructor; + StrobeAPI.Destructor = StrobeAPI_destructor; + StrobeAPI.Invoker = StrobeAPI_Invoker; +} -#endif \ No newline at end of file +#endif diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 27e6738a0..a9c6f7f61 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -1,10 +1,10 @@ /* r_strobe_api.h - Software based strobing implementation -Copyright (C) 2018 * fuzun +Copyright (C) 2018 - fuzun * github/fuzun For information: - https://forums.blurbusters.com + https://forums.blurbusters.com/viewtopic.php?f=7&t=3815&p=30401 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,92 +21,97 @@ See the GNU General Public License for more details. #if !defined R_STROBE_API_H && !defined STROBE_DISABLED #define R_STROBE_API_H -#define STROBE_ENABLED // Integrate with cmake? +#define STROBE_ENABLED #include "common.h" #include "wrect.h" typedef struct StrobeAPI_s StrobeAPI_t; -typedef enum { - CT_TotalFrame, - CT_PositiveFrame, - CT_PositiveNormalFrame, - CT_PositiveBlackFrame, - CT_NegativeFrame, - CT_NegativeNormalFrame, - CT_NegativeBlackFrame -}counterType; - -typedef struct StrobeAPI_exported_funcs_BRIGHTNESSREDUCTION_s { - double(*ActualBrightnessReduction)(StrobeAPI_t *self); - double(*LogarithmicBrightnessReduction)(StrobeAPI_t *self, double base); - double(*SquareBrightnessReduction)(StrobeAPI_t *self, double base); - double(*CubeBrightnessReduction)(StrobeAPI_t *self, double base); - double(*OtherBrightnessReduction)(StrobeAPI_t *self, double base, double(*reductionFunction)(double)); -} StrobeAPI_exported_funcs_BRIGHTNESSREDUCTION_t; - -typedef struct StrobeAPI_exported_funcs_EXPERIMENTAL_s { - double(*BADNESS)(StrobeAPI_t *self, qboolean PWMInvolved); - double(*BADNESS_REDUCTED)(StrobeAPI_t *self, qboolean PWMInvolved); -} StrobeAPI_exported_funcs_EXPERIMENTAL_t; - -typedef struct StrobeAPI_exported_funcs_PWMSIMULATION_s { - int(*Frequency)(StrobeAPI_t *self); - double(*DutyCycle)(void); - double(*PositivePhaseShift)(StrobeAPI_t *self); - double(*NegativePhaseShift)(StrobeAPI_t *self); - double(*Period)(StrobeAPI_t *self); -} StrobeAPI_exported_funcs_PWMSIMULATION_t; - -typedef struct StrobeAPI_exported_funcs_HELPER_s { - qboolean(*isPhaseInverted)(StrobeAPI_t *self); - qboolean(*isNormal)(StrobeAPI_t *self); - qboolean(*isPositive)(StrobeAPI_t *self); - double(*effectiveFPS)(StrobeAPI_t *self); - void(*GenerateDebugStatistics)(StrobeAPI_t *self, char *src, int size); - void(*GenerateDiffBar)(StrobeAPI_t *self, char *src, int size, char type); - double(*GeometricMean)(double, double); - double(*ArithmeticMean)(double, double); - double(*StandardDeviation)(const double *data, int size); -} StrobeAPI_exported_funcs_HELPER_t; - -typedef struct StrobeAPI_get_s { - size_t(*FrameCounter)(StrobeAPI_t *self, counterType); - double(*Deviation)(StrobeAPI_t *self); - double(*CooldownTimer)(StrobeAPI_t *self); - double(*CurrentFPS)(StrobeAPI_t *self); - double(*Cooldown)(StrobeAPI_t *self); -} StrobeAPI_get_t; +typedef enum +{ + STROBE_CT_TotalFrame, + STROBE_CT_PositiveFrame, + STROBE_CT_PositiveNormalFrame, + STROBE_CT_PositiveBlackFrame, + STROBE_CT_NegativeFrame, + STROBE_CT_NegativeNormalFrame, + STROBE_CT_NegativeBlackFrame +} STROBE_counterType; + +typedef struct StrobeAPI_funcs_BRIGHTNESSREDUCTION_s +{ + double ( *ActualBrightnessReduction )( StrobeAPI_t *self ); + double ( *LogarithmicBrightnessReduction )( StrobeAPI_t *self, double base ); + double ( *SquareBrightnessReduction )( StrobeAPI_t *self, double base ); + double ( *CubeBrightnessReduction )( StrobeAPI_t *self, double base ); + double ( *OtherBrightnessReduction )( StrobeAPI_t *self, double base, double ( *reductionFunction )( double ) ); +} StrobeAPI_funcs_BRIGHTNESSREDUCTION_t; + +typedef struct StrobeAPI_funcs_EXPERIMENTAL_s +{ + double ( *BADNESS )( StrobeAPI_t *self, qboolean PWMInvolved ); + double ( *BADNESS_REDUCTED )( StrobeAPI_t *self, qboolean PWMInvolved ); +} StrobeAPI_funcs_EXPERIMENTAL_t; + +typedef struct StrobeAPI_funcs_PWMSIMULATION_s +{ + int ( *Frequency )( StrobeAPI_t *self ); + double ( *DutyCycle )( void ); + double ( *PositivePhaseShift )( StrobeAPI_t *self ); + double ( *NegativePhaseShift )( StrobeAPI_t *self ); + double ( *Period )( StrobeAPI_t *self ); +} StrobeAPI_funcs_PWMSIMULATION_t; + +typedef struct StrobeAPI_funcs_HELPER_s +{ + qboolean ( *isPhaseInverted )( StrobeAPI_t *self ); + qboolean ( *isNormal )( StrobeAPI_t *self ); + qboolean ( *isPositive )( StrobeAPI_t *self ); + double ( *effectiveFPS )( StrobeAPI_t *self ); + double ( *CurrentFPS )( StrobeAPI_t *self ); + void ( *GenerateDebugStatistics )( StrobeAPI_t *self, char *src, int size ); + void ( *GenerateDiffBar )( StrobeAPI_t *self, char *src, int size, char type ); + double ( *GeometricMean )( double, double ); + double ( *ArithmeticMean )( double, double ); + double ( *StandardDeviation )( const double *data, int size ); + double ( *Cooldown )( StrobeAPI_t *self ); +} StrobeAPI_funcs_HELPER_t; + +typedef struct StrobeAPI_GET_s +{ + size_t ( *FrameCounter )( StrobeAPI_t *self, STROBE_counterType ); +} StrobeAPI_GET_t; typedef struct StrobeAPI_protected_s StrobeAPI_protected_t; -typedef struct StrobeAPI_s { +typedef struct StrobeAPI_s +{ StrobeAPI_protected_t *protected; // r_strobe_base_protected_.h - StrobeAPI_exported_funcs_EXPERIMENTAL_t Experimentals; - StrobeAPI_exported_funcs_BRIGHTNESSREDUCTION_t BrightnessReductions; - StrobeAPI_exported_funcs_PWMSIMULATION_t PWM; - StrobeAPI_exported_funcs_HELPER_t Helpers; - StrobeAPI_get_t get; - void(*GenerateBlackFrame)(void); - void(*ProcessFrame)(StrobeAPI_t *self); + StrobeAPI_funcs_EXPERIMENTAL_t Experimentals; + StrobeAPI_funcs_BRIGHTNESSREDUCTION_t BrightnessReductions; + StrobeAPI_funcs_PWMSIMULATION_t PWM; + StrobeAPI_funcs_HELPER_t Helpers; + StrobeAPI_GET_t get; + void ( *GenerateBlackFrame )( void ); + void ( *ProcessFrame )( StrobeAPI_t *self ); } StrobeAPI_t; +typedef struct StrobeAPI_EXPORTS_s +{ + void ( *Invoker )( void **self, void ( *constructor )( void ** ), void ( *main )( void ** ), void ( *destructor )( void ** ) ); // Strobe Invoker + void ( *Constructor )( StrobeAPI_t *self ); + void ( *Destructor )( StrobeAPI_t *self ); -void Strobe_Invoker(void **self, void(*constructor)(void **), void(*main)(void **), void(*destructor)(void **)); // Strobe Invoker + // Strobe related convars should be in StrobeAPI derived implementations! + convar_t *r_strobe; + convar_t *r_strobe_swapinterval; + convar_t *r_strobe_debug; + convar_t *r_strobe_cooldown; +} StrobeAPI_EXPORTS_t; -void StrobeAPI_constructor(StrobeAPI_t *self); -void StrobeAPI_destructor(StrobeAPI_t *self); +extern StrobeAPI_EXPORTS_t StrobeAPI; -void R_InitStrobe(); +void R_InitStrobeAPI( ); -#define STROBE_DEVIATION_LIMIT 2.75 -#define STROBE_DEVIATION_SIZE 60 - -extern convar_t *r_strobe; -extern convar_t *r_strobe_swapinterval; -extern convar_t *r_strobe_debug; -extern convar_t *r_strobe_cooldown; - - -#endif \ No newline at end of file +#endif diff --git a/engine/client/strobe/r_strobe_base_protected_.h b/engine/client/strobe/r_strobe_base_protected_.h index 6b67c322e..74c5c3bdd 100644 --- a/engine/client/strobe/r_strobe_base_protected_.h +++ b/engine/client/strobe/r_strobe_base_protected_.h @@ -4,7 +4,7 @@ r_strobe_base_protected_.h - Software based strobing implementation Copyright (C) 2018 - fuzun * github/fuzun For information: - https://forums.blurbusters.com + https://forums.blurbusters.com/viewtopic.php?f=7&t=3815&p=30401 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -23,22 +23,24 @@ See the GNU General Public License for more details. #include "common.h" -typedef enum { - p_positive = BIT(0), // Phase: Positive - p_inverted = BIT(1), // Phase: Inverted - f_normal = BIT(2) // Frame: Normal -} fstate_e; // Frame State +typedef enum +{ + p_positive = BIT( 0 ), // Phase: Positive + p_inverted = BIT( 1 ), // Phase: Inverted + f_normal = BIT( 2 ) // Frame: Normal +} fstate_e; // Frame State - -typedef struct StrobeAPI_protected_s { - size_t fCounter; // Frame counter +typedef struct StrobeAPI_protected_s +{ + size_t fCounter; // Frame counter size_t pCounter, pNCounter, pBCounter; // Positive phase counters size_t nCounter, nNCounter, nBCounter; // Negative phase counters + int strobeInterval; + int swapInterval; double deviation; // deviation - double cdTimer; // Cooldown timer - char cdTriggered; - fstate_e frameInfo; // Frame info + double cdTimer; // Cooldown timer + qboolean cdTriggered; + fstate_e frameInfo; // Frame info } StrobeAPI_protected_t; // Protected members - -#endif \ No newline at end of file +#endif diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index fc7bfdc15..02aaf21b3 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -1,10 +1,10 @@ /* r_strobe_core.c - Software based strobing implementation -Copyright (C) 2018 - fuzun * github.com/fuzun +Copyright (C) 2018 - fuzun * github/fuzun For information: -https://forums.blurbusters.com + https://forums.blurbusters.com/viewtopic.php?f=7&t=3815&p=30401 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,125 +20,102 @@ See the GNU General Public License for more details. #if !defined XASH_DEDICATED && !defined STROBE_DISABLED - -#include -#include -#include "r_strobe_base_protected_.h" #include "r_strobe_core.h" -#include "gl_local.h" #include "client.h" - +#include "gl_local.h" +#include "r_strobe_base_protected_.h" STROBE_CORE_t *STROBE_CORE = NULL; -typedef struct STROBE_CORE_priv_s { - int strobeInterval; // Move to base ? - int swapInterval; +typedef struct STROBE_CORE_private_s +{ double recentTime, recentTime2; - double delta[STROBE_DEVIATION_SIZE]; + double delta[STROBE_CORE_DEVIATION_SIZE]; // double *delta; size_t fCounterSnapshot; -}STROBE_CORE_priv_t; - +} STROBE_CORE_private_t; /* =============== R_Strobe TODO: +* Make timers global (at StrobeAPI level). * Make swapping transition seamless by rendering non-opaque frames. * Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) =============== */ -static void R_Strobe(STROBE_CORE_THIS_PARAM) +static void R_Strobe( STROBE_CORE_THIS_PARAM ) { - //static int strobeInterval = 0; - //static int swapInterval = 0; - //static double recentTime = 0.0, recentTime2 = 0.0; - double _delta, _delta2; - //static qboolean cdTriggered = false; - //static double delta[STROBE_DEVIATION_SIZE] = { 0.0 }; - //static size_t fCounterSnapshot = 0; - double currentTime = Sys_DoubleTime(); - _delta2 = currentTime - STROBE_CORE_THIS->private->recentTime2; + double delta, delta2; + double currentTime = Sys_DoubleTime( ); + delta2 = currentTime - STROBE_CORE_THIS->private->recentTime2; STROBE_CORE_THIS->private->recentTime2 = currentTime; - - if (CL_IsInMenu()) + + if ( CL_IsInMenu( ) ) { - R_Set2DMode(false); + R_Set2DMode( false ); return; } - if (STROBE_CORE_THIS->base.protected->cdTimer >= 0.0 && _delta2 > 0.0) - STROBE_CORE_THIS->base.protected->cdTimer += _delta2; - if (STROBE_CORE_THIS->base.protected->fCounter - STROBE_CORE_THIS->private->fCounterSnapshot == 1) + if ( STROBE_CORE_THIS->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) + STROBE_CORE_THIS->base.protected->cdTimer += delta2; + if ( STROBE_CORE_THIS->base.protected->fCounter - STROBE_CORE_THIS->private->fCounterSnapshot == 1 ) { - STROBE_CORE_THIS->private->delta[STROBE_CORE_THIS->base.protected->fCounter % ARRAYSIZE(STROBE_CORE_THIS->private->delta)] = _delta2; - STROBE_CORE_THIS->base.protected->deviation = STROBE_CORE_THIS->base.Helpers.StandardDeviation(STROBE_CORE_THIS->private->delta, ARRAYSIZE(STROBE_CORE_THIS->private->delta)) * 1000; + STROBE_CORE_THIS->private->delta[STROBE_CORE_THIS->base.protected->fCounter % ARRAYSIZE( STROBE_CORE_THIS->private->delta )] = delta2; + STROBE_CORE_THIS->base.protected->deviation = STROBE_CORE_THIS->base.Helpers.StandardDeviation( STROBE_CORE_THIS->private->delta, ARRAYSIZE( STROBE_CORE_THIS->private->delta ) ) * 1000; } STROBE_CORE_THIS->private->fCounterSnapshot = STROBE_CORE_THIS->base.protected->fCounter; - if (r_strobe_cooldown->integer > 0) + if ( StrobeAPI.r_strobe_cooldown->integer > 0 ) { - if ((STROBE_CORE_THIS->base.protected->cdTimer > (double)abs(r_strobe_cooldown->integer)) && STROBE_CORE_THIS->base.protected->cdTriggered == 1) + if ( ( STROBE_CORE_THIS->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && STROBE_CORE_THIS->base.protected->cdTriggered == true ) { - STROBE_CORE_THIS->base.protected->cdTriggered = 0; - STROBE_CORE_THIS->base.protected->cdTimer = -1.0; + STROBE_CORE_THIS->base.protected->cdTriggered = false; + STROBE_CORE_THIS->base.protected->cdTimer = -1.0; } - if (STROBE_CORE_THIS->base.protected->fCounter > ARRAYSIZE(STROBE_CORE_THIS->private->delta)) + if ( STROBE_CORE_THIS->base.protected->fCounter > ARRAYSIZE( STROBE_CORE_THIS->private->delta ) ) { - if (STROBE_CORE_THIS->base.protected->deviation > STROBE_DEVIATION_LIMIT) + if ( STROBE_CORE_THIS->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) { - STROBE_CORE_THIS->base.protected->cdTriggered = 1; - STROBE_CORE_THIS->base.protected->cdTimer = 0.0; + STROBE_CORE_THIS->base.protected->cdTriggered = false; + STROBE_CORE_THIS->base.protected->cdTimer = 0.0; } } } else { - STROBE_CORE_THIS->base.protected->cdTriggered = 0; + STROBE_CORE_THIS->base.protected->cdTriggered = false; } - //Msg("Snapshot: %d - Deviation: %f - timer %f - delta %f\n\n", snapshot, standard_deviation(data, 10) * 1000, StrobeInfo.cdTimer, _delta2); - - if (((STROBE_CORE_THIS->private->strobeInterval != r_strobe->integer) && (STROBE_CORE_THIS->private->strobeInterval != 0)) || - /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - STROBE_CORE_THIS->base.protected->fCounter == UINT_MAX) // Reset stats after some time + if ( ( ( STROBE_CORE_THIS->base.protected->strobeInterval != StrobeAPI.r_strobe->integer ) && ( STROBE_CORE_THIS->base.protected->strobeInterval ) ) || + /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ + STROBE_CORE_THIS->base.protected->fCounter == UINT_MAX ) { - - STROBE_CORE_EXPORTEDFUNC_reinit(*(void***)&_STROBE_CORE_THIS); - R_Strobe(&STROBE_CORE_THIS); - /* - STROBE_CORE_THIS->base.protected->pCounter = 0; STROBE_CORE_THIS->base.protected->pBCounter = 0; STROBE_CORE_THIS->base.protected->pNCounter = 0; - STROBE_CORE_THIS->base.protected->nCounter = 0; STROBE_CORE_THIS->base.protected->nBCounter = 0; STROBE_CORE_THIS->base.protected->nNCounter = 0; - STROBE_CORE_THIS->base.protected->fCounter = 0; - STROBE_CORE_THIS->base.protected->deviation = 0.0; - Q_memset(STROBE_CORE_THIS->private->delta, 0, sizeof(STROBE_CORE_THIS->private->delta)); - - STROBE_CORE_THIS->base.protected->frameInfo &= ~p_inverted; - */ + STROBE_CORE_EXPORTEDFUNC_reinit( *(void ***)&_STROBE_CORE_THIS ); + R_Strobe( &STROBE_CORE_THIS ); } - STROBE_CORE_THIS->private->strobeInterval = r_strobe->integer; - STROBE_CORE_THIS->private->swapInterval = r_strobe_swapinterval->integer; + STROBE_CORE_THIS->base.protected->strobeInterval = StrobeAPI.r_strobe->integer; + STROBE_CORE_THIS->base.protected->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; - if ((STROBE_CORE_THIS->private->strobeInterval == 0) || - ((gl_swapInterval->integer == 0) && (STROBE_CORE_THIS->private->strobeInterval != 0))) + if ( ( STROBE_CORE_THIS->base.protected->strobeInterval == 0 ) || + ( ( gl_swapInterval->integer == 0 ) && ( STROBE_CORE_THIS->base.protected->strobeInterval ) ) ) { - if (!gl_swapInterval->integer) - MsgDev(D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n"); + if ( !gl_swapInterval->integer ) + MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - if (STROBE_CORE_THIS->private->strobeInterval != 0) // If v-sync is off, turn off strobing + if ( STROBE_CORE_THIS->base.protected->strobeInterval ) // If v-sync is off, turn off strobing { - Cvar_Set("r_strobe", "0"); + Cvar_Set( "r_strobe", "0" ); } STROBE_CORE_THIS->base.protected->fCounter = 0; - R_Set2DMode(false); + R_Set2DMode( false ); return; } - if ((STROBE_CORE_THIS->base.protected->fCounter % 2) == 0) + if ( ( STROBE_CORE_THIS->base.protected->fCounter % 2 ) == 0 ) { ++STROBE_CORE_THIS->base.protected->pCounter; STROBE_CORE_THIS->base.protected->frameInfo |= p_positive; @@ -149,183 +126,161 @@ static void R_Strobe(STROBE_CORE_THIS_PARAM) STROBE_CORE_THIS->base.protected->frameInfo &= ~p_positive; } - if (STROBE_CORE_THIS->private->swapInterval < 0) - STROBE_CORE_THIS->private->swapInterval = abs(STROBE_CORE_THIS->private->swapInterval); + if ( STROBE_CORE_THIS->base.protected->swapInterval < 0 ) + STROBE_CORE_THIS->base.protected->swapInterval = abs( STROBE_CORE_THIS->base.protected->swapInterval ); - if ((STROBE_CORE_THIS->private->swapInterval != 0) && (STROBE_CORE_THIS->private->strobeInterval % 2 != 0)) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ( ( STROBE_CORE_THIS->base.protected->swapInterval ) && ( STROBE_CORE_THIS->base.protected->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { - _delta = currentTime - STROBE_CORE_THIS->private->recentTime; // New Currenttime for _delta ? - if ((_delta >= (double)(STROBE_CORE_THIS->private->swapInterval)) && (_delta < (double)(2 * STROBE_CORE_THIS->private->swapInterval))) // Basic timer + delta = currentTime - STROBE_CORE_THIS->private->recentTime; // New Currenttime for _delta ? + if ( ( delta >= (double)( STROBE_CORE_THIS->base.protected->swapInterval ) ) && ( delta < (double)( 2 * STROBE_CORE_THIS->base.protected->swapInterval ) ) ) // Basic timer { STROBE_CORE_THIS->base.protected->frameInfo |= p_inverted; } - else if (_delta < (double)(STROBE_CORE_THIS->private->swapInterval)) + else if ( delta < (double)( STROBE_CORE_THIS->base.protected->swapInterval ) ) { STROBE_CORE_THIS->base.protected->frameInfo &= ~p_inverted; } - else //if (_delta >= (double)(2 * swapInterval)) + else //if (delta >= (double)(2 * swapInterval)) { STROBE_CORE_THIS->private->recentTime = currentTime; } } - switch (STROBE_CORE_THIS->base.protected->frameInfo & (p_positive | p_inverted)) + switch ( STROBE_CORE_THIS->base.protected->frameInfo & ( p_positive | p_inverted ) ) { - case (p_positive | p_inverted): - if ((abs(STROBE_CORE_THIS->private->strobeInterval) % 2) == 0) - STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->pCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == (abs(STROBE_CORE_THIS->private->strobeInterval) / 2)) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + case ( p_positive | p_inverted ): + if ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 ) == 0 ) + STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->pCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) / 2 ) ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even else STROBE_CORE_THIS->base.protected->frameInfo &= ~f_normal; break; - case(p_positive & ~p_inverted): - if (abs(STROBE_CORE_THIS->private->strobeInterval) % 2 == 0) - STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->pCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + case ( p_positive & ~p_inverted ): + if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 == 0 ) + STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->pCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even else { - if (abs(STROBE_CORE_THIS->private->strobeInterval) == 1) + if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) == 1 ) STROBE_CORE_THIS->base.protected->frameInfo |= f_normal; else - STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->pCounter - 1) % ((abs(STROBE_CORE_THIS->private->strobeInterval) + 1) / 2)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd + STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->pCounter - 1 ) % ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd } break; - case(~p_positive & p_inverted): - if (abs(STROBE_CORE_THIS->private->strobeInterval) % 2 == 0) - STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->nCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + case ( ~p_positive & p_inverted ): + if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 == 0 ) + STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->nCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even else { - if (abs(STROBE_CORE_THIS->private->strobeInterval) == 1) + if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) == 1 ) STROBE_CORE_THIS->base.protected->frameInfo |= f_normal; else - STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->nCounter - 1) % ((abs(STROBE_CORE_THIS->private->strobeInterval) + 1) / 2)) == 0) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd + STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->nCounter - 1 ) % ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd } break; case 0: - if ((abs(STROBE_CORE_THIS->private->strobeInterval) % 2) == 0) - STROBE_CORE_THIS->base.protected->frameInfo = (((STROBE_CORE_THIS->base.protected->nCounter - 1) % (abs(STROBE_CORE_THIS->private->strobeInterval) + 1)) == (abs(STROBE_CORE_THIS->private->strobeInterval) / 2)) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + if ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 ) == 0 ) + STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->nCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) / 2 ) ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even else STROBE_CORE_THIS->base.protected->frameInfo &= ~f_normal; break; default: - STROBE_CORE_THIS->base.protected->frameInfo = (p_positive | f_normal); + STROBE_CORE_THIS->base.protected->frameInfo = ( p_positive | f_normal ); } - if (STROBE_CORE_THIS->private->strobeInterval < 0) + if ( STROBE_CORE_THIS->base.protected->strobeInterval < 0 ) STROBE_CORE_THIS->base.protected->frameInfo ^= f_normal; - - - STROBE_CORE_THIS->base.ProcessFrame(&STROBE_CORE_THIS->base); + STROBE_CORE_THIS->base.ProcessFrame( &STROBE_CORE_THIS->base ); } - -_inline void debugDrawer(STROBE_CORE_THIS_PARAM) +_inline void debugDrawer( STROBE_CORE_THIS_PARAM ) { rgba_t color; char debugStr[2048]; // Heap allocation ? int offsetX, offsetY; - qboolean strobeDebug = !!r_strobe_debug->integer ? true : false; // Why not just r_strobe_debug->integer ? + qboolean strobeDebug = StrobeAPI.r_strobe_debug->integer ? true : false; - /* - if (!(STROBE_CORE_THIS->base.protected->frameInfo & f_normal && (r_strobe_debug->integer || cl_showfps->integer))) - { + if ( cls.state != ca_active ) + return; + if ( ( !strobeDebug && !cl_showfps->integer ) || cl.background ) return; - } - */ - - if (cls.state != ca_active) return; - if ((!strobeDebug && !cl_showfps->integer) || cl.background) return; - switch (cls.scrshot_action) + switch ( cls.scrshot_action ) { case scrshot_normal: case scrshot_snapshot: case scrshot_inactive: break; - default: return; + default: + return; } - if (strobeDebug) - { - STROBE_CORE_THIS->base.Helpers.GenerateDebugStatistics(&STROBE_CORE_THIS->base, debugStr, ARRAYSIZE(debugStr)); - } - else if (cl_showfps->integer) - { - Q_snprintf(debugStr, sizeof(debugStr), "%3d eFPS", (int)round(STROBE_CORE_THIS->base.Helpers.effectiveFPS(&STROBE_CORE_THIS->base))); - } + if ( strobeDebug ) + { + STROBE_CORE_THIS->base.Helpers.GenerateDebugStatistics( &STROBE_CORE_THIS->base, debugStr, ARRAYSIZE( debugStr ) ); + } + else if ( cl_showfps->integer ) + { + Q_snprintf( debugStr, sizeof( debugStr ), "%3d eFPS", (int)round( STROBE_CORE_THIS->base.Helpers.effectiveFPS( &STROBE_CORE_THIS->base ) ) ); + } - MakeRGBA(color, 255, 255, 255, 255); - Con_DrawStringLen(debugStr, &offsetX, &offsetY); - if (strobeDebug) - Con_DrawString(scr_width->integer - offsetX - 50, 4, debugStr, color); + MakeRGBA( color, 255, 255, 255, 255 ); + Con_DrawStringLen( debugStr, &offsetX, &offsetY ); + if ( strobeDebug ) + Con_DrawString( scr_width->integer - offsetX - 50, 4, debugStr, color ); else - Con_DrawString(scr_width->integer - offsetX - 2, offsetY + 8, debugStr, color); - + Con_DrawString( scr_width->integer - offsetX - 2, offsetY + 8, debugStr, color ); } -void STROBE_CORE_EXPORTEDFUNC_constructor(void **STROBE_CORE) +void STROBE_CORE_EXPORTEDFUNC_constructor( void **STROBE_CORE ) { STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; - *instance = (STROBE_CORE_t *)malloc(sizeof(STROBE_CORE_t)); - /*(*instance)->private = (STROBE_CORE_priv_t *)malloc(sizeof(STROBE_CORE_priv_t)); - (*instance)->private->strobeInterval = 0; - (*instance)->private->swapInterval = 0; - (*instance)->private->recentTime = 0.0; - (*instance)->private->recentTime2 = 0.0; - Q_memset((*instance)->private->delta, 0, sizeof((*instance)->private->delta)); - (*instance)->private->fCounterSnapshot = 0;*/ - (*instance)->private = (STROBE_CORE_priv_t *)calloc(1, sizeof(STROBE_CORE_priv_t)); - - (*instance)->STROBE_CORE_FUNC_main = R_Strobe; - (*instance)->STROBE_CORE_FUNC_debughandler = debugDrawer; + *instance = (STROBE_CORE_t *)malloc( sizeof( STROBE_CORE_t ) ); + ( *instance )->private = (STROBE_CORE_private_t *)calloc( 1, sizeof( STROBE_CORE_private_t ) ); + ( *instance )->STROBE_CORE_FUNC_main = R_Strobe; + ( *instance )->STROBE_CORE_FUNC_debughandler = debugDrawer; - StrobeAPI_constructor(&(*instance)->base); + StrobeAPI.Constructor( &( *instance )->base ); } - -void STROBE_CORE_EXPORTEDFUNC_destructor(void **STROBE_CORE) +void STROBE_CORE_EXPORTEDFUNC_destructor( void **STROBE_CORE ) { STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; - - if (*instance) // Check anyway + + if ( *instance ) { - StrobeAPI_destructor(&(*instance)->base); - if ((*instance)->private) + StrobeAPI.Destructor( &( *instance )->base ); + if ( ( *instance )->private ) { - free((*instance)->private); - (*instance)->private = NULL; + free( ( *instance )->private ); + ( *instance )->private = NULL; } - free(*instance); + free( *instance ); *instance = NULL; } } -void STROBE_CORE_EXPORTEDFUNC_reinit(void **STROBE_CORE) +void STROBE_CORE_EXPORTEDFUNC_reinit( void **STROBE_CORE ) { - //STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; - - if (!(*STROBE_CORE)) + if ( !( *STROBE_CORE ) ) { - STROBE_CORE_EXPORTEDFUNC_destructor(STROBE_CORE); + STROBE_CORE_EXPORTEDFUNC_destructor( STROBE_CORE ); } - STROBE_CORE_EXPORTEDFUNC_constructor(STROBE_CORE); + STROBE_CORE_EXPORTEDFUNC_constructor( STROBE_CORE ); } - -void STROBE_CORE_EXPORTEDFUNC_main(void **STROBE_CORE) +void STROBE_CORE_EXPORTEDFUNC_main( void **STROBE_CORE ) { STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; - - if (*instance) + if ( *instance ) { - (*instance)->STROBE_CORE_FUNC_main(instance); + ( *instance )->STROBE_CORE_FUNC_main( instance ); } } - -#endif \ No newline at end of file +#endif diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 3d8d183e7..dcbe18782 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -1,10 +1,10 @@ /* r_strobe_core.h - Software based strobing implementation -Copyright (C) 2018 - fuzun * github.com/fuzun +Copyright (C) 2018 - fuzun * github/fuzun For information: -https://forums.blurbusters.com + https://forums.blurbusters.com/viewtopic.php?f=7&t=3815&p=30401 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -24,36 +24,41 @@ See the GNU General Public License for more details. #include "r_strobe_api.h" #define STROBE_CORE Strobe_Core +#define STROBE_CORE_DEVIATION_LIMIT 2.75 +#define STROBE_CORE_DEVIATION_SIZE 60 + #define _STROBE_CORE_THIS self #define STROBE_CORE_FUNC_main main #define STROBE_CORE_FUNC_debughandler debugDrawer -#define STROBE_CORE_s STROBE_CORE ## _s -#define STROBE_CORE_t STROBE_CORE ## _t -#define STROBE_CORE_priv_s STROBE_CORE ## _priv_s -#define STROBE_CORE_priv_t STROBE_CORE ## _priv_t -#define STROBE_CORE_THIS (*_STROBE_CORE_THIS) -#define STROBE_CORE_THIS_PARAM STROBE_CORE_t**_STROBE_CORE_THIS -#define STROBE_CORE_EXPORTEDFUNC_main STROBE_CORE ## _STROBE_CORE_FUNC_main -#define STROBE_CORE_EXPORTEDFUNC_constructor STROBE_CORE ## _constructor -#define STROBE_CORE_EXPORTEDFUNC_destructor STROBE_CORE ## _destructor -#define STROBE_CORE_EXPORTEDFUNC_reinit STROBE_CORE ## _reinit +// ============= +#define STROBE_CORE_s STROBE_CORE##_s +#define STROBE_CORE_t STROBE_CORE##_t +#define STROBE_CORE_private_s STROBE_CORE##_priv_s +#define STROBE_CORE_private_t STROBE_CORE##_priv_t +#define STROBE_CORE_THIS ( *_STROBE_CORE_THIS ) +#define STROBE_CORE_THIS_PARAM STROBE_CORE_t **_STROBE_CORE_THIS +#define STROBE_CORE_EXPORTEDFUNC_main STROBE_CORE##_STROBE_CORE_FUNC_main +#define STROBE_CORE_EXPORTEDFUNC_constructor STROBE_CORE##_STROBE_CORE_FUNC_constructor +#define STROBE_CORE_EXPORTEDFUNC_destructor STROBE_CORE##_STROBE_CORE_FUNC_destructor +#define STROBE_CORE_EXPORTEDFUNC_reinit STROBE_CORE##_STROBE_CORE_FUNC_reinit +// ============= typedef struct STROBE_CORE_s STROBE_CORE_t; -typedef struct STROBE_CORE_priv_s STROBE_CORE_priv_t; +typedef struct STROBE_CORE_private_s STROBE_CORE_private_t; -typedef struct STROBE_CORE_s { +typedef struct STROBE_CORE_s +{ StrobeAPI_t base; - STROBE_CORE_priv_t *private; - void(*STROBE_CORE_FUNC_main)(STROBE_CORE_THIS_PARAM); - void(*STROBE_CORE_FUNC_debughandler)(STROBE_CORE_THIS_PARAM); + STROBE_CORE_private_t *private; + void ( *STROBE_CORE_FUNC_main )( STROBE_CORE_THIS_PARAM ); + void ( *STROBE_CORE_FUNC_debughandler )( STROBE_CORE_THIS_PARAM ); } STROBE_CORE_t; - -void STROBE_CORE_EXPORTEDFUNC_constructor(void **STROBE_CORE); -void STROBE_CORE_EXPORTEDFUNC_destructor(void **STROBE_CORE); -void STROBE_CORE_EXPORTEDFUNC_reinit(void **STROBE_CORE); -void STROBE_CORE_EXPORTEDFUNC_main(void **STROBE_CORE); - extern STROBE_CORE_t *STROBE_CORE; -#endif \ No newline at end of file +void STROBE_CORE_EXPORTEDFUNC_constructor( void **STROBE_CORE ); +void STROBE_CORE_EXPORTEDFUNC_destructor( void **STROBE_CORE ); +void STROBE_CORE_EXPORTEDFUNC_reinit( void **STROBE_CORE ); +void STROBE_CORE_EXPORTEDFUNC_main( void **STROBE_CORE ); + +#endif diff --git a/engine/client/strobe/r_strobe_template.c.TEMPLATE b/engine/client/strobe/r_strobe_template.c.TEMPLATE index 48e2bffd0..707bc0377 100644 --- a/engine/client/strobe/r_strobe_template.c.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.c.TEMPLATE @@ -1,10 +1,10 @@ /* r_strobe_template.c - Software based strobing implementation -Copyright (C) 2018 - fuzun * github.com/fuzun +Copyright (C) 2018 - fuzun * github/fuzun For information: -https://forums.blurbusters.com + https://forums.blurbusters.com/viewtopic.php?f=7&t=3815&p=30401 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,46 +21,36 @@ See the GNU General Public License for more details. #if !defined XASH_DEDICATED && !defined STROBE_DISABLED - -#include "r_strobe_base_protected_.h" -#include "r_strobe_template.h" -// #include "gl_local.h" +#include "r_strobe_core.h" #include "client.h" - +#include "gl_local.h" +#include "r_strobe_base_protected_.h" STROBE_TEMPLATE_t *STROBE_TEMPLATE = NULL; -typedef struct STROBE_TEMPLATE_priv_s { +typedef struct STROBE_TEMPLATE_private_s +{ // Private members -} STROBE_TEMPLATE_priv_t; +} STROBE_TEMPLATE_private_t; - -void STROBE_TEMPLATE_EXPORTEDFUNC_constructor(void **STROBE_TEMPLATE); -void STROBE_TEMPLATE_EXPORTEDFUNC_destructor(void **STROBE_TEMPLATE); -void STROBE_TEMPLATE_EXPORTEDFUNC_reinit(void **STROBE_TEMPLATE); -void STROBE_TEMPLATE_EXPORTEDFUNC_main(void **STROBE_TEMPLATE); - - - -static void main(STROBE_TEMPLATE_THIS_PARAM) +static void main( STROBE_TEMPLATE_THIS_PARAM ) { - STROBE_TEMPLATE_THIS->base.protected->frameInfo = (p_positive | f_normal); - STROBE_TEMPLATE_THIS->base.ProcessFrame(&STROBE_TEMPLATE_THIS->base); + STROBE_TEMPLATE_THIS->base.protected->frameInfo = ( p_positive | f_normal ); + STROBE_TEMPLATE_THIS->base.ProcessFrame( &STROBE_TEMPLATE_THIS->base ); } - -static inline void debugHandler(STROBE_TEMPLATE_THIS_PARAM) +static void debugHandler( STROBE_TEMPLATE_THIS_PARAM ) { char debugstr[2048]; - STROBE_TEMPLATE_THIS->base.Helpers.GenerateDebugStatistics(&STROBE_TEMPLATE_THIS->base, debugstr, 2048); + STROBE_TEMPLATE_THIS->base.Helpers.GenerateDebugStatistics( &STROBE_TEMPLATE_THIS->base, debugstr, 2048 ); } -void STROBE_TEMPLATE_EXPORTEDFUNC_constructor(void **STROBE_TEMPLATE) +void STROBE_TEMPLATE_EXPORTEDFUNC_constructor( void **STROBE_TEMPLATE ) { STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; *instance = (STROBE_TEMPLATE_t *)malloc(sizeof(STROBE_TEMPLATE_t)); - (*instance)->private = (STROBE_TEMPLATE_priv_t *)malloc(sizeof(STROBE_TEMPLATE_priv_t)); + (*instance)->private = (STROBE_TEMPLATE_private_t *)malloc(sizeof(STROBE_TEMPLATE_private_t)); (*instance)->STROBE_TEMPLATE_FUNC_main = main; (*instance)->STROBE_TEMPLATE_FUNC_debughandler = debugHandler; @@ -68,7 +58,7 @@ void STROBE_TEMPLATE_EXPORTEDFUNC_constructor(void **STROBE_TEMPLATE) } -void STROBE_TEMPLATE_EXPORTEDFUNC_destructor(void **STROBE_TEMPLATE) +void STROBE_TEMPLATE_EXPORTEDFUNC_destructor( void **STROBE_TEMPLATE ) { STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; @@ -85,7 +75,7 @@ void STROBE_TEMPLATE_EXPORTEDFUNC_destructor(void **STROBE_TEMPLATE) } } -void STROBE_TEMPLATE_EXPORTEDFUNC_reinit(void **STROBE_TEMPLATE) +void STROBE_TEMPLATE_EXPORTEDFUNC_reinit( void **STROBE_TEMPLATE ) { STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; diff --git a/engine/client/strobe/r_strobe_template.h.TEMPLATE b/engine/client/strobe/r_strobe_template.h.TEMPLATE index 07032f89b..89ec4e317 100644 --- a/engine/client/strobe/r_strobe_template.h.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.h.TEMPLATE @@ -1,10 +1,10 @@ /* r_strobe_template.h - Software based strobing implementation -Copyright (C) 2018 - fuzun * github.com/fuzun +Copyright (C) 2018 - fuzun * github/fuzun For information: -https://forums.blurbusters.com + https://forums.blurbusters.com/viewtopic.php?f=7&t=3815&p=30401 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -25,30 +25,30 @@ See the GNU General Public License for more details. #define STROBE_TEMPLATE Strobe_Example + #define _STROBE_TEMPLATE_THIS self #define STROBE_TEMPLATE_FUNC_main main #define STROBE_TEMPLATE_FUNC_debughandler debugHandler -// ===================== - +// ============= #define STROBE_TEMPLATE_s STROBE_TEMPLATE ## _s #define STROBE_TEMPLATE_t STROBE_TEMPLATE ## _t -#define STROBE_TEMPLATE_priv_s STROBE_TEMPLATE ## _priv_s -#define STROBE_TEMPLATE_priv_t STROBE_TEMPLATE ## _priv_t -#define STROBE_TEMPLATE_THIS (*_STROBE_TEMPLATE__THIS ## ) +#define STROBE_TEMPLATE_private_s STROBE_TEMPLATE ## _private_s +#define STROBE_TEMPLATE_private_t STROBE_TEMPLATE ## _private_t +#define STROBE_TEMPLATE_THIS (*_STROBE_TEMPLATE__THIS) #define STROBE_TEMPLATE_THIS_PARAM STROBE_TEMPLATE_t**_STROBE_TEMPLATE__THIS -#define STROBE_TEMPLATE_EXPORTEDFUNC_main STROBE_TEMPLATE ## _ ## STROBE_TEMPLATE_FUNC_main +#define STROBE_TEMPLATE_EXPORTEDFUNC_main STROBE_TEMPLATE _STROBE_TEMPLATE_FUNC_main #define STROBE_TEMPLATE_EXPORTEDFUNC_constructor STROBE_TEMPLATE ## _constructor #define STROBE_TEMPLATE_EXPORTEDFUNC_destructor STROBE_TEMPLATE ## _destructor #define STROBE_TEMPLATE_EXPORTEDFUNC_reinit STROBE_TEMPLATE ## _reinit +// ============= typedef struct STROBE_TEMPLATE_s STROBE_TEMPLATE_t; -typedef struct STROBE_TEMPLATE_priv_s STROBE_TEMPLATE_priv_t; - +typedef struct STROBE_TEMPLATE_private_s STROBE_TEMPLATE_private_t; typedef struct STROBE_TEMPLATE_s { StrobeAPI_t base; - STROBE_TEMPLATE_priv_t *private; + STROBE_TEMPLATE_private_t *private; void(*STROBE_TEMPLATE_FUNC_main)(STROBE_TEMPLATE_THIS_PARAM); void(*STROBE_TEMPLATE_FUNC_debughandler)(STROBE_TEMPLATE_THIS_PARAM); } STROBE_TEMPLATE_t; diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index fd8fa025f..d156c24e2 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -1097,10 +1097,9 @@ qboolean R_Init( void ) R_InitImages(); R_SpriteInit(); R_StudioInit(); - + #ifdef STROBE_ENABLED - R_InitStrobe(); - //StrobeInfo = new_Strobe(); + R_InitStrobeAPI(); #endif R_ClearDecals(); From 6c9e4da9e92b3e4a568a03f5d316951593b33544 Mon Sep 17 00:00:00 2001 From: fuzun Date: Fri, 9 Mar 2018 22:46:09 +0300 Subject: [PATCH 17/35] Fix non consistent draw of debug drawer --- engine/client/cl_scrn.c | 81 +++++++++++++++------------- engine/client/gl_rmain.c | 2 +- engine/client/strobe/r_strobe_api.h | 2 + engine/client/strobe/r_strobe_core.c | 8 ++- 4 files changed, 53 insertions(+), 40 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index d8ede2c9d..421a74ae8 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -49,78 +49,85 @@ static qboolean scr_init = false; SCR_DrawFPS ============== */ -void SCR_DrawFPS(void) +void SCR_DrawFPS( void ) { - float calc; - rgba_t color; - static double nexttime = 0, lasttime = 0; - static double framerate = 0, avgrate = 0; - static int framecount = 0; - static int minfps = 9999; - static int maxfps = 0; - double newtime; - char fpsstring[64]; - int offset; - - if (cls.state != ca_active) return; - if (!cl_showfps->integer || cl.background) return; - - switch (cls.scrshot_action) + float calc; + rgba_t color; + static double nexttime = 0, lasttime = 0; + static double framerate = 0, avgrate = 0; + static int framecount = 0; + static int minfps = 9999; + static int maxfps = 0; + double newtime; + char fpsstring[64]; + int offset; + + if ( cls.state != ca_active ) + return; + if ( !cl_showfps->integer || cl.background ) + return; + + switch ( cls.scrshot_action ) { case scrshot_normal: case scrshot_snapshot: case scrshot_inactive: break; - default: return; + default: + return; } - newtime = Sys_DoubleTime(); - if (newtime >= nexttime) + newtime = Sys_DoubleTime( ); + if ( newtime >= nexttime ) { - framerate = framecount / (newtime - lasttime); - lasttime = newtime; - nexttime = max(nexttime + 1, lasttime - 1); + framerate = framecount / ( newtime - lasttime ); + lasttime = newtime; + nexttime = max( nexttime + 1, lasttime - 1 ); framecount = 0; } framecount++; calc = framerate; - if (calc == 0) return; + if ( calc == 0 ) + return; - if (calc < 1.0f) + if ( calc < 1.0f ) { - Q_snprintf(fpsstring, sizeof(fpsstring), "%4i spf", (int)(1.0f / calc + 0.5f)); - MakeRGBA(color, 255, 0, 0, 255); + Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i spf", (int)( 1.0f / calc + 0.5f ) ); + MakeRGBA( color, 255, 0, 0, 255 ); } else { - int curfps = (int)(calc + 0.5f); + int curfps = (int)( calc + 0.5f ); - if (curfps < minfps) minfps = curfps; - if (curfps > maxfps) maxfps = curfps; + if ( curfps < minfps ) + minfps = curfps; + if ( curfps > maxfps ) + maxfps = curfps; /*if( !avgrate ) avgrate = ( maxfps - minfps ) / 2.0f; - else */avgrate += (calc - avgrate) / host.framecount; + else */ + avgrate += ( calc - avgrate ) / host.framecount; - switch (cl_showfps->integer) + switch ( cl_showfps->integer ) { case 3: - Q_snprintf(fpsstring, sizeof(fpsstring), "fps: ^1%4i min, ^3%4i cur, ^2%4i max | ^3%.2f avg", minfps, curfps, maxfps, avgrate); + Q_snprintf( fpsstring, sizeof( fpsstring ), "fps: ^1%4i min, ^3%4i cur, ^2%4i max | ^3%.2f avg", minfps, curfps, maxfps, avgrate ); break; case 2: - Q_snprintf(fpsstring, sizeof(fpsstring), "fps: ^1%4i min, ^3%4i cur, ^2%4i max", minfps, curfps, maxfps); + Q_snprintf( fpsstring, sizeof( fpsstring ), "fps: ^1%4i min, ^3%4i cur, ^2%4i max", minfps, curfps, maxfps ); break; case 1: default: - Q_snprintf(fpsstring, sizeof(fpsstring), "%4i fps", curfps); + Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i fps", curfps ); } - MakeRGBA(color, 255, 255, 255, 255); + MakeRGBA( color, 255, 255, 255, 255 ); } - Con_DrawStringLen(fpsstring, &offset, NULL); - Con_DrawString(scr_width->integer - offset - 2, 4, fpsstring, color); + Con_DrawStringLen( fpsstring, &offset, NULL ); + Con_DrawString( scr_width->integer - offset - 2, 4, fpsstring, color ); } /* diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 0c6ff282f..3a27840ce 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1336,7 +1336,7 @@ R_EndFrame void R_EndFrame( void ) { #ifdef STROBE_ENABLED - StrobeAPI.Invoker( (void **)( &STROBE_CORE ), STROBE_CORE_EXPORTEDFUNC_constructor, STROBE_CORE_EXPORTEDFUNC_main, STROBE_CORE_EXPORTEDFUNC_destructor ); + StrobeAPI.Invoker( STROBE_INVOKE(STROBE_CORE,STROBE_CORE_EXPORTEDFUNC_constructor,STROBE_CORE_EXPORTEDFUNC_main,STROBE_CORE_EXPORTEDFUNC_destructor) ); #else // flush any remaining 2D bits R_Set2DMode( false ); diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index a9c6f7f61..2fbc4d978 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -26,6 +26,8 @@ See the GNU General Public License for more details. #include "common.h" #include "wrect.h" +#define STROBE_INVOKE(IMPL,CONSTRUCTOR,MAIN,DESTRUCTOR) (void**)(&IMPL##),CONSTRUCTOR,##MAIN,##DESTRUCTOR + typedef struct StrobeAPI_s StrobeAPI_t; typedef enum diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index 02aaf21b3..ba44af4c7 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -200,7 +200,9 @@ _inline void debugDrawer( STROBE_CORE_THIS_PARAM ) { rgba_t color; char debugStr[2048]; // Heap allocation ? - int offsetX, offsetY; + static int offsetX; + int offsetY; + int fixer; qboolean strobeDebug = StrobeAPI.r_strobe_debug->integer ? true : false; @@ -229,11 +231,13 @@ _inline void debugDrawer( STROBE_CORE_THIS_PARAM ) } MakeRGBA( color, 255, 255, 255, 255 ); - Con_DrawStringLen( debugStr, &offsetX, &offsetY ); + Con_DrawStringLen( debugStr, &fixer, &offsetY ); if ( strobeDebug ) Con_DrawString( scr_width->integer - offsetX - 50, 4, debugStr, color ); else Con_DrawString( scr_width->integer - offsetX - 2, offsetY + 8, debugStr, color ); + if(abs(fixer - offsetX) > 30 || offsetX == 0) + offsetX = fixer; } void STROBE_CORE_EXPORTEDFUNC_constructor( void **STROBE_CORE ) From ec2c7b9be03ab870968f4573d1b6ab75b09a9867 Mon Sep 17 00:00:00 2001 From: fuzun Date: Fri, 9 Mar 2018 22:55:20 +0300 Subject: [PATCH 18/35] gcc fix --- engine/client/strobe/r_strobe_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 2fbc4d978..d59540202 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -26,7 +26,7 @@ See the GNU General Public License for more details. #include "common.h" #include "wrect.h" -#define STROBE_INVOKE(IMPL,CONSTRUCTOR,MAIN,DESTRUCTOR) (void**)(&IMPL##),CONSTRUCTOR,##MAIN,##DESTRUCTOR +#define STROBE_INVOKE(IMPL,CONSTRUCTOR,MAIN,DESTRUCTOR) (void**)(&IMPL),CONSTRUCTOR,MAIN,DESTRUCTOR typedef struct StrobeAPI_s StrobeAPI_t; From de7bbd95fe759322881919d3c8cac76ab61d772a Mon Sep 17 00:00:00 2001 From: fuzun Date: Wed, 28 Mar 2018 00:36:09 +0300 Subject: [PATCH 19/35] Better OOP & Bug Fix --- engine/client/cl_view.c | 2 +- engine/client/gl_rmain.c | 2 +- engine/client/strobe/r_strobe_api.c | 125 ++++++------ engine/client/strobe/r_strobe_api.h | 42 +++- ...protected_.h => r_strobe_api_protected_.h} | 17 +- engine/client/strobe/r_strobe_core.c | 190 ++++++++++-------- engine/client/strobe/r_strobe_core.h | 48 ++--- .../strobe/r_strobe_template.c.TEMPLATE | 82 ++++---- .../strobe/r_strobe_template.h.TEMPLATE | 49 ++--- 9 files changed, 283 insertions(+), 274 deletions(-) rename engine/client/strobe/{r_strobe_base_protected_.h => r_strobe_api_protected_.h} (70%) diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index c22c2b2a1..c40c91433 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -424,7 +424,7 @@ void V_PostRender( void ) #ifdef STROBE_ENABLED if ( STROBE_CORE ) - STROBE_CORE->STROBE_CORE_FUNC_debughandler( &STROBE_CORE ); + STROBE_CORE->STROBE_IMPL_FUNC_DEBUGHANDLER( &STROBE_CORE ); #endif SCR_DrawPos(); diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 3a27840ce..cb25cf808 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1336,7 +1336,7 @@ R_EndFrame void R_EndFrame( void ) { #ifdef STROBE_ENABLED - StrobeAPI.Invoker( STROBE_INVOKE(STROBE_CORE,STROBE_CORE_EXPORTEDFUNC_constructor,STROBE_CORE_EXPORTEDFUNC_main,STROBE_CORE_EXPORTEDFUNC_destructor) ); + StrobeAPI.Invoker( STROBE_INVOKE(STROBE_CORE) ); #else // flush any remaining 2D bits R_Set2DMode( false ); diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index fd63a95a3..584b37822 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -23,9 +23,9 @@ See the GNU General Public License for more details. #include "r_strobe_api.h" #include "client.h" #include "gl_local.h" -#include "r_strobe_base_protected_.h" +#include "r_strobe_api_protected_.h" -#define lossCalculator( x, y ) ( ( ( x ) - ( y ) ) * 100.0 / ( x ) ) // x : supposed y : current +#define lossCalculator( x, y ) ( ( ( x ) - ( y ) ) * 100.0 / ( x ) ) StrobeAPI_EXPORTS_t StrobeAPI; @@ -224,17 +224,17 @@ _inline void func_helper_GenerateDiffBar( StrobeAPI_t *self, char *src, int size } if ( type == 2 ) { - Q_strcat( src, va( "] - %4d", diff ) ); + Q_strcat( src, va( "] - %d / 200", diff ) ); } else { - Q_strcat( src, va( "] - %4d%%", ( Neg ? -diff : diff ) ) ); + Q_strcat( src, va( "] - %d%%", ( Neg ? -diff : diff ) ) ); } } -_inline int func_pwmsimulation_Frequency( StrobeAPI_t *self ) +_inline double func_pwmsimulation_Frequency( StrobeAPI_t *self ) { - return (int)round( ( 1 / ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) ) ); + return ( 1 / ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) ); } _inline double func_pwmsimulation_DutyCycle( void ) @@ -245,7 +245,10 @@ _inline double func_pwmsimulation_DutyCycle( void ) _inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *self ) { - return !!( self->protected->frameInfo & p_inverted ) ? ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000 : 0.0f; + if ( !!( self->protected->frameInfo & p_inverted ) ) + return ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; + else + return 0.0f; } _inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *self ) @@ -264,13 +267,6 @@ _inline double func_pwmsimulation_Period( StrobeAPI_t *self ) _inline double func_helper_GeometricMean( double x, double y ) { return sqrt( abs( x * y ) ); - /* - int multiply = (x * y); - if (multiply >= 0) - return sqrt(multiply); - else - return sqrt(abs(multiply)); - */ } _inline double func_helper_ArithmeticMean( double x, double y ) @@ -280,10 +276,7 @@ _inline double func_helper_ArithmeticMean( double x, double y ) _inline double func_brightnessreduction_ActualBrightnessReduction( StrobeAPI_t *self ) { - double currentFPS = self->Helpers.CurrentFPS( self ); - double effectiveFPS = self->Helpers.effectiveFPS( self ); - //return ((currentFPS - effectiveFPS) * 100.0 / currentFPS); - return lossCalculator( currentFPS, effectiveFPS ); + return lossCalculator( self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ) ); } _inline double func_brightnessreduction_LogarithmicBrightnessReduction( StrobeAPI_t *self, double base ) @@ -308,18 +301,17 @@ _inline double func_brightnessreduction_OtherBrightnessReduction( StrobeAPI_t *s _inline double func_experimental_Badness_Reducted( StrobeAPI_t *self, qboolean PWMInvolved ) { - double badness; + double badness, Diff; int diffP_NB, diffN_NB; - diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); - diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); double diffP = 0.0, diffN = 0.0; - double Diff; + diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); + diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); if ( self->protected->pCounter ) - diffP = round( abs( diffP_NB ) * 100 / self->protected->pCounter ); + diffP = abs( diffP_NB ) * 100.0 / self->protected->pCounter; if ( self->protected->nCounter ) - diffN = round( abs( diffN_NB ) * 100 / self->protected->nCounter ); + diffN = abs( diffN_NB ) * 100.0 / self->protected->nCounter; if ( diffP_NB < 0.0 ) diffP = -diffP; @@ -344,29 +336,33 @@ _inline double func_experimental_Badness_Reducted( StrobeAPI_t *self, qboolean P _inline double func_experimental_Badness( StrobeAPI_t *self, qboolean PWMInvolved ) { int diffP_NB, diffN_NB; + double diffP = 0.0, diffN = 0.0; + double absoluteDifference = 0.0; + double badness = 0.0; + diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); - double diffP = 0.0, diffN = 0.0; - if ( self->protected->pCounter ) - diffP = round( abs( diffP_NB ) * 100 / self->protected->pCounter ); + diffP = abs( diffP_NB ) * 100.0 / self->protected->pCounter; if ( self->protected->nCounter ) - diffN = round( abs( diffN_NB ) * 100 / self->protected->nCounter ); + diffN = abs( diffN_NB ) * 100.0 / self->protected->nCounter; - double absoluteDifference = fabs( diffP - diffN ); + absoluteDifference = fabs( diffP - diffN ); if ( absoluteDifference > 100.0 ) absoluteDifference = 100.0; - double badness = + + badness = -log( ( ( absoluteDifference + func_helper_GeometricMean( ( 100.0 - diffP ), ( 100.0 - diffN ) ) ) / ( absoluteDifference + func_helper_GeometricMean( diffP, diffN ) ) ) ); + if ( PWMInvolved ) return ( badness * func_pwmsimulation_Period( self ) ); else return badness; } -_inline size_t get_FrameCounter( StrobeAPI_t *self, STROBE_counterType type ) +_inline size_t func_get_FrameCounter( StrobeAPI_t *self, STROBE_counterType type ) { switch ( type ) { @@ -405,10 +401,9 @@ _inline size_t get_FrameCounter( StrobeAPI_t *self, STROBE_counterType type ) return self->protected->fCounter; break; } - return self->protected->fCounter; } -_inline double get_currentFPS( StrobeAPI_t *self ) +_inline double func_get_currentFPS( StrobeAPI_t *self ) { // Copied from SCR_DrawFps // This way until current fps becomes global!!! @@ -423,7 +418,7 @@ _inline double get_currentFPS( StrobeAPI_t *self ) { framerate = ( self->protected->fCounter - mark ) / ( newtime - lasttime ); lasttime = newtime; - nexttime = max( nexttime + 0.5, lasttime - 0.5 ); // Make Update tick configurable ? + nexttime = max( nexttime + 0.35, lasttime - 0.35 ); mark = self->protected->fCounter; } @@ -433,54 +428,59 @@ _inline double get_currentFPS( StrobeAPI_t *self ) _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) { char diffBarP[128], diffBarN[128], diffBarT[128]; - + static size_t PositiveNormal, PositiveBlack, NegativeNormal, NegativeBlack; + size_t nPositiveNormal, nPositiveBlack, nNegativeNormal, nNegativeBlack; int diffP_NB, diffN_NB; + double diffP = 0.0, diffN = 0.0; + double cooldown = self->protected->cdTimer; + diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); - double diffP = 0.0, diffN = 0.0; - if ( self->protected->pCounter ) - diffP = round( abs( diffP_NB ) * 100 / self->protected->pCounter ); + diffP = abs( diffP_NB ) * 100.0 / self->protected->pCounter; // round( abs( diffP_NB ) * 100 / self->protected->pCounter ); if ( self->protected->nCounter ) - diffN = round( abs( diffN_NB ) * 100 / self->protected->nCounter ); + diffN = abs( diffN_NB ) * 100.0 / self->protected->nCounter; // round( abs( diffN_NB ) * 100 / self->protected->nCounter ); self->Helpers.GenerateDiffBar( self, diffBarP, sizeof( diffBarP ), 0 ); self->Helpers.GenerateDiffBar( self, diffBarN, sizeof( diffBarN ), 1 ); self->Helpers.GenerateDiffBar( self, diffBarT, sizeof( diffBarT ), 2 ); - double cooldown = self->protected->cdTimer; + nPositiveNormal = self->get.FrameCounter( self, STROBE_CT_PositiveNormalFrame ); + nPositiveBlack = self->get.FrameCounter( self, STROBE_CT_PositiveBlackFrame ); + nNegativeNormal = self->get.FrameCounter( self, STROBE_CT_NegativeNormalFrame ); + nNegativeBlack = self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ); Q_snprintf( src, size, "%.2f FPS\n%.2f eFPS\n" - "Total Frame Count: %u\n" - "(+) Phase Frame Count: %u\n" - " |-> Normal Frame Count: %u\n" - " |-> Black Frame Count: %u\n" - "(-) Phase Frame Count: %u\n" - " |-> Normal Frame Count: %u\n" - " |-> Black Frame Count: %u\n" - ".isPhaseInverted: %d\n" + "Total Frame Count: %zu\n" + "isPhaseInverted = %d\n" + "^7(+) Phase Frame Count: %zu\n" + "%s\n" + "%s\n" + "(-) Phase Frame Count: %zu\n" + "%s\n" + "%s\n" "^5=====ANALYSIS=====\n^3" "PWM Simulation:\n" - " |-> Frequency: %d Hz\n" + " |-> Frequency: %.2f Hz\n" " |-> Duty Cycle: %.2f%%\n" " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" " |-> Period: %.4f msec\n" "Brightness Reduction:\n" - " |-> [^7LINEAR^3] Actual Reduction: %3f%%\n" + " |-> [^7LINEAR^3] Actual Reduction: %.2f%%\n" " |-> [^7LOG^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" " |-> [^7SQUARE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" " |-> [^7CUBE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" - "Difference (+): %s\nDifference (-): %s\nDifference (+ & -): %s\n" /* Diff 3 (Total): |Diff + - Diff -| . Max 200 Min 0*/ + "Difference (+): %s\nDifference (-): %s\nDifference (+ & -): %s\n" "Geometric Mean: %.4f\n" "G/A Difference: %.4f\n" "[^7EXPERIMENTAL^3] Badness: %.4f\n" "[^7EXPERIMENTAL^3] Badness x PWM Period: %.4f\n" "[^7EXPERIMENTAL^3] Badness (Reducted): %.4f\n" - "[^7EXPERIMENTAL^3] Badness (Reducted) x PWM Period: %.4f\n" /* Badness -log((200-n)/n) */ + "[^7EXPERIMENTAL^3] Badness (Reducted) x PWM Period: %.4f\n" "Stability:\n" " |-> Standard Deviation: %.3f\n" " |-> Cooldown: %s\n" @@ -488,13 +488,13 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ), self->get.FrameCounter( self, STROBE_CT_TotalFrame ), + self->Helpers.isPhaseInverted( self ), self->get.FrameCounter( self, STROBE_CT_PositiveFrame ), - self->get.FrameCounter( self, STROBE_CT_PositiveNormalFrame ), - self->get.FrameCounter( self, STROBE_CT_PositiveBlackFrame ), + ( nPositiveNormal > PositiveNormal ? va( "^2|-> Normal Frame Count: %zu^7", nPositiveNormal ) : va( "|-> Normal Frame Count: %zu", nPositiveNormal ) ), // Should be white instead of ^7 but white is not available in the color table + ( nPositiveBlack > PositiveBlack ? va( "^2|-> Black Frame Count: %zu^7", nPositiveBlack ) : va( "|-> Black Frame Count: %zu", nPositiveBlack ) ), self->get.FrameCounter( self, STROBE_CT_NegativeFrame ), - self->get.FrameCounter( self, STROBE_CT_NegativeNormalFrame ), - self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ), - self->Helpers.isPhaseInverted( self ), + ( nNegativeNormal > NegativeNormal ? va( "^2|-> Normal Frame Count: %zu^7", nNegativeNormal ) : va( "|-> Normal Frame Count: %zu", nNegativeNormal ) ), + ( nNegativeBlack > NegativeBlack ? va( "^2|-> Black Frame Count: %zu^7", nNegativeBlack ) : va( "|-> Black Frame Count: %zu", nNegativeBlack ) ), self->PWM.Frequency( self ), self->PWM.DutyCycle( ), self->PWM.PositivePhaseShift( self ), @@ -514,7 +514,12 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) self->Experimentals.BADNESS_REDUCTED( self, false ), self->Experimentals.BADNESS_REDUCTED( self, true ), self->protected->deviation, - ( cooldown > 0.0 && self->protected->cdTriggered ? va( "^1 %.2f secs\n[STROBING DISABLED] ^3", (double)StrobeAPI.r_strobe_cooldown->integer - cooldown ) : "0" ) ); + ( cooldown >= 0.0 && self->protected->cdTriggered ? va( "^1 %.2f secs\n[STROBING DISABLED] ^3", (double)StrobeAPI.r_strobe_cooldown->integer - cooldown ) : "0" ) ); + + PositiveNormal = self->get.FrameCounter( self, STROBE_CT_PositiveNormalFrame ); + PositiveBlack = self->get.FrameCounter( self, STROBE_CT_PositiveBlackFrame ); + NegativeNormal = self->get.FrameCounter( self, STROBE_CT_NegativeNormalFrame ); + NegativeBlack = self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ); } _inline void ProcessFrame( StrobeAPI_t *self ) @@ -560,7 +565,6 @@ _inline void StrobeAPI_constructor( StrobeAPI_t *self ) self->Helpers.GenerateDiffBar = func_helper_GenerateDiffBar; self->Helpers.GeometricMean = func_helper_GeometricMean; self->Helpers.Cooldown = func_helper_getCooldown; - self->Helpers.CurrentFPS = get_currentFPS; self->Helpers.isPhaseInverted = func_helper_isPhaseInverted; self->Helpers.isNormal = func_helper_isNormal; self->Helpers.isPositive = func_helper_isPositive; @@ -577,10 +581,11 @@ _inline void StrobeAPI_constructor( StrobeAPI_t *self ) self->PWM.PositivePhaseShift = func_pwmsimulation_PositivePhaseShift; self->PWM.NegativePhaseShift = func_pwmsimulation_NegativePhaseShift; self->PWM.Period = func_pwmsimulation_Period; + self->Helpers.CurrentFPS = func_get_currentFPS; + self->get.FrameCounter = func_get_FrameCounter; self->GenerateBlackFrame = GL_GenerateBlackFrame; self->ProcessFrame = ProcessFrame; self->Helpers.GenerateDebugStatistics = GenerateDebugStatistics; - self->get.FrameCounter = get_FrameCounter; } _inline void StrobeAPI_destructor( StrobeAPI_t *self ) diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index d59540202..7f5f9b711 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -21,12 +21,35 @@ See the GNU General Public License for more details. #if !defined R_STROBE_API_H && !defined STROBE_DISABLED #define R_STROBE_API_H -#define STROBE_ENABLED - #include "common.h" #include "wrect.h" -#define STROBE_INVOKE(IMPL,CONSTRUCTOR,MAIN,DESTRUCTOR) (void**)(&IMPL),CONSTRUCTOR,MAIN,DESTRUCTOR + +#define STROBE_ENABLED + +// MACROS FOR STROBE IMPLEMENTATIONS +#define STROBE_IMPL(_IMPL) STROBE_##_IMPL +#define STROBE_IMPL_(IMPL) IMPL_ +#define _STROBE_IMPL_THIS STROBE_self +#define STROBE_IMPL_FUNC_MAIN STROBE_main +#define STROBE_IMPL_FUNC_DEBUGHANDLER STROBE_debugHandler +#define STROBE_IMPL_FUNC_CONSTRUCTOR STROBE_constructor +#define STROBE_IMPL_FUNC_DESTRUCTOR STROBE_destructor +#define STROBE_IMPL_FUNC_REINIT STROBE_reinit + +#define STROBE_IMPL_STRUCT_S(IMPL) IMPL##_s +#define STROBE_IMPL_STRUCT_T(IMPL) IMPL##_t +#define STROBE_IMPL_PRIVATE_S(IMPL) IMPL##_private_s +#define STROBE_IMPL_PRIVATE_T(IMPL) IMPL##_private_t +#define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) +#define STROBE_IMPL_THIS_PARAM(IMPL) STROBE_IMPL_STRUCT_T(IMPL) **_STROBE_IMPL_THIS +#define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_MAIN +#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_CONSTRUCTOR +#define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_DESTRUCTOR +#define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_REINIT + +#define STROBE_INVOKE(IMPL) (void**)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) +// MACROS FOR STROBE IMPLEMENTATIONS typedef struct StrobeAPI_s StrobeAPI_t; @@ -58,7 +81,7 @@ typedef struct StrobeAPI_funcs_EXPERIMENTAL_s typedef struct StrobeAPI_funcs_PWMSIMULATION_s { - int ( *Frequency )( StrobeAPI_t *self ); + double ( *Frequency )( StrobeAPI_t *self ); double ( *DutyCycle )( void ); double ( *PositivePhaseShift )( StrobeAPI_t *self ); double ( *NegativePhaseShift )( StrobeAPI_t *self ); @@ -74,16 +97,16 @@ typedef struct StrobeAPI_funcs_HELPER_s double ( *CurrentFPS )( StrobeAPI_t *self ); void ( *GenerateDebugStatistics )( StrobeAPI_t *self, char *src, int size ); void ( *GenerateDiffBar )( StrobeAPI_t *self, char *src, int size, char type ); - double ( *GeometricMean )( double, double ); - double ( *ArithmeticMean )( double, double ); + double ( *GeometricMean )( double x, double y ); + double ( *ArithmeticMean )( double x, double y ); double ( *StandardDeviation )( const double *data, int size ); double ( *Cooldown )( StrobeAPI_t *self ); } StrobeAPI_funcs_HELPER_t; -typedef struct StrobeAPI_GET_s +typedef struct StrobeAPI_funcs_GET_s { size_t ( *FrameCounter )( StrobeAPI_t *self, STROBE_counterType ); -} StrobeAPI_GET_t; +} StrobeAPI_funcs_GET_t; typedef struct StrobeAPI_protected_s StrobeAPI_protected_t; @@ -94,7 +117,7 @@ typedef struct StrobeAPI_s StrobeAPI_funcs_BRIGHTNESSREDUCTION_t BrightnessReductions; StrobeAPI_funcs_PWMSIMULATION_t PWM; StrobeAPI_funcs_HELPER_t Helpers; - StrobeAPI_GET_t get; + StrobeAPI_funcs_GET_t get; void ( *GenerateBlackFrame )( void ); void ( *ProcessFrame )( StrobeAPI_t *self ); } StrobeAPI_t; @@ -105,7 +128,6 @@ typedef struct StrobeAPI_EXPORTS_s void ( *Constructor )( StrobeAPI_t *self ); void ( *Destructor )( StrobeAPI_t *self ); - // Strobe related convars should be in StrobeAPI derived implementations! convar_t *r_strobe; convar_t *r_strobe_swapinterval; convar_t *r_strobe_debug; diff --git a/engine/client/strobe/r_strobe_base_protected_.h b/engine/client/strobe/r_strobe_api_protected_.h similarity index 70% rename from engine/client/strobe/r_strobe_base_protected_.h rename to engine/client/strobe/r_strobe_api_protected_.h index 74c5c3bdd..9154e3fd5 100644 --- a/engine/client/strobe/r_strobe_base_protected_.h +++ b/engine/client/strobe/r_strobe_api_protected_.h @@ -1,5 +1,5 @@ /* -r_strobe_base_protected_.h - Software based strobing implementation +r_strobe_api_protected_.h - Software based strobing implementation Copyright (C) 2018 - fuzun * github/fuzun @@ -18,8 +18,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ -#if !defined R_STROBE_BASE_PROTECTED_ && !defined STROBE_DISABLED -#define R_STROBE_BASE_PROTECTED_ +#if !defined R_STROBE_API_PROTECTED_ && !defined STROBE_DISABLED +#define R_STROBE_API_PROTECTED_ #include "common.h" @@ -37,10 +37,11 @@ typedef struct StrobeAPI_protected_s size_t nCounter, nNCounter, nBCounter; // Negative phase counters int strobeInterval; int swapInterval; - double deviation; // deviation - double cdTimer; // Cooldown timer - qboolean cdTriggered; - fstate_e frameInfo; // Frame info -} StrobeAPI_protected_t; // Protected members + fstate_e frameInfo; // Frame info + + double deviation; // deviation - Should be in implementation! + double cdTimer; // Cooldown timer - Should be in implementation! + qboolean cdTriggered; // Cooldown trigger flag - Should be in implementation! +} StrobeAPI_protected_t; // Protected members #endif diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index ba44af4c7..5a52789ae 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -23,16 +23,21 @@ See the GNU General Public License for more details. #include "r_strobe_core.h" #include "client.h" #include "gl_local.h" -#include "r_strobe_base_protected_.h" +#include "r_strobe_api_protected_.h" -STROBE_CORE_t *STROBE_CORE = NULL; +#ifdef _this +#undef _this +#endif +#define _this STROBE_IMPL_THIS( STROBE_CORE ) + +STROBE_IMPL_STRUCT_T( STROBE_CORE ) *STROBE_CORE = NULL; -typedef struct STROBE_CORE_private_s +typedef struct STROBE_IMPL_PRIVATE_S( STROBE_CORE ) { double recentTime, recentTime2; - double delta[STROBE_CORE_DEVIATION_SIZE]; // double *delta; + double delta[STROBE_CORE_DEVIATION_SIZE]; size_t fCounterSnapshot; -} STROBE_CORE_private_t; +} STROBE_IMPL_PRIVATE_T( STROBE_CORE ); /* =============== @@ -44,12 +49,12 @@ R_Strobe * Implement high precision timer to keep the internal phase on track with monitor. (In case of freezes etc.) =============== */ -static void R_Strobe( STROBE_CORE_THIS_PARAM ) +static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) { double delta, delta2; - double currentTime = Sys_DoubleTime( ); - delta2 = currentTime - STROBE_CORE_THIS->private->recentTime2; - STROBE_CORE_THIS->private->recentTime2 = currentTime; + double currentTime = Sys_DoubleTime( ); + delta2 = currentTime - _this->private->recentTime2; + _this->private->recentTime2 = currentTime; if ( CL_IsInMenu( ) ) { @@ -57,153 +62,154 @@ static void R_Strobe( STROBE_CORE_THIS_PARAM ) return; } - if ( STROBE_CORE_THIS->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) - STROBE_CORE_THIS->base.protected->cdTimer += delta2; - if ( STROBE_CORE_THIS->base.protected->fCounter - STROBE_CORE_THIS->private->fCounterSnapshot == 1 ) + if ( _this->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) + _this->base.protected->cdTimer += delta2; + if ( _this->base.protected->fCounter - _this->private->fCounterSnapshot == 1 ) { - STROBE_CORE_THIS->private->delta[STROBE_CORE_THIS->base.protected->fCounter % ARRAYSIZE( STROBE_CORE_THIS->private->delta )] = delta2; - STROBE_CORE_THIS->base.protected->deviation = STROBE_CORE_THIS->base.Helpers.StandardDeviation( STROBE_CORE_THIS->private->delta, ARRAYSIZE( STROBE_CORE_THIS->private->delta ) ) * 1000; + _this->private->delta[_this->base.protected->fCounter % ARRAYSIZE( _this->private->delta )] = delta2; + _this->base.protected->deviation = _this->base.Helpers.StandardDeviation( _this->private->delta, ARRAYSIZE( _this->private->delta ) ) * 1000; } - STROBE_CORE_THIS->private->fCounterSnapshot = STROBE_CORE_THIS->base.protected->fCounter; + _this->private->fCounterSnapshot = _this->base.protected->fCounter; if ( StrobeAPI.r_strobe_cooldown->integer > 0 ) { - if ( ( STROBE_CORE_THIS->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && STROBE_CORE_THIS->base.protected->cdTriggered == true ) + if ( ( _this->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && _this->base.protected->cdTriggered == true ) { - STROBE_CORE_THIS->base.protected->cdTriggered = false; - STROBE_CORE_THIS->base.protected->cdTimer = -1.0; + _this->base.protected->cdTriggered = false; + _this->base.protected->cdTimer = -1.0; } - if ( STROBE_CORE_THIS->base.protected->fCounter > ARRAYSIZE( STROBE_CORE_THIS->private->delta ) ) + if ( _this->base.protected->fCounter > ARRAYSIZE( _this->private->delta ) ) { - if ( STROBE_CORE_THIS->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) + if ( _this->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) { - STROBE_CORE_THIS->base.protected->cdTriggered = false; - STROBE_CORE_THIS->base.protected->cdTimer = 0.0; + _this->base.protected->cdTriggered = true; + _this->base.protected->cdTimer = 0.0; } } } else { - STROBE_CORE_THIS->base.protected->cdTriggered = false; + _this->base.protected->cdTriggered = false; } - if ( ( ( STROBE_CORE_THIS->base.protected->strobeInterval != StrobeAPI.r_strobe->integer ) && ( STROBE_CORE_THIS->base.protected->strobeInterval ) ) || + if ( ( ( _this->base.protected->strobeInterval != StrobeAPI.r_strobe->integer ) && ( _this->base.protected->strobeInterval ) ) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - STROBE_CORE_THIS->base.protected->fCounter == UINT_MAX ) + _this->base.protected->fCounter == UINT_MAX ) { - STROBE_CORE_EXPORTEDFUNC_reinit( *(void ***)&_STROBE_CORE_THIS ); - R_Strobe( &STROBE_CORE_THIS ); + STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( *(void ***)&_STROBE_IMPL_THIS ); + R_Strobe( &_this ); } - STROBE_CORE_THIS->base.protected->strobeInterval = StrobeAPI.r_strobe->integer; - STROBE_CORE_THIS->base.protected->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; + _this->base.protected->strobeInterval = StrobeAPI.r_strobe->integer; + _this->base.protected->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; - if ( ( STROBE_CORE_THIS->base.protected->strobeInterval == 0 ) || - ( ( gl_swapInterval->integer == 0 ) && ( STROBE_CORE_THIS->base.protected->strobeInterval ) ) ) + if ( ( _this->base.protected->strobeInterval == 0 ) || + ( ( gl_swapInterval->integer == 0 ) && ( _this->base.protected->strobeInterval ) ) ) { if ( !gl_swapInterval->integer ) MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - if ( STROBE_CORE_THIS->base.protected->strobeInterval ) // If v-sync is off, turn off strobing + if ( _this->base.protected->strobeInterval ) // If v-sync is off, turn off strobing { Cvar_Set( "r_strobe", "0" ); } - STROBE_CORE_THIS->base.protected->fCounter = 0; + _this->base.protected->fCounter = 0; R_Set2DMode( false ); return; } - if ( ( STROBE_CORE_THIS->base.protected->fCounter % 2 ) == 0 ) + if ( ( _this->base.protected->fCounter % 2 ) == 0 ) { - ++STROBE_CORE_THIS->base.protected->pCounter; - STROBE_CORE_THIS->base.protected->frameInfo |= p_positive; + ++_this->base.protected->pCounter; + _this->base.protected->frameInfo |= p_positive; } else { - ++STROBE_CORE_THIS->base.protected->nCounter; - STROBE_CORE_THIS->base.protected->frameInfo &= ~p_positive; + ++_this->base.protected->nCounter; + _this->base.protected->frameInfo &= ~p_positive; } - if ( STROBE_CORE_THIS->base.protected->swapInterval < 0 ) - STROBE_CORE_THIS->base.protected->swapInterval = abs( STROBE_CORE_THIS->base.protected->swapInterval ); + if ( _this->base.protected->swapInterval < 0 ) + _this->base.protected->swapInterval = abs( _this->base.protected->swapInterval ); - if ( ( STROBE_CORE_THIS->base.protected->swapInterval ) && ( STROBE_CORE_THIS->base.protected->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ( ( _this->base.protected->swapInterval ) && ( _this->base.protected->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { - delta = currentTime - STROBE_CORE_THIS->private->recentTime; // New Currenttime for _delta ? - if ( ( delta >= (double)( STROBE_CORE_THIS->base.protected->swapInterval ) ) && ( delta < (double)( 2 * STROBE_CORE_THIS->base.protected->swapInterval ) ) ) // Basic timer + delta = currentTime - _this->private->recentTime; // New Currenttime for _delta ? + if ( ( delta >= (double)( _this->base.protected->swapInterval ) ) && ( delta < (double)( 2 * _this->base.protected->swapInterval ) ) ) // Basic timer { - STROBE_CORE_THIS->base.protected->frameInfo |= p_inverted; + _this->base.protected->frameInfo |= p_inverted; } - else if ( delta < (double)( STROBE_CORE_THIS->base.protected->swapInterval ) ) + else if ( delta < (double)( _this->base.protected->swapInterval ) ) { - STROBE_CORE_THIS->base.protected->frameInfo &= ~p_inverted; + _this->base.protected->frameInfo &= ~p_inverted; } else //if (delta >= (double)(2 * swapInterval)) { - STROBE_CORE_THIS->private->recentTime = currentTime; + _this->private->recentTime = currentTime; } } - switch ( STROBE_CORE_THIS->base.protected->frameInfo & ( p_positive | p_inverted ) ) + switch ( _this->base.protected->frameInfo & ( p_positive | p_inverted ) ) { case ( p_positive | p_inverted ): - if ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 ) == 0 ) - STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->pCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) / 2 ) ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + if ( ( abs( _this->base.protected->strobeInterval ) % 2 ) == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == ( abs( _this->base.protected->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even else - STROBE_CORE_THIS->base.protected->frameInfo &= ~f_normal; + _this->base.protected->frameInfo &= ~f_normal; break; case ( p_positive & ~p_inverted ): - if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 == 0 ) - STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->pCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + if ( abs( _this->base.protected->strobeInterval ) % 2 == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even else { - if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) == 1 ) - STROBE_CORE_THIS->base.protected->frameInfo |= f_normal; + if ( abs( _this->base.protected->strobeInterval ) == 1 ) + _this->base.protected->frameInfo |= f_normal; else - STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->pCounter - 1 ) % ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( ( abs( _this->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //odd } break; case ( ~p_positive & p_inverted ): - if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 == 0 ) - STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->nCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + if ( abs( _this->base.protected->strobeInterval ) % 2 == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even else { - if ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) == 1 ) - STROBE_CORE_THIS->base.protected->frameInfo |= f_normal; + if ( abs( _this->base.protected->strobeInterval ) == 1 ) + _this->base.protected->frameInfo |= f_normal; else - STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->nCounter - 1 ) % ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //odd + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( ( abs( _this->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //odd } break; case 0: - if ( ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) % 2 ) == 0 ) - STROBE_CORE_THIS->base.protected->frameInfo = ( ( ( STROBE_CORE_THIS->base.protected->nCounter - 1 ) % ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) + 1 ) ) == ( abs( STROBE_CORE_THIS->base.protected->strobeInterval ) / 2 ) ) ? STROBE_CORE_THIS->base.protected->frameInfo | f_normal : STROBE_CORE_THIS->base.protected->frameInfo & ~f_normal; //even + if ( ( abs( _this->base.protected->strobeInterval ) % 2 ) == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == ( abs( _this->base.protected->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even else - STROBE_CORE_THIS->base.protected->frameInfo &= ~f_normal; + _this->base.protected->frameInfo &= ~f_normal; break; default: - STROBE_CORE_THIS->base.protected->frameInfo = ( p_positive | f_normal ); + _this->base.protected->frameInfo = ( p_positive | f_normal ); } - if ( STROBE_CORE_THIS->base.protected->strobeInterval < 0 ) - STROBE_CORE_THIS->base.protected->frameInfo ^= f_normal; + if ( _this->base.protected->strobeInterval < 0 ) + _this->base.protected->frameInfo ^= f_normal; - STROBE_CORE_THIS->base.ProcessFrame( &STROBE_CORE_THIS->base ); + _this->base.ProcessFrame( &_this->base ); } -_inline void debugDrawer( STROBE_CORE_THIS_PARAM ) +_inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) { rgba_t color; - char debugStr[2048]; // Heap allocation ? + static char debugStr[2048]; // Heap allocation ? static int offsetX; int offsetY; int fixer; - + static double nexttime = 0, lasttime = 0; + double newtime; qboolean strobeDebug = StrobeAPI.r_strobe_debug->integer ? true : false; if ( cls.state != ca_active ) @@ -223,11 +229,17 @@ _inline void debugDrawer( STROBE_CORE_THIS_PARAM ) if ( strobeDebug ) { - STROBE_CORE_THIS->base.Helpers.GenerateDebugStatistics( &STROBE_CORE_THIS->base, debugStr, ARRAYSIZE( debugStr ) ); + newtime = Sys_DoubleTime( ); + if ( newtime >= nexttime ) + { + _this->base.Helpers.GenerateDebugStatistics( &_this->base, debugStr, ARRAYSIZE( debugStr ) ); + lasttime = newtime; + nexttime = max( nexttime + 0.15, lasttime - 0.15 ); // Make this configurable + } } else if ( cl_showfps->integer ) { - Q_snprintf( debugStr, sizeof( debugStr ), "%3d eFPS", (int)round( STROBE_CORE_THIS->base.Helpers.effectiveFPS( &STROBE_CORE_THIS->base ) ) ); + Q_snprintf( debugStr, sizeof( debugStr ), "%3d eFPS", (int)round( _this->base.Helpers.effectiveFPS( &_this->base ) ) ); } MakeRGBA( color, 255, 255, 255, 255 ); @@ -236,25 +248,25 @@ _inline void debugDrawer( STROBE_CORE_THIS_PARAM ) Con_DrawString( scr_width->integer - offsetX - 50, 4, debugStr, color ); else Con_DrawString( scr_width->integer - offsetX - 2, offsetY + 8, debugStr, color ); - if(abs(fixer - offsetX) > 30 || offsetX == 0) + if ( abs( fixer - offsetX ) > 30 || offsetX == 0 ) offsetX = fixer; } -void STROBE_CORE_EXPORTEDFUNC_constructor( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) { - STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + STROBE_IMPL_STRUCT_T( STROBE_CORE ) **instance = *(STROBE_IMPL_STRUCT_T( STROBE_CORE ) ***)&STROBE_CORE; - *instance = (STROBE_CORE_t *)malloc( sizeof( STROBE_CORE_t ) ); - ( *instance )->private = (STROBE_CORE_private_t *)calloc( 1, sizeof( STROBE_CORE_private_t ) ); - ( *instance )->STROBE_CORE_FUNC_main = R_Strobe; - ( *instance )->STROBE_CORE_FUNC_debughandler = debugDrawer; + *instance = (STROBE_IMPL_STRUCT_T( STROBE_CORE ) *)malloc( sizeof( STROBE_IMPL_STRUCT_T( STROBE_CORE ) ) ); + ( *instance )->private = (STROBE_IMPL_PRIVATE_T( STROBE_CORE ) *)calloc( 1, sizeof( STROBE_IMPL_PRIVATE_T( STROBE_CORE ) ) ); + ( *instance )->STROBE_IMPL_FUNC_MAIN = R_Strobe; + ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugDrawer; StrobeAPI.Constructor( &( *instance )->base ); } -void STROBE_CORE_EXPORTEDFUNC_destructor( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ) { - STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + STROBE_IMPL_STRUCT_T( STROBE_CORE ) **instance = *(STROBE_IMPL_STRUCT_T( STROBE_CORE ) ***)&STROBE_CORE; if ( *instance ) { @@ -269,22 +281,24 @@ void STROBE_CORE_EXPORTEDFUNC_destructor( void **STROBE_CORE ) } } -void STROBE_CORE_EXPORTEDFUNC_reinit( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ) { if ( !( *STROBE_CORE ) ) { - STROBE_CORE_EXPORTEDFUNC_destructor( STROBE_CORE ); + STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( STROBE_CORE ); } - STROBE_CORE_EXPORTEDFUNC_constructor( STROBE_CORE ); + STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( STROBE_CORE ); } -void STROBE_CORE_EXPORTEDFUNC_main( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ) { - STROBE_CORE_t **instance = *(STROBE_CORE_t ***)&STROBE_CORE; + STROBE_IMPL_STRUCT_T( STROBE_CORE ) **instance = *(STROBE_IMPL_STRUCT_T( STROBE_CORE ) ***)&STROBE_CORE; if ( *instance ) { - ( *instance )->STROBE_CORE_FUNC_main( instance ); + ( *instance )->STROBE_IMPL_FUNC_MAIN( instance ); } } +#undef _this + #endif diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index dcbe18782..84498a7cf 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -23,42 +23,26 @@ See the GNU General Public License for more details. #include "r_strobe_api.h" -#define STROBE_CORE Strobe_Core -#define STROBE_CORE_DEVIATION_LIMIT 2.75 -#define STROBE_CORE_DEVIATION_SIZE 60 - -#define _STROBE_CORE_THIS self -#define STROBE_CORE_FUNC_main main -#define STROBE_CORE_FUNC_debughandler debugDrawer +#define STROBE_CORE STROBE_IMPL( CORE ) -// ============= -#define STROBE_CORE_s STROBE_CORE##_s -#define STROBE_CORE_t STROBE_CORE##_t -#define STROBE_CORE_private_s STROBE_CORE##_priv_s -#define STROBE_CORE_private_t STROBE_CORE##_priv_t -#define STROBE_CORE_THIS ( *_STROBE_CORE_THIS ) -#define STROBE_CORE_THIS_PARAM STROBE_CORE_t **_STROBE_CORE_THIS -#define STROBE_CORE_EXPORTEDFUNC_main STROBE_CORE##_STROBE_CORE_FUNC_main -#define STROBE_CORE_EXPORTEDFUNC_constructor STROBE_CORE##_STROBE_CORE_FUNC_constructor -#define STROBE_CORE_EXPORTEDFUNC_destructor STROBE_CORE##_STROBE_CORE_FUNC_destructor -#define STROBE_CORE_EXPORTEDFUNC_reinit STROBE_CORE##_STROBE_CORE_FUNC_reinit -// ============= +#define STROBE_CORE_DEVIATION_LIMIT 2.5 +#define STROBE_CORE_DEVIATION_SIZE 60 -typedef struct STROBE_CORE_s STROBE_CORE_t; -typedef struct STROBE_CORE_private_s STROBE_CORE_private_t; +typedef struct STROBE_IMPL_STRUCT_S( STROBE_CORE ) STROBE_IMPL_STRUCT_T( STROBE_CORE ); +typedef struct STROBE_IMPL_PRIVATE_S( STROBE_CORE ) STROBE_IMPL_PRIVATE_T( STROBE_CORE ); -typedef struct STROBE_CORE_s +typedef struct STROBE_IMPL_STRUCT_S( STROBE_CORE ) { StrobeAPI_t base; - STROBE_CORE_private_t *private; - void ( *STROBE_CORE_FUNC_main )( STROBE_CORE_THIS_PARAM ); - void ( *STROBE_CORE_FUNC_debughandler )( STROBE_CORE_THIS_PARAM ); -} STROBE_CORE_t; -extern STROBE_CORE_t *STROBE_CORE; - -void STROBE_CORE_EXPORTEDFUNC_constructor( void **STROBE_CORE ); -void STROBE_CORE_EXPORTEDFUNC_destructor( void **STROBE_CORE ); -void STROBE_CORE_EXPORTEDFUNC_reinit( void **STROBE_CORE ); -void STROBE_CORE_EXPORTEDFUNC_main( void **STROBE_CORE ); + STROBE_IMPL_PRIVATE_T( STROBE_CORE ) * private; + void ( *STROBE_IMPL_FUNC_MAIN )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); + void ( *STROBE_IMPL_FUNC_DEBUGHANDLER )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); +} STROBE_IMPL_STRUCT_T( STROBE_CORE ); +extern STROBE_IMPL_STRUCT_T( STROBE_CORE ) * STROBE_CORE; + +void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ); #endif diff --git a/engine/client/strobe/r_strobe_template.c.TEMPLATE b/engine/client/strobe/r_strobe_template.c.TEMPLATE index 707bc0377..2904ba206 100644 --- a/engine/client/strobe/r_strobe_template.c.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.c.TEMPLATE @@ -21,81 +21,83 @@ See the GNU General Public License for more details. #if !defined XASH_DEDICATED && !defined STROBE_DISABLED -#include "r_strobe_core.h" +#include "r_strobe_template.h" +#include "r_strobe_api_protected_.h" #include "client.h" #include "gl_local.h" -#include "r_strobe_base_protected_.h" -STROBE_TEMPLATE_t *STROBE_TEMPLATE = NULL; +#ifdef _this +#undef _this +#endif +#define _this STROBE_IMPL_THIS(STROBE_TEMPLATE) -typedef struct STROBE_TEMPLATE_private_s +STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) *STROBE_TEMPLATE = NULL; + +typedef struct STROBE_IMPL_PRIVATE_S(STROBE_TEMPLATE) { // Private members -} STROBE_TEMPLATE_private_t; +} STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE); -static void main( STROBE_TEMPLATE_THIS_PARAM ) +static void main( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) { - STROBE_TEMPLATE_THIS->base.protected->frameInfo = ( p_positive | f_normal ); - STROBE_TEMPLATE_THIS->base.ProcessFrame( &STROBE_TEMPLATE_THIS->base ); + _this->base.protected->frameInfo = ( p_positive | f_normal ); + _this->base.ProcessFrame( &_this->base ); } -static void debugHandler( STROBE_TEMPLATE_THIS_PARAM ) +static void debugHandler( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) { - char debugstr[2048]; - STROBE_TEMPLATE_THIS->base.Helpers.GenerateDebugStatistics( &STROBE_TEMPLATE_THIS->base, debugstr, 2048 ); + char debugstr[2048] = {0}; + _this->base.Helpers.GenerateDebugStatistics( &_this->base, debugstr, 2048 ); } -void STROBE_TEMPLATE_EXPORTEDFUNC_constructor( void **STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { - STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; - *instance = (STROBE_TEMPLATE_t *)malloc(sizeof(STROBE_TEMPLATE_t)); + STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) **instance = *(STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; - (*instance)->private = (STROBE_TEMPLATE_private_t *)malloc(sizeof(STROBE_TEMPLATE_private_t)); - (*instance)->STROBE_TEMPLATE_FUNC_main = main; - (*instance)->STROBE_TEMPLATE_FUNC_debughandler = debugHandler; + *instance = (STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) *)malloc( sizeof( STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ) ); + ( *instance )->private = (STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) *)calloc( 1, sizeof( STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) ) ); + ( *instance )->STROBE_IMPL_FUNC_MAIN = R_Strobe; + ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugDrawer; - StrobeAPI_constructor(&(*instance)->base); + StrobeAPI.Constructor( &( *instance )->base ); } - -void STROBE_TEMPLATE_EXPORTEDFUNC_destructor( void **STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { - STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; - - if (*instance) + STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) **instance = *(STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; + + if ( *instance ) { - StrobeAPI_destructor(&(*instance)->base); - if ((*instance)->private) + StrobeAPI.Destructor( &( *instance )->base ); + if ( ( *instance )->private ) { - free((*instance)->private); - (*instance)->private = NULL; + free( ( *instance )->private ); + ( *instance )->private = NULL; } - free(*instance); + free( *instance ); *instance = NULL; } } -void STROBE_TEMPLATE_EXPORTEDFUNC_reinit( void **STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { - STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; - - if (!(*STROBE_TEMPLATE)) + if ( !( *STROBE_TEMPLATE ) ) { - STROBE_TEMPLATE_EXPORTEDFUNC_destructor(instance); + STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( STROBE_TEMPLATE ); } - STROBE_TEMPLATE_EXPORTEDFUNC_constructor(instance); + STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( STROBE_TEMPLATE ); } - -void STROBE_TEMPLATE_EXPORTEDFUNC_main(void **STROBE_TEMPLATE) +void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { - STROBE_TEMPLATE_t **instance = *(STROBE_TEMPLATE_t ***)&STROBE_TEMPLATE; - - if (*instance) + STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) **instance = *(STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; + if ( *instance ) { - (*instance)->STROBE_TEMPLATE_FUNC_main(instance); + ( *instance )->STROBE_IMPL_FUNC_MAIN( instance ); } } +#undef _this + #endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_template.h.TEMPLATE b/engine/client/strobe/r_strobe_template.h.TEMPLATE index 89ec4e317..9107c0156 100644 --- a/engine/client/strobe/r_strobe_template.h.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.h.TEMPLATE @@ -23,42 +23,23 @@ See the GNU General Public License for more details. #include "r_strobe_api.h" +#define STROBE_TEMPLATE STROBE_IMPL(TEMPLATE) -#define STROBE_TEMPLATE Strobe_Example +typedef struct STROBE_IMPL_STRUCT_S( STROBE_TEMPLATE ) STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE); +typedef struct STROBE_IMPL_PRIVATE_S( STROBE_TEMPLATE ) STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE); -#define _STROBE_TEMPLATE_THIS self -#define STROBE_TEMPLATE_FUNC_main main -#define STROBE_TEMPLATE_FUNC_debughandler debugHandler - -// ============= -#define STROBE_TEMPLATE_s STROBE_TEMPLATE ## _s -#define STROBE_TEMPLATE_t STROBE_TEMPLATE ## _t -#define STROBE_TEMPLATE_private_s STROBE_TEMPLATE ## _private_s -#define STROBE_TEMPLATE_private_t STROBE_TEMPLATE ## _private_t -#define STROBE_TEMPLATE_THIS (*_STROBE_TEMPLATE__THIS) -#define STROBE_TEMPLATE_THIS_PARAM STROBE_TEMPLATE_t**_STROBE_TEMPLATE__THIS -#define STROBE_TEMPLATE_EXPORTEDFUNC_main STROBE_TEMPLATE _STROBE_TEMPLATE_FUNC_main -#define STROBE_TEMPLATE_EXPORTEDFUNC_constructor STROBE_TEMPLATE ## _constructor -#define STROBE_TEMPLATE_EXPORTEDFUNC_destructor STROBE_TEMPLATE ## _destructor -#define STROBE_TEMPLATE_EXPORTEDFUNC_reinit STROBE_TEMPLATE ## _reinit -// ============= - -typedef struct STROBE_TEMPLATE_s STROBE_TEMPLATE_t; -typedef struct STROBE_TEMPLATE_private_s STROBE_TEMPLATE_private_t; - -typedef struct STROBE_TEMPLATE_s { +typedef struct STROBE_IMPL_STRUCT_S(STROBE_TEMPLATE) +{ StrobeAPI_t base; - STROBE_TEMPLATE_private_t *private; - void(*STROBE_TEMPLATE_FUNC_main)(STROBE_TEMPLATE_THIS_PARAM); - void(*STROBE_TEMPLATE_FUNC_debughandler)(STROBE_TEMPLATE_THIS_PARAM); -} STROBE_TEMPLATE_t; - -extern STROBE_TEMPLATE_t *STROBE_TEMPLATE; - -void STROBE_TEMPLATE_EXPORTEDFUNC_constructor(void **STROBE_TEMPLATE); -void STROBE_TEMPLATE_EXPORTEDFUNC_destructor(void **STROBE_TEMPLATE); -void STROBE_TEMPLATE_EXPORTEDFUNC_reinit(void **STROBE_TEMPLATE); -void STROBE_TEMPLATE_EXPORTEDFUNC_main(void **STROBE_TEMPLATE); - + STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) *private; + void ( *STROBE_IMPL_FUNC_MAIN)(STROBE_IMPL_THIS_PARAM(STROBE_TEMPLATE)); + void ( *STROBE_IMPL_FUNC_DEBUGHANDLER)(STROBE_IMPL_THIS_PARAM(STROBE_TEMPLATE)); +} STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE); +extern STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) *STROBE_TEMPLATE; + +void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); #endif \ No newline at end of file From e81370a0c40d61af68ed9e1628da55c286aa41a3 Mon Sep 17 00:00:00 2001 From: fuzun Date: Wed, 28 Mar 2018 00:56:03 +0300 Subject: [PATCH 20/35] GCC Fix ? --- engine/client/cl_scrn.c | 2 -- engine/client/strobe/r_strobe_api.h | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 421a74ae8..6f6f0ff81 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -22,8 +22,6 @@ GNU General Public License for more details. #include "qfont.h" #include "library.h" -#include "strobe/r_strobe_core.h" - convar_t *scr_centertime; convar_t *scr_loading; convar_t *scr_download; diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 7f5f9b711..aacab4925 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -43,10 +43,10 @@ See the GNU General Public License for more details. #define STROBE_IMPL_PRIVATE_T(IMPL) IMPL##_private_t #define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) #define STROBE_IMPL_THIS_PARAM(IMPL) STROBE_IMPL_STRUCT_T(IMPL) **_STROBE_IMPL_THIS -#define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_MAIN -#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_CONSTRUCTOR -#define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_DESTRUCTOR -#define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_REINIT +#define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_MAIN +#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_CONSTRUCTOR +#define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_DESTRUCTOR +#define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_REINIT #define STROBE_INVOKE(IMPL) (void**)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) // MACROS FOR STROBE IMPLEMENTATIONS From f46692db838aeeaec8088b2e1df7fdf775cc4b5d Mon Sep 17 00:00:00 2001 From: fuzun Date: Wed, 28 Mar 2018 01:03:38 +0300 Subject: [PATCH 21/35] Revert "GCC Fix ?" This reverts commit e81370a0c40d61af68ed9e1628da55c286aa41a3. --- engine/client/cl_scrn.c | 2 ++ engine/client/strobe/r_strobe_api.h | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 6f6f0ff81..421a74ae8 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -22,6 +22,8 @@ GNU General Public License for more details. #include "qfont.h" #include "library.h" +#include "strobe/r_strobe_core.h" + convar_t *scr_centertime; convar_t *scr_loading; convar_t *scr_download; diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index aacab4925..7f5f9b711 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -43,10 +43,10 @@ See the GNU General Public License for more details. #define STROBE_IMPL_PRIVATE_T(IMPL) IMPL##_private_t #define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) #define STROBE_IMPL_THIS_PARAM(IMPL) STROBE_IMPL_STRUCT_T(IMPL) **_STROBE_IMPL_THIS -#define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_MAIN -#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_CONSTRUCTOR -#define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_DESTRUCTOR -#define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_(IMPL)##STROBE_IMPL_FUNC_REINIT +#define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_MAIN +#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_CONSTRUCTOR +#define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_DESTRUCTOR +#define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_REINIT #define STROBE_INVOKE(IMPL) (void**)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) // MACROS FOR STROBE IMPLEMENTATIONS From 2a43c7d6368b0005b93bcd345c354d228d61495a Mon Sep 17 00:00:00 2001 From: fuzun Date: Wed, 28 Mar 2018 13:34:41 +0300 Subject: [PATCH 22/35] GCC Fix ? --- engine/client/strobe/r_strobe_api.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 7f5f9b711..80ab92508 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -30,6 +30,8 @@ See the GNU General Public License for more details. // MACROS FOR STROBE IMPLEMENTATIONS #define STROBE_IMPL(_IMPL) STROBE_##_IMPL #define STROBE_IMPL_(IMPL) IMPL_ +#define _STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) STROBE_IMPL_(IMPL)##FUNC +#define STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) _STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) #define _STROBE_IMPL_THIS STROBE_self #define STROBE_IMPL_FUNC_MAIN STROBE_main #define STROBE_IMPL_FUNC_DEBUGHANDLER STROBE_debugHandler @@ -43,10 +45,10 @@ See the GNU General Public License for more details. #define STROBE_IMPL_PRIVATE_T(IMPL) IMPL##_private_t #define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) #define STROBE_IMPL_THIS_PARAM(IMPL) STROBE_IMPL_STRUCT_T(IMPL) **_STROBE_IMPL_THIS -#define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_MAIN -#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_CONSTRUCTOR -#define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_DESTRUCTOR -#define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_(IMPL)STROBE_IMPL_FUNC_REINIT +#define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_MAIN) +#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL)STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_CONSTRUCTOR) +#define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_DESTRUCTOR) +#define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_REINIT) #define STROBE_INVOKE(IMPL) (void**)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) // MACROS FOR STROBE IMPLEMENTATIONS From 4db52f1f5d9d5957be215188a4c9fbff5353df22 Mon Sep 17 00:00:00 2001 From: fuzun Date: Wed, 28 Mar 2018 13:54:38 +0300 Subject: [PATCH 23/35] GCC Fix #2 ? --- engine/client/strobe/r_strobe_api.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 80ab92508..f20ad534a 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -29,15 +29,15 @@ See the GNU General Public License for more details. // MACROS FOR STROBE IMPLEMENTATIONS #define STROBE_IMPL(_IMPL) STROBE_##_IMPL -#define STROBE_IMPL_(IMPL) IMPL_ -#define _STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) STROBE_IMPL_(IMPL)##FUNC -#define STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) _STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) -#define _STROBE_IMPL_THIS STROBE_self -#define STROBE_IMPL_FUNC_MAIN STROBE_main -#define STROBE_IMPL_FUNC_DEBUGHANDLER STROBE_debugHandler -#define STROBE_IMPL_FUNC_CONSTRUCTOR STROBE_constructor -#define STROBE_IMPL_FUNC_DESTRUCTOR STROBE_destructor -#define STROBE_IMPL_FUNC_REINIT STROBE_reinit +#define STROBE_CONCAT(SRC1, SRC2) SRC1##SRC2 +#define STROBE_IMPL_EXPORTFUNC_(IMPL, FUNC) STROBE_CONCAT(IMPL, FUNC) +#define STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) STROBE_IMPL_EXPORTFUNC_(STROBE_IMPL_EXPORTFUNC_(IMPL,_), FUNC) // GCC Workaround +#define _STROBE_IMPL_THIS self +#define STROBE_IMPL_FUNC_MAIN main +#define STROBE_IMPL_FUNC_DEBUGHANDLER debugHandler +#define STROBE_IMPL_FUNC_CONSTRUCTOR constructor +#define STROBE_IMPL_FUNC_DESTRUCTOR destructor +#define STROBE_IMPL_FUNC_REINIT reinit #define STROBE_IMPL_STRUCT_S(IMPL) IMPL##_s #define STROBE_IMPL_STRUCT_T(IMPL) IMPL##_t @@ -46,7 +46,7 @@ See the GNU General Public License for more details. #define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) #define STROBE_IMPL_THIS_PARAM(IMPL) STROBE_IMPL_STRUCT_T(IMPL) **_STROBE_IMPL_THIS #define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_MAIN) -#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL)STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_CONSTRUCTOR) +#define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_CONSTRUCTOR) #define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_DESTRUCTOR) #define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_REINIT) From bb5d06587eb97998d39802ded3754cea79413db1 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 31 Mar 2018 20:51:16 +0300 Subject: [PATCH 24/35] Record elapsed time & small fixes --- engine/client/cl_scrn.c | 2 -- engine/client/strobe/r_strobe_api.c | 7 +++++-- engine/client/strobe/r_strobe_api_protected_.h | 7 ++++--- engine/client/strobe/r_strobe_core.c | 3 ++- engine/client/strobe/r_strobe_template.c.TEMPLATE | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 421a74ae8..6f6f0ff81 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -22,8 +22,6 @@ GNU General Public License for more details. #include "qfont.h" #include "library.h" -#include "strobe/r_strobe_core.h" - convar_t *scr_centertime; convar_t *scr_loading; convar_t *scr_download; diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 584b37822..5268526c0 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -455,8 +455,9 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) Q_snprintf( src, size, "%.2f FPS\n%.2f eFPS\n" + "Elapsed Time: %.2f\n" + "isPhaseInverted = %d\n" "Total Frame Count: %zu\n" - "isPhaseInverted = %d\n" "^7(+) Phase Frame Count: %zu\n" "%s\n" "%s\n" @@ -487,8 +488,9 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) "^5=====ANALYSIS=====\n^3", self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ), + self->protected->elapsedTime, + self->Helpers.isPhaseInverted(self), self->get.FrameCounter( self, STROBE_CT_TotalFrame ), - self->Helpers.isPhaseInverted( self ), self->get.FrameCounter( self, STROBE_CT_PositiveFrame ), ( nPositiveNormal > PositiveNormal ? va( "^2|-> Normal Frame Count: %zu^7", nPositiveNormal ) : va( "|-> Normal Frame Count: %zu", nPositiveNormal ) ), // Should be white instead of ^7 but white is not available in the color table ( nPositiveBlack > PositiveBlack ? va( "^2|-> Black Frame Count: %zu^7", nPositiveBlack ) : va( "|-> Black Frame Count: %zu", nPositiveBlack ) ), @@ -560,6 +562,7 @@ _inline void StrobeAPI_constructor( StrobeAPI_t *self ) return; // Fix handling! } self->protected->frameInfo = ( p_positive | f_normal ); + self->protected->initialTime = Sys_DoubleTime( ); self->Helpers.ArithmeticMean = func_helper_ArithmeticMean; self->Helpers.effectiveFPS = func_helper_effectiveFPS; self->Helpers.GenerateDiffBar = func_helper_GenerateDiffBar; diff --git a/engine/client/strobe/r_strobe_api_protected_.h b/engine/client/strobe/r_strobe_api_protected_.h index 9154e3fd5..914dd3dd6 100644 --- a/engine/client/strobe/r_strobe_api_protected_.h +++ b/engine/client/strobe/r_strobe_api_protected_.h @@ -37,11 +37,12 @@ typedef struct StrobeAPI_protected_s size_t nCounter, nNCounter, nBCounter; // Negative phase counters int strobeInterval; int swapInterval; + double initialTime, elapsedTime; fstate_e frameInfo; // Frame info - double deviation; // deviation - Should be in implementation! - double cdTimer; // Cooldown timer - Should be in implementation! - qboolean cdTriggered; // Cooldown trigger flag - Should be in implementation! + double deviation; // deviation + double cdTimer; // Cooldown timer + qboolean cdTriggered; // Cooldown trigger status } StrobeAPI_protected_t; // Protected members #endif diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index 5a52789ae..8ae6d1b9b 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -55,6 +55,7 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) double currentTime = Sys_DoubleTime( ); delta2 = currentTime - _this->private->recentTime2; _this->private->recentTime2 = currentTime; + _this->base.protected->elapsedTime = currentTime - _this->base.protected->initialTime; if ( CL_IsInMenu( ) ) { @@ -248,7 +249,7 @@ _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) Con_DrawString( scr_width->integer - offsetX - 50, 4, debugStr, color ); else Con_DrawString( scr_width->integer - offsetX - 2, offsetY + 8, debugStr, color ); - if ( abs( fixer - offsetX ) > 30 || offsetX == 0 ) + if ( abs( fixer - offsetX ) > 50 || offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! offsetX = fixer; } diff --git a/engine/client/strobe/r_strobe_template.c.TEMPLATE b/engine/client/strobe/r_strobe_template.c.TEMPLATE index 2904ba206..016626bd1 100644 --- a/engine/client/strobe/r_strobe_template.c.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.c.TEMPLATE @@ -56,8 +56,8 @@ void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLA *instance = (STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) *)malloc( sizeof( STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ) ); ( *instance )->private = (STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) *)calloc( 1, sizeof( STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) ) ); - ( *instance )->STROBE_IMPL_FUNC_MAIN = R_Strobe; - ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugDrawer; + ( *instance )->STROBE_IMPL_FUNC_MAIN = main; + ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugHandler; StrobeAPI.Constructor( &( *instance )->base ); } From 1c1be721fd7a5e5d830ebcd4d9447c3f466ac619 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 31 Mar 2018 21:33:51 +0300 Subject: [PATCH 25/35] Reduced macros --- engine/client/strobe/r_strobe_api.h | 19 +++++++++---------- engine/client/strobe/r_strobe_core.c | 16 ++++++++-------- engine/client/strobe/r_strobe_core.h | 12 ++++++------ .../strobe/r_strobe_template.c.TEMPLATE | 16 ++++++++-------- .../strobe/r_strobe_template.h.TEMPLATE | 12 ++++++------ 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index f20ad534a..0c1dd7bb9 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -28,23 +28,22 @@ See the GNU General Public License for more details. #define STROBE_ENABLED // MACROS FOR STROBE IMPLEMENTATIONS -#define STROBE_IMPL(_IMPL) STROBE_##_IMPL -#define STROBE_CONCAT(SRC1, SRC2) SRC1##SRC2 -#define STROBE_IMPL_EXPORTFUNC_(IMPL, FUNC) STROBE_CONCAT(IMPL, FUNC) -#define STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) STROBE_IMPL_EXPORTFUNC_(STROBE_IMPL_EXPORTFUNC_(IMPL,_), FUNC) // GCC Workaround +#define STROBE_CONCAT_(SRC1, SRC2) SRC1##SRC2 +#define STROBE_CONCAT(SRC1, SRC2) STROBE_CONCAT_(SRC1, SRC2) // GCC Workaround + +#define STROBE_IMPL(_IMPL) STROBE_CONCAT(STROBE_, _IMPL) +#define STROBE_IMPL_EXPORTFUNC(IMPL, FUNC) STROBE_CONCAT(STROBE_CONCAT(IMPL,_), FUNC) #define _STROBE_IMPL_THIS self #define STROBE_IMPL_FUNC_MAIN main #define STROBE_IMPL_FUNC_DEBUGHANDLER debugHandler #define STROBE_IMPL_FUNC_CONSTRUCTOR constructor #define STROBE_IMPL_FUNC_DESTRUCTOR destructor #define STROBE_IMPL_FUNC_REINIT reinit - -#define STROBE_IMPL_STRUCT_S(IMPL) IMPL##_s -#define STROBE_IMPL_STRUCT_T(IMPL) IMPL##_t -#define STROBE_IMPL_PRIVATE_S(IMPL) IMPL##_private_s -#define STROBE_IMPL_PRIVATE_T(IMPL) IMPL##_private_t +#define STROBE_IMPL_STRUCT(IMPL) STROBE_CONCAT(IMPL, _s) +#define STROBE_IMPL_PRIVATE_STRUCT(IMPL) STROBE_CONCAT(IMPL, _private_s) #define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) -#define STROBE_IMPL_THIS_PARAM(IMPL) STROBE_IMPL_STRUCT_T(IMPL) **_STROBE_IMPL_THIS +#define STROBE_IMPL_THIS_PARAM(IMPL) struct STROBE_IMPL_STRUCT(IMPL) **_STROBE_IMPL_THIS + #define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_MAIN) #define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_CONSTRUCTOR) #define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_DESTRUCTOR) diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index 8ae6d1b9b..dba26c2d7 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -30,14 +30,14 @@ See the GNU General Public License for more details. #endif #define _this STROBE_IMPL_THIS( STROBE_CORE ) -STROBE_IMPL_STRUCT_T( STROBE_CORE ) *STROBE_CORE = NULL; +struct STROBE_IMPL_STRUCT( STROBE_CORE ) *STROBE_CORE = NULL; -typedef struct STROBE_IMPL_PRIVATE_S( STROBE_CORE ) +struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) { double recentTime, recentTime2; double delta[STROBE_CORE_DEVIATION_SIZE]; size_t fCounterSnapshot; -} STROBE_IMPL_PRIVATE_T( STROBE_CORE ); +}; /* =============== @@ -255,10 +255,10 @@ _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) { - STROBE_IMPL_STRUCT_T( STROBE_CORE ) **instance = *(STROBE_IMPL_STRUCT_T( STROBE_CORE ) ***)&STROBE_CORE; + struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; - *instance = (STROBE_IMPL_STRUCT_T( STROBE_CORE ) *)malloc( sizeof( STROBE_IMPL_STRUCT_T( STROBE_CORE ) ) ); - ( *instance )->private = (STROBE_IMPL_PRIVATE_T( STROBE_CORE ) *)calloc( 1, sizeof( STROBE_IMPL_PRIVATE_T( STROBE_CORE ) ) ); + *instance = (struct STROBE_IMPL_STRUCT( STROBE_CORE ) *)malloc( sizeof(struct STROBE_IMPL_STRUCT(STROBE_CORE)) ); + ( *instance )->private = (struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *)calloc( 1, sizeof(struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_CORE)) ); ( *instance )->STROBE_IMPL_FUNC_MAIN = R_Strobe; ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugDrawer; @@ -267,7 +267,7 @@ void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ) { - STROBE_IMPL_STRUCT_T( STROBE_CORE ) **instance = *(STROBE_IMPL_STRUCT_T( STROBE_CORE ) ***)&STROBE_CORE; + struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; if ( *instance ) { @@ -293,7 +293,7 @@ void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ) void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ) { - STROBE_IMPL_STRUCT_T( STROBE_CORE ) **instance = *(STROBE_IMPL_STRUCT_T( STROBE_CORE ) ***)&STROBE_CORE; + struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; if ( *instance ) { ( *instance )->STROBE_IMPL_FUNC_MAIN( instance ); diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 84498a7cf..8131e03c0 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -28,17 +28,17 @@ See the GNU General Public License for more details. #define STROBE_CORE_DEVIATION_LIMIT 2.5 #define STROBE_CORE_DEVIATION_SIZE 60 -typedef struct STROBE_IMPL_STRUCT_S( STROBE_CORE ) STROBE_IMPL_STRUCT_T( STROBE_CORE ); -typedef struct STROBE_IMPL_PRIVATE_S( STROBE_CORE ) STROBE_IMPL_PRIVATE_T( STROBE_CORE ); +struct STROBE_IMPL_STRUCT( STROBE_CORE ); +struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ); -typedef struct STROBE_IMPL_STRUCT_S( STROBE_CORE ) +struct STROBE_IMPL_STRUCT( STROBE_CORE ) { StrobeAPI_t base; - STROBE_IMPL_PRIVATE_T( STROBE_CORE ) * private; + struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *private; void ( *STROBE_IMPL_FUNC_MAIN )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); void ( *STROBE_IMPL_FUNC_DEBUGHANDLER )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); -} STROBE_IMPL_STRUCT_T( STROBE_CORE ); -extern STROBE_IMPL_STRUCT_T( STROBE_CORE ) * STROBE_CORE; +}; +extern struct STROBE_IMPL_STRUCT( STROBE_CORE ) * STROBE_CORE; void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ); void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ); diff --git a/engine/client/strobe/r_strobe_template.c.TEMPLATE b/engine/client/strobe/r_strobe_template.c.TEMPLATE index 016626bd1..d62d92792 100644 --- a/engine/client/strobe/r_strobe_template.c.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.c.TEMPLATE @@ -31,12 +31,12 @@ See the GNU General Public License for more details. #endif #define _this STROBE_IMPL_THIS(STROBE_TEMPLATE) -STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) *STROBE_TEMPLATE = NULL; +struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) *STROBE_TEMPLATE = NULL; -typedef struct STROBE_IMPL_PRIVATE_S(STROBE_TEMPLATE) +struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_TEMPLATE) { // Private members -} STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE); +}; static void main( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) { @@ -52,10 +52,10 @@ static void debugHandler( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { - STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) **instance = *(STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; + struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; - *instance = (STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) *)malloc( sizeof( STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ) ); - ( *instance )->private = (STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) *)calloc( 1, sizeof( STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) ) ); + *instance = (struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) *)malloc( sizeof( struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ) ); + ( *instance )->private = (struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_TEMPLATE) *)calloc( 1, sizeof( struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_TEMPLATE) ) ); ( *instance )->STROBE_IMPL_FUNC_MAIN = main; ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugHandler; @@ -64,7 +64,7 @@ void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLA void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { - STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) **instance = *(STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; + struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; if ( *instance ) { @@ -90,7 +90,7 @@ void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { - STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) **instance = *(STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; + struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; if ( *instance ) { ( *instance )->STROBE_IMPL_FUNC_MAIN( instance ); diff --git a/engine/client/strobe/r_strobe_template.h.TEMPLATE b/engine/client/strobe/r_strobe_template.h.TEMPLATE index 9107c0156..341c19491 100644 --- a/engine/client/strobe/r_strobe_template.h.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.h.TEMPLATE @@ -25,17 +25,17 @@ See the GNU General Public License for more details. #define STROBE_TEMPLATE STROBE_IMPL(TEMPLATE) -typedef struct STROBE_IMPL_STRUCT_S( STROBE_TEMPLATE ) STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE); -typedef struct STROBE_IMPL_PRIVATE_S( STROBE_TEMPLATE ) STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE); +struct STROBE_IMPL_STRUCT( STROBE_TEMPLATE ); +struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_TEMPLATE ); -typedef struct STROBE_IMPL_STRUCT_S(STROBE_TEMPLATE) +struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) { StrobeAPI_t base; - STROBE_IMPL_PRIVATE_T(STROBE_TEMPLATE) *private; + struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_TEMPLATE) *private; void ( *STROBE_IMPL_FUNC_MAIN)(STROBE_IMPL_THIS_PARAM(STROBE_TEMPLATE)); void ( *STROBE_IMPL_FUNC_DEBUGHANDLER)(STROBE_IMPL_THIS_PARAM(STROBE_TEMPLATE)); -} STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE); -extern STROBE_IMPL_STRUCT_T(STROBE_TEMPLATE) *STROBE_TEMPLATE; +}; +extern struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) *STROBE_TEMPLATE; void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); From 2bcc54fe92208873014956b8611d828c604212e6 Mon Sep 17 00:00:00 2001 From: fuzun Date: Fri, 6 Apr 2018 23:49:59 +0300 Subject: [PATCH 26/35] Fixes & Better oop --- engine/client/strobe/r_strobe_api.c | 70 +++++++----- engine/client/strobe/r_strobe_api.h | 3 + .../client/strobe/r_strobe_api_protected_.h | 13 +-- engine/client/strobe/r_strobe_core.c | 106 +++++++++--------- 4 files changed, 103 insertions(+), 89 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 5268526c0..288b085f1 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -29,6 +29,13 @@ See the GNU General Public License for more details. StrobeAPI_EXPORTS_t StrobeAPI; +typedef struct StrobeAPI_private_s +{ + double nexttime, lasttime, framerate; + size_t mark; + size_t PositiveNormal, PositiveBlack, NegativeNormal, NegativeBlack; +}StrobeAPI_private_t; + _inline double func_helper_StandardDeviation( const double *data, int n ) { double mean = 0.0, sum_deviation = 0.0; @@ -80,7 +87,7 @@ _inline double func_helper_getCooldown( StrobeAPI_t *self ) _inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *self ) { - if ( self->protected->frameInfo & p_inverted ) + if ( self->protected->frameInfo & PHASE_INVERTED ) return true; else return false; @@ -88,7 +95,7 @@ _inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *self ) _inline qboolean func_helper_isNormal( StrobeAPI_t *self ) { - if ( self->protected->frameInfo & f_normal ) + if ( self->protected->frameInfo & FRAME_RENDER ) return true; else return false; @@ -96,7 +103,7 @@ _inline qboolean func_helper_isNormal( StrobeAPI_t *self ) _inline qboolean func_helper_isPositive( StrobeAPI_t *self ) // ... { - if ( self->protected->frameInfo & p_positive ) + if ( self->protected->frameInfo & PHASE_POSITIVE ) return true; else return false; @@ -245,7 +252,7 @@ _inline double func_pwmsimulation_DutyCycle( void ) _inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *self ) { - if ( !!( self->protected->frameInfo & p_inverted ) ) + if ( !!( self->protected->frameInfo & PHASE_INVERTED ) ) return ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; else return 0.0f; @@ -253,7 +260,7 @@ _inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *self ) _inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *self ) { - if ( !!( self->protected->frameInfo & p_inverted ) ) + if ( !!( self->protected->frameInfo & PHASE_INVERTED ) ) return abs( StrobeAPI.r_strobe->integer ) * ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; else return 0.0; @@ -408,27 +415,23 @@ _inline double func_get_currentFPS( StrobeAPI_t *self ) // Copied from SCR_DrawFps // This way until current fps becomes global!!! - static double nexttime = 0, lasttime = 0; - static double framerate = 0; - static unsigned int mark = 0; double newtime; newtime = Sys_DoubleTime( ); - if ( newtime >= nexttime ) + if ( newtime >= self->private->nexttime ) { - framerate = ( self->protected->fCounter - mark ) / ( newtime - lasttime ); - lasttime = newtime; - nexttime = max( nexttime + 0.35, lasttime - 0.35 ); - mark = self->protected->fCounter; + self->private->framerate = ( self->protected->fCounter - self->private->mark ) / ( newtime - self->private->lasttime ); + self->private->lasttime = newtime; + self->private->nexttime = max(self->private->nexttime + 0.35, self->private->lasttime - 0.35 ); + self->private->mark = self->protected->fCounter; } - return framerate; + return self->private->framerate; } _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) { char diffBarP[128], diffBarN[128], diffBarT[128]; - static size_t PositiveNormal, PositiveBlack, NegativeNormal, NegativeBlack; size_t nPositiveNormal, nPositiveBlack, nNegativeNormal, nNegativeBlack; int diffP_NB, diffN_NB; double diffP = 0.0, diffN = 0.0; @@ -492,11 +495,11 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) self->Helpers.isPhaseInverted(self), self->get.FrameCounter( self, STROBE_CT_TotalFrame ), self->get.FrameCounter( self, STROBE_CT_PositiveFrame ), - ( nPositiveNormal > PositiveNormal ? va( "^2|-> Normal Frame Count: %zu^7", nPositiveNormal ) : va( "|-> Normal Frame Count: %zu", nPositiveNormal ) ), // Should be white instead of ^7 but white is not available in the color table - ( nPositiveBlack > PositiveBlack ? va( "^2|-> Black Frame Count: %zu^7", nPositiveBlack ) : va( "|-> Black Frame Count: %zu", nPositiveBlack ) ), + ( nPositiveNormal > self->private->PositiveNormal ? va( "^2|-> Normal Frame Count: %zu^7", nPositiveNormal ) : va( "|-> Normal Frame Count: %zu", nPositiveNormal ) ), // Should be white instead of ^7 but white is not available in the color table + ( nPositiveBlack > self->private->PositiveBlack ? va( "^2|-> Black Frame Count: %zu^7", nPositiveBlack ) : va( "|-> Black Frame Count: %zu", nPositiveBlack ) ), self->get.FrameCounter( self, STROBE_CT_NegativeFrame ), - ( nNegativeNormal > NegativeNormal ? va( "^2|-> Normal Frame Count: %zu^7", nNegativeNormal ) : va( "|-> Normal Frame Count: %zu", nNegativeNormal ) ), - ( nNegativeBlack > NegativeBlack ? va( "^2|-> Black Frame Count: %zu^7", nNegativeBlack ) : va( "|-> Black Frame Count: %zu", nNegativeBlack ) ), + ( nNegativeNormal > self->private->NegativeNormal ? va( "^2|-> Normal Frame Count: %zu^7", nNegativeNormal ) : va( "|-> Normal Frame Count: %zu", nNegativeNormal ) ), + ( nNegativeBlack > self->private->NegativeBlack ? va( "^2|-> Black Frame Count: %zu^7", nNegativeBlack ) : va( "|-> Black Frame Count: %zu", nNegativeBlack ) ), self->PWM.Frequency( self ), self->PWM.DutyCycle( ), self->PWM.PositivePhaseShift( self ), @@ -518,22 +521,22 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) self->protected->deviation, ( cooldown >= 0.0 && self->protected->cdTriggered ? va( "^1 %.2f secs\n[STROBING DISABLED] ^3", (double)StrobeAPI.r_strobe_cooldown->integer - cooldown ) : "0" ) ); - PositiveNormal = self->get.FrameCounter( self, STROBE_CT_PositiveNormalFrame ); - PositiveBlack = self->get.FrameCounter( self, STROBE_CT_PositiveBlackFrame ); - NegativeNormal = self->get.FrameCounter( self, STROBE_CT_NegativeNormalFrame ); - NegativeBlack = self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ); + self->private->PositiveNormal = self->get.FrameCounter( self, STROBE_CT_PositiveNormalFrame ); + self->private->PositiveBlack = self->get.FrameCounter( self, STROBE_CT_PositiveBlackFrame ); + self->private->NegativeNormal = self->get.FrameCounter( self, STROBE_CT_NegativeNormalFrame ); + self->private->NegativeBlack = self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ); } _inline void ProcessFrame( StrobeAPI_t *self ) { if ( self->protected->cdTriggered != false ) { - self->protected->frameInfo = f_normal | ( self->protected->frameInfo & p_positive ); + self->protected->frameInfo = FRAME_RENDER | ( self->protected->frameInfo & PHASE_POSITIVE ); } - if ( self->protected->frameInfo & f_normal ) // Show normal + if ( self->protected->frameInfo & FRAME_RENDER ) // Show normal { - if ( self->protected->frameInfo & p_positive ) + if ( self->protected->frameInfo & PHASE_POSITIVE ) ++self->protected->pNCounter; else ++self->protected->nNCounter; @@ -542,7 +545,7 @@ _inline void ProcessFrame( StrobeAPI_t *self ) } else // Show black { - if ( self->protected->frameInfo & p_positive ) + if ( self->protected->frameInfo & PHASE_POSITIVE ) ++self->protected->pBCounter; else ++self->protected->nBCounter; @@ -557,12 +560,14 @@ _inline void ProcessFrame( StrobeAPI_t *self ) _inline void StrobeAPI_constructor( StrobeAPI_t *self ) { self->protected = (StrobeAPI_protected_t *)calloc( 1, sizeof( StrobeAPI_protected_t ) ); - if ( self->protected == NULL ) + self->private = (StrobeAPI_private_t *)calloc(1, sizeof(StrobeAPI_private_t)); + + if (self->protected == NULL || self->private == NULL) { return; // Fix handling! } - self->protected->frameInfo = ( p_positive | f_normal ); - self->protected->initialTime = Sys_DoubleTime( ); + + self->protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); self->Helpers.ArithmeticMean = func_helper_ArithmeticMean; self->Helpers.effectiveFPS = func_helper_effectiveFPS; self->Helpers.GenerateDiffBar = func_helper_GenerateDiffBar; @@ -593,6 +598,11 @@ _inline void StrobeAPI_constructor( StrobeAPI_t *self ) _inline void StrobeAPI_destructor( StrobeAPI_t *self ) { + if (self->private) + { + free( self->private ); + self->private = NULL; + } if ( self->protected ) { free( self->protected ); diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 0c1dd7bb9..25595d1ae 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -111,8 +111,11 @@ typedef struct StrobeAPI_funcs_GET_s typedef struct StrobeAPI_protected_s StrobeAPI_protected_t; +typedef struct StrobeAPI_private_s StrobeAPI_private_t; + typedef struct StrobeAPI_s { + StrobeAPI_private_t *private; StrobeAPI_protected_t *protected; // r_strobe_base_protected_.h StrobeAPI_funcs_EXPERIMENTAL_t Experimentals; StrobeAPI_funcs_BRIGHTNESSREDUCTION_t BrightnessReductions; diff --git a/engine/client/strobe/r_strobe_api_protected_.h b/engine/client/strobe/r_strobe_api_protected_.h index 914dd3dd6..c62ea4749 100644 --- a/engine/client/strobe/r_strobe_api_protected_.h +++ b/engine/client/strobe/r_strobe_api_protected_.h @@ -25,9 +25,9 @@ See the GNU General Public License for more details. typedef enum { - p_positive = BIT( 0 ), // Phase: Positive - p_inverted = BIT( 1 ), // Phase: Inverted - f_normal = BIT( 2 ) // Frame: Normal + PHASE_POSITIVE = BIT( 0 ), // Phase: Positive + PHASE_INVERTED = BIT( 1 ), // Phase: Inverted + FRAME_RENDER = BIT( 2 ) // Frame: Rendered } fstate_e; // Frame State typedef struct StrobeAPI_protected_s @@ -35,14 +35,11 @@ typedef struct StrobeAPI_protected_s size_t fCounter; // Frame counter size_t pCounter, pNCounter, pBCounter; // Positive phase counters size_t nCounter, nNCounter, nBCounter; // Negative phase counters - int strobeInterval; - int swapInterval; - double initialTime, elapsedTime; - fstate_e frameInfo; // Frame info - + double elapsedTime; double deviation; // deviation double cdTimer; // Cooldown timer qboolean cdTriggered; // Cooldown trigger status + fstate_e frameInfo; // Frame info } StrobeAPI_protected_t; // Protected members #endif diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index dba26c2d7..3b5c2c919 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -37,6 +37,12 @@ struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) double recentTime, recentTime2; double delta[STROBE_CORE_DEVIATION_SIZE]; size_t fCounterSnapshot; + char debugStr[2048]; // Heap allocation ? + int offsetX; + double nexttime, lasttime; + int strobeInterval; + int swapInterval; + double initialTime; }; /* @@ -94,7 +100,7 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) _this->base.protected->cdTriggered = false; } - if ( ( ( _this->base.protected->strobeInterval != StrobeAPI.r_strobe->integer ) && ( _this->base.protected->strobeInterval ) ) || + if ( ( ( _this->private->strobeInterval != StrobeAPI.r_strobe->integer ) && ( _this->private->strobeInterval ) ) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ _this->base.protected->fCounter == UINT_MAX ) { @@ -102,16 +108,16 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) R_Strobe( &_this ); } - _this->base.protected->strobeInterval = StrobeAPI.r_strobe->integer; - _this->base.protected->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; + _this->private->strobeInterval = StrobeAPI.r_strobe->integer; + _this->private->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; - if ( ( _this->base.protected->strobeInterval == 0 ) || - ( ( gl_swapInterval->integer == 0 ) && ( _this->base.protected->strobeInterval ) ) ) + if ( ( _this->private->strobeInterval == 0 ) || + ( ( gl_swapInterval->integer == 0 ) && ( _this->private->strobeInterval ) ) ) { if ( !gl_swapInterval->integer ) MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - if ( _this->base.protected->strobeInterval ) // If v-sync is off, turn off strobing + if ( _this->private->strobeInterval ) // If v-sync is off, turn off strobing { Cvar_Set( "r_strobe", "0" ); } @@ -124,27 +130,27 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) if ( ( _this->base.protected->fCounter % 2 ) == 0 ) { ++_this->base.protected->pCounter; - _this->base.protected->frameInfo |= p_positive; + _this->base.protected->frameInfo |= PHASE_POSITIVE; } else { ++_this->base.protected->nCounter; - _this->base.protected->frameInfo &= ~p_positive; + _this->base.protected->frameInfo &= ~PHASE_POSITIVE; } - if ( _this->base.protected->swapInterval < 0 ) - _this->base.protected->swapInterval = abs( _this->base.protected->swapInterval ); + if ( _this->private->swapInterval < 0 ) + _this->private->swapInterval = abs( _this->private->swapInterval ); - if ( ( _this->base.protected->swapInterval ) && ( _this->base.protected->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ( ( _this->private->swapInterval ) && ( _this->private->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { delta = currentTime - _this->private->recentTime; // New Currenttime for _delta ? - if ( ( delta >= (double)( _this->base.protected->swapInterval ) ) && ( delta < (double)( 2 * _this->base.protected->swapInterval ) ) ) // Basic timer + if ( ( delta >= (double)( _this->private->swapInterval ) ) && ( delta < (double)( 2 * _this->private->swapInterval ) ) ) // Basic timer { - _this->base.protected->frameInfo |= p_inverted; + _this->base.protected->frameInfo |= PHASE_INVERTED; } - else if ( delta < (double)( _this->base.protected->swapInterval ) ) + else if ( delta < (double)( _this->private->swapInterval ) ) { - _this->base.protected->frameInfo &= ~p_inverted; + _this->base.protected->frameInfo &= ~PHASE_INVERTED; } else //if (delta >= (double)(2 * swapInterval)) { @@ -152,52 +158,52 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) } } - switch ( _this->base.protected->frameInfo & ( p_positive | p_inverted ) ) + switch ( _this->base.protected->frameInfo & ( PHASE_POSITIVE | PHASE_INVERTED ) ) { - case ( p_positive | p_inverted ): - if ( ( abs( _this->base.protected->strobeInterval ) % 2 ) == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == ( abs( _this->base.protected->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even + case ( PHASE_POSITIVE | PHASE_INVERTED ): + if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else - _this->base.protected->frameInfo &= ~f_normal; + _this->base.protected->frameInfo &= ~FRAME_RENDER; break; - case ( p_positive & ~p_inverted ): - if ( abs( _this->base.protected->strobeInterval ) % 2 == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even + case ( PHASE_POSITIVE & ~PHASE_INVERTED ): + if ( abs( _this->private->strobeInterval ) % 2 == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( _this->base.protected->strobeInterval ) == 1 ) - _this->base.protected->frameInfo |= f_normal; + if ( abs( _this->private->strobeInterval ) == 1 ) + _this->base.protected->frameInfo |= FRAME_RENDER; else - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( ( abs( _this->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //odd + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; - case ( ~p_positive & p_inverted ): - if ( abs( _this->base.protected->strobeInterval ) % 2 == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even + case ( ~PHASE_POSITIVE & PHASE_INVERTED ): + if ( abs( _this->private->strobeInterval ) % 2 == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( _this->base.protected->strobeInterval ) == 1 ) - _this->base.protected->frameInfo |= f_normal; + if ( abs( _this->private->strobeInterval ) == 1 ) + _this->base.protected->frameInfo |= FRAME_RENDER; else - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( ( abs( _this->base.protected->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //odd + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; case 0: - if ( ( abs( _this->base.protected->strobeInterval ) % 2 ) == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->base.protected->strobeInterval ) + 1 ) ) == ( abs( _this->base.protected->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | f_normal : _this->base.protected->frameInfo & ~f_normal; //even + if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else - _this->base.protected->frameInfo &= ~f_normal; + _this->base.protected->frameInfo &= ~FRAME_RENDER; break; default: - _this->base.protected->frameInfo = ( p_positive | f_normal ); + _this->base.protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); } - if ( _this->base.protected->strobeInterval < 0 ) - _this->base.protected->frameInfo ^= f_normal; + if ( _this->private->strobeInterval < 0 ) + _this->base.protected->frameInfo ^= FRAME_RENDER; _this->base.ProcessFrame( &_this->base ); } @@ -205,11 +211,8 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) { rgba_t color; - static char debugStr[2048]; // Heap allocation ? - static int offsetX; int offsetY; int fixer; - static double nexttime = 0, lasttime = 0; double newtime; qboolean strobeDebug = StrobeAPI.r_strobe_debug->integer ? true : false; @@ -231,26 +234,26 @@ _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) if ( strobeDebug ) { newtime = Sys_DoubleTime( ); - if ( newtime >= nexttime ) + if ( newtime >= _this->private->nexttime ) { - _this->base.Helpers.GenerateDebugStatistics( &_this->base, debugStr, ARRAYSIZE( debugStr ) ); - lasttime = newtime; - nexttime = max( nexttime + 0.15, lasttime - 0.15 ); // Make this configurable + _this->base.Helpers.GenerateDebugStatistics( &_this->base, _this->private->debugStr, ARRAYSIZE( _this->private->debugStr ) ); + _this->private->lasttime = newtime; + _this->private->nexttime = max( _this->private->nexttime + 0.15, _this->private->lasttime - 0.15 ); // Make this configurable } } else if ( cl_showfps->integer ) { - Q_snprintf( debugStr, sizeof( debugStr ), "%3d eFPS", (int)round( _this->base.Helpers.effectiveFPS( &_this->base ) ) ); + Q_snprintf( _this->private->debugStr, sizeof( _this->private->debugStr ), "%3d eFPS", (int)round( _this->base.Helpers.effectiveFPS( &_this->base ) ) ); } MakeRGBA( color, 255, 255, 255, 255 ); - Con_DrawStringLen( debugStr, &fixer, &offsetY ); + Con_DrawStringLen( _this->private->debugStr, &fixer, &offsetY ); if ( strobeDebug ) - Con_DrawString( scr_width->integer - offsetX - 50, 4, debugStr, color ); + Con_DrawString( scr_width->integer - _this->private->offsetX - 50, 4, _this->private->debugStr, color ); else - Con_DrawString( scr_width->integer - offsetX - 2, offsetY + 8, debugStr, color ); - if ( abs( fixer - offsetX ) > 50 || offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! - offsetX = fixer; + Con_DrawString( scr_width->integer - _this->private->offsetX - 2, offsetY + 8, _this->private->debugStr, color ); + if ( abs( fixer - _this->private->offsetX ) > 50 || _this->private->offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! + _this->private->offsetX = fixer; } void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) @@ -259,6 +262,7 @@ void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) *instance = (struct STROBE_IMPL_STRUCT( STROBE_CORE ) *)malloc( sizeof(struct STROBE_IMPL_STRUCT(STROBE_CORE)) ); ( *instance )->private = (struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *)calloc( 1, sizeof(struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_CORE)) ); + ( *instance )->private->initialTime = Sys_DoubleTime(); ( *instance )->STROBE_IMPL_FUNC_MAIN = R_Strobe; ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugDrawer; From 84759c70d8da740a9c2165f6f39c0e669f9857c6 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 7 Apr 2018 01:02:26 +0300 Subject: [PATCH 27/35] Adjusted constness & format --- engine/client/strobe/r_strobe_api.c | 64 +++---- engine/client/strobe/r_strobe_api.h | 52 +++--- .../client/strobe/r_strobe_api_protected_.h | 4 +- engine/client/strobe/r_strobe_core.c | 166 +++++++++--------- engine/client/strobe/r_strobe_core.h | 10 +- .../strobe/r_strobe_template.c.TEMPLATE | 22 +-- .../strobe/r_strobe_template.h.TEMPLATE | 8 +- 7 files changed, 163 insertions(+), 163 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 288b085f1..4d3a3ebe0 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -34,7 +34,7 @@ typedef struct StrobeAPI_private_s double nexttime, lasttime, framerate; size_t mark; size_t PositiveNormal, PositiveBlack, NegativeNormal, NegativeBlack; -}StrobeAPI_private_t; +} StrobeAPI_private_t; _inline double func_helper_StandardDeviation( const double *data, int n ) { @@ -73,7 +73,7 @@ _inline void GL_GenerateBlackFrame( void ) // Generates partial or full black fr } } -_inline double func_helper_getCooldown( StrobeAPI_t *self ) +_inline double func_helper_getCooldown( StrobeAPI_t *const self ) { if ( 0 <= self->protected->cdTimer ) { @@ -85,7 +85,7 @@ _inline double func_helper_getCooldown( StrobeAPI_t *self ) } } -_inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *self ) +_inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *const self ) { if ( self->protected->frameInfo & PHASE_INVERTED ) return true; @@ -93,7 +93,7 @@ _inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *self ) return false; } -_inline qboolean func_helper_isNormal( StrobeAPI_t *self ) +_inline qboolean func_helper_isNormal( StrobeAPI_t *const self ) { if ( self->protected->frameInfo & FRAME_RENDER ) return true; @@ -101,7 +101,7 @@ _inline qboolean func_helper_isNormal( StrobeAPI_t *self ) return false; } -_inline qboolean func_helper_isPositive( StrobeAPI_t *self ) // ... +_inline qboolean func_helper_isPositive( StrobeAPI_t *const self ) // ... { if ( self->protected->frameInfo & PHASE_POSITIVE ) return true; @@ -109,7 +109,7 @@ _inline qboolean func_helper_isPositive( StrobeAPI_t *self ) // ... return false; } -_inline double func_helper_effectiveFPS( StrobeAPI_t *self ) +_inline double func_helper_effectiveFPS( StrobeAPI_t *const self ) { int strobeInterval = StrobeAPI.r_strobe->integer; double eFPS; @@ -127,7 +127,7 @@ _inline double func_helper_effectiveFPS( StrobeAPI_t *self ) return eFPS; } -_inline void func_helper_GenerateDiffBar( StrobeAPI_t *self, char *src, int size, char type ) +_inline void func_helper_GenerateDiffBar( StrobeAPI_t *const self, char *src, int size, char type ) { char _barCounter = 0; int diff_NB = 0; @@ -239,7 +239,7 @@ _inline void func_helper_GenerateDiffBar( StrobeAPI_t *self, char *src, int size } } -_inline double func_pwmsimulation_Frequency( StrobeAPI_t *self ) +_inline double func_pwmsimulation_Frequency( StrobeAPI_t *const self ) { return ( 1 / ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) ); } @@ -250,7 +250,7 @@ _inline double func_pwmsimulation_DutyCycle( void ) return ( ( ( 1.0f / ( abs( strobeInterval ) + 1 ) ) * 100 ) * ( strobeInterval < 0 ? -strobeInterval : 1 ) ); } -_inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *self ) +_inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *const self ) { if ( !!( self->protected->frameInfo & PHASE_INVERTED ) ) return ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; @@ -258,7 +258,7 @@ _inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *self ) return 0.0f; } -_inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *self ) +_inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *const self ) { if ( !!( self->protected->frameInfo & PHASE_INVERTED ) ) return abs( StrobeAPI.r_strobe->integer ) * ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; @@ -266,7 +266,7 @@ _inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *self ) return 0.0; } -_inline double func_pwmsimulation_Period( StrobeAPI_t *self ) +_inline double func_pwmsimulation_Period( StrobeAPI_t *const self ) { return ( ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) * 1000 ); } @@ -281,32 +281,32 @@ _inline double func_helper_ArithmeticMean( double x, double y ) return ( x + y ) / 2; } -_inline double func_brightnessreduction_ActualBrightnessReduction( StrobeAPI_t *self ) +_inline double func_brightnessreduction_ActualBrightnessReduction( StrobeAPI_t *const self ) { return lossCalculator( self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ) ); } -_inline double func_brightnessreduction_LogarithmicBrightnessReduction( StrobeAPI_t *self, double base ) +_inline double func_brightnessreduction_LogarithmicBrightnessReduction( StrobeAPI_t *const self, double base ) { return lossCalculator( log( base ), log( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_SquareBrightnessReduction( StrobeAPI_t *self, double base ) +_inline double func_brightnessreduction_SquareBrightnessReduction( StrobeAPI_t *const self, double base ) { return lossCalculator( sqrt( base ), sqrt( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_CubeBrightnessReduction( StrobeAPI_t *self, double base ) +_inline double func_brightnessreduction_CubeBrightnessReduction( StrobeAPI_t *const self, double base ) { return lossCalculator( cbrt( base ), cbrt( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_OtherBrightnessReduction( StrobeAPI_t *self, double base, double ( *reductionFunction )( double ) ) +_inline double func_brightnessreduction_OtherBrightnessReduction( StrobeAPI_t *const self, double base, double ( *reductionFunction )( double ) ) { return lossCalculator( reductionFunction( base ), reductionFunction( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_experimental_Badness_Reducted( StrobeAPI_t *self, qboolean PWMInvolved ) +_inline double func_experimental_Badness_Reducted( StrobeAPI_t *const self, qboolean PWMInvolved ) { double badness, Diff; int diffP_NB, diffN_NB; @@ -340,7 +340,7 @@ _inline double func_experimental_Badness_Reducted( StrobeAPI_t *self, qboolean P return badness; } -_inline double func_experimental_Badness( StrobeAPI_t *self, qboolean PWMInvolved ) +_inline double func_experimental_Badness( StrobeAPI_t *const self, qboolean PWMInvolved ) { int diffP_NB, diffN_NB; double diffP = 0.0, diffN = 0.0; @@ -369,7 +369,7 @@ _inline double func_experimental_Badness( StrobeAPI_t *self, qboolean PWMInvolve return badness; } -_inline size_t func_get_FrameCounter( StrobeAPI_t *self, STROBE_counterType type ) +_inline size_t func_get_FrameCounter( StrobeAPI_t *const self, STROBE_counterType type ) { switch ( type ) { @@ -410,7 +410,7 @@ _inline size_t func_get_FrameCounter( StrobeAPI_t *self, STROBE_counterType type } } -_inline double func_get_currentFPS( StrobeAPI_t *self ) +_inline double func_get_currentFPS( StrobeAPI_t *const self ) { // Copied from SCR_DrawFps // This way until current fps becomes global!!! @@ -421,15 +421,15 @@ _inline double func_get_currentFPS( StrobeAPI_t *self ) if ( newtime >= self->private->nexttime ) { self->private->framerate = ( self->protected->fCounter - self->private->mark ) / ( newtime - self->private->lasttime ); - self->private->lasttime = newtime; - self->private->nexttime = max(self->private->nexttime + 0.35, self->private->lasttime - 0.35 ); + self->private->lasttime = newtime; + self->private->nexttime = max( self->private->nexttime + 0.35, self->private->lasttime - 0.35 ); self->private->mark = self->protected->fCounter; } return self->private->framerate; } -_inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) +_inline void GenerateDebugStatistics( StrobeAPI_t *const self, char *src, int size ) { char diffBarP[128], diffBarN[128], diffBarT[128]; size_t nPositiveNormal, nPositiveBlack, nNegativeNormal, nNegativeBlack; @@ -459,7 +459,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) size, "%.2f FPS\n%.2f eFPS\n" "Elapsed Time: %.2f\n" - "isPhaseInverted = %d\n" + "isPhaseInverted = %d\n" "Total Frame Count: %zu\n" "^7(+) Phase Frame Count: %zu\n" "%s\n" @@ -492,7 +492,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ), self->protected->elapsedTime, - self->Helpers.isPhaseInverted(self), + self->Helpers.isPhaseInverted( self ), self->get.FrameCounter( self, STROBE_CT_TotalFrame ), self->get.FrameCounter( self, STROBE_CT_PositiveFrame ), ( nPositiveNormal > self->private->PositiveNormal ? va( "^2|-> Normal Frame Count: %zu^7", nPositiveNormal ) : va( "|-> Normal Frame Count: %zu", nPositiveNormal ) ), // Should be white instead of ^7 but white is not available in the color table @@ -527,7 +527,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) self->private->NegativeBlack = self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ); } -_inline void ProcessFrame( StrobeAPI_t *self ) +_inline void ProcessFrame( StrobeAPI_t *const self ) { if ( self->protected->cdTriggered != false ) { @@ -557,12 +557,12 @@ _inline void ProcessFrame( StrobeAPI_t *self ) ++self->protected->fCounter; } -_inline void StrobeAPI_constructor( StrobeAPI_t *self ) +_inline void StrobeAPI_constructor( StrobeAPI_t *const self ) { self->protected = (StrobeAPI_protected_t *)calloc( 1, sizeof( StrobeAPI_protected_t ) ); - self->private = (StrobeAPI_private_t *)calloc(1, sizeof(StrobeAPI_private_t)); + self->private = (StrobeAPI_private_t *)calloc( 1, sizeof( StrobeAPI_private_t ) ); - if (self->protected == NULL || self->private == NULL) + if ( self->protected == NULL || self->private == NULL ) { return; // Fix handling! } @@ -596,9 +596,9 @@ _inline void StrobeAPI_constructor( StrobeAPI_t *self ) self->Helpers.GenerateDebugStatistics = GenerateDebugStatistics; } -_inline void StrobeAPI_destructor( StrobeAPI_t *self ) +_inline void StrobeAPI_destructor( StrobeAPI_t *const self ) { - if (self->private) + if ( self->private ) { free( self->private ); self->private = NULL; @@ -610,7 +610,7 @@ _inline void StrobeAPI_destructor( StrobeAPI_t *self ) } } -_inline void StrobeAPI_Invoker( void **self, void ( *constructor )( void ** ), void ( *main )( void ** ), void ( *destructor )( void ** ) ) +_inline void StrobeAPI_Invoker( const void *const *const self, void ( *constructor )( const void *const *const ), void ( *main )( const void *const *const ), void ( *destructor )( const void *const *const ) ) { if ( StrobeAPI.r_strobe->integer ) { diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 25595d1ae..4814c2fbe 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -42,14 +42,14 @@ See the GNU General Public License for more details. #define STROBE_IMPL_STRUCT(IMPL) STROBE_CONCAT(IMPL, _s) #define STROBE_IMPL_PRIVATE_STRUCT(IMPL) STROBE_CONCAT(IMPL, _private_s) #define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) -#define STROBE_IMPL_THIS_PARAM(IMPL) struct STROBE_IMPL_STRUCT(IMPL) **_STROBE_IMPL_THIS +#define STROBE_IMPL_THIS_PARAM(IMPL) struct STROBE_IMPL_STRUCT(IMPL) *const *const _STROBE_IMPL_THIS #define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_MAIN) #define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_CONSTRUCTOR) #define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_DESTRUCTOR) #define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_REINIT) -#define STROBE_INVOKE(IMPL) (void**)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) +#define STROBE_INVOKE(IMPL) (const void *const *const)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) // MACROS FOR STROBE IMPLEMENTATIONS typedef struct StrobeAPI_s StrobeAPI_t; @@ -67,46 +67,46 @@ typedef enum typedef struct StrobeAPI_funcs_BRIGHTNESSREDUCTION_s { - double ( *ActualBrightnessReduction )( StrobeAPI_t *self ); - double ( *LogarithmicBrightnessReduction )( StrobeAPI_t *self, double base ); - double ( *SquareBrightnessReduction )( StrobeAPI_t *self, double base ); - double ( *CubeBrightnessReduction )( StrobeAPI_t *self, double base ); - double ( *OtherBrightnessReduction )( StrobeAPI_t *self, double base, double ( *reductionFunction )( double ) ); + double ( *ActualBrightnessReduction )( StrobeAPI_t *const self ); + double ( *LogarithmicBrightnessReduction )( StrobeAPI_t *const self, double base ); + double ( *SquareBrightnessReduction )( StrobeAPI_t *const self, double base ); + double ( *CubeBrightnessReduction )( StrobeAPI_t *const self, double base ); + double ( *OtherBrightnessReduction )( StrobeAPI_t *const self, double base, double ( *reductionFunction )( double ) ); } StrobeAPI_funcs_BRIGHTNESSREDUCTION_t; typedef struct StrobeAPI_funcs_EXPERIMENTAL_s { - double ( *BADNESS )( StrobeAPI_t *self, qboolean PWMInvolved ); - double ( *BADNESS_REDUCTED )( StrobeAPI_t *self, qboolean PWMInvolved ); + double ( *BADNESS )( StrobeAPI_t *const self, qboolean PWMInvolved ); + double ( *BADNESS_REDUCTED )( StrobeAPI_t *const self, qboolean PWMInvolved ); } StrobeAPI_funcs_EXPERIMENTAL_t; typedef struct StrobeAPI_funcs_PWMSIMULATION_s { - double ( *Frequency )( StrobeAPI_t *self ); + double ( *Frequency )( StrobeAPI_t *const self ); double ( *DutyCycle )( void ); - double ( *PositivePhaseShift )( StrobeAPI_t *self ); - double ( *NegativePhaseShift )( StrobeAPI_t *self ); - double ( *Period )( StrobeAPI_t *self ); + double ( *PositivePhaseShift )( StrobeAPI_t *const self ); + double ( *NegativePhaseShift )( StrobeAPI_t *const self ); + double ( *Period )( StrobeAPI_t *const self ); } StrobeAPI_funcs_PWMSIMULATION_t; typedef struct StrobeAPI_funcs_HELPER_s { - qboolean ( *isPhaseInverted )( StrobeAPI_t *self ); - qboolean ( *isNormal )( StrobeAPI_t *self ); - qboolean ( *isPositive )( StrobeAPI_t *self ); - double ( *effectiveFPS )( StrobeAPI_t *self ); - double ( *CurrentFPS )( StrobeAPI_t *self ); - void ( *GenerateDebugStatistics )( StrobeAPI_t *self, char *src, int size ); - void ( *GenerateDiffBar )( StrobeAPI_t *self, char *src, int size, char type ); + qboolean ( *isPhaseInverted )( StrobeAPI_t *const self ); + qboolean ( *isNormal )( StrobeAPI_t *const self ); + qboolean ( *isPositive )( StrobeAPI_t *const self ); + double ( *effectiveFPS )( StrobeAPI_t *const self ); + double ( *CurrentFPS )( StrobeAPI_t *const self ); + void ( *GenerateDebugStatistics )( StrobeAPI_t *const self, char *src, int size ); + void ( *GenerateDiffBar )( StrobeAPI_t *const self, char *src, int size, char type ); double ( *GeometricMean )( double x, double y ); double ( *ArithmeticMean )( double x, double y ); double ( *StandardDeviation )( const double *data, int size ); - double ( *Cooldown )( StrobeAPI_t *self ); + double ( *Cooldown )( StrobeAPI_t *const self ); } StrobeAPI_funcs_HELPER_t; typedef struct StrobeAPI_funcs_GET_s { - size_t ( *FrameCounter )( StrobeAPI_t *self, STROBE_counterType ); + size_t ( *FrameCounter )( StrobeAPI_t *const self, STROBE_counterType ); } StrobeAPI_funcs_GET_t; typedef struct StrobeAPI_protected_s StrobeAPI_protected_t; @@ -123,14 +123,14 @@ typedef struct StrobeAPI_s StrobeAPI_funcs_HELPER_t Helpers; StrobeAPI_funcs_GET_t get; void ( *GenerateBlackFrame )( void ); - void ( *ProcessFrame )( StrobeAPI_t *self ); + void ( *ProcessFrame )( StrobeAPI_t *const self ); } StrobeAPI_t; typedef struct StrobeAPI_EXPORTS_s { - void ( *Invoker )( void **self, void ( *constructor )( void ** ), void ( *main )( void ** ), void ( *destructor )( void ** ) ); // Strobe Invoker - void ( *Constructor )( StrobeAPI_t *self ); - void ( *Destructor )( StrobeAPI_t *self ); + void ( *Invoker )( const void *const *const self, void ( *constructor )( const void *const *const ), void ( *main )( const void *const *const ), void ( *destructor )( const void *const *const ) ); // Strobe Invoker + void ( *Constructor )( StrobeAPI_t *const self ); + void ( *Destructor )( StrobeAPI_t *const self ); convar_t *r_strobe; convar_t *r_strobe_swapinterval; diff --git a/engine/client/strobe/r_strobe_api_protected_.h b/engine/client/strobe/r_strobe_api_protected_.h index c62ea4749..87e18c1d6 100644 --- a/engine/client/strobe/r_strobe_api_protected_.h +++ b/engine/client/strobe/r_strobe_api_protected_.h @@ -28,7 +28,7 @@ typedef enum PHASE_POSITIVE = BIT( 0 ), // Phase: Positive PHASE_INVERTED = BIT( 1 ), // Phase: Inverted FRAME_RENDER = BIT( 2 ) // Frame: Rendered -} fstate_e; // Frame State +} fstate_e; // Frame State typedef struct StrobeAPI_protected_s { @@ -39,7 +39,7 @@ typedef struct StrobeAPI_protected_s double deviation; // deviation double cdTimer; // Cooldown timer qboolean cdTriggered; // Cooldown trigger status - fstate_e frameInfo; // Frame info + fstate_e frameInfo; // Frame info } StrobeAPI_protected_t; // Protected members #endif diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index 3b5c2c919..f9d84ca6f 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -25,10 +25,10 @@ See the GNU General Public License for more details. #include "gl_local.h" #include "r_strobe_api_protected_.h" -#ifdef _this -#undef _this +#ifdef this +#undef this #endif -#define _this STROBE_IMPL_THIS( STROBE_CORE ) +#define this STROBE_IMPL_THIS( STROBE_CORE ) struct STROBE_IMPL_STRUCT( STROBE_CORE ) *STROBE_CORE = NULL; @@ -58,10 +58,10 @@ R_Strobe static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) { double delta, delta2; - double currentTime = Sys_DoubleTime( ); - delta2 = currentTime - _this->private->recentTime2; - _this->private->recentTime2 = currentTime; - _this->base.protected->elapsedTime = currentTime - _this->base.protected->initialTime; + double currentTime = Sys_DoubleTime( ); + delta2 = currentTime - this->private->recentTime2; + this->private->recentTime2 = currentTime; + this->base.protected->elapsedTime = currentTime - this->private->initialTime; if ( CL_IsInMenu( ) ) { @@ -69,143 +69,143 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) return; } - if ( _this->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) - _this->base.protected->cdTimer += delta2; - if ( _this->base.protected->fCounter - _this->private->fCounterSnapshot == 1 ) + if ( this->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) + this->base.protected->cdTimer += delta2; + if ( this->base.protected->fCounter - this->private->fCounterSnapshot == 1 ) { - _this->private->delta[_this->base.protected->fCounter % ARRAYSIZE( _this->private->delta )] = delta2; - _this->base.protected->deviation = _this->base.Helpers.StandardDeviation( _this->private->delta, ARRAYSIZE( _this->private->delta ) ) * 1000; + this->private->delta[this->base.protected->fCounter % ARRAYSIZE( this->private->delta )] = delta2; + this->base.protected->deviation = this->base.Helpers.StandardDeviation( this->private->delta, ARRAYSIZE( this->private->delta ) ) * 1000; } - _this->private->fCounterSnapshot = _this->base.protected->fCounter; + this->private->fCounterSnapshot = this->base.protected->fCounter; if ( StrobeAPI.r_strobe_cooldown->integer > 0 ) { - if ( ( _this->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && _this->base.protected->cdTriggered == true ) + if ( ( this->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && this->base.protected->cdTriggered == true ) { - _this->base.protected->cdTriggered = false; - _this->base.protected->cdTimer = -1.0; + this->base.protected->cdTriggered = false; + this->base.protected->cdTimer = -1.0; } - if ( _this->base.protected->fCounter > ARRAYSIZE( _this->private->delta ) ) + if ( this->base.protected->fCounter > ARRAYSIZE( this->private->delta ) ) { - if ( _this->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) + if ( this->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) { - _this->base.protected->cdTriggered = true; - _this->base.protected->cdTimer = 0.0; + this->base.protected->cdTriggered = true; + this->base.protected->cdTimer = 0.0; } } } else { - _this->base.protected->cdTriggered = false; + this->base.protected->cdTriggered = false; } - if ( ( ( _this->private->strobeInterval != StrobeAPI.r_strobe->integer ) && ( _this->private->strobeInterval ) ) || + if ( ( ( this->private->strobeInterval != StrobeAPI.r_strobe->integer ) && ( this->private->strobeInterval ) ) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - _this->base.protected->fCounter == UINT_MAX ) + this->base.protected->fCounter == UINT_MAX ) { STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( *(void ***)&_STROBE_IMPL_THIS ); - R_Strobe( &_this ); + R_Strobe( &this ); } - _this->private->strobeInterval = StrobeAPI.r_strobe->integer; - _this->private->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; + this->private->strobeInterval = StrobeAPI.r_strobe->integer; + this->private->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; - if ( ( _this->private->strobeInterval == 0 ) || - ( ( gl_swapInterval->integer == 0 ) && ( _this->private->strobeInterval ) ) ) + if ( ( this->private->strobeInterval == 0 ) || + ( ( gl_swapInterval->integer == 0 ) && ( this->private->strobeInterval ) ) ) { if ( !gl_swapInterval->integer ) MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - if ( _this->private->strobeInterval ) // If v-sync is off, turn off strobing + if ( this->private->strobeInterval ) // If v-sync is off, turn off strobing { Cvar_Set( "r_strobe", "0" ); } - _this->base.protected->fCounter = 0; + this->base.protected->fCounter = 0; R_Set2DMode( false ); return; } - if ( ( _this->base.protected->fCounter % 2 ) == 0 ) + if ( ( this->base.protected->fCounter % 2 ) == 0 ) { - ++_this->base.protected->pCounter; - _this->base.protected->frameInfo |= PHASE_POSITIVE; + ++this->base.protected->pCounter; + this->base.protected->frameInfo |= PHASE_POSITIVE; } else { - ++_this->base.protected->nCounter; - _this->base.protected->frameInfo &= ~PHASE_POSITIVE; + ++this->base.protected->nCounter; + this->base.protected->frameInfo &= ~PHASE_POSITIVE; } - if ( _this->private->swapInterval < 0 ) - _this->private->swapInterval = abs( _this->private->swapInterval ); + if ( this->private->swapInterval < 0 ) + this->private->swapInterval = abs( this->private->swapInterval ); - if ( ( _this->private->swapInterval ) && ( _this->private->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ( ( this->private->swapInterval ) && ( this->private->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { - delta = currentTime - _this->private->recentTime; // New Currenttime for _delta ? - if ( ( delta >= (double)( _this->private->swapInterval ) ) && ( delta < (double)( 2 * _this->private->swapInterval ) ) ) // Basic timer + delta = currentTime - this->private->recentTime; // New Currenttime for _delta ? + if ( ( delta >= (double)( this->private->swapInterval ) ) && ( delta < (double)( 2 * this->private->swapInterval ) ) ) // Basic timer { - _this->base.protected->frameInfo |= PHASE_INVERTED; + this->base.protected->frameInfo |= PHASE_INVERTED; } - else if ( delta < (double)( _this->private->swapInterval ) ) + else if ( delta < (double)( this->private->swapInterval ) ) { - _this->base.protected->frameInfo &= ~PHASE_INVERTED; + this->base.protected->frameInfo &= ~PHASE_INVERTED; } else //if (delta >= (double)(2 * swapInterval)) { - _this->private->recentTime = currentTime; + this->private->recentTime = currentTime; } } - switch ( _this->base.protected->frameInfo & ( PHASE_POSITIVE | PHASE_INVERTED ) ) + switch ( this->base.protected->frameInfo & ( PHASE_POSITIVE | PHASE_INVERTED ) ) { case ( PHASE_POSITIVE | PHASE_INVERTED ): - if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( ( abs( this->private->strobeInterval ) % 2 ) == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == ( abs( this->private->strobeInterval ) / 2 ) ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else - _this->base.protected->frameInfo &= ~FRAME_RENDER; + this->base.protected->frameInfo &= ~FRAME_RENDER; break; case ( PHASE_POSITIVE & ~PHASE_INVERTED ): - if ( abs( _this->private->strobeInterval ) % 2 == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( abs( this->private->strobeInterval ) % 2 == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( _this->private->strobeInterval ) == 1 ) - _this->base.protected->frameInfo |= FRAME_RENDER; + if ( abs( this->private->strobeInterval ) == 1 ) + this->base.protected->frameInfo |= FRAME_RENDER; else - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd + this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( ( abs( this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; case ( ~PHASE_POSITIVE & PHASE_INVERTED ): - if ( abs( _this->private->strobeInterval ) % 2 == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( abs( this->private->strobeInterval ) % 2 == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( _this->private->strobeInterval ) == 1 ) - _this->base.protected->frameInfo |= FRAME_RENDER; + if ( abs( this->private->strobeInterval ) == 1 ) + this->base.protected->frameInfo |= FRAME_RENDER; else - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd + this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( ( abs( this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; case 0: - if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( ( abs( this->private->strobeInterval ) % 2 ) == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == ( abs( this->private->strobeInterval ) / 2 ) ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else - _this->base.protected->frameInfo &= ~FRAME_RENDER; + this->base.protected->frameInfo &= ~FRAME_RENDER; break; default: - _this->base.protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); + this->base.protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); } - if ( _this->private->strobeInterval < 0 ) - _this->base.protected->frameInfo ^= FRAME_RENDER; + if ( this->private->strobeInterval < 0 ) + this->base.protected->frameInfo ^= FRAME_RENDER; - _this->base.ProcessFrame( &_this->base ); + this->base.ProcessFrame( &this->base ); } _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) @@ -234,42 +234,42 @@ _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) if ( strobeDebug ) { newtime = Sys_DoubleTime( ); - if ( newtime >= _this->private->nexttime ) + if ( newtime >= this->private->nexttime ) { - _this->base.Helpers.GenerateDebugStatistics( &_this->base, _this->private->debugStr, ARRAYSIZE( _this->private->debugStr ) ); - _this->private->lasttime = newtime; - _this->private->nexttime = max( _this->private->nexttime + 0.15, _this->private->lasttime - 0.15 ); // Make this configurable + this->base.Helpers.GenerateDebugStatistics( &this->base, this->private->debugStr, ARRAYSIZE( this->private->debugStr ) ); + this->private->lasttime = newtime; + this->private->nexttime = max( this->private->nexttime + 0.15, this->private->lasttime - 0.15 ); // Make this configurable } } else if ( cl_showfps->integer ) { - Q_snprintf( _this->private->debugStr, sizeof( _this->private->debugStr ), "%3d eFPS", (int)round( _this->base.Helpers.effectiveFPS( &_this->base ) ) ); + Q_snprintf( this->private->debugStr, sizeof( this->private->debugStr ), "%3d eFPS", (int)round( this->base.Helpers.effectiveFPS( &this->base ) ) ); } MakeRGBA( color, 255, 255, 255, 255 ); - Con_DrawStringLen( _this->private->debugStr, &fixer, &offsetY ); + Con_DrawStringLen( this->private->debugStr, &fixer, &offsetY ); if ( strobeDebug ) - Con_DrawString( scr_width->integer - _this->private->offsetX - 50, 4, _this->private->debugStr, color ); + Con_DrawString( scr_width->integer - this->private->offsetX - 50, 4, this->private->debugStr, color ); else - Con_DrawString( scr_width->integer - _this->private->offsetX - 2, offsetY + 8, _this->private->debugStr, color ); - if ( abs( fixer - _this->private->offsetX ) > 50 || _this->private->offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! - _this->private->offsetX = fixer; + Con_DrawString( scr_width->integer - this->private->offsetX - 2, offsetY + 8, this->private->debugStr, color ); + if ( abs( fixer - this->private->offsetX ) > 50 || this->private->offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! + this->private->offsetX = fixer; } -void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( const void *const *const STROBE_CORE ) { struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; - *instance = (struct STROBE_IMPL_STRUCT( STROBE_CORE ) *)malloc( sizeof(struct STROBE_IMPL_STRUCT(STROBE_CORE)) ); - ( *instance )->private = (struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *)calloc( 1, sizeof(struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_CORE)) ); - ( *instance )->private->initialTime = Sys_DoubleTime(); + *instance = (struct STROBE_IMPL_STRUCT( STROBE_CORE ) *)malloc( sizeof( struct STROBE_IMPL_STRUCT( STROBE_CORE ) ) ); + ( *instance )->private = (struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *)calloc( 1, sizeof( struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) ) ); + ( *instance )->private->initialTime = Sys_DoubleTime( ); ( *instance )->STROBE_IMPL_FUNC_MAIN = R_Strobe; ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugDrawer; StrobeAPI.Constructor( &( *instance )->base ); } -void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( const void *const *const STROBE_CORE ) { struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; @@ -286,7 +286,7 @@ void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ) } } -void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( const void *const *const STROBE_CORE ) { if ( !( *STROBE_CORE ) ) { @@ -295,7 +295,7 @@ void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ) STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( STROBE_CORE ); } -void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( const void *const *const STROBE_CORE ) { struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; if ( *instance ) @@ -304,6 +304,6 @@ void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ) } } -#undef _this +#undef this #endif diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 8131e03c0..6bcb5e9fb 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -34,15 +34,15 @@ struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ); struct STROBE_IMPL_STRUCT( STROBE_CORE ) { StrobeAPI_t base; - struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *private; + struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) * private; void ( *STROBE_IMPL_FUNC_MAIN )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); void ( *STROBE_IMPL_FUNC_DEBUGHANDLER )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); }; extern struct STROBE_IMPL_STRUCT( STROBE_CORE ) * STROBE_CORE; -void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ); -void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ); -void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ); -void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( const void *const *const STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( const void *const *const STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( const void *const *const STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( const void *const *const STROBE_CORE ); #endif diff --git a/engine/client/strobe/r_strobe_template.c.TEMPLATE b/engine/client/strobe/r_strobe_template.c.TEMPLATE index d62d92792..f5c9d0f40 100644 --- a/engine/client/strobe/r_strobe_template.c.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.c.TEMPLATE @@ -26,10 +26,10 @@ See the GNU General Public License for more details. #include "client.h" #include "gl_local.h" -#ifdef _this -#undef _this +#ifdef this +#undef this #endif -#define _this STROBE_IMPL_THIS(STROBE_TEMPLATE) +#define this STROBE_IMPL_THIS(STROBE_TEMPLATE) struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) *STROBE_TEMPLATE = NULL; @@ -40,17 +40,17 @@ struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_TEMPLATE) static void main( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) { - _this->base.protected->frameInfo = ( p_positive | f_normal ); - _this->base.ProcessFrame( &_this->base ); + this->base.protected->frameInfo = ( p_positive | f_normal ); + this->base.ProcessFrame( &this->base ); } static void debugHandler( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) { char debugstr[2048] = {0}; - _this->base.Helpers.GenerateDebugStatistics( &_this->base, debugstr, 2048 ); + this->base.Helpers.GenerateDebugStatistics( &this->base, debugstr, 2048 ); } -void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) { struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; @@ -62,7 +62,7 @@ void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLA StrobeAPI.Constructor( &( *instance )->base ); } -void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) { struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; @@ -79,7 +79,7 @@ void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLAT } } -void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) { if ( !( *STROBE_TEMPLATE ) ) { @@ -88,7 +88,7 @@ void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( STROBE_TEMPLATE ); } -void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) { struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; if ( *instance ) @@ -98,6 +98,6 @@ void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) } -#undef _this +#undef this #endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_template.h.TEMPLATE b/engine/client/strobe/r_strobe_template.h.TEMPLATE index 341c19491..788317ca2 100644 --- a/engine/client/strobe/r_strobe_template.h.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.h.TEMPLATE @@ -37,9 +37,9 @@ struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) }; extern struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) *STROBE_TEMPLATE; -void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); -void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); -void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); -void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); #endif \ No newline at end of file From 41524d7ef886905e32c351d567ec5ef3e29e2d83 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 7 Apr 2018 02:13:10 +0300 Subject: [PATCH 28/35] Format --- engine/client/cl_view.c | 2 ++ engine/client/gl_rmain.c | 1 + engine/client/strobe/r_strobe_api.c | 2 +- engine/client/strobe/r_strobe_core.c | 11 +++++++++-- engine/client/strobe/r_strobe_core.h | 4 +--- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index 947bee2cd..0838b2525 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -435,6 +435,8 @@ void V_PostRender( void ) SCR_DrawFPS(); #ifdef STROBE_ENABLED + // if ( STROBE_TEMPLATE ) + // STROBE_TEMPLATE->STROBE_IMPL_FUNC_DEBUGHANDLER( &STROBE_TEMPLATE ); if ( STROBE_CORE ) STROBE_CORE->STROBE_IMPL_FUNC_DEBUGHANDLER( &STROBE_CORE ); #endif diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index 567138390..76e7bf8e2 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1343,6 +1343,7 @@ R_EndFrame void R_EndFrame( void ) { #ifdef STROBE_ENABLED + // StrobeAPI.Invoker( STROBE_INVOKE(STROBE_TEMPLATE) ); StrobeAPI.Invoker( STROBE_INVOKE(STROBE_CORE) ); #else // flush any remaining 2D bits diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 4d3a3ebe0..b0a2c0fc1 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -478,7 +478,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *const self, char *src, int si " |-> [^7LOG^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" " |-> [^7SQUARE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" " |-> [^7CUBE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" - "Difference (+): %s\nDifference (-): %s\nDifference (+ & -): %s\n" + "Difference (+): %s\nDifference (-): %s\nDifference (TOTAL): %s\n" "Geometric Mean: %.4f\n" "G/A Difference: %.4f\n" "[^7EXPERIMENTAL^3] Badness: %.4f\n" diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index f9d84ca6f..fae3a5abc 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -32,10 +32,17 @@ See the GNU General Public License for more details. struct STROBE_IMPL_STRUCT( STROBE_CORE ) *STROBE_CORE = NULL; +#ifdef _DEBUG +#define DEVIATION_LIMIT 2.0 +#else +#define DEVIATION_LIMIT 0.75 +#endif +#define DEVIATION_SIZE 120 + struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) { double recentTime, recentTime2; - double delta[STROBE_CORE_DEVIATION_SIZE]; + double delta[DEVIATION_SIZE]; size_t fCounterSnapshot; char debugStr[2048]; // Heap allocation ? int offsetX; @@ -88,7 +95,7 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) if ( this->base.protected->fCounter > ARRAYSIZE( this->private->delta ) ) { - if ( this->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) + if ( this->base.protected->deviation > DEVIATION_LIMIT ) { this->base.protected->cdTriggered = true; this->base.protected->cdTimer = 0.0; diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 6bcb5e9fb..0fd5b9b50 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -20,13 +20,11 @@ See the GNU General Public License for more details. #if !defined R_STROBE_CORE_H && !defined STROBE_DISABLED #define R_STROBE_CORE_H - #include "r_strobe_api.h" + #define STROBE_CORE STROBE_IMPL( CORE ) -#define STROBE_CORE_DEVIATION_LIMIT 2.5 -#define STROBE_CORE_DEVIATION_SIZE 60 struct STROBE_IMPL_STRUCT( STROBE_CORE ); struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ); From 8944808195b7d8fa50da69742162f702d1154245 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 5 May 2018 23:28:12 +0300 Subject: [PATCH 29/35] Revert "Adjusted constness & format" This reverts commit 84759c70d8da740a9c2165f6f39c0e669f9857c6. --- engine/client/strobe/r_strobe_api.c | 64 +++---- engine/client/strobe/r_strobe_api.h | 52 +++--- .../client/strobe/r_strobe_api_protected_.h | 4 +- engine/client/strobe/r_strobe_core.c | 166 +++++++++--------- engine/client/strobe/r_strobe_core.h | 10 +- .../strobe/r_strobe_template.c.TEMPLATE | 22 +-- .../strobe/r_strobe_template.h.TEMPLATE | 8 +- 7 files changed, 163 insertions(+), 163 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index b0a2c0fc1..17883be83 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -34,7 +34,7 @@ typedef struct StrobeAPI_private_s double nexttime, lasttime, framerate; size_t mark; size_t PositiveNormal, PositiveBlack, NegativeNormal, NegativeBlack; -} StrobeAPI_private_t; +}StrobeAPI_private_t; _inline double func_helper_StandardDeviation( const double *data, int n ) { @@ -73,7 +73,7 @@ _inline void GL_GenerateBlackFrame( void ) // Generates partial or full black fr } } -_inline double func_helper_getCooldown( StrobeAPI_t *const self ) +_inline double func_helper_getCooldown( StrobeAPI_t *self ) { if ( 0 <= self->protected->cdTimer ) { @@ -85,7 +85,7 @@ _inline double func_helper_getCooldown( StrobeAPI_t *const self ) } } -_inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *const self ) +_inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *self ) { if ( self->protected->frameInfo & PHASE_INVERTED ) return true; @@ -93,7 +93,7 @@ _inline qboolean func_helper_isPhaseInverted( StrobeAPI_t *const self ) return false; } -_inline qboolean func_helper_isNormal( StrobeAPI_t *const self ) +_inline qboolean func_helper_isNormal( StrobeAPI_t *self ) { if ( self->protected->frameInfo & FRAME_RENDER ) return true; @@ -101,7 +101,7 @@ _inline qboolean func_helper_isNormal( StrobeAPI_t *const self ) return false; } -_inline qboolean func_helper_isPositive( StrobeAPI_t *const self ) // ... +_inline qboolean func_helper_isPositive( StrobeAPI_t *self ) // ... { if ( self->protected->frameInfo & PHASE_POSITIVE ) return true; @@ -109,7 +109,7 @@ _inline qboolean func_helper_isPositive( StrobeAPI_t *const self ) // ... return false; } -_inline double func_helper_effectiveFPS( StrobeAPI_t *const self ) +_inline double func_helper_effectiveFPS( StrobeAPI_t *self ) { int strobeInterval = StrobeAPI.r_strobe->integer; double eFPS; @@ -127,7 +127,7 @@ _inline double func_helper_effectiveFPS( StrobeAPI_t *const self ) return eFPS; } -_inline void func_helper_GenerateDiffBar( StrobeAPI_t *const self, char *src, int size, char type ) +_inline void func_helper_GenerateDiffBar( StrobeAPI_t *self, char *src, int size, char type ) { char _barCounter = 0; int diff_NB = 0; @@ -239,7 +239,7 @@ _inline void func_helper_GenerateDiffBar( StrobeAPI_t *const self, char *src, in } } -_inline double func_pwmsimulation_Frequency( StrobeAPI_t *const self ) +_inline double func_pwmsimulation_Frequency( StrobeAPI_t *self ) { return ( 1 / ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) ); } @@ -250,7 +250,7 @@ _inline double func_pwmsimulation_DutyCycle( void ) return ( ( ( 1.0f / ( abs( strobeInterval ) + 1 ) ) * 100 ) * ( strobeInterval < 0 ? -strobeInterval : 1 ) ); } -_inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *const self ) +_inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *self ) { if ( !!( self->protected->frameInfo & PHASE_INVERTED ) ) return ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; @@ -258,7 +258,7 @@ _inline double func_pwmsimulation_PositivePhaseShift( StrobeAPI_t *const self ) return 0.0f; } -_inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *const self ) +_inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *self ) { if ( !!( self->protected->frameInfo & PHASE_INVERTED ) ) return abs( StrobeAPI.r_strobe->integer ) * ( 1.0f / self->Helpers.CurrentFPS( self ) ) * 1000; @@ -266,7 +266,7 @@ _inline double func_pwmsimulation_NegativePhaseShift( StrobeAPI_t *const self ) return 0.0; } -_inline double func_pwmsimulation_Period( StrobeAPI_t *const self ) +_inline double func_pwmsimulation_Period( StrobeAPI_t *self ) { return ( ( ( 1.0f / self->Helpers.CurrentFPS( self ) ) * ( abs( StrobeAPI.r_strobe->integer ) + 1 ) ) * 1000 ); } @@ -281,32 +281,32 @@ _inline double func_helper_ArithmeticMean( double x, double y ) return ( x + y ) / 2; } -_inline double func_brightnessreduction_ActualBrightnessReduction( StrobeAPI_t *const self ) +_inline double func_brightnessreduction_ActualBrightnessReduction( StrobeAPI_t *self ) { return lossCalculator( self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ) ); } -_inline double func_brightnessreduction_LogarithmicBrightnessReduction( StrobeAPI_t *const self, double base ) +_inline double func_brightnessreduction_LogarithmicBrightnessReduction( StrobeAPI_t *self, double base ) { return lossCalculator( log( base ), log( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_SquareBrightnessReduction( StrobeAPI_t *const self, double base ) +_inline double func_brightnessreduction_SquareBrightnessReduction( StrobeAPI_t *self, double base ) { return lossCalculator( sqrt( base ), sqrt( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_CubeBrightnessReduction( StrobeAPI_t *const self, double base ) +_inline double func_brightnessreduction_CubeBrightnessReduction( StrobeAPI_t *self, double base ) { return lossCalculator( cbrt( base ), cbrt( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_brightnessreduction_OtherBrightnessReduction( StrobeAPI_t *const self, double base, double ( *reductionFunction )( double ) ) +_inline double func_brightnessreduction_OtherBrightnessReduction( StrobeAPI_t *self, double base, double ( *reductionFunction )( double ) ) { return lossCalculator( reductionFunction( base ), reductionFunction( base * self->Helpers.effectiveFPS( self ) / self->Helpers.CurrentFPS( self ) ) ); } -_inline double func_experimental_Badness_Reducted( StrobeAPI_t *const self, qboolean PWMInvolved ) +_inline double func_experimental_Badness_Reducted( StrobeAPI_t *self, qboolean PWMInvolved ) { double badness, Diff; int diffP_NB, diffN_NB; @@ -340,7 +340,7 @@ _inline double func_experimental_Badness_Reducted( StrobeAPI_t *const self, qboo return badness; } -_inline double func_experimental_Badness( StrobeAPI_t *const self, qboolean PWMInvolved ) +_inline double func_experimental_Badness( StrobeAPI_t *self, qboolean PWMInvolved ) { int diffP_NB, diffN_NB; double diffP = 0.0, diffN = 0.0; @@ -369,7 +369,7 @@ _inline double func_experimental_Badness( StrobeAPI_t *const self, qboolean PWMI return badness; } -_inline size_t func_get_FrameCounter( StrobeAPI_t *const self, STROBE_counterType type ) +_inline size_t func_get_FrameCounter( StrobeAPI_t *self, STROBE_counterType type ) { switch ( type ) { @@ -410,7 +410,7 @@ _inline size_t func_get_FrameCounter( StrobeAPI_t *const self, STROBE_counterTyp } } -_inline double func_get_currentFPS( StrobeAPI_t *const self ) +_inline double func_get_currentFPS( StrobeAPI_t *self ) { // Copied from SCR_DrawFps // This way until current fps becomes global!!! @@ -421,15 +421,15 @@ _inline double func_get_currentFPS( StrobeAPI_t *const self ) if ( newtime >= self->private->nexttime ) { self->private->framerate = ( self->protected->fCounter - self->private->mark ) / ( newtime - self->private->lasttime ); - self->private->lasttime = newtime; - self->private->nexttime = max( self->private->nexttime + 0.35, self->private->lasttime - 0.35 ); + self->private->lasttime = newtime; + self->private->nexttime = max(self->private->nexttime + 0.35, self->private->lasttime - 0.35 ); self->private->mark = self->protected->fCounter; } return self->private->framerate; } -_inline void GenerateDebugStatistics( StrobeAPI_t *const self, char *src, int size ) +_inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) { char diffBarP[128], diffBarN[128], diffBarT[128]; size_t nPositiveNormal, nPositiveBlack, nNegativeNormal, nNegativeBlack; @@ -459,7 +459,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *const self, char *src, int si size, "%.2f FPS\n%.2f eFPS\n" "Elapsed Time: %.2f\n" - "isPhaseInverted = %d\n" + "isPhaseInverted = %d\n" "Total Frame Count: %zu\n" "^7(+) Phase Frame Count: %zu\n" "%s\n" @@ -492,7 +492,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *const self, char *src, int si self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ), self->protected->elapsedTime, - self->Helpers.isPhaseInverted( self ), + self->Helpers.isPhaseInverted(self), self->get.FrameCounter( self, STROBE_CT_TotalFrame ), self->get.FrameCounter( self, STROBE_CT_PositiveFrame ), ( nPositiveNormal > self->private->PositiveNormal ? va( "^2|-> Normal Frame Count: %zu^7", nPositiveNormal ) : va( "|-> Normal Frame Count: %zu", nPositiveNormal ) ), // Should be white instead of ^7 but white is not available in the color table @@ -527,7 +527,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *const self, char *src, int si self->private->NegativeBlack = self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ); } -_inline void ProcessFrame( StrobeAPI_t *const self ) +_inline void ProcessFrame( StrobeAPI_t *self ) { if ( self->protected->cdTriggered != false ) { @@ -557,12 +557,12 @@ _inline void ProcessFrame( StrobeAPI_t *const self ) ++self->protected->fCounter; } -_inline void StrobeAPI_constructor( StrobeAPI_t *const self ) +_inline void StrobeAPI_constructor( StrobeAPI_t *self ) { self->protected = (StrobeAPI_protected_t *)calloc( 1, sizeof( StrobeAPI_protected_t ) ); - self->private = (StrobeAPI_private_t *)calloc( 1, sizeof( StrobeAPI_private_t ) ); + self->private = (StrobeAPI_private_t *)calloc(1, sizeof(StrobeAPI_private_t)); - if ( self->protected == NULL || self->private == NULL ) + if (self->protected == NULL || self->private == NULL) { return; // Fix handling! } @@ -596,9 +596,9 @@ _inline void StrobeAPI_constructor( StrobeAPI_t *const self ) self->Helpers.GenerateDebugStatistics = GenerateDebugStatistics; } -_inline void StrobeAPI_destructor( StrobeAPI_t *const self ) +_inline void StrobeAPI_destructor( StrobeAPI_t *self ) { - if ( self->private ) + if (self->private) { free( self->private ); self->private = NULL; @@ -610,7 +610,7 @@ _inline void StrobeAPI_destructor( StrobeAPI_t *const self ) } } -_inline void StrobeAPI_Invoker( const void *const *const self, void ( *constructor )( const void *const *const ), void ( *main )( const void *const *const ), void ( *destructor )( const void *const *const ) ) +_inline void StrobeAPI_Invoker( void **self, void ( *constructor )( void ** ), void ( *main )( void ** ), void ( *destructor )( void ** ) ) { if ( StrobeAPI.r_strobe->integer ) { diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 4814c2fbe..25595d1ae 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -42,14 +42,14 @@ See the GNU General Public License for more details. #define STROBE_IMPL_STRUCT(IMPL) STROBE_CONCAT(IMPL, _s) #define STROBE_IMPL_PRIVATE_STRUCT(IMPL) STROBE_CONCAT(IMPL, _private_s) #define STROBE_IMPL_THIS(IMPL) ( *_STROBE_IMPL_THIS ) -#define STROBE_IMPL_THIS_PARAM(IMPL) struct STROBE_IMPL_STRUCT(IMPL) *const *const _STROBE_IMPL_THIS +#define STROBE_IMPL_THIS_PARAM(IMPL) struct STROBE_IMPL_STRUCT(IMPL) **_STROBE_IMPL_THIS #define STROBE_IMPL_EXPORTEDFUNC_main(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_MAIN) #define STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_CONSTRUCTOR) #define STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_DESTRUCTOR) #define STROBE_IMPL_EXPORTEDFUNC_reinit(IMPL) STROBE_IMPL_EXPORTFUNC(IMPL, STROBE_IMPL_FUNC_REINIT) -#define STROBE_INVOKE(IMPL) (const void *const *const)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) +#define STROBE_INVOKE(IMPL) (void**)(&IMPL),STROBE_IMPL_EXPORTEDFUNC_constructor(IMPL),STROBE_IMPL_EXPORTEDFUNC_main(IMPL),STROBE_IMPL_EXPORTEDFUNC_destructor(IMPL) // MACROS FOR STROBE IMPLEMENTATIONS typedef struct StrobeAPI_s StrobeAPI_t; @@ -67,46 +67,46 @@ typedef enum typedef struct StrobeAPI_funcs_BRIGHTNESSREDUCTION_s { - double ( *ActualBrightnessReduction )( StrobeAPI_t *const self ); - double ( *LogarithmicBrightnessReduction )( StrobeAPI_t *const self, double base ); - double ( *SquareBrightnessReduction )( StrobeAPI_t *const self, double base ); - double ( *CubeBrightnessReduction )( StrobeAPI_t *const self, double base ); - double ( *OtherBrightnessReduction )( StrobeAPI_t *const self, double base, double ( *reductionFunction )( double ) ); + double ( *ActualBrightnessReduction )( StrobeAPI_t *self ); + double ( *LogarithmicBrightnessReduction )( StrobeAPI_t *self, double base ); + double ( *SquareBrightnessReduction )( StrobeAPI_t *self, double base ); + double ( *CubeBrightnessReduction )( StrobeAPI_t *self, double base ); + double ( *OtherBrightnessReduction )( StrobeAPI_t *self, double base, double ( *reductionFunction )( double ) ); } StrobeAPI_funcs_BRIGHTNESSREDUCTION_t; typedef struct StrobeAPI_funcs_EXPERIMENTAL_s { - double ( *BADNESS )( StrobeAPI_t *const self, qboolean PWMInvolved ); - double ( *BADNESS_REDUCTED )( StrobeAPI_t *const self, qboolean PWMInvolved ); + double ( *BADNESS )( StrobeAPI_t *self, qboolean PWMInvolved ); + double ( *BADNESS_REDUCTED )( StrobeAPI_t *self, qboolean PWMInvolved ); } StrobeAPI_funcs_EXPERIMENTAL_t; typedef struct StrobeAPI_funcs_PWMSIMULATION_s { - double ( *Frequency )( StrobeAPI_t *const self ); + double ( *Frequency )( StrobeAPI_t *self ); double ( *DutyCycle )( void ); - double ( *PositivePhaseShift )( StrobeAPI_t *const self ); - double ( *NegativePhaseShift )( StrobeAPI_t *const self ); - double ( *Period )( StrobeAPI_t *const self ); + double ( *PositivePhaseShift )( StrobeAPI_t *self ); + double ( *NegativePhaseShift )( StrobeAPI_t *self ); + double ( *Period )( StrobeAPI_t *self ); } StrobeAPI_funcs_PWMSIMULATION_t; typedef struct StrobeAPI_funcs_HELPER_s { - qboolean ( *isPhaseInverted )( StrobeAPI_t *const self ); - qboolean ( *isNormal )( StrobeAPI_t *const self ); - qboolean ( *isPositive )( StrobeAPI_t *const self ); - double ( *effectiveFPS )( StrobeAPI_t *const self ); - double ( *CurrentFPS )( StrobeAPI_t *const self ); - void ( *GenerateDebugStatistics )( StrobeAPI_t *const self, char *src, int size ); - void ( *GenerateDiffBar )( StrobeAPI_t *const self, char *src, int size, char type ); + qboolean ( *isPhaseInverted )( StrobeAPI_t *self ); + qboolean ( *isNormal )( StrobeAPI_t *self ); + qboolean ( *isPositive )( StrobeAPI_t *self ); + double ( *effectiveFPS )( StrobeAPI_t *self ); + double ( *CurrentFPS )( StrobeAPI_t *self ); + void ( *GenerateDebugStatistics )( StrobeAPI_t *self, char *src, int size ); + void ( *GenerateDiffBar )( StrobeAPI_t *self, char *src, int size, char type ); double ( *GeometricMean )( double x, double y ); double ( *ArithmeticMean )( double x, double y ); double ( *StandardDeviation )( const double *data, int size ); - double ( *Cooldown )( StrobeAPI_t *const self ); + double ( *Cooldown )( StrobeAPI_t *self ); } StrobeAPI_funcs_HELPER_t; typedef struct StrobeAPI_funcs_GET_s { - size_t ( *FrameCounter )( StrobeAPI_t *const self, STROBE_counterType ); + size_t ( *FrameCounter )( StrobeAPI_t *self, STROBE_counterType ); } StrobeAPI_funcs_GET_t; typedef struct StrobeAPI_protected_s StrobeAPI_protected_t; @@ -123,14 +123,14 @@ typedef struct StrobeAPI_s StrobeAPI_funcs_HELPER_t Helpers; StrobeAPI_funcs_GET_t get; void ( *GenerateBlackFrame )( void ); - void ( *ProcessFrame )( StrobeAPI_t *const self ); + void ( *ProcessFrame )( StrobeAPI_t *self ); } StrobeAPI_t; typedef struct StrobeAPI_EXPORTS_s { - void ( *Invoker )( const void *const *const self, void ( *constructor )( const void *const *const ), void ( *main )( const void *const *const ), void ( *destructor )( const void *const *const ) ); // Strobe Invoker - void ( *Constructor )( StrobeAPI_t *const self ); - void ( *Destructor )( StrobeAPI_t *const self ); + void ( *Invoker )( void **self, void ( *constructor )( void ** ), void ( *main )( void ** ), void ( *destructor )( void ** ) ); // Strobe Invoker + void ( *Constructor )( StrobeAPI_t *self ); + void ( *Destructor )( StrobeAPI_t *self ); convar_t *r_strobe; convar_t *r_strobe_swapinterval; diff --git a/engine/client/strobe/r_strobe_api_protected_.h b/engine/client/strobe/r_strobe_api_protected_.h index 87e18c1d6..c62ea4749 100644 --- a/engine/client/strobe/r_strobe_api_protected_.h +++ b/engine/client/strobe/r_strobe_api_protected_.h @@ -28,7 +28,7 @@ typedef enum PHASE_POSITIVE = BIT( 0 ), // Phase: Positive PHASE_INVERTED = BIT( 1 ), // Phase: Inverted FRAME_RENDER = BIT( 2 ) // Frame: Rendered -} fstate_e; // Frame State +} fstate_e; // Frame State typedef struct StrobeAPI_protected_s { @@ -39,7 +39,7 @@ typedef struct StrobeAPI_protected_s double deviation; // deviation double cdTimer; // Cooldown timer qboolean cdTriggered; // Cooldown trigger status - fstate_e frameInfo; // Frame info + fstate_e frameInfo; // Frame info } StrobeAPI_protected_t; // Protected members #endif diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index fae3a5abc..057756453 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -25,10 +25,10 @@ See the GNU General Public License for more details. #include "gl_local.h" #include "r_strobe_api_protected_.h" -#ifdef this -#undef this +#ifdef _this +#undef _this #endif -#define this STROBE_IMPL_THIS( STROBE_CORE ) +#define _this STROBE_IMPL_THIS( STROBE_CORE ) struct STROBE_IMPL_STRUCT( STROBE_CORE ) *STROBE_CORE = NULL; @@ -65,10 +65,10 @@ R_Strobe static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) { double delta, delta2; - double currentTime = Sys_DoubleTime( ); - delta2 = currentTime - this->private->recentTime2; - this->private->recentTime2 = currentTime; - this->base.protected->elapsedTime = currentTime - this->private->initialTime; + double currentTime = Sys_DoubleTime( ); + delta2 = currentTime - _this->private->recentTime2; + _this->private->recentTime2 = currentTime; + _this->base.protected->elapsedTime = currentTime - _this->base.protected->initialTime; if ( CL_IsInMenu( ) ) { @@ -76,143 +76,143 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) return; } - if ( this->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) - this->base.protected->cdTimer += delta2; - if ( this->base.protected->fCounter - this->private->fCounterSnapshot == 1 ) + if ( _this->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) + _this->base.protected->cdTimer += delta2; + if ( _this->base.protected->fCounter - _this->private->fCounterSnapshot == 1 ) { - this->private->delta[this->base.protected->fCounter % ARRAYSIZE( this->private->delta )] = delta2; - this->base.protected->deviation = this->base.Helpers.StandardDeviation( this->private->delta, ARRAYSIZE( this->private->delta ) ) * 1000; + _this->private->delta[_this->base.protected->fCounter % ARRAYSIZE( _this->private->delta )] = delta2; + _this->base.protected->deviation = _this->base.Helpers.StandardDeviation( _this->private->delta, ARRAYSIZE( _this->private->delta ) ) * 1000; } - this->private->fCounterSnapshot = this->base.protected->fCounter; + _this->private->fCounterSnapshot = _this->base.protected->fCounter; if ( StrobeAPI.r_strobe_cooldown->integer > 0 ) { - if ( ( this->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && this->base.protected->cdTriggered == true ) + if ( ( _this->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && _this->base.protected->cdTriggered == true ) { - this->base.protected->cdTriggered = false; - this->base.protected->cdTimer = -1.0; + _this->base.protected->cdTriggered = false; + _this->base.protected->cdTimer = -1.0; } - if ( this->base.protected->fCounter > ARRAYSIZE( this->private->delta ) ) + if ( _this->base.protected->fCounter > ARRAYSIZE( _this->private->delta ) ) { - if ( this->base.protected->deviation > DEVIATION_LIMIT ) + if ( _this->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) { - this->base.protected->cdTriggered = true; - this->base.protected->cdTimer = 0.0; + _this->base.protected->cdTriggered = true; + _this->base.protected->cdTimer = 0.0; } } } else { - this->base.protected->cdTriggered = false; + _this->base.protected->cdTriggered = false; } - if ( ( ( this->private->strobeInterval != StrobeAPI.r_strobe->integer ) && ( this->private->strobeInterval ) ) || + if ( ( ( _this->private->strobeInterval != StrobeAPI.r_strobe->integer ) && ( _this->private->strobeInterval ) ) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - this->base.protected->fCounter == UINT_MAX ) + _this->base.protected->fCounter == UINT_MAX ) { STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( *(void ***)&_STROBE_IMPL_THIS ); - R_Strobe( &this ); + R_Strobe( &_this ); } - this->private->strobeInterval = StrobeAPI.r_strobe->integer; - this->private->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; + _this->private->strobeInterval = StrobeAPI.r_strobe->integer; + _this->private->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; - if ( ( this->private->strobeInterval == 0 ) || - ( ( gl_swapInterval->integer == 0 ) && ( this->private->strobeInterval ) ) ) + if ( ( _this->private->strobeInterval == 0 ) || + ( ( gl_swapInterval->integer == 0 ) && ( _this->private->strobeInterval ) ) ) { if ( !gl_swapInterval->integer ) MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - if ( this->private->strobeInterval ) // If v-sync is off, turn off strobing + if ( _this->private->strobeInterval ) // If v-sync is off, turn off strobing { Cvar_Set( "r_strobe", "0" ); } - this->base.protected->fCounter = 0; + _this->base.protected->fCounter = 0; R_Set2DMode( false ); return; } - if ( ( this->base.protected->fCounter % 2 ) == 0 ) + if ( ( _this->base.protected->fCounter % 2 ) == 0 ) { - ++this->base.protected->pCounter; - this->base.protected->frameInfo |= PHASE_POSITIVE; + ++_this->base.protected->pCounter; + _this->base.protected->frameInfo |= PHASE_POSITIVE; } else { - ++this->base.protected->nCounter; - this->base.protected->frameInfo &= ~PHASE_POSITIVE; + ++_this->base.protected->nCounter; + _this->base.protected->frameInfo &= ~PHASE_POSITIVE; } - if ( this->private->swapInterval < 0 ) - this->private->swapInterval = abs( this->private->swapInterval ); + if ( _this->private->swapInterval < 0 ) + _this->private->swapInterval = abs( _this->private->swapInterval ); - if ( ( this->private->swapInterval ) && ( this->private->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ( ( _this->private->swapInterval ) && ( _this->private->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { - delta = currentTime - this->private->recentTime; // New Currenttime for _delta ? - if ( ( delta >= (double)( this->private->swapInterval ) ) && ( delta < (double)( 2 * this->private->swapInterval ) ) ) // Basic timer + delta = currentTime - _this->private->recentTime; // New Currenttime for _delta ? + if ( ( delta >= (double)( _this->private->swapInterval ) ) && ( delta < (double)( 2 * _this->private->swapInterval ) ) ) // Basic timer { - this->base.protected->frameInfo |= PHASE_INVERTED; + _this->base.protected->frameInfo |= PHASE_INVERTED; } - else if ( delta < (double)( this->private->swapInterval ) ) + else if ( delta < (double)( _this->private->swapInterval ) ) { - this->base.protected->frameInfo &= ~PHASE_INVERTED; + _this->base.protected->frameInfo &= ~PHASE_INVERTED; } else //if (delta >= (double)(2 * swapInterval)) { - this->private->recentTime = currentTime; + _this->private->recentTime = currentTime; } } - switch ( this->base.protected->frameInfo & ( PHASE_POSITIVE | PHASE_INVERTED ) ) + switch ( _this->base.protected->frameInfo & ( PHASE_POSITIVE | PHASE_INVERTED ) ) { case ( PHASE_POSITIVE | PHASE_INVERTED ): - if ( ( abs( this->private->strobeInterval ) % 2 ) == 0 ) - this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == ( abs( this->private->strobeInterval ) / 2 ) ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else - this->base.protected->frameInfo &= ~FRAME_RENDER; + _this->base.protected->frameInfo &= ~FRAME_RENDER; break; case ( PHASE_POSITIVE & ~PHASE_INVERTED ): - if ( abs( this->private->strobeInterval ) % 2 == 0 ) - this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( abs( _this->private->strobeInterval ) % 2 == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( this->private->strobeInterval ) == 1 ) - this->base.protected->frameInfo |= FRAME_RENDER; + if ( abs( _this->private->strobeInterval ) == 1 ) + _this->base.protected->frameInfo |= FRAME_RENDER; else - this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( ( abs( this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //odd + _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; case ( ~PHASE_POSITIVE & PHASE_INVERTED ): - if ( abs( this->private->strobeInterval ) % 2 == 0 ) - this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( abs( _this->private->strobeInterval ) % 2 == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( this->private->strobeInterval ) == 1 ) - this->base.protected->frameInfo |= FRAME_RENDER; + if ( abs( _this->private->strobeInterval ) == 1 ) + _this->base.protected->frameInfo |= FRAME_RENDER; else - this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( ( abs( this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //odd + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; case 0: - if ( ( abs( this->private->strobeInterval ) % 2 ) == 0 ) - this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == ( abs( this->private->strobeInterval ) / 2 ) ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) + _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even else - this->base.protected->frameInfo &= ~FRAME_RENDER; + _this->base.protected->frameInfo &= ~FRAME_RENDER; break; default: - this->base.protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); + _this->base.protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); } - if ( this->private->strobeInterval < 0 ) - this->base.protected->frameInfo ^= FRAME_RENDER; + if ( _this->private->strobeInterval < 0 ) + _this->base.protected->frameInfo ^= FRAME_RENDER; - this->base.ProcessFrame( &this->base ); + _this->base.ProcessFrame( &_this->base ); } _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) @@ -241,42 +241,42 @@ _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) if ( strobeDebug ) { newtime = Sys_DoubleTime( ); - if ( newtime >= this->private->nexttime ) + if ( newtime >= _this->private->nexttime ) { - this->base.Helpers.GenerateDebugStatistics( &this->base, this->private->debugStr, ARRAYSIZE( this->private->debugStr ) ); - this->private->lasttime = newtime; - this->private->nexttime = max( this->private->nexttime + 0.15, this->private->lasttime - 0.15 ); // Make this configurable + _this->base.Helpers.GenerateDebugStatistics( &_this->base, _this->private->debugStr, ARRAYSIZE( _this->private->debugStr ) ); + _this->private->lasttime = newtime; + _this->private->nexttime = max( _this->private->nexttime + 0.15, _this->private->lasttime - 0.15 ); // Make this configurable } } else if ( cl_showfps->integer ) { - Q_snprintf( this->private->debugStr, sizeof( this->private->debugStr ), "%3d eFPS", (int)round( this->base.Helpers.effectiveFPS( &this->base ) ) ); + Q_snprintf( _this->private->debugStr, sizeof( _this->private->debugStr ), "%3d eFPS", (int)round( _this->base.Helpers.effectiveFPS( &_this->base ) ) ); } MakeRGBA( color, 255, 255, 255, 255 ); - Con_DrawStringLen( this->private->debugStr, &fixer, &offsetY ); + Con_DrawStringLen( _this->private->debugStr, &fixer, &offsetY ); if ( strobeDebug ) - Con_DrawString( scr_width->integer - this->private->offsetX - 50, 4, this->private->debugStr, color ); + Con_DrawString( scr_width->integer - _this->private->offsetX - 50, 4, _this->private->debugStr, color ); else - Con_DrawString( scr_width->integer - this->private->offsetX - 2, offsetY + 8, this->private->debugStr, color ); - if ( abs( fixer - this->private->offsetX ) > 50 || this->private->offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! - this->private->offsetX = fixer; + Con_DrawString( scr_width->integer - _this->private->offsetX - 2, offsetY + 8, _this->private->debugStr, color ); + if ( abs( fixer - _this->private->offsetX ) > 50 || _this->private->offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! + _this->private->offsetX = fixer; } -void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( const void *const *const STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) { struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; - *instance = (struct STROBE_IMPL_STRUCT( STROBE_CORE ) *)malloc( sizeof( struct STROBE_IMPL_STRUCT( STROBE_CORE ) ) ); - ( *instance )->private = (struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *)calloc( 1, sizeof( struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) ) ); - ( *instance )->private->initialTime = Sys_DoubleTime( ); + *instance = (struct STROBE_IMPL_STRUCT( STROBE_CORE ) *)malloc( sizeof(struct STROBE_IMPL_STRUCT(STROBE_CORE)) ); + ( *instance )->private = (struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *)calloc( 1, sizeof(struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_CORE)) ); + ( *instance )->private->initialTime = Sys_DoubleTime(); ( *instance )->STROBE_IMPL_FUNC_MAIN = R_Strobe; ( *instance )->STROBE_IMPL_FUNC_DEBUGHANDLER = debugDrawer; StrobeAPI.Constructor( &( *instance )->base ); } -void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( const void *const *const STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ) { struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; @@ -293,7 +293,7 @@ void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( const void *const *cons } } -void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( const void *const *const STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ) { if ( !( *STROBE_CORE ) ) { @@ -302,7 +302,7 @@ void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( const void *const *const ST STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( STROBE_CORE ); } -void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( const void *const *const STROBE_CORE ) +void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ) { struct STROBE_IMPL_STRUCT( STROBE_CORE ) **instance = *(struct STROBE_IMPL_STRUCT( STROBE_CORE ) ***)&STROBE_CORE; if ( *instance ) @@ -311,6 +311,6 @@ void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( const void *const *const STRO } } -#undef this +#undef _this #endif diff --git a/engine/client/strobe/r_strobe_core.h b/engine/client/strobe/r_strobe_core.h index 0fd5b9b50..a9dbe9cba 100644 --- a/engine/client/strobe/r_strobe_core.h +++ b/engine/client/strobe/r_strobe_core.h @@ -32,15 +32,15 @@ struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ); struct STROBE_IMPL_STRUCT( STROBE_CORE ) { StrobeAPI_t base; - struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) * private; + struct STROBE_IMPL_PRIVATE_STRUCT( STROBE_CORE ) *private; void ( *STROBE_IMPL_FUNC_MAIN )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); void ( *STROBE_IMPL_FUNC_DEBUGHANDLER )( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ); }; extern struct STROBE_IMPL_STRUCT( STROBE_CORE ) * STROBE_CORE; -void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( const void *const *const STROBE_CORE ); -void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( const void *const *const STROBE_CORE ); -void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( const void *const *const STROBE_CORE ); -void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( const void *const *const STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_destructor( STROBE_CORE )( void **STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( void **STROBE_CORE ); +void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ); #endif diff --git a/engine/client/strobe/r_strobe_template.c.TEMPLATE b/engine/client/strobe/r_strobe_template.c.TEMPLATE index f5c9d0f40..d62d92792 100644 --- a/engine/client/strobe/r_strobe_template.c.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.c.TEMPLATE @@ -26,10 +26,10 @@ See the GNU General Public License for more details. #include "client.h" #include "gl_local.h" -#ifdef this -#undef this +#ifdef _this +#undef _this #endif -#define this STROBE_IMPL_THIS(STROBE_TEMPLATE) +#define _this STROBE_IMPL_THIS(STROBE_TEMPLATE) struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) *STROBE_TEMPLATE = NULL; @@ -40,17 +40,17 @@ struct STROBE_IMPL_PRIVATE_STRUCT(STROBE_TEMPLATE) static void main( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) { - this->base.protected->frameInfo = ( p_positive | f_normal ); - this->base.ProcessFrame( &this->base ); + _this->base.protected->frameInfo = ( p_positive | f_normal ); + _this->base.ProcessFrame( &_this->base ); } static void debugHandler( STROBE_IMPL_THIS_PARAM( STROBE_TEMPLATE ) ) { char debugstr[2048] = {0}; - this->base.Helpers.GenerateDebugStatistics( &this->base, debugstr, 2048 ); + _this->base.Helpers.GenerateDebugStatistics( &_this->base, debugstr, 2048 ); } -void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; @@ -62,7 +62,7 @@ void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( const void * const * StrobeAPI.Constructor( &( *instance )->base ); } -void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; @@ -79,7 +79,7 @@ void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( const void * const * } } -void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { if ( !( *STROBE_TEMPLATE ) ) { @@ -88,7 +88,7 @@ void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( const void * const * cons STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( STROBE_TEMPLATE ); } -void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ) +void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ) { struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) **instance = *(struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) ***)&STROBE_TEMPLATE; if ( *instance ) @@ -98,6 +98,6 @@ void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( const void * const * const } -#undef this +#undef _this #endif \ No newline at end of file diff --git a/engine/client/strobe/r_strobe_template.h.TEMPLATE b/engine/client/strobe/r_strobe_template.h.TEMPLATE index 788317ca2..341c19491 100644 --- a/engine/client/strobe/r_strobe_template.h.TEMPLATE +++ b/engine/client/strobe/r_strobe_template.h.TEMPLATE @@ -37,9 +37,9 @@ struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) }; extern struct STROBE_IMPL_STRUCT(STROBE_TEMPLATE) *STROBE_TEMPLATE; -void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); -void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); -void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); -void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( const void * const * const STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_constructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_destructor(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_reinit(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); +void STROBE_IMPL_EXPORTEDFUNC_main(STROBE_TEMPLATE)( void **STROBE_TEMPLATE ); #endif \ No newline at end of file From b590a5b0b2e31b9b7dacab65924d8c7657fa0a4a Mon Sep 17 00:00:00 2001 From: fuzun Date: Mon, 7 May 2018 19:14:31 +0300 Subject: [PATCH 30/35] Better transition for r_strobe = 1 or -1 --- engine/client/strobe/r_strobe_api.c | 28 +++++++++++++++++++++------- engine/client/strobe/r_strobe_api.h | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 17883be83..a1a162725 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -34,6 +34,7 @@ typedef struct StrobeAPI_private_s double nexttime, lasttime, framerate; size_t mark; size_t PositiveNormal, PositiveBlack, NegativeNormal, NegativeBlack; + qboolean firstInverted; }StrobeAPI_private_t; _inline double func_helper_StandardDeviation( const double *data, int n ) @@ -50,8 +51,11 @@ _inline double func_helper_StandardDeviation( const double *data, int n ) return sqrt( sum_deviation / n ); } -_inline void GL_GenerateBlackFrame( void ) // Generates partial or full black frame +_inline void GL_GenerateBlackFrame( float opacity ) // Generates partial or full black frame { + if (opacity < 0.0f || opacity > 1.0f) + opacity = 1.0f; + if ( CL_IsInConsole( ) ) // No strobing on the console { if ( !vid_fullscreen->integer ) // Disable when not fullscreen due to viewport problems @@ -61,7 +65,7 @@ _inline void GL_GenerateBlackFrame( void ) // Generates partial or full black fr } pglEnable( GL_SCISSOR_TEST ); pglScissor( con_rect.x, ( -con_rect.y ) - ( con_rect.h * 1.25 ), con_rect.w, con_rect.h ); // Preview strobe setting on static - pglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + pglClearColor( 0.0f, 0.0f, 0.0f, opacity ); pglClear( GL_COLOR_BUFFER_BIT ); pglDisable( GL_SCISSOR_TEST ); } @@ -529,10 +533,13 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) _inline void ProcessFrame( StrobeAPI_t *self ) { + if ((self->private->firstInverted && self->Helpers.isPhaseInverted(self)) || !self->Helpers.isPhaseInverted(self)) + self->private->firstInverted = false; + else if (self->Helpers.isPhaseInverted(self) && (StrobeAPI.r_strobe->integer == 1 || StrobeAPI.r_strobe->integer == -1)) + self->private->firstInverted = true; + if ( self->protected->cdTriggered != false ) - { self->protected->frameInfo = FRAME_RENDER | ( self->protected->frameInfo & PHASE_POSITIVE ); - } if ( self->protected->frameInfo & FRAME_RENDER ) // Show normal { @@ -541,7 +548,8 @@ _inline void ProcessFrame( StrobeAPI_t *self ) else ++self->protected->nNCounter; - R_Set2DMode( false ); + if(!self->private->firstInverted) + R_Set2DMode( false ); } else // Show black { @@ -550,8 +558,14 @@ _inline void ProcessFrame( StrobeAPI_t *self ) else ++self->protected->nBCounter; - //GL_GenerateBlackFrame(); - self->GenerateBlackFrame( ); + if(!self->private->firstInverted) + self->GenerateBlackFrame( 1.0f ); + } + + if (self->private->firstInverted) + { + R_Set2DMode(false); + self->GenerateBlackFrame(0.5f); } ++self->protected->fCounter; diff --git a/engine/client/strobe/r_strobe_api.h b/engine/client/strobe/r_strobe_api.h index 25595d1ae..0063defe9 100644 --- a/engine/client/strobe/r_strobe_api.h +++ b/engine/client/strobe/r_strobe_api.h @@ -122,7 +122,7 @@ typedef struct StrobeAPI_s StrobeAPI_funcs_PWMSIMULATION_t PWM; StrobeAPI_funcs_HELPER_t Helpers; StrobeAPI_funcs_GET_t get; - void ( *GenerateBlackFrame )( void ); + void ( *GenerateBlackFrame )( float opacity ); void ( *ProcessFrame )( StrobeAPI_t *self ); } StrobeAPI_t; From c372b1c50e06e77a1fe86533203279cafccadbf8 Mon Sep 17 00:00:00 2001 From: fuzun Date: Mon, 7 May 2018 21:22:58 +0300 Subject: [PATCH 31/35] Better statistics & transition fix --- engine/client/strobe/r_strobe_api.c | 37 ++++++++++++++++++++++------ engine/client/strobe/r_strobe_core.c | 4 +-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index a1a162725..62dea1fcd 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -35,6 +35,7 @@ typedef struct StrobeAPI_private_s size_t mark; size_t PositiveNormal, PositiveBlack, NegativeNormal, NegativeBlack; qboolean firstInverted; + char strobemethod[128]; }StrobeAPI_private_t; _inline double func_helper_StandardDeviation( const double *data, int n ) @@ -440,6 +441,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) int diffP_NB, diffN_NB; double diffP = 0.0, diffN = 0.0; double cooldown = self->protected->cdTimer; + int strobeMethod = StrobeAPI.r_strobe->integer; diffP_NB = ( self->protected->pNCounter - self->protected->pBCounter ); diffN_NB = ( self->protected->nNCounter - self->protected->nBCounter ); @@ -459,9 +461,23 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) nNegativeNormal = self->get.FrameCounter( self, STROBE_CT_NegativeNormalFrame ); nNegativeBlack = self->get.FrameCounter( self, STROBE_CT_NegativeBlackFrame ); + + if (!strlen(self->private->strobemethod)) + { + Q_snprintf(self->private->strobemethod, sizeof(self->private->strobemethod), (strobeMethod > 0 ? "%d [NORMAL" : "%d [BLACK"), strobeMethod); + for (int k = 1; k <= abs(strobeMethod); ++k) + { + Q_strcat(self->private->strobemethod, (strobeMethod > 0 ? " - BLACK" : " - NORMAL")); + } + Q_strcat(self->private->strobemethod, "]"); + } + Q_snprintf( src, size, "%.2f FPS\n%.2f eFPS\n" + "Strobe Method: %s\n" + "Strobe Swap Interval: %d\n" + "Strobe Cooldown Delay: %d\n" "Elapsed Time: %.2f\n" "isPhaseInverted = %d\n" "Total Frame Count: %zu\n" @@ -476,7 +492,7 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) " |-> Frequency: %.2f Hz\n" " |-> Duty Cycle: %.2f%%\n" " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" - " |-> Period: %.4f msec\n" + " |-> Period: %.2f msec\n" "Brightness Reduction:\n" " |-> [^7LINEAR^3] Actual Reduction: %.2f%%\n" " |-> [^7LOG^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" @@ -495,6 +511,9 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) "^5=====ANALYSIS=====\n^3", self->Helpers.CurrentFPS( self ), self->Helpers.effectiveFPS( self ), + self->private->strobemethod, + StrobeAPI.r_strobe_swapinterval->integer, + StrobeAPI.r_strobe_cooldown->integer, self->protected->elapsedTime, self->Helpers.isPhaseInverted(self), self->get.FrameCounter( self, STROBE_CT_TotalFrame ), @@ -533,13 +552,16 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) _inline void ProcessFrame( StrobeAPI_t *self ) { - if ((self->private->firstInverted && self->Helpers.isPhaseInverted(self)) || !self->Helpers.isPhaseInverted(self)) - self->private->firstInverted = false; - else if (self->Helpers.isPhaseInverted(self) && (StrobeAPI.r_strobe->integer == 1 || StrobeAPI.r_strobe->integer == -1)) + static qboolean phase = 0; + if (phase != self->Helpers.isPhaseInverted(self) && (StrobeAPI.r_strobe->integer == 1 || StrobeAPI.r_strobe->integer == -1) && !self->protected->cdTriggered) self->private->firstInverted = true; + else + self->private->firstInverted = false; - if ( self->protected->cdTriggered != false ) - self->protected->frameInfo = FRAME_RENDER | ( self->protected->frameInfo & PHASE_POSITIVE ); + if (self->protected->cdTriggered) + { + self->protected->frameInfo = FRAME_RENDER | (self->protected->frameInfo & PHASE_POSITIVE); + } if ( self->protected->frameInfo & FRAME_RENDER ) // Show normal { @@ -567,7 +589,8 @@ _inline void ProcessFrame( StrobeAPI_t *self ) R_Set2DMode(false); self->GenerateBlackFrame(0.5f); } - + + phase = self->Helpers.isPhaseInverted(self); ++self->protected->fCounter; } diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index 057756453..ec502287a 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -68,7 +68,7 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) double currentTime = Sys_DoubleTime( ); delta2 = currentTime - _this->private->recentTime2; _this->private->recentTime2 = currentTime; - _this->base.protected->elapsedTime = currentTime - _this->base.protected->initialTime; + _this->base.protected->elapsedTime = currentTime - _this->private->initialTime; if ( CL_IsInMenu( ) ) { @@ -95,7 +95,7 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) if ( _this->base.protected->fCounter > ARRAYSIZE( _this->private->delta ) ) { - if ( _this->base.protected->deviation > STROBE_CORE_DEVIATION_LIMIT ) + if ( _this->base.protected->deviation > DEVIATION_LIMIT ) { _this->base.protected->cdTriggered = true; _this->base.protected->cdTimer = 0.0; From 2592dd99a1fd93861748069941d63952732567aa Mon Sep 17 00:00:00 2001 From: fuzun Date: Mon, 7 May 2018 21:33:13 +0300 Subject: [PATCH 32/35] Change in stability measurement --- engine/client/strobe/r_strobe_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index ec502287a..3a6e7e02d 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -33,7 +33,7 @@ See the GNU General Public License for more details. struct STROBE_IMPL_STRUCT( STROBE_CORE ) *STROBE_CORE = NULL; #ifdef _DEBUG -#define DEVIATION_LIMIT 2.0 +#define DEVIATION_LIMIT 1.5 #else #define DEVIATION_LIMIT 0.75 #endif @@ -80,8 +80,8 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) _this->base.protected->cdTimer += delta2; if ( _this->base.protected->fCounter - _this->private->fCounterSnapshot == 1 ) { - _this->private->delta[_this->base.protected->fCounter % ARRAYSIZE( _this->private->delta )] = delta2; - _this->base.protected->deviation = _this->base.Helpers.StandardDeviation( _this->private->delta, ARRAYSIZE( _this->private->delta ) ) * 1000; + _this->private->delta[_this->base.protected->fCounter % ARRAYSIZE( _this->private->delta )] = _this->base.Helpers.CurrentFPS(&_this->base); + _this->base.protected->deviation = _this->base.Helpers.StandardDeviation( _this->private->delta, ARRAYSIZE( _this->private->delta ) ); } _this->private->fCounterSnapshot = _this->base.protected->fCounter; From 325d3854e8c02a19ed87d41bd687c97a8310128b Mon Sep 17 00:00:00 2001 From: fuzun Date: Mon, 7 May 2018 21:54:14 +0300 Subject: [PATCH 33/35] Format --- engine/client/strobe/r_strobe_api.c | 14 +-- engine/client/strobe/r_strobe_core.c | 152 +++++++++++++-------------- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 62dea1fcd..43f0f1fe9 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -476,9 +476,9 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) size, "%.2f FPS\n%.2f eFPS\n" "Strobe Method: %s\n" - "Strobe Swap Interval: %d\n" - "Strobe Cooldown Delay: %d\n" - "Elapsed Time: %.2f\n" + "Strobe Swap Interval: %d second(s)\n" + "Strobe Cooldown Delay: %d second(s)\n" + "Elapsed Time: %.2f second(s)\n" "isPhaseInverted = %d\n" "Total Frame Count: %zu\n" "^7(+) Phase Frame Count: %zu\n" @@ -491,20 +491,20 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) "PWM Simulation:\n" " |-> Frequency: %.2f Hz\n" " |-> Duty Cycle: %.2f%%\n" - " |-> Current Phase Shift: +%.4f msec || -%.4f msec\n" + " |-> Current Phase Shift: +%.2f msec || -%.2f msec\n" " |-> Period: %.2f msec\n" "Brightness Reduction:\n" " |-> [^7LINEAR^3] Actual Reduction: %.2f%%\n" " |-> [^7LOG^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" " |-> [^7SQUARE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" " |-> [^7CUBE^3] Realistic Reduction (400 cd/m2 base): %.2f%%\n" - "Difference (+): %s\nDifference (-): %s\nDifference (TOTAL): %s\n" + "Difference (+): %s\nDifference (-): %s\nDifference (Total): %s\n" "Geometric Mean: %.4f\n" "G/A Difference: %.4f\n" "[^7EXPERIMENTAL^3] Badness: %.4f\n" "[^7EXPERIMENTAL^3] Badness x PWM Period: %.4f\n" - "[^7EXPERIMENTAL^3] Badness (Reducted): %.4f\n" - "[^7EXPERIMENTAL^3] Badness (Reducted) x PWM Period: %.4f\n" + "[^7EXPERIMENTAL^3] Badness (Reduced): %.4f\n" + "[^7EXPERIMENTAL^3] Badness (Reduced) x PWM Period: %.4f\n" "Stability:\n" " |-> Standard Deviation: %.3f\n" " |-> Cooldown: %s\n" diff --git a/engine/client/strobe/r_strobe_core.c b/engine/client/strobe/r_strobe_core.c index 3a6e7e02d..e855df574 100644 --- a/engine/client/strobe/r_strobe_core.c +++ b/engine/client/strobe/r_strobe_core.c @@ -25,17 +25,17 @@ See the GNU General Public License for more details. #include "gl_local.h" #include "r_strobe_api_protected_.h" -#ifdef _this -#undef _this +#ifdef this +#undef this #endif -#define _this STROBE_IMPL_THIS( STROBE_CORE ) +#define this STROBE_IMPL_THIS( STROBE_CORE ) struct STROBE_IMPL_STRUCT( STROBE_CORE ) *STROBE_CORE = NULL; #ifdef _DEBUG #define DEVIATION_LIMIT 1.5 #else -#define DEVIATION_LIMIT 0.75 +#define DEVIATION_LIMIT 0.15 #endif #define DEVIATION_SIZE 120 @@ -66,9 +66,9 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) { double delta, delta2; double currentTime = Sys_DoubleTime( ); - delta2 = currentTime - _this->private->recentTime2; - _this->private->recentTime2 = currentTime; - _this->base.protected->elapsedTime = currentTime - _this->private->initialTime; + delta2 = currentTime - this->private->recentTime2; + this->private->recentTime2 = currentTime; + this->base.protected->elapsedTime = currentTime - this->private->initialTime; if ( CL_IsInMenu( ) ) { @@ -76,143 +76,143 @@ static void R_Strobe( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) return; } - if ( _this->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) - _this->base.protected->cdTimer += delta2; - if ( _this->base.protected->fCounter - _this->private->fCounterSnapshot == 1 ) + if ( this->base.protected->cdTimer >= 0.0 && delta2 > 0.0 ) + this->base.protected->cdTimer += delta2; + if ( this->base.protected->fCounter - this->private->fCounterSnapshot == 1 ) { - _this->private->delta[_this->base.protected->fCounter % ARRAYSIZE( _this->private->delta )] = _this->base.Helpers.CurrentFPS(&_this->base); - _this->base.protected->deviation = _this->base.Helpers.StandardDeviation( _this->private->delta, ARRAYSIZE( _this->private->delta ) ); + this->private->delta[this->base.protected->fCounter % ARRAYSIZE( this->private->delta )] = this->base.Helpers.CurrentFPS(&this->base); + this->base.protected->deviation = this->base.Helpers.StandardDeviation( this->private->delta, ARRAYSIZE( this->private->delta ) ); } - _this->private->fCounterSnapshot = _this->base.protected->fCounter; + this->private->fCounterSnapshot = this->base.protected->fCounter; if ( StrobeAPI.r_strobe_cooldown->integer > 0 ) { - if ( ( _this->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && _this->base.protected->cdTriggered == true ) + if ( ( this->base.protected->cdTimer > (double)abs( StrobeAPI.r_strobe_cooldown->integer ) ) && this->base.protected->cdTriggered == true ) { - _this->base.protected->cdTriggered = false; - _this->base.protected->cdTimer = -1.0; + this->base.protected->cdTriggered = false; + this->base.protected->cdTimer = -1.0; } - if ( _this->base.protected->fCounter > ARRAYSIZE( _this->private->delta ) ) + if ( this->base.protected->fCounter > ARRAYSIZE( this->private->delta ) ) { - if ( _this->base.protected->deviation > DEVIATION_LIMIT ) + if ( this->base.protected->deviation > DEVIATION_LIMIT ) { - _this->base.protected->cdTriggered = true; - _this->base.protected->cdTimer = 0.0; + this->base.protected->cdTriggered = true; + this->base.protected->cdTimer = 0.0; } } } else { - _this->base.protected->cdTriggered = false; + this->base.protected->cdTriggered = false; } - if ( ( ( _this->private->strobeInterval != StrobeAPI.r_strobe->integer ) && ( _this->private->strobeInterval ) ) || + if ( ( ( this->private->strobeInterval != StrobeAPI.r_strobe->integer ) && ( this->private->strobeInterval ) ) || /*((swapInterval != r_strobe_swapinterval->integer) && (swapInterval != 0)) || */ - _this->base.protected->fCounter == UINT_MAX ) + this->base.protected->fCounter == UINT_MAX ) { STROBE_IMPL_EXPORTEDFUNC_reinit( STROBE_CORE )( *(void ***)&_STROBE_IMPL_THIS ); - R_Strobe( &_this ); + R_Strobe( &this ); } - _this->private->strobeInterval = StrobeAPI.r_strobe->integer; - _this->private->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; + this->private->strobeInterval = StrobeAPI.r_strobe->integer; + this->private->swapInterval = StrobeAPI.r_strobe_swapinterval->integer; - if ( ( _this->private->strobeInterval == 0 ) || - ( ( gl_swapInterval->integer == 0 ) && ( _this->private->strobeInterval ) ) ) + if ( ( this->private->strobeInterval == 0 ) || + ( ( gl_swapInterval->integer == 0 ) && ( this->private->strobeInterval ) ) ) { if ( !gl_swapInterval->integer ) MsgDev( D_WARN, "Strobing requires V-SYNC not being turned off! (gl_swapInterval != 0) \n" ); - if ( _this->private->strobeInterval ) // If v-sync is off, turn off strobing + if ( this->private->strobeInterval ) // If v-sync is off, turn off strobing { Cvar_Set( "r_strobe", "0" ); } - _this->base.protected->fCounter = 0; + this->base.protected->fCounter = 0; R_Set2DMode( false ); return; } - if ( ( _this->base.protected->fCounter % 2 ) == 0 ) + if ( ( this->base.protected->fCounter % 2 ) == 0 ) { - ++_this->base.protected->pCounter; - _this->base.protected->frameInfo |= PHASE_POSITIVE; + ++this->base.protected->pCounter; + this->base.protected->frameInfo |= PHASE_POSITIVE; } else { - ++_this->base.protected->nCounter; - _this->base.protected->frameInfo &= ~PHASE_POSITIVE; + ++this->base.protected->nCounter; + this->base.protected->frameInfo &= ~PHASE_POSITIVE; } - if ( _this->private->swapInterval < 0 ) - _this->private->swapInterval = abs( _this->private->swapInterval ); + if ( this->private->swapInterval < 0 ) + this->private->swapInterval = abs( this->private->swapInterval ); - if ( ( _this->private->swapInterval ) && ( _this->private->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended + if ( ( this->private->swapInterval ) && ( this->private->strobeInterval % 2 ) ) // Swapping not enabled for even intervals as it is neither necessary nor works as intended { - delta = currentTime - _this->private->recentTime; // New Currenttime for _delta ? - if ( ( delta >= (double)( _this->private->swapInterval ) ) && ( delta < (double)( 2 * _this->private->swapInterval ) ) ) // Basic timer + delta = currentTime - this->private->recentTime; // New Currenttime for _delta ? + if ( ( delta >= (double)( this->private->swapInterval ) ) && ( delta < (double)( 2 * this->private->swapInterval ) ) ) // Basic timer { - _this->base.protected->frameInfo |= PHASE_INVERTED; + this->base.protected->frameInfo |= PHASE_INVERTED; } - else if ( delta < (double)( _this->private->swapInterval ) ) + else if ( delta < (double)( this->private->swapInterval ) ) { - _this->base.protected->frameInfo &= ~PHASE_INVERTED; + this->base.protected->frameInfo &= ~PHASE_INVERTED; } else //if (delta >= (double)(2 * swapInterval)) { - _this->private->recentTime = currentTime; + this->private->recentTime = currentTime; } } - switch ( _this->base.protected->frameInfo & ( PHASE_POSITIVE | PHASE_INVERTED ) ) + switch ( this->base.protected->frameInfo & ( PHASE_POSITIVE | PHASE_INVERTED ) ) { case ( PHASE_POSITIVE | PHASE_INVERTED ): - if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( ( abs( this->private->strobeInterval ) % 2 ) == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == ( abs( this->private->strobeInterval ) / 2 ) ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else - _this->base.protected->frameInfo &= ~FRAME_RENDER; + this->base.protected->frameInfo &= ~FRAME_RENDER; break; case ( PHASE_POSITIVE & ~PHASE_INVERTED ): - if ( abs( _this->private->strobeInterval ) % 2 == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( abs( this->private->strobeInterval ) % 2 == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( _this->private->strobeInterval ) == 1 ) - _this->base.protected->frameInfo |= FRAME_RENDER; + if ( abs( this->private->strobeInterval ) == 1 ) + this->base.protected->frameInfo |= FRAME_RENDER; else - _this->base.protected->frameInfo = ( ( ( _this->base.protected->pCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd + this->base.protected->frameInfo = ( ( ( this->base.protected->pCounter - 1 ) % ( ( abs( this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; case ( ~PHASE_POSITIVE & PHASE_INVERTED ): - if ( abs( _this->private->strobeInterval ) % 2 == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( abs( this->private->strobeInterval ) % 2 == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else { - if ( abs( _this->private->strobeInterval ) == 1 ) - _this->base.protected->frameInfo |= FRAME_RENDER; + if ( abs( this->private->strobeInterval ) == 1 ) + this->base.protected->frameInfo |= FRAME_RENDER; else - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( ( abs( _this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //odd + this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( ( abs( this->private->strobeInterval ) + 1 ) / 2 ) ) == 0 ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //odd } break; case 0: - if ( ( abs( _this->private->strobeInterval ) % 2 ) == 0 ) - _this->base.protected->frameInfo = ( ( ( _this->base.protected->nCounter - 1 ) % ( abs( _this->private->strobeInterval ) + 1 ) ) == ( abs( _this->private->strobeInterval ) / 2 ) ) ? _this->base.protected->frameInfo | FRAME_RENDER : _this->base.protected->frameInfo & ~FRAME_RENDER; //even + if ( ( abs( this->private->strobeInterval ) % 2 ) == 0 ) + this->base.protected->frameInfo = ( ( ( this->base.protected->nCounter - 1 ) % ( abs( this->private->strobeInterval ) + 1 ) ) == ( abs( this->private->strobeInterval ) / 2 ) ) ? this->base.protected->frameInfo | FRAME_RENDER : this->base.protected->frameInfo & ~FRAME_RENDER; //even else - _this->base.protected->frameInfo &= ~FRAME_RENDER; + this->base.protected->frameInfo &= ~FRAME_RENDER; break; default: - _this->base.protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); + this->base.protected->frameInfo = ( PHASE_POSITIVE | FRAME_RENDER ); } - if ( _this->private->strobeInterval < 0 ) - _this->base.protected->frameInfo ^= FRAME_RENDER; + if ( this->private->strobeInterval < 0 ) + this->base.protected->frameInfo ^= FRAME_RENDER; - _this->base.ProcessFrame( &_this->base ); + this->base.ProcessFrame( &this->base ); } _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) @@ -241,26 +241,26 @@ _inline void debugDrawer( STROBE_IMPL_THIS_PARAM( STROBE_CORE ) ) if ( strobeDebug ) { newtime = Sys_DoubleTime( ); - if ( newtime >= _this->private->nexttime ) + if ( newtime >= this->private->nexttime ) { - _this->base.Helpers.GenerateDebugStatistics( &_this->base, _this->private->debugStr, ARRAYSIZE( _this->private->debugStr ) ); - _this->private->lasttime = newtime; - _this->private->nexttime = max( _this->private->nexttime + 0.15, _this->private->lasttime - 0.15 ); // Make this configurable + this->base.Helpers.GenerateDebugStatistics( &this->base, this->private->debugStr, ARRAYSIZE( this->private->debugStr ) ); + this->private->lasttime = newtime; + this->private->nexttime = max( this->private->nexttime + 0.15, this->private->lasttime - 0.15 ); // Make this configurable } } else if ( cl_showfps->integer ) { - Q_snprintf( _this->private->debugStr, sizeof( _this->private->debugStr ), "%3d eFPS", (int)round( _this->base.Helpers.effectiveFPS( &_this->base ) ) ); + Q_snprintf( this->private->debugStr, sizeof( this->private->debugStr ), "%3d eFPS", (int)round( this->base.Helpers.effectiveFPS( &this->base ) ) ); } MakeRGBA( color, 255, 255, 255, 255 ); - Con_DrawStringLen( _this->private->debugStr, &fixer, &offsetY ); + Con_DrawStringLen( this->private->debugStr, &fixer, &offsetY ); if ( strobeDebug ) - Con_DrawString( scr_width->integer - _this->private->offsetX - 50, 4, _this->private->debugStr, color ); + Con_DrawString( scr_width->integer - this->private->offsetX - 50, 4, this->private->debugStr, color ); else - Con_DrawString( scr_width->integer - _this->private->offsetX - 2, offsetY + 8, _this->private->debugStr, color ); - if ( abs( fixer - _this->private->offsetX ) > 50 || _this->private->offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! - _this->private->offsetX = fixer; + Con_DrawString( scr_width->integer - this->private->offsetX - 2, offsetY + 8, this->private->debugStr, color ); + if ( abs( fixer - this->private->offsetX ) > 50 || this->private->offsetX == 0 ) // 50 is for 1080p ! Needs to be dynamic ! + this->private->offsetX = fixer; } void STROBE_IMPL_EXPORTEDFUNC_constructor( STROBE_CORE )( void **STROBE_CORE ) @@ -311,6 +311,6 @@ void STROBE_IMPL_EXPORTEDFUNC_main( STROBE_CORE )( void **STROBE_CORE ) } } -#undef _this +#undef this #endif From 419422efcd90e6edb5fe2066c66b032f268cf6ad Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 30 Jun 2018 17:15:55 +0300 Subject: [PATCH 34/35] Safer alpha value for transitions --- engine/client/strobe/r_strobe_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index 43f0f1fe9..f38daaece 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -587,7 +587,7 @@ _inline void ProcessFrame( StrobeAPI_t *self ) if (self->private->firstInverted) { R_Set2DMode(false); - self->GenerateBlackFrame(0.5f); + self->GenerateBlackFrame(0.8f); } phase = self->Helpers.isPhaseInverted(self); From 54aeb8326c95d439fe605df1649815fc64e48d29 Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 30 Jun 2018 17:29:35 +0300 Subject: [PATCH 35/35] C89 compatibility --- engine/client/strobe/r_strobe_api.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/client/strobe/r_strobe_api.c b/engine/client/strobe/r_strobe_api.c index f38daaece..0e124f2b7 100644 --- a/engine/client/strobe/r_strobe_api.c +++ b/engine/client/strobe/r_strobe_api.c @@ -465,7 +465,8 @@ _inline void GenerateDebugStatistics( StrobeAPI_t *self, char *src, int size ) if (!strlen(self->private->strobemethod)) { Q_snprintf(self->private->strobemethod, sizeof(self->private->strobemethod), (strobeMethod > 0 ? "%d [NORMAL" : "%d [BLACK"), strobeMethod); - for (int k = 1; k <= abs(strobeMethod); ++k) + int _k; + for (_k = 1; _k <= abs(strobeMethod); ++_k) { Q_strcat(self->private->strobemethod, (strobeMethod > 0 ? " - BLACK" : " - NORMAL")); }