Skip to content

StrobeAPI Implementation #353

Merged
merged 48 commits into from
Jul 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5c14dfa
Strobe Implementation v2
fuzun Feb 10, 2018
5a01798
Brightness reduction calculations
fuzun Feb 10, 2018
511a8fe
PWM Simulation (Debug Mode)
fuzun Feb 10, 2018
faa97ce
Sync with 8578012e17982a0b7e37b6f2a7c20f64ae48bc22
fuzun Feb 10, 2018
1d58b1e
Revert "Sync with 8578012e17982a0b7e37b6f2a7c20f64ae48bc22"
fuzun Feb 10, 2018
f6a61e8
Sync with 8578012e17982a0b7e37b6f2a7c20f64ae48bc22
fuzun Feb 10, 2018
7739e2d
Some typo correction
fuzun Feb 10, 2018
9d01da8
Refactor & PWM Simulation Updates
fuzun Feb 17, 2018
03a3b9e
Merge branch 'master' of https://github.com/FWGS/xash3d into FWGS-master
fuzun Feb 17, 2018
c473483
Merge branch 'FWGS-master' into strobe-support
fuzun Feb 17, 2018
48782be
MainUI Sync
fuzun Feb 17, 2018
9a89b57
Implemented Stability Checker & Refactoring
fuzun Feb 18, 2018
b2fe83e
Complete refactor due to OOP implementation
fuzun Mar 3, 2018
425f426
Merge branch 'master' of https://github.com/FWGS/xash3d into FWGS-master
fuzun Mar 3, 2018
6a4683a
Merge branch 'FWGS-master' into strobe-support
fuzun Mar 3, 2018
f449716
Try to make gcc happy
fuzun Mar 3, 2018
d33d3d9
Try to make gcc happy #2
fuzun Mar 3, 2018
427c135
Try to make gcc happy #3
fuzun Mar 3, 2018
ebc5b49
Try to make gcc happy #4
fuzun Mar 3, 2018
4947d1b
Merge branch 'master' into strobe-support
fuzun Mar 9, 2018
fa412c3
Refactored
fuzun Mar 9, 2018
6c9e4da
Fix non consistent draw of debug drawer
fuzun Mar 9, 2018
ec2c7b9
gcc fix
fuzun Mar 9, 2018
de7bbd9
Better OOP & Bug Fix
fuzun Mar 27, 2018
e81370a
GCC Fix ?
fuzun Mar 27, 2018
f46692d
Revert "GCC Fix ?"
fuzun Mar 27, 2018
2a43c7d
GCC Fix ?
fuzun Mar 28, 2018
4db52f1
GCC Fix #2 ?
fuzun Mar 28, 2018
465c428
Merge pull request #3 from FWGS/master
fuzun Mar 29, 2018
bb5d065
Record elapsed time & small fixes
fuzun Mar 31, 2018
1c1be72
Reduced macros
fuzun Mar 31, 2018
2bcc54f
Fixes & Better oop
fuzun Apr 6, 2018
f1ffa67
Merge pull request #4 from FWGS/master
fuzun Apr 6, 2018
72642be
Merge branch 'strobe-support' of https://github.com/fuzun/xash3d into…
fuzun Apr 6, 2018
84759c7
Adjusted constness & format
fuzun Apr 6, 2018
41524d7
Format
fuzun Apr 6, 2018
472b8c0
Merge branch 'master' into strobe-support
fuzun Apr 13, 2018
8944808
Revert "Adjusted constness & format"
fuzun May 5, 2018
1ccf81a
Merge branch 'strobe-support' of https://github.com/fuzun/xash3d into…
fuzun May 5, 2018
b590a5b
Better transition for r_strobe = 1 or -1
fuzun May 7, 2018
c372b1c
Better statistics & transition fix
fuzun May 7, 2018
2592dd9
Change in stability measurement
fuzun May 7, 2018
325d385
Format
fuzun May 7, 2018
254e43a
Merge pull request #5 from FWGS/master
fuzun May 7, 2018
419422e
Safer alpha value for transitions
fuzun Jun 30, 2018
620d12b
Merge pull request #6 from FWGS/master
fuzun Jun 30, 2018
3d5d0cb
Merge branch 'strobe-support' of https://github.com/fuzun/xash3d into…
fuzun Jun 30, 2018
54aeb83
C89 compatibility
fuzun Jun 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/wrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ typedef struct wrect_s
int left, right, top, bottom;
} wrect_t;

#endif//WRECT_H
typedef struct rectf_s
{
float x, y, w, h;
} rectf_t;

#endif //WRECT_H
2 changes: 2 additions & 0 deletions engine/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
86 changes: 37 additions & 49 deletions engine/client/cl_scrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,71 +49,66 @@ SCR_DrawFPS
*/
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;
int strobeInterval = r_strobe->integer; // cvar: r_strobe
int eFPS; // Effective FPS (strobing effect)

if( cls.state != ca_active ) return;
if( !cl_showfps->integer || cl.background ) return;
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 )
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));
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;

if( strobeInterval > 0 )
{
eFPS = (int)(( curfps ) / ( strobeInterval + 1 ));
}
else if( strobeInterval < 0 )
{
strobeInterval = abs( strobeInterval );
eFPS = (int)(( curfps * strobeInterval ) / ( strobeInterval + 1 ));
}
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 );
Expand All @@ -123,21 +118,14 @@ void SCR_DrawFPS( void )
break;
case 1:
default:
if( !strobeInterval )
{
Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i fps", curfps );
}
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 );
}

Con_DrawStringLen( fpsstring, &offset, NULL );
Con_DrawString( scr_width->integer - offset - 5, 4, fpsstring, color );
Con_DrawString( scr_width->integer - offset - 2, 4, fpsstring, color );
}

/*
Expand Down
12 changes: 12 additions & 0 deletions engine/client/cl_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -417,6 +421,14 @@ void V_PostRender( void )
SCR_RSpeeds();
SCR_NetSpeeds();
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

SCR_DrawPos();
SV_DrawOrthoTriangles();
CL_DrawDemoRecording();
Expand Down
2 changes: 1 addition & 1 deletion engine/client/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions engine/client/gl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ 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
Expand Down Expand Up @@ -703,7 +702,6 @@ extern convar_t *r_vbo;
extern convar_t *r_vbo_dlightmode;

extern convar_t *r_bump;
extern convar_t *r_strobe;
extern convar_t *r_underwater_distortion;

extern convar_t *mp_decals;
Expand Down
96 changes: 10 additions & 86 deletions engine/client/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1326,99 +1328,21 @@ void R_RenderFrame( const ref_params_t *fd, qboolean drawWorld )
GL_BackendEndFrame();
}

_inline void GL_InsertBlackFrame( void )
{
// No strobing on the console
if( CL_IsInConsole() )
{
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 );
}
}

/*
===============
R_Strobe

TODO: Consider vsync timings and do not render the supposed black frame at all.
===============
*/
void R_Strobe( void )
{
static int sCounter = 0;
int getInterval = r_strobe->integer; // Check through modified tag first?

if( CL_IsInMenu() )
{
R_Set2DMode(false);
return;
}

if( !getInterval || ( !gl_swapInterval->integer && getInterval ) )
{
if( getInterval ) //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" );
}
else if( sCounter )
sCounter = 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( sCounter < getInterval )
{
GL_InsertBlackFrame();
++sCounter;
}
else
{
sCounter = 0;
R_Set2DMode( false );
}
}
// 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
{
getInterval = abs( getInterval );
if( sCounter < getInterval )
{
++sCounter;
R_Set2DMode( false );
}
else
{
GL_InsertBlackFrame();
sCounter = 0;
}
}
}

/*
===============
R_EndFrame
===============
*/
void R_EndFrame( void )
{
R_Strobe();

#ifdef STROBE_ENABLED
// StrobeAPI.Invoker( STROBE_INVOKE(STROBE_TEMPLATE) );
StrobeAPI.Invoker( STROBE_INVOKE(STROBE_CORE) );
#else
// flush any remaining 2D bits
R_Set2DMode( false );
#endif

#ifdef XASH_SDL
SDL_GL_SwapWindow( host.hWnd );
#elif defined __ANDROID__ // For direct android backend
Expand Down
Loading