From 563eb77c3d5f87a4519b6bcede732420725a2b23 Mon Sep 17 00:00:00 2001 From: xwidghet Date: Thu, 8 Sep 2016 01:39:08 -0700 Subject: [PATCH] Pointerise GetParams, net a 7% gameplay speed boost. --- src/GameLoop.cpp | 2 +- src/GameSoundManager.cpp | 2 +- src/RageDisplay.cpp | 16 +++++------ src/RageDisplay.h | 6 ++-- src/RageDisplay_D3D.cpp | 7 ++--- src/RageDisplay_D3D.h | 2 +- src/RageDisplay_Null.h | 2 +- src/RageDisplay_OGL.cpp | 28 +++++++++---------- src/RageDisplay_OGL.h | 2 +- src/StepMania.cpp | 4 +-- src/arch/LowLevelWindow/LowLevelWindow.h | 2 +- .../LowLevelWindow/LowLevelWindow_MacOSX.h | 2 +- .../LowLevelWindow/LowLevelWindow_Win32.cpp | 2 +- .../LowLevelWindow/LowLevelWindow_Win32.h | 2 +- src/arch/LowLevelWindow/LowLevelWindow_X11.h | 2 +- src/archutils/Win32/GraphicsWindow.cpp | 4 +-- src/archutils/Win32/GraphicsWindow.h | 2 +- 17 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index f88d9c1609..214b8f312d 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -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; diff --git a/src/GameSoundManager.cpp b/src/GameSoundManager.cpp index 222cbe8359..60f9a374fe 100644 --- a/src/GameSoundManager.cpp +++ b/src/GameSoundManager.cpp @@ -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; diff --git a/src/RageDisplay.cpp b/src/RageDisplay.cpp index f9c00f63ce..134b8546dd 100644 --- a/src/RageDisplay.cpp +++ b/src/RageDisplay.cpp @@ -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. @@ -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 ); @@ -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(ceilf( iHeight * GetActualVideoModeParams().fDisplayAspectRatio )); + int iWidth = static_cast(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() ); @@ -996,14 +996,14 @@ class LunaRageDisplay: public Luna 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; } diff --git a/src/RageDisplay.h b/src/RageDisplay.h index 5f286681d6..a834172c13 100644 --- a/src/RageDisplay.h +++ b/src/RageDisplay.h @@ -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; @@ -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 diff --git a/src/RageDisplay_D3D.cpp b/src/RageDisplay_D3D.cpp index 7a3bab0617..55d5b65895 100644 --- a/src/RageDisplay_D3D.cpp +++ b/src/RageDisplay_D3D.cpp @@ -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(); @@ -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() diff --git a/src/RageDisplay_D3D.h b/src/RageDisplay_D3D.h index 3064273b39..4eeaff1a11 100644 --- a/src/RageDisplay_D3D.h +++ b/src/RageDisplay_D3D.h @@ -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(); diff --git a/src/RageDisplay_Null.h b/src/RageDisplay_Null.h index 88cb6d64b9..29d2ea4bd7 100644 --- a/src/RageDisplay_Null.h +++ b/src/RageDisplay_Null.h @@ -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; } diff --git a/src/RageDisplay_OGL.cpp b/src/RageDisplay_OGL.cpp index 9268e7534d..adb7e51a18 100644 --- a/src/RageDisplay_OGL.cpp +++ b/src/RageDisplay_OGL.cpp @@ -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 ); @@ -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(); @@ -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, @@ -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(); @@ -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(); } @@ -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 ); @@ -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; } @@ -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; @@ -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; @@ -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) diff --git a/src/RageDisplay_OGL.h b/src/RageDisplay_OGL.h index 8fa8f3a5a0..2bb32477e6 100644 --- a/src/RageDisplay_OGL.h +++ b/src/RageDisplay_OGL.h @@ -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(); diff --git a/src/StepMania.cpp b/src/StepMania.cpp index 14f3824e2f..33d444ef7b 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -125,7 +125,7 @@ static LocalizedString NO_SMOOTH_LINES ("StepMania","NoSmoothLines"); static RString GetActualGraphicOptionsString() { - const VideoModeParams ¶ms = DISPLAY->GetActualVideoModeParams(); + VideoModeParams ¶ms = (*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(), @@ -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 ¶ms = DISPLAY->GetActualVideoModeParams(); + VideoModeParams ¶ms = (*DISPLAY->GetActualVideoModeParams()); PREFSMAN->m_bWindowed.Set( params.windowed ); /* If we're windowed, we may have tweaked the width based on the aspect ratio. diff --git a/src/arch/LowLevelWindow/LowLevelWindow.h b/src/arch/LowLevelWindow/LowLevelWindow.h index ad31aab327..88b72475e6 100644 --- a/src/arch/LowLevelWindow/LowLevelWindow.h +++ b/src/arch/LowLevelWindow/LowLevelWindow.h @@ -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; } diff --git a/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.h b/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.h index 9dd1644616..04de6ca332 100644 --- a/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.h +++ b/src/arch/LowLevelWindow/LowLevelWindow_MacOSX.h @@ -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(); diff --git a/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp b/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp index 1f6b108bea..ab753482da 100644 --- a/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp +++ b/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp @@ -292,7 +292,7 @@ void LowLevelWindow_Win32::Update() GraphicsWindow::Update(); } -const VideoModeParams &LowLevelWindow_Win32::GetActualVideoModeParams() const +VideoModeParams* LowLevelWindow_Win32::GetActualVideoModeParams() { return GraphicsWindow::GetParams(); } diff --git a/src/arch/LowLevelWindow/LowLevelWindow_Win32.h b/src/arch/LowLevelWindow/LowLevelWindow_Win32.h index 2f371b1481..812ffbfbd1 100644 --- a/src/arch/LowLevelWindow/LowLevelWindow_Win32.h +++ b/src/arch/LowLevelWindow/LowLevelWindow_Win32.h @@ -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 diff --git a/src/arch/LowLevelWindow/LowLevelWindow_X11.h b/src/arch/LowLevelWindow/LowLevelWindow_X11.h index e2fee3544c..a38f135ea1 100644 --- a/src/arch/LowLevelWindow/LowLevelWindow_X11.h +++ b/src/arch/LowLevelWindow/LowLevelWindow_X11.h @@ -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; diff --git a/src/archutils/Win32/GraphicsWindow.cpp b/src/archutils/Win32/GraphicsWindow.cpp index f2eb90c54e..36d059337e 100644 --- a/src/archutils/Win32/GraphicsWindow.cpp +++ b/src/archutils/Win32/GraphicsWindow.cpp @@ -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() diff --git a/src/archutils/Win32/GraphicsWindow.h b/src/archutils/Win32/GraphicsWindow.h index 6e1e6ebcef..a8cea1d383 100644 --- a/src/archutils/Win32/GraphicsWindow.h +++ b/src/archutils/Win32/GraphicsWindow.h @@ -30,7 +30,7 @@ namespace GraphicsWindow void GetDisplayResolutions( DisplayResolutions &out ); - const VideoModeParams &GetParams(); + VideoModeParams* GetParams(); HDC GetHDC(); void Update();