Decouple <cstdint>

This commit is contained in:
Martin Natano
2023-04-21 22:13:41 +02:00
parent bcea05dd67
commit aa87f85eef
167 changed files with 1533 additions and 1307 deletions
+3 -1
View File
@@ -10,6 +10,8 @@
#include "RageDisplay.h" #include "RageDisplay.h"
#include "ScreenDimensions.h" #include "ScreenDimensions.h"
#include <cstdint>
/* Tricky: We need ActorFrames created in Lua to auto delete their children. /* Tricky: We need ActorFrames created in Lua to auto delete their children.
* We don't want classes that derive from ActorFrame to auto delete their * We don't want classes that derive from ActorFrame to auto delete their
@@ -146,7 +148,7 @@ void ActorFrame::AddChild( Actor *pActor )
#endif #endif
ASSERT( pActor != nullptr ); ASSERT( pActor != nullptr );
ASSERT( reinterpret_cast<uintptr_t>(pActor) != static_cast<uintptr_t>(0xC0000005) ); ASSERT( reinterpret_cast<std::uintptr_t>(pActor) != static_cast<std::uintptr_t>(0xC0000005) );
m_SubActors.push_back( pActor ); m_SubActors.push_back( pActor );
pActor->SetParent( this ); pActor->SetParent( this );
+3 -1
View File
@@ -5,6 +5,8 @@
#include "RageLog.h" #include "RageLog.h"
#include "ActorUtil.h" #include "ActorUtil.h"
#include <cstdint>
REGISTER_ACTOR_CLASS_WITH_NAME( ActorFrameTextureAutoDeleteChildren, ActorFrameTexture ); REGISTER_ACTOR_CLASS_WITH_NAME( ActorFrameTextureAutoDeleteChildren, ActorFrameTexture );
ActorFrameTexture *ActorFrameTexture::Copy() const { return new ActorFrameTexture(*this); } ActorFrameTexture *ActorFrameTexture::Copy() const { return new ActorFrameTexture(*this); }
@@ -14,7 +16,7 @@ ActorFrameTexture::ActorFrameTexture()
m_bAlphaBuffer = false; m_bAlphaBuffer = false;
m_bFloat = false; m_bFloat = false;
m_bPreserveTexture = false; m_bPreserveTexture = false;
static uint64_t i = 0; static std::uint64_t i = 0;
++i; ++i;
m_sTextureName = ssprintf( ConvertI64FormatString("ActorFrameTexture %lli"), i ); m_sTextureName = ssprintf( ConvertI64FormatString("ActorFrameTexture %lli"), i );
+5 -4
View File
@@ -14,6 +14,7 @@
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <numeric> #include <numeric>
const float min_state_delay= 0.0001f; const float min_state_delay= 0.0001f;
@@ -237,16 +238,16 @@ void ActorMultiVertex::DrawPrimitives()
for( std::size_t i=0; i < TS.vertices.size(); i++ ) for( std::size_t i=0; i < TS.vertices.size(); i++ )
{ {
// RageVColor uses a uint8_t for each channel. 0-255. // RageVColor uses a std::uint8_t for each channel. 0-255.
// RageColor uses a float. 0-1. // RageColor uses a float. 0-1.
// So each channel of the RageVColor needs to be converted to a float, // So each channel of the RageVColor needs to be converted to a float,
// multiplied by the channel from the RageColor, then the result // multiplied by the channel from the RageColor, then the result
// converted to uint8_t. If implicit conversion is allowed to happen, // converted to std::uint8_t. If implicit conversion is allowed to happen,
// sometimes the compiler decides to turn the RageColor into a uint8_t, // sometimes the compiler decides to turn the RageColor into a std::uint8_t,
// which makes any value other than 1 into 0. Thus, the explicit // which makes any value other than 1 into 0. Thus, the explicit
// conversions. -Kyz // conversions. -Kyz
#define MULT_COLOR_ELEMENTS(color_a, color_b) \ #define MULT_COLOR_ELEMENTS(color_a, color_b) \
color_a= static_cast<uint8_t>(static_cast<float>(color_a) * color_b); color_a= static_cast<std::uint8_t>(static_cast<float>(color_a) * color_b);
// RageVColor * RageColor // RageVColor * RageColor
MULT_COLOR_ELEMENTS(TS.vertices[i].c.b, m_pTempState->diffuse[0].b); MULT_COLOR_ELEMENTS(TS.vertices[i].c.b, m_pTempState->diffuse[0].b);
MULT_COLOR_ELEMENTS(TS.vertices[i].c.r, m_pTempState->diffuse[0].r); MULT_COLOR_ELEMENTS(TS.vertices[i].c.r, m_pTempState->diffuse[0].r);
+2 -1
View File
@@ -1,6 +1,7 @@
#include "global.h" #include "global.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <cstdio> #include <cstdio>
#if defined(_WINDOWS) #if defined(_WINDOWS)
@@ -339,7 +340,7 @@ typedef unsigned IPos; // A Pos is an index in the character window. Pos is used
typedef int64_t lutime_t; // define it ourselves since we don't include time.h typedef std::int64_t lutime_t; // define it ourselves since we don't include time.h
typedef struct iztimes { typedef struct iztimes {
lutime_t atime,mtime,ctime; lutime_t atime,mtime,ctime;
+5 -3
View File
@@ -16,6 +16,8 @@
#include "LuaReference.h" #include "LuaReference.h"
#include "LuaManager.h" #include "LuaManager.h"
#include <cstdint>
CryptManager* CRYPTMAN = nullptr; // global and accessible from anywhere in our program CryptManager* CRYPTMAN = nullptr; // global and accessible from anywhere in our program
static const RString PRIVATE_KEY_PATH = "Data/private.rsa"; static const RString PRIVATE_KEY_PATH = "Data/private.rsa";
@@ -62,9 +64,9 @@ bool CryptManager::VerifyFileWithFile( RString sPath, RString sSignatureFile )
void CryptManager::GetRandomBytes( void *pData, int iBytes ) void CryptManager::GetRandomBytes( void *pData, int iBytes )
{ {
uint8_t *pBuf = (uint8_t *) pData; std::uint8_t *pBuf = (std::uint8_t *) pData;
while( iBytes-- ) while( iBytes-- )
*pBuf++ = (uint8_t) RandomInt( 256 ); *pBuf++ = (std::uint8_t) RandomInt( 256 );
} }
#else #else
@@ -463,7 +465,7 @@ RString CryptManager::GetPublicKeyFileName()
/* Generate a version 4 random UUID. */ /* Generate a version 4 random UUID. */
RString CryptManager::GenerateRandomUUID() RString CryptManager::GenerateRandomUUID()
{ {
uint32_t buf[4]; std::uint32_t buf[4];
CryptManager::GetRandomBytes( buf, sizeof(buf) ); CryptManager::GetRandomBytes( buf, sizeof(buf) );
buf[1] &= 0xFFFF0FFF; buf[1] &= 0xFFFF0FFF;
+3 -2
View File
@@ -21,6 +21,7 @@
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
static Preference<bool> g_bPalettedImageCache( "PalettedImageCache", false ); static Preference<bool> g_bPalettedImageCache( "PalettedImageCache", false );
@@ -188,8 +189,8 @@ void ImageCache::ReadFromDisk()
struct ImageTexture: public RageTexture struct ImageTexture: public RageTexture
{ {
uintptr_t m_uTexHandle; std::uintptr_t m_uTexHandle;
uintptr_t GetTexHandle() const { return m_uTexHandle; }; // accessed by RageDisplay std::uintptr_t GetTexHandle() const { return m_uTexHandle; }; // accessed by RageDisplay
/* This is a reference to a pointer in g_ImagePathToImage. */ /* This is a reference to a pointer in g_ImagePathToImage. */
RageSurface *&m_pImage; RageSurface *&m_pImage;
int m_iWidth, m_iHeight; int m_iWidth, m_iHeight;
+3 -2
View File
@@ -17,6 +17,7 @@
#include <cmath> #include <cmath>
#include <csetjmp> #include <csetjmp>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <map> #include <map>
#include <sstream> // conversion for lua functions. #include <sstream> // conversion for lua functions.
@@ -420,8 +421,8 @@ LuaThreadVariable::LuaThreadVariable( lua_State *L )
RString LuaThreadVariable::GetCurrentThreadIDString() RString LuaThreadVariable::GetCurrentThreadIDString()
{ {
uint64_t iID = RageThread::GetCurrentThreadID(); std::uint64_t iID = RageThread::GetCurrentThreadID();
return ssprintf( "%08x%08x", uint32_t(iID >> 32), uint32_t(iID) ); return ssprintf( "%08x%08x", std::uint32_t(iID >> 32), std::uint32_t(iID) );
} }
bool LuaThreadVariable::PushThreadTable( lua_State *L, bool bCreate ) bool LuaThreadVariable::PushThreadTable( lua_State *L, bool bCreate )
+3 -2
View File
@@ -14,6 +14,7 @@
#include "PrefsManager.h" #include "PrefsManager.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
REGISTER_ACTOR_CLASS( Model ); REGISTER_ACTOR_CLASS( Model );
@@ -541,7 +542,7 @@ void Model::PlayAnimation( const RString &sAniName, float fPlayRate )
{ {
// int iBoneIndex = (pMesh->m_iBoneIndex!=-1) ? pMesh->m_iBoneIndex : bone; // int iBoneIndex = (pMesh->m_iBoneIndex!=-1) ? pMesh->m_iBoneIndex : bone;
RageVector3 &pos = Vertices[j].p; RageVector3 &pos = Vertices[j].p;
int8_t bone = Vertices[j].bone; std::int8_t bone = Vertices[j].bone;
if( bone != -1 ) if( bone != -1 )
{ {
pos[0] -= m_vpBones[bone].m_Absolute.m[3][0]; pos[0] -= m_vpBones[bone].m_Absolute.m[3][0];
@@ -698,7 +699,7 @@ void Model::UpdateTempGeometry()
RageVector3 &tempNormal = tempVertices[j].n; RageVector3 &tempNormal = tempVertices[j].n;
const RageVector3 &originalPos = origVertices[j].p; const RageVector3 &originalPos = origVertices[j].p;
const RageVector3 &originalNormal = origVertices[j].n; const RageVector3 &originalNormal = origVertices[j].n;
int8_t bone = origVertices[j].bone; std::int8_t bone = origVertices[j].bone;
if( bone == -1 ) if( bone == -1 )
{ {
+3 -1
View File
@@ -5,9 +5,11 @@
#include "RageTypes.h" #include "RageTypes.h"
#include <cstdint>
struct msTriangle struct msTriangle
{ {
uint16_t nVertexIndices[3]; std::uint16_t nVertexIndices[3];
}; };
+2 -1
View File
@@ -12,6 +12,7 @@
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <utility> #include <utility>
// TODO: Remove these constants that aren't time signature-aware // TODO: Remove these constants that aren't time signature-aware
@@ -144,7 +145,7 @@ static void LoadFromSMNoteDataStringWithPlayer( NoteData& out, const RString &sS
int iHeadRow; int iHeadRow;
if( !out.IsHoldNoteAtRow( iTrack, iIndex, &iHeadRow ) ) if( !out.IsHoldNoteAtRow( iTrack, iIndex, &iHeadRow ) )
{ {
int n = intptr_t(endLine) - intptr_t(beginLine); int n = std::intptr_t(endLine) - std::intptr_t(beginLine);
LOG->Warn( "Unmatched 3 in \"%.*s\"", n, beginLine ); LOG->Warn( "Unmatched 3 in \"%.*s\"", n, beginLine );
} }
else else
+2 -1
View File
@@ -20,6 +20,7 @@
#include "Style.h" #include "Style.h"
#include <cmath> #include <cmath>
#include <cstdint>
static Preference<bool> g_bRenderEarlierNotesOnTop( "RenderEarlierNotesOnTop", false ); static Preference<bool> g_bRenderEarlierNotesOnTop( "RenderEarlierNotesOnTop", false );
@@ -1358,7 +1359,7 @@ void NoteDisplay::DrawActor(const TapNote& tn, Actor* pActor, NotePart part,
break; break;
case NoteColorType_ProgressAlternate: case NoteColorType_ProgressAlternate:
fScaledBeat = fBeat * cache->m_iNoteColorCount[part]; fScaledBeat = fBeat * cache->m_iNoteColorCount[part];
if( fScaledBeat - int64_t(fScaledBeat) == 0.0f ) if( fScaledBeat - std::int64_t(fScaledBeat) == 0.0f )
//we're on a boundary, so move to the previous frame. //we're on a boundary, so move to the previous frame.
//doing it this way ensures that fScaledBeat is never negative so std::fmod works. //doing it this way ensures that fScaledBeat is never negative so std::fmod works.
fScaledBeat += cache->m_iNoteColorCount[part] - 1; fScaledBeat += cache->m_iNoteColorCount[part] - 1;
+2 -1
View File
@@ -28,6 +28,7 @@
#include <algorithm> #include <algorithm>
#include <cstddef> #include <cstddef>
#include <cstdint>
const RString STATS_XML = "Stats.xml"; const RString STATS_XML = "Stats.xml";
const RString STATS_XML_GZ = "Stats.xml.gz"; const RString STATS_XML_GZ = "Stats.xml.gz";
@@ -1254,7 +1255,7 @@ ProfileLoadResult Profile::LoadStatsFromDir(RString dir, bool require_signature)
if(compressed) if(compressed)
{ {
RString sError; RString sError;
uint32_t iCRC32; std::uint32_t iCRC32;
RageFileObjInflate *pInflate = GunzipFile(pFile.release(), sError, &iCRC32); RageFileObjInflate *pInflate = GunzipFile(pFile.release(), sError, &iCRC32);
if(pInflate == nullptr) if(pInflate == nullptr)
{ {
+4 -2
View File
@@ -5,6 +5,8 @@
#include "RageTexture.h" #include "RageTexture.h"
#include <cstddef>
class RageBitmapTexture : public RageTexture class RageBitmapTexture : public RageTexture
{ {
public: public:
@@ -13,12 +15,12 @@ public:
/* only called by RageTextureManager::InvalidateTextures */ /* only called by RageTextureManager::InvalidateTextures */
virtual void Invalidate() { m_uTexHandle = 0; /* don't Destroy() */} virtual void Invalidate() { m_uTexHandle = 0; /* don't Destroy() */}
virtual void Reload(); virtual void Reload();
virtual uintptr_t GetTexHandle() const { return m_uTexHandle; }; // accessed by RageDisplay virtual std::uintptr_t GetTexHandle() const { return m_uTexHandle; }; // accessed by RageDisplay
private: private:
void Create(); // called by constructor and Reload void Create(); // called by constructor and Reload
void Destroy(); void Destroy();
uintptr_t m_uTexHandle; // treat as unsigned in OpenGL, IDirect3DTexture9* for D3D std::uintptr_t m_uTexHandle; // treat as unsigned in OpenGL, IDirect3DTexture9* for D3D
}; };
#endif #endif
+2 -1
View File
@@ -17,6 +17,7 @@
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
// Statistics stuff // Statistics stuff
RageTimer g_LastCheckTimer; RageTimer g_LastCheckTimer;
@@ -653,7 +654,7 @@ RageSurface *RageDisplay::CreateSurfaceFromPixfmt( RagePixelFormat pixfmt,
RageSurface *surf = CreateSurfaceFrom( RageSurface *surf = CreateSurfaceFrom(
width, height, tpf->bpp, width, height, tpf->bpp,
tpf->masks[0], tpf->masks[1], tpf->masks[2], tpf->masks[3], tpf->masks[0], tpf->masks[1], tpf->masks[2], tpf->masks[3],
(uint8_t *) pixels, pitch ); (std::uint8_t *) pixels, pitch );
return surf; return surf;
} }
+11 -10
View File
@@ -7,6 +7,7 @@
#include "ModelTypes.h" #include "ModelTypes.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <set> #include <set>
class DisplaySpec; class DisplaySpec;
@@ -200,7 +201,7 @@ struct RageTextureLock
/* Given a surface with a format and no pixel data, lock the texture into the /* Given a surface with a format and no pixel data, lock the texture into the
* surface. The data is write-only. */ * surface. The data is write-only. */
virtual void Lock( uintptr_t iTexHandle, RageSurface *pSurface ) = 0; virtual void Lock( std::uintptr_t iTexHandle, RageSurface *pSurface ) = 0;
/* Unlock and update the texture. If bChanged is false, the texture update /* Unlock and update the texture. If bChanged is false, the texture update
* may be omitted. */ * may be omitted. */
@@ -256,23 +257,23 @@ public:
/* return 0 if failed or internal texture resource handle /* return 0 if failed or internal texture resource handle
* (unsigned in OpenGL, texture pointer in D3D) */ * (unsigned in OpenGL, texture pointer in D3D) */
virtual uintptr_t CreateTexture( virtual std::uintptr_t CreateTexture(
RagePixelFormat pixfmt, // format of img and of texture in video mem RagePixelFormat pixfmt, // format of img and of texture in video mem
RageSurface* img, // must be in pixfmt RageSurface* img, // must be in pixfmt
bool bGenerateMipMaps bool bGenerateMipMaps
) = 0; ) = 0;
virtual void UpdateTexture( virtual void UpdateTexture(
uintptr_t iTexHandle, std::uintptr_t iTexHandle,
RageSurface* img, RageSurface* img,
int xoffset, int yoffset, int width, int height int xoffset, int yoffset, int width, int height
) = 0; ) = 0;
virtual void DeleteTexture( uintptr_t iTexHandle ) = 0; virtual void DeleteTexture( std::uintptr_t iTexHandle ) = 0;
/* Return an object to lock pixels for streaming. If not supported, returns nullptr. /* Return an object to lock pixels for streaming. If not supported, returns nullptr.
* Delete the object normally. */ * Delete the object normally. */
virtual RageTextureLock *CreateTextureLock() { return nullptr; } virtual RageTextureLock *CreateTextureLock() { return nullptr; }
virtual void ClearAllTextures() = 0; virtual void ClearAllTextures() = 0;
virtual int GetNumTextureUnits() = 0; virtual int GetNumTextureUnits() = 0;
virtual void SetTexture( TextureUnit, uintptr_t /* iTexture */ ) = 0; virtual void SetTexture( TextureUnit, std::uintptr_t /* iTexture */ ) = 0;
virtual void SetTextureMode( TextureUnit, TextureMode ) = 0; virtual void SetTextureMode( TextureUnit, TextureMode ) = 0;
virtual void SetTextureWrapping( TextureUnit, bool ) = 0; virtual void SetTextureWrapping( TextureUnit, bool ) = 0;
virtual int GetMaxTextureSize() const = 0; virtual int GetMaxTextureSize() const = 0;
@@ -288,9 +289,9 @@ public:
* DeleteTexture. (UpdateTexture is not permitted.) Returns 0 if render-to- * DeleteTexture. (UpdateTexture is not permitted.) Returns 0 if render-to-
* texture is unsupported. * texture is unsupported.
*/ */
virtual uintptr_t CreateRenderTarget( const RenderTargetParam &, int & /* iTextureWidthOut */, int & /* iTextureHeightOut */ ) { return 0; } virtual std::uintptr_t CreateRenderTarget( const RenderTargetParam &, int & /* iTextureWidthOut */, int & /* iTextureHeightOut */ ) { return 0; }
virtual uintptr_t GetRenderTarget() { return 0; } virtual std::uintptr_t GetRenderTarget() { return 0; }
/* Set the render target, or 0 to resume rendering to the framebuffer. An active render /* Set the render target, or 0 to resume rendering to the framebuffer. An active render
* target may not be used as a texture. If bPreserveTexture is true, the contents * target may not be used as a texture. If bPreserveTexture is true, the contents
@@ -298,7 +299,7 @@ public:
* bPreserveTexture is true the first time a render target is used, behave as if * bPreserveTexture is true the first time a render target is used, behave as if
* bPreserveTexture was false. * bPreserveTexture was false.
*/ */
virtual void SetRenderTarget( uintptr_t /* iHandle */, bool /* bPreserveTexture */ = true ) { } virtual void SetRenderTarget( std::uintptr_t /* iHandle */, bool /* bPreserveTexture */ = true ) { }
virtual bool IsZTestEnabled() const = 0; virtual bool IsZTestEnabled() const = 0;
virtual bool IsZWriteEnabled() const = 0; virtual bool IsZWriteEnabled() const = 0;
@@ -359,9 +360,9 @@ public:
}; };
bool SaveScreenshot( RString sPath, GraphicsFileFormat format ); bool SaveScreenshot( RString sPath, GraphicsFileFormat format );
virtual RString GetTextureDiagnostics( uintptr_t /* id */ ) const { return RString(); } virtual RString GetTextureDiagnostics( std::uintptr_t /* id */ ) const { return RString(); }
virtual RageSurface* CreateScreenshot() = 0; // allocates a surface. Caller must delete it. virtual RageSurface* CreateScreenshot() = 0; // allocates a surface. Caller must delete it.
virtual RageSurface *GetTexture( uintptr_t /* iTexture */ ) { return nullptr; } // allocates a surface. Caller must delete it. virtual RageSurface *GetTexture( std::uintptr_t /* iTexture */ ) { return nullptr; } // allocates a surface. Caller must delete it.
protected: protected:
virtual void DrawQuadsInternal( const RageSpriteVertex v[], int iNumVerts ) = 0; virtual void DrawQuadsInternal( const RageSpriteVertex v[], int iNumVerts ) = 0;
+17 -16
View File
@@ -26,6 +26,7 @@
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <list> #include <list>
// Globals // Globals
@@ -45,13 +46,13 @@ const D3DFORMAT g_DefaultAdapterFormat = D3DFMT_X8R8G8B8;
/* Direct3D doesn't associate a palette with textures. Instead, we load a /* Direct3D doesn't associate a palette with textures. Instead, we load a
* palette into a slot. We need to keep track of which texture's palette is * palette into a slot. We need to keep track of which texture's palette is
* stored in what slot. */ * stored in what slot. */
std::map<uintptr_t, std::size_t> g_TexResourceToPaletteIndex; std::map<std::uintptr_t, std::size_t> g_TexResourceToPaletteIndex;
std::list<std::size_t> g_PaletteIndex; std::list<std::size_t> g_PaletteIndex;
struct TexturePalette { PALETTEENTRY p[256]; }; struct TexturePalette { PALETTEENTRY p[256]; };
std::map<uintptr_t, TexturePalette> g_TexResourceToTexturePalette; std::map<std::uintptr_t, TexturePalette> g_TexResourceToTexturePalette;
// Load the palette, if any, for the given texture into a palette slot, and make it current. // Load the palette, if any, for the given texture into a palette slot, and make it current.
static void SetPalette( uintptr_t TexResource ) static void SetPalette( std::uintptr_t TexResource )
{ {
// If the texture isn't paletted, we have nothing to do. // If the texture isn't paletted, we have nothing to do.
if( g_TexResourceToTexturePalette.find(TexResource) == g_TexResourceToTexturePalette.end() ) if( g_TexResourceToTexturePalette.find(TexResource) == g_TexResourceToTexturePalette.end() )
@@ -64,7 +65,7 @@ static void SetPalette( uintptr_t TexResource )
UINT iPalIndex = static_cast<UINT>(g_PaletteIndex.front()); UINT iPalIndex = static_cast<UINT>(g_PaletteIndex.front());
// If any other texture is currently using this slot, mark that palette unloaded. // If any other texture is currently using this slot, mark that palette unloaded.
for( std::map<uintptr_t, std::size_t>::iterator i = g_TexResourceToPaletteIndex.begin(); i != g_TexResourceToPaletteIndex.end(); ++i ) for( std::map<std::uintptr_t, std::size_t>::iterator i = g_TexResourceToPaletteIndex.begin(); i != g_TexResourceToPaletteIndex.end(); ++i )
{ {
if( i->second != iPalIndex ) if( i->second != iPalIndex )
continue; continue;
@@ -795,7 +796,7 @@ public:
for( std::size_t j=0; j<Triangles.size(); j++ ) for( std::size_t j=0; j<Triangles.size(); j++ )
for( std::size_t k=0; k<3; k++ ) for( std::size_t k=0; k<3; k++ )
m_vTriangles[meshInfo.iTriangleStart+j].nVertexIndices[k] = (uint16_t) meshInfo.iVertexStart + Triangles[j].nVertexIndices[k]; m_vTriangles[meshInfo.iTriangleStart+j].nVertexIndices[k] = (std::uint16_t) meshInfo.iVertexStart + Triangles[j].nVertexIndices[k];
} }
} }
void Draw( int iMeshIndex ) const void Draw( int iMeshIndex ) const
@@ -851,11 +852,11 @@ void RageDisplay_D3D::DrawQuadsInternal( const RageSpriteVertex v[], int iNumVer
int iNumIndices = iNumTriangles*3; int iNumIndices = iNumTriangles*3;
// make a temporary index buffer // make a temporary index buffer
static std::vector<uint16_t> vIndices; static std::vector<std::uint16_t> vIndices;
std::size_t uOldSize = vIndices.size(); std::size_t uOldSize = vIndices.size();
std::size_t uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices)); std::size_t uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices));
vIndices.resize( uNewSize ); vIndices.resize( uNewSize );
for( uint16_t i=(uint16_t)uOldSize/6; i<(uint16_t)iNumQuads; i++ ) for( std::uint16_t i=(std::uint16_t)uOldSize/6; i<(std::uint16_t)iNumQuads; i++ )
{ {
vIndices[i*6+0] = i*4+0; vIndices[i*6+0] = i*4+0;
vIndices[i*6+1] = i*4+1; vIndices[i*6+1] = i*4+1;
@@ -887,11 +888,11 @@ void RageDisplay_D3D::DrawQuadStripInternal( const RageSpriteVertex v[], int iNu
int iNumIndices = iNumTriangles*3; int iNumIndices = iNumTriangles*3;
// make a temporary index buffer // make a temporary index buffer
static std::vector<uint16_t> vIndices; static std::vector<std::uint16_t> vIndices;
std::size_t uOldSize = vIndices.size(); std::size_t uOldSize = vIndices.size();
std::size_t uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices)); std::size_t uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices));
vIndices.resize( uNewSize ); vIndices.resize( uNewSize );
for( uint16_t i=(uint16_t)uOldSize/6; i<(uint16_t)iNumQuads; i++ ) for( std::uint16_t i=(std::uint16_t)uOldSize/6; i<(std::uint16_t)iNumQuads; i++ )
{ {
vIndices[i*6+0] = i*2+0; vIndices[i*6+0] = i*2+0;
vIndices[i*6+1] = i*2+1; vIndices[i*6+1] = i*2+1;
@@ -922,11 +923,11 @@ void RageDisplay_D3D::DrawSymmetricQuadStripInternal( const RageSpriteVertex v[]
int iNumIndices = iNumTriangles*3; int iNumIndices = iNumTriangles*3;
// make a temporary index buffer // make a temporary index buffer
static std::vector<uint16_t> vIndices; static std::vector<std::uint16_t> vIndices;
std::size_t uOldSize = vIndices.size(); std::size_t uOldSize = vIndices.size();
std::size_t uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices)); std::size_t uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices));
vIndices.resize( uNewSize ); vIndices.resize( uNewSize );
for( uint16_t i=(uint16_t)uOldSize/12; i<(uint16_t)iNumPieces; i++ ) for( std::uint16_t i=(std::uint16_t)uOldSize/12; i<(std::uint16_t)iNumPieces; i++ )
{ {
// { 1, 3, 0 } { 1, 4, 3 } { 1, 5, 4 } { 1, 2, 5 } // { 1, 3, 0 } { 1, 4, 3 } { 1, 5, 4 } { 1, 2, 5 }
vIndices[i*12+0] = i*3+1; vIndices[i*12+0] = i*3+1;
@@ -1049,7 +1050,7 @@ int RageDisplay_D3D::GetNumTextureUnits()
return g_DeviceCaps.MaxSimultaneousTextures; return g_DeviceCaps.MaxSimultaneousTextures;
} }
void RageDisplay_D3D::SetTexture( TextureUnit tu, uintptr_t iTexture ) void RageDisplay_D3D::SetTexture( TextureUnit tu, std::uintptr_t iTexture )
{ {
// g_DeviceCaps.MaxSimultaneousTextures = 1; // g_DeviceCaps.MaxSimultaneousTextures = 1;
if( tu >= (int) g_DeviceCaps.MaxSimultaneousTextures ) // not supported if( tu >= (int) g_DeviceCaps.MaxSimultaneousTextures ) // not supported
@@ -1357,7 +1358,7 @@ void RageDisplay_D3D::SetCullMode( CullMode mode )
} }
} }
void RageDisplay_D3D::DeleteTexture( uintptr_t iTexHandle ) void RageDisplay_D3D::DeleteTexture( std::uintptr_t iTexHandle )
{ {
if( iTexHandle == 0 ) if( iTexHandle == 0 )
return; return;
@@ -1373,7 +1374,7 @@ void RageDisplay_D3D::DeleteTexture( uintptr_t iTexHandle )
} }
uintptr_t RageDisplay_D3D::CreateTexture( std::uintptr_t RageDisplay_D3D::CreateTexture(
RagePixelFormat pixfmt, RagePixelFormat pixfmt,
RageSurface* img, RageSurface* img,
bool bGenerateMipMaps ) bool bGenerateMipMaps )
@@ -1386,7 +1387,7 @@ uintptr_t RageDisplay_D3D::CreateTexture(
RageException::Throw( "CreateTexture(%i,%i,%s) failed: %s", RageException::Throw( "CreateTexture(%i,%i,%s) failed: %s",
img->w, img->h, RagePixelFormatToString(pixfmt).c_str(), GetErrorString(hr).c_str() ); img->w, img->h, RagePixelFormatToString(pixfmt).c_str(), GetErrorString(hr).c_str() );
uintptr_t uTexHandle = reinterpret_cast<uintptr_t>(pTex); std::uintptr_t uTexHandle = reinterpret_cast<std::uintptr_t>(pTex);
if( pixfmt == RagePixelFormat_PAL ) if( pixfmt == RagePixelFormat_PAL )
{ {
@@ -1412,7 +1413,7 @@ uintptr_t RageDisplay_D3D::CreateTexture(
} }
void RageDisplay_D3D::UpdateTexture( void RageDisplay_D3D::UpdateTexture(
uintptr_t uTexHandle, std::uintptr_t uTexHandle,
RageSurface* img, RageSurface* img,
int xoffset, int yoffset, int width, int height ) int xoffset, int yoffset, int width, int height )
{ {
+6 -4
View File
@@ -5,6 +5,8 @@
#include "RageDisplay.h" #include "RageDisplay.h"
#include <cstdint>
class RageDisplay_D3D: public RageDisplay class RageDisplay_D3D: public RageDisplay
{ {
public: public:
@@ -24,19 +26,19 @@ public:
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false ); bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsThreadedRendering(); bool SupportsThreadedRendering();
bool SupportsPerVertexMatrixScale() { return false; } bool SupportsPerVertexMatrixScale() { return false; }
uintptr_t CreateTexture( std::uintptr_t CreateTexture(
RagePixelFormat pixfmt, RagePixelFormat pixfmt,
RageSurface* img, RageSurface* img,
bool bGenerateMipMaps ); bool bGenerateMipMaps );
void UpdateTexture( void UpdateTexture(
uintptr_t iTexHandle, std::uintptr_t iTexHandle,
RageSurface* img, RageSurface* img,
int xoffset, int yoffset, int width, int height int xoffset, int yoffset, int width, int height
); );
void DeleteTexture( uintptr_t iTexHandle ); void DeleteTexture( std::uintptr_t iTexHandle );
void ClearAllTextures(); void ClearAllTextures();
int GetNumTextureUnits(); int GetNumTextureUnits();
void SetTexture( TextureUnit tu, uintptr_t iTexture ); void SetTexture( TextureUnit tu, std::uintptr_t iTexture );
void SetTextureMode( TextureUnit tu, TextureMode tm ); void SetTextureMode( TextureUnit tu, TextureMode tm );
void SetTextureWrapping( TextureUnit tu, bool b ); void SetTextureWrapping( TextureUnit tu, bool b );
int GetMaxTextureSize() const; int GetMaxTextureSize() const;
+5 -4
View File
@@ -17,6 +17,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <cstddef> #include <cstddef>
#include <cstdint>
#ifdef NO_GL_FLUSH #ifdef NO_GL_FLUSH
#define glFlush() #define glFlush()
@@ -562,7 +563,7 @@ RageDisplay_GLES2::SupportsPerVertexMatrixScale()
return true; return true;
} }
uintptr_t std::uintptr_t
RageDisplay_GLES2::CreateTexture( RageDisplay_GLES2::CreateTexture(
RagePixelFormat pixfmt, RagePixelFormat pixfmt,
RageSurface* img, RageSurface* img,
@@ -575,7 +576,7 @@ RageDisplay_GLES2::CreateTexture(
void void
RageDisplay_GLES2::UpdateTexture( RageDisplay_GLES2::UpdateTexture(
uintptr_t iTexHandle, std::uintptr_t iTexHandle,
RageSurface* img, RageSurface* img,
int xoffset, int yoffset, int width, int height int xoffset, int yoffset, int width, int height
) )
@@ -584,7 +585,7 @@ RageDisplay_GLES2::UpdateTexture(
} }
void void
RageDisplay_GLES2::DeleteTexture( uintptr_t iTexHandle ) RageDisplay_GLES2::DeleteTexture( std::uintptr_t iTexHandle )
{ {
// TODO // TODO
} }
@@ -616,7 +617,7 @@ SetTextureUnit( TextureUnit tu )
} }
void void
RageDisplay_GLES2::SetTexture( TextureUnit tu, uintptr_t iTexture ) RageDisplay_GLES2::SetTexture( TextureUnit tu, std::uintptr_t iTexture )
{ {
if (!SetTextureUnit( tu )) if (!SetTextureUnit( tu ))
return; return;
+6 -4
View File
@@ -1,6 +1,8 @@
#ifndef RAGE_DISPLAY_GLES2_H #ifndef RAGE_DISPLAY_GLES2_H
#define RAGE_DISPLAY_GLES2_H #define RAGE_DISPLAY_GLES2_H
#include <cstdint>
class RageDisplay_GLES2: public RageDisplay class RageDisplay_GLES2: public RageDisplay
{ {
public: public:
@@ -18,18 +20,18 @@ public:
void SetBlendMode( BlendMode mode ); void SetBlendMode( BlendMode mode );
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false ); bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsPerVertexMatrixScale(); bool SupportsPerVertexMatrixScale();
uintptr_t CreateTexture( std::uintptr_t CreateTexture(
RagePixelFormat pixfmt, RagePixelFormat pixfmt,
RageSurface* img, RageSurface* img,
bool bGenerateMipMaps ); bool bGenerateMipMaps );
void UpdateTexture( void UpdateTexture(
uintptr_t iTexHandle, std::uintptr_t iTexHandle,
RageSurface* img, RageSurface* img,
int xoffset, int yoffset, int width, int height ); int xoffset, int yoffset, int width, int height );
void DeleteTexture( uintptr_t iTexHandle ); void DeleteTexture( std::uintptr_t iTexHandle );
void ClearAllTextures(); void ClearAllTextures();
int GetNumTextureUnits(); int GetNumTextureUnits();
void SetTexture( TextureUnit tu, uintptr_t iTexture ); void SetTexture( TextureUnit tu, std::uintptr_t iTexture );
void SetTextureMode( TextureUnit tu, TextureMode tm ); void SetTextureMode( TextureUnit tu, TextureMode tm );
void SetTextureWrapping( TextureUnit tu, bool b ); void SetTextureWrapping( TextureUnit tu, bool b );
int GetMaxTextureSize() const; int GetMaxTextureSize() const;
+6 -4
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_DISPLAY_NULL_H #ifndef RAGE_DISPLAY_NULL_H
#define RAGE_DISPLAY_NULL_H #define RAGE_DISPLAY_NULL_H
#include <cstdint>
class RageDisplay_Null: public RageDisplay class RageDisplay_Null: public RageDisplay
{ {
public: public:
@@ -19,19 +21,19 @@ public:
void SetBlendMode( BlendMode ) { } void SetBlendMode( BlendMode ) { }
bool SupportsTextureFormat( RagePixelFormat, bool /* realtime */ =false ) { return true; } bool SupportsTextureFormat( RagePixelFormat, bool /* realtime */ =false ) { return true; }
bool SupportsPerVertexMatrixScale() { return false; } bool SupportsPerVertexMatrixScale() { return false; }
uintptr_t CreateTexture( std::uintptr_t CreateTexture(
RagePixelFormat, RagePixelFormat,
RageSurface* /* img */, RageSurface* /* img */,
bool /* bGenerateMipMaps */ ) { return 1; } bool /* bGenerateMipMaps */ ) { return 1; }
void UpdateTexture( void UpdateTexture(
uintptr_t /* iTexHandle */, std::uintptr_t /* iTexHandle */,
RageSurface* /* img */, RageSurface* /* img */,
int /* xoffset */, int /* yoffset */, int /* width */, int /* height */ int /* xoffset */, int /* yoffset */, int /* width */, int /* height */
) { } ) { }
void DeleteTexture( uintptr_t /* iTexHandle */ ) { } void DeleteTexture( std::uintptr_t /* iTexHandle */ ) { }
void ClearAllTextures() { } void ClearAllTextures() { }
int GetNumTextureUnits() { return 1; } int GetNumTextureUnits() { return 1; }
void SetTexture( TextureUnit, uintptr_t /* iTexture */ ) { } void SetTexture( TextureUnit, std::uintptr_t /* iTexture */ ) { }
void SetTextureMode( TextureUnit, TextureMode ) { } void SetTextureMode( TextureUnit, TextureMode ) { }
void SetTextureWrapping( TextureUnit, bool ) { } void SetTextureWrapping( TextureUnit, bool ) { }
int GetMaxTextureSize() const { return 2048; } int GetMaxTextureSize() const { return 2048; }
+26 -25
View File
@@ -21,6 +21,7 @@ using namespace RageDisplay_Legacy_Helpers;
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <set> #include <set>
#if defined(WINDOWS) #if defined(WINDOWS)
@@ -64,7 +65,7 @@ static const GLenum RageSpriteVertexFormat = GL_T2F_C4F_N3F_V3F;
/* If we support texture matrix scaling, a handle to the vertex program: */ /* If we support texture matrix scaling, a handle to the vertex program: */
static GLhandleARB g_bTextureMatrixShader = 0; static GLhandleARB g_bTextureMatrixShader = 0;
static std::map<uintptr_t, RenderTarget *> g_mapRenderTargets; static std::map<std::uintptr_t, RenderTarget *> g_mapRenderTargets;
static RenderTarget *g_pCurrentRenderTarget = nullptr; static RenderTarget *g_pCurrentRenderTarget = nullptr;
static LowLevelWindow *g_pWind; static LowLevelWindow *g_pWind;
@@ -799,7 +800,7 @@ RString RageDisplay_Legacy::TryVideoMode( const VideoModeParams &p, bool &bNewDe
/* Delete all render targets. They may have associated resources other than /* Delete all render targets. They may have associated resources other than
* the texture itself. */ * the texture itself. */
for (std::pair<uintptr_t const, RenderTarget *> &rt : g_mapRenderTargets) for (std::pair<std::uintptr_t const, RenderTarget *> &rt : g_mapRenderTargets)
delete rt.second; delete rt.second;
g_mapRenderTargets.clear(); g_mapRenderTargets.clear();
@@ -926,7 +927,7 @@ RageSurface* RageDisplay_Legacy::CreateScreenshot()
return image; return image;
} }
RageSurface *RageDisplay_Legacy::GetTexture( uintptr_t iTexture ) RageSurface *RageDisplay_Legacy::GetTexture( std::uintptr_t iTexture )
{ {
if (iTexture == 0) if (iTexture == 0)
return nullptr; // XXX return nullptr; // XXX
@@ -1070,7 +1071,7 @@ public:
for( unsigned k=0; k<3; k++ ) for( unsigned k=0; k<3; k++ )
{ {
int iVertexIndexInVBO = meshInfo.iVertexStart + Triangles[j].nVertexIndices[k]; int iVertexIndexInVBO = meshInfo.iVertexStart + Triangles[j].nVertexIndices[k];
m_vTriangles[meshInfo.iTriangleStart+j].nVertexIndices[k] = (uint16_t) iVertexIndexInVBO; m_vTriangles[meshInfo.iTriangleStart+j].nVertexIndices[k] = (std::uint16_t) iVertexIndexInVBO;
} }
} }
} }
@@ -1512,11 +1513,11 @@ void RageDisplay_Legacy::DrawSymmetricQuadStripInternal( const RageSpriteVertex
int iNumIndices = iNumTriangles*3; int iNumIndices = iNumTriangles*3;
// make a temporary index buffer // make a temporary index buffer
static std::vector<uint16_t> vIndices; static std::vector<std::uint16_t> vIndices;
unsigned uOldSize = vIndices.size(); unsigned uOldSize = vIndices.size();
unsigned uNewSize = std::max(uOldSize,(unsigned)iNumIndices); unsigned uNewSize = std::max(uOldSize,(unsigned)iNumIndices);
vIndices.resize( uNewSize ); vIndices.resize( uNewSize );
for( uint16_t i=(uint16_t)uOldSize/12; i<(uint16_t)iNumPieces; i++ ) for( std::uint16_t i=(std::uint16_t)uOldSize/12; i<(std::uint16_t)iNumPieces; i++ )
{ {
// { 1, 3, 0 } { 1, 4, 3 } { 1, 5, 4 } { 1, 2, 5 } // { 1, 3, 0 } { 1, 4, 3 } { 1, 5, 4 } { 1, 2, 5 }
vIndices[i*12+0] = i*3+1; vIndices[i*12+0] = i*3+1;
@@ -1686,7 +1687,7 @@ int RageDisplay_Legacy::GetNumTextureUnits()
return g_iMaxTextureUnits; return g_iMaxTextureUnits;
} }
void RageDisplay_Legacy::SetTexture( TextureUnit tu, uintptr_t iTexture ) void RageDisplay_Legacy::SetTexture( TextureUnit tu, std::uintptr_t iTexture )
{ {
if (!SetTextureUnit( tu )) if (!SetTextureUnit( tu ))
return; return;
@@ -2113,7 +2114,7 @@ void RageDisplay_Legacy::EndConcurrentRendering()
g_pWind->EndConcurrentRendering(); g_pWind->EndConcurrentRendering();
} }
void RageDisplay_Legacy::DeleteTexture( uintptr_t iTexture ) void RageDisplay_Legacy::DeleteTexture( std::uintptr_t iTexture )
{ {
if (iTexture == 0) if (iTexture == 0)
return; return;
@@ -2198,7 +2199,7 @@ void SetPixelMapForSurface( int glImageFormat, int glTexFormat, const RageSurfac
DebugAssertNoGLError(); DebugAssertNoGLError();
} }
uintptr_t RageDisplay_Legacy::CreateTexture( std::uintptr_t RageDisplay_Legacy::CreateTexture(
RagePixelFormat pixfmt, RagePixelFormat pixfmt,
RageSurface* pImg, RageSurface* pImg,
bool bGenerateMipMaps ) bool bGenerateMipMaps )
@@ -2243,7 +2244,7 @@ uintptr_t RageDisplay_Legacy::CreateTexture(
SetTextureUnit( TextureUnit_1 ); SetTextureUnit( TextureUnit_1 );
// allocate OpenGL texture resource // allocate OpenGL texture resource
uintptr_t iTexHandle; std::uintptr_t iTexHandle;
glGenTextures( 1, reinterpret_cast<GLuint*>(&iTexHandle) ); glGenTextures( 1, reinterpret_cast<GLuint*>(&iTexHandle) );
ASSERT( iTexHandle != 0 ); ASSERT( iTexHandle != 0 );
@@ -2359,7 +2360,7 @@ public:
m_iTexHandle = 0; m_iTexHandle = 0;
} }
void Lock( uintptr_t iTexHandle, RageSurface *pSurface ) void Lock( std::uintptr_t iTexHandle, RageSurface *pSurface )
{ {
ASSERT( m_iTexHandle == 0 ); ASSERT( m_iTexHandle == 0 );
ASSERT( pSurface->pixels == nullptr ); ASSERT( pSurface->pixels == nullptr );
@@ -2373,7 +2374,7 @@ public:
glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, iSize, nullptr, GL_STREAM_DRAW ); glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, iSize, nullptr, GL_STREAM_DRAW );
void *pSurfaceMemory = glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY ); void *pSurfaceMemory = glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY );
pSurface->pixels = (uint8_t *) pSurfaceMemory; pSurface->pixels = (std::uint8_t *) pSurfaceMemory;
pSurface->pixels_owned = false; pSurface->pixels_owned = false;
} }
@@ -2381,7 +2382,7 @@ public:
{ {
glUnmapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB ); glUnmapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB );
pSurface->pixels = (uint8_t *) BUFFER_OFFSET(0); pSurface->pixels = (std::uint8_t *) BUFFER_OFFSET(0);
if (bChanged) if (bChanged)
DISPLAY->UpdateTexture( m_iTexHandle, pSurface, 0, 0, pSurface->w, pSurface->h ); DISPLAY->UpdateTexture( m_iTexHandle, pSurface, 0, 0, pSurface->w, pSurface->h );
@@ -2405,7 +2406,7 @@ private:
GLuint m_iBuffer; GLuint m_iBuffer;
uintptr_t m_iTexHandle; std::uintptr_t m_iTexHandle;
}; };
RageTextureLock *RageDisplay_Legacy::CreateTextureLock() RageTextureLock *RageDisplay_Legacy::CreateTextureLock()
@@ -2417,7 +2418,7 @@ RageTextureLock *RageDisplay_Legacy::CreateTextureLock()
} }
void RageDisplay_Legacy::UpdateTexture( void RageDisplay_Legacy::UpdateTexture(
uintptr_t iTexHandle, std::uintptr_t iTexHandle,
RageSurface* pImg, RageSurface* pImg,
int iXOffset, int iYOffset, int iWidth, int iHeight ) int iXOffset, int iYOffset, int iWidth, int iHeight )
{ {
@@ -2459,16 +2460,16 @@ public:
RenderTarget_FramebufferObject(); RenderTarget_FramebufferObject();
~RenderTarget_FramebufferObject(); ~RenderTarget_FramebufferObject();
void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ); void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut );
uintptr_t GetTexture() const { return m_iTexHandle; } std::uintptr_t GetTexture() const { return m_iTexHandle; }
void StartRenderingTo(); void StartRenderingTo();
void FinishRenderingTo(); void FinishRenderingTo();
virtual bool InvertY() const { return true; } virtual bool InvertY() const { return true; }
private: private:
uintptr_t m_iFrameBufferHandle; std::uintptr_t m_iFrameBufferHandle;
uintptr_t m_iTexHandle; std::uintptr_t m_iTexHandle;
uintptr_t m_iDepthBufferHandle; std::uintptr_t m_iDepthBufferHandle;
}; };
RenderTarget_FramebufferObject::RenderTarget_FramebufferObject() RenderTarget_FramebufferObject::RenderTarget_FramebufferObject()
@@ -2591,7 +2592,7 @@ bool RageDisplay_Legacy::SupportsFullscreenBorderlessWindow() const
* particularly GeForce 2, but is simpler and faster when available. * particularly GeForce 2, but is simpler and faster when available.
*/ */
uintptr_t RageDisplay_Legacy::CreateRenderTarget( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ) std::uintptr_t RageDisplay_Legacy::CreateRenderTarget( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut )
{ {
RenderTarget *pTarget; RenderTarget *pTarget;
if (GLEW_EXT_framebuffer_object) if (GLEW_EXT_framebuffer_object)
@@ -2601,22 +2602,22 @@ uintptr_t RageDisplay_Legacy::CreateRenderTarget( const RenderTargetParam &param
pTarget->Create( param, iTextureWidthOut, iTextureHeightOut ); pTarget->Create( param, iTextureWidthOut, iTextureHeightOut );
uintptr_t iTexture = pTarget->GetTexture(); std::uintptr_t iTexture = pTarget->GetTexture();
ASSERT( g_mapRenderTargets.find(iTexture) == g_mapRenderTargets.end() ); ASSERT( g_mapRenderTargets.find(iTexture) == g_mapRenderTargets.end() );
g_mapRenderTargets[iTexture] = pTarget; g_mapRenderTargets[iTexture] = pTarget;
return iTexture; return iTexture;
} }
uintptr_t RageDisplay_Legacy::GetRenderTarget() std::uintptr_t RageDisplay_Legacy::GetRenderTarget()
{ {
for( std::map<uintptr_t, RenderTarget*>::const_iterator it = g_mapRenderTargets.begin(); it != g_mapRenderTargets.end(); ++it ) for( std::map<std::uintptr_t, RenderTarget*>::const_iterator it = g_mapRenderTargets.begin(); it != g_mapRenderTargets.end(); ++it )
if( it->second == g_pCurrentRenderTarget ) if( it->second == g_pCurrentRenderTarget )
return it->first; return it->first;
return 0; return 0;
} }
void RageDisplay_Legacy::SetRenderTarget( uintptr_t iTexture, bool bPreserveTexture ) void RageDisplay_Legacy::SetRenderTarget( std::uintptr_t iTexture, bool bPreserveTexture )
{ {
if (iTexture == 0) if (iTexture == 0)
{ {
@@ -2695,7 +2696,7 @@ void RageDisplay_Legacy::SetLineWidth(float fWidth)
glLineWidth(fWidth); glLineWidth(fWidth);
} }
RString RageDisplay_Legacy::GetTextureDiagnostics(uintptr_t iTexture) const RString RageDisplay_Legacy::GetTextureDiagnostics(std::uintptr_t iTexture) const
{ {
/* /*
s << (bGenerateMipMaps? "gluBuild2DMipmaps":"glTexImage2D"); s << (bGenerateMipMaps? "gluBuild2DMipmaps":"glTexImage2D");
+11 -9
View File
@@ -11,6 +11,8 @@
#include "RageTextureRenderTarget.h" #include "RageTextureRenderTarget.h"
#include "Sprite.h" #include "Sprite.h"
#include <cstdint>
/* Making an OpenGL call doesn't also flush the error state; if we happen /* Making an OpenGL call doesn't also flush the error state; if we happen
* to have an error from a previous call, then the assert below will fail. * to have an error from a previous call, then the assert below will fail.
* Flush it. */ * Flush it. */
@@ -53,23 +55,23 @@ public:
void SetBlendMode( BlendMode mode ); void SetBlendMode( BlendMode mode );
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false ); bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsPerVertexMatrixScale(); bool SupportsPerVertexMatrixScale();
uintptr_t CreateTexture( std::uintptr_t CreateTexture(
RagePixelFormat pixfmt, RagePixelFormat pixfmt,
RageSurface* img, RageSurface* img,
bool bGenerateMipMaps ); bool bGenerateMipMaps );
void UpdateTexture( void UpdateTexture(
uintptr_t iTexHandle, std::uintptr_t iTexHandle,
RageSurface* img, RageSurface* img,
int xoffset, int yoffset, int width, int height int xoffset, int yoffset, int width, int height
); );
void DeleteTexture( uintptr_t iTexHandle ); void DeleteTexture( std::uintptr_t iTexHandle );
bool UseOffscreenRenderTarget(); bool UseOffscreenRenderTarget();
RageSurface *GetTexture( uintptr_t iTexture ); RageSurface *GetTexture( std::uintptr_t iTexture );
RageTextureLock *CreateTextureLock(); RageTextureLock *CreateTextureLock();
void ClearAllTextures(); void ClearAllTextures();
int GetNumTextureUnits(); int GetNumTextureUnits();
void SetTexture( TextureUnit tu, uintptr_t iTexture ); void SetTexture( TextureUnit tu, std::uintptr_t iTexture );
void SetTextureMode( TextureUnit tu, TextureMode tm ); void SetTextureMode( TextureUnit tu, TextureMode tm );
void SetTextureWrapping( TextureUnit tu, bool b ); void SetTextureWrapping( TextureUnit tu, bool b );
int GetMaxTextureSize() const; int GetMaxTextureSize() const;
@@ -78,9 +80,9 @@ public:
bool IsEffectModeSupported( EffectMode effect ); bool IsEffectModeSupported( EffectMode effect );
bool SupportsRenderToTexture() const; bool SupportsRenderToTexture() const;
bool SupportsFullscreenBorderlessWindow() const; bool SupportsFullscreenBorderlessWindow() const;
uintptr_t CreateRenderTarget( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ); std::uintptr_t CreateRenderTarget( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut );
uintptr_t GetRenderTarget(); std::uintptr_t GetRenderTarget();
void SetRenderTarget( uintptr_t iHandle, bool bPreserveTexture ); void SetRenderTarget( std::uintptr_t iHandle, bool bPreserveTexture );
bool IsZWriteEnabled() const; bool IsZWriteEnabled() const;
bool IsZTestEnabled() const; bool IsZTestEnabled() const;
void SetZWrite( bool b ); void SetZWrite( bool b );
@@ -115,7 +117,7 @@ public:
virtual void SetPolygonMode( PolygonMode pm ); virtual void SetPolygonMode( PolygonMode pm );
virtual void SetLineWidth( float fWidth ); virtual void SetLineWidth( float fWidth );
RString GetTextureDiagnostics( uintptr_t id ) const; RString GetTextureDiagnostics( std::uintptr_t id ) const;
protected: protected:
void DrawQuadsInternal( const RageSpriteVertex v[], int iNumVerts ); void DrawQuadsInternal( const RageSpriteVertex v[], int iNumVerts );
+6 -4
View File
@@ -1,15 +1,17 @@
#ifndef RAGE_DISPLAY_OGL_HELPERS_H #ifndef RAGE_DISPLAY_OGL_HELPERS_H
#define RAGE_DISPLAY_OGL_HELPERS_H #define RAGE_DISPLAY_OGL_HELPERS_H
/* Import RageDisplay, for types. Do not include RageDisplay_Legacy.h. */
#include "RageDisplay.h"
#include <cstdint>
#if defined(WIN32) #if defined(WIN32)
#include <windows.h> #include <windows.h>
#endif #endif
#include <GL/glew.h> #include <GL/glew.h>
/* Import RageDisplay, for types. Do not include RageDisplay_Legacy.h. */
#include "RageDisplay.h"
/* Windows defines GL_EXT_paletted_texture incompletely: */ /* Windows defines GL_EXT_paletted_texture incompletely: */
#ifndef GL_TEXTURE_INDEX_SIZE_EXT #ifndef GL_TEXTURE_INDEX_SIZE_EXT
#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED #define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
@@ -28,7 +30,7 @@ public:
virtual ~RenderTarget() { } virtual ~RenderTarget() { }
virtual void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ) = 0; virtual void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ) = 0;
virtual uintptr_t GetTexture() const = 0; virtual std::uintptr_t GetTexture() const = 0;
/* Render to this RenderTarget. */ /* Render to this RenderTarget. */
virtual void StartRenderingTo() = 0; virtual void StartRenderingTo() = 0;
+2 -1
View File
@@ -5,6 +5,7 @@
#include "RageThreads.h" #include "RageThreads.h"
#include <cstdarg> #include <cstdarg>
#include <cstdint>
#if defined(_WINDOWS) && defined(DEBUG) #if defined(_WINDOWS) && defined(DEBUG)
#include <windows.h> #include <windows.h>
@@ -14,7 +15,7 @@ using CrashHandler::IsDebuggerPresent;
using CrashHandler::DebugBreak; using CrashHandler::DebugBreak;
#endif #endif
static uint64_t g_HandlerThreadID = RageThread::GetInvalidThreadID(); static std::uint64_t g_HandlerThreadID = RageThread::GetInvalidThreadID();
static void (*g_CleanupHandler)( const RString &sError ) = nullptr; static void (*g_CleanupHandler)( const RString &sError ) = nullptr;
void RageException::SetCleanupHandler( void (*pHandler)(const RString &sError) ) void RageException::SetCleanupHandler( void (*pHandler)(const RString &sError) )
{ {
+17 -16
View File
@@ -13,6 +13,7 @@
#include "RageFileDriver.h" #include "RageFileDriver.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
RageFile::RageFile() RageFile::RageFile()
{ {
@@ -110,7 +111,7 @@ void RageFile::EnableCRC32( bool on )
m_File->EnableCRC32( on ); m_File->EnableCRC32( on );
} }
bool RageFile::GetCRC32( uint32_t *iRet ) bool RageFile::GetCRC32( std::uint32_t *iRet )
{ {
ASSERT_OPEN; ASSERT_OPEN;
return m_File->GetCRC32( iRet ); return m_File->GetCRC32( iRet );
@@ -266,50 +267,50 @@ void FileReading::Seek( RageFileBasic &f, int iOffset, RString &sError )
sError = "Unexpected end of file"; sError = "Unexpected end of file";
} }
uint8_t FileReading::read_8( RageFileBasic &f, RString &sError ) std::uint8_t FileReading::read_8( RageFileBasic &f, RString &sError )
{ {
uint8_t val; std::uint8_t val;
ReadBytes( f, &val, sizeof(uint8_t), sError ); ReadBytes( f, &val, sizeof(std::uint8_t), sError );
if( sError.size() == 0 ) if( sError.size() == 0 )
return val; return val;
else else
return 0; return 0;
} }
uint16_t FileReading::read_u16_le( RageFileBasic &f, RString &sError ) std::uint16_t FileReading::read_u16_le( RageFileBasic &f, RString &sError )
{ {
uint16_t val; std::uint16_t val;
ReadBytes( f, &val, sizeof(uint16_t), sError ); ReadBytes( f, &val, sizeof(std::uint16_t), sError );
if( sError.size() == 0 ) if( sError.size() == 0 )
return Swap16LE( val ); return Swap16LE( val );
else else
return 0; return 0;
} }
int16_t FileReading::read_16_le( RageFileBasic &f, RString &sError ) std::int16_t FileReading::read_16_le( RageFileBasic &f, RString &sError )
{ {
int16_t val; std::int16_t val;
ReadBytes( f, &val, sizeof(int16_t), sError ); ReadBytes( f, &val, sizeof(std::int16_t), sError );
if( sError.size() == 0 ) if( sError.size() == 0 )
return Swap16LE( val ); return Swap16LE( val );
else else
return 0; return 0;
} }
uint32_t FileReading::read_u32_le( RageFileBasic &f, RString &sError ) std::uint32_t FileReading::read_u32_le( RageFileBasic &f, RString &sError )
{ {
uint32_t val; std::uint32_t val;
ReadBytes( f, &val, sizeof(uint32_t), sError ); ReadBytes( f, &val, sizeof(std::uint32_t), sError );
if( sError.size() == 0 ) if( sError.size() == 0 )
return Swap32LE( val ); return Swap32LE( val );
else else
return 0; return 0;
} }
int32_t FileReading::read_32_le( RageFileBasic &f, RString &sError ) std::int32_t FileReading::read_32_le( RageFileBasic &f, RString &sError )
{ {
int32_t val; std::int32_t val;
ReadBytes( f, &val, sizeof(int32_t), sError ); ReadBytes( f, &val, sizeof(std::int32_t), sError );
if( sError.size() == 0 ) if( sError.size() == 0 )
return Swap32LE( val ); return Swap32LE( val );
else else
+7 -6
View File
@@ -6,6 +6,7 @@
#include "RageFileBasic.h" #include "RageFileBasic.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
struct lua_State; struct lua_State;
@@ -77,7 +78,7 @@ public:
int PutLine( const RString &str ); int PutLine( const RString &str );
void EnableCRC32( bool on=true ); void EnableCRC32( bool on=true );
bool GetCRC32( uint32_t *iRet ); bool GetCRC32( std::uint32_t *iRet );
// Lua // Lua
virtual void PushSelf( lua_State *L ); virtual void PushSelf( lua_State *L );
@@ -102,11 +103,11 @@ namespace FileReading
void SkipBytes( RageFileBasic &f, int size, RString &sError ); void SkipBytes( RageFileBasic &f, int size, RString &sError );
void Seek( RageFileBasic &f, int iOffset, RString &sError ); void Seek( RageFileBasic &f, int iOffset, RString &sError );
RString ReadString( RageFileBasic &f, int size, RString &sError ); RString ReadString( RageFileBasic &f, int size, RString &sError );
uint8_t read_8( RageFileBasic &f, RString &sError ); std::uint8_t read_8( RageFileBasic &f, RString &sError );
int16_t read_16_le( RageFileBasic &f, RString &sError ); std::int16_t read_16_le( RageFileBasic &f, RString &sError );
uint16_t read_u16_le( RageFileBasic &f, RString &sError ); std::uint16_t read_u16_le( RageFileBasic &f, RString &sError );
int32_t read_32_le( RageFileBasic &f, RString &sError ); std::int32_t read_32_le( RageFileBasic &f, RString &sError );
uint32_t read_u32_le( RageFileBasic &f, RString &sError ); std::uint32_t read_u32_le( RageFileBasic &f, RString &sError );
}; };
#endif #endif
+2 -1
View File
@@ -4,6 +4,7 @@
#include "RageUtil_AutoPtr.h" #include "RageUtil_AutoPtr.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
REGISTER_CLASS_TRAITS( RageFileBasic, pCopy->Copy() ); REGISTER_CLASS_TRAITS( RageFileBasic, pCopy->Copy() );
@@ -313,7 +314,7 @@ void RageFileObj::EnableCRC32( bool bOn )
m_iCRC32 = 0; m_iCRC32 = 0;
} }
bool RageFileObj::GetCRC32( uint32_t *iRet ) bool RageFileObj::GetCRC32( std::uint32_t *iRet )
{ {
if( !m_bCRC32Enabled ) if( !m_bCRC32Enabled )
return false; return false;
+4 -3
View File
@@ -6,6 +6,7 @@
#include "global.h" #include "global.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
/* This is a simple file I/O interface. Although most of these operations /* This is a simple file I/O interface. Although most of these operations
* are straightforward, there are several of them; most of the time, you'll * are straightforward, there are several of them; most of the time, you'll
@@ -54,7 +55,7 @@ public:
virtual int PutLine( const RString &str ) = 0; virtual int PutLine( const RString &str ) = 0;
virtual void EnableCRC32( bool on=true ) = 0; virtual void EnableCRC32( bool on=true ) = 0;
virtual bool GetCRC32( uint32_t *iRet ) = 0; virtual bool GetCRC32( std::uint32_t *iRet ) = 0;
virtual int GetFileSize() const = 0; virtual int GetFileSize() const = 0;
@@ -94,7 +95,7 @@ public:
int PutLine( const RString &str ); int PutLine( const RString &str );
void EnableCRC32( bool on=true ); void EnableCRC32( bool on=true );
bool GetCRC32( uint32_t *iRet ); bool GetCRC32( std::uint32_t *iRet );
virtual int GetFileSize() const = 0; virtual int GetFileSize() const = 0;
virtual int GetFD() { return -1; } virtual int GetFD() { return -1; }
@@ -155,7 +156,7 @@ private:
* This is only meaningful if EnableCRC32() is called at the very start of the * This is only meaningful if EnableCRC32() is called at the very start of the
* file, and no seeking is performed. */ * file, and no seeking is performed. */
bool m_bCRC32Enabled; bool m_bCRC32Enabled;
uint32_t m_iCRC32; std::uint32_t m_iCRC32;
// Swallow up warnings. If they must be used, define them. // Swallow up warnings. If they must be used, define them.
RageFileObj& operator=(const RageFileObj& rhs); RageFileObj& operator=(const RageFileObj& rhs);
+13 -12
View File
@@ -6,6 +6,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <memory> #include <memory>
#if defined(_WINDOWS) #if defined(_WINDOWS)
@@ -313,7 +314,7 @@ int RageFileObjDeflate::FlushInternal()
* Parse a .gz file, check the header CRC16 if present, and return the data * Parse a .gz file, check the header CRC16 if present, and return the data
* CRC32 and a decompressor. pFile will be deleted. * CRC32 and a decompressor. pFile will be deleted.
*/ */
RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t *iCRC32 ) RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, std::uint32_t *iCRC32 )
{ {
std::unique_ptr<RageFileBasic> pFile(pFile_); std::unique_ptr<RageFileBasic> pFile(pFile_);
@@ -335,8 +336,8 @@ RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t
} }
} }
uint8_t iCompressionMethod = FileReading::read_8( *pFile, sError ); std::uint8_t iCompressionMethod = FileReading::read_8( *pFile, sError );
uint8_t iFlags = FileReading::read_8( *pFile, sError ); std::uint8_t iFlags = FileReading::read_8( *pFile, sError );
FileReading::read_32_le( *pFile, sError ); /* time */ FileReading::read_32_le( *pFile, sError ); /* time */
FileReading::read_8( *pFile, sError ); /* xfl */ FileReading::read_8( *pFile, sError ); /* xfl */
FileReading::read_8( *pFile, sError ); /* os */ FileReading::read_8( *pFile, sError ); /* os */
@@ -365,7 +366,7 @@ RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t
if( iFlags & FEXTRA ) if( iFlags & FEXTRA )
{ {
int16_t iSize = FileReading::read_16_le( *pFile, sError ); std::int16_t iSize = FileReading::read_16_le( *pFile, sError );
FileReading::SkipBytes( *pFile, iSize, sError ); FileReading::SkipBytes( *pFile, iSize, sError );
} }
@@ -380,12 +381,12 @@ RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t
{ {
/* Get the CRC of the data read so far. Be sure to do this before /* Get the CRC of the data read so far. Be sure to do this before
* reading iExpectedCRC16. */ * reading iExpectedCRC16. */
uint32_t iActualCRC32; std::uint32_t iActualCRC32;
bool bOK = pFile->GetCRC32( &iActualCRC32 ); bool bOK = pFile->GetCRC32( &iActualCRC32 );
ASSERT( bOK ); ASSERT( bOK );
uint16_t iExpectedCRC16 = FileReading::read_u16_le( *pFile, sError ); std::uint16_t iExpectedCRC16 = FileReading::read_u16_le( *pFile, sError );
uint16_t iActualCRC16 = int16_t( iActualCRC32 & 0xFFFF ); std::uint16_t iActualCRC16 = std::int16_t( iActualCRC32 & 0xFFFF );
if( sError != "" ) if( sError != "" )
return nullptr; return nullptr;
@@ -410,8 +411,8 @@ RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t
FileReading::Seek( *pFile, iFooterPos, sError ); FileReading::Seek( *pFile, iFooterPos, sError );
uint32_t iExpectedCRC32 = FileReading::read_u32_le( *pFile, sError ); std::uint32_t iExpectedCRC32 = FileReading::read_u32_le( *pFile, sError );
uint32_t iUncompressedSize = FileReading::read_u32_le( *pFile, sError ); std::uint32_t iUncompressedSize = FileReading::read_u32_le( *pFile, sError );
if( iCRC32 != nullptr ) if( iCRC32 != nullptr )
*iCRC32 = iExpectedCRC32; *iCRC32 = iExpectedCRC32;
@@ -486,12 +487,12 @@ int RageFileObjGzip::Finish()
return -1; return -1;
/* Read the CRC of the data that's been written. */ /* Read the CRC of the data that's been written. */
uint32_t iCRC; std::uint32_t iCRC;
bool bOK = this->GetCRC32( &iCRC ); bool bOK = this->GetCRC32( &iCRC );
ASSERT( bOK ); ASSERT( bOK );
/* Figure out the size of the data. */ /* Figure out the size of the data. */
uint32_t iSize = Tell() - m_iDataStartOffset; std::uint32_t iSize = Tell() - m_iDataStartOffset;
/* Write the CRC and size directly to the file, so they don't get compressed. */ /* Write the CRC and size directly to the file, so they don't get compressed. */
iCRC = Swap32LE( iCRC ); iCRC = Swap32LE( iCRC );
@@ -532,7 +533,7 @@ bool GunzipString( const RString &sIn, RString &sOut, RString &sError )
RageFileObjMem *mem = new RageFileObjMem; RageFileObjMem *mem = new RageFileObjMem;
mem->PutString( sIn ); mem->PutString( sIn );
uint32_t iCRC32; std::uint32_t iCRC32;
RageFileBasic *pFile = GunzipFile( mem, sError, &iCRC32 ); RageFileBasic *pFile = GunzipFile( mem, sError, &iCRC32 );
if( pFile == nullptr ) if( pFile == nullptr )
return false; return false;
+2 -1
View File
@@ -6,6 +6,7 @@
#include "RageFileBasic.h" #include "RageFileBasic.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
typedef struct z_stream_s z_stream; typedef struct z_stream_s z_stream;
@@ -69,7 +70,7 @@ private:
int m_iDataStartOffset; int m_iDataStartOffset;
}; };
RageFileObjInflate *GunzipFile( RageFileBasic *pFile, RString &sError, uint32_t *iCRC32 ); RageFileObjInflate *GunzipFile( RageFileBasic *pFile, RString &sError, std::uint32_t *iCRC32 );
/* Quick helpers: */ /* Quick helpers: */
void GzipString( const RString &sIn, RString &sOut ); void GzipString( const RString &sIn, RString &sOut );
+2 -1
View File
@@ -11,6 +11,7 @@
#include <cerrno> #include <cerrno>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <sstream> #include <sstream>
#if defined(WIN32) #if defined(WIN32)
@@ -117,7 +118,7 @@ std::size_t zipRead(void *pOpaque, mz_uint64 file_ofs, void *pBuf, std::size_t n
RageFile *f = static_cast<RageFile*>(pOpaque); RageFile *f = static_cast<RageFile*>(pOpaque);
const int pos = f->Seek(file_ofs); const int pos = f->Seek(file_ofs);
if (pos >= 0 && static_cast<uint64_t>(pos) != file_ofs) if (pos >= 0 && static_cast<std::uint64_t>(pos) != file_ofs)
{ {
return 0; return 0;
} }
+8 -6
View File
@@ -5,6 +5,8 @@
#include "RageMath.h" #include "RageMath.h"
#include "RageDisplay.h" #include "RageDisplay.h"
#include <cstdint>
#define MS_MAX_NAME 32 #define MS_MAX_NAME 32
RageModelGeometry::RageModelGeometry () RageModelGeometry::RageModelGeometry ()
@@ -69,8 +71,8 @@ void RageModelGeometry::MergeMeshes( int iFromIndex, int iToIndex )
{ {
for( int j=0; j<3; j++ ) for( int j=0; j<3; j++ )
{ {
uint16_t &iIndex = meshTo.Triangles[i].nVertexIndices[j]; std::uint16_t &iIndex = meshTo.Triangles[i].nVertexIndices[j];
iIndex = uint16_t(iIndex + iShiftTriangleVertexIndicesBy); iIndex = std::uint16_t(iIndex + iShiftTriangleVertexIndicesBy);
} }
} }
} }
@@ -147,7 +149,7 @@ void RageModelGeometry::LoadMilkshapeAscii( const RString& _sPath, bool bNeedsNo
mesh.sName = szName; mesh.sName = szName;
// mesh.nFlags = nFlags; // mesh.nFlags = nFlags;
mesh.nMaterialIndex = (uint8_t) nIndex; mesh.nMaterialIndex = (std::uint8_t) nIndex;
mesh.m_iBoneIndex = -1; mesh.m_iBoneIndex = -1;
@@ -190,7 +192,7 @@ void RageModelGeometry::LoadMilkshapeAscii( const RString& _sPath, bool bNeedsNo
v.t[0] = v.p[0] / v.t[0]; v.t[0] = v.p[0] / v.t[0];
v.t[1] = v.p[1] / v.t[1]; v.t[1] = v.p[1] / v.t[1];
} }
v.bone = (uint8_t) nIndex; v.bone = (std::uint8_t) nIndex;
RageVec3AddToBounds( v.p, m_vMins, m_vMaxs ); RageVec3AddToBounds( v.p, m_vMins, m_vMaxs );
} }
@@ -237,8 +239,8 @@ void RageModelGeometry::LoadMilkshapeAscii( const RString& _sPath, bool bNeedsNo
if( f.GetLine( sLine ) <= 0 ) if( f.GetLine( sLine ) <= 0 )
THROW; THROW;
uint16_t nIndices[3]; std::uint16_t nIndices[3];
uint16_t nNormalIndices[3]; std::uint16_t nNormalIndices[3];
if( sscanf (sLine, "%d %hu %hu %hu %hu %hu %hu %d", if( sscanf (sLine, "%d %hu %hu %hu %hu %hu %hu %d",
&nFlags, &nFlags,
&nIndices[0], &nIndices[1], &nIndices[2], &nIndices[0], &nIndices[1], &nIndices[2],
+8 -7
View File
@@ -37,6 +37,7 @@
#include "RageSoundReader_ThreadedBuffer.h" #include "RageSoundReader_ThreadedBuffer.h"
#include <cmath> #include <cmath>
#include <cstdint>
#define samplerate() m_pSource->GetSampleRate() #define samplerate() m_pSource->GetSampleRate()
@@ -268,7 +269,7 @@ void RageSound::LoadSoundReader( RageSoundReader *pSound )
* conditions are masked and will be seen on the next call. Otherwise, the requested * conditions are masked and will be seen on the next call. Otherwise, the requested
* number of frames will always be returned. * number of frames will always be returned.
*/ */
int RageSound::GetDataToPlay( float *pBuffer, int iFrames, int64_t &iStreamFrame, int &iFramesStored ) int RageSound::GetDataToPlay( float *pBuffer, int iFrames, std::int64_t &iStreamFrame, int &iFramesStored )
{ {
/* We only update m_iStreamFrame; only take a shared lock, so we don't block the main thread. */ /* We only update m_iStreamFrame; only take a shared lock, so we don't block the main thread. */
// LockMut(m_Mutex); // LockMut(m_Mutex);
@@ -317,7 +318,7 @@ int RageSound::GetDataToPlay( float *pBuffer, int iFrames, int64_t &iStreamFrame
} }
/* Indicate that a block of audio data has been written to the device. */ /* Indicate that a block of audio data has been written to the device. */
void RageSound::CommitPlayingPosition( int64_t iHardwareFrame, int64_t iStreamFrame, int iGotFrames ) void RageSound::CommitPlayingPosition( std::int64_t iHardwareFrame, std::int64_t iStreamFrame, int iGotFrames )
{ {
m_Mutex.Lock(); m_Mutex.Lock();
m_HardwareToStreamMap.Insert( iHardwareFrame, iGotFrames, iStreamFrame ); m_HardwareToStreamMap.Insert( iHardwareFrame, iGotFrames, iStreamFrame );
@@ -372,7 +373,7 @@ void RageSound::SoundIsFinishedPlaying()
return; return;
/* Get our current hardware position. */ /* Get our current hardware position. */
int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition(nullptr); std::int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition(nullptr);
m_Mutex.Lock(); m_Mutex.Lock();
@@ -474,16 +475,16 @@ float RageSound::GetLengthSeconds()
return iLength / 1000.f; // ms -> secs return iLength / 1000.f; // ms -> secs
} }
int RageSound::GetSourceFrameFromHardwareFrame( int64_t iHardwareFrame, bool *bApproximate ) const int RageSound::GetSourceFrameFromHardwareFrame( std::int64_t iHardwareFrame, bool *bApproximate ) const
{ {
if( m_HardwareToStreamMap.IsEmpty() || m_StreamToSourceMap.IsEmpty() ) if( m_HardwareToStreamMap.IsEmpty() || m_StreamToSourceMap.IsEmpty() )
return 0; return 0;
bool bApprox; bool bApprox;
int64_t iStreamFrame = m_HardwareToStreamMap.Search( iHardwareFrame, &bApprox ); std::int64_t iStreamFrame = m_HardwareToStreamMap.Search( iHardwareFrame, &bApprox );
if( bApproximate && bApprox ) if( bApproximate && bApprox )
*bApproximate = true; *bApproximate = true;
int64_t iSourceFrame = m_StreamToSourceMap.Search( iStreamFrame, &bApprox ); std::int64_t iSourceFrame = m_StreamToSourceMap.Search( iStreamFrame, &bApprox );
if( bApproximate && bApprox ) if( bApproximate && bApprox )
*bApproximate = true; *bApproximate = true;
return (int) iSourceFrame; return (int) iSourceFrame;
@@ -499,7 +500,7 @@ int RageSound::GetSourceFrameFromHardwareFrame( int64_t iHardwareFrame, bool *bA
float RageSound::GetPositionSeconds( bool *bApproximate, RageTimer *pTimestamp ) const float RageSound::GetPositionSeconds( bool *bApproximate, RageTimer *pTimestamp ) const
{ {
/* Get our current hardware position. */ /* Get our current hardware position. */
int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition( pTimestamp ); std::int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition( pTimestamp );
/* Lock the mutex after calling SOUNDMAN->GetPosition(). We must not make driver /* Lock the mutex after calling SOUNDMAN->GetPosition(). We must not make driver
* calls with our mutex locked (driver mutex < sound mutex). */ * calls with our mutex locked (driver mutex < sound mutex). */
+8 -6
View File
@@ -7,6 +7,8 @@
#include "RageTimer.h" #include "RageTimer.h"
#include "RageSoundPosMap.h" #include "RageSoundPosMap.h"
#include <cstdint>
class RageSoundReader; class RageSoundReader;
struct lua_State; struct lua_State;
@@ -16,8 +18,8 @@ class RageSoundBase
public: public:
virtual ~RageSoundBase() { } virtual ~RageSoundBase() { }
virtual void SoundIsFinishedPlaying() = 0; virtual void SoundIsFinishedPlaying() = 0;
virtual int GetDataToPlay( float *buffer, int size, int64_t &iStreamFrame, int &got_bytes ) = 0; virtual int GetDataToPlay( float *buffer, int size, std::int64_t &iStreamFrame, int &got_bytes ) = 0;
virtual void CommitPlayingPosition( int64_t iFrameno, int64_t iPosition, int iBytesRead ) = 0; virtual void CommitPlayingPosition( std::int64_t iFrameno, std::int64_t iPosition, int iBytesRead ) = 0;
virtual RageTimer GetStartTime() const { return RageZeroTimer; } virtual RageTimer GetStartTime() const { return RageZeroTimer; }
virtual RString GetLoadedFilePath() const = 0; virtual RString GetLoadedFilePath() const = 0;
}; };
@@ -159,7 +161,7 @@ private:
/* Current position of the output sound, in frames. If < 0, nothing will play /* Current position of the output sound, in frames. If < 0, nothing will play
* until it becomes positive. */ * until it becomes positive. */
int64_t m_iStreamFrame; std::int64_t m_iStreamFrame;
/* Hack: When we stop a playing sound, we can't ask the driver the position /* Hack: When we stop a playing sound, we can't ask the driver the position
* (we're not playing); and we can't seek back to the current playing position * (we're not playing); and we can't seek back to the current playing position
@@ -173,7 +175,7 @@ private:
RString m_sError; RString m_sError;
int GetSourceFrameFromHardwareFrame( int64_t iHardwareFrame, bool *bApproximate = nullptr ) const; int GetSourceFrameFromHardwareFrame( std::int64_t iHardwareFrame, bool *bApproximate = nullptr ) const;
bool SetPositionFrames( int frames = -1 ); bool SetPositionFrames( int frames = -1 );
RageSoundParams::StopMode_t GetStopMode() const; // resolves M_AUTO RageSoundParams::StopMode_t GetStopMode() const; // resolves M_AUTO
@@ -187,8 +189,8 @@ public:
* it signals the stream to stop; once it's flushed, SoundStopped will be * it signals the stream to stop; once it's flushed, SoundStopped will be
* called. Until then, SOUNDMAN->GetPosition can still be called; the sound * called. Until then, SOUNDMAN->GetPosition can still be called; the sound
* is still playing. */ * is still playing. */
int GetDataToPlay( float *pBuffer, int iSize, int64_t &iStreamFrame, int &iBytesRead ); int GetDataToPlay( float *pBuffer, int iSize, std::int64_t &iStreamFrame, int &iBytesRead );
void CommitPlayingPosition( int64_t iHardwareFrame, int64_t iStreamFrame, int iGotFrames ); void CommitPlayingPosition( std::int64_t iHardwareFrame, std::int64_t iStreamFrame, int iGotFrames );
}; };
#endif #endif
+3 -1
View File
@@ -21,6 +21,8 @@
#include "arch/Sound/RageSoundDriver.h" #include "arch/Sound/RageSoundDriver.h"
#include <cstdint>
/* /*
* The lock ordering requirements are: * The lock ordering requirements are:
* RageSound::Lock before g_SoundManMutex * RageSound::Lock before g_SoundManMutex
@@ -98,7 +100,7 @@ bool RageSoundManager::Pause( RageSoundBase *pSound, bool bPause )
return m_pDriver->PauseMixing( pSound, bPause ); return m_pDriver->PauseMixing( pSound, bPause );
} }
int64_t RageSoundManager::GetPosition( RageTimer *pTimer ) const std::int64_t RageSoundManager::GetPosition( RageTimer *pTimer ) const
{ {
if( m_pDriver == nullptr ) if( m_pDriver == nullptr )
return 0; return 0;
+5 -3
View File
@@ -3,10 +3,12 @@
#ifndef RAGE_SOUND_MANAGER_H #ifndef RAGE_SOUND_MANAGER_H
#define RAGE_SOUND_MANAGER_H #define RAGE_SOUND_MANAGER_H
#include <set>
#include <map>
#include "RageUtil_CircularBuffer.h" #include "RageUtil_CircularBuffer.h"
#include <cstdint>
#include <map>
#include <set>
class RageSound; class RageSound;
class RageSoundBase; class RageSoundBase;
class RageSoundDriver; class RageSoundDriver;
@@ -37,7 +39,7 @@ public:
void StartMixing( RageSoundBase *snd ); /* used by RageSound */ void StartMixing( RageSoundBase *snd ); /* used by RageSound */
void StopMixing( RageSoundBase *snd ); /* used by RageSound */ void StopMixing( RageSoundBase *snd ); /* used by RageSound */
bool Pause( RageSoundBase *snd, bool bPause ); /* used by RageSound */ bool Pause( RageSoundBase *snd, bool bPause ); /* used by RageSound */
int64_t GetPosition( RageTimer *pTimer ) const; /* used by RageSound */ std::int64_t GetPosition( RageTimer *pTimer ) const; /* used by RageSound */
float GetPlayLatency() const; float GetPlayLatency() const;
int GetDriverSampleRate() const; int GetDriverSampleRate() const;
+2 -1
View File
@@ -3,6 +3,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include <cmath> #include <cmath>
#include <cstdint>
#if defined(MACOSX) #if defined(MACOSX)
#include "archutils/Darwin/VectorHelper.h" #include "archutils/Darwin/VectorHelper.h"
@@ -75,7 +76,7 @@ void RageSoundMixBuffer::write( const float *pBuf, unsigned iSize, int iSourceSt
} }
} }
void RageSoundMixBuffer::read( int16_t *pBuf ) void RageSoundMixBuffer::read( std::int16_t *pBuf )
{ {
for( unsigned iPos = 0; iPos < m_iBufUsed; ++iPos ) for( unsigned iPos = 0; iPos < m_iBufUsed; ++iPos )
{ {
+3 -1
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_SOUND_MIX_BUFFER_H #ifndef RAGE_SOUND_MIX_BUFFER_H
#define RAGE_SOUND_MIX_BUFFER_H #define RAGE_SOUND_MIX_BUFFER_H
#include <cstdint>
class RageSoundMixBuffer class RageSoundMixBuffer
{ {
public: public:
@@ -15,7 +17,7 @@ public:
/* Extend the buffer as if write() was called with a buffer of silence. */ /* Extend the buffer as if write() was called with a buffer of silence. */
void Extend( unsigned iSamples ); void Extend( unsigned iSamples );
void read( int16_t *pBuf ); void read( std::int16_t *pBuf );
void read( float *pBuf ); void read( float *pBuf );
void read_deinterlace( float **pBufs, int channels ); void read_deinterlace( float **pBufs, int channels );
float *read() { return m_pMixbuf; } float *read() { return m_pMixbuf; }
+7 -6
View File
@@ -6,6 +6,7 @@
#include <climits> #include <climits>
#include <cmath> #include <cmath>
#include <cstdint>
#include <list> #include <list>
/* The number of frames we should keep pos_map data for. This being too high /* The number of frames we should keep pos_map data for. This being too high
@@ -14,8 +15,8 @@ const int pos_map_backlog_frames = 100000;
struct pos_map_t struct pos_map_t
{ {
int64_t m_iSourceFrame; std::int64_t m_iSourceFrame;
int64_t m_iDestFrame; std::int64_t m_iDestFrame;
int m_iFrames; int m_iFrames;
float m_fSourceToDestRatio; float m_fSourceToDestRatio;
@@ -53,7 +54,7 @@ pos_map_queue &pos_map_queue::operator=( const pos_map_queue &rhs )
return *this; return *this;
} }
void pos_map_queue::Insert( int64_t iSourceFrame, int iFrames, int64_t iDestFrame, float fSourceToDestRatio ) void pos_map_queue::Insert( std::int64_t iSourceFrame, int iFrames, std::int64_t iDestFrame, float fSourceToDestRatio )
{ {
if( !m_pImpl->m_Queue.empty() ) if( !m_pImpl->m_Queue.empty() )
{ {
@@ -120,7 +121,7 @@ void pos_map_impl::Cleanup()
m_Queue.erase( m_Queue.begin(), it ); m_Queue.erase( m_Queue.begin(), it );
} }
int64_t pos_map_queue::Search( int64_t iSourceFrame, bool *bApproximate ) const std::int64_t pos_map_queue::Search( std::int64_t iSourceFrame, bool *bApproximate ) const
{ {
if( bApproximate ) if( bApproximate )
*bApproximate = false; *bApproximate = false;
@@ -134,7 +135,7 @@ int64_t pos_map_queue::Search( int64_t iSourceFrame, bool *bApproximate ) const
/* iSourceFrame is probably in pos_map. Search to figure out what position /* iSourceFrame is probably in pos_map. Search to figure out what position
* it maps to. */ * it maps to. */
int64_t iClosestPosition = 0, iClosestPositionDist = INT_MAX; std::int64_t iClosestPosition = 0, iClosestPositionDist = INT_MAX;
const pos_map_t *pClosestBlock = &*m_pImpl->m_Queue.begin(); /* print only */ const pos_map_t *pClosestBlock = &*m_pImpl->m_Queue.begin(); /* print only */
for (pos_map_t const &pm : m_pImpl->m_Queue) for (pos_map_t const &pm : m_pImpl->m_Queue)
{ {
@@ -149,7 +150,7 @@ int64_t pos_map_queue::Search( int64_t iSourceFrame, bool *bApproximate ) const
} }
/* See if the current position is close to the beginning of this block. */ /* See if the current position is close to the beginning of this block. */
int64_t dist = llabs( pm.m_iSourceFrame - iSourceFrame ); std::int64_t dist = llabs( pm.m_iSourceFrame - iSourceFrame );
if( dist < iClosestPositionDist ) if( dist < iClosestPositionDist )
{ {
iClosestPositionDist = dist; iClosestPositionDist = dist;
+4 -2
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_SOUND_POS_MAP_H #ifndef RAGE_SOUND_POS_MAP_H
#define RAGE_SOUND_POS_MAP_H #define RAGE_SOUND_POS_MAP_H
#include <cstdint>
struct pos_map_impl; struct pos_map_impl;
class pos_map_queue class pos_map_queue
{ {
@@ -13,10 +15,10 @@ public:
pos_map_queue &operator=( const pos_map_queue &rhs ); pos_map_queue &operator=( const pos_map_queue &rhs );
/* Insert a mapping from iSourceFrame to iDestFrame, containing iFrames. */ /* Insert a mapping from iSourceFrame to iDestFrame, containing iFrames. */
void Insert( int64_t iSourceFrame, int iFrames, int64_t iDestFrame, float fSourceToDestRatio = 1.0f ); void Insert( std::int64_t iSourceFrame, int iFrames, std::int64_t iDestFrame, float fSourceToDestRatio = 1.0f );
/* Return the iDestFrame for the given iSourceFrame. */ /* Return the iDestFrame for the given iSourceFrame. */
int64_t Search( int64_t iSourceFrame, bool *bApproximate ) const; std::int64_t Search( std::int64_t iSourceFrame, bool *bApproximate ) const;
/* Erase all mappings. */ /* Erase all mappings. */
void Clear(); void Clear();
+2 -1
View File
@@ -5,6 +5,7 @@
#include "RageSoundReader.h" #include "RageSoundReader.h"
#include <cstdint>
#include <map> #include <map>
class RageSoundReader_Chain: public RageSoundReader class RageSoundReader_Chain: public RageSoundReader
@@ -59,7 +60,7 @@ private:
float fPan; float fPan;
RageSoundReader *pSound; // nullptr if not activated RageSoundReader *pSound; // nullptr if not activated
int GetOffsetFrame( int iSampleRate ) const { return int( int64_t(iOffsetMS) * iSampleRate / 1000 ); } int GetOffsetFrame( int iSampleRate ) const { return int( std::int64_t(iOffsetMS) * iSampleRate / 1000 ); }
bool operator<( const Sound &rhs ) const { return iOffsetMS < rhs.iOffsetMS; } bool operator<( const Sound &rhs ) const { return iOffsetMS < rhs.iOffsetMS; }
}; };
std::vector<Sound> m_aSounds; std::vector<Sound> m_aSounds;
+3 -2
View File
@@ -5,8 +5,9 @@
#include "RageLog.h" #include "RageLog.h"
#include "RageUtil.h" #include "RageUtil.h"
#include <cstdio>
#include <cerrno> #include <cerrno>
#include <cstdint>
#include <cstdio>
#include <map> #include <map>
#include "mad.h" #include "mad.h"
@@ -188,7 +189,7 @@ struct madlib_t
bitrate = 0; bitrate = 0;
} }
uint8_t inbuf[16384]; std::uint8_t inbuf[16384];
float outbuf[8192]; float outbuf[8192];
int outpos; int outpos;
unsigned outleft; unsigned outleft;
+4 -3
View File
@@ -8,6 +8,7 @@
#include "Preference.h" #include "Preference.h"
#include <cmath> #include <cmath>
#include <cstdint>
/* If true, preloaded sounds are stored in 16-bit instead of floats. Most /* If true, preloaded sounds are stored in 16-bit instead of floats. Most
* processing happens after preloading, and it's usually a waste to store high- * processing happens after preloading, and it's usually a waste to store high-
@@ -17,7 +18,7 @@ Preference<bool> g_bSoundPreload16bit( "SoundPreload16bit", true );
/* If a sound is smaller than this, we'll load it entirely into memory. */ /* If a sound is smaller than this, we'll load it entirely into memory. */
Preference<int> g_iSoundPreloadMaxSamples( "SoundPreloadMaxSamples", 1024*1024 ); Preference<int> g_iSoundPreloadMaxSamples( "SoundPreloadMaxSamples", 1024*1024 );
#define samplesize (m_bBufferIs16Bit? sizeof(int16_t):sizeof(float)) #define samplesize (m_bBufferIs16Bit? sizeof(std::int16_t):sizeof(float))
#define framesize (samplesize * m_iChannels) #define framesize (samplesize * m_iChannels)
bool RageSoundReader_Preload::PreloadSound( RageSoundReader *&pSound ) bool RageSoundReader_Preload::PreloadSound( RageSoundReader *&pSound )
@@ -92,7 +93,7 @@ bool RageSoundReader_Preload::Open( RageSoundReader *pSource )
/* Add the buffer. */ /* Add the buffer. */
if( m_bBufferIs16Bit ) if( m_bBufferIs16Bit )
{ {
int16_t buffer16[1024]; std::int16_t buffer16[1024];
RageSoundUtil::ConvertFloatToNativeInt16( buffer, buffer16, iCnt*m_iChannels ); RageSoundUtil::ConvertFloatToNativeInt16( buffer, buffer16, iCnt*m_iChannels );
m_Buffer.Get()->append( (char *) buffer16, (char *) (buffer16+iCnt*m_iChannels) ); m_Buffer.Get()->append( (char *) buffer16, (char *) (buffer16+iCnt*m_iChannels) );
} }
@@ -151,7 +152,7 @@ int RageSoundReader_Preload::Read( float *pBuffer, int iFrames )
return END_OF_FILE; return END_OF_FILE;
if( m_bBufferIs16Bit ) if( m_bBufferIs16Bit )
{ {
const int16_t *pIn = (const int16_t *) (m_Buffer->data() + (m_iPosition * framesize)); const std::int16_t *pIn = (const std::int16_t *) (m_Buffer->data() + (m_iPosition * framesize));
RageSoundUtil::ConvertNativeInt16ToFloat( pIn, pBuffer, iFrames * m_iChannels ); RageSoundUtil::ConvertNativeInt16ToFloat( pIn, pBuffer, iFrames * m_iChannels );
} }
else else
+3 -2
View File
@@ -14,6 +14,7 @@
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <numeric> #include <numeric>
/* Filter length. This must be a power of 2. */ /* Filter length. This must be a power of 2. */
@@ -538,7 +539,7 @@ private:
int RageSoundReader_Resample_Good::GetNextSourceFrame() const int RageSoundReader_Resample_Good::GetNextSourceFrame() const
{ {
int64_t iPosition = m_pSource->GetNextSourceFrame(); std::int64_t iPosition = m_pSource->GetNextSourceFrame();
iPosition -= m_apResamplers[0]->GetFilled(); iPosition -= m_apResamplers[0]->GetFilled();
iPosition *= m_iSampleRate; iPosition *= m_iSampleRate;
@@ -638,7 +639,7 @@ RageSoundReader_Resample_Good::~RageSoundReader_Resample_Good()
int RageSoundReader_Resample_Good::SetPosition( int iFrame ) int RageSoundReader_Resample_Good::SetPosition( int iFrame )
{ {
Reset(); Reset();
iFrame = (int) SCALE( iFrame, 0, (int64_t) m_iSampleRate, 0, (int64_t) m_pSource->GetSampleRate() ); iFrame = (int) SCALE( iFrame, 0, (std::int64_t) m_iSampleRate, 0, (std::int64_t) m_pSource->GetSampleRate() );
return m_pSource->SetPosition( iFrame ); return m_pSource->SetPosition( iFrame );
} }
+4 -3
View File
@@ -13,6 +13,7 @@
#include <cerrno> #include <cerrno>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <cstring> #include <cstring>
static std::size_t OggRageFile_read_func( void *ptr, std::size_t size, std::size_t nmemb, void *datasource ) static std::size_t OggRageFile_read_func( void *ptr, std::size_t size, std::size_t nmemb, void *datasource )
@@ -184,7 +185,7 @@ int RageSoundReader_Vorbisfile::Read( float *buf, int iFrames )
{ {
int bstream; int bstream;
#if defined(INTEGER_VORBIS) #if defined(INTEGER_VORBIS)
int ret = ov_read( vf, (char *) buf, iFrames * channels * sizeof(int16_t), &bstream ); int ret = ov_read( vf, (char *) buf, iFrames * channels * sizeof(std::int16_t), &bstream );
#else // float vorbis decoder #else // float vorbis decoder
float **pcm; float **pcm;
int ret = ov_read_float( vf, &pcm, iFrames, &bstream ); int ret = ov_read_float( vf, &pcm, iFrames, &bstream );
@@ -217,11 +218,11 @@ int RageSoundReader_Vorbisfile::Read( float *buf, int iFrames )
#if defined(INTEGER_VORBIS) #if defined(INTEGER_VORBIS)
if( ret > 0 ) if( ret > 0 )
{ {
int iSamplesRead = ret / sizeof(int16_t); int iSamplesRead = ret / sizeof(std::int16_t);
iFramesRead = iSamplesRead / channels; iFramesRead = iSamplesRead / channels;
/* Convert in reverse, so we can do it in-place. */ /* Convert in reverse, so we can do it in-place. */
const int16_t *pIn = (int16_t *) buf; const std::int16_t *pIn = (std::int16_t *) buf;
float *pOut = (float *) buf; float *pOut = (float *) buf;
for( int i = iSamplesRead-1; i >= 0; --i ) for( int i = iSamplesRead-1; i >= 0; --i )
pOut[i] = pIn[i] / 32768.0f; pOut[i] = pIn[i] / 32768.0f;
+28 -26
View File
@@ -15,6 +15,8 @@
#include "RageLog.h" #include "RageLog.h"
#include "RageFileBasic.h" #include "RageFileBasic.h"
#include <cstdint>
namespace namespace
{ {
/* pBuf contains iSamples 8-bit samples; convert to 16-bit. pBuf must /* pBuf contains iSamples 8-bit samples; convert to 16-bit. pBuf must
@@ -22,7 +24,7 @@ namespace
void Convert8bitToFloat( void *pBuf, int iSamples ) void Convert8bitToFloat( void *pBuf, int iSamples )
{ {
/* Convert in reverse, so we can do it in-place. */ /* Convert in reverse, so we can do it in-place. */
const uint8_t *pIn = (uint8_t *) pBuf; const std::uint8_t *pIn = (std::uint8_t *) pBuf;
float *pOut = (float *) pBuf; float *pOut = (float *) pBuf;
for( int i = iSamples-1; i >= 0; --i ) for( int i = iSamples-1; i >= 0; --i )
{ {
@@ -37,11 +39,11 @@ namespace
void ConvertLittleEndian16BitToFloat( void *pBuf, int iSamples ) void ConvertLittleEndian16BitToFloat( void *pBuf, int iSamples )
{ {
/* Convert in reverse, so we can do it in-place. */ /* Convert in reverse, so we can do it in-place. */
const int16_t *pIn = (int16_t *) pBuf; const std::int16_t *pIn = (std::int16_t *) pBuf;
float *pOut = (float *) pBuf; float *pOut = (float *) pBuf;
for( int i = iSamples-1; i >= 0; --i ) for( int i = iSamples-1; i >= 0; --i )
{ {
int16_t iSample = Swap16LE( pIn[i] ); std::int16_t iSample = Swap16LE( pIn[i] );
pOut[i] = iSample / 32768.0f; pOut[i] = iSample / 32768.0f;
} }
} }
@@ -56,7 +58,7 @@ namespace
{ {
pIn -= 3; pIn -= 3;
int32_t iSample = std::int32_t iSample =
(int(pIn[0]) << 0) | (int(pIn[0]) << 0) |
(int(pIn[1]) << 8) | (int(pIn[1]) << 8) |
(int(pIn[2]) << 16); (int(pIn[2]) << 16);
@@ -72,11 +74,11 @@ namespace
void ConvertLittleEndian32BitToFloat( void *pBuf, int iSamples ) void ConvertLittleEndian32BitToFloat( void *pBuf, int iSamples )
{ {
/* Convert in reverse, so we can do it in-place. */ /* Convert in reverse, so we can do it in-place. */
const int32_t *pIn = (int32_t *) pBuf; const std::int32_t *pIn = (std::int32_t *) pBuf;
float *pOut = (float *) pBuf; float *pOut = (float *) pBuf;
for( int i = iSamples-1; i >= 0; --i ) for( int i = iSamples-1; i >= 0; --i )
{ {
int32_t iSample = Swap32LE( pIn[i] ); std::int32_t iSample = Swap32LE( pIn[i] );
pOut[i] = iSample / 2147483648.0f; pOut[i] = iSample / 2147483648.0f;
} }
} }
@@ -163,13 +165,13 @@ struct WavReaderPCM: public WavReader
int GetLength() const int GetLength() const
{ {
const int iBytesPerSec = m_WavData.m_iSampleRate * m_WavData.m_iChannels * m_WavData.m_iBitsPerSample / 8; const int iBytesPerSec = m_WavData.m_iSampleRate * m_WavData.m_iChannels * m_WavData.m_iBitsPerSample / 8;
int64_t iMS = (int64_t(m_WavData.m_iDataChunkSize) * 1000) / iBytesPerSec; std::int64_t iMS = (std::int64_t(m_WavData.m_iDataChunkSize) * 1000) / iBytesPerSec;
return (int) iMS; return (int) iMS;
} }
int SetPosition( int iFrame ) int SetPosition( int iFrame )
{ {
int iByte = (int) (int64_t(iFrame) * m_WavData.m_iChannels * m_WavData.m_iBitsPerSample / 8); int iByte = (int) (std::int64_t(iFrame) * m_WavData.m_iChannels * m_WavData.m_iBitsPerSample / 8);
if( iByte > m_WavData.m_iDataChunkSize ) if( iByte > m_WavData.m_iDataChunkSize )
{ {
m_File.Seek( m_WavData.m_iDataChunkSize+m_WavData.m_iDataChunkPos ); m_File.Seek( m_WavData.m_iDataChunkSize+m_WavData.m_iDataChunkPos );
@@ -192,8 +194,8 @@ struct WavReaderPCM: public WavReader
struct WavReaderADPCM: public WavReader struct WavReaderADPCM: public WavReader
{ {
public: public:
std::vector<int16_t> m_iaCoef1, m_iaCoef2; std::vector<std::int16_t> m_iaCoef1, m_iaCoef2;
int16_t m_iFramesPerBlock; std::int16_t m_iFramesPerBlock;
float *m_pBuffer; float *m_pBuffer;
int m_iBufferAvail, m_iBufferUsed; int m_iBufferAvail, m_iBufferUsed;
@@ -219,7 +221,7 @@ public:
m_File.Seek( m_WavData.m_iExtraFmtPos ); m_File.Seek( m_WavData.m_iExtraFmtPos );
m_iFramesPerBlock = FileReading::read_16_le( m_File, m_sError ); m_iFramesPerBlock = FileReading::read_16_le( m_File, m_sError );
int16_t iNumCoef = FileReading::read_16_le( m_File, m_sError ); std::int16_t iNumCoef = FileReading::read_16_le( m_File, m_sError );
m_iaCoef1.resize( iNumCoef ); m_iaCoef1.resize( iNumCoef );
m_iaCoef2.resize( iNumCoef ); m_iaCoef2.resize( iNumCoef );
for( int i = 0; i < iNumCoef; ++i ) for( int i = 0; i < iNumCoef; ++i )
@@ -255,8 +257,8 @@ public:
if( m_File.Tell() >= m_WavData.m_iDataChunkSize+m_WavData.m_iDataChunkPos || m_File.AtEOF() ) if( m_File.Tell() >= m_WavData.m_iDataChunkSize+m_WavData.m_iDataChunkPos || m_File.AtEOF() )
return true; /* past the data chunk */ return true; /* past the data chunk */
int8_t iPredictor[2]; std::int8_t iPredictor[2];
int16_t iDelta[2], iSamp1[2], iSamp2[2]; std::int16_t iDelta[2], iSamp1[2], iSamp2[2];
for( int i = 0; i < m_WavData.m_iChannels; ++i ) for( int i = 0; i < m_WavData.m_iChannels; ++i )
iPredictor[i] = FileReading::read_8( m_File, m_sError ); iPredictor[i] = FileReading::read_8( m_File, m_sError );
for( int i = 0; i < m_WavData.m_iChannels; ++i ) for( int i = 0; i < m_WavData.m_iChannels; ++i )
@@ -300,12 +302,12 @@ public:
} }
for( int i = 0; i < m_WavData.m_iChannels; ++i ) for( int i = 0; i < m_WavData.m_iChannels; ++i )
pBuffer[m_iBufferAvail++] = (int16_t)iSamp2[i] / 32768.0f; pBuffer[m_iBufferAvail++] = (std::int16_t)iSamp2[i] / 32768.0f;
for( int i = 0; i < m_WavData.m_iChannels; ++i ) for( int i = 0; i < m_WavData.m_iChannels; ++i )
pBuffer[m_iBufferAvail++] = (int16_t)iSamp1[i] / 32768.0f; pBuffer[m_iBufferAvail++] = (std::int16_t)iSamp1[i] / 32768.0f;
int8_t iBufSize = 0; std::int8_t iBufSize = 0;
uint8_t iBuf = 0; std::uint8_t iBuf = 0;
bool bDone = false; bool bDone = false;
for( int i = 2; !bDone && i < m_iFramesPerBlock; ++i ) for( int i = 2; !bDone && i < m_iFramesPerBlock; ++i )
@@ -326,24 +328,24 @@ public:
} }
/* Store the nibble in signed char, so we get an arithmetic shift. */ /* Store the nibble in signed char, so we get an arithmetic shift. */
int8_t iErrorDelta = (int8_t)(iBuf) >> 4; std::int8_t iErrorDelta = (std::int8_t)(iBuf) >> 4;
uint8_t iErrorDeltaUnsigned = iBuf >> 4; std::uint8_t iErrorDeltaUnsigned = iBuf >> 4;
iBuf <<= 4; iBuf <<= 4;
--iBufSize; --iBufSize;
int32_t iPredSample = (iSamp1[c] * iCoef1[c] + iSamp2[c] * iCoef2[c]) / (1<<8); std::int32_t iPredSample = (iSamp1[c] * iCoef1[c] + iSamp2[c] * iCoef2[c]) / (1<<8);
if( iPredSample < -32768 ) iPredSample = -32768; if( iPredSample < -32768 ) iPredSample = -32768;
if( iPredSample > 32767 ) iPredSample = 32767; if( iPredSample > 32767 ) iPredSample = 32767;
int16_t iNewSample = (int16_t)iPredSample + (iDelta[c] * iErrorDelta); std::int16_t iNewSample = (std::int16_t)iPredSample + (iDelta[c] * iErrorDelta);
pBuffer[m_iBufferAvail++] = iNewSample / 32768.0f; pBuffer[m_iBufferAvail++] = iNewSample / 32768.0f;
static const int aAdaptionTable[] = { static const int aAdaptionTable[] = {
230, 230, 230, 230, 307, 409, 512, 614, 230, 230, 230, 230, 307, 409, 512, 614,
768, 614, 512, 409, 307, 230, 230, 230 768, 614, 512, 409, 307, 230, 230, 230
}; };
iDelta[c] = int16_t( (iDelta[c] * aAdaptionTable[iErrorDeltaUnsigned]) / (1<<8) ); iDelta[c] = std::int16_t( (iDelta[c] * aAdaptionTable[iErrorDeltaUnsigned]) / (1<<8) );
iDelta[c] = std::max( (int16_t) 16, iDelta[c] ); iDelta[c] = std::max( (std::int16_t) 16, iDelta[c] );
iSamp2[c] = iSamp1[c]; iSamp2[c] = iSamp1[c];
iSamp1[c] = iNewSample; iSamp1[c] = iNewSample;
@@ -398,7 +400,7 @@ public:
iFrames += 2+iExtraADPCMFrames; iFrames += 2+iExtraADPCMFrames;
} }
int iMS = int((int64_t(iFrames)*1000)/m_WavData.m_iSampleRate); int iMS = int((std::int64_t(iFrames)*1000)/m_WavData.m_iSampleRate);
return iMS; return iMS;
} }
@@ -441,7 +443,7 @@ public:
int iFrame = iBlock * m_iFramesPerBlock; int iFrame = iBlock * m_iFramesPerBlock;
int iBufferRemainingBytes = m_iBufferAvail - m_iBufferUsed; int iBufferRemainingBytes = m_iBufferAvail - m_iBufferUsed;
int iBufferRemainingFrames = iBufferRemainingBytes / (m_WavData.m_iChannels * sizeof(int16_t)); int iBufferRemainingFrames = iBufferRemainingBytes / (m_WavData.m_iChannels * sizeof(std::int16_t));
iFrame -= iBufferRemainingFrames; iFrame -= iBufferRemainingFrames;
return iFrame; return iFrame;
@@ -492,7 +494,7 @@ RageSoundReader_FileReader::OpenResult RageSoundReader_WAV::Open( RageFileBasic
while( !bGotFormatChunk || !bGotDataChunk ) while( !bGotFormatChunk || !bGotDataChunk )
{ {
RString ChunkID = ReadString( *m_pFile, 4, sError ); RString ChunkID = ReadString( *m_pFile, 4, sError );
int32_t iChunkSize = FileReading::read_32_le( *m_pFile, sError ); std::int32_t iChunkSize = FileReading::read_32_le( *m_pFile, sError );
if( sError.size() != 0 ) if( sError.size() != 0 )
{ {
+4 -2
View File
@@ -6,6 +6,8 @@
#include "RageSoundReader_FileReader.h" #include "RageSoundReader_FileReader.h"
#include "RageFile.h" #include "RageFile.h"
#include <cstdint>
struct WavReader; struct WavReader;
RString ReadString( RageFileBasic &f, int iSize, RString &sError ); RString ReadString( RageFileBasic &f, int iSize, RString &sError );
@@ -28,8 +30,8 @@ public:
struct WavData struct WavData
{ {
int32_t m_iDataChunkPos, m_iDataChunkSize, m_iExtraFmtPos, m_iSampleRate, m_iFormatTag; std::int32_t m_iDataChunkPos, m_iDataChunkSize, m_iExtraFmtPos, m_iSampleRate, m_iFormatTag;
int16_t m_iChannels, m_iBitsPerSample, m_iBlockAlign, m_iExtraFmtBytes; std::int16_t m_iChannels, m_iBitsPerSample, m_iBlockAlign, m_iExtraFmtBytes;
}; };
private: private:
+3 -2
View File
@@ -3,6 +3,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include <cmath> #include <cmath>
#include <cstdint>
void RageSoundUtil::Attenuate( float *pBuf, int iSamples, float fVolume ) void RageSoundUtil::Attenuate( float *pBuf, int iSamples, float fVolume )
{ {
@@ -81,7 +82,7 @@ void RageSoundUtil::ConvertMonoToStereoInPlace( float *data, int iFrames )
} }
} }
void RageSoundUtil::ConvertNativeInt16ToFloat( const int16_t *pFrom, float *pTo, int iSamples ) void RageSoundUtil::ConvertNativeInt16ToFloat( const std::int16_t *pFrom, float *pTo, int iSamples )
{ {
for( int i = 0; i < iSamples; ++i ) for( int i = 0; i < iSamples; ++i )
{ {
@@ -89,7 +90,7 @@ void RageSoundUtil::ConvertNativeInt16ToFloat( const int16_t *pFrom, float *pTo,
} }
} }
void RageSoundUtil::ConvertFloatToNativeInt16( const float *pFrom, int16_t *pTo, int iSamples ) void RageSoundUtil::ConvertFloatToNativeInt16( const float *pFrom, std::int16_t *pTo, int iSamples )
{ {
for( int i = 0; i < iSamples; ++i ) for( int i = 0; i < iSamples; ++i )
{ {
+5 -2
View File
@@ -1,5 +1,8 @@
#ifndef RAGE_SOUND_UTIL_H #ifndef RAGE_SOUND_UTIL_H
#define RAGE_SOUND_UTIL_H #define RAGE_SOUND_UTIL_H
#include <cstdint>
/** @brief Simple utilities that operate on sound buffers. */ /** @brief Simple utilities that operate on sound buffers. */
namespace RageSoundUtil namespace RageSoundUtil
{ {
@@ -7,8 +10,8 @@ namespace RageSoundUtil
void Pan( float *pBuffer, int iFrames, float fPos ); void Pan( float *pBuffer, int iFrames, float fPos );
void Fade( float *pBuffer, int iFrames, int iChannels, float fStartVolume, float fEndVolume ); void Fade( float *pBuffer, int iFrames, int iChannels, float fStartVolume, float fEndVolume );
void ConvertMonoToStereoInPlace( float *pBuffer, int iFrames ); void ConvertMonoToStereoInPlace( float *pBuffer, int iFrames );
void ConvertNativeInt16ToFloat( const int16_t *pFrom, float *pTo, int iSamples ); void ConvertNativeInt16ToFloat( const std::int16_t *pFrom, float *pTo, int iSamples );
void ConvertFloatToNativeInt16( const float *pFrom, int16_t *pTo, int iSamples ); void ConvertFloatToNativeInt16( const float *pFrom, std::int16_t *pTo, int iSamples );
}; };
#endif #endif
+21 -20
View File
@@ -4,9 +4,10 @@
#include <climits> #include <climits>
#include <cmath> #include <cmath>
#include <cstdint>
int32_t RageSurfacePalette::FindColor( const RageSurfaceColor &color ) const std::int32_t RageSurfacePalette::FindColor( const RageSurfaceColor &color ) const
{ {
for( int i = 0; i < ncolors; ++i ) for( int i = 0; i < ncolors; ++i )
if( colors[i] == color ) if( colors[i] == color )
@@ -15,7 +16,7 @@ int32_t RageSurfacePalette::FindColor( const RageSurfaceColor &color ) const
} }
/* XXX: untested */ /* XXX: untested */
int32_t RageSurfacePalette::FindClosestColor( const RageSurfaceColor &color ) const std::int32_t RageSurfacePalette::FindClosestColor( const RageSurfaceColor &color ) const
{ {
int iBest = -1; int iBest = -1;
int iBestDist = INT_MAX; int iBestDist = INT_MAX;
@@ -60,7 +61,7 @@ RageSurfaceFormat::RageSurfaceFormat( const RageSurfaceFormat &cpy ):
} }
} }
void RageSurfaceFormat::GetRGB( uint32_t val, uint8_t *r, uint8_t *g, uint8_t *b ) const void RageSurfaceFormat::GetRGB( std::uint32_t val, std::uint8_t *r, std::uint8_t *g, std::uint8_t *b ) const
{ {
if( BytesPerPixel == 1 ) if( BytesPerPixel == 1 )
{ {
@@ -69,21 +70,21 @@ void RageSurfaceFormat::GetRGB( uint32_t val, uint8_t *r, uint8_t *g, uint8_t *b
*g = palette->colors[val].g; *g = palette->colors[val].g;
*b = palette->colors[val].b; *b = palette->colors[val].b;
} else { } else {
*r = int8_t( (val & Mask[0]) >> Shift[0] << Loss[0] ); *r = std::int8_t( (val & Mask[0]) >> Shift[0] << Loss[0] );
*g = int8_t( (val & Mask[1]) >> Shift[1] << Loss[1] ); *g = std::int8_t( (val & Mask[1]) >> Shift[1] << Loss[1] );
*b = int8_t( (val & Mask[2]) >> Shift[2] << Loss[2] ); *b = std::int8_t( (val & Mask[2]) >> Shift[2] << Loss[2] );
} }
} }
bool RageSurfaceFormat::MapRGBA( uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint32_t &val ) const bool RageSurfaceFormat::MapRGBA( std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a, std::uint32_t &val ) const
{ {
if( BytesPerPixel == 1 ) if( BytesPerPixel == 1 )
{ {
RageSurfaceColor c( r, g, b, a ); RageSurfaceColor c( r, g, b, a );
int32_t n = palette->FindColor( c ); std::int32_t n = palette->FindColor( c );
if( n == -1 ) if( n == -1 )
return false; return false;
val = (uint32_t) n; val = (std::uint32_t) n;
} else { } else {
val = val =
(r >> Loss[0] << Shift[0]) | (r >> Loss[0] << Shift[0]) |
@@ -136,7 +137,7 @@ RageSurface::RageSurface( const RageSurface &cpy )
pixels_owned = true; pixels_owned = true;
if( cpy.pixels ) if( cpy.pixels )
{ {
pixels = new uint8_t[ pitch*h ]; pixels = new std::uint8_t[ pitch*h ];
memcpy( pixels, cpy.pixels, pitch*h ); memcpy( pixels, cpy.pixels, pitch*h );
} }
else else
@@ -149,7 +150,7 @@ RageSurface::~RageSurface()
delete [] pixels; delete [] pixels;
} }
static int GetShiftFromMask( uint32_t mask ) static int GetShiftFromMask( std::uint32_t mask )
{ {
if( !mask ) if( !mask )
return 0; return 0;
@@ -163,7 +164,7 @@ static int GetShiftFromMask( uint32_t mask )
return iShift; return iShift;
} }
static int GetBitsFromMask( uint32_t mask ) static int GetBitsFromMask( std::uint32_t mask )
{ {
if( !mask ) if( !mask )
return 0; return 0;
@@ -181,7 +182,7 @@ static int GetBitsFromMask( uint32_t mask )
void SetupFormat( RageSurfaceFormat &fmt, void SetupFormat( RageSurfaceFormat &fmt,
int width, int height, int BitsPerPixel, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask ) int width, int height, int BitsPerPixel, std::uint32_t Rmask, std::uint32_t Gmask, std::uint32_t Bmask, std::uint32_t Amask )
{ {
fmt.BitsPerPixel = BitsPerPixel; fmt.BitsPerPixel = BitsPerPixel;
fmt.BytesPerPixel = BitsPerPixel/8; fmt.BytesPerPixel = BitsPerPixel/8;
@@ -208,14 +209,14 @@ void SetupFormat( RageSurfaceFormat &fmt,
fmt.Shift[2] = GetShiftFromMask( Bmask ); fmt.Shift[2] = GetShiftFromMask( Bmask );
fmt.Shift[3] = GetShiftFromMask( Amask ); fmt.Shift[3] = GetShiftFromMask( Amask );
fmt.Loss[0] = (uint8_t) (8-GetBitsFromMask( Rmask )); fmt.Loss[0] = (std::uint8_t) (8-GetBitsFromMask( Rmask ));
fmt.Loss[1] = (uint8_t) (8-GetBitsFromMask( Gmask )); fmt.Loss[1] = (std::uint8_t) (8-GetBitsFromMask( Gmask ));
fmt.Loss[2] = (uint8_t) (8-GetBitsFromMask( Bmask )); fmt.Loss[2] = (std::uint8_t) (8-GetBitsFromMask( Bmask ));
fmt.Loss[3] = (uint8_t) (8-GetBitsFromMask( Amask )); fmt.Loss[3] = (std::uint8_t) (8-GetBitsFromMask( Amask ));
} }
} }
RageSurface *CreateSurface( int width, int height, int BitsPerPixel, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask ) RageSurface *CreateSurface( int width, int height, int BitsPerPixel, std::uint32_t Rmask, std::uint32_t Gmask, std::uint32_t Bmask, std::uint32_t Amask )
{ {
RageSurface *pImg = new RageSurface; RageSurface *pImg = new RageSurface;
@@ -225,7 +226,7 @@ RageSurface *CreateSurface( int width, int height, int BitsPerPixel, uint32_t Rm
pImg->h = height; pImg->h = height;
pImg->flags = 0; pImg->flags = 0;
pImg->pitch = width*BitsPerPixel/8; pImg->pitch = width*BitsPerPixel/8;
pImg->pixels = new uint8_t[ pImg->pitch*height ]; pImg->pixels = new std::uint8_t[ pImg->pitch*height ];
/* /*
if( BitsPerPixel == 8 ) if( BitsPerPixel == 8 )
@@ -237,7 +238,7 @@ RageSurface *CreateSurface( int width, int height, int BitsPerPixel, uint32_t Rm
return pImg; return pImg;
} }
RageSurface *CreateSurfaceFrom( int width, int height, int BitsPerPixel, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask, uint8_t *pPixels, uint32_t pitch ) RageSurface *CreateSurfaceFrom( int width, int height, int BitsPerPixel, std::uint32_t Rmask, std::uint32_t Gmask, std::uint32_t Bmask, std::uint32_t Amask, std::uint8_t *pPixels, std::uint32_t pitch )
{ {
RageSurface *pImg = new RageSurface; RageSurface *pImg = new RageSurface;
+21 -20
View File
@@ -4,14 +4,15 @@
#define RAGE_SURFACE_H #define RAGE_SURFACE_H
#include <array> #include <array>
#include <cstdint>
#include <memory> #include <memory>
/* XXX remove? */ /* XXX remove? */
struct RageSurfaceColor struct RageSurfaceColor
{ {
uint8_t r, g, b, a; std::uint8_t r, g, b, a;
RageSurfaceColor(): r(0), g(0), b(0), a(0) { } RageSurfaceColor(): r(0), g(0), b(0), a(0) { }
RageSurfaceColor( uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_ ): RageSurfaceColor( std::uint8_t r_, std::uint8_t g_, std::uint8_t b_, std::uint8_t a_ ):
r(r_), g(g_), b(b_), a(a_) { } r(r_), g(g_), b(b_), a(a_) { }
}; };
@@ -32,11 +33,11 @@ inline bool operator!=(RageSurfaceColor const &lhs, RageSurfaceColor const &rhs)
struct RageSurfacePalette struct RageSurfacePalette
{ {
RageSurfaceColor colors[256]; RageSurfaceColor colors[256];
int32_t ncolors; std::int32_t ncolors;
/* Find the exact color; returns -1 if not found. */ /* Find the exact color; returns -1 if not found. */
int32_t FindColor( const RageSurfaceColor &color ) const; std::int32_t FindColor( const RageSurfaceColor &color ) const;
int32_t FindClosestColor( const RageSurfaceColor &color ) const; std::int32_t FindClosestColor( const RageSurfaceColor &color ) const;
}; };
struct RageSurfaceFormat struct RageSurfaceFormat
@@ -45,24 +46,24 @@ struct RageSurfaceFormat
RageSurfaceFormat( const RageSurfaceFormat &cpy ); RageSurfaceFormat( const RageSurfaceFormat &cpy );
~RageSurfaceFormat() = default; ~RageSurfaceFormat() = default;
int32_t BytesPerPixel; std::int32_t BytesPerPixel;
int32_t BitsPerPixel; std::int32_t BitsPerPixel;
std::array<uint32_t, 4> Mask; std::array<std::uint32_t, 4> Mask;
std::array<uint32_t, 4> Shift; std::array<std::uint32_t, 4> Shift;
std::array<uint32_t, 4> Loss; std::array<std::uint32_t, 4> Loss;
uint32_t &Rmask, &Gmask, &Bmask, &Amask; /* deprecated */ std::uint32_t &Rmask, &Gmask, &Bmask, &Amask; /* deprecated */
uint32_t &Rshift, &Gshift, &Bshift, &Ashift; /* deprecated */ std::uint32_t &Rshift, &Gshift, &Bshift, &Ashift; /* deprecated */
std::unique_ptr<RageSurfacePalette> palette; std::unique_ptr<RageSurfacePalette> palette;
void GetRGB( uint32_t val, uint8_t *r, uint8_t *g, uint8_t *b ) const; void GetRGB( std::uint32_t val, std::uint8_t *r, std::uint8_t *g, std::uint8_t *b ) const;
/* Return the decoded value for the given color; the result can be compared to /* Return the decoded value for the given color; the result can be compared to
* decodepixel() results. If the image is paletted and the color isn't found, * decodepixel() results. If the image is paletted and the color isn't found,
* val is undefined and false is returned. */ * val is undefined and false is returned. */
bool MapRGBA( uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint32_t &val ) const; bool MapRGBA( std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a, std::uint32_t &val ) const;
/* MapRGBA, but also do a nearest-match on palette colors. */ /* MapRGBA, but also do a nearest-match on palette colors. */
uint32_t MapNearestRGBA( uint8_t r, uint8_t g, uint8_t b, uint8_t a ) const; std::uint32_t MapNearestRGBA( std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a ) const;
bool operator== ( const RageSurfaceFormat &rhs ) const; bool operator== ( const RageSurfaceFormat &rhs ) const;
@@ -76,18 +77,18 @@ struct RageSurface
RageSurfaceFormat *format; /* compatibility only */ RageSurfaceFormat *format; /* compatibility only */
RageSurfaceFormat fmt; RageSurfaceFormat fmt;
uint8_t *pixels; std::uint8_t *pixels;
bool pixels_owned; bool pixels_owned;
int32_t w, h, pitch; std::int32_t w, h, pitch;
int32_t flags; std::int32_t flags;
RageSurface(); RageSurface();
RageSurface( const RageSurface &cpy ); RageSurface( const RageSurface &cpy );
~RageSurface(); ~RageSurface();
}; };
RageSurface *CreateSurface( int width, int height, int bpp, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask ); RageSurface *CreateSurface( int width, int height, int bpp, std::uint32_t Rmask, std::uint32_t Gmask, std::uint32_t Bmask, std::uint32_t Amask );
RageSurface *CreateSurfaceFrom( int width, int height, int bpp, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask, uint8_t *pPixels, uint32_t pitch ); RageSurface *CreateSurfaceFrom( int width, int height, int bpp, std::uint32_t Rmask, std::uint32_t Gmask, std::uint32_t Bmask, std::uint32_t Amask, std::uint8_t *pPixels, std::uint32_t pitch );
#endif #endif
+92 -91
View File
@@ -7,48 +7,49 @@
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
uint32_t RageSurfaceUtils::decodepixel( const uint8_t *p, int bpp ) std::uint32_t RageSurfaceUtils::decodepixel( const std::uint8_t *p, int bpp )
{ {
switch(bpp) switch(bpp)
{ {
case 1: return *p; case 1: return *p;
case 2: return *(uint16_t *)p; case 2: return *(std::uint16_t *)p;
case 3: case 3:
if constexpr ( Endian::big ) if constexpr ( Endian::big )
return p[0] << 16 | p[1] << 8 | p[2]; return p[0] << 16 | p[1] << 8 | p[2];
else else
return p[0] | p[1] << 8 | p[2] << 16; return p[0] | p[1] << 8 | p[2] << 16;
case 4: return *(uint32_t *)p; case 4: return *(std::uint32_t *)p;
default: return 0; // shouldn't happen, but avoids warnings default: return 0; // shouldn't happen, but avoids warnings
} }
} }
void RageSurfaceUtils::encodepixel( uint8_t *p, int bpp, uint32_t pixel ) void RageSurfaceUtils::encodepixel( std::uint8_t *p, int bpp, std::uint32_t pixel )
{ {
switch(bpp) switch(bpp)
{ {
case 1: *p = uint8_t(pixel); break; case 1: *p = std::uint8_t(pixel); break;
case 2: *(uint16_t *)p = uint16_t(pixel); break; case 2: *(std::uint16_t *)p = std::uint16_t(pixel); break;
case 3: case 3:
if constexpr ( Endian::big ) if constexpr ( Endian::big )
{ {
p[0] = uint8_t((pixel >> 16) & 0xff); p[0] = std::uint8_t((pixel >> 16) & 0xff);
p[1] = uint8_t((pixel >> 8) & 0xff); p[1] = std::uint8_t((pixel >> 8) & 0xff);
p[2] = uint8_t(pixel & 0xff); p[2] = std::uint8_t(pixel & 0xff);
} else { } else {
p[0] = uint8_t(pixel & 0xff); p[0] = std::uint8_t(pixel & 0xff);
p[1] = uint8_t((pixel >> 8) & 0xff); p[1] = std::uint8_t((pixel >> 8) & 0xff);
p[2] = uint8_t((pixel >> 16) & 0xff); p[2] = std::uint8_t((pixel >> 16) & 0xff);
} }
break; break;
case 4: *(uint32_t *)p = pixel; break; case 4: *(std::uint32_t *)p = pixel; break;
} }
} }
// Get and set colors without scaling to 0..255. // Get and set colors without scaling to 0..255.
void RageSurfaceUtils::GetRawRGBAV( uint32_t pixel, const RageSurfaceFormat &fmt, uint8_t *v ) void RageSurfaceUtils::GetRawRGBAV( std::uint32_t pixel, const RageSurfaceFormat &fmt, std::uint8_t *v )
{ {
if( fmt.BytesPerPixel == 1 ) if( fmt.BytesPerPixel == 1 )
{ {
@@ -57,20 +58,20 @@ void RageSurfaceUtils::GetRawRGBAV( uint32_t pixel, const RageSurfaceFormat &fmt
v[2] = fmt.palette->colors[pixel].b; v[2] = fmt.palette->colors[pixel].b;
v[3] = fmt.palette->colors[pixel].a; v[3] = fmt.palette->colors[pixel].a;
} else { } else {
v[0] = uint8_t((pixel & fmt.Rmask) >> fmt.Rshift); v[0] = std::uint8_t((pixel & fmt.Rmask) >> fmt.Rshift);
v[1] = uint8_t((pixel & fmt.Gmask) >> fmt.Gshift); v[1] = std::uint8_t((pixel & fmt.Gmask) >> fmt.Gshift);
v[2] = uint8_t((pixel & fmt.Bmask) >> fmt.Bshift); v[2] = std::uint8_t((pixel & fmt.Bmask) >> fmt.Bshift);
v[3] = uint8_t((pixel & fmt.Amask) >> fmt.Ashift); v[3] = std::uint8_t((pixel & fmt.Amask) >> fmt.Ashift);
} }
} }
void RageSurfaceUtils::GetRawRGBAV( const uint8_t *p, const RageSurfaceFormat &fmt, uint8_t *v ) void RageSurfaceUtils::GetRawRGBAV( const std::uint8_t *p, const RageSurfaceFormat &fmt, std::uint8_t *v )
{ {
uint32_t pixel = decodepixel( p, fmt.BytesPerPixel ); std::uint32_t pixel = decodepixel( p, fmt.BytesPerPixel );
GetRawRGBAV( pixel, fmt, v ); GetRawRGBAV( pixel, fmt, v );
} }
void RageSurfaceUtils::GetRGBAV( uint32_t pixel, const RageSurface *src, uint8_t *v ) void RageSurfaceUtils::GetRGBAV( std::uint32_t pixel, const RageSurface *src, std::uint8_t *v )
{ {
GetRawRGBAV(pixel, src->fmt, v); GetRawRGBAV(pixel, src->fmt, v);
const RageSurfaceFormat *fmt = src->format; const RageSurfaceFormat *fmt = src->format;
@@ -82,9 +83,9 @@ void RageSurfaceUtils::GetRGBAV( uint32_t pixel, const RageSurface *src, uint8_t
v[3] = 255; v[3] = 255;
} }
void RageSurfaceUtils::GetRGBAV( const uint8_t *p, const RageSurface *src, uint8_t *v ) void RageSurfaceUtils::GetRGBAV( const std::uint8_t *p, const RageSurface *src, std::uint8_t *v )
{ {
uint32_t pixel = decodepixel(p, src->format->BytesPerPixel); std::uint32_t pixel = decodepixel(p, src->format->BytesPerPixel);
if( src->format->BytesPerPixel == 1 ) // paletted if( src->format->BytesPerPixel == 1 ) // paletted
{ {
memcpy( v, &src->format->palette->colors[pixel], sizeof(RageSurfaceColor)); memcpy( v, &src->format->palette->colors[pixel], sizeof(RageSurfaceColor));
@@ -95,7 +96,7 @@ void RageSurfaceUtils::GetRGBAV( const uint8_t *p, const RageSurface *src, uint8
// Inverse of GetRawRGBAV. // Inverse of GetRawRGBAV.
uint32_t RageSurfaceUtils::SetRawRGBAV( const RageSurfaceFormat *fmt, const uint8_t *v ) std::uint32_t RageSurfaceUtils::SetRawRGBAV( const RageSurfaceFormat *fmt, const std::uint8_t *v )
{ {
return v[0] << fmt->Rshift | return v[0] << fmt->Rshift |
v[1] << fmt->Gshift | v[1] << fmt->Gshift |
@@ -103,14 +104,14 @@ uint32_t RageSurfaceUtils::SetRawRGBAV( const RageSurfaceFormat *fmt, const uint
v[3] << fmt->Ashift; v[3] << fmt->Ashift;
} }
void RageSurfaceUtils::SetRawRGBAV( uint8_t *p, const RageSurface *src, const uint8_t *v ) void RageSurfaceUtils::SetRawRGBAV( std::uint8_t *p, const RageSurface *src, const std::uint8_t *v )
{ {
uint32_t pixel = SetRawRGBAV(src->format, v); std::uint32_t pixel = SetRawRGBAV(src->format, v);
encodepixel(p, src->format->BytesPerPixel, pixel); encodepixel(p, src->format->BytesPerPixel, pixel);
} }
// Inverse of GetRGBAV. // Inverse of GetRGBAV.
uint32_t RageSurfaceUtils::SetRGBAV( const RageSurfaceFormat *fmt, const uint8_t *v ) std::uint32_t RageSurfaceUtils::SetRGBAV( const RageSurfaceFormat *fmt, const std::uint8_t *v )
{ {
return (v[0] >> fmt->Loss[0]) << fmt->Shift[0] | return (v[0] >> fmt->Loss[0]) << fmt->Shift[0] |
(v[1] >> fmt->Loss[1]) << fmt->Shift[1] | (v[1] >> fmt->Loss[1]) << fmt->Shift[1] |
@@ -118,14 +119,14 @@ uint32_t RageSurfaceUtils::SetRGBAV( const RageSurfaceFormat *fmt, const uint8_t
(v[3] >> fmt->Loss[3]) << fmt->Shift[3]; (v[3] >> fmt->Loss[3]) << fmt->Shift[3];
} }
void RageSurfaceUtils::SetRGBAV( uint8_t *p, const RageSurface *src, const uint8_t *v ) void RageSurfaceUtils::SetRGBAV( std::uint8_t *p, const RageSurface *src, const std::uint8_t *v )
{ {
uint32_t pixel = SetRGBAV(src->format, v); std::uint32_t pixel = SetRGBAV(src->format, v);
encodepixel(p, src->format->BytesPerPixel, pixel); encodepixel(p, src->format->BytesPerPixel, pixel);
} }
void RageSurfaceUtils::GetBitsPerChannel( const RageSurfaceFormat *fmt, uint32_t bits[4] ) void RageSurfaceUtils::GetBitsPerChannel( const RageSurfaceFormat *fmt, std::uint32_t bits[4] )
{ {
// The actual bits stored in each color is 8-loss. // The actual bits stored in each color is 8-loss.
for( int c = 0; c < 4; ++c ) for( int c = 0; c < 4; ++c )
@@ -146,7 +147,7 @@ void RageSurfaceUtils::CopySurface( const RageSurface *src, RageSurface *dest )
bool RageSurfaceUtils::ConvertSurface( const RageSurface *src, RageSurface *&dst, bool RageSurfaceUtils::ConvertSurface( const RageSurface *src, RageSurface *&dst,
int width, int height, int bpp, int width, int height, int bpp,
uint32_t R, uint32_t G, uint32_t B, uint32_t A ) std::uint32_t R, std::uint32_t G, std::uint32_t B, std::uint32_t A )
{ {
dst = CreateSurface( width, height, bpp, R, G, B, A ); dst = CreateSurface( width, height, bpp, R, G, B, A );
@@ -164,7 +165,7 @@ bool RageSurfaceUtils::ConvertSurface( const RageSurface *src, RageSurface *&dst
void RageSurfaceUtils::ConvertSurface(RageSurface *&image, void RageSurfaceUtils::ConvertSurface(RageSurface *&image,
int width, int height, int bpp, int width, int height, int bpp,
uint32_t R, uint32_t G, uint32_t B, uint32_t A) std::uint32_t R, std::uint32_t G, std::uint32_t B, std::uint32_t A)
{ {
RageSurface *ret_image; RageSurface *ret_image;
if( !ConvertSurface( image, ret_image, width, height, bpp, R, G, B, A ) ) if( !ConvertSurface( image, ret_image, width, height, bpp, R, G, B, A ) )
@@ -176,7 +177,7 @@ void RageSurfaceUtils::ConvertSurface(RageSurface *&image,
// Local helper for FixHiddenAlpha. // Local helper for FixHiddenAlpha.
static void FindAlphaRGB(const RageSurface *img, uint8_t &r, uint8_t &g, uint8_t &b, bool reverse) static void FindAlphaRGB(const RageSurface *img, std::uint8_t &r, std::uint8_t &g, std::uint8_t &b, bool reverse)
{ {
r = g = b = 0; r = g = b = 0;
@@ -188,13 +189,13 @@ static void FindAlphaRGB(const RageSurface *img, uint8_t &r, uint8_t &g, uint8_t
for(int y = reverse? img->h-1:0; for(int y = reverse? img->h-1:0;
reverse? (y >=0):(y < img->h); reverse? (--y):(++y)) reverse? (y >=0):(y < img->h); reverse? (--y):(++y))
{ {
uint8_t *row = (uint8_t *)img->pixels + img->pitch*y; std::uint8_t *row = (std::uint8_t *)img->pixels + img->pitch*y;
if(reverse) if(reverse)
row += img->format->BytesPerPixel * (img->w-1); row += img->format->BytesPerPixel * (img->w-1);
for(int x = 0; x < img->w; ++x) for(int x = 0; x < img->w; ++x)
{ {
uint32_t val = RageSurfaceUtils::decodepixel(row, img->format->BytesPerPixel); std::uint32_t val = RageSurfaceUtils::decodepixel(row, img->format->BytesPerPixel);
if( img->format->BitsPerPixel == 8 ) if( img->format->BitsPerPixel == 8 )
{ {
if( img->format->palette->colors[val].a ) if( img->format->palette->colors[val].a )
@@ -229,7 +230,7 @@ static void FindAlphaRGB(const RageSurface *img, uint8_t &r, uint8_t &g, uint8_t
/* Local helper for FixHiddenAlpha. Set the underlying RGB values of all pixels /* Local helper for FixHiddenAlpha. Set the underlying RGB values of all pixels
* in img that are completely transparent. */ * in img that are completely transparent. */
static void SetAlphaRGB(const RageSurface *pImg, uint8_t r, uint8_t g, uint8_t b) static void SetAlphaRGB(const RageSurface *pImg, std::uint8_t r, std::uint8_t g, std::uint8_t b)
{ {
// If it's a paletted surface, all we have to do is change the palette. // If it's a paletted surface, all we have to do is change the palette.
if( pImg->format->BitsPerPixel == 8 ) if( pImg->format->BitsPerPixel == 8 )
@@ -249,15 +250,15 @@ static void SetAlphaRGB(const RageSurface *pImg, uint8_t r, uint8_t g, uint8_t b
if( pImg->format->BitsPerPixel > 8 && !pImg->format->Amask ) if( pImg->format->BitsPerPixel > 8 && !pImg->format->Amask )
return; return;
uint32_t trans; std::uint32_t trans;
pImg->format->MapRGBA( r, g, b, 0, trans ); pImg->format->MapRGBA( r, g, b, 0, trans );
for( int y = 0; y < pImg->h; ++y ) for( int y = 0; y < pImg->h; ++y )
{ {
uint8_t *row = pImg->pixels + pImg->pitch*y; std::uint8_t *row = pImg->pixels + pImg->pitch*y;
for( int x = 0; x < pImg->w; ++x ) for( int x = 0; x < pImg->w; ++x )
{ {
uint32_t val = RageSurfaceUtils::decodepixel( row, pImg->format->BytesPerPixel ); std::uint32_t val = RageSurfaceUtils::decodepixel( row, pImg->format->BytesPerPixel );
if( val != trans && !(val&pImg->format->Amask) ) if( val != trans && !(val&pImg->format->Amask) )
{ {
RageSurfaceUtils::encodepixel( row, pImg->format->BytesPerPixel, trans ); RageSurfaceUtils::encodepixel( row, pImg->format->BytesPerPixel, trans );
@@ -289,10 +290,10 @@ void RageSurfaceUtils::FixHiddenAlpha( RageSurface *pImg )
if( pImg->format->BitsPerPixel != 8 && pImg->format->Amask == 0 ) if( pImg->format->BitsPerPixel != 8 && pImg->format->Amask == 0 )
return; return;
uint8_t r, g, b; std::uint8_t r, g, b;
FindAlphaRGB( pImg, r, g, b, false ); FindAlphaRGB( pImg, r, g, b, false );
uint8_t cr, cg, cb; // compare std::uint8_t cr, cg, cb; // compare
FindAlphaRGB( pImg, cr, cg, cb, true ); FindAlphaRGB( pImg, cr, cg, cb, true );
if( cr != r || cg != g || cb != b ) if( cr != r || cg != g || cb != b )
@@ -310,7 +311,7 @@ int RageSurfaceUtils::FindSurfaceTraits( const RageSurface *img )
const int NEEDS_NO_ALPHA=0, NEEDS_BOOL_ALPHA=1, NEEDS_FULL_ALPHA=2; const int NEEDS_NO_ALPHA=0, NEEDS_BOOL_ALPHA=1, NEEDS_FULL_ALPHA=2;
int alpha_type = NEEDS_NO_ALPHA; int alpha_type = NEEDS_NO_ALPHA;
uint32_t max_alpha; std::uint32_t max_alpha;
if( img->format->BitsPerPixel == 8 ) if( img->format->BitsPerPixel == 8 )
{ {
// Short circuit if we already know we have no transparency. // Short circuit if we already know we have no transparency.
@@ -337,13 +338,13 @@ int RageSurfaceUtils::FindSurfaceTraits( const RageSurface *img )
for(int y = 0; y < img->h; ++y) for(int y = 0; y < img->h; ++y)
{ {
uint8_t *row = (uint8_t *)img->pixels + img->pitch*y; std::uint8_t *row = (std::uint8_t *)img->pixels + img->pitch*y;
for(int x = 0; x < img->w; ++x) for(int x = 0; x < img->w; ++x)
{ {
uint32_t val = decodepixel(row, img->format->BytesPerPixel); std::uint32_t val = decodepixel(row, img->format->BytesPerPixel);
uint32_t alpha; std::uint32_t alpha;
if( img->format->BitsPerPixel == 8 ) if( img->format->BitsPerPixel == 8 )
alpha = img->format->palette->colors[val].a; alpha = img->format->palette->colors[val].a;
else else
@@ -373,10 +374,10 @@ int RageSurfaceUtils::FindSurfaceTraits( const RageSurface *img )
// Local helper for BlitTransform. // Local helper for BlitTransform.
static inline void GetRawRGBAV_XY( const RageSurface *src, uint8_t *v, int x, int y ) static inline void GetRawRGBAV_XY( const RageSurface *src, std::uint8_t *v, int x, int y )
{ {
const uint8_t *srcp = (const uint8_t *) src->pixels + (y * src->pitch); const std::uint8_t *srcp = (const std::uint8_t *) src->pixels + (y * src->pitch);
const uint8_t *srcpx = srcp + (x * src->fmt.BytesPerPixel); const std::uint8_t *srcpx = srcp + (x * src->fmt.BytesPerPixel);
RageSurfaceUtils::GetRawRGBAV( srcpx, src->fmt, v ); RageSurfaceUtils::GetRawRGBAV( srcpx, src->fmt, v );
} }
@@ -404,8 +405,8 @@ void RageSurfaceUtils::BlitTransform( const RageSurface *src, RageSurface *dst,
for( int y = 0; y < dst->h; ++y ) for( int y = 0; y < dst->h; ++y )
{ {
uint8_t *dstp = (uint8_t *) dst->pixels + (y * dst->pitch); /* line */ std::uint8_t *dstp = (std::uint8_t *) dst->pixels + (y * dst->pitch); /* line */
uint8_t *dstpx = dstp; // pixel std::uint8_t *dstpx = dstp; // pixel
const float start_y = scale(float(y), 0, float(dst->h), Coords[TL_Y], Coords[BL_Y]); const float start_y = scale(float(y), 0, float(dst->h), Coords[TL_Y], Coords[BL_Y]);
const float end_y = scale(float(y), 0, float(dst->h), Coords[TR_Y], Coords[BR_Y]); const float end_y = scale(float(y), 0, float(dst->h), Coords[TR_Y], Coords[BR_Y]);
@@ -436,7 +437,7 @@ void RageSurfaceUtils::BlitTransform( const RageSurface *src, RageSurface *dst,
src_y[1] = clamp(src_y[1], 0, src->h); src_y[1] = clamp(src_y[1], 0, src->h);
// Decode our four pixels. // Decode our four pixels.
uint8_t v[4][4]; std::uint8_t v[4][4];
GetRawRGBAV_XY(src, v[0], src_x[0], src_y[0]); GetRawRGBAV_XY(src, v[0], src_x[0], src_y[0]);
GetRawRGBAV_XY(src, v[1], src_x[0], src_y[1]); GetRawRGBAV_XY(src, v[1], src_x[0], src_y[1]);
GetRawRGBAV_XY(src, v[2], src_x[1], src_y[0]); GetRawRGBAV_XY(src, v[2], src_x[1], src_y[0]);
@@ -447,7 +448,7 @@ void RageSurfaceUtils::BlitTransform( const RageSurface *src, RageSurface *dst,
float weight_y = src_yp - (src_y[0] + 0.5f); float weight_y = src_yp - (src_y[0] + 0.5f);
// Filter: // Filter:
uint8_t out[4] = { 0,0,0,0 }; std::uint8_t out[4] = { 0,0,0,0 };
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
float sum = 0; float sum = 0;
@@ -455,12 +456,12 @@ void RageSurfaceUtils::BlitTransform( const RageSurface *src, RageSurface *dst,
sum += v[1][i] * (1-weight_x) * (weight_y); sum += v[1][i] * (1-weight_x) * (weight_y);
sum += v[2][i] * (weight_x) * (1-weight_y); sum += v[2][i] * (weight_x) * (1-weight_y);
sum += v[3][i] * (weight_x) * (weight_y); sum += v[3][i] * (weight_x) * (weight_y);
out[i] = (uint8_t) clamp( std::lrint(sum), 0L, 255L ); out[i] = (std::uint8_t) clamp( std::lrint(sum), 0L, 255L );
} }
// If the source has no alpha, set the destination to opaque. // If the source has no alpha, set the destination to opaque.
if( src->format->Amask == 0 ) if( src->format->Amask == 0 )
out[3] = uint8_t( dst->format->Amask >> dst->format->Ashift ); out[3] = std::uint8_t( dst->format->Amask >> dst->format->Ashift );
SetRawRGBAV(dstpx, dst, out); SetRawRGBAV(dstpx, dst, out);
@@ -486,8 +487,8 @@ static bool blit_same_type( const RageSurface *src_surf, const RageSurface *dst_
src_surf->format->Amask != dst_surf->format->Amask ) src_surf->format->Amask != dst_surf->format->Amask )
return false; return false;
const uint8_t *src = src_surf->pixels; const std::uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels; std::uint8_t *dst = dst_surf->pixels;
// If possible, memcpy the whole thing. // If possible, memcpy the whole thing.
if( src_surf->w == width && dst_surf->w == width && src_surf->pitch == dst_surf->pitch ) if( src_surf->w == width && dst_surf->w == width && src_surf->pitch == dst_surf->pitch )
@@ -514,23 +515,23 @@ static bool blit_rgba_to_rgba( const RageSurface *src_surf, const RageSurface *d
if( src_surf->format->BytesPerPixel == 1 || dst_surf->format->BytesPerPixel == 1 ) if( src_surf->format->BytesPerPixel == 1 || dst_surf->format->BytesPerPixel == 1 )
return false; return false;
const uint8_t *src = src_surf->pixels; const std::uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels; std::uint8_t *dst = dst_surf->pixels;
// Bytes to skip at the end of a line. // Bytes to skip at the end of a line.
const int srcskip = src_surf->pitch - width*src_surf->format->BytesPerPixel; const int srcskip = src_surf->pitch - width*src_surf->format->BytesPerPixel;
const int dstskip = dst_surf->pitch - width*dst_surf->format->BytesPerPixel; const int dstskip = dst_surf->pitch - width*dst_surf->format->BytesPerPixel;
const std::array<uint32_t, 4> &src_shifts = src_surf->format->Shift; const std::array<std::uint32_t, 4> &src_shifts = src_surf->format->Shift;
const std::array<uint32_t, 4> &dst_shifts = dst_surf->format->Shift; const std::array<std::uint32_t, 4> &dst_shifts = dst_surf->format->Shift;
const std::array<uint32_t, 4> &src_masks = src_surf->format->Mask; const std::array<std::uint32_t, 4> &src_masks = src_surf->format->Mask;
const std::array<uint32_t, 4> &dst_masks = dst_surf->format->Mask; const std::array<std::uint32_t, 4> &dst_masks = dst_surf->format->Mask;
uint8_t lookup[4][256]; std::uint8_t lookup[4][256];
for( int c = 0; c < 4; ++c ) for( int c = 0; c < 4; ++c )
{ {
const uint32_t max_src_val = src_masks[c] >> src_shifts[c]; const std::uint32_t max_src_val = src_masks[c] >> src_shifts[c];
const uint32_t max_dst_val = dst_masks[c] >> dst_shifts[c]; const std::uint32_t max_dst_val = dst_masks[c] >> dst_shifts[c];
ASSERT( max_src_val <= 0xFF ); ASSERT( max_src_val <= 0xFF );
ASSERT( max_dst_val <= 0xFF ); ASSERT( max_dst_val <= 0xFF );
@@ -539,7 +540,7 @@ static bool blit_rgba_to_rgba( const RageSurface *src_surf, const RageSurface *d
/* The source is missing a channel. Alpha defaults to opaque, other /* The source is missing a channel. Alpha defaults to opaque, other
* channels default to 0. */ * channels default to 0. */
if( c == 3 ) if( c == 3 )
lookup[c][0] = (uint8_t) max_dst_val; lookup[c][0] = (std::uint8_t) max_dst_val;
else else
lookup[c][0] = 0; lookup[c][0] = 0;
} else { } else {
@@ -570,11 +571,11 @@ static bool blit_rgba_to_rgba( const RageSurface *src_surf, const RageSurface *d
* Having separate formulas for increasing and decreasing resolution seems * Having separate formulas for increasing and decreasing resolution seems
* strange; what's wrong here? */ * strange; what's wrong here? */
if( max_src_val > max_dst_val ) if( max_src_val > max_dst_val )
for( uint32_t i = 0; i <= max_src_val; ++i ) for( std::uint32_t i = 0; i <= max_src_val; ++i )
lookup[c][i] = (uint8_t) SCALE( i, 0, max_src_val+1, 0, max_dst_val+1 ); lookup[c][i] = (std::uint8_t) SCALE( i, 0, max_src_val+1, 0, max_dst_val+1 );
else else
for( uint32_t i = 0; i <= max_src_val; ++i ) for( std::uint32_t i = 0; i <= max_src_val; ++i )
lookup[c][i] = (uint8_t) SCALE( i, 0, max_src_val, 0, max_dst_val ); lookup[c][i] = (std::uint8_t) SCALE( i, 0, max_src_val, 0, max_dst_val );
} }
} }
@@ -612,8 +613,8 @@ static bool blit_generic( const RageSurface *src_surf, const RageSurface *dst_su
if( src_surf->format->BytesPerPixel != 1 || dst_surf->format->BytesPerPixel == 1 ) if( src_surf->format->BytesPerPixel != 1 || dst_surf->format->BytesPerPixel == 1 )
return false; return false;
const uint8_t *src = src_surf->pixels; const std::uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels; std::uint8_t *dst = dst_surf->pixels;
// Bytes to skip at the end of a line. // Bytes to skip at the end of a line.
const int srcskip = src_surf->pitch - width*src_surf->format->BytesPerPixel; const int srcskip = src_surf->pitch - width*src_surf->format->BytesPerPixel;
@@ -626,7 +627,7 @@ static bool blit_generic( const RageSurface *src_surf, const RageSurface *dst_su
{ {
unsigned int pixel = RageSurfaceUtils::decodepixel( src, src_surf->format->BytesPerPixel ); unsigned int pixel = RageSurfaceUtils::decodepixel( src, src_surf->format->BytesPerPixel );
uint8_t colors[4]; std::uint8_t colors[4];
// Convert pixel to the destination RGBA. // Convert pixel to the destination RGBA.
colors[0] = src_surf->format->palette->colors[pixel].r; colors[0] = src_surf->format->palette->colors[pixel].r;
colors[1] = src_surf->format->palette->colors[pixel].g; colors[1] = src_surf->format->palette->colors[pixel].g;
@@ -712,11 +713,11 @@ void RageSurfaceUtils::CorrectBorderPixels( RageSurface *img, int width, int hei
{ {
// Duplicate the last column. // Duplicate the last column.
int offset = img->format->BytesPerPixel * (width-1); int offset = img->format->BytesPerPixel * (width-1);
uint8_t *p = (uint8_t *) img->pixels + offset; std::uint8_t *p = (std::uint8_t *) img->pixels + offset;
for( int y = 0; y < height; ++y ) for( int y = 0; y < height; ++y )
{ {
uint32_t pixel = decodepixel( p, img->format->BytesPerPixel ); std::uint32_t pixel = decodepixel( p, img->format->BytesPerPixel );
encodepixel( p+img->format->BytesPerPixel, img->format->BytesPerPixel, pixel ); encodepixel( p+img->format->BytesPerPixel, img->format->BytesPerPixel, pixel );
p += img->pitch; p += img->pitch;
@@ -726,7 +727,7 @@ void RageSurfaceUtils::CorrectBorderPixels( RageSurface *img, int width, int hei
if( height < img->h ) if( height < img->h )
{ {
// Duplicate the last row. // Duplicate the last row.
uint8_t *srcp = img->pixels; std::uint8_t *srcp = img->pixels;
srcp += img->pitch * (height-1); srcp += img->pitch * (height-1);
memcpy( srcp + img->pitch, srcp, img->pitch ); memcpy( srcp + img->pitch, srcp, img->pitch );
} }
@@ -864,10 +865,10 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf
const unsigned int A = (index & Amask) >> Ashift; const unsigned int A = (index & Amask) >> Ashift;
// if only one intensity value, always fullbright // if only one intensity value, always fullbright
const uint8_t ScaledI = Ivalues == 1 ? 255 : clamp( std::lrint(I * (255.0f / (Ivalues-1))), 0L, 255L ); const std::uint8_t ScaledI = Ivalues == 1 ? 255 : clamp( std::lrint(I * (255.0f / (Ivalues-1))), 0L, 255L );
// if only one alpha value, always opaque // if only one alpha value, always opaque
const uint8_t ScaledA = Avalues == 1 ? 255 : clamp( std::lrint(A * (255.0f / (Avalues-1))), 0L, 255L ); const std::uint8_t ScaledA = Avalues == 1 ? 255 : clamp( std::lrint(A * (255.0f / (Avalues-1))), 0L, 255L );
RageSurfaceColor c; RageSurfaceColor c;
c.r = ScaledI; c.r = ScaledI;
@@ -878,8 +879,8 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf
dst_surf->fmt.palette->colors[index] = c; dst_surf->fmt.palette->colors[index] = c;
} }
const uint8_t *src = src_surf->pixels; const std::uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels; std::uint8_t *dst = dst_surf->pixels;
int height = src_surf->h; int height = src_surf->h;
int width = src_surf->w; int width = src_surf->w;
@@ -895,7 +896,7 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf
{ {
unsigned int pixel = decodepixel( src, src_surf->format->BytesPerPixel ); unsigned int pixel = decodepixel( src, src_surf->format->BytesPerPixel );
uint8_t colors[4]; std::uint8_t colors[4];
GetRGBAV(pixel, src_surf, colors); GetRGBAV(pixel, src_surf, colors);
int Ival = 0; int Ival = 0;
@@ -908,7 +909,7 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf
(colors[3] >> Aloss) << Ashift; (colors[3] >> Aloss) << Ashift;
// Store it. // Store it.
*dst = uint8_t(pixel); *dst = std::uint8_t(pixel);
src += src_surf->format->BytesPerPixel; src += src_surf->format->BytesPerPixel;
dst += dst_surf->format->BytesPerPixel; dst += dst_surf->format->BytesPerPixel;
@@ -938,14 +939,14 @@ RageSurface *RageSurfaceUtils::MakeDummySurface( int height, int width )
* Search the edge for it; if we find it, use that as the color key. */ * Search the edge for it; if we find it, use that as the color key. */
static bool ImageUsesOffHotPink( const RageSurface *img ) static bool ImageUsesOffHotPink( const RageSurface *img )
{ {
uint32_t OffHotPink; std::uint32_t OffHotPink;
if( !img->format->MapRGBA( 0xF8, 0, 0xF8, 0xFF, OffHotPink ) ) if( !img->format->MapRGBA( 0xF8, 0, 0xF8, 0xFF, OffHotPink ) )
return false; return false;
const uint8_t *p = img->pixels; const std::uint8_t *p = img->pixels;
for( int x = 0; x < img->w; ++x ) for( int x = 0; x < img->w; ++x )
{ {
uint32_t val = RageSurfaceUtils::decodepixel( p, img->format->BytesPerPixel ); std::uint32_t val = RageSurfaceUtils::decodepixel( p, img->format->BytesPerPixel );
if( val == OffHotPink ) if( val == OffHotPink )
return true; return true;
p += img->format->BytesPerPixel; p += img->format->BytesPerPixel;
@@ -955,7 +956,7 @@ static bool ImageUsesOffHotPink( const RageSurface *img )
p += img->pitch * (img->h-1); p += img->pitch * (img->h-1);
for( int i=0; i < img->w; i++ ) for( int i=0; i < img->w; i++ )
{ {
uint32_t val = RageSurfaceUtils::decodepixel( p, img->format->BytesPerPixel ); std::uint32_t val = RageSurfaceUtils::decodepixel( p, img->format->BytesPerPixel );
if( val == OffHotPink ) if( val == OffHotPink )
return true; return true;
p += img->format->BytesPerPixel; p += img->format->BytesPerPixel;
@@ -969,7 +970,7 @@ void RageSurfaceUtils::ApplyHotPinkColorKey( RageSurface *&img )
{ {
if( img->format->BitsPerPixel == 8 ) if( img->format->BitsPerPixel == 8 )
{ {
uint32_t color; std::uint32_t color;
if( img->format->MapRGBA( 0xF8, 0, 0xF8, 0xFF, color ) ) if( img->format->MapRGBA( 0xF8, 0, 0xF8, 0xFF, color ) )
img->format->palette->colors[ color ].a = 0; img->format->palette->colors[ color ].a = 0;
if( img->format->MapRGBA( 0xFF, 0, 0xFF, 0xFF, color ) ) if( img->format->MapRGBA( 0xFF, 0, 0xFF, 0xFF, color ) )
@@ -991,7 +992,7 @@ void RageSurfaceUtils::ApplyHotPinkColorKey( RageSurface *&img )
{ {
img->format->Amask = 1<<i; img->format->Amask = 1<<i;
img->format->Aloss = 7; img->format->Aloss = 7;
img->format->Ashift = (uint8_t) i; img->format->Ashift = (std::uint8_t) i;
} }
} }
*/ */
@@ -1001,7 +1002,7 @@ void RageSurfaceUtils::ApplyHotPinkColorKey( RageSurface *&img )
32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF ); 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF );
} }
uint32_t HotPink; std::uint32_t HotPink;
bool bHaveColorKey; bool bHaveColorKey;
if( ImageUsesOffHotPink(img) ) if( ImageUsesOffHotPink(img) )
@@ -1013,11 +1014,11 @@ void RageSurfaceUtils::ApplyHotPinkColorKey( RageSurface *&img )
for( int y = 0; y < img->h; ++y ) for( int y = 0; y < img->h; ++y )
{ {
uint8_t *row = img->pixels + img->pitch*y; std::uint8_t *row = img->pixels + img->pitch*y;
for( int x = 0; x < img->w; ++x ) for( int x = 0; x < img->w; ++x )
{ {
uint32_t val = decodepixel( row, img->format->BytesPerPixel ); std::uint32_t val = decodepixel( row, img->format->BytesPerPixel );
if( val == HotPink ) if( val == HotPink )
encodepixel( row, img->format->BytesPerPixel, 0 ); encodepixel( row, img->format->BytesPerPixel, 0 );
+15 -13
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_SURFACE_UTILS_H #ifndef RAGE_SURFACE_UTILS_H
#define RAGE_SURFACE_UTILS_H #define RAGE_SURFACE_UTILS_H
#include <cstdint>
struct RageSurfaceColor; struct RageSurfaceColor;
struct RageSurfacePalette; struct RageSurfacePalette;
struct RageSurfaceFormat; struct RageSurfaceFormat;
@@ -11,27 +13,27 @@ struct RageSurface;
/** @brief Utility functions for the RageSurfaces. */ /** @brief Utility functions for the RageSurfaces. */
namespace RageSurfaceUtils namespace RageSurfaceUtils
{ {
uint32_t decodepixel( const uint8_t *p, int bpp ); std::uint32_t decodepixel( const std::uint8_t *p, int bpp );
void encodepixel( uint8_t *p, int bpp, uint32_t pixel ); void encodepixel( std::uint8_t *p, int bpp, std::uint32_t pixel );
void GetRawRGBAV( uint32_t pixel, const RageSurfaceFormat &fmt, uint8_t *v ); void GetRawRGBAV( std::uint32_t pixel, const RageSurfaceFormat &fmt, std::uint8_t *v );
void GetRawRGBAV( const uint8_t *p, const RageSurfaceFormat &fmt, uint8_t *v ); void GetRawRGBAV( const std::uint8_t *p, const RageSurfaceFormat &fmt, std::uint8_t *v );
void GetRGBAV( uint32_t pixel, const RageSurface *src, uint8_t *v ); void GetRGBAV( std::uint32_t pixel, const RageSurface *src, std::uint8_t *v );
void GetRGBAV( const uint8_t *p, const RageSurface *src, uint8_t *v ); void GetRGBAV( const std::uint8_t *p, const RageSurface *src, std::uint8_t *v );
uint32_t SetRawRGBAV( const RageSurfaceFormat *fmt, const uint8_t *v ); std::uint32_t SetRawRGBAV( const RageSurfaceFormat *fmt, const std::uint8_t *v );
void SetRawRGBAV( uint8_t *p, const RageSurface *src, const uint8_t *v ); void SetRawRGBAV( std::uint8_t *p, const RageSurface *src, const std::uint8_t *v );
uint32_t SetRGBAV( const RageSurfaceFormat *fmt, const uint8_t *v ); std::uint32_t SetRGBAV( const RageSurfaceFormat *fmt, const std::uint8_t *v );
void SetRGBAV( uint8_t *p, const RageSurface *src, const uint8_t *v ); void SetRGBAV( std::uint8_t *p, const RageSurface *src, const std::uint8_t *v );
/* Get the number of bits representing each color channel in fmt. */ /* Get the number of bits representing each color channel in fmt. */
void GetBitsPerChannel( const RageSurfaceFormat *fmt, uint32_t bits[4] ); void GetBitsPerChannel( const RageSurfaceFormat *fmt, std::uint32_t bits[4] );
void CopySurface( const RageSurface *src, RageSurface *dest ); void CopySurface( const RageSurface *src, RageSurface *dest );
bool ConvertSurface( const RageSurface *src, RageSurface *&dst, bool ConvertSurface( const RageSurface *src, RageSurface *&dst,
int width, int height, int bpp, uint32_t R, uint32_t G, uint32_t B, uint32_t A ); int width, int height, int bpp, std::uint32_t R, std::uint32_t G, std::uint32_t B, std::uint32_t A );
void ConvertSurface( RageSurface *&image, void ConvertSurface( RageSurface *&image,
int width, int height, int bpp, uint32_t R, uint32_t G, uint32_t B, uint32_t A ); int width, int height, int bpp, std::uint32_t R, std::uint32_t G, std::uint32_t B, std::uint32_t A );
void FixHiddenAlpha( RageSurface *img ); void FixHiddenAlpha( RageSurface *img );
+19 -17
View File
@@ -4,6 +4,8 @@
#include "RageSurface.h" #include "RageSurface.h"
#include "RageSurfaceUtils.h" #include "RageSurfaceUtils.h"
#include <cstdint>
#define DitherMatDim 4 #define DitherMatDim 4
// Fractions, 0/16 to 15/16: // Fractions, 0/16 to 15/16:
@@ -18,7 +20,7 @@ static const int DitherMat[DitherMatDim][DitherMatDim] =
static int DitherMatCalc[DitherMatDim][DitherMatDim]; static int DitherMatCalc[DitherMatDim][DitherMatDim];
// conv is the ratio from the input to the output. // conv is the ratio from the input to the output.
static uint8_t DitherPixel(int x, int y, int intensity, int conv) static std::uint8_t DitherPixel(int x, int y, int intensity, int conv)
{ {
// The intensity matrix wraps. This assumes the matrix dims are a power of 2. // The intensity matrix wraps. This assumes the matrix dims are a power of 2.
x &= DitherMatDim-1; x &= DitherMatDim-1;
@@ -41,7 +43,7 @@ static uint8_t DitherPixel(int x, int y, int intensity, int conv)
out_intensity += DitherMatCalc[y][x]; out_intensity += DitherMatCalc[y][x];
// Truncate, and add e to make sure a value of 14.999998 -> 15. // Truncate, and add e to make sure a value of 14.999998 -> 15.
return uint8_t((out_intensity + 1) >> 16); return std::uint8_t((out_intensity + 1) >> 16);
} }
void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst ) void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst )
@@ -66,7 +68,7 @@ void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst )
// We can't dither to paletted surfaces. // We can't dither to paletted surfaces.
ASSERT( dst->format->BytesPerPixel > 1 ); ASSERT( dst->format->BytesPerPixel > 1 );
uint32_t src_cbits[4], dst_cbits[4]; std::uint32_t src_cbits[4], dst_cbits[4];
RageSurfaceUtils::GetBitsPerChannel( src->format, src_cbits ); RageSurfaceUtils::GetBitsPerChannel( src->format, src_cbits );
RageSurfaceUtils::GetBitsPerChannel( dst->format, dst_cbits ); RageSurfaceUtils::GetBitsPerChannel( dst->format, dst_cbits );
@@ -84,18 +86,18 @@ void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst )
} }
// Max alpha value; used when there's no alpha source. // Max alpha value; used when there's no alpha source.
const uint8_t alpha_max = uint8_t((1 << dst_cbits[3]) - 1); const std::uint8_t alpha_max = std::uint8_t((1 << dst_cbits[3]) - 1);
// For each row: // For each row:
for( int row = 0; row < src->h; ++row ) for( int row = 0; row < src->h; ++row )
{ {
const uint8_t *srcp = src->pixels + row * src->pitch; const std::uint8_t *srcp = src->pixels + row * src->pitch;
uint8_t *dstp = dst->pixels + row * dst->pitch; std::uint8_t *dstp = dst->pixels + row * dst->pitch;
// For each pixel: // For each pixel:
for( int col = 0; col < src->w; ++col ) for( int col = 0; col < src->w; ++col )
{ {
uint8_t colors[4]; std::uint8_t colors[4];
RageSurfaceUtils::GetRawRGBAV( srcp, src->fmt, colors ); RageSurfaceUtils::GetRawRGBAV( srcp, src->fmt, colors );
// Note that we don't dither the alpha channel. // Note that we don't dither the alpha channel.
@@ -117,7 +119,7 @@ void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst )
int out_intensity = colors[3] * conv[3]; int out_intensity = colors[3] * conv[3];
// Round: // Round:
colors[3] = uint8_t((out_intensity + 32767) >> 16); colors[3] = std::uint8_t((out_intensity + 32767) >> 16);
} }
// Raw value -> int -> pixel // Raw value -> int -> pixel
@@ -130,7 +132,7 @@ void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst )
} }
static uint8_t EDDitherPixel( int x, int y, int intensity, int conv, int32_t &accumError ) static std::uint8_t EDDitherPixel( int x, int y, int intensity, int conv, std::int32_t &accumError )
{ {
// Convert the number to the destination range. // Convert the number to the destination range.
int out_intensity = intensity * conv; int out_intensity = intensity * conv;
@@ -149,7 +151,7 @@ static uint8_t EDDitherPixel( int x, int y, int intensity, int conv, int32_t &ac
clamped_intensity &= 0xFF0000; clamped_intensity &= 0xFF0000;
// Truncate. // Truncate.
uint8_t ret = uint8_t(clamped_intensity >> 16); std::uint8_t ret = std::uint8_t(clamped_intensity >> 16);
accumError = out_intensity - clamped_intensity; accumError = out_intensity - clamped_intensity;
@@ -170,7 +172,7 @@ void RageSurfaceUtils::ErrorDiffusionDither( const RageSurface *src, RageSurface
// We can't dither to paletted surfaces. // We can't dither to paletted surfaces.
ASSERT( dst->format->BytesPerPixel > 1 ); ASSERT( dst->format->BytesPerPixel > 1 );
uint32_t src_cbits[4], dst_cbits[4]; std::uint32_t src_cbits[4], dst_cbits[4];
RageSurfaceUtils::GetBitsPerChannel( src->format, src_cbits ); RageSurfaceUtils::GetBitsPerChannel( src->format, src_cbits );
RageSurfaceUtils::GetBitsPerChannel( dst->format, dst_cbits ); RageSurfaceUtils::GetBitsPerChannel( dst->format, dst_cbits );
@@ -188,20 +190,20 @@ void RageSurfaceUtils::ErrorDiffusionDither( const RageSurface *src, RageSurface
} }
// Max alpha value; used when there's no alpha source. // Max alpha value; used when there's no alpha source.
const uint8_t alpha_max = uint8_t((1 << dst_cbits[3]) - 1); const std::uint8_t alpha_max = std::uint8_t((1 << dst_cbits[3]) - 1);
// For each row: // For each row:
for(int row = 0; row < src->h; ++row) for(int row = 0; row < src->h; ++row)
{ {
int32_t accumError[4] = { 0, 0, 0, 0 }; // accum error values are reset every row std::int32_t accumError[4] = { 0, 0, 0, 0 }; // accum error values are reset every row
const uint8_t *srcp = src->pixels + row * src->pitch; const std::uint8_t *srcp = src->pixels + row * src->pitch;
uint8_t *dstp = dst->pixels + row * dst->pitch; std::uint8_t *dstp = dst->pixels + row * dst->pitch;
// For each pixel in row: // For each pixel in row:
for( int col = 0; col < src->w; ++col ) for( int col = 0; col < src->w; ++col )
{ {
uint8_t colors[4]; std::uint8_t colors[4];
RageSurfaceUtils::GetRawRGBAV( srcp, src->fmt, colors ); RageSurfaceUtils::GetRawRGBAV( srcp, src->fmt, colors );
for( int c = 0; c < 3; ++c ) for( int c = 0; c < 3; ++c )
@@ -221,7 +223,7 @@ void RageSurfaceUtils::ErrorDiffusionDither( const RageSurface *src, RageSurface
int out_intensity = colors[3] * conv[3]; int out_intensity = colors[3] * conv[3];
// Round: // Round:
colors[3] = uint8_t((out_intensity + 32767) >> 16); colors[3] = std::uint8_t((out_intensity + 32767) >> 16);
} }
RageSurfaceUtils::SetRawRGBAV( dstp, dst, colors ); RageSurfaceUtils::SetRawRGBAV( dstp, dst, colors );
+19 -17
View File
@@ -6,8 +6,10 @@
#include "RageSurfaceUtils.h" #include "RageSurfaceUtils.h"
#include "RageUtil.h" #include "RageUtil.h"
typedef uint8_t pixval; #include <cstdint>
typedef uint8_t apixel[4];
typedef std::uint8_t pixval;
typedef std::uint8_t apixel[4];
#define PAM_GETR(p) ((p)[0]) #define PAM_GETR(p) ((p)[0])
#define PAM_GETG(p) ((p)[1]) #define PAM_GETG(p) ((p)[1])
@@ -18,7 +20,7 @@ typedef uint8_t apixel[4];
#define PAM_EQUAL(p,q) \ #define PAM_EQUAL(p,q) \
((p)[0] == (q)[0] && (p)[1] == (q)[1] && (p)[2] == (q)[2] && (p)[3] == (q)[3]) ((p)[0] == (q)[0] && (p)[1] == (q)[1] && (p)[2] == (q)[2] && (p)[3] == (q)[3])
#define PAM_DEPTH(p) \ #define PAM_DEPTH(p) \
PAM_ASSIGN( (p), (uint8_t) table[PAM_GETR(p)], (uint8_t) table[PAM_GETG(p)], (uint8_t) table[PAM_GETB(p)], (uint8_t) table[PAM_GETA(p)] ) PAM_ASSIGN( (p), (std::uint8_t) table[PAM_GETR(p)], (std::uint8_t) table[PAM_GETG(p)], (std::uint8_t) table[PAM_GETB(p)], (std::uint8_t) table[PAM_GETA(p)] )
struct acolorhist_item struct acolorhist_item
{ {
@@ -90,8 +92,8 @@ static bool compare_index_3( const acolorhist_item &ch1, const acolorhist_item &
} }
static acolorhist_item *pam_computeacolorhist( const RageSurface *src, int maxacolors, int* acolorsP ); static acolorhist_item *pam_computeacolorhist( const RageSurface *src, int maxacolors, int* acolorsP );
static void pam_addtoacolorhash( acolorhash_hash &acht, const uint8_t acolorP[4], int value ); static void pam_addtoacolorhash( acolorhash_hash &acht, const std::uint8_t acolorP[4], int value );
static int pam_lookupacolor( const acolorhash_hash &acht, const uint8_t acolorP[4] ); static int pam_lookupacolor( const acolorhash_hash &acht, const std::uint8_t acolorP[4] );
static void pam_freeacolorhist( acolorhist_item *achv ); static void pam_freeacolorhist( acolorhist_item *achv );
struct pixerror_t struct pixerror_t
@@ -132,7 +134,7 @@ void RageSurfaceUtils::Palettize( RageSurface *&pImg, int iColors, bool bDither
int table[256]; int table[256];
for( int c = 0; c <= maxval; ++c ) for( int c = 0; c <= maxval; ++c )
{ {
table[c] = ( (uint8_t) c * newmaxval + maxval/2 ) / maxval; table[c] = ( (std::uint8_t) c * newmaxval + maxval/2 ) / maxval;
} }
for( int row = 0; row < pImg->h; ++row ) for( int row = 0; row < pImg->h; ++row )
{ {
@@ -201,25 +203,25 @@ void RageSurfaceUtils::Palettize( RageSurface *&pImg, int iColors, bool bDither
limitcol = -1; limitcol = -1;
} }
const uint8_t *pIn = pImg->pixels + row*pImg->pitch; const std::uint8_t *pIn = pImg->pixels + row*pImg->pitch;
uint8_t *pOut = pRet->pixels + row*pRet->pitch; std::uint8_t *pOut = pRet->pixels + row*pRet->pitch;
pIn += col * 4; pIn += col * 4;
pOut += col; pOut += col;
do do
{ {
int32_t sc[4]; std::int32_t sc[4];
uint8_t pixel[4] = { pIn[0], pIn[1], pIn[2], pIn[3] }; std::uint8_t pixel[4] = { pIn[0], pIn[1], pIn[2], pIn[3] };
if( bDither ) if( bDither )
{ {
// Use Floyd-Steinberg errors to adjust actual color. // Use Floyd-Steinberg errors to adjust actual color.
for( int c = 0; c < 4; ++c ) for( int c = 0; c < 4; ++c )
{ {
sc[c] = pixel[c] + thiserr[col + 1].c[c] / FS_SCALE; sc[c] = pixel[c] + thiserr[col + 1].c[c] / FS_SCALE;
sc[c] = clamp( sc[c], 0, (int32_t) maxval ); sc[c] = clamp( sc[c], 0, (std::int32_t) maxval );
} }
PAM_ASSIGN( pixel, (uint8_t)sc[0], (uint8_t)sc[1], (uint8_t)sc[2], (uint8_t)sc[3] ); PAM_ASSIGN( pixel, (std::uint8_t)sc[0], (std::uint8_t)sc[1], (std::uint8_t)sc[2], (std::uint8_t)sc[3] );
} }
// Check hash table to see if we have already matched this color. // Check hash table to see if we have already matched this color.
@@ -238,7 +240,7 @@ void RageSurfaceUtils::Palettize( RageSurface *&pImg, int iColors, bool bDither
long dist = 2000000000; long dist = 2000000000;
for( int i = 0; i < newcolors; ++i ) for( int i = 0; i < newcolors; ++i )
{ {
const uint8_t *colors2 = acolormap[i].acolor; const std::uint8_t *colors2 = acolormap[i].acolor;
int newdist = 0; int newdist = 0;
newdist += pSquareTable[ int(pixel[0]) - colors2[0] ]; newdist += pSquareTable[ int(pixel[0]) - colors2[0] ];
@@ -281,7 +283,7 @@ void RageSurfaceUtils::Palettize( RageSurface *&pImg, int iColors, bool bDither
} }
} }
*pOut = (uint8_t) ind; *pOut = (std::uint8_t) ind;
if( !fs_direction ) if( !fs_direction )
{ {
@@ -478,7 +480,7 @@ static acolorhist_item *mediancut( acolorhist_item *achv, int colors, int sum, i
b = std::min( b, (long) maxval ); b = std::min( b, (long) maxval );
a = a / lSum; a = a / lSum;
a = std::min( a, (long) maxval ); a = std::min( a, (long) maxval );
PAM_ASSIGN( acolormap[bi].acolor, (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a ); PAM_ASSIGN( acolormap[bi].acolor, (std::uint8_t)r, (std::uint8_t)g, (std::uint8_t)b, (std::uint8_t)a );
#endif // REP_AVERAGE_PIXELS #endif // REP_AVERAGE_PIXELS
} }
@@ -577,7 +579,7 @@ static acolorhist_item *pam_computeacolorhist( const RageSurface *src, int maxac
return achv; return achv;
} }
static void pam_addtoacolorhash( acolorhash_hash &acht, const uint8_t acolorP[4], int value ) static void pam_addtoacolorhash( acolorhash_hash &acht, const std::uint8_t acolorP[4], int value )
{ {
acolorhist_list achl = (acolorhist_list) malloc( sizeof(struct acolorhist_list_item) ); acolorhist_list achl = (acolorhist_list) malloc( sizeof(struct acolorhist_list_item) );
ASSERT( achl != nullptr ); ASSERT( achl != nullptr );
@@ -590,7 +592,7 @@ static void pam_addtoacolorhash( acolorhash_hash &acht, const uint8_t acolorP[4]
} }
static int pam_lookupacolor( const acolorhash_hash &acht, const uint8_t acolorP[4] ) static int pam_lookupacolor( const acolorhash_hash &acht, const std::uint8_t acolorP[4] )
{ {
const int hash = pam_hashapixel( acolorP ); const int hash = pam_hashapixel( acolorP );
for ( acolorhist_list_item *achl = acht.hash[hash]; achl != nullptr; achl = achl->next ) for ( acolorhist_list_item *achl = acht.hash[hash]; achl != nullptr; achl = achl->next )
+19 -18
View File
@@ -5,6 +5,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include <cmath> #include <cmath>
#include <cstdint>
#include <vector> #include <vector>
/* Coordinate 0x0 represents the exact top-left corner of a bitmap. .5x.5 /* Coordinate 0x0 represents the exact top-left corner of a bitmap. .5x.5
@@ -14,7 +15,7 @@
* (Look at a grid: map coordinates to the lines, not the squares between the * (Look at a grid: map coordinates to the lines, not the squares between the
* lines.) */ * lines.) */
static void InitVectors( std::vector<int> &s0, std::vector<int> &s1, std::vector<uint32_t> &percent, int src, int dst ) static void InitVectors( std::vector<int> &s0, std::vector<int> &s1, std::vector<std::uint32_t> &percent, int src, int dst )
{ {
if( src >= dst ) if( src >= dst )
{ {
@@ -51,7 +52,7 @@ static void InitVectors( std::vector<int> &s0, std::vector<int> &s1, std::vector
/* sax is somewhere between the centers of both sampled /* sax is somewhere between the centers of both sampled
* pixels; find the percentage: */ * pixels; find the percentage: */
const float p = (1.0f - (sax - fleft) / xdist) * 16777216.0f; const float p = (1.0f - (sax - fleft) / xdist) * 16777216.0f;
percent.push_back( uint32_t(p) ); percent.push_back( std::uint32_t(p) );
} }
} }
} }
@@ -74,7 +75,7 @@ static void InitVectors( std::vector<int> &s0, std::vector<int> &s1, std::vector
s1.push_back( clamp(int(sax+1), 0, src-1) ); s1.push_back( clamp(int(sax+1), 0, src-1) );
const float p = (1.0f - (sax - std::floor(sax))) * 16777216.0f; const float p = (1.0f - (sax - std::floor(sax))) * 16777216.0f;
percent.push_back( uint32_t(p) ); percent.push_back( std::uint32_t(p) );
} }
} }
} }
@@ -84,42 +85,42 @@ static void ZoomSurface( const RageSurface * src, RageSurface * dst )
/* For each destination coordinate, two source rows, two source columns /* For each destination coordinate, two source rows, two source columns
* and the percentage of the first row and first column: */ * and the percentage of the first row and first column: */
std::vector<int> esx0, esx1, esy0, esy1; std::vector<int> esx0, esx1, esy0, esy1;
std::vector<uint32_t> ex0, ey0; std::vector<std::uint32_t> ex0, ey0;
InitVectors( esx0, esx1, ex0, src->w, dst->w ); InitVectors( esx0, esx1, ex0, src->w, dst->w );
InitVectors( esy0, esy1, ey0, src->h, dst->h ); InitVectors( esy0, esy1, ey0, src->h, dst->h );
// This is where all of the real work is done. // This is where all of the real work is done.
const uint8_t *sp = (uint8_t *) src->pixels; const std::uint8_t *sp = (std::uint8_t *) src->pixels;
const int height = dst->h; const int height = dst->h;
const int width = dst->w; const int width = dst->w;
for( int y = 0; y < height; y++ ) for( int y = 0; y < height; y++ )
{ {
uint8_t *dp = (uint8_t *) (dst->pixels + dst->pitch*y); std::uint8_t *dp = (std::uint8_t *) (dst->pixels + dst->pitch*y);
/* current source pointer and next source pointer (first and second /* current source pointer and next source pointer (first and second
* rows sampled for this row): */ * rows sampled for this row): */
const uint8_t *csp = sp + esy0[y] * src->pitch; const std::uint8_t *csp = sp + esy0[y] * src->pitch;
const uint8_t *ncsp = sp + esy1[y] * src->pitch; const std::uint8_t *ncsp = sp + esy1[y] * src->pitch;
for( int x = 0; x < width; x++ ) for( int x = 0; x < width; x++ )
{ {
// Grab pointers to the sampled pixels: // Grab pointers to the sampled pixels:
const uint8_t *c00 = csp + esx0[x]*4; const std::uint8_t *c00 = csp + esx0[x]*4;
const uint8_t *c01 = csp + esx1[x]*4; const std::uint8_t *c01 = csp + esx1[x]*4;
const uint8_t *c10 = ncsp + esx0[x]*4; const std::uint8_t *c10 = ncsp + esx0[x]*4;
const uint8_t *c11 = ncsp + esx1[x]*4; const std::uint8_t *c11 = ncsp + esx1[x]*4;
for( int c = 0; c < 4; ++c ) for( int c = 0; c < 4; ++c )
{ {
uint32_t x0 = uint32_t(c00[c]) * ex0[x]; std::uint32_t x0 = std::uint32_t(c00[c]) * ex0[x];
x0 += uint32_t(c01[c]) * (16777216 - ex0[x]); x0 += std::uint32_t(c01[c]) * (16777216 - ex0[x]);
x0 >>= 24; x0 >>= 24;
uint32_t x1 = uint32_t(c10[c]) * ex0[x]; std::uint32_t x1 = std::uint32_t(c10[c]) * ex0[x];
x1 += uint32_t(c11[c]) * (16777216 - ex0[x]); x1 += std::uint32_t(c11[c]) * (16777216 - ex0[x]);
x1 >>= 24; x1 >>= 24;
const uint32_t res = ((x0 * ey0[y]) + (x1 * (16777216-ey0[y])) + 8388608) >> 24; const std::uint32_t res = ((x0 * ey0[y]) + (x1 * (16777216-ey0[y])) + 8388608) >> 24;
dp[c] = uint8_t(res); dp[c] = std::uint8_t(res);
} }
// Advance destination pointer. // Advance destination pointer.
+7 -4
View File
@@ -4,6 +4,9 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "RageLog.h" #include "RageLog.h"
#include "RageSurface.h" #include "RageSurface.h"
#include <cstdint>
using namespace FileReading; using namespace FileReading;
/* Tested with http://entropymine.com/jason/bmpsuite/. */ /* Tested with http://entropymine.com/jason/bmpsuite/. */
@@ -38,10 +41,10 @@ static RageSurfaceUtils::OpenResult LoadBMP( RageFile &f, RageSurface *&img, RSt
read_u32_le( f, sError ); /* file size */ read_u32_le( f, sError ); /* file size */
read_u32_le( f, sError ); /* unused */ read_u32_le( f, sError ); /* unused */
uint32_t iDataOffset = read_u32_le( f, sError ); std::uint32_t iDataOffset = read_u32_le( f, sError );
uint32_t iHeaderSize = read_u32_le( f, sError ); std::uint32_t iHeaderSize = read_u32_le( f, sError );
uint32_t iWidth, iHeight, iPlanes, iBPP, iCompression = COMP_BI_RGB, iColors = 0; std::uint32_t iWidth, iHeight, iPlanes, iBPP, iCompression = COMP_BI_RGB, iColors = 0;
if( iHeaderSize == 12 ) if( iHeaderSize == 12 )
{ {
/* OS/2 format */ /* OS/2 format */
@@ -154,7 +157,7 @@ static RageSurfaceUtils::OpenResult LoadBMP( RageFile &f, RageSurface *&img, RSt
for( int y = (int) iHeight-1; y >= 0; --y ) for( int y = (int) iHeight-1; y >= 0; --y )
{ {
uint8_t *pRow = img->pixels + img->pitch*y; std::uint8_t *pRow = img->pixels + img->pitch*y;
RString buf; RString buf;
f.Read( buf, iFilePitch ); f.Read( buf, iFilePitch );
+2 -1
View File
@@ -6,6 +6,7 @@
#include "RageSurface.h" #include "RageSurface.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <setjmp.h> #include <setjmp.h>
extern "C" { extern "C" {
@@ -169,7 +170,7 @@ static RageSurface *RageSurface_Load_JPEG( RageFile *f, const char *fn, char err
for( int i = 0; i < 256; ++i ) for( int i = 0; i < 256; ++i )
{ {
RageSurfaceColor color; RageSurfaceColor color;
color.r = color.g = color.b = (int8_t) i; color.r = color.g = color.b = (std::int8_t) i;
color.a = 0xFF; color.a = 0xFF;
img->fmt.palette->colors[i] = color; img->fmt.palette->colors[i] = color;
} }
+5 -3
View File
@@ -1,13 +1,15 @@
#include "global.h" #include "global.h"
#include <png.h>
#include "RageSurface_Load_PNG.h" #include "RageSurface_Load_PNG.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "RageLog.h" #include "RageLog.h"
#include "RageFile.h" #include "RageFile.h"
#include "RageSurface.h" #include "RageSurface.h"
#include <cstdint>
#include <png.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#if defined(_BINARY_PNG) #if defined(_BINARY_PNG)
#pragma comment(lib, "libpng.lib") #pragma comment(lib, "libpng.lib")
@@ -142,7 +144,7 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro
/* Fake PNG_COLOR_TYPE_GRAY. */ /* Fake PNG_COLOR_TYPE_GRAY. */
for( int i = 0; i < 256; ++i ) for( int i = 0; i < 256; ++i )
{ {
colors[i].r = colors[i].g = colors[i].b = (int8_t) i; colors[i].r = colors[i].g = colors[i].b = (std::int8_t) i;
colors[i].a = 0xFF; colors[i].a = 0xFF;
} }
+8 -6
View File
@@ -6,6 +6,8 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "RageLog.h" #include "RageLog.h"
#include "RageSurface.h" #include "RageSurface.h"
#include <cstdint>
#include <map> #include <map>
#define CheckLine() \ #define CheckLine() \
@@ -57,9 +59,9 @@ RageSurface *RageSurface_Load_XPM( char * const *xpm, RString &error )
if( sscanf( clr, "%2x%2x%2x", &r, &g, &b ) != 3 ) if( sscanf( clr, "%2x%2x%2x", &r, &g, &b ) != 3 )
continue; continue;
RageSurfaceColor colorval; RageSurfaceColor colorval;
colorval.r = (uint8_t) r; colorval.r = (std::uint8_t) r;
colorval.g = (uint8_t) g; colorval.g = (std::uint8_t) g;
colorval.b = (uint8_t) b; colorval.b = (std::uint8_t) b;
colorval.a = 0xFF; colorval.a = 0xFF;
colors.push_back( colorval ); colors.push_back( colorval );
@@ -88,9 +90,9 @@ RageSurface *RageSurface_Load_XPM( char * const *xpm, RString &error )
return nullptr; return nullptr;
} }
int8_t *p = (int8_t *) img->pixels; std::int8_t *p = (std::int8_t *) img->pixels;
p += y * img->pitch; p += y * img->pitch;
int32_t *p32 = (int32_t *) p; std::int32_t *p32 = (std::int32_t *) p;
for( int x = 0; x < width; ++x ) for( int x = 0; x < width; ++x )
{ {
RString color_name = row.substr( x*color_length, color_length ); RString color_name = row.substr( x*color_length, color_length );
@@ -105,7 +107,7 @@ RageSurface *RageSurface_Load_XPM( char * const *xpm, RString &error )
if( colors.size() <= 256 ) if( colors.size() <= 256 )
{ {
p[x] = (int8_t) it->second; p[x] = (std::int8_t) it->second;
} else { } else {
const RageSurfaceColor &color = colors[it->second]; const RageSurfaceColor &color = colors[it->second];
p32[x] = (color.r << 24) + (color.g << 16) + (color.b << 8); p32[x] = (color.r << 24) + (color.g << 16) + (color.b << 8);
+9 -7
View File
@@ -5,6 +5,8 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "RageFile.h" #include "RageFile.h"
#include <cstdint>
static void WriteBytes( RageFile &f, RString &sError, const void *buf, int size ) static void WriteBytes( RageFile &f, RString &sError, const void *buf, int size )
{ {
if( sError.size() != 0 ) if( sError.size() != 0 )
@@ -15,16 +17,16 @@ static void WriteBytes( RageFile &f, RString &sError, const void *buf, int size
sError = f.GetError(); sError = f.GetError();
} }
static void write_le16( RageFile &f, RString &sError, uint16_t val ) static void write_le16( RageFile &f, RString &sError, std::uint16_t val )
{ {
val = Swap16LE( val ); val = Swap16LE( val );
WriteBytes( f, sError, &val, sizeof(uint16_t) ); WriteBytes( f, sError, &val, sizeof(std::uint16_t) );
} }
static void write_le32( RageFile &f, RString &sError, uint32_t val ) static void write_le32( RageFile &f, RString &sError, std::uint32_t val )
{ {
val = Swap32LE( val ); val = Swap32LE( val );
WriteBytes( f, sError, &val, sizeof(uint32_t) ); WriteBytes( f, sError, &val, sizeof(std::uint32_t) );
} }
bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f ) bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f )
@@ -51,7 +53,7 @@ bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f )
write_le32( f, sError, surface->w ); // width (offset 0x14) write_le32( f, sError, surface->w ); // width (offset 0x14)
write_le32( f, sError, surface->h ); // height (offset 0x18) write_le32( f, sError, surface->h ); // height (offset 0x18)
write_le16( f, sError, 1 ); // planes (offset 0x1A) write_le16( f, sError, 1 ); // planes (offset 0x1A)
write_le16( f, sError, (uint16_t) converted_surface->fmt.BytesPerPixel*8 ); // bpp (offset 0x1C) write_le16( f, sError, (std::uint16_t) converted_surface->fmt.BytesPerPixel*8 ); // bpp (offset 0x1C)
write_le32( f, sError, 0 ); // compression (offset 0x1E) write_le32( f, sError, 0 ); // compression (offset 0x1E)
write_le32( f, sError, iDataSize ); // bitmap size (offset 0x22) write_le32( f, sError, iDataSize ); // bitmap size (offset 0x22)
write_le32( f, sError, 0 ); // horiz resolution (offset 0x26) write_le32( f, sError, 0 ); // horiz resolution (offset 0x26)
@@ -61,11 +63,11 @@ bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f )
for( int y = converted_surface->h-1; y >= 0; --y ) for( int y = converted_surface->h-1; y >= 0; --y )
{ {
const uint8_t *pRow = converted_surface->pixels + converted_surface->pitch*y; const std::uint8_t *pRow = converted_surface->pixels + converted_surface->pitch*y;
WriteBytes( f, sError, pRow, converted_surface->pitch ); WriteBytes( f, sError, pRow, converted_surface->pitch );
/* Pad the row to the pitch. */ /* Pad the row to the pitch. */
uint8_t padding[4] = { 0,0,0,0 }; std::uint8_t padding[4] = { 0,0,0,0 };
WriteBytes( f, sError, padding, iFilePitch-converted_surface->pitch ); WriteBytes( f, sError, padding, iFilePitch-converted_surface->pitch );
} }
+2 -1
View File
@@ -7,6 +7,7 @@
#include "RageFile.h" #include "RageFile.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#undef FAR // fix for VC #undef FAR // fix for VC
/** @brief A helper to get the jpeg lib. */ /** @brief A helper to get the jpeg lib. */
@@ -24,7 +25,7 @@ typedef struct
struct jpeg::jpeg_destination_mgr pub; struct jpeg::jpeg_destination_mgr pub;
RageFile *f; RageFile *f;
uint8_t buffer[OUTPUT_BUFFER_SIZE]; std::uint8_t buffer[OUTPUT_BUFFER_SIZE];
} my_destination_mgr; } my_destination_mgr;
+3 -1
View File
@@ -6,6 +6,8 @@
#include "RageTypes.h" #include "RageTypes.h"
#include "RageTextureID.h" #include "RageTextureID.h"
#include <cstdint>
struct lua_State; struct lua_State;
class RageTexture class RageTexture
{ {
@@ -15,7 +17,7 @@ public:
virtual void Update( float /* fDeltaTime */ ) {} virtual void Update( float /* fDeltaTime */ ) {}
virtual void Reload() {} virtual void Reload() {}
virtual void Invalidate() { } /* only called by RageTextureManager::InvalidateTextures */ virtual void Invalidate() { } /* only called by RageTextureManager::InvalidateTextures */
virtual uintptr_t GetTexHandle() const = 0; // accessed by RageDisplay virtual std::uintptr_t GetTexHandle() const = 0; // accessed by RageDisplay
// movie texture/animated texture stuff // movie texture/animated texture stuff
virtual void SetPosition( float /* fSeconds */ ) {} // seek virtual void SetPosition( float /* fSeconds */ ) {} // seek
+3 -2
View File
@@ -27,6 +27,7 @@
#include "RageDisplay.h" #include "RageDisplay.h"
#include "ActorUtil.h" #include "ActorUtil.h"
#include <cstdint>
#include <map> #include <map>
RageTextureManager* TEXTUREMAN = nullptr; // global and accessible from anywhere in our program RageTextureManager* TEXTUREMAN = nullptr; // global and accessible from anywhere in our program
@@ -132,10 +133,10 @@ public:
m_iImageWidth = m_iImageHeight = 1; m_iImageWidth = m_iImageHeight = 1;
CreateFrameRects(); CreateFrameRects();
} }
uintptr_t GetTexHandle() const { return m_uTexHandle; } std::uintptr_t GetTexHandle() const { return m_uTexHandle; }
private: private:
uintptr_t m_uTexHandle; std::uintptr_t m_uTexHandle;
}; };
// Load and unload textures from disk. // Load and unload textures from disk.
+5 -3
View File
@@ -7,6 +7,8 @@
#include "RageTextureID.h" #include "RageTextureID.h"
#include "RageDisplay.h" // for RenderTargetParam #include "RageDisplay.h" // for RenderTargetParam
#include <cstdint>
class RageTextureRenderTarget: public RageTexture class RageTextureRenderTarget: public RageTexture
{ {
public: public:
@@ -14,7 +16,7 @@ public:
virtual ~RageTextureRenderTarget(); virtual ~RageTextureRenderTarget();
virtual void Invalidate() { m_iTexHandle = 0; /* don't Destroy() */ } virtual void Invalidate() { m_iTexHandle = 0; /* don't Destroy() */ }
virtual void Reload(); virtual void Reload();
virtual uintptr_t GetTexHandle() const { return m_iTexHandle; } virtual std::uintptr_t GetTexHandle() const { return m_iTexHandle; }
void BeginRenderingTo( bool bPreserveTexture = true ); void BeginRenderingTo( bool bPreserveTexture = true );
void FinishRenderingTo(); void FinishRenderingTo();
@@ -26,8 +28,8 @@ private:
void Create(); void Create();
void Destroy(); void Destroy();
uintptr_t m_iTexHandle; std::uintptr_t m_iTexHandle;
uintptr_t m_iPreviousRenderTarget; std::uintptr_t m_iPreviousRenderTarget;
}; };
#endif #endif
+11 -10
View File
@@ -17,6 +17,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include <cerrno> #include <cerrno>
#include <cstdint>
#include <set> #include <set>
#include "arch/Threads/Threads.h" #include "arch/Threads/Threads.h"
@@ -45,7 +46,7 @@ struct ThreadSlot
char m_szThreadFormattedOutput[1024]; char m_szThreadFormattedOutput[1024];
bool m_bUsed; bool m_bUsed;
uint64_t m_iID; std::uint64_t m_iID;
ThreadImpl *m_pImpl; ThreadImpl *m_pImpl;
@@ -183,7 +184,7 @@ static void InitThreads()
} }
static ThreadSlot *GetThreadSlotFromID( uint64_t iID ) static ThreadSlot *GetThreadSlotFromID( std::uint64_t iID )
{ {
InitThreads(); InitThreads();
@@ -283,7 +284,7 @@ const char *RageThread::GetCurrentThreadName()
return GetThreadNameByID( GetCurrentThreadID() ); return GetThreadNameByID( GetCurrentThreadID() );
} }
const char *RageThread::GetThreadNameByID( uint64_t iID ) const char *RageThread::GetThreadNameByID( std::uint64_t iID )
{ {
ThreadSlot *slot = GetThreadSlotFromID( iID ); ThreadSlot *slot = GetThreadSlotFromID( iID );
if( slot == nullptr ) if( slot == nullptr )
@@ -292,7 +293,7 @@ const char *RageThread::GetThreadNameByID( uint64_t iID )
return slot->GetThreadName(); return slot->GetThreadName();
} }
bool RageThread::EnumThreadIDs( int n, uint64_t &iID ) bool RageThread::EnumThreadIDs( int n, std::uint64_t &iID )
{ {
if( n >= MAX_THREADS ) if( n >= MAX_THREADS )
return false; return false;
@@ -336,7 +337,7 @@ void RageThread::Resume() {
void RageThread::HaltAllThreads( bool Kill ) void RageThread::HaltAllThreads( bool Kill )
{ {
const uint64_t ThisThreadID = GetThisThreadId(); const std::uint64_t ThisThreadID = GetThisThreadId();
for( int entry = 0; entry < MAX_THREADS; ++entry ) for( int entry = 0; entry < MAX_THREADS; ++entry )
{ {
if( !g_ThreadSlots[entry].m_bUsed ) if( !g_ThreadSlots[entry].m_bUsed )
@@ -349,7 +350,7 @@ void RageThread::HaltAllThreads( bool Kill )
void RageThread::ResumeAllThreads() void RageThread::ResumeAllThreads()
{ {
const uint64_t ThisThreadID = GetThisThreadId(); const std::uint64_t ThisThreadID = GetThisThreadId();
for( int entry = 0; entry < MAX_THREADS; ++entry ) for( int entry = 0; entry < MAX_THREADS; ++entry )
{ {
if( !g_ThreadSlots[entry].m_bUsed ) if( !g_ThreadSlots[entry].m_bUsed )
@@ -361,11 +362,11 @@ void RageThread::ResumeAllThreads()
} }
} }
uint64_t RageThread::GetCurrentThreadID() std::uint64_t RageThread::GetCurrentThreadID()
{ {
return GetThisThreadId(); return GetThisThreadId();
} }
uint64_t RageThread::GetInvalidThreadID() std::uint64_t RageThread::GetInvalidThreadID()
{ {
return GetInvalidThreadId(); return GetInvalidThreadId();
} }
@@ -582,7 +583,7 @@ RageMutex::~RageMutex()
void RageMutex::Lock() void RageMutex::Lock()
{ {
uint64_t iThisThreadId = GetThisThreadId(); std::uint64_t iThisThreadId = GetThisThreadId();
if( m_LockedBy == iThisThreadId ) if( m_LockedBy == iThisThreadId )
{ {
++m_LockCnt; ++m_LockCnt;
@@ -606,7 +607,7 @@ void RageMutex::Lock()
#if defined(CRASH_HANDLER) #if defined(CRASH_HANDLER)
/* Don't leave GetThreadSlotsLock() locked when we call ForceCrashHandlerDeadlock. */ /* Don't leave GetThreadSlotsLock() locked when we call ForceCrashHandlerDeadlock. */
GetThreadSlotsLock().Lock(); GetThreadSlotsLock().Lock();
uint64_t CrashHandle = OtherSlot? OtherSlot->m_iID:0; std::uint64_t CrashHandle = OtherSlot? OtherSlot->m_iID:0;
GetThreadSlotsLock().Unlock(); GetThreadSlotsLock().Unlock();
/* Pass the crash handle of the other thread, so it can backtrace that thread. */ /* Pass the crash handle of the other thread, so it can backtrace that thread. */
+7 -5
View File
@@ -1,6 +1,8 @@
#ifndef RAGE_THREADS_H #ifndef RAGE_THREADS_H
#define RAGE_THREADS_H #define RAGE_THREADS_H
#include <cstdint>
struct ThreadSlot; struct ThreadSlot;
class RageTimer; class RageTimer;
/** @brief Thread, mutex, semaphore, and event classes. */ /** @brief Thread, mutex, semaphore, and event classes. */
@@ -25,11 +27,11 @@ public:
/* If HaltAllThreads was called (with Kill==false), resume. */ /* If HaltAllThreads was called (with Kill==false), resume. */
static void ResumeAllThreads(); static void ResumeAllThreads();
static uint64_t GetCurrentThreadID(); static std::uint64_t GetCurrentThreadID();
static const char *GetCurrentThreadName(); static const char *GetCurrentThreadName();
static const char *GetThreadNameByID( uint64_t iID ); static const char *GetThreadNameByID( std::uint64_t iID );
static bool EnumThreadIDs( int n, uint64_t &iID ); static bool EnumThreadIDs( int n, std::uint64_t &iID );
int Wait(); int Wait();
bool IsCreated() const { return m_pSlot != nullptr; } bool IsCreated() const { return m_pSlot != nullptr; }
@@ -41,7 +43,7 @@ public:
static bool GetIsShowingDialog() { return s_bIsShowingDialog; } static bool GetIsShowingDialog() { return s_bIsShowingDialog; }
static void SetIsShowingDialog( bool b ) { s_bIsShowingDialog = b; } static void SetIsShowingDialog( bool b ) { s_bIsShowingDialog = b; }
static uint64_t GetInvalidThreadID(); static std::uint64_t GetInvalidThreadID();
private: private:
ThreadSlot *m_pSlot; ThreadSlot *m_pSlot;
@@ -106,7 +108,7 @@ protected:
int m_UniqueID; int m_UniqueID;
uint64_t m_LockedBy; std::uint64_t m_LockedBy;
int m_LockCnt; int m_LockCnt;
void MarkLockedMutex(); void MarkLockedMutex();
+8 -7
View File
@@ -28,13 +28,14 @@
#include "arch/ArchHooks/ArchHooks.h" #include "arch/ArchHooks/ArchHooks.h"
#include <cmath> #include <cmath>
#include <cstdint>
#define TIMESTAMP_RESOLUTION 1000000 #define TIMESTAMP_RESOLUTION 1000000
const RageTimer RageZeroTimer(0,0); const RageTimer RageZeroTimer(0,0);
static uint64_t g_iStartTime = ArchHooks::GetMicrosecondsSinceStart( true ); static std::uint64_t g_iStartTime = ArchHooks::GetMicrosecondsSinceStart( true );
static uint64_t GetTime( bool /* bAccurate */ ) static std::uint64_t GetTime( bool /* bAccurate */ )
{ {
return ArchHooks::GetMicrosecondsSinceStart( true ); return ArchHooks::GetMicrosecondsSinceStart( true );
@@ -43,7 +44,7 @@ static uint64_t GetTime( bool /* bAccurate */ )
#if 0 #if 0
// if !bAccurate, then don't call ArchHooks to find the current time. Just return the // if !bAccurate, then don't call ArchHooks to find the current time. Just return the
// last calculated time. GetMicrosecondsSinceStart is slow on some archs. // last calculated time. GetMicrosecondsSinceStart is slow on some archs.
static uint64_t usecs = 0; static std::uint64_t usecs = 0;
if( bAccurate ) if( bAccurate )
usecs = ArchHooks::GetMicrosecondsSinceStart( true ); usecs = ArchHooks::GetMicrosecondsSinceStart( true );
return usecs; return usecs;
@@ -52,22 +53,22 @@ static uint64_t GetTime( bool /* bAccurate */ )
float RageTimer::GetTimeSinceStart( bool bAccurate ) float RageTimer::GetTimeSinceStart( bool bAccurate )
{ {
uint64_t usecs = GetTime( bAccurate ); std::uint64_t usecs = GetTime( bAccurate );
usecs -= g_iStartTime; usecs -= g_iStartTime;
/* Avoid using doubles for hardware that doesn't support them. /* Avoid using doubles for hardware that doesn't support them.
* This is writing usecs = high*2^32 + low and doing * This is writing usecs = high*2^32 + low and doing
* usecs/10^6 = high * (2^32/10^6) + low/10^6. */ * usecs/10^6 = high * (2^32/10^6) + low/10^6. */
return uint32_t(usecs>>32) * 4294.967296f + uint32_t(usecs)/1000000.f; return std::uint32_t(usecs>>32) * 4294.967296f + std::uint32_t(usecs)/1000000.f;
} }
uint64_t RageTimer::GetUsecsSinceStart() std::uint64_t RageTimer::GetUsecsSinceStart()
{ {
return GetTime(true) - g_iStartTime; return GetTime(true) - g_iStartTime;
} }
void RageTimer::Touch() void RageTimer::Touch()
{ {
uint64_t usecs = GetTime( true ); std::uint64_t usecs = GetTime( true );
this->m_secs = unsigned(usecs / 1000000); this->m_secs = unsigned(usecs / 1000000);
this->m_us = unsigned(usecs % 1000000); this->m_us = unsigned(usecs % 1000000);
+12 -10
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_TIMER_H #ifndef RAGE_TIMER_H
#define RAGE_TIMER_H #define RAGE_TIMER_H
#include <cstdint>
class RageTimer class RageTimer
{ {
public: public:
@@ -23,7 +25,7 @@ public:
/* deprecated: */ /* deprecated: */
static float GetTimeSinceStart( bool bAccurate = true ); // seconds since the program was started static float GetTimeSinceStart( bool bAccurate = true ); // seconds since the program was started
static float GetTimeSinceStartFast() { return GetTimeSinceStart(false); } static float GetTimeSinceStartFast() { return GetTimeSinceStart(false); }
static uint64_t GetUsecsSinceStart(); static std::uint64_t GetUsecsSinceStart();
/* Get a timer representing half of the time ago as this one. */ /* Get a timer representing half of the time ago as this one. */
RageTimer Half() const; RageTimer Half() const;
@@ -53,20 +55,20 @@ private:
extern const RageTimer RageZeroTimer; extern const RageTimer RageZeroTimer;
// For profiling how long some chunk of code takes. -Kyz // For profiling how long some chunk of code takes. -Kyz
#define START_TIME(name) uint64_t name##_start_time= RageTimer::GetUsecsSinceStart(); #define START_TIME(name) std::uint64_t name##_start_time= RageTimer::GetUsecsSinceStart();
#define START_TIME_CALL_COUNT(name) START_TIME(name); ++name##_call_count; #define START_TIME_CALL_COUNT(name) START_TIME(name); ++name##_call_count;
#define END_TIME(name) uint64_t name##_end_time= RageTimer::GetUsecsSinceStart(); LOG->Time(#name " time: %zu to %zu = %zu", name##_start_time, name##_end_time, name##_end_time - name##_start_time); #define END_TIME(name) std::uint64_t name##_end_time= RageTimer::GetUsecsSinceStart(); LOG->Time(#name " time: %zu to %zu = %zu", name##_start_time, name##_end_time, name##_end_time - name##_start_time);
#define END_TIME_ADD_TO(name) uint64_t name##_end_time= RageTimer::GetUsecsSinceStart(); name##_total += name##_end_time - name##_start_time; #define END_TIME_ADD_TO(name) std::uint64_t name##_end_time= RageTimer::GetUsecsSinceStart(); name##_total += name##_end_time - name##_start_time;
#define END_TIME_CALL_COUNT(name) END_TIME_ADD_TO(name); ++name##_end_count; #define END_TIME_CALL_COUNT(name) END_TIME_ADD_TO(name); ++name##_end_count;
#define DECL_TOTAL_TIME(name) extern uint64_t name##_total; #define DECL_TOTAL_TIME(name) extern std::uint64_t name##_total;
#define DEF_TOTAL_TIME(name) uint64_t name##_total= 0; #define DEF_TOTAL_TIME(name) std::uint64_t name##_total= 0;
#define PRINT_TOTAL_TIME(name) LOG->Time(#name " total time: %zu", name##_total); #define PRINT_TOTAL_TIME(name) LOG->Time(#name " total time: %zu", name##_total);
#define DECL_TOT_CALL_PAIR(name) extern uint64_t name##_total; extern uint64_t name##_call_count; #define DECL_TOT_CALL_PAIR(name) extern std::uint64_t name##_total; extern std::uint64_t name##_call_count;
#define DEF_TOT_CALL_PAIR(name) uint64_t name##_total= 0; uint64_t name##_call_count= 0; #define DEF_TOT_CALL_PAIR(name) std::uint64_t name##_total= 0; std::uint64_t name##_call_count= 0;
#define PRINT_TOT_CALL_PAIR(name) LOG->Time(#name " calls: %zu, time: %zu, per: %f", name##_call_count, name##_total, static_cast<float>(name##_total) / name##_call_count); #define PRINT_TOT_CALL_PAIR(name) LOG->Time(#name " calls: %zu, time: %zu, per: %f", name##_call_count, name##_total, static_cast<float>(name##_total) / name##_call_count);
#define DECL_TOT_CALL_END(name) DECL_TOT_CALL_PAIR(name); extern uint64_t name##_end_count; #define DECL_TOT_CALL_END(name) DECL_TOT_CALL_PAIR(name); extern std::uint64_t name##_end_count;
#define DEF_TOT_CALL_END(name) DEF_TOT_CALL_PAIR(name); uint64_t name##_end_count= 0; #define DEF_TOT_CALL_END(name) DEF_TOT_CALL_PAIR(name); std::uint64_t name##_end_count= 0;
#define PRINT_TOT_CALL_END(name) LOG->Time(#name " calls: %zu, time: %zu, early end: %zu, per: %f", name##_call_count, name##_total, name##_end_count, static_cast<float>(name##_total) / (name##_call_count - name##_end_count)); #define PRINT_TOT_CALL_END(name) LOG->Time(#name " calls: %zu, time: %zu, early end: %zu, per: %f", name##_call_count, name##_total, name##_end_count, static_cast<float>(name##_total) / (name##_call_count - name##_end_count));
#endif #endif
+5 -4
View File
@@ -3,10 +3,11 @@
#ifndef RAGETYPES_H #ifndef RAGETYPES_H
#define RAGETYPES_H #define RAGETYPES_H
#include <array>
#include "EnumHelper.h" #include "EnumHelper.h"
#include <array>
#include <cstdint>
enum BlendMode enum BlendMode
{ {
BLEND_NORMAL, BLEND_NORMAL,
@@ -320,7 +321,7 @@ inline unsigned char FTOC(float a)
class RageVColor class RageVColor
{ {
public: public:
uint8_t b,g,r,a; // specific ordering required by Direct3D std::uint8_t b,g,r,a; // specific ordering required by Direct3D
RageVColor(): b(0), g(0), r(0), a(0) { } RageVColor(): b(0), g(0), r(0), a(0) { }
RageVColor(const RageColor &rc): b(0), g(0), r(0), a(0) { *this = rc; } RageVColor(const RageColor &rc): b(0), g(0), r(0), a(0) { *this = rc; }
@@ -390,7 +391,7 @@ struct RageModelVertex // doesn't have color. Relies on material color
RageVector3 p; // position RageVector3 p; // position
RageVector3 n; // normal RageVector3 n; // normal
RageVector2 t; // texture coordinates RageVector2 t; // texture coordinates
int8_t bone; std::int8_t bone;
RageVector2 TextureMatrixScale; // usually 1,1 RageVector2 TextureMatrixScale; // usually 1,1
}; };
+2 -1
View File
@@ -15,6 +15,7 @@
#include <cfloat> #include <cfloat>
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <ctime> #include <ctime>
#include <functional> #include <functional>
#include <map> #include <map>
@@ -194,7 +195,7 @@ bool HexToBinary( const RString &s, unsigned char *stringOut )
break; break;
RString sByte = s.substr( i*2, 2 ); RString sByte = s.substr( i*2, 2 );
uint8_t val = 0; std::uint8_t val = 0;
if( sscanf( sByte, "%hhx", &val ) != 1 ) if( sscanf( sByte, "%hhx", &val ) != 1 )
return false; return false;
stringOut[i] = val; stringOut[i] = val;
+11 -10
View File
@@ -8,10 +8,11 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <map> #include <map>
#include <random> #include <random>
#include <vector>
#include <sstream> #include <sstream>
#include <vector>
class RageFileDriver; class RageFileDriver;
@@ -215,7 +216,7 @@ namespace Endian
#define Swap24 ArchSwap24 #define Swap24 ArchSwap24
#define Swap16 ArchSwap16 #define Swap16 ArchSwap16
#else #else
inline uint32_t Swap32( uint32_t n ) inline std::uint32_t Swap32( std::uint32_t n )
{ {
return (n >> 24) | return (n >> 24) |
((n >> 8) & 0x0000FF00) | ((n >> 8) & 0x0000FF00) |
@@ -223,23 +224,23 @@ inline uint32_t Swap32( uint32_t n )
(n << 24); (n << 24);
} }
inline uint32_t Swap24( uint32_t n ) inline std::uint32_t Swap24( std::uint32_t n )
{ {
return Swap32( n ) >> 8; // xx223344 -> 443322xx -> 00443322 return Swap32( n ) >> 8; // xx223344 -> 443322xx -> 00443322
} }
inline uint16_t Swap16( uint16_t n ) inline std::uint16_t Swap16( std::uint16_t n )
{ {
return (n >> 8) | (n << 8); return (n >> 8) | (n << 8);
} }
#endif #endif
inline uint32_t Swap32LE( uint32_t n ) { return Endian::little ? n : Swap32( n ); } inline std::uint32_t Swap32LE( std::uint32_t n ) { return Endian::little ? n : Swap32( n ); }
inline uint32_t Swap24LE( uint32_t n ) { return Endian::little ? n : Swap24( n ); } inline std::uint32_t Swap24LE( std::uint32_t n ) { return Endian::little ? n : Swap24( n ); }
inline uint16_t Swap16LE( uint16_t n ) { return Endian::little ? n : Swap16( n ); } inline std::uint16_t Swap16LE( std::uint16_t n ) { return Endian::little ? n : Swap16( n ); }
inline uint32_t Swap32BE( uint32_t n ) { return Endian::big ? n : Swap32( n ); } inline std::uint32_t Swap32BE( std::uint32_t n ) { return Endian::big ? n : Swap32( n ); }
inline uint32_t Swap24BE( uint32_t n ) { return Endian::big ? n : Swap24( n ); } inline std::uint32_t Swap24BE( std::uint32_t n ) { return Endian::big ? n : Swap24( n ); }
inline uint16_t Swap16BE( uint16_t n ) { return Endian::big ? n : Swap16( n ); } inline std::uint16_t Swap16BE( std::uint16_t n ) { return Endian::big ? n : Swap16( n ); }
class MersenneTwister : public std::mt19937 class MersenneTwister : public std::mt19937
{ {
+5 -4
View File
@@ -21,6 +21,7 @@
#include "NoteDataWithScoring.h" #include "NoteDataWithScoring.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
static RString PercentScoreWeightName( std::size_t i ) { return "PercentScoreWeight" + ScoreEventToString( (ScoreEvent)i ); } static RString PercentScoreWeightName( std::size_t i ) { return "PercentScoreWeight" + ScoreEventToString( (ScoreEvent)i ); }
static RString GradeWeightName( std::size_t i ) { return "GradeWeight" + ScoreEventToString( (ScoreEvent)i ); } static RString GradeWeightName( std::size_t i ) { return "GradeWeight" + ScoreEventToString( (ScoreEvent)i ); }
@@ -200,7 +201,7 @@ void ScoreKeeperNormal::OnNextSong( int iSongInCourseIndex, const Steps* pSteps,
GAMESTATE->SetProcessedTimingData(nullptr); GAMESTATE->SetProcessedTimingData(nullptr);
} }
static int GetScore(int p, int Z, int64_t S, int n) static int GetScore(int p, int Z, std::int64_t S, int n)
{ {
/* There's a problem with the scoring system described below. Z/S is truncated /* There's a problem with the scoring system described below. Z/S is truncated
* to an int. However, in some cases we can end up with very small base scores. * to an int. However, in some cases we can end up with very small base scores.
@@ -218,7 +219,7 @@ static int GetScore(int p, int Z, int64_t S, int n)
return p * (Z / S) * n; return p * (Z / S) * n;
#elif 1 #elif 1
// This doesn't round down Z/S. // This doesn't round down Z/S.
return int(int64_t(p) * n * Z / S); return int(std::int64_t(p) * n * Z / S);
#else #else
// This also doesn't round down Z/S. Use this if you don't have 64-bit ints. // This also doesn't round down Z/S. Use this if you don't have 64-bit ints.
return int(p * n * (float(Z) / S)); return int(p * n * (float(Z) / S));
@@ -279,8 +280,8 @@ void ScoreKeeperNormal::AddScoreInternal( TapNoteScore score )
m_iTapNotesHit++; m_iTapNotesHit++;
const int64_t N = uint64_t(m_iNumTapsAndHolds); const std::int64_t N = std::uint64_t(m_iNumTapsAndHolds);
const int64_t sum = (N * (N + 1)) / 2; const std::int64_t sum = (N * (N + 1)) / 2;
const int Z = m_iMaxPossiblePoints/10; const int Z = m_iMaxPossiblePoints/10;
// Don't use a multiplier if the player has failed // Don't use a multiplier if the player has failed
+4 -3
View File
@@ -1,6 +1,7 @@
#ifndef ARCH_HOOKS_H #ifndef ARCH_HOOKS_H
#define ARCH_HOOKS_H #define ARCH_HOOKS_H
#include <cstdint>
#include <ctime> #include <ctime>
struct lua_State; struct lua_State;
@@ -86,7 +87,7 @@ public:
* underlying timers may be 32-bit, but implementations should try to avoid * underlying timers may be 32-bit, but implementations should try to avoid
* wrapping if possible. * wrapping if possible.
*/ */
static int64_t GetMicrosecondsSinceStart( bool bAccurate ); static std::int64_t GetMicrosecondsSinceStart( bool bAccurate );
/* /*
* Add file search paths, higher priority first. * Add file search paths, higher priority first.
@@ -130,8 +131,8 @@ public:
private: private:
/* This are helpers for GetMicrosecondsSinceStart on systems with a timer /* This are helpers for GetMicrosecondsSinceStart on systems with a timer
* that may loop or move backwards. */ * that may loop or move backwards. */
static int64_t FixupTimeIfLooped( int64_t usecs ); static std::int64_t FixupTimeIfLooped( std::int64_t usecs );
static int64_t FixupTimeIfBackwards( int64_t usecs ); static std::int64_t FixupTimeIfBackwards( std::int64_t usecs );
static bool g_bQuitting; static bool g_bQuitting;
static bool g_bToggleWindowed; static bool g_bToggleWindowed;
+11 -9
View File
@@ -1,6 +1,8 @@
#include "global.h" #include "global.h"
#include "ArchHooks.h" #include "ArchHooks.h"
#include <cstdint>
/* /*
* This is a helper for GetMicrosecondsSinceStart on systems with a system * This is a helper for GetMicrosecondsSinceStart on systems with a system
* timer that may loop or move backwards. * timer that may loop or move backwards.
@@ -25,15 +27,15 @@
* bAccurate == false. * bAccurate == false.
*/ */
int64_t ArchHooks::FixupTimeIfLooped( int64_t usecs ) std::int64_t ArchHooks::FixupTimeIfLooped( std::int64_t usecs )
{ {
static int64_t last = 0; static std::int64_t last = 0;
static int64_t offset_us = 0; static std::int64_t offset_us = 0;
/* The time has wrapped if the last time was very high and the current time is very low. */ /* The time has wrapped if the last time was very high and the current time is very low. */
const int64_t i32BitMaxMs = uint64_t(1) << 32; const std::int64_t i32BitMaxMs = std::uint64_t(1) << 32;
const int64_t i32BitMaxUs = i32BitMaxMs*1000; const std::int64_t i32BitMaxUs = i32BitMaxMs*1000;
const int64_t one_day = uint64_t(24*60*60)*1000000; const std::int64_t one_day = std::uint64_t(24*60*60)*1000000;
if( last > (i32BitMaxUs-one_day) && usecs < one_day ) if( last > (i32BitMaxUs-one_day) && usecs < one_day )
offset_us += i32BitMaxUs; offset_us += i32BitMaxUs;
@@ -42,10 +44,10 @@ int64_t ArchHooks::FixupTimeIfLooped( int64_t usecs )
return usecs + offset_us; return usecs + offset_us;
} }
int64_t ArchHooks::FixupTimeIfBackwards( int64_t usecs ) std::int64_t ArchHooks::FixupTimeIfBackwards( std::int64_t usecs )
{ {
static int64_t last = 0; static std::int64_t last = 0;
static int64_t offset_us = 0; static std::int64_t offset_us = 0;
if( usecs < last ) if( usecs < last )
{ {
+5 -4
View File
@@ -7,6 +7,7 @@
#include "ProductInfo.h" #include "ProductInfo.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
@@ -160,7 +161,7 @@ void ArchHooks_MacOSX::DumpDebugInfo()
float fRam; float fRam;
char ramPower; char ramPower;
{ {
uint64_t iRam = 0; std::uint64_t iRam = 0;
GET_PARAM( "hw.memsize", iRam ); GET_PARAM( "hw.memsize", iRam );
fRam = float( double(iRam) / 1073741824.0 ); fRam = float( double(iRam) / 1073741824.0 );
@@ -175,7 +176,7 @@ void ArchHooks_MacOSX::DumpDebugInfo()
RString sModel("Unknown"); RString sModel("Unknown");
do { do {
char szModel[128]; char szModel[128];
uint64_t iFreq; std::uint64_t iFreq;
GET_PARAM( "hw.logicalcpu_max", iMaxCPUs ); GET_PARAM( "hw.logicalcpu_max", iMaxCPUs );
GET_PARAM( "hw.logicalcpu", iCPUs ); GET_PARAM( "hw.logicalcpu", iCPUs );
@@ -257,7 +258,7 @@ bool ArchHooks_MacOSX::GoToURL( RString sUrl )
return result == 0; return result == 0;
} }
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{ {
// http://developer.apple.com/qa/qa2004/qa1398.html // http://developer.apple.com/qa/qa2004/qa1398.html
static double factor = 0.0; static double factor = 0.0;
@@ -269,7 +270,7 @@ int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
mach_timebase_info( &timeBase ); mach_timebase_info( &timeBase );
factor = timeBase.numer / ( 1000.0 * timeBase.denom ); factor = timeBase.numer / ( 1000.0 * timeBase.denom );
} }
return int64_t( mach_absolute_time() * factor ); return std::int64_t( mach_absolute_time() * factor );
} }
#include "RageFileManager.h" #include "RageFileManager.h"
+7 -4
View File
@@ -11,6 +11,9 @@
#include "archutils/Common/PthreadHelpers.h" #include "archutils/Common/PthreadHelpers.h"
#include "archutils/Unix/EmergencyShutdown.h" #include "archutils/Unix/EmergencyShutdown.h"
#include "archutils/Unix/AssertionHandler.h" #include "archutils/Unix/AssertionHandler.h"
#include <cstdint>
#if defined(HAVE_UNISTD_H) #if defined(HAVE_UNISTD_H)
#include <unistd.h> #include <unistd.h>
#endif #endif
@@ -149,25 +152,25 @@ clockid_t ArchHooks_Unix::GetClock()
return g_Clock; return g_Clock;
} }
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{ {
OpenGetTime(); OpenGetTime();
timespec ts; timespec ts;
clock_gettime( g_Clock, &ts ); clock_gettime( g_Clock, &ts );
int64_t iRet = int64_t(ts.tv_sec) * 1000000 + int64_t(ts.tv_nsec)/1000; std::int64_t iRet = std::int64_t(ts.tv_sec) * 1000000 + std::int64_t(ts.tv_nsec)/1000;
if( g_Clock != CLOCK_MONOTONIC ) if( g_Clock != CLOCK_MONOTONIC )
iRet = ArchHooks::FixupTimeIfBackwards( iRet ); iRet = ArchHooks::FixupTimeIfBackwards( iRet );
return iRet; return iRet;
} }
#else #else
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{ {
struct timeval tv; struct timeval tv;
gettimeofday( &tv, nullptr ); gettimeofday( &tv, nullptr );
int64_t iRet = int64_t(tv.tv_sec) * 1000000 + int64_t(tv.tv_usec); std::int64_t iRet = std::int64_t(tv.tv_sec) * 1000000 + std::int64_t(tv.tv_usec);
ret = FixupTimeIfBackwards( ret ); ret = FixupTimeIfBackwards( ret );
return iRet; return iRet;
} }
+4 -1
View File
@@ -2,6 +2,9 @@
#define ARCH_HOOKS_UNIX_H #define ARCH_HOOKS_UNIX_H
#include "ArchHooks.h" #include "ArchHooks.h"
#include <cstdint>
class ArchHooks_Unix: public ArchHooks class ArchHooks_Unix: public ArchHooks
{ {
public: public:
@@ -10,7 +13,7 @@ public:
void DumpDebugInfo(); void DumpDebugInfo();
void SetTime( tm newtime ); void SetTime( tm newtime );
int64_t GetMicrosecondsSinceStart(); std::int64_t GetMicrosecondsSinceStart();
void MountInitialFilesystems( const RString &sDirOfExecutable ); void MountInitialFilesystems( const RString &sDirOfExecutable );
float GetDisplayAspectRatio() { return 4.0f/3; } float GetDisplayAspectRatio() { return 4.0f/3; }
+3 -1
View File
@@ -14,11 +14,13 @@
#include "VersionHelpers.h" #include "VersionHelpers.h"
#include <cstdint>
static HANDLE g_hInstanceMutex; static HANDLE g_hInstanceMutex;
static bool g_bIsMultipleInstance = false; static bool g_bIsMultipleInstance = false;
void InvalidParameterHandler( const wchar_t *szExpression, const wchar_t *szFunction, const wchar_t *szFile, void InvalidParameterHandler( const wchar_t *szExpression, const wchar_t *szFunction, const wchar_t *szFile,
unsigned int iLine, uintptr_t pReserved ) unsigned int iLine, std::uintptr_t pReserved )
{ {
FAIL_M( "Invalid parameter" ); //TODO: Make this more informative FAIL_M( "Invalid parameter" ); //TODO: Make this more informative
} }
+4 -2
View File
@@ -6,6 +6,8 @@
#include "ProductInfo.h" #include "ProductInfo.h"
#include "RageFileManager.h" #include "RageFileManager.h"
#include <cstdint>
// for timeGetTime // for timeGetTime
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
@@ -25,12 +27,12 @@ static void InitTimer()
timeBeginPeriod( 1 ); timeBeginPeriod( 1 );
} }
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{ {
if( !g_bTimerInitialized ) if( !g_bTimerInitialized )
InitTimer(); InitTimer();
int64_t ret = timeGetTime() * int64_t(1000); std::int64_t ret = timeGetTime() * std::int64_t(1000);
if( bAccurate ) if( bAccurate )
{ {
ret = FixupTimeIfLooped( ret ); ret = FixupTimeIfLooped( ret );
@@ -13,7 +13,8 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#include <errno.h> #include <cerrno>
#include <cstdint>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <linux/input.h> #include <linux/input.h>
@@ -69,7 +70,7 @@ struct EventDevice
static std::vector<EventDevice *> g_apEventDevices; static std::vector<EventDevice *> g_apEventDevices;
static bool BitIsSet( const uint8_t *pArray, uint32_t iBit ) static bool BitIsSet( const std::uint8_t *pArray, std::uint32_t iBit )
{ {
return !!(pArray[iBit/8] & (1<<(iBit%8))); return !!(pArray[iBit/8] & (1<<(iBit%8)));
} }
@@ -125,7 +126,7 @@ bool EventDevice::Open( RString sFile, InputDevice dev )
DevInfo.version, m_sName.c_str() ); DevInfo.version, m_sName.c_str() );
} }
uint8_t iABSMask[ABS_MAX/8 + 1]; std::uint8_t iABSMask[ABS_MAX/8 + 1];
memset( iABSMask, 0, sizeof(iABSMask) ); memset( iABSMask, 0, sizeof(iABSMask) );
if( ioctl(m_iFD, EVIOCGBIT(EV_ABS, sizeof(iABSMask)), iABSMask) < 0 ) if( ioctl(m_iFD, EVIOCGBIT(EV_ABS, sizeof(iABSMask)), iABSMask) < 0 )
LOG->Warn( "ioctl(EVIOCGBIT(EV_ABS)): %s", strerror(errno) ); LOG->Warn( "ioctl(EVIOCGBIT(EV_ABS)): %s", strerror(errno) );
@@ -142,12 +143,12 @@ bool EventDevice::Open( RString sFile, InputDevice dev )
} }
} }
uint8_t iKeyMask[KEY_MAX/8 + 1]; std::uint8_t iKeyMask[KEY_MAX/8 + 1];
memset( iKeyMask, 0, sizeof(iKeyMask) ); memset( iKeyMask, 0, sizeof(iKeyMask) );
if( ioctl(m_iFD, EVIOCGBIT(EV_KEY, sizeof(iKeyMask)), iKeyMask) < 0 ) if( ioctl(m_iFD, EVIOCGBIT(EV_KEY, sizeof(iKeyMask)), iKeyMask) < 0 )
LOG->Warn( "ioctl(EVIOCGBIT(EV_KEY)): %s", strerror(errno) ); LOG->Warn( "ioctl(EVIOCGBIT(EV_KEY)): %s", strerror(errno) );
uint8_t iEventTypes[EV_MAX/8]; std::uint8_t iEventTypes[EV_MAX/8];
memset( iEventTypes, 0, sizeof(iEventTypes) ); memset( iEventTypes, 0, sizeof(iEventTypes) );
if( ioctl(m_iFD, EVIOCGBIT(0, EV_MAX), iEventTypes) == -1 ) if( ioctl(m_iFD, EVIOCGBIT(0, EV_MAX), iEventTypes) == -1 )
LOG->Warn( "ioctl(EV_MAX): %s", strerror(errno) ); LOG->Warn( "ioctl(EV_MAX): %s", strerror(errno) );
@@ -7,6 +7,7 @@
#include <cerrno> #include <cerrno>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@@ -130,7 +131,7 @@ class InputHandler_SextetStream::Impl
handler->ButtonPressed(di); handler->ButtonPressed(di);
} }
uint8_t stateBuffer[STATE_BUFFER_SIZE]; std::uint8_t stateBuffer[STATE_BUFFER_SIZE];
std::size_t timeout_ms; std::size_t timeout_ms;
RageThread inputThread; RageThread inputThread;
bool continueInputThread; bool continueInputThread;
@@ -190,7 +191,7 @@ class InputHandler_SextetStream::Impl
return 0; return 0;
} }
inline void GetNewState(uint8_t * buffer, RString& line) inline void GetNewState(std::uint8_t * buffer, RString& line)
{ {
std::size_t lineLen = line.length(); std::size_t lineLen = line.length();
std::size_t i, cursor; std::size_t i, cursor;
@@ -226,10 +227,10 @@ class InputHandler_SextetStream::Impl
} }
} }
inline void ReactToChanges(const uint8_t * newStateBuffer) inline void ReactToChanges(const std::uint8_t * newStateBuffer)
{ {
InputDevice id = InputDevice(FIRST_DEVICE); InputDevice id = InputDevice(FIRST_DEVICE);
uint8_t changes[STATE_BUFFER_SIZE]; std::uint8_t changes[STATE_BUFFER_SIZE];
RageTimer now; RageTimer now;
// XOR to find differences // XOR to find differences
@@ -274,7 +275,7 @@ class InputHandler_SextetStream::Impl
if(linereader->ReadLine(line)) { if(linereader->ReadLine(line)) {
LOG->Trace("Got line: '%s'", line.c_str()); LOG->Trace("Got line: '%s'", line.c_str());
if(line.length() > 0) { if(line.length() > 0) {
uint8_t newStateBuffer[STATE_BUFFER_SIZE]; std::uint8_t newStateBuffer[STATE_BUFFER_SIZE];
GetNewState(newStateBuffer, line); GetNewState(newStateBuffer, line);
ReactToChanges(newStateBuffer); ReactToChanges(newStateBuffer);
} }
@@ -4,12 +4,14 @@
#include "RageLog.h" #include "RageLog.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "RageInputDevice.h" #include "RageInputDevice.h"
#include <windows.h>
#include <process.h>
#include "PrefsManager.h" #include "PrefsManager.h"
#include <cstdint>
#include <windows.h>
#include <process.h>
typedef int (*thread_create_t)( typedef int (*thread_create_t)(
int (*proc)(void*), void* ctx, uint32_t stack_sz, unsigned int priority); int (*proc)(void*), void* ctx, std::uint32_t stack_sz, unsigned int priority);
typedef void (*thread_join_t)(int thread_id, int* result); typedef void (*thread_join_t)(int thread_id, int* result);
typedef void (*thread_destroy_t)(int thread_id); typedef void (*thread_destroy_t)(int thread_id);
@@ -24,13 +26,13 @@ static DDRIO_IO_INIT ddrio_io_init;
typedef int (*DDRIO_READ_PAD)(); typedef int (*DDRIO_READ_PAD)();
static DDRIO_READ_PAD ddrio_io_read_pad; static DDRIO_READ_PAD ddrio_io_read_pad;
typedef int (*DDRIO_SETLIGHTS_P3IO)(uint32_t lights); typedef int (*DDRIO_SETLIGHTS_P3IO)(std::uint32_t lights);
static DDRIO_SETLIGHTS_P3IO ddrio_set_lights_p3io; static DDRIO_SETLIGHTS_P3IO ddrio_set_lights_p3io;
typedef int (*DDRIO_SETLIGHTS_EXTIO)(uint32_t lights); typedef int (*DDRIO_SETLIGHTS_EXTIO)(std::uint32_t lights);
static DDRIO_SETLIGHTS_EXTIO ddrio_set_lights_extio; static DDRIO_SETLIGHTS_EXTIO ddrio_set_lights_extio;
typedef int (*DDRIO_SETLIGHTS_HDXSPANEL)(uint32_t lights); typedef int (*DDRIO_SETLIGHTS_HDXSPANEL)(std::uint32_t lights);
static DDRIO_SETLIGHTS_HDXSPANEL ddrio_set_lights_hdxs_panel; static DDRIO_SETLIGHTS_HDXSPANEL ddrio_set_lights_hdxs_panel;
typedef int (*DDRIO_FINI)(); typedef int (*DDRIO_FINI)();
@@ -65,13 +67,13 @@ static unsigned int crt_thread_shim(void* outer_ctx)
int crt_thread_create( int crt_thread_create(
int (*proc)(void*), void* ctx, uint32_t stack_sz, unsigned int priority) int (*proc)(void*), void* ctx, std::uint32_t stack_sz, unsigned int priority)
{ {
LOG->Trace("crt_thread_create"); LOG->Trace("crt_thread_create");
struct shim_ctx sctx; struct shim_ctx sctx;
uintptr_t thread_id; std::uintptr_t thread_id;
sctx.barrier = CreateEvent(NULL, TRUE, FALSE, NULL); sctx.barrier = CreateEvent(NULL, TRUE, FALSE, NULL);
sctx.proc = proc; sctx.proc = proc;
@@ -92,7 +94,7 @@ void crt_thread_destroy(int thread_id)
{ {
LOG->Trace("crt_thread_destroy %d", thread_id); LOG->Trace("crt_thread_destroy %d", thread_id);
CloseHandle((HANDLE)(uintptr_t)thread_id); CloseHandle((HANDLE)(std::uintptr_t)thread_id);
} }
@@ -100,11 +102,11 @@ void crt_thread_join(int thread_id, int* result)
{ {
LOG->Trace("crt_thread_join %d", thread_id); LOG->Trace("crt_thread_join %d", thread_id);
WaitForSingleObject((HANDLE)(uintptr_t)thread_id, INFINITE); WaitForSingleObject((HANDLE)(std::uintptr_t)thread_id, INFINITE);
if (result) if (result)
{ {
GetExitCodeThread((HANDLE)(uintptr_t)thread_id, (DWORD*)result); GetExitCodeThread((HANDLE)(std::uintptr_t)thread_id, (DWORD*)result);
} }
} }
@@ -261,7 +263,7 @@ int InputHandler_Win32_ddrio::InputThread_Start( void *p )
void InputHandler_Win32_ddrio::InputThreadMain() void InputHandler_Win32_ddrio::InputThreadMain()
{ {
uint32_t prevInput = 0, newInput = 0; std::uint32_t prevInput = 0, newInput = 0;
LightsState prevLS = { 0 }; LightsState prevLS = { 0 };
LightsState newLS = { 0 }; LightsState newLS = { 0 };
@@ -290,7 +292,7 @@ void InputHandler_Win32_ddrio::InputThreadMain()
} }
} }
void InputHandler_Win32_ddrio::PushInputState(uint32_t newInput) void InputHandler_Win32_ddrio::PushInputState(std::uint32_t newInput)
{ {
for (int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
{ {
@@ -333,9 +335,9 @@ bool InputHandler_Win32_ddrio::IsLightChange(LightsState prevLS, LightsState new
void InputHandler_Win32_ddrio::PushLightState(LightsState newLS) void InputHandler_Win32_ddrio::PushLightState(LightsState newLS)
{ {
uint32_t p3io = 0; std::uint32_t p3io = 0;
uint32_t hdxs = 0; std::uint32_t hdxs = 0;
uint32_t extio = 0; std::uint32_t extio = 0;
//lighting state has already been verified to have changed in this method, so create the new one from scratch. //lighting state has already been verified to have changed in this method, so create the new one from scratch.
@@ -5,6 +5,8 @@
#include "RageThreads.h" #include "RageThreads.h"
#include "arch/Lights/LightsDriver_Export.h" #include "arch/Lights/LightsDriver_Export.h"
#include <cstdint>
static bool _ddriodll_loaded = false; static bool _ddriodll_loaded = false;
//we want to use a //we want to use a
@@ -77,7 +79,7 @@ private:
static int InputThread_Start( void *p ); static int InputThread_Start( void *p );
void InputThreadMain(); void InputThreadMain();
void PushInputState(uint32_t newInput); void PushInputState(std::uint32_t newInput);
bool IsLightChange(LightsState prevLS, LightsState newLS); bool IsLightChange(LightsState prevLS, LightsState newLS);
void PushLightState(LightsState newLS); void PushLightState(LightsState newLS);
@@ -5,6 +5,8 @@
#include "RageLog.h" #include "RageLog.h"
#include "LightsDriver_LinuxPacDrive.h" #include "LightsDriver_LinuxPacDrive.h"
#include <cstdint>
extern "C" { extern "C" {
#include <usb.h> #include <usb.h>
} }
@@ -77,7 +79,7 @@ void LightsDriver_LinuxPacDrive::Set( const LightsState *ls )
{ {
if ( !DeviceHandle ) return; if ( !DeviceHandle ) return;
uint16_t outb = 0; std::uint16_t outb = 0;
switch (iLightingOrder) { switch (iLightingOrder) {
case 1: case 1:
@@ -243,13 +245,13 @@ void LightsDriver_LinuxPacDrive::OpenDevice()
} }
} }
void LightsDriver_LinuxPacDrive::WriteDevice(uint16_t out) void LightsDriver_LinuxPacDrive::WriteDevice(std::uint16_t out)
{ {
if ( !DeviceHandle ) return; if ( !DeviceHandle ) return;
// output is within the first 16 bits - accept a // output is within the first 16 bits - accept a
// 16-bit arg and cast it, for simplicity's sake. // 16-bit arg and cast it, for simplicity's sake.
uint32_t data = (out << 16); std::uint32_t data = (out << 16);
int expected = sizeof(data); int expected = sizeof(data);
int result = usb_control_msg( DeviceHandle, USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, int result = usb_control_msg( DeviceHandle, USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+3 -1
View File
@@ -3,6 +3,8 @@
#include "LightsDriver.h" #include "LightsDriver.h"
#include <cstdint>
extern "C" { extern "C" {
#include <usb.h> #include <usb.h>
} }
@@ -20,7 +22,7 @@ private:
void FindDevice(); void FindDevice();
void OpenDevice(); void OpenDevice();
void WriteDevice(uint16_t out); void WriteDevice(std::uint16_t out);
void CloseDevice(); void CloseDevice();
struct usb_device *Device; struct usb_device *Device;
+4 -2
View File
@@ -5,11 +5,13 @@
#include "arch/Lights/LightsDriver.h" #include "arch/Lights/LightsDriver.h"
#include <cstdint>
class LightsDriver_Linux_Leds : public LightsDriver class LightsDriver_Linux_Leds : public LightsDriver
{ {
private: private:
static const uint8_t LINUX_LED_STATE_ON = 255; static const std::uint8_t LINUX_LED_STATE_ON = 255;
static const uint8_t LINUX_LED_STATE_OFF = 0; static const std::uint8_t LINUX_LED_STATE_OFF = 0;
static const int LINUX_LED_MAX_DIRECTORY_LENGTH = PATH_MAX; static const int LINUX_LED_MAX_DIRECTORY_LENGTH = PATH_MAX;
const InputScheme *pInput; const InputScheme *pInput;
+12 -10
View File
@@ -1,5 +1,13 @@
#include "global.h" #include "global.h"
#include <stdio.h> #include "LightsDriver_Linux_stac.h"
#include "GameState.h"
#include "Game.h"
#include "RageLog.h"
#include <cerrno>
#include <cstdint>
#include <cstdio>
#if defined(HAVE_UNISTD_H) #if defined(HAVE_UNISTD_H)
#include <unistd.h> #include <unistd.h>
#endif #endif
@@ -10,12 +18,6 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#include <errno.h>
#include "LightsDriver_Linux_stac.h"
#include "GameState.h"
#include "Game.h"
#include "RageLog.h"
#include <libudev.h> #include <libudev.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/hidraw.h> #include <linux/hidraw.h>
@@ -23,7 +25,7 @@
REGISTER_LIGHTS_DRIVER_CLASS2(stac, Linux_stac); REGISTER_LIGHTS_DRIVER_CLASS2(stac, Linux_stac);
StacDevice::StacDevice(uint8_t pn) StacDevice::StacDevice(std::uint8_t pn)
{ {
memset(outputBuffer, 0x00, sizeof(outputBuffer)); memset(outputBuffer, 0x00, sizeof(outputBuffer));
@@ -175,11 +177,11 @@ void StacDevice::Close()
void StacDevice::SetInBuffer(int index, bool lightState) void StacDevice::SetInBuffer(int index, bool lightState)
{ {
//the first byte is the report ID, so we offset it here to adjust. //the first byte is the report ID, so we offset it here to adjust.
uint8_t index_offset = index + 1; std::uint8_t index_offset = index + 1;
//each index in the array represents a single light, //each index in the array represents a single light,
//the light will turn on for any value that isn't 0x00 //the light will turn on for any value that isn't 0x00
uint8_t val = lightState ? 0xFF : 0x00; std::uint8_t val = lightState ? 0xFF : 0x00;
//ensure the index is valid and the light value has changed. //ensure the index is valid and the light value has changed.
if (index_offset < STAC_HIDREPORT_SIZE && outputBuffer[index_offset] != val) if (index_offset < STAC_HIDREPORT_SIZE && outputBuffer[index_offset] != val)
+5 -3
View File
@@ -20,6 +20,8 @@
#include "arch/Lights/LightsDriver.h" #include "arch/Lights/LightsDriver.h"
#include <cstdint>
//static information about the device(s) in question. //static information about the device(s) in question.
#define STAC_VID "04d8" #define STAC_VID "04d8"
#define STAC_PID_P1 "ea4b" #define STAC_PID_P1 "ea4b"
@@ -50,12 +52,12 @@ public:
const char *devicePath; const char *devicePath;
int fd = -1; int fd = -1;
uint8_t playerNumber = 0; std::uint8_t playerNumber = 0;
bool newState = false; bool newState = false;
uint8_t outputBuffer[STAC_HIDREPORT_SIZE]; std::uint8_t outputBuffer[STAC_HIDREPORT_SIZE];
StacDevice(uint8_t pn); StacDevice(std::uint8_t pn);
void FindDevice(); void FindDevice();
void Connect(); void Connect();
@@ -5,6 +5,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "SextetUtils.h" #include "SextetUtils.h"
#include <cstdint>
#include <cstring> #include <cstring>
// Private members/methods are kept out of the header using an opaque pointer `_impl`. // Private members/methods are kept out of the header using an opaque pointer `_impl`.
@@ -18,7 +19,7 @@ namespace
class Impl class Impl
{ {
protected: protected:
uint8_t lastOutput[FULL_SEXTET_COUNT]; std::uint8_t lastOutput[FULL_SEXTET_COUNT];
RageFile * out; RageFile * out;
public: public:
@@ -40,7 +41,7 @@ namespace
void Set(const LightsState * ls) void Set(const LightsState * ls)
{ {
uint8_t buffer[FULL_SEXTET_COUNT]; std::uint8_t buffer[FULL_SEXTET_COUNT];
packLine(buffer, ls); packLine(buffer, ls);
+3 -1
View File
@@ -3,6 +3,8 @@
#include "windows.h" #include "windows.h"
#include "RageUtil.h" #include "RageUtil.h"
#include <cstdint>
REGISTER_LIGHTS_DRIVER_CLASS(Win32Serial); REGISTER_LIGHTS_DRIVER_CLASS(Win32Serial);
static Preference<RString> g_sLightsComPort("LightsComPort", "COM54"); static Preference<RString> g_sLightsComPort("LightsComPort", "COM54");
@@ -68,7 +70,7 @@ LightsDriver_Win32Serial::~LightsDriver_Win32Serial()
void LightsDriver_Win32Serial::Set(const LightsState* ls) void LightsDriver_Win32Serial::Set(const LightsState* ls)
{ {
if (serialPort != INVALID_HANDLE_VALUE) { if (serialPort != INVALID_HANDLE_VALUE) {
uint8_t buffer[FULL_SEXTET_COUNT]; std::uint8_t buffer[FULL_SEXTET_COUNT];
packLine(buffer, ls); packLine(buffer, ls);
+3 -1
View File
@@ -11,10 +11,12 @@
#include "LightsDriver.h" #include "LightsDriver.h"
#include "SextetUtils.h" #include "SextetUtils.h"
#include <cstdint>
class LightsDriver_Win32Serial : public LightsDriver class LightsDriver_Win32Serial : public LightsDriver
{ {
protected: protected:
uint8_t lastOutput[FULL_SEXTET_COUNT]; std::uint8_t lastOutput[FULL_SEXTET_COUNT];
public: public:
LightsDriver_Win32Serial(); LightsDriver_Win32Serial();
virtual ~LightsDriver_Win32Serial(); virtual ~LightsDriver_Win32Serial();
+9 -8
View File
@@ -4,6 +4,7 @@
#include "LightsDriver.h" #include "LightsDriver.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
/* /*
* Utility functions that both `LightsDriver_Win32Serial` and `LightsDriver_SextetStream` * Utility functions that both `LightsDriver_Win32Serial` and `LightsDriver_SextetStream`
@@ -22,7 +23,7 @@ static const std::size_t FULL_SEXTET_COUNT = CABINET_SEXTET_COUNT + (NUM_GameCon
// Encodes the low 6 bits of a byte as a printable, non-space ASCII // Encodes the low 6 bits of a byte as a printable, non-space ASCII
// character (i.e., within the range 0x21-0x7E) such that the low 6 bits of // character (i.e., within the range 0x21-0x7E) such that the low 6 bits of
// the character are the same as the input. // the character are the same as the input.
inline uint8_t printableSextet(uint8_t data) inline std::uint8_t printableSextet(std::uint8_t data)
{ {
// Maps the 6-bit value into the range 0x30-0x6F, wrapped in such a way // Maps the 6-bit value into the range 0x30-0x6F, wrapped in such a way
// that the low 6 bits of the result are the same as the data (so // that the low 6 bits of the result are the same as the data (so
@@ -37,13 +38,13 @@ inline uint8_t printableSextet(uint8_t data)
// the top two bits T of the input like so: // the top two bits T of the input like so:
// H = ((T + 1) mod 4) + 3 // H = ((T + 1) mod 4) + 3
return ((data + (uint8_t)0x10) & (uint8_t)0x3F) + (uint8_t)0x30; return ((data + (std::uint8_t)0x10) & (std::uint8_t)0x3F) + (std::uint8_t)0x30;
} }
// Packs 6 booleans into a 6-bit value // Packs 6 booleans into a 6-bit value
inline uint8_t packPlainSextet(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5) inline std::uint8_t packPlainSextet(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5)
{ {
return (uint8_t)( return (std::uint8_t)(
(b0 ? 0x01 : 0) | (b0 ? 0x01 : 0) |
(b1 ? 0x02 : 0) | (b1 ? 0x02 : 0) |
(b2 ? 0x04 : 0) | (b2 ? 0x04 : 0) |
@@ -53,13 +54,13 @@ inline uint8_t packPlainSextet(bool b0, bool b1, bool b2, bool b3, bool b4, bool
} }
// Packs 6 booleans into a printable sextet // Packs 6 booleans into a printable sextet
inline uint8_t packPrintableSextet(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5) inline std::uint8_t packPrintableSextet(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5)
{ {
return printableSextet(packPlainSextet(b0, b1, b2, b3, b4, b5)); return printableSextet(packPlainSextet(b0, b1, b2, b3, b4, b5));
} }
// Packs the cabinet lights into a printable sextet and adds it to a buffer // Packs the cabinet lights into a printable sextet and adds it to a buffer
inline std::size_t packCabinetLights(const LightsState* ls, uint8_t* buffer) inline std::size_t packCabinetLights(const LightsState* ls, std::uint8_t* buffer)
{ {
buffer[0] = packPrintableSextet( buffer[0] = packPrintableSextet(
ls->m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT], ls->m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT],
@@ -73,7 +74,7 @@ inline std::size_t packCabinetLights(const LightsState* ls, uint8_t* buffer)
// Packs the button lights for a controller into 6 printable sextets and // Packs the button lights for a controller into 6 printable sextets and
// adds them to a buffer // adds them to a buffer
inline std::size_t packControllerLights(const LightsState* ls, GameController gc, uint8_t* buffer) inline std::size_t packControllerLights(const LightsState* ls, GameController gc, std::uint8_t* buffer)
{ {
// Menu buttons // Menu buttons
buffer[0] = packPrintableSextet( buffer[0] = packPrintableSextet(
@@ -126,7 +127,7 @@ inline std::size_t packControllerLights(const LightsState* ls, GameController gc
return CONTROLLER_SEXTET_COUNT; return CONTROLLER_SEXTET_COUNT;
} }
inline std::size_t packLine(uint8_t* buffer, const LightsState* ls) inline std::size_t packLine(std::uint8_t* buffer, const LightsState* ls)
{ {
std::size_t index = 0; std::size_t index = 0;
+3 -1
View File
@@ -5,6 +5,8 @@
#include "RageSurface_Load.h" #include "RageSurface_Load.h"
#include "LoadingWindow_Gtk.h" #include "LoadingWindow_Gtk.h"
#include <cstdint>
#include <gtk/gtk.h> #include <gtk/gtk.h>
static GtkWidget *label; static GtkWidget *label;
@@ -75,7 +77,7 @@ void LoadingWindow_Gtk::SetText( RString s )
static void DeletePixels( guchar *pixels, gpointer data ) static void DeletePixels( guchar *pixels, gpointer data )
{ {
delete[] (uint8_t *)pixels; delete[] (std::uint8_t *)pixels;
} }
static GdkPixbuf *MakePixbuf( const RageSurface *pSrc ) static GdkPixbuf *MakePixbuf( const RageSurface *pSrc )
@@ -3,10 +3,13 @@
#include "LowLevelWindow.h" #include "LowLevelWindow.h"
#include "RageDisplay.h" #include "RageDisplay.h"
#include <cstdint>
#include <objc/objc.h> #include <objc/objc.h>
typedef const struct __CFDictionary *CFDictionaryRef; typedef const struct __CFDictionary *CFDictionaryRef;
typedef uint32_t CGDirectDisplayID; typedef std::uint32_t CGDirectDisplayID;
class LowLevelWindow_MacOSX : public LowLevelWindow class LowLevelWindow_MacOSX : public LowLevelWindow
{ {
@@ -7,6 +7,7 @@
#import "arch/ArchHooks/ArchHooks.h" #import "arch/ArchHooks/ArchHooks.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h> #import <OpenGL/OpenGL.h>
@@ -189,7 +190,7 @@ public:
RenderTarget_MacOSX( id shareContext ); RenderTarget_MacOSX( id shareContext );
~RenderTarget_MacOSX(); ~RenderTarget_MacOSX();
void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ); void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut );
uintptr_t GetTexture() const { return static_cast<uintptr_t>(m_iTexHandle); } std::uintptr_t GetTexture() const { return static_cast<std::uintptr_t>(m_iTexHandle); }
void StartRenderingTo(); void StartRenderingTo();
void FinishRenderingTo(); void FinishRenderingTo();
@@ -325,11 +326,11 @@ void *LowLevelWindow_MacOSX::GetProcAddress( RString s )
// http://developer.apple.com/qa/qa2001/qa1188.html // http://developer.apple.com/qa/qa2001/qa1188.html
// Both functions mentioned in there are deprecated in 10.4. // Both functions mentioned in there are deprecated in 10.4.
const RString& symbolName( '_' + s ); const RString& symbolName( '_' + s );
const uint32_t count = _dyld_image_count(); const std::uint32_t count = _dyld_image_count();
NSSymbol symbol = nil; NSSymbol symbol = nil;
const uint32_t options = NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR; const std::uint32_t options = NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR;
for( uint32_t i = 0; i < count && !symbol; ++i ) for( std::uint32_t i = 0; i < count && !symbol; ++i )
symbol = NSLookupSymbolInImage( _dyld_get_image_header(i), symbolName, options ); symbol = NSLookupSymbolInImage( _dyld_get_image_header(i), symbolName, options );
return symbol ? NSAddressOfSymbol( symbol ) : nil; return symbol ? NSAddressOfSymbol( symbol ) : nil;
} }
@@ -11,6 +11,8 @@
#include "RageDisplay_OGL_Helpers.h" #include "RageDisplay_OGL_Helpers.h"
#include "RageDisplay_OGL.h" #include "RageDisplay_OGL.h"
#include <cstdint>
#include <GL/glew.h> #include <GL/glew.h>
static PIXELFORMATDESCRIPTOR g_CurrentPixelFormat; static PIXELFORMATDESCRIPTOR g_CurrentPixelFormat;
@@ -323,7 +325,7 @@ public:
virtual ~RenderTarget_Win32(); virtual ~RenderTarget_Win32();
void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ); void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut );
uintptr_t GetTexture() const { return static_cast<uintptr_t>(m_texHandle); } std::uintptr_t GetTexture() const { return static_cast<std::uintptr_t>(m_texHandle); }
void StartRenderingTo(); void StartRenderingTo();
void FinishRenderingTo(); void FinishRenderingTo();
+11 -9
View File
@@ -13,7 +13,9 @@ using namespace RageDisplay_Legacy_Helpers;
using namespace X11Helper; using namespace X11Helper;
#include <cmath> #include <cmath>
#include <cstdint>
#include <set> #include <set>
#include <GL/glxew.h> #include <GL/glxew.h>
#define GLX_GLXEXT_PROTOTYPES #define GLX_GLXEXT_PROTOTYPES
#include <GL/glx.h> // All sorts of stuff... #include <GL/glx.h> // All sorts of stuff...
@@ -315,7 +317,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
// If an output name has been specified, search for it // If an output name has been specified, search for it
RROutput targetOut = None; RROutput targetOut = None;
if (p.sDisplayId.length() > 0) { if (p.sDisplayId.length() > 0) {
for (unsigned int i = 0; i < static_cast<uint32_t>(scrRes->noutput) && targetOut == None; ++i) { for (unsigned int i = 0; i < static_cast<std::uint32_t>(scrRes->noutput) && targetOut == None; ++i) {
XRROutputInfo *outInfo = XRRGetOutputInfo(Dpy, scrRes, scrRes->outputs[i]); XRROutputInfo *outInfo = XRRGetOutputInfo(Dpy, scrRes, scrRes->outputs[i]);
std::string outName = std::string(outInfo->name, static_cast<unsigned int> (outInfo->nameLen)); std::string outName = std::string(outInfo->name, static_cast<unsigned int> (outInfo->nameLen));
if (p.sDisplayId == outName) { if (p.sDisplayId == outName) {
@@ -335,7 +337,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
// (it is possible the connection state could be unknown), we'll at least // (it is possible the connection state could be unknown), we'll at least
// look for an output with a CRTC driving it // look for an output with a CRTC driving it
RROutput connected = None, hasCrtc = None; RROutput connected = None, hasCrtc = None;
for (unsigned int i = 0; i < static_cast<uint32_t>(scrRes->noutput); ++i) { for (unsigned int i = 0; i < static_cast<std::uint32_t>(scrRes->noutput); ++i) {
XRROutputInfo *outInfo = XRRGetOutputInfo(Dpy, scrRes, scrRes->outputs[i]); XRROutputInfo *outInfo = XRRGetOutputInfo(Dpy, scrRes, scrRes->outputs[i]);
if (outInfo->connection == RR_Connected) { // Check for CONNECTED state: Connected == 0 if (outInfo->connection == RR_Connected) { // Check for CONNECTED state: Connected == 0
connected = scrRes->outputs[i]; connected = scrRes->outputs[i];
@@ -362,7 +364,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
RRCrtc tgtOutCrtc = tgtOutInfo->crtc; RRCrtc tgtOutCrtc = tgtOutInfo->crtc;
if (tgtOutCrtc == None) if (tgtOutCrtc == None)
{ {
for (unsigned int i = 0; i < static_cast<uint32_t>(tgtOutInfo->ncrtc); ++i) for (unsigned int i = 0; i < static_cast<std::uint32_t>(tgtOutInfo->ncrtc); ++i)
{ {
XRRCrtcInfo *crtcInfo = XRRGetCrtcInfo( Dpy, scrRes, tgtOutInfo->crtcs[i] ); XRRCrtcInfo *crtcInfo = XRRGetCrtcInfo( Dpy, scrRes, tgtOutInfo->crtcs[i] );
if (crtcInfo->mode == None) if (crtcInfo->mode == None)
@@ -390,7 +392,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
const XRRModeInfo &thisMI = scrRes->modes[i]; const XRRModeInfo &thisMI = scrRes->modes[i];
const unsigned int modeWidth = bPortrait ? thisMI.height : thisMI.width; const unsigned int modeWidth = bPortrait ? thisMI.height : thisMI.width;
const unsigned int modeHeight = bPortrait ? thisMI.width : thisMI.height; const unsigned int modeHeight = bPortrait ? thisMI.width : thisMI.height;
if (p.width >= 0 && p.height >= 0 && modeWidth == static_cast<uint32_t>(p.width) && modeHeight == static_cast<uint32_t>(p.height)) { if (p.width >= 0 && p.height >= 0 && modeWidth == static_cast<std::uint32_t>(p.width) && modeHeight == static_cast<std::uint32_t>(p.height)) {
float fTempRefresh = calcRandRRefresh(thisMI.dotClock, thisMI.hTotal, thisMI.vTotal); float fTempRefresh = calcRandRRefresh(thisMI.dotClock, thisMI.hTotal, thisMI.vTotal);
float fTempDiff = std::abs(p.rate - fTempRefresh); float fTempDiff = std::abs(p.rate - fTempRefresh);
if ((p.rate != REFRESH_DEFAULT && fTempDiff < fRefreshDiff) || if ((p.rate != REFRESH_DEFAULT && fTempDiff < fRefreshDiff) ||
@@ -660,11 +662,11 @@ void LowLevelWindow_X11::GetDisplaySpecs(DisplaySpecs &out) const {
int nsizes = 0; int nsizes = 0;
XRRScreenSize *screenSizes = XRRSizes( Dpy, screenNum, &nsizes); XRRScreenSize *screenSizes = XRRSizes( Dpy, screenNum, &nsizes);
DisplayMode screenCurMode{}; DisplayMode screenCurMode{};
for (unsigned int szIdx = 0, mode_idx = 0; nsizes >= 0 && szIdx < static_cast<uint32_t>(nsizes); ++szIdx) { for (unsigned int szIdx = 0, mode_idx = 0; nsizes >= 0 && szIdx < static_cast<std::uint32_t>(nsizes); ++szIdx) {
XRRScreenSize &size = screenSizes[szIdx]; XRRScreenSize &size = screenSizes[szIdx];
int nrates = 0; int nrates = 0;
short *rates = XRRRates(Dpy, screenNum, szIdx, &nrates); short *rates = XRRRates(Dpy, screenNum, szIdx, &nrates);
for (unsigned int rIdx = 0; nrates >=0 && rIdx < static_cast<uint32_t>(nrates); ++rIdx, ++mode_idx) { for (unsigned int rIdx = 0; nrates >=0 && rIdx < static_cast<std::uint32_t>(nrates); ++rIdx, ++mode_idx) {
DisplayMode m = {static_cast<unsigned int> (size.width), static_cast<unsigned int> (size.height), static_cast<double> (rates[rIdx])}; DisplayMode m = {static_cast<unsigned int> (size.width), static_cast<unsigned int> (size.height), static_cast<double> (rates[rIdx])};
screenModes.insert(m); screenModes.insert(m);
if (rates[rIdx] == curRate && szIdx == curSizeId) { if (rates[rIdx] == curRate && szIdx == curSizeId) {
@@ -694,7 +696,7 @@ void LowLevelWindow_X11::GetDisplaySpecs(DisplaySpecs &out) const {
} }
// Now, for each output, build a corresponding DisplaySpec // Now, for each output, build a corresponding DisplaySpec
for (unsigned int outIdx = 0; outIdx < static_cast<uint32_t>(scrRes->noutput); ++outIdx) for (unsigned int outIdx = 0; outIdx < static_cast<std::uint32_t>(scrRes->noutput); ++outIdx)
{ {
XRROutputInfo *outInfo = XRRGetOutputInfo( Dpy, scrRes, scrRes->outputs[outIdx] ); XRROutputInfo *outInfo = XRRGetOutputInfo( Dpy, scrRes, scrRes->outputs[outIdx] );
if (outInfo->nmode > 0) if (outInfo->nmode > 0)
@@ -717,7 +719,7 @@ void LowLevelWindow_X11::GetDisplaySpecs(DisplaySpecs &out) const {
std::set<DisplayMode> outputSupported; std::set<DisplayMode> outputSupported;
DisplayMode outputCurMode{}; DisplayMode outputCurMode{};
RectI outBounds; RectI outBounds;
for (unsigned int modeIdx = 0; modeIdx < static_cast<uint32_t>(outInfo->nmode); ++modeIdx) for (unsigned int modeIdx = 0; modeIdx < static_cast<std::uint32_t>(outInfo->nmode); ++modeIdx)
{ {
DisplayMode mode = outputModes[outInfo->modes[modeIdx]]; DisplayMode mode = outputModes[outInfo->modes[modeIdx]];
unsigned int modeWidth = bPortrait ? mode.height : mode.width; unsigned int modeWidth = bPortrait ? mode.height : mode.width;
@@ -758,7 +760,7 @@ public:
~RenderTarget_X11(); ~RenderTarget_X11();
void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut ); void Create( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut );
uintptr_t GetTexture() const { return static_cast<uintptr_t>(m_iTexHandle); } std::uintptr_t GetTexture() const { return static_cast<std::uintptr_t>(m_iTexHandle); }
void StartRenderingTo(); void StartRenderingTo();
void FinishRenderingTo(); void FinishRenderingTo();
@@ -4,6 +4,7 @@
#include "RageLog.h" #include "RageLog.h"
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <IOKit/IOKitLib.h> #include <IOKit/IOKitLib.h>
@@ -204,7 +205,7 @@ void MemoryCardDriverThreaded_MacOSX::GetUSBStorageDevices( std::vector<UsbStora
LOG->Trace( "Found memory card at path: %s.", fs[i].f_mntonname ); LOG->Trace( "Found memory card at path: %s.", fs[i].f_mntonname );
usbd.SetOsMountDir( fs[i].f_mntonname ); usbd.SetOsMountDir( fs[i].f_mntonname );
usbd.iVolumeSizeMB = int( (uint64_t(fs[i].f_blocks) * fs[i].f_bsize) >> 20 ); usbd.iVolumeSizeMB = int( (std::uint64_t(fs[i].f_blocks) * fs[i].f_bsize) >> 20 );
// Now we can get some more information from the registry tree. // Now we can get some more information from the registry tree.
usbd.iBus = GetIntProperty( device, CFSTR("USB Address") ); usbd.iBus = GetIntProperty( device, CFSTR("USB Address") );
+3 -1
View File
@@ -24,6 +24,8 @@
#include "arch/Dialog/Dialog.h" #include "arch/Dialog/Dialog.h"
#include "archutils/Win32/DirectXHelpers.h" #include "archutils/Win32/DirectXHelpers.h"
#include <cstdint>
#include <vfw.h> /* for GetVideoCodecDebugInfo */ #include <vfw.h> /* for GetVideoCodecDebugInfo */
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma comment(lib, "vfw32.lib") #pragma comment(lib, "vfw32.lib")
@@ -235,7 +237,7 @@ void MovieTexture_DShow::CheckFrame()
0x00FF00, 0x00FF00,
0x0000FF, 0x0000FF,
0x000000, 0x000000,
(uint8_t *) buffer, m_iSourceWidth*3 ); (std::uint8_t *) buffer, m_iSourceWidth*3 );
/* /*
* Optimization notes: * Optimization notes:

Some files were not shown because too many files have changed in this diff Show More