Skip to content

Commit

Permalink
Pointerise GetParams, net a 7% gameplay speed boost.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwidghet committed Sep 8, 2016
1 parent 427f9f0 commit 563eb77
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/GameLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void CheckGameLoopTimerSkips( float fDeltaTime )
/* If vsync is on, and we have a solid framerate (vsync == refresh and we've
* sustained this for at least one second), we expect the amount of time for
* the last frame to be 1/FPS. */
if( iThisFPS != DISPLAY->GetActualVideoModeParams().rate || iThisFPS != iLastFPS )
if( iThisFPS != (*DISPLAY->GetActualVideoModeParams()).rate || iThisFPS != iLastFPS )
{
iLastFPS = iThisFPS;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/GameSoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ float GameSoundManager::GetFrameTimingAdjustment( float fDeltaTime )
static int iLastFPS = 0;
int iThisFPS = DISPLAY->GetFPS();

if( iThisFPS != DISPLAY->GetActualVideoModeParams().rate || iThisFPS != iLastFPS )
if( iThisFPS != (*DISPLAY->GetActualVideoModeParams()).rate || iThisFPS != iLastFPS )
{
iLastFPS = iThisFPS;
return 0;
Expand Down
16 changes: 8 additions & 8 deletions src/RageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ void RageDisplay::CameraPopMatrix()
* post-multiplied. */
void RageDisplay::LoadLookAt( float fFOV, const RageVector3 &Eye, const RageVector3 &At, const RageVector3 &Up )
{
float fAspect = GetActualVideoModeParams().fDisplayAspectRatio;
float fAspect = (*GetActualVideoModeParams()).fDisplayAspectRatio;
g_ProjectionStack.LoadMatrix( GetPerspectiveMatrix(fFOV, fAspect, 1, 1000) );

// Flip the Y coordinate, so positive numbers go down.
Expand Down Expand Up @@ -711,11 +711,11 @@ void RageDisplay::ChangeCentering( int iTranslateX, int iTranslateY, int iAddWid
UpdateCentering();
}

RageMatrix RageDisplay::GetCenteringMatrix( float fTranslateX, float fTranslateY, float fAddWidth, float fAddHeight ) const
RageMatrix RageDisplay::GetCenteringMatrix( float fTranslateX, float fTranslateY, float fAddWidth, float fAddHeight )
{
// in screen space, left edge = -1, right edge = 1, bottom edge = -1. top edge = 1
float fWidth = (float) GetActualVideoModeParams().width;
float fHeight = (float) GetActualVideoModeParams().height;
float fWidth = (float) (*GetActualVideoModeParams()).width;
float fHeight = (float) (*GetActualVideoModeParams()).height;
float fPercentShiftX = SCALE( fTranslateX, 0, fWidth, 0, +2.0f );
float fPercentShiftY = SCALE( fTranslateY, 0, fHeight, 0, -2.0f );
float fPercentScaleX = SCALE( fAddWidth, 0, fWidth, 1.0f, 2.0f );
Expand Down Expand Up @@ -756,11 +756,11 @@ bool RageDisplay::SaveScreenshot( RString sPath, GraphicsFileFormat format )
if( format != SAVE_LOSSLESS && format != SAVE_LOSSLESS_SENSIBLE )
{
// Maintain the DAR.
ASSERT( GetActualVideoModeParams().fDisplayAspectRatio > 0 );
ASSERT( (*GetActualVideoModeParams()).fDisplayAspectRatio > 0 );
int iHeight = 480;
// This used to be lrintf. However, lrintf causes odd resolutions like
// 639x480 (4:3) and 853x480 (16:9). ceilf gives correct values. -aj
int iWidth = static_cast<int>(ceilf( iHeight * GetActualVideoModeParams().fDisplayAspectRatio ));
int iWidth = static_cast<int>(ceilf( iHeight * (*GetActualVideoModeParams()).fDisplayAspectRatio ));
timer.Touch();
RageSurfaceUtils::Zoom( surface, iWidth, iHeight );
// LOG->Trace( "%ix%i -> %ix%i (%.3f) in %f seconds", surface->w, surface->h, iWidth, iHeight, GetActualVideoModeParams().fDisplayAspectRatio, timer.GetDeltaTime() );
Expand Down Expand Up @@ -996,14 +996,14 @@ class LunaRageDisplay: public Luna<RageDisplay>
public:
static int GetDisplayWidth( T* p, lua_State *L )
{
VideoModeParams params = p->GetActualVideoModeParams();
VideoModeParams params = *p->GetActualVideoModeParams();
LuaHelpers::Push( L, params.width );
return 1;
}

static int GetDisplayHeight( T* p, lua_State *L )
{
VideoModeParams params = p->GetActualVideoModeParams();
VideoModeParams params = *p->GetActualVideoModeParams();
LuaHelpers::Push( L, params.height );
return 1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/RageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ class RageDisplay

virtual bool BeginFrame();
virtual void EndFrame();
virtual VideoModeParams GetActualVideoModeParams() const = 0;
bool IsWindowed() const { return this->GetActualVideoModeParams().windowed; }
virtual VideoModeParams* GetActualVideoModeParams() = 0;
bool IsWindowed() { return (*GetActualVideoModeParams()).windowed; }

virtual void SetBlendMode( BlendMode mode ) = 0;

Expand Down Expand Up @@ -395,7 +395,7 @@ class RageDisplay
virtual RageMatrix GetFrustumMatrix( float l, float r, float b, float t, float zn, float zf );

// Matrix that adjusts position and scale of image on the screen
RageMatrix GetCenteringMatrix( float fTranslateX, float fTranslateY, float fAddWidth, float fAddHeight ) const;
RageMatrix GetCenteringMatrix( float fTranslateX, float fTranslateY, float fAddWidth, float fAddHeight );
void UpdateCentering();

// Called by the RageDisplay derivitives
Expand Down
7 changes: 3 additions & 4 deletions src/RageDisplay_D3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ void RageDisplay_D3D::EndFrame()
{
g_pd3dDevice->EndScene();

FrameLimitBeforeVsync( GetActualVideoModeParams().rate );
FrameLimitBeforeVsync( (*GetActualVideoModeParams()).rate );
g_pd3dDevice->Present( 0, 0, 0, 0 );
FrameLimitAfterVsync();

Expand Down Expand Up @@ -673,10 +673,9 @@ RageSurface* RageDisplay_D3D::CreateScreenshot()
return result;
}

VideoModeParams RageDisplay_D3D::GetActualVideoModeParams() const
VideoModeParams* RageDisplay_D3D::GetActualVideoModeParams()
{
VideoModeParams p = GraphicsWindow::GetParams();
return p;
return GraphicsWindow::GetParams();
}

void RageDisplay_D3D::SendCurrentMatrices()
Expand Down
2 changes: 1 addition & 1 deletion src/RageDisplay_D3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RageDisplay_D3D: public RageDisplay

bool BeginFrame();
void EndFrame();
VideoModeParams GetActualVideoModeParams() const;
VideoModeParams* GetActualVideoModeParams();
void SetBlendMode( BlendMode mode );
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsThreadedRendering();
Expand Down
2 changes: 1 addition & 1 deletion src/RageDisplay_Null.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RageDisplay_Null: public RageDisplay

bool BeginFrame() { return true; }
void EndFrame();
VideoModeParams GetActualVideoModeParams() const { return m_Params; }
VideoModeParams* GetActualVideoModeParams() { return (VideoModeParams*)&m_Params; }
void SetBlendMode( BlendMode ) { }
bool SupportsTextureFormat( RagePixelFormat, bool /* realtime */ =false ) { return true; }
bool SupportsPerVertexMatrixScale() { return false; }
Expand Down
28 changes: 14 additions & 14 deletions src/RageDisplay_OGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,8 @@ bool RageDisplay_Legacy::BeginFrame()
{
/* We do this in here, rather than ResolutionChanged, or we won't update the
* viewport for the concurrent rendering context. */
int fWidth = g_pWind->GetActualVideoModeParams().width;
int fHeight = g_pWind->GetActualVideoModeParams().height;
int fWidth = (*g_pWind->GetActualVideoModeParams()).width;
int fHeight = (*g_pWind->GetActualVideoModeParams()).height;

glViewport( 0, 0, fWidth, fHeight );

Expand All @@ -798,7 +798,7 @@ bool RageDisplay_Legacy::BeginFrame()

void RageDisplay_Legacy::EndFrame()
{
FrameLimitBeforeVsync( g_pWind->GetActualVideoModeParams().rate );
FrameLimitBeforeVsync( (*g_pWind->GetActualVideoModeParams()).rate );
g_pWind->SwapBuffers();
FrameLimitAfterVsync();

Expand All @@ -820,8 +820,8 @@ void RageDisplay_Legacy::EndFrame()

RageSurface* RageDisplay_Legacy::CreateScreenshot()
{
int width = g_pWind->GetActualVideoModeParams().width;
int height = g_pWind->GetActualVideoModeParams().height;
int width = (*g_pWind->GetActualVideoModeParams()).width;
int height = (*g_pWind->GetActualVideoModeParams()).height;

const RagePixelFormatDesc &desc = PIXEL_FORMAT_DESC[RagePixelFormat_RGBA8];
RageSurface *image = CreateSurface( width, height, desc.bpp,
Expand All @@ -832,7 +832,7 @@ RageSurface* RageDisplay_Legacy::CreateScreenshot()
glReadBuffer( GL_FRONT );
DebugAssertNoGLError();

glReadPixels( 0, 0, g_pWind->GetActualVideoModeParams().width, g_pWind->GetActualVideoModeParams().height, GL_RGBA,
glReadPixels( 0, 0, (*g_pWind->GetActualVideoModeParams()).width, (*g_pWind->GetActualVideoModeParams()).height, GL_RGBA,
GL_UNSIGNED_BYTE, image->pixels );
DebugAssertNoGLError();

Expand Down Expand Up @@ -865,7 +865,7 @@ RageSurface *RageDisplay_Legacy::GetTexture( unsigned iTexture )
return pImage;
}

VideoModeParams RageDisplay_Legacy::GetActualVideoModeParams() const
VideoModeParams* RageDisplay_Legacy::GetActualVideoModeParams()
{
return g_pWind->GetActualVideoModeParams();
}
Expand Down Expand Up @@ -1495,7 +1495,7 @@ void RageDisplay_Legacy::DrawLineStripInternal( const RageSpriteVertex v[], int
{
TurnOffHardwareVBO();

if (!GetActualVideoModeParams().bSmoothLines)
if (!(*GetActualVideoModeParams()).bSmoothLines)
{
/* Fall back on the generic polygon-based line strip. */
RageDisplay::DrawLineStripInternal(v, iNumVerts, fLineWidth );
Expand All @@ -1517,8 +1517,8 @@ void RageDisplay_Legacy::DrawLineStripInternal( const RageSpriteVertex v[], int
const RageMatrix* pMat = GetProjectionTop();
float fW = 2 / pMat->m[0][0];
float fH = -2 / pMat->m[1][1];
float fWidthVal = float(g_pWind->GetActualVideoModeParams().width) / fW;
float fHeightVal = float(g_pWind->GetActualVideoModeParams().height) / fH;
float fWidthVal = (float)(*g_pWind->GetActualVideoModeParams()).width / fW;
float fHeightVal = (float)(*g_pWind->GetActualVideoModeParams()).height / fH;
fLineWidth *= (fWidthVal + fHeightVal) / 2;
}

Expand Down Expand Up @@ -1667,7 +1667,7 @@ void RageDisplay_Legacy::SetTextureFiltering( TextureUnit tu, bool b )
if (iWidth1 > 1 && iWidth2 != 0)
{
/* Mipmaps are enabled. */
if (g_pWind->GetActualVideoModeParams().bTrilinearFiltering)
if ((*g_pWind->GetActualVideoModeParams()).bTrilinearFiltering)
iMinFilter = GL_LINEAR_MIPMAP_LINEAR;
else
iMinFilter = GL_LINEAR_MIPMAP_NEAREST;
Expand Down Expand Up @@ -2155,7 +2155,7 @@ unsigned RageDisplay_Legacy::CreateTexture(

glBindTexture( GL_TEXTURE_2D, iTexHandle );

if (g_pWind->GetActualVideoModeParams().bAnisotropicFiltering &&
if ((*g_pWind->GetActualVideoModeParams()).bAnisotropicFiltering &&
GLEW_EXT_texture_filter_anisotropic )
{
GLfloat fLargestSupportedAnisotropy;
Expand Down Expand Up @@ -2525,8 +2525,8 @@ void RageDisplay_Legacy::SetRenderTarget( unsigned iTexture, bool bPreserveTextu
DISPLAY->CameraPopMatrix();

/* Reset the viewport. */
int fWidth = g_pWind->GetActualVideoModeParams().width;
int fHeight = g_pWind->GetActualVideoModeParams().height;
int fWidth = (*g_pWind->GetActualVideoModeParams()).width;
int fHeight = (*g_pWind->GetActualVideoModeParams()).height;
glViewport( 0, 0, fWidth, fHeight );

if (g_pCurrentRenderTarget)
Expand Down
2 changes: 1 addition & 1 deletion src/RageDisplay_OGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RageDisplay_Legacy: public RageDisplay

bool BeginFrame();
void EndFrame();
VideoModeParams GetActualVideoModeParams() const;
VideoModeParams* GetActualVideoModeParams();
void SetBlendMode( BlendMode mode );
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsPerVertexMatrixScale();
Expand Down
4 changes: 2 additions & 2 deletions src/StepMania.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static LocalizedString NO_SMOOTH_LINES ("StepMania","NoSmoothLines");

static RString GetActualGraphicOptionsString()
{
const VideoModeParams &params = DISPLAY->GetActualVideoModeParams();
VideoModeParams &params = (*DISPLAY->GetActualVideoModeParams());
RString sFormat = "%s %s %dx%d %d "+COLOR.GetValue()+" %d "+TEXTURE.GetValue()+" %dHz %s %s";
RString sLog = ssprintf( sFormat,
DISPLAY->GetApiDescription().c_str(),
Expand All @@ -145,7 +145,7 @@ static void StoreActualGraphicOptions()
/* Store the settings that RageDisplay was actually able to use so that
* we don't go through the process of auto-detecting a usable video mode
* every time. */
const VideoModeParams &params = DISPLAY->GetActualVideoModeParams();
VideoModeParams &params = (*DISPLAY->GetActualVideoModeParams());
PREFSMAN->m_bWindowed.Set( params.windowed );

/* If we're windowed, we may have tweaked the width based on the aspect ratio.
Expand Down
2 changes: 1 addition & 1 deletion src/arch/LowLevelWindow/LowLevelWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LowLevelWindow
virtual void SwapBuffers() = 0;
virtual void Update() { }

virtual const VideoModeParams &GetActualVideoModeParams() const = 0;
virtual VideoModeParams* GetActualVideoModeParams() = 0;

virtual bool SupportsRenderToTexture() const { return false; }
virtual RenderTarget *CreateRenderTarget() { return NULL; }
Expand Down
2 changes: 1 addition & 1 deletion src/arch/LowLevelWindow/LowLevelWindow_MacOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LowLevelWindow_MacOSX : public LowLevelWindow
void SwapBuffers();
void Update();

const VideoModeParams &GetActualVideoModeParams() const { return m_CurrentParams; }
VideoModeParams* GetActualVideoModeParams() { return m_CurrentParams; }

bool SupportsRenderToTexture() const { return true; }
RenderTarget *CreateRenderTarget();
Expand Down
2 changes: 1 addition & 1 deletion src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void LowLevelWindow_Win32::Update()
GraphicsWindow::Update();
}

const VideoModeParams &LowLevelWindow_Win32::GetActualVideoModeParams() const
VideoModeParams* LowLevelWindow_Win32::GetActualVideoModeParams()
{
return GraphicsWindow::GetParams();
}
Expand Down
2 changes: 1 addition & 1 deletion src/arch/LowLevelWindow/LowLevelWindow_Win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LowLevelWindow_Win32: public LowLevelWindow
virtual bool SupportsRenderToTexture() const { return true; }
virtual RenderTarget *CreateRenderTarget();

const VideoModeParams &GetActualVideoModeParams() const;
VideoModeParams* GetActualVideoModeParams();
};

#ifdef ARCH_LOW_LEVEL_WINDOW
Expand Down
2 changes: 1 addition & 1 deletion src/arch/LowLevelWindow/LowLevelWindow_X11.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LowLevelWindow_X11 : public LowLevelWindow
bool IsSoftwareRenderer( RString &sError );
void SwapBuffers();

const VideoModeParams &GetActualVideoModeParams() const { return CurrentParams; }
VideoModeParams* GetActualVideoModeParams() { return CurrentParams; }

void GetDisplayResolutions( DisplayResolutions &out ) const;

Expand Down
4 changes: 2 additions & 2 deletions src/archutils/Win32/GraphicsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ HDC GraphicsWindow::GetHDC()
return g_HDC;
}

const VideoModeParams &GraphicsWindow::GetParams()
VideoModeParams* GraphicsWindow::GetParams()
{
return g_CurrentParams;
return &g_CurrentParams;
}

void GraphicsWindow::Update()
Expand Down
2 changes: 1 addition & 1 deletion src/archutils/Win32/GraphicsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace GraphicsWindow

void GetDisplayResolutions( DisplayResolutions &out );

const VideoModeParams &GetParams();
VideoModeParams* GetParams();
HDC GetHDC();
void Update();

Expand Down

0 comments on commit 563eb77

Please sign in to comment.