Clean up math functions
- Remove checking for standard functions from the build system - Prefix all invocations with std:: - Replace suffixed functions with unprefixed versions - Include <cmath> in all files that use it and remove the global include e.g. floorf(x) -> std::floor(x)
This commit is contained in:
+44
-42
@@ -15,6 +15,8 @@
|
||||
#include "DisplaySpec.h"
|
||||
#include "arch/ArchHooks/ArchHooks.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
// Statistics stuff
|
||||
RageTimer g_LastCheckTimer;
|
||||
int g_iNumVerts;
|
||||
@@ -63,7 +65,7 @@ static const char *RagePixelFormatNames[] = {
|
||||
XToString( RagePixelFormat );
|
||||
|
||||
/* bNeedReloadTextures is set to true if the device was re-created and we need
|
||||
* to reload textures. On failure, an error message is returned.
|
||||
* to reload textures. On failure, an error message is returned.
|
||||
* XXX: the renderer itself should probably be the one to try fallback modes */
|
||||
static LocalizedString SETVIDEOMODE_FAILED ( "RageDisplay", "SetVideoMode failed:" );
|
||||
RString RageDisplay::SetVideoMode( VideoModeParams p, bool &bNeedReloadTextures )
|
||||
@@ -82,7 +84,7 @@ RString RageDisplay::SetVideoMode( VideoModeParams p, bool &bNeedReloadTextures
|
||||
return RString();
|
||||
vs.push_back( err );
|
||||
|
||||
// "Intel(R) 82810E Graphics Controller" won't accept a 16 bpp surface if
|
||||
// "Intel(R) 82810E Graphics Controller" won't accept a 16 bpp surface if
|
||||
// the desktop is 32 bpp, so try 32 bpp as well.
|
||||
p.bpp = 32;
|
||||
if( (err = this->TryVideoMode(p,bNeedReloadTextures)) == "" )
|
||||
@@ -116,7 +118,7 @@ RString RageDisplay::SetVideoMode( VideoModeParams p, bool &bNeedReloadTextures
|
||||
const DisplayMode supported = d.currentMode() != nullptr ? *d.currentMode() : *d.supportedModes().begin();
|
||||
p.width = supported.width;
|
||||
p.height = supported.height;
|
||||
p.rate = static_cast<int> (round(supported.refreshRate));
|
||||
p.rate = std::round(supported.refreshRate);
|
||||
if( (err = this->TryVideoMode(p,bNeedReloadTextures)) == "" )
|
||||
return RString();
|
||||
vs.push_back( err );
|
||||
@@ -133,9 +135,9 @@ void RageDisplay::ProcessStatsOnFlip()
|
||||
{
|
||||
float fActualTime = g_LastCheckTimer.GetDeltaTime();
|
||||
g_iNumChecksSinceLastReset++;
|
||||
g_iFPS = lrintf( g_iFramesRenderedSinceLastCheck / fActualTime );
|
||||
g_iFPS = std::lrint( g_iFramesRenderedSinceLastCheck / fActualTime );
|
||||
g_iCFPS = g_iFramesRenderedSinceLastReset / g_iNumChecksSinceLastReset;
|
||||
g_iCFPS = lrintf( g_iCFPS / fActualTime );
|
||||
g_iCFPS = std::lrint( g_iCFPS / fActualTime );
|
||||
g_iVPF = g_iVertsRenderedSinceLastCheck / g_iFramesRenderedSinceLastCheck;
|
||||
g_iFramesRenderedSinceLastCheck = g_iVertsRenderedSinceLastCheck = 0;
|
||||
if( LOG_FPS )
|
||||
@@ -199,7 +201,7 @@ void RageDisplay::DrawPolyLine(const RageSpriteVertex &p1, const RageSpriteVerte
|
||||
// soh cah toa strikes strikes again!
|
||||
float opp = p2.p.x - p1.p.x;
|
||||
float adj = p2.p.y - p1.p.y;
|
||||
float hyp = powf(opp*opp + adj*adj, 0.5f);
|
||||
float hyp = std::pow(opp*opp + adj*adj, 0.5f);
|
||||
|
||||
float lsin = opp/hyp;
|
||||
float lcos = adj/hyp;
|
||||
@@ -246,7 +248,7 @@ void RageDisplay::DrawCircleInternal( const RageSpriteVertex &p, float radius )
|
||||
RageSpriteVertex v[subdivisions+2];
|
||||
v[0] = p;
|
||||
|
||||
for(int i = 0; i < subdivisions+1; ++i)
|
||||
for(int i = 0; i < subdivisions+1; ++i)
|
||||
{
|
||||
const float fRotation = float(i) / subdivisions * 2*PI;
|
||||
const float fX = RageFastCos(fRotation) * radius;
|
||||
@@ -264,7 +266,7 @@ void RageDisplay::SetDefaultRenderStates()
|
||||
{
|
||||
SetLighting( false );
|
||||
SetCullMode( CULL_NONE );
|
||||
SetZWrite( false );
|
||||
SetZWrite( false );
|
||||
SetZTestMode( ZTEST_OFF );
|
||||
SetAlphaTest( true );
|
||||
SetBlendMode( BLEND_NORMAL );
|
||||
@@ -412,7 +414,7 @@ public:
|
||||
RageMatrixSkewX( &m, fAmount );
|
||||
MultMatrixLocal( m );
|
||||
}
|
||||
|
||||
|
||||
void SkewY( float fAmount )
|
||||
{
|
||||
RageMatrix m;
|
||||
@@ -482,13 +484,13 @@ const RageMatrix* RageDisplay::GetTextureTop() const
|
||||
return g_TextureStack.GetTop();
|
||||
}
|
||||
|
||||
void RageDisplay::PushMatrix()
|
||||
{
|
||||
void RageDisplay::PushMatrix()
|
||||
{
|
||||
g_WorldStack.Push();
|
||||
}
|
||||
|
||||
void RageDisplay::PopMatrix()
|
||||
{
|
||||
void RageDisplay::PopMatrix()
|
||||
{
|
||||
g_WorldStack.Pop();
|
||||
}
|
||||
|
||||
@@ -548,13 +550,13 @@ void RageDisplay::LoadIdentity()
|
||||
}
|
||||
|
||||
|
||||
void RageDisplay::TexturePushMatrix()
|
||||
{
|
||||
void RageDisplay::TexturePushMatrix()
|
||||
{
|
||||
g_TextureStack.Push();
|
||||
}
|
||||
|
||||
void RageDisplay::TexturePopMatrix()
|
||||
{
|
||||
void RageDisplay::TexturePopMatrix()
|
||||
{
|
||||
g_TextureStack.Pop();
|
||||
}
|
||||
|
||||
@@ -578,7 +580,7 @@ void RageDisplay::LoadMenuPerspective( float fovDegrees, float fWidth, float fHe
|
||||
CLAMP( fovDegrees, 0.1f, 179.9f );
|
||||
float fovRadians = fovDegrees / 180.f * PI;
|
||||
float theta = fovRadians/2;
|
||||
float fDistCameraFromImage = fWidth/2 / tanf( theta );
|
||||
float fDistCameraFromImage = fWidth/2 / std::tan( theta );
|
||||
|
||||
fVanishPointX = SCALE( fVanishPointX, 0, fWidth, fWidth, 0 );
|
||||
fVanishPointY = SCALE( fVanishPointY, 0, fHeight, fHeight, 0 );
|
||||
@@ -596,7 +598,7 @@ void RageDisplay::LoadMenuPerspective( float fovDegrees, float fWidth, float fHe
|
||||
1,
|
||||
fDistCameraFromImage+1000 ) );
|
||||
|
||||
g_ViewStack.LoadMatrix(
|
||||
g_ViewStack.LoadMatrix(
|
||||
RageLookAt(
|
||||
-fVanishPointX+fWidth/2, -fVanishPointY+fHeight/2, fDistCameraFromImage,
|
||||
-fVanishPointX+fWidth/2, -fVanishPointY+fHeight/2, 0,
|
||||
@@ -634,7 +636,7 @@ void RageDisplay::LoadLookAt( float fFOV, const RageVector3 &Eye, const RageVect
|
||||
|
||||
RageMatrix RageDisplay::GetPerspectiveMatrix(float fovy, float aspect, float zNear, float zFar)
|
||||
{
|
||||
float ymax = zNear * tanf(fovy * PI / 360.0f);
|
||||
float ymax = zNear * std::tan(fovy * PI / 360.0f);
|
||||
float ymin = -ymax;
|
||||
float xmin = ymin * aspect;
|
||||
float xmax = ymax * aspect;
|
||||
@@ -648,7 +650,7 @@ RageSurface *RageDisplay::CreateSurfaceFromPixfmt( RagePixelFormat pixfmt,
|
||||
const RagePixelFormatDesc *tpf = GetPixelFormatDesc(pixfmt);
|
||||
|
||||
RageSurface *surf = CreateSurfaceFrom(
|
||||
width, height, tpf->bpp,
|
||||
width, height, tpf->bpp,
|
||||
tpf->masks[0], tpf->masks[1], tpf->masks[2], tpf->masks[3],
|
||||
(uint8_t *) pixels, pitch );
|
||||
|
||||
@@ -739,15 +741,15 @@ RageMatrix RageDisplay::GetCenteringMatrix( float fTranslateX, float fTranslateY
|
||||
|
||||
RageMatrix m1;
|
||||
RageMatrix m2;
|
||||
RageMatrixTranslation(
|
||||
&m1,
|
||||
fPercentShiftX,
|
||||
fPercentShiftY,
|
||||
RageMatrixTranslation(
|
||||
&m1,
|
||||
fPercentShiftX,
|
||||
fPercentShiftY,
|
||||
0 );
|
||||
RageMatrixScaling(
|
||||
&m2,
|
||||
fPercentScaleX,
|
||||
fPercentScaleY,
|
||||
RageMatrixScaling(
|
||||
&m2,
|
||||
fPercentScaleX,
|
||||
fPercentScaleY,
|
||||
1 );
|
||||
RageMatrix mOut;
|
||||
RageMatrixMultiply( &mOut, &m1, &m2 );
|
||||
@@ -757,7 +759,7 @@ RageMatrix RageDisplay::GetCenteringMatrix( float fTranslateX, float fTranslateY
|
||||
void RageDisplay::UpdateCentering()
|
||||
{
|
||||
const Centering &p = g_CenteringStack.back();
|
||||
g_CenteringMatrix = GetCenteringMatrix(
|
||||
g_CenteringMatrix = GetCenteringMatrix(
|
||||
(float) p.m_iTranslateX, (float) p.m_iTranslateY, (float) p.m_iAddWidth, (float) p.m_iAddHeight );
|
||||
}
|
||||
|
||||
@@ -766,13 +768,13 @@ bool RageDisplay::SaveScreenshot( RString sPath, GraphicsFileFormat format )
|
||||
RageTimer timer;
|
||||
RageSurface *surface = this->CreateScreenshot();
|
||||
// LOG->Trace( "CreateScreenshot took %f seconds", timer.GetDeltaTime() );
|
||||
|
||||
|
||||
if (nullptr == surface)
|
||||
{
|
||||
LOG->Trace("CreateScreenshot failed to return a surface");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Unless we're in lossless, resize the image to 640x480. If we're saving lossy,
|
||||
* there's no sense in saving 1280x960 screenshots, and we don't want to output
|
||||
* screenshots in a strange (non-1) sample aspect ratio. */
|
||||
@@ -781,9 +783,9 @@ bool RageDisplay::SaveScreenshot( RString sPath, GraphicsFileFormat format )
|
||||
// Maintain the DAR.
|
||||
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 ));
|
||||
// This used to be lrint. However, lrint causes odd resolutions like
|
||||
// 639x480 (4:3) and 853x480 (16:9). ceil gives correct values. -aj
|
||||
int iWidth = std::ceil( 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() );
|
||||
@@ -868,7 +870,7 @@ void RageDisplay::DrawStrip( const RageSpriteVertex v[], int iNumVerts )
|
||||
|
||||
this->DrawStripInternal(v,iNumVerts);
|
||||
|
||||
StatsAddVerts(iNumVerts);
|
||||
StatsAddVerts(iNumVerts);
|
||||
}
|
||||
|
||||
void RageDisplay::DrawTriangles( const RageSpriteVertex v[], int iNumVerts )
|
||||
@@ -887,7 +889,7 @@ void RageDisplay::DrawCompiledGeometry( const RageCompiledGeometry *p, int iMesh
|
||||
{
|
||||
this->DrawCompiledGeometryInternal( p, iMeshIndex );
|
||||
|
||||
StatsAddVerts( vMeshes[iMeshIndex].Triangles.size() );
|
||||
StatsAddVerts( vMeshes[iMeshIndex].Triangles.size() );
|
||||
}
|
||||
|
||||
void RageDisplay::DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth )
|
||||
@@ -1023,7 +1025,7 @@ static void register_REFRESH_DEFAULT(lua_State *L)
|
||||
REGISTER_WITH_LUA_FUNCTION( register_REFRESH_DEFAULT );
|
||||
|
||||
|
||||
/** @brief Allow Lua to have access to the RageDisplay. */
|
||||
/** @brief Allow Lua to have access to the RageDisplay. */
|
||||
class LunaRageDisplay: public Luna<RageDisplay>
|
||||
{
|
||||
public:
|
||||
@@ -1040,19 +1042,19 @@ public:
|
||||
LuaHelpers::Push( L, params.height );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int GetFPS( T* p, lua_State *L )
|
||||
{
|
||||
lua_pushnumber(L, p->GetFPS());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int GetVPF( T* p, lua_State *L )
|
||||
{
|
||||
lua_pushnumber(L, p->GetVPF());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int GetCumFPS( T* p, lua_State *L )
|
||||
{
|
||||
lua_pushnumber(L, p->GetCumFPS());
|
||||
@@ -1079,7 +1081,7 @@ public:
|
||||
return 1;
|
||||
}
|
||||
|
||||
LunaRageDisplay()
|
||||
LunaRageDisplay()
|
||||
{
|
||||
ADD_METHOD( GetDisplayWidth );
|
||||
ADD_METHOD( GetDisplayHeight );
|
||||
|
||||
Reference in New Issue
Block a user