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
+12 -10
View File
@@ -10,9 +10,11 @@
#include "RageDisplay.h"
#include "ScreenDimensions.h"
#include <cstdint>
/* 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
* children. The name "ActorFrame" is widely used in Lua, so we'll have
* that string instead create an ActorFrameAutoDeleteChildren object.
*/
@@ -146,7 +148,7 @@ void ActorFrame::AddChild( Actor *pActor )
#endif
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 );
pActor->SetParent( this );
@@ -226,7 +228,7 @@ void ActorFrame::DrawPrimitives()
m_bClearZBuffer = false;
}
// Don't set Actor-defined render states because we won't be drawing
// Don't set Actor-defined render states because we won't be drawing
// any geometry that belongs to this object.
// Actor::DrawPrimitives();
@@ -577,7 +579,7 @@ void ActorFrame::HandleMessage( const Message &msg )
if( msg.IsBroadcast() )
return;
for( unsigned i=0; i<m_SubActors.size(); i++ )
for( unsigned i=0; i<m_SubActors.size(); i++ )
{
Actor* pActor = m_SubActors[i];
pActor->HandleMessage( msg );
@@ -593,7 +595,7 @@ void ActorFrame::SetDrawByZPosition( bool b )
// lua start
#include "LuaBinding.h"
/** @brief Allow Lua to have access to the ActorFrame. */
/** @brief Allow Lua to have access to the ActorFrame. */
class LunaActorFrame : public Luna<ActorFrame>
{
public:
@@ -659,7 +661,7 @@ public:
p->SetDrawFunction( ref );
COMMON_RETURN_SELF;
}
luaL_checktype( L, 1, LUA_TFUNCTION );
LuaReference ref;
@@ -683,7 +685,7 @@ public:
p->SetUpdateFunction( ref );
COMMON_RETURN_SELF;
}
luaL_checktype( L, 1, LUA_TFUNCTION );
LuaReference ref;
@@ -769,7 +771,7 @@ public:
ADD_METHOD( AddChildFromPath );
ADD_METHOD( RemoveChild );
ADD_METHOD( RemoveAllChildren );
}
};
@@ -779,7 +781,7 @@ LUA_REGISTER_DERIVED_CLASS( ActorFrame, Actor )
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -789,7 +791,7 @@ LUA_REGISTER_DERIVED_CLASS( ActorFrame, Actor )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+7 -5
View File
@@ -5,6 +5,8 @@
#include "RageLog.h"
#include "ActorUtil.h"
#include <cstdint>
REGISTER_ACTOR_CLASS_WITH_NAME( ActorFrameTextureAutoDeleteChildren, ActorFrameTexture );
ActorFrameTexture *ActorFrameTexture::Copy() const { return new ActorFrameTexture(*this); }
@@ -14,7 +16,7 @@ ActorFrameTexture::ActorFrameTexture()
m_bAlphaBuffer = false;
m_bFloat = false;
m_bPreserveTexture = false;
static uint64_t i = 0;
static std::uint64_t i = 0;
++i;
m_sTextureName = ssprintf( ConvertI64FormatString("ActorFrameTexture %lli"), i );
@@ -84,7 +86,7 @@ void ActorFrameTexture::DrawPrimitives()
// lua start
#include "LuaBinding.h"
/** @brief Allow Lua to have access to the ActorFrameTexture. */
/** @brief Allow Lua to have access to the ActorFrameTexture. */
class LunaActorFrameTexture : public Luna<ActorFrameTexture>
{
public:
@@ -107,7 +109,7 @@ public:
}
return 1;
}
LunaActorFrameTexture()
{
ADD_METHOD( Create );
@@ -126,7 +128,7 @@ LUA_REGISTER_DERIVED_CLASS( ActorFrameTexture, ActorFrame )
/*
* (c) 2006 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -136,7 +138,7 @@ LUA_REGISTER_DERIVED_CLASS( ActorFrameTexture, ActorFrame )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+5 -4
View File
@@ -14,6 +14,7 @@
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <numeric>
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++ )
{
// 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.
// So each channel of the RageVColor needs to be converted to a float,
// multiplied by the channel from the RageColor, then the result
// converted to uint8_t. If implicit conversion is allowed to happen,
// sometimes the compiler decides to turn the RageColor into a uint8_t,
// converted to std::uint8_t. If implicit conversion is allowed to happen,
// 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
// conversions. -Kyz
#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
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);
+2 -1
View File
@@ -1,6 +1,7 @@
#include "global.h"
#include <cstddef>
#include <cstdint>
#include <cstdio>
#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 {
lutime_t atime,mtime,ctime;
+5 -3
View File
@@ -16,6 +16,8 @@
#include "LuaReference.h"
#include "LuaManager.h"
#include <cstdint>
CryptManager* CRYPTMAN = nullptr; // global and accessible from anywhere in our program
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 )
{
uint8_t *pBuf = (uint8_t *) pData;
std::uint8_t *pBuf = (std::uint8_t *) pData;
while( iBytes-- )
*pBuf++ = (uint8_t) RandomInt( 256 );
*pBuf++ = (std::uint8_t) RandomInt( 256 );
}
#else
@@ -463,7 +465,7 @@ RString CryptManager::GetPublicKeyFileName()
/* Generate a version 4 random UUID. */
RString CryptManager::GenerateRandomUUID()
{
uint32_t buf[4];
std::uint32_t buf[4];
CryptManager::GetRandomBytes( buf, sizeof(buf) );
buf[1] &= 0xFFFF0FFF;
+3 -2
View File
@@ -21,6 +21,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
static Preference<bool> g_bPalettedImageCache( "PalettedImageCache", false );
@@ -188,8 +189,8 @@ void ImageCache::ReadFromDisk()
struct ImageTexture: public RageTexture
{
uintptr_t m_uTexHandle;
uintptr_t GetTexHandle() const { return m_uTexHandle; }; // accessed by RageDisplay
std::uintptr_t m_uTexHandle;
std::uintptr_t GetTexHandle() const { return m_uTexHandle; }; // accessed by RageDisplay
/* This is a reference to a pointer in g_ImagePathToImage. */
RageSurface *&m_pImage;
int m_iWidth, m_iHeight;
+3 -2
View File
@@ -17,6 +17,7 @@
#include <cmath>
#include <csetjmp>
#include <cstddef>
#include <cstdint>
#include <map>
#include <sstream> // conversion for lua functions.
@@ -420,8 +421,8 @@ LuaThreadVariable::LuaThreadVariable( lua_State *L )
RString LuaThreadVariable::GetCurrentThreadIDString()
{
uint64_t iID = RageThread::GetCurrentThreadID();
return ssprintf( "%08x%08x", uint32_t(iID >> 32), uint32_t(iID) );
std::uint64_t iID = RageThread::GetCurrentThreadID();
return ssprintf( "%08x%08x", std::uint32_t(iID >> 32), std::uint32_t(iID) );
}
bool LuaThreadVariable::PushThreadTable( lua_State *L, bool bCreate )
+3 -2
View File
@@ -14,6 +14,7 @@
#include "PrefsManager.h"
#include <cstddef>
#include <cstdint>
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;
RageVector3 &pos = Vertices[j].p;
int8_t bone = Vertices[j].bone;
std::int8_t bone = Vertices[j].bone;
if( bone != -1 )
{
pos[0] -= m_vpBones[bone].m_Absolute.m[3][0];
@@ -698,7 +699,7 @@ void Model::UpdateTempGeometry()
RageVector3 &tempNormal = tempVertices[j].n;
const RageVector3 &originalPos = origVertices[j].p;
const RageVector3 &originalNormal = origVertices[j].n;
int8_t bone = origVertices[j].bone;
std::int8_t bone = origVertices[j].bone;
if( bone == -1 )
{
+6 -4
View File
@@ -5,9 +5,11 @@
#include "RageTypes.h"
#include <cstdint>
struct msTriangle
{
uint16_t nVertexIndices[3];
std::uint16_t nVertexIndices[3];
};
@@ -18,7 +20,7 @@ struct msMesh
std::vector<RageModelVertex> Vertices;
// OPTIMIZATION: If all verts in a mesh are transformed by the same bone,
// OPTIMIZATION: If all verts in a mesh are transformed by the same bone,
// then send the transform to the graphics card for the whole mesh instead
// of transforming each vertex on the CPU;
char m_iBoneIndex; // -1 = no bone
@@ -146,7 +148,7 @@ struct myBone_t
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -156,7 +158,7 @@ struct myBone_t
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+2 -1
View File
@@ -12,6 +12,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <utility>
// TODO: Remove these constants that aren't time signature-aware
@@ -144,7 +145,7 @@ static void LoadFromSMNoteDataStringWithPlayer( NoteData& out, const RString &sS
int 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 );
}
else
+2 -1
View File
@@ -20,6 +20,7 @@
#include "Style.h"
#include <cmath>
#include <cstdint>
static Preference<bool> g_bRenderEarlierNotesOnTop( "RenderEarlierNotesOnTop", false );
@@ -1358,7 +1359,7 @@ void NoteDisplay::DrawActor(const TapNote& tn, Actor* pActor, NotePart part,
break;
case NoteColorType_ProgressAlternate:
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.
//doing it this way ensures that fScaledBeat is never negative so std::fmod works.
fScaledBeat += cache->m_iNoteColorCount[part] - 1;
+2 -1
View File
@@ -28,6 +28,7 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
const RString STATS_XML = "Stats.xml";
const RString STATS_XML_GZ = "Stats.xml.gz";
@@ -1254,7 +1255,7 @@ ProfileLoadResult Profile::LoadStatsFromDir(RString dir, bool require_signature)
if(compressed)
{
RString sError;
uint32_t iCRC32;
std::uint32_t iCRC32;
RageFileObjInflate *pInflate = GunzipFile(pFile.release(), sError, &iCRC32);
if(pInflate == nullptr)
{
+4 -2
View File
@@ -5,6 +5,8 @@
#include "RageTexture.h"
#include <cstddef>
class RageBitmapTexture : public RageTexture
{
public:
@@ -13,12 +15,12 @@ public:
/* only called by RageTextureManager::InvalidateTextures */
virtual void Invalidate() { m_uTexHandle = 0; /* don't Destroy() */}
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:
void Create(); // called by constructor and Reload
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
+2 -1
View File
@@ -17,6 +17,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
// Statistics stuff
RageTimer g_LastCheckTimer;
@@ -653,7 +654,7 @@ RageSurface *RageDisplay::CreateSurfaceFromPixfmt( RagePixelFormat pixfmt,
RageSurface *surf = CreateSurfaceFrom(
width, height, tpf->bpp,
tpf->masks[0], tpf->masks[1], tpf->masks[2], tpf->masks[3],
(uint8_t *) pixels, pitch );
(std::uint8_t *) pixels, pitch );
return surf;
}
+11 -10
View File
@@ -7,6 +7,7 @@
#include "ModelTypes.h"
#include <cstddef>
#include <cstdint>
#include <set>
class DisplaySpec;
@@ -200,7 +201,7 @@ struct RageTextureLock
/* Given a surface with a format and no pixel data, lock the texture into the
* 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
* may be omitted. */
@@ -256,23 +257,23 @@ public:
/* return 0 if failed or internal texture resource handle
* (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
RageSurface* img, // must be in pixfmt
bool bGenerateMipMaps
) = 0;
virtual void UpdateTexture(
uintptr_t iTexHandle,
std::uintptr_t iTexHandle,
RageSurface* img,
int xoffset, int yoffset, int width, int height
) = 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.
* Delete the object normally. */
virtual RageTextureLock *CreateTextureLock() { return nullptr; }
virtual void ClearAllTextures() = 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 SetTextureWrapping( TextureUnit, bool ) = 0;
virtual int GetMaxTextureSize() const = 0;
@@ -288,9 +289,9 @@ public:
* DeleteTexture. (UpdateTexture is not permitted.) Returns 0 if render-to-
* 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
* 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 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 IsZWriteEnabled() const = 0;
@@ -359,9 +360,9 @@ public:
};
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 *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:
virtual void DrawQuadsInternal( const RageSpriteVertex v[], int iNumVerts ) = 0;
+17 -16
View File
@@ -26,6 +26,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <list>
// Globals
@@ -45,13 +46,13 @@ const D3DFORMAT g_DefaultAdapterFormat = D3DFMT_X8R8G8B8;
/* 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
* 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;
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.
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( 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());
// 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 )
continue;
@@ -795,7 +796,7 @@ public:
for( std::size_t j=0; j<Triangles.size(); j++ )
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
@@ -851,11 +852,11 @@ void RageDisplay_D3D::DrawQuadsInternal( const RageSpriteVertex v[], int iNumVer
int iNumIndices = iNumTriangles*3;
// 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 uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices));
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+1] = i*4+1;
@@ -887,11 +888,11 @@ void RageDisplay_D3D::DrawQuadStripInternal( const RageSpriteVertex v[], int iNu
int iNumIndices = iNumTriangles*3;
// 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 uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices));
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+1] = i*2+1;
@@ -922,11 +923,11 @@ void RageDisplay_D3D::DrawSymmetricQuadStripInternal( const RageSpriteVertex v[]
int iNumIndices = iNumTriangles*3;
// 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 uNewSize = std::max(uOldSize, static_cast<std::size_t>(iNumIndices));
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 }
vIndices[i*12+0] = i*3+1;
@@ -1049,7 +1050,7 @@ int RageDisplay_D3D::GetNumTextureUnits()
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;
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 )
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,
RageSurface* img,
bool bGenerateMipMaps )
@@ -1386,7 +1387,7 @@ uintptr_t RageDisplay_D3D::CreateTexture(
RageException::Throw( "CreateTexture(%i,%i,%s) failed: %s",
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 )
{
@@ -1412,7 +1413,7 @@ uintptr_t RageDisplay_D3D::CreateTexture(
}
void RageDisplay_D3D::UpdateTexture(
uintptr_t uTexHandle,
std::uintptr_t uTexHandle,
RageSurface* img,
int xoffset, int yoffset, int width, int height )
{
+19 -17
View File
@@ -5,6 +5,8 @@
#include "RageDisplay.h"
#include <cstdint>
class RageDisplay_D3D: public RageDisplay
{
public:
@@ -17,26 +19,26 @@ public:
void ResolutionChanged();
const RagePixelFormatDesc *GetPixelFormatDesc(RagePixelFormat pf) const;
bool BeginFrame();
bool BeginFrame();
void EndFrame();
ActualVideoModeParams GetActualVideoModeParams() const;
void SetBlendMode( BlendMode mode );
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsThreadedRendering();
bool SupportsPerVertexMatrixScale() { return false; }
uintptr_t CreateTexture(
RagePixelFormat pixfmt,
RageSurface* img,
bool bGenerateMipMaps );
void UpdateTexture(
uintptr_t iTexHandle,
std::uintptr_t CreateTexture(
RagePixelFormat pixfmt,
RageSurface* img,
int xoffset, int yoffset, int width, int height
bool bGenerateMipMaps );
void UpdateTexture(
std::uintptr_t iTexHandle,
RageSurface* img,
int xoffset, int yoffset, int width, int height
);
void DeleteTexture( uintptr_t iTexHandle );
void DeleteTexture( std::uintptr_t iTexHandle );
void ClearAllTextures();
int GetNumTextureUnits();
void SetTexture( TextureUnit tu, uintptr_t iTexture );
void SetTexture( TextureUnit tu, std::uintptr_t iTexture );
void SetTextureMode( TextureUnit tu, TextureMode tm );
void SetTextureWrapping( TextureUnit tu, bool b );
int GetMaxTextureSize() const;
@@ -49,7 +51,7 @@ public:
void ClearZBuffer();
void SetCullMode( CullMode mode );
void SetAlphaTest( bool b );
void SetMaterial(
void SetMaterial(
const RageColor &emissive,
const RageColor &ambient,
const RageColor &diffuse,
@@ -58,11 +60,11 @@ public:
);
void SetLighting( bool b );
void SetLightOff( int index );
void SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
void SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
const RageVector3 &dir );
void SetSphereEnvironmentMapping( TextureUnit tu, bool b );
@@ -82,7 +84,7 @@ protected:
RString TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut );
RageSurface* CreateScreenshot();
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
void SendCurrentMatrices();
};
+5 -4
View File
@@ -17,6 +17,7 @@
#include <GL/glew.h>
#include <cstddef>
#include <cstdint>
#ifdef NO_GL_FLUSH
#define glFlush()
@@ -562,7 +563,7 @@ RageDisplay_GLES2::SupportsPerVertexMatrixScale()
return true;
}
uintptr_t
std::uintptr_t
RageDisplay_GLES2::CreateTexture(
RagePixelFormat pixfmt,
RageSurface* img,
@@ -575,7 +576,7 @@ RageDisplay_GLES2::CreateTexture(
void
RageDisplay_GLES2::UpdateTexture(
uintptr_t iTexHandle,
std::uintptr_t iTexHandle,
RageSurface* img,
int xoffset, int yoffset, int width, int height
)
@@ -584,7 +585,7 @@ RageDisplay_GLES2::UpdateTexture(
}
void
RageDisplay_GLES2::DeleteTexture( uintptr_t iTexHandle )
RageDisplay_GLES2::DeleteTexture( std::uintptr_t iTexHandle )
{
// TODO
}
@@ -616,7 +617,7 @@ SetTextureUnit( TextureUnit tu )
}
void
RageDisplay_GLES2::SetTexture( TextureUnit tu, uintptr_t iTexture )
RageDisplay_GLES2::SetTexture( TextureUnit tu, std::uintptr_t iTexture )
{
if (!SetTextureUnit( tu ))
return;
+12 -10
View File
@@ -1,6 +1,8 @@
#ifndef RAGE_DISPLAY_GLES2_H
#define RAGE_DISPLAY_GLES2_H
#include <cstdint>
class RageDisplay_GLES2: public RageDisplay
{
public:
@@ -18,18 +20,18 @@ public:
void SetBlendMode( BlendMode mode );
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsPerVertexMatrixScale();
uintptr_t CreateTexture(
std::uintptr_t CreateTexture(
RagePixelFormat pixfmt,
RageSurface* img,
bool bGenerateMipMaps );
void UpdateTexture(
uintptr_t iTexHandle,
std::uintptr_t iTexHandle,
RageSurface* img,
int xoffset, int yoffset, int width, int height );
void DeleteTexture( uintptr_t iTexHandle );
void DeleteTexture( std::uintptr_t iTexHandle );
void ClearAllTextures();
int GetNumTextureUnits();
void SetTexture( TextureUnit tu, uintptr_t iTexture );
void SetTexture( TextureUnit tu, std::uintptr_t iTexture );
void SetTextureMode( TextureUnit tu, TextureMode tm );
void SetTextureWrapping( TextureUnit tu, bool b );
int GetMaxTextureSize() const;
@@ -51,11 +53,11 @@ public:
);
void SetLighting( bool b );
void SetLightOff( int index );
void SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
void SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
const RageVector3 &dir );
void SetSphereEnvironmentMapping( TextureUnit tu, bool b );
@@ -79,7 +81,7 @@ protected:
RString TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut );
RageSurface* CreateScreenshot();
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
bool SupportsSurfaceFormat( RagePixelFormat pixfmt );
bool SupportsRenderToTexture() const { return true; }
};
+12 -10
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_DISPLAY_NULL_H
#define RAGE_DISPLAY_NULL_H
#include <cstdint>
class RageDisplay_Null: public RageDisplay
{
public:
@@ -19,19 +21,19 @@ public:
void SetBlendMode( BlendMode ) { }
bool SupportsTextureFormat( RagePixelFormat, bool /* realtime */ =false ) { return true; }
bool SupportsPerVertexMatrixScale() { return false; }
uintptr_t CreateTexture(
std::uintptr_t CreateTexture(
RagePixelFormat,
RageSurface* /* img */,
bool /* bGenerateMipMaps */ ) { return 1; }
void UpdateTexture(
uintptr_t /* iTexHandle */,
std::uintptr_t /* iTexHandle */,
RageSurface* /* img */,
int /* xoffset */, int /* yoffset */, int /* width */, int /* height */
) { }
void DeleteTexture( uintptr_t /* iTexHandle */ ) { }
void DeleteTexture( std::uintptr_t /* iTexHandle */ ) { }
void ClearAllTextures() { }
int GetNumTextureUnits() { return 1; }
void SetTexture( TextureUnit, uintptr_t /* iTexture */ ) { }
void SetTexture( TextureUnit, std::uintptr_t /* iTexture */ ) { }
void SetTextureMode( TextureUnit, TextureMode ) { }
void SetTextureWrapping( TextureUnit, bool ) { }
int GetMaxTextureSize() const { return 2048; }
@@ -53,11 +55,11 @@ public:
) { }
void SetLighting( bool ) { }
void SetLightOff( int /* index */ ) { }
void SetLightDirectional(
int /* index */,
const RageColor & /* unreferenced: ambient */,
const RageColor & /* unreferenced: diffuse */,
const RageColor & /* unreferenced: specular */,
void SetLightDirectional(
int /* index */,
const RageColor & /* unreferenced: ambient */,
const RageColor & /* unreferenced: diffuse */,
const RageColor & /* unreferenced: specular */,
const RageVector3 & /* unreferenced: dir */ ) { }
void SetSphereEnvironmentMapping( TextureUnit /* tu */, bool /* b */ ) { }
@@ -79,7 +81,7 @@ protected:
VideoModeParams m_Params;
RString TryVideoMode( const VideoModeParams &p, bool & /* bNewDeviceOut */ ) { m_Params = p; return RString(); }
RageSurface* CreateScreenshot();
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
bool SupportsSurfaceFormat( RagePixelFormat ) { return true; }
};
+26 -25
View File
@@ -21,6 +21,7 @@ using namespace RageDisplay_Legacy_Helpers;
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <set>
#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: */
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 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
* 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;
g_mapRenderTargets.clear();
@@ -926,7 +927,7 @@ RageSurface* RageDisplay_Legacy::CreateScreenshot()
return image;
}
RageSurface *RageDisplay_Legacy::GetTexture( uintptr_t iTexture )
RageSurface *RageDisplay_Legacy::GetTexture( std::uintptr_t iTexture )
{
if (iTexture == 0)
return nullptr; // XXX
@@ -1070,7 +1071,7 @@ public:
for( unsigned k=0; k<3; 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;
// make a temporary index buffer
static std::vector<uint16_t> vIndices;
static std::vector<std::uint16_t> vIndices;
unsigned uOldSize = vIndices.size();
unsigned uNewSize = std::max(uOldSize,(unsigned)iNumIndices);
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 }
vIndices[i*12+0] = i*3+1;
@@ -1686,7 +1687,7 @@ int RageDisplay_Legacy::GetNumTextureUnits()
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 ))
return;
@@ -2113,7 +2114,7 @@ void RageDisplay_Legacy::EndConcurrentRendering()
g_pWind->EndConcurrentRendering();
}
void RageDisplay_Legacy::DeleteTexture( uintptr_t iTexture )
void RageDisplay_Legacy::DeleteTexture( std::uintptr_t iTexture )
{
if (iTexture == 0)
return;
@@ -2198,7 +2199,7 @@ void SetPixelMapForSurface( int glImageFormat, int glTexFormat, const RageSurfac
DebugAssertNoGLError();
}
uintptr_t RageDisplay_Legacy::CreateTexture(
std::uintptr_t RageDisplay_Legacy::CreateTexture(
RagePixelFormat pixfmt,
RageSurface* pImg,
bool bGenerateMipMaps )
@@ -2243,7 +2244,7 @@ uintptr_t RageDisplay_Legacy::CreateTexture(
SetTextureUnit( TextureUnit_1 );
// allocate OpenGL texture resource
uintptr_t iTexHandle;
std::uintptr_t iTexHandle;
glGenTextures( 1, reinterpret_cast<GLuint*>(&iTexHandle) );
ASSERT( iTexHandle != 0 );
@@ -2359,7 +2360,7 @@ public:
m_iTexHandle = 0;
}
void Lock( uintptr_t iTexHandle, RageSurface *pSurface )
void Lock( std::uintptr_t iTexHandle, RageSurface *pSurface )
{
ASSERT( m_iTexHandle == 0 );
ASSERT( pSurface->pixels == nullptr );
@@ -2373,7 +2374,7 @@ public:
glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, iSize, nullptr, GL_STREAM_DRAW );
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;
}
@@ -2381,7 +2382,7 @@ public:
{
glUnmapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB );
pSurface->pixels = (uint8_t *) BUFFER_OFFSET(0);
pSurface->pixels = (std::uint8_t *) BUFFER_OFFSET(0);
if (bChanged)
DISPLAY->UpdateTexture( m_iTexHandle, pSurface, 0, 0, pSurface->w, pSurface->h );
@@ -2405,7 +2406,7 @@ private:
GLuint m_iBuffer;
uintptr_t m_iTexHandle;
std::uintptr_t m_iTexHandle;
};
RageTextureLock *RageDisplay_Legacy::CreateTextureLock()
@@ -2417,7 +2418,7 @@ RageTextureLock *RageDisplay_Legacy::CreateTextureLock()
}
void RageDisplay_Legacy::UpdateTexture(
uintptr_t iTexHandle,
std::uintptr_t iTexHandle,
RageSurface* pImg,
int iXOffset, int iYOffset, int iWidth, int iHeight )
{
@@ -2459,16 +2460,16 @@ public:
RenderTarget_FramebufferObject();
~RenderTarget_FramebufferObject();
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 FinishRenderingTo();
virtual bool InvertY() const { return true; }
private:
uintptr_t m_iFrameBufferHandle;
uintptr_t m_iTexHandle;
uintptr_t m_iDepthBufferHandle;
std::uintptr_t m_iFrameBufferHandle;
std::uintptr_t m_iTexHandle;
std::uintptr_t m_iDepthBufferHandle;
};
RenderTarget_FramebufferObject::RenderTarget_FramebufferObject()
@@ -2591,7 +2592,7 @@ bool RageDisplay_Legacy::SupportsFullscreenBorderlessWindow() const
* 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;
if (GLEW_EXT_framebuffer_object)
@@ -2601,22 +2602,22 @@ uintptr_t RageDisplay_Legacy::CreateRenderTarget( const RenderTargetParam &param
pTarget->Create( param, iTextureWidthOut, iTextureHeightOut );
uintptr_t iTexture = pTarget->GetTexture();
std::uintptr_t iTexture = pTarget->GetTexture();
ASSERT( g_mapRenderTargets.find(iTexture) == g_mapRenderTargets.end() );
g_mapRenderTargets[iTexture] = pTarget;
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 )
return it->first;
return 0;
}
void RageDisplay_Legacy::SetRenderTarget( uintptr_t iTexture, bool bPreserveTexture )
void RageDisplay_Legacy::SetRenderTarget( std::uintptr_t iTexture, bool bPreserveTexture )
{
if (iTexture == 0)
{
@@ -2695,7 +2696,7 @@ void RageDisplay_Legacy::SetLineWidth(float fWidth)
glLineWidth(fWidth);
}
RString RageDisplay_Legacy::GetTextureDiagnostics(uintptr_t iTexture) const
RString RageDisplay_Legacy::GetTextureDiagnostics(std::uintptr_t iTexture) const
{
/*
s << (bGenerateMipMaps? "gluBuild2DMipmaps":"glTexImage2D");
+17 -15
View File
@@ -11,6 +11,8 @@
#include "RageTextureRenderTarget.h"
#include "Sprite.h"
#include <cstdint>
/* 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.
* Flush it. */
@@ -53,23 +55,23 @@ public:
void SetBlendMode( BlendMode mode );
bool SupportsTextureFormat( RagePixelFormat pixfmt, bool realtime=false );
bool SupportsPerVertexMatrixScale();
uintptr_t CreateTexture(
std::uintptr_t CreateTexture(
RagePixelFormat pixfmt,
RageSurface* img,
bool bGenerateMipMaps );
void UpdateTexture(
uintptr_t iTexHandle,
std::uintptr_t iTexHandle,
RageSurface* img,
int xoffset, int yoffset, int width, int height
);
void DeleteTexture( uintptr_t iTexHandle );
void DeleteTexture( std::uintptr_t iTexHandle );
bool UseOffscreenRenderTarget();
RageSurface *GetTexture( uintptr_t iTexture );
RageSurface *GetTexture( std::uintptr_t iTexture );
RageTextureLock *CreateTextureLock();
void ClearAllTextures();
int GetNumTextureUnits();
void SetTexture( TextureUnit tu, uintptr_t iTexture );
void SetTexture( TextureUnit tu, std::uintptr_t iTexture );
void SetTextureMode( TextureUnit tu, TextureMode tm );
void SetTextureWrapping( TextureUnit tu, bool b );
int GetMaxTextureSize() const;
@@ -78,9 +80,9 @@ public:
bool IsEffectModeSupported( EffectMode effect );
bool SupportsRenderToTexture() const;
bool SupportsFullscreenBorderlessWindow() const;
uintptr_t CreateRenderTarget( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut );
uintptr_t GetRenderTarget();
void SetRenderTarget( uintptr_t iHandle, bool bPreserveTexture );
std::uintptr_t CreateRenderTarget( const RenderTargetParam &param, int &iTextureWidthOut, int &iTextureHeightOut );
std::uintptr_t GetRenderTarget();
void SetRenderTarget( std::uintptr_t iHandle, bool bPreserveTexture );
bool IsZWriteEnabled() const;
bool IsZTestEnabled() const;
void SetZWrite( bool b );
@@ -98,11 +100,11 @@ public:
);
void SetLighting( bool b );
void SetLightOff( int index );
void SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
void SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
const RageVector3 &dir );
void SetSphereEnvironmentMapping( TextureUnit tu, bool b );
@@ -115,7 +117,7 @@ public:
virtual void SetPolygonMode( PolygonMode pm );
virtual void SetLineWidth( float fWidth );
RString GetTextureDiagnostics( uintptr_t id ) const;
RString GetTextureDiagnostics( std::uintptr_t id ) const;
protected:
void DrawQuadsInternal( const RageSpriteVertex v[], int iNumVerts );
@@ -131,7 +133,7 @@ protected:
RageSurface* CreateScreenshot();
RagePixelFormat GetImgPixelFormat( RageSurface* &img, bool &FreeImg, int width, int height, bool bPalettedTexture );
bool SupportsSurfaceFormat( RagePixelFormat pixfmt );
void SendCurrentMatrices();
private:
+6 -4
View File
@@ -1,15 +1,17 @@
#ifndef 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)
#include <windows.h>
#endif
#include <GL/glew.h>
/* Import RageDisplay, for types. Do not include RageDisplay_Legacy.h. */
#include "RageDisplay.h"
/* Windows defines GL_EXT_paletted_texture incompletely: */
#ifndef GL_TEXTURE_INDEX_SIZE_EXT
#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
@@ -28,7 +30,7 @@ public:
virtual ~RenderTarget() { }
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. */
virtual void StartRenderingTo() = 0;
+2 -1
View File
@@ -5,6 +5,7 @@
#include "RageThreads.h"
#include <cstdarg>
#include <cstdint>
#if defined(_WINDOWS) && defined(DEBUG)
#include <windows.h>
@@ -14,7 +15,7 @@ using CrashHandler::IsDebuggerPresent;
using CrashHandler::DebugBreak;
#endif
static uint64_t g_HandlerThreadID = RageThread::GetInvalidThreadID();
static std::uint64_t g_HandlerThreadID = RageThread::GetInvalidThreadID();
static void (*g_CleanupHandler)( const RString &sError ) = nullptr;
void RageException::SetCleanupHandler( void (*pHandler)(const RString &sError) )
{
+17 -16
View File
@@ -13,6 +13,7 @@
#include "RageFileDriver.h"
#include <cstddef>
#include <cstdint>
RageFile::RageFile()
{
@@ -110,7 +111,7 @@ void RageFile::EnableCRC32( bool on )
m_File->EnableCRC32( on );
}
bool RageFile::GetCRC32( uint32_t *iRet )
bool RageFile::GetCRC32( std::uint32_t *iRet )
{
ASSERT_OPEN;
return m_File->GetCRC32( iRet );
@@ -266,50 +267,50 @@ void FileReading::Seek( RageFileBasic &f, int iOffset, RString &sError )
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;
ReadBytes( f, &val, sizeof(uint8_t), sError );
std::uint8_t val;
ReadBytes( f, &val, sizeof(std::uint8_t), sError );
if( sError.size() == 0 )
return val;
else
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;
ReadBytes( f, &val, sizeof(uint16_t), sError );
std::uint16_t val;
ReadBytes( f, &val, sizeof(std::uint16_t), sError );
if( sError.size() == 0 )
return Swap16LE( val );
else
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;
ReadBytes( f, &val, sizeof(int16_t), sError );
std::int16_t val;
ReadBytes( f, &val, sizeof(std::int16_t), sError );
if( sError.size() == 0 )
return Swap16LE( val );
else
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;
ReadBytes( f, &val, sizeof(uint32_t), sError );
std::uint32_t val;
ReadBytes( f, &val, sizeof(std::uint32_t), sError );
if( sError.size() == 0 )
return Swap32LE( val );
else
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;
ReadBytes( f, &val, sizeof(int32_t), sError );
std::int32_t val;
ReadBytes( f, &val, sizeof(std::int32_t), sError );
if( sError.size() == 0 )
return Swap32LE( val );
else
+7 -6
View File
@@ -6,6 +6,7 @@
#include "RageFileBasic.h"
#include <cstddef>
#include <cstdint>
struct lua_State;
@@ -77,7 +78,7 @@ public:
int PutLine( const RString &str );
void EnableCRC32( bool on=true );
bool GetCRC32( uint32_t *iRet );
bool GetCRC32( std::uint32_t *iRet );
// Lua
virtual void PushSelf( lua_State *L );
@@ -102,11 +103,11 @@ namespace FileReading
void SkipBytes( RageFileBasic &f, int size, RString &sError );
void Seek( RageFileBasic &f, int iOffset, RString &sError );
RString ReadString( RageFileBasic &f, int size, RString &sError );
uint8_t read_8( RageFileBasic &f, RString &sError );
int16_t read_16_le( RageFileBasic &f, RString &sError );
uint16_t read_u16_le( RageFileBasic &f, RString &sError );
int32_t read_32_le( RageFileBasic &f, RString &sError );
uint32_t read_u32_le( RageFileBasic &f, RString &sError );
std::uint8_t read_8( RageFileBasic &f, RString &sError );
std::int16_t read_16_le( RageFileBasic &f, RString &sError );
std::uint16_t read_u16_le( RageFileBasic &f, RString &sError );
std::int32_t read_32_le( RageFileBasic &f, RString &sError );
std::uint32_t read_u32_le( RageFileBasic &f, RString &sError );
};
#endif
+2 -1
View File
@@ -4,6 +4,7 @@
#include "RageUtil_AutoPtr.h"
#include <cstddef>
#include <cstdint>
REGISTER_CLASS_TRAITS( RageFileBasic, pCopy->Copy() );
@@ -313,7 +314,7 @@ void RageFileObj::EnableCRC32( bool bOn )
m_iCRC32 = 0;
}
bool RageFileObj::GetCRC32( uint32_t *iRet )
bool RageFileObj::GetCRC32( std::uint32_t *iRet )
{
if( !m_bCRC32Enabled )
return false;
+4 -3
View File
@@ -6,6 +6,7 @@
#include "global.h"
#include <cstddef>
#include <cstdint>
/* 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
@@ -54,7 +55,7 @@ public:
virtual int PutLine( const RString &str ) = 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;
@@ -94,7 +95,7 @@ public:
int PutLine( const RString &str );
void EnableCRC32( bool on=true );
bool GetCRC32( uint32_t *iRet );
bool GetCRC32( std::uint32_t *iRet );
virtual int GetFileSize() const = 0;
virtual int GetFD() { return -1; }
@@ -155,7 +156,7 @@ private:
* This is only meaningful if EnableCRC32() is called at the very start of the
* file, and no seeking is performed. */
bool m_bCRC32Enabled;
uint32_t m_iCRC32;
std::uint32_t m_iCRC32;
// Swallow up warnings. If they must be used, define them.
RageFileObj& operator=(const RageFileObj& rhs);
+13 -12
View File
@@ -6,6 +6,7 @@
#include "RageUtil.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#if defined(_WINDOWS)
@@ -313,7 +314,7 @@ int RageFileObjDeflate::FlushInternal()
* Parse a .gz file, check the header CRC16 if present, and return the data
* 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_);
@@ -335,8 +336,8 @@ RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t
}
}
uint8_t iCompressionMethod = FileReading::read_8( *pFile, sError );
uint8_t iFlags = FileReading::read_8( *pFile, sError );
std::uint8_t iCompressionMethod = FileReading::read_8( *pFile, sError );
std::uint8_t iFlags = FileReading::read_8( *pFile, sError );
FileReading::read_32_le( *pFile, sError ); /* time */
FileReading::read_8( *pFile, sError ); /* xfl */
FileReading::read_8( *pFile, sError ); /* os */
@@ -365,7 +366,7 @@ RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t
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 );
}
@@ -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
* reading iExpectedCRC16. */
uint32_t iActualCRC32;
std::uint32_t iActualCRC32;
bool bOK = pFile->GetCRC32( &iActualCRC32 );
ASSERT( bOK );
uint16_t iExpectedCRC16 = FileReading::read_u16_le( *pFile, sError );
uint16_t iActualCRC16 = int16_t( iActualCRC32 & 0xFFFF );
std::uint16_t iExpectedCRC16 = FileReading::read_u16_le( *pFile, sError );
std::uint16_t iActualCRC16 = std::int16_t( iActualCRC32 & 0xFFFF );
if( sError != "" )
return nullptr;
@@ -410,8 +411,8 @@ RageFileObjInflate *GunzipFile( RageFileBasic *pFile_, RString &sError, uint32_t
FileReading::Seek( *pFile, iFooterPos, sError );
uint32_t iExpectedCRC32 = FileReading::read_u32_le( *pFile, sError );
uint32_t iUncompressedSize = FileReading::read_u32_le( *pFile, sError );
std::uint32_t iExpectedCRC32 = FileReading::read_u32_le( *pFile, sError );
std::uint32_t iUncompressedSize = FileReading::read_u32_le( *pFile, sError );
if( iCRC32 != nullptr )
*iCRC32 = iExpectedCRC32;
@@ -486,12 +487,12 @@ int RageFileObjGzip::Finish()
return -1;
/* Read the CRC of the data that's been written. */
uint32_t iCRC;
std::uint32_t iCRC;
bool bOK = this->GetCRC32( &iCRC );
ASSERT( bOK );
/* 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. */
iCRC = Swap32LE( iCRC );
@@ -532,7 +533,7 @@ bool GunzipString( const RString &sIn, RString &sOut, RString &sError )
RageFileObjMem *mem = new RageFileObjMem;
mem->PutString( sIn );
uint32_t iCRC32;
std::uint32_t iCRC32;
RageFileBasic *pFile = GunzipFile( mem, sError, &iCRC32 );
if( pFile == nullptr )
return false;
+2 -1
View File
@@ -6,6 +6,7 @@
#include "RageFileBasic.h"
#include <cstddef>
#include <cstdint>
typedef struct z_stream_s z_stream;
@@ -69,7 +70,7 @@ private:
int m_iDataStartOffset;
};
RageFileObjInflate *GunzipFile( RageFileBasic *pFile, RString &sError, uint32_t *iCRC32 );
RageFileObjInflate *GunzipFile( RageFileBasic *pFile, RString &sError, std::uint32_t *iCRC32 );
/* Quick helpers: */
void GzipString( const RString &sIn, RString &sOut );
+2 -1
View File
@@ -11,6 +11,7 @@
#include <cerrno>
#include <cstddef>
#include <cstdint>
#include <sstream>
#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);
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;
}
+9 -7
View File
@@ -5,6 +5,8 @@
#include "RageMath.h"
#include "RageDisplay.h"
#include <cstdint>
#define MS_MAX_NAME 32
RageModelGeometry::RageModelGeometry ()
@@ -29,7 +31,7 @@ void RageModelGeometry::OptimizeBones()
// check to see if all vertices have the same bone index
bool bAllVertsUseSameBone = true;
char iBoneIndex = mesh.Vertices[0].bone;
for (unsigned j = 1; j < mesh.Vertices.size(); j++)
@@ -69,8 +71,8 @@ void RageModelGeometry::MergeMeshes( int iFromIndex, int iToIndex )
{
for( int j=0; j<3; j++ )
{
uint16_t &iIndex = meshTo.Triangles[i].nVertexIndices[j];
iIndex = uint16_t(iIndex + iShiftTriangleVertexIndicesBy);
std::uint16_t &iIndex = meshTo.Triangles[i].nVertexIndices[j];
iIndex = std::uint16_t(iIndex + iShiftTriangleVertexIndicesBy);
}
}
}
@@ -147,7 +149,7 @@ void RageModelGeometry::LoadMilkshapeAscii( const RString& _sPath, bool bNeedsNo
mesh.sName = szName;
// mesh.nFlags = nFlags;
mesh.nMaterialIndex = (uint8_t) nIndex;
mesh.nMaterialIndex = (std::uint8_t) nIndex;
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[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 );
}
@@ -237,8 +239,8 @@ void RageModelGeometry::LoadMilkshapeAscii( const RString& _sPath, bool bNeedsNo
if( f.GetLine( sLine ) <= 0 )
THROW;
uint16_t nIndices[3];
uint16_t nNormalIndices[3];
std::uint16_t nIndices[3];
std::uint16_t nNormalIndices[3];
if( sscanf (sLine, "%d %hu %hu %hu %hu %hu %hu %d",
&nFlags,
&nIndices[0], &nIndices[1], &nIndices[2],
+8 -7
View File
@@ -37,6 +37,7 @@
#include "RageSoundReader_ThreadedBuffer.h"
#include <cmath>
#include <cstdint>
#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
* 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. */
// 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. */
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_HardwareToStreamMap.Insert( iHardwareFrame, iGotFrames, iStreamFrame );
@@ -372,7 +373,7 @@ void RageSound::SoundIsFinishedPlaying()
return;
/* Get our current hardware position. */
int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition(nullptr);
std::int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition(nullptr);
m_Mutex.Lock();
@@ -474,16 +475,16 @@ float RageSound::GetLengthSeconds()
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() )
return 0;
bool bApprox;
int64_t iStreamFrame = m_HardwareToStreamMap.Search( iHardwareFrame, &bApprox );
std::int64_t iStreamFrame = m_HardwareToStreamMap.Search( iHardwareFrame, &bApprox );
if( bApproximate && bApprox )
*bApproximate = true;
int64_t iSourceFrame = m_StreamToSourceMap.Search( iStreamFrame, &bApprox );
std::int64_t iSourceFrame = m_StreamToSourceMap.Search( iStreamFrame, &bApprox );
if( bApproximate && bApprox )
*bApproximate = true;
return (int) iSourceFrame;
@@ -499,7 +500,7 @@ int RageSound::GetSourceFrameFromHardwareFrame( int64_t iHardwareFrame, bool *bA
float RageSound::GetPositionSeconds( bool *bApproximate, RageTimer *pTimestamp ) const
{
/* 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
* calls with our mutex locked (driver mutex < sound mutex). */
+11 -9
View File
@@ -7,6 +7,8 @@
#include "RageTimer.h"
#include "RageSoundPosMap.h"
#include <cstdint>
class RageSoundReader;
struct lua_State;
@@ -16,8 +18,8 @@ class RageSoundBase
public:
virtual ~RageSoundBase() { }
virtual void SoundIsFinishedPlaying() = 0;
virtual int GetDataToPlay( float *buffer, int size, int64_t &iStreamFrame, int &got_bytes ) = 0;
virtual void CommitPlayingPosition( int64_t iFrameno, int64_t iPosition, int iBytesRead ) = 0;
virtual int GetDataToPlay( float *buffer, int size, std::int64_t &iStreamFrame, int &got_bytes ) = 0;
virtual void CommitPlayingPosition( std::int64_t iFrameno, std::int64_t iPosition, int iBytesRead ) = 0;
virtual RageTimer GetStartTime() const { return RageZeroTimer; }
virtual RString GetLoadedFilePath() const = 0;
};
@@ -92,7 +94,7 @@ public:
*
* If cache == false, we'll always stream the sound on demand, which
* makes loads much faster.
*
*
* If the file failed to load, false is returned, Error() is set
* and a null sample will be loaded. This makes failed loads nonfatal;
* they can be ignored most of the time, so we continue to work if a file
@@ -100,7 +102,7 @@ public:
*/
bool Load( RString sFile, bool bPrecache, const RageSoundLoadParams *pParams = nullptr );
/* Using this version means the "don't care" about caching. Currently,
/* Using this version means the "don't care" about caching. Currently,
* this always will not cache the sound; this may become a preference. */
bool Load( RString sFile );
@@ -159,12 +161,12 @@ private:
/* Current position of the output sound, in frames. If < 0, nothing will play
* 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
* (we're not playing); and we can't seek back to the current playing position
* when we stop (too slow), but we want to be able to report the position we
* were at when we stopped without jumping to the last position we buffered.
* were at when we stopped without jumping to the last position we buffered.
* Keep track of the position after a seek or stop, so we can return a sane
* position when stopped, and when playing but pos_map hasn't yet been filled. */
int m_iStoppedSourceFrame;
@@ -173,7 +175,7 @@ private:
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 );
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
* called. Until then, SOUNDMAN->GetPosition can still be called; the sound
* is still playing. */
int GetDataToPlay( float *pBuffer, int iSize, int64_t &iStreamFrame, int &iBytesRead );
void CommitPlayingPosition( int64_t iHardwareFrame, int64_t iStreamFrame, int iGotFrames );
int GetDataToPlay( float *pBuffer, int iSize, std::int64_t &iStreamFrame, int &iBytesRead );
void CommitPlayingPosition( std::int64_t iHardwareFrame, std::int64_t iStreamFrame, int iGotFrames );
};
#endif
+5 -3
View File
@@ -21,6 +21,8 @@
#include "arch/Sound/RageSoundDriver.h"
#include <cstdint>
/*
* The lock ordering requirements are:
* RageSound::Lock before g_SoundManMutex
@@ -98,7 +100,7 @@ bool RageSoundManager::Pause( RageSoundBase *pSound, bool 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 )
return 0;
@@ -112,7 +114,7 @@ void RageSoundManager::Update()
{
std::map<RString, RageSoundReader_Preload*>::iterator it, next;
it = m_mapPreloadedSounds.begin();
while( it != m_mapPreloadedSounds.end() )
{
next = it; ++next;
@@ -179,7 +181,7 @@ void RageSoundManager::AddLoadedSound( const RString &sPath_, RageSoundReader_Pr
std::map<RString, RageSoundReader_Preload*>::const_iterator it;
it = m_mapPreloadedSounds.find( sPath );
ASSERT_M( it == m_mapPreloadedSounds.end(), sPath );
m_mapPreloadedSounds[sPath] = pSound->Copy();
}
+5 -3
View File
@@ -3,10 +3,12 @@
#ifndef RAGE_SOUND_MANAGER_H
#define RAGE_SOUND_MANAGER_H
#include <set>
#include <map>
#include "RageUtil_CircularBuffer.h"
#include <cstdint>
#include <map>
#include <set>
class RageSound;
class RageSoundBase;
class RageSoundDriver;
@@ -37,7 +39,7 @@ public:
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
void StopMixing( RageSoundBase *snd ); /* 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;
int GetDriverSampleRate() const;
+2 -1
View File
@@ -3,6 +3,7 @@
#include "RageUtil.h"
#include <cmath>
#include <cstdint>
#if defined(MACOSX)
#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 )
{
+3 -1
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_SOUND_MIX_BUFFER_H
#define RAGE_SOUND_MIX_BUFFER_H
#include <cstdint>
class RageSoundMixBuffer
{
public:
@@ -15,7 +17,7 @@ public:
/* Extend the buffer as if write() was called with a buffer of silence. */
void Extend( unsigned iSamples );
void read( int16_t *pBuf );
void read( std::int16_t *pBuf );
void read( float *pBuf );
void read_deinterlace( float **pBufs, int channels );
float *read() { return m_pMixbuf; }
+7 -6
View File
@@ -6,6 +6,7 @@
#include <climits>
#include <cmath>
#include <cstdint>
#include <list>
/* 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
{
int64_t m_iSourceFrame;
int64_t m_iDestFrame;
std::int64_t m_iSourceFrame;
std::int64_t m_iDestFrame;
int m_iFrames;
float m_fSourceToDestRatio;
@@ -53,7 +54,7 @@ pos_map_queue &pos_map_queue::operator=( const pos_map_queue &rhs )
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() )
{
@@ -120,7 +121,7 @@ void pos_map_impl::Cleanup()
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 )
*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
* 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 */
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. */
int64_t dist = llabs( pm.m_iSourceFrame - iSourceFrame );
std::int64_t dist = llabs( pm.m_iSourceFrame - iSourceFrame );
if( dist < iClosestPositionDist )
{
iClosestPositionDist = dist;
+4 -2
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_SOUND_POS_MAP_H
#define RAGE_SOUND_POS_MAP_H
#include <cstdint>
struct pos_map_impl;
class pos_map_queue
{
@@ -13,10 +15,10 @@ public:
pos_map_queue &operator=( const pos_map_queue &rhs );
/* 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. */
int64_t Search( int64_t iSourceFrame, bool *bApproximate ) const;
std::int64_t Search( std::int64_t iSourceFrame, bool *bApproximate ) const;
/* Erase all mappings. */
void Clear();
+3 -2
View File
@@ -5,6 +5,7 @@
#include "RageSoundReader.h"
#include <cstdint>
#include <map>
class RageSoundReader_Chain: public RageSoundReader
@@ -30,7 +31,7 @@ public:
/* Return the number of added sounds. */
int GetNumSounds() const { return m_aSounds.size(); }
int GetLength() const;
int GetLength_Fast() const;
int SetPosition( int iFrame );
@@ -59,7 +60,7 @@ private:
float fPan;
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; }
};
std::vector<Sound> m_aSounds;
+11 -10
View File
@@ -5,8 +5,9 @@
#include "RageLog.h"
#include "RageUtil.h"
#include <cstdio>
#include <cerrno>
#include <cstdint>
#include <cstdio>
#include <map>
#include "mad.h"
@@ -188,7 +189,7 @@ struct madlib_t
bitrate = 0;
}
uint8_t inbuf[16384];
std::uint8_t inbuf[16384];
float outbuf[8192];
int outpos;
unsigned outleft;
@@ -213,7 +214,7 @@ struct madlib_t
return mad_timer_compare( timer1, timer2 ) < 0;
}
};
typedef std::map<mad_timer_t, int, mad_timer_compare_lt> tocmap_t;
tocmap_t tocmap;
@@ -283,7 +284,7 @@ bool RageSoundReader_MP3::handle_first_frame()
/*
* "Info" tags are written by some tools. They're just Xing tags, but for
* CBR files.
*
*
* However, DWI's decoder, BASS, doesn't understand this, and treats it as a
* corrupt frame, outputting a frame of silence. Let's ignore the tag, so
* it'll be treated as an invalid frame, so we match DWI sync.
@@ -458,7 +459,7 @@ int RageSoundReader_MP3::do_mad_frame_decode( bool headers_only )
continue;
}
/* We've decoded the first frame of data.
/* We've decoded the first frame of data.
*
* We want mad->Timer to represent the timestamp of the first sample of the
* currently decoded frame. Don't increment mad->Timer on the first frame,
@@ -730,7 +731,7 @@ int RageSoundReader_MP3::Read( float *buf, int iFrames )
bool RageSoundReader_MP3::MADLIB_rewind()
{
m_pFile->Seek(0);
mad_frame_mute(&mad->Frame);
mad_synth_mute(&mad->Synth);
mad_timer_reset(&mad->Timer);
@@ -765,7 +766,7 @@ bool RageSoundReader_MP3::MADLIB_rewind()
* 3. We can seek from any position to any higher position by decoding headers.
* (SetPosition_hard)
*
* Both 1 and 2 will leave the position behind the actual requested position;
* Both 1 and 2 will leave the position behind the actual requested position;
* combine them with 3 to catch up. Never do 3 alone in "fast" mode, since it's
* slow if it ends up seeking from the beginning of the file. Never do 2 in
* "precise" mode.
@@ -867,7 +868,7 @@ int RageSoundReader_MP3::SetPosition_hard( int iFrame )
* already decoded the frame, synth it, too. */
mad_timer_t next_frame_timer = mad->Timer;
mad_timer_add( &next_frame_timer, mad->framelength );
if( mad_timer_compare(desired, next_frame_timer) < 0 )
{
if( !synthed )
@@ -937,7 +938,7 @@ int RageSoundReader_MP3::SetPosition_estimate( int iFrame )
seekpos += mad->header_bytes;
seek_stream_to_byte( seekpos );
/* We've jumped across the file, so the decoder is currently desynced.
/* We've jumped across the file, so the decoder is currently desynced.
* Don't use resync(); it's slow. Just decode a few frames. */
for( int i = 0; i < 2; ++i )
{
@@ -965,7 +966,7 @@ int RageSoundReader_MP3::SetPosition( int iFrame )
int ret = SetPosition_toc( iFrame, false );
if( ret <= 0 )
return ret; /* it set the error */
/* Align exactly. */
return SetPosition_hard( iFrame );
}
+4 -3
View File
@@ -8,6 +8,7 @@
#include "Preference.h"
#include <cmath>
#include <cstdint>
/* 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-
@@ -17,7 +18,7 @@ Preference<bool> g_bSoundPreload16bit( "SoundPreload16bit", true );
/* If a sound is smaller than this, we'll load it entirely into memory. */
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)
bool RageSoundReader_Preload::PreloadSound( RageSoundReader *&pSound )
@@ -92,7 +93,7 @@ bool RageSoundReader_Preload::Open( RageSoundReader *pSource )
/* Add the buffer. */
if( m_bBufferIs16Bit )
{
int16_t buffer16[1024];
std::int16_t buffer16[1024];
RageSoundUtil::ConvertFloatToNativeInt16( buffer, 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;
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 );
}
else
+3 -2
View File
@@ -14,6 +14,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <numeric>
/* Filter length. This must be a power of 2. */
@@ -538,7 +539,7 @@ private:
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_iSampleRate;
@@ -638,7 +639,7 @@ RageSoundReader_Resample_Good::~RageSoundReader_Resample_Good()
int RageSoundReader_Resample_Good::SetPosition( int iFrame )
{
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 );
}
+4 -3
View File
@@ -13,6 +13,7 @@
#include <cerrno>
#include <cstddef>
#include <cstdint>
#include <cstring>
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;
#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
float **pcm;
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( ret > 0 )
{
int iSamplesRead = ret / sizeof(int16_t);
int iSamplesRead = ret / sizeof(std::int16_t);
iFramesRead = iSamplesRead / channels;
/* 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;
for( int i = iSamplesRead-1; i >= 0; --i )
pOut[i] = pIn[i] / 32768.0f;
+38 -36
View File
@@ -15,6 +15,8 @@
#include "RageLog.h"
#include "RageFileBasic.h"
#include <cstdint>
namespace
{
/* pBuf contains iSamples 8-bit samples; convert to 16-bit. pBuf must
@@ -22,7 +24,7 @@ namespace
void Convert8bitToFloat( void *pBuf, int iSamples )
{
/* 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;
for( int i = iSamples-1; i >= 0; --i )
{
@@ -37,11 +39,11 @@ namespace
void ConvertLittleEndian16BitToFloat( void *pBuf, int iSamples )
{
/* 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;
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;
}
}
@@ -56,7 +58,7 @@ namespace
{
pIn -= 3;
int32_t iSample =
std::int32_t iSample =
(int(pIn[0]) << 0) |
(int(pIn[1]) << 8) |
(int(pIn[2]) << 16);
@@ -72,11 +74,11 @@ namespace
void ConvertLittleEndian32BitToFloat( void *pBuf, int iSamples )
{
/* 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;
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;
}
}
@@ -163,13 +165,13 @@ struct WavReaderPCM: public WavReader
int GetLength() const
{
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;
}
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 )
{
m_File.Seek( m_WavData.m_iDataChunkSize+m_WavData.m_iDataChunkPos );
@@ -192,11 +194,11 @@ struct WavReaderPCM: public WavReader
struct WavReaderADPCM: public WavReader
{
public:
std::vector<int16_t> m_iaCoef1, m_iaCoef2;
int16_t m_iFramesPerBlock;
std::vector<std::int16_t> m_iaCoef1, m_iaCoef2;
std::int16_t m_iFramesPerBlock;
float *m_pBuffer;
int m_iBufferAvail, m_iBufferUsed;
WavReaderADPCM( RageFileBasic &f, const RageSoundReader_WAV::WavData &data ):
WavReader(f, data)
{
@@ -219,7 +221,7 @@ public:
m_File.Seek( m_WavData.m_iExtraFmtPos );
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_iaCoef2.resize( iNumCoef );
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() )
return true; /* past the data chunk */
int8_t iPredictor[2];
int16_t iDelta[2], iSamp1[2], iSamp2[2];
std::int8_t iPredictor[2];
std::int16_t iDelta[2], iSamp1[2], iSamp2[2];
for( int i = 0; i < m_WavData.m_iChannels; ++i )
iPredictor[i] = FileReading::read_8( m_File, m_sError );
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 )
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 )
pBuffer[m_iBufferAvail++] = (int16_t)iSamp1[i] / 32768.0f;
pBuffer[m_iBufferAvail++] = (std::int16_t)iSamp1[i] / 32768.0f;
int8_t iBufSize = 0;
uint8_t iBuf = 0;
std::int8_t iBufSize = 0;
std::uint8_t iBuf = 0;
bool bDone = false;
for( int i = 2; !bDone && i < m_iFramesPerBlock; ++i )
@@ -326,39 +328,39 @@ public:
}
/* Store the nibble in signed char, so we get an arithmetic shift. */
int8_t iErrorDelta = (int8_t)(iBuf) >> 4;
uint8_t iErrorDeltaUnsigned = iBuf >> 4;
std::int8_t iErrorDelta = (std::int8_t)(iBuf) >> 4;
std::uint8_t iErrorDeltaUnsigned = iBuf >> 4;
iBuf <<= 4;
--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 > 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;
static const int aAdaptionTable[] = {
230, 230, 230, 230, 307, 409, 512, 614,
768, 614, 512, 409, 307, 230, 230, 230
};
iDelta[c] = int16_t( (iDelta[c] * aAdaptionTable[iErrorDeltaUnsigned]) / (1<<8) );
iDelta[c] = std::max( (int16_t) 16, iDelta[c] );
iDelta[c] = std::int16_t( (iDelta[c] * aAdaptionTable[iErrorDeltaUnsigned]) / (1<<8) );
iDelta[c] = std::max( (std::int16_t) 16, iDelta[c] );
iSamp2[c] = iSamp1[c];
iSamp1[c] = iNewSample;
}
}
return true;
}
int Read( float *buf, int iFrames )
{
int iGotFrames = 0;
int iSample = 0;
while( iGotFrames < (int) iFrames )
{
if( m_iBufferUsed == m_iBufferAvail )
@@ -386,7 +388,7 @@ public:
{
const int iNumWholeBlocks = m_WavData.m_iDataChunkSize / m_WavData.m_iBlockAlign;
const int iExtraBytes = m_WavData.m_iDataChunkSize - (iNumWholeBlocks*m_WavData.m_iBlockAlign);
int iFrames = iNumWholeBlocks * m_iFramesPerBlock;
const int iBlockHeaderSize = 7 * m_WavData.m_iChannels;
@@ -394,11 +396,11 @@ public:
{
const int iExtraADPCMNibbles = std::max( 0, iExtraBytes-iBlockHeaderSize )*2;
const int iExtraADPCMFrames = iExtraADPCMNibbles/m_WavData.m_iChannels;
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;
}
@@ -441,7 +443,7 @@ public:
int iFrame = iBlock * m_iFramesPerBlock;
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;
return iFrame;
@@ -492,7 +494,7 @@ RageSoundReader_FileReader::OpenResult RageSoundReader_WAV::Open( RageFileBasic
while( !bGotFormatChunk || !bGotDataChunk )
{
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 )
{
@@ -625,7 +627,7 @@ RageSoundReader_WAV *RageSoundReader_WAV::Copy() const
/*
* (c) 2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -635,7 +637,7 @@ RageSoundReader_WAV *RageSoundReader_WAV::Copy() const
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+6 -4
View File
@@ -6,6 +6,8 @@
#include "RageSoundReader_FileReader.h"
#include "RageFile.h"
#include <cstdint>
struct WavReader;
RString ReadString( RageFileBasic &f, int iSize, RString &sError );
@@ -28,8 +30,8 @@ public:
struct WavData
{
int32_t m_iDataChunkPos, m_iDataChunkSize, m_iExtraFmtPos, m_iSampleRate, m_iFormatTag;
int16_t m_iChannels, m_iBitsPerSample, m_iBlockAlign, m_iExtraFmtBytes;
std::int32_t m_iDataChunkPos, m_iDataChunkSize, m_iExtraFmtPos, m_iSampleRate, m_iFormatTag;
std::int16_t m_iChannels, m_iBitsPerSample, m_iBlockAlign, m_iExtraFmtBytes;
};
private:
@@ -43,7 +45,7 @@ private:
/*
* (c) 2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -53,7 +55,7 @@ private:
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+3 -2
View File
@@ -3,6 +3,7 @@
#include "RageUtil.h"
#include <cmath>
#include <cstdint>
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 )
{
@@ -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 )
{
+5 -2
View File
@@ -1,5 +1,8 @@
#ifndef RAGE_SOUND_UTIL_H
#define RAGE_SOUND_UTIL_H
#include <cstdint>
/** @brief Simple utilities that operate on sound buffers. */
namespace RageSoundUtil
{
@@ -7,8 +10,8 @@ namespace RageSoundUtil
void Pan( float *pBuffer, int iFrames, float fPos );
void Fade( float *pBuffer, int iFrames, int iChannels, float fStartVolume, float fEndVolume );
void ConvertMonoToStereoInPlace( float *pBuffer, int iFrames );
void ConvertNativeInt16ToFloat( const int16_t *pFrom, float *pTo, int iSamples );
void ConvertFloatToNativeInt16( const float *pFrom, int16_t *pTo, int iSamples );
void ConvertNativeInt16ToFloat( const std::int16_t *pFrom, float *pTo, int iSamples );
void ConvertFloatToNativeInt16( const float *pFrom, std::int16_t *pTo, int iSamples );
};
#endif
+21 -20
View File
@@ -4,9 +4,10 @@
#include <climits>
#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 )
if( colors[i] == color )
@@ -15,7 +16,7 @@ int32_t RageSurfacePalette::FindColor( const RageSurfaceColor &color ) const
}
/* XXX: untested */
int32_t RageSurfacePalette::FindClosestColor( const RageSurfaceColor &color ) const
std::int32_t RageSurfacePalette::FindClosestColor( const RageSurfaceColor &color ) const
{
int iBest = -1;
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 )
{
@@ -69,21 +70,21 @@ void RageSurfaceFormat::GetRGB( uint32_t val, uint8_t *r, uint8_t *g, uint8_t *b
*g = palette->colors[val].g;
*b = palette->colors[val].b;
} else {
*r = int8_t( (val & Mask[0]) >> Shift[0] << Loss[0] );
*g = int8_t( (val & Mask[1]) >> Shift[1] << Loss[1] );
*b = int8_t( (val & Mask[2]) >> Shift[2] << Loss[2] );
*r = std::int8_t( (val & Mask[0]) >> Shift[0] << Loss[0] );
*g = std::int8_t( (val & Mask[1]) >> Shift[1] << Loss[1] );
*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 )
{
RageSurfaceColor c( r, g, b, a );
int32_t n = palette->FindColor( c );
std::int32_t n = palette->FindColor( c );
if( n == -1 )
return false;
val = (uint32_t) n;
val = (std::uint32_t) n;
} else {
val =
(r >> Loss[0] << Shift[0]) |
@@ -136,7 +137,7 @@ RageSurface::RageSurface( const RageSurface &cpy )
pixels_owned = true;
if( cpy.pixels )
{
pixels = new uint8_t[ pitch*h ];
pixels = new std::uint8_t[ pitch*h ];
memcpy( pixels, cpy.pixels, pitch*h );
}
else
@@ -149,7 +150,7 @@ RageSurface::~RageSurface()
delete [] pixels;
}
static int GetShiftFromMask( uint32_t mask )
static int GetShiftFromMask( std::uint32_t mask )
{
if( !mask )
return 0;
@@ -163,7 +164,7 @@ static int GetShiftFromMask( uint32_t mask )
return iShift;
}
static int GetBitsFromMask( uint32_t mask )
static int GetBitsFromMask( std::uint32_t mask )
{
if( !mask )
return 0;
@@ -181,7 +182,7 @@ static int GetBitsFromMask( uint32_t mask )
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.BytesPerPixel = BitsPerPixel/8;
@@ -208,14 +209,14 @@ void SetupFormat( RageSurfaceFormat &fmt,
fmt.Shift[2] = GetShiftFromMask( Bmask );
fmt.Shift[3] = GetShiftFromMask( Amask );
fmt.Loss[0] = (uint8_t) (8-GetBitsFromMask( Rmask ));
fmt.Loss[1] = (uint8_t) (8-GetBitsFromMask( Gmask ));
fmt.Loss[2] = (uint8_t) (8-GetBitsFromMask( Bmask ));
fmt.Loss[3] = (uint8_t) (8-GetBitsFromMask( Amask ));
fmt.Loss[0] = (std::uint8_t) (8-GetBitsFromMask( Rmask ));
fmt.Loss[1] = (std::uint8_t) (8-GetBitsFromMask( Gmask ));
fmt.Loss[2] = (std::uint8_t) (8-GetBitsFromMask( Bmask ));
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;
@@ -225,7 +226,7 @@ RageSurface *CreateSurface( int width, int height, int BitsPerPixel, uint32_t Rm
pImg->h = height;
pImg->flags = 0;
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 )
@@ -237,7 +238,7 @@ RageSurface *CreateSurface( int width, int height, int BitsPerPixel, uint32_t Rm
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;
+24 -23
View File
@@ -4,14 +4,15 @@
#define RAGE_SURFACE_H
#include <array>
#include <cstdint>
#include <memory>
/* 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( 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_) { }
};
@@ -29,14 +30,14 @@ inline bool operator!=(RageSurfaceColor const &lhs, RageSurfaceColor const &rhs)
return !operator==(lhs, rhs);
}
struct RageSurfacePalette
struct RageSurfacePalette
{
RageSurfaceColor colors[256];
int32_t ncolors;
std::int32_t ncolors;
/* Find the exact color; returns -1 if not found. */
int32_t FindColor( const RageSurfaceColor &color ) const;
int32_t FindClosestColor( const RageSurfaceColor &color ) const;
std::int32_t FindColor( const RageSurfaceColor &color ) const;
std::int32_t FindClosestColor( const RageSurfaceColor &color ) const;
};
struct RageSurfaceFormat
@@ -45,25 +46,25 @@ struct RageSurfaceFormat
RageSurfaceFormat( const RageSurfaceFormat &cpy );
~RageSurfaceFormat() = default;
int32_t BytesPerPixel;
int32_t BitsPerPixel;
std::array<uint32_t, 4> Mask;
std::array<uint32_t, 4> Shift;
std::array<uint32_t, 4> Loss;
uint32_t &Rmask, &Gmask, &Bmask, &Amask; /* deprecated */
uint32_t &Rshift, &Gshift, &Bshift, &Ashift; /* deprecated */
std::int32_t BytesPerPixel;
std::int32_t BitsPerPixel;
std::array<std::uint32_t, 4> Mask;
std::array<std::uint32_t, 4> Shift;
std::array<std::uint32_t, 4> Loss;
std::uint32_t &Rmask, &Gmask, &Bmask, &Amask; /* deprecated */
std::uint32_t &Rshift, &Gshift, &Bshift, &Ashift; /* deprecated */
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
* decodepixel() results. If the image is paletted and the color isn't found,
* 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. */
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;
/* Like operator==, but ignores the palette (which is really a part of the
@@ -76,18 +77,18 @@ struct RageSurface
RageSurfaceFormat *format; /* compatibility only */
RageSurfaceFormat fmt;
uint8_t *pixels;
std::uint8_t *pixels;
bool pixels_owned;
int32_t w, h, pitch;
int32_t flags;
std::int32_t w, h, pitch;
std::int32_t flags;
RageSurface();
RageSurface( const RageSurface &cpy );
~RageSurface();
};
RageSurface *CreateSurface( int width, int height, int bpp, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, 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 *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, 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
+92 -91
View File
@@ -7,48 +7,49 @@
#include <cmath>
#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)
{
case 1: return *p;
case 2: return *(uint16_t *)p;
case 2: return *(std::uint16_t *)p;
case 3:
if constexpr ( Endian::big )
return p[0] << 16 | p[1] << 8 | p[2];
else
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
}
}
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)
{
case 1: *p = uint8_t(pixel); break;
case 2: *(uint16_t *)p = uint16_t(pixel); break;
case 1: *p = std::uint8_t(pixel); break;
case 2: *(std::uint16_t *)p = std::uint16_t(pixel); break;
case 3:
if constexpr ( Endian::big )
{
p[0] = uint8_t((pixel >> 16) & 0xff);
p[1] = uint8_t((pixel >> 8) & 0xff);
p[2] = uint8_t(pixel & 0xff);
p[0] = std::uint8_t((pixel >> 16) & 0xff);
p[1] = std::uint8_t((pixel >> 8) & 0xff);
p[2] = std::uint8_t(pixel & 0xff);
} else {
p[0] = uint8_t(pixel & 0xff);
p[1] = uint8_t((pixel >> 8) & 0xff);
p[2] = uint8_t((pixel >> 16) & 0xff);
p[0] = std::uint8_t(pixel & 0xff);
p[1] = std::uint8_t((pixel >> 8) & 0xff);
p[2] = std::uint8_t((pixel >> 16) & 0xff);
}
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.
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 )
{
@@ -57,20 +58,20 @@ void RageSurfaceUtils::GetRawRGBAV( uint32_t pixel, const RageSurfaceFormat &fmt
v[2] = fmt.palette->colors[pixel].b;
v[3] = fmt.palette->colors[pixel].a;
} else {
v[0] = uint8_t((pixel & fmt.Rmask) >> fmt.Rshift);
v[1] = uint8_t((pixel & fmt.Gmask) >> fmt.Gshift);
v[2] = uint8_t((pixel & fmt.Bmask) >> fmt.Bshift);
v[3] = uint8_t((pixel & fmt.Amask) >> fmt.Ashift);
v[0] = std::uint8_t((pixel & fmt.Rmask) >> fmt.Rshift);
v[1] = std::uint8_t((pixel & fmt.Gmask) >> fmt.Gshift);
v[2] = std::uint8_t((pixel & fmt.Bmask) >> fmt.Bshift);
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 );
}
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);
const RageSurfaceFormat *fmt = src->format;
@@ -82,9 +83,9 @@ void RageSurfaceUtils::GetRGBAV( uint32_t pixel, const RageSurface *src, uint8_t
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
{
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.
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 |
v[1] << fmt->Gshift |
@@ -103,14 +104,14 @@ uint32_t RageSurfaceUtils::SetRawRGBAV( const RageSurfaceFormat *fmt, const uint
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);
}
// 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] |
(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];
}
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);
}
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.
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,
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 );
@@ -164,7 +165,7 @@ bool RageSurfaceUtils::ConvertSurface( const RageSurface *src, RageSurface *&dst
void RageSurfaceUtils::ConvertSurface(RageSurface *&image,
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;
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.
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;
@@ -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;
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)
row += img->format->BytesPerPixel * (img->w-1);
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->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
* 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( 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 )
return;
uint32_t trans;
std::uint32_t trans;
pImg->format->MapRGBA( r, g, b, 0, trans );
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 )
{
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) )
{
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 )
return;
uint8_t r, g, b;
std::uint8_t r, g, b;
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 );
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;
int alpha_type = NEEDS_NO_ALPHA;
uint32_t max_alpha;
std::uint32_t max_alpha;
if( img->format->BitsPerPixel == 8 )
{
// 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)
{
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)
{
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 )
alpha = img->format->palette->colors[val].a;
else
@@ -373,10 +374,10 @@ int RageSurfaceUtils::FindSurfaceTraits( const RageSurface *img )
// 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 uint8_t *srcpx = srcp + (x * src->fmt.BytesPerPixel);
const std::uint8_t *srcp = (const std::uint8_t *) src->pixels + (y * src->pitch);
const std::uint8_t *srcpx = srcp + (x * src->fmt.BytesPerPixel);
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 )
{
uint8_t *dstp = (uint8_t *) dst->pixels + (y * dst->pitch); /* line */
uint8_t *dstpx = dstp; // pixel
std::uint8_t *dstp = (std::uint8_t *) dst->pixels + (y * dst->pitch); /* line */
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 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);
// 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[1], src_x[0], src_y[1]);
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);
// 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)
{
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[2][i] * (weight_x) * (1-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( 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);
@@ -486,8 +487,8 @@ static bool blit_same_type( const RageSurface *src_surf, const RageSurface *dst_
src_surf->format->Amask != dst_surf->format->Amask )
return false;
const uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels;
const std::uint8_t *src = src_surf->pixels;
std::uint8_t *dst = dst_surf->pixels;
// If possible, memcpy the whole thing.
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 )
return false;
const uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels;
const std::uint8_t *src = src_surf->pixels;
std::uint8_t *dst = dst_surf->pixels;
// Bytes to skip at the end of a line.
const int srcskip = src_surf->pitch - width*src_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<uint32_t, 4> &dst_shifts = dst_surf->format->Shift;
const std::array<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> &src_shifts = src_surf->format->Shift;
const std::array<std::uint32_t, 4> &dst_shifts = dst_surf->format->Shift;
const std::array<std::uint32_t, 4> &src_masks = src_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 )
{
const 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_src_val = src_masks[c] >> src_shifts[c];
const std::uint32_t max_dst_val = dst_masks[c] >> dst_shifts[c];
ASSERT( max_src_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
* channels default to 0. */
if( c == 3 )
lookup[c][0] = (uint8_t) max_dst_val;
lookup[c][0] = (std::uint8_t) max_dst_val;
else
lookup[c][0] = 0;
} 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
* strange; what's wrong here? */
if( max_src_val > max_dst_val )
for( 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 );
for( std::uint32_t i = 0; i <= max_src_val; ++i )
lookup[c][i] = (std::uint8_t) SCALE( i, 0, max_src_val+1, 0, max_dst_val+1 );
else
for( uint32_t i = 0; i <= max_src_val; ++i )
lookup[c][i] = (uint8_t) SCALE( i, 0, max_src_val, 0, max_dst_val );
for( std::uint32_t i = 0; i <= max_src_val; ++i )
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 )
return false;
const uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels;
const std::uint8_t *src = src_surf->pixels;
std::uint8_t *dst = dst_surf->pixels;
// Bytes to skip at the end of a line.
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 );
uint8_t colors[4];
std::uint8_t colors[4];
// Convert pixel to the destination RGBA.
colors[0] = src_surf->format->palette->colors[pixel].r;
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.
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 )
{
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 );
p += img->pitch;
@@ -726,7 +727,7 @@ void RageSurfaceUtils::CorrectBorderPixels( RageSurface *img, int width, int hei
if( height < img->h )
{
// Duplicate the last row.
uint8_t *srcp = img->pixels;
std::uint8_t *srcp = img->pixels;
srcp += img->pitch * (height-1);
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;
// 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
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;
c.r = ScaledI;
@@ -878,8 +879,8 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf
dst_surf->fmt.palette->colors[index] = c;
}
const uint8_t *src = src_surf->pixels;
uint8_t *dst = dst_surf->pixels;
const std::uint8_t *src = src_surf->pixels;
std::uint8_t *dst = dst_surf->pixels;
int height = src_surf->h;
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 );
uint8_t colors[4];
std::uint8_t colors[4];
GetRGBAV(pixel, src_surf, colors);
int Ival = 0;
@@ -908,7 +909,7 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf
(colors[3] >> Aloss) << Ashift;
// Store it.
*dst = uint8_t(pixel);
*dst = std::uint8_t(pixel);
src += src_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. */
static bool ImageUsesOffHotPink( const RageSurface *img )
{
uint32_t OffHotPink;
std::uint32_t OffHotPink;
if( !img->format->MapRGBA( 0xF8, 0, 0xF8, 0xFF, OffHotPink ) )
return false;
const uint8_t *p = img->pixels;
const std::uint8_t *p = img->pixels;
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 )
return true;
p += img->format->BytesPerPixel;
@@ -955,7 +956,7 @@ static bool ImageUsesOffHotPink( const RageSurface *img )
p += img->pitch * (img->h-1);
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 )
return true;
p += img->format->BytesPerPixel;
@@ -969,7 +970,7 @@ void RageSurfaceUtils::ApplyHotPinkColorKey( RageSurface *&img )
{
if( img->format->BitsPerPixel == 8 )
{
uint32_t color;
std::uint32_t color;
if( img->format->MapRGBA( 0xF8, 0, 0xF8, 0xFF, color ) )
img->format->palette->colors[ color ].a = 0;
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->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 );
}
uint32_t HotPink;
std::uint32_t HotPink;
bool bHaveColorKey;
if( ImageUsesOffHotPink(img) )
@@ -1013,11 +1014,11 @@ void RageSurfaceUtils::ApplyHotPinkColorKey( RageSurface *&img )
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 )
{
uint32_t val = decodepixel( row, img->format->BytesPerPixel );
std::uint32_t val = decodepixel( row, img->format->BytesPerPixel );
if( val == HotPink )
encodepixel( row, img->format->BytesPerPixel, 0 );
+16 -14
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_SURFACE_UTILS_H
#define RAGE_SURFACE_UTILS_H
#include <cstdint>
struct RageSurfaceColor;
struct RageSurfacePalette;
struct RageSurfaceFormat;
@@ -11,27 +13,27 @@ struct RageSurface;
/** @brief Utility functions for the RageSurfaces. */
namespace RageSurfaceUtils
{
uint32_t decodepixel( const uint8_t *p, int bpp );
void encodepixel( uint8_t *p, int bpp, uint32_t pixel );
std::uint32_t decodepixel( const std::uint8_t *p, int bpp );
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( const uint8_t *p, const RageSurfaceFormat &fmt, uint8_t *v );
void GetRGBAV( uint32_t pixel, const RageSurface *src, uint8_t *v );
void GetRGBAV( const uint8_t *p, const RageSurface *src, uint8_t *v );
void GetRawRGBAV( std::uint32_t pixel, const RageSurfaceFormat &fmt, std::uint8_t *v );
void GetRawRGBAV( const std::uint8_t *p, const RageSurfaceFormat &fmt, std::uint8_t *v );
void GetRGBAV( std::uint32_t pixel, const RageSurface *src, std::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 );
void SetRawRGBAV( uint8_t *p, const RageSurface *src, const uint8_t *v );
uint32_t SetRGBAV( const RageSurfaceFormat *fmt, const uint8_t *v );
void SetRGBAV( uint8_t *p, const RageSurface *src, const uint8_t *v );
std::uint32_t SetRawRGBAV( const RageSurfaceFormat *fmt, const std::uint8_t *v );
void SetRawRGBAV( std::uint8_t *p, const RageSurface *src, const std::uint8_t *v );
std::uint32_t SetRGBAV( const RageSurfaceFormat *fmt, const std::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. */
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 );
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,
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 );
@@ -45,7 +47,7 @@ namespace RageSurfaceUtils
* It only needs one bit of alpha. */
enum { TRAIT_BOOL_TRANSPARENCY = 0x0002 }; /* 1alpha */
void BlitTransform( const RageSurface *src, RageSurface *dst,
void BlitTransform( const RageSurface *src, RageSurface *dst,
const float fCoords[8] /* TL, BR, BL, TR */ );
void Blit( const RageSurface *src, RageSurface *dst, int width = -1, int height = -1 );
+24 -22
View File
@@ -4,6 +4,8 @@
#include "RageSurface.h"
#include "RageSurfaceUtils.h"
#include <cstdint>
#define DitherMatDim 4
// Fractions, 0/16 to 15/16:
@@ -18,7 +20,7 @@ static const int DitherMat[DitherMatDim][DitherMatDim] =
static int DitherMatCalc[DitherMatDim][DitherMatDim];
// 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.
x &= DitherMatDim-1;
@@ -41,7 +43,7 @@ static uint8_t DitherPixel(int x, int y, int intensity, int conv)
out_intensity += DitherMatCalc[y][x];
// 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 )
@@ -59,14 +61,14 @@ void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst )
DitherMatCalc[i][j] = DitherMat[i][j] * 65536 / 16;
}
}
DitherMatCalc_initted = true;
}
// We can't dither to paletted surfaces.
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( 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.
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( int row = 0; row < src->h; ++row )
{
const uint8_t *srcp = src->pixels + row * src->pitch;
uint8_t *dstp = dst->pixels + row * dst->pitch;
const std::uint8_t *srcp = src->pixels + row * src->pitch;
std::uint8_t *dstp = dst->pixels + row * dst->pitch;
// For each pixel:
for( int col = 0; col < src->w; ++col )
{
uint8_t colors[4];
std::uint8_t colors[4];
RageSurfaceUtils::GetRawRGBAV( srcp, src->fmt, colors );
// Note that we don't dither the alpha channel.
@@ -115,9 +117,9 @@ void RageSurfaceUtils::OrderedDither( const RageSurface *src, RageSurface *dst )
/* Same as DitherPixel, except it doesn't actually dither;
* dithering looks bad on the alpha channel. */
int out_intensity = colors[3] * conv[3];
// Round:
colors[3] = uint8_t((out_intensity + 32767) >> 16);
colors[3] = std::uint8_t((out_intensity + 32767) >> 16);
}
// 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.
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;
// Truncate.
uint8_t ret = uint8_t(clamped_intensity >> 16);
std::uint8_t ret = std::uint8_t(clamped_intensity >> 16);
accumError = out_intensity - clamped_intensity;
@@ -170,7 +172,7 @@ void RageSurfaceUtils::ErrorDiffusionDither( const RageSurface *src, RageSurface
// We can't dither to paletted surfaces.
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( 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.
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(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;
uint8_t *dstp = dst->pixels + row * dst->pitch;
const std::uint8_t *srcp = src->pixels + row * src->pitch;
std::uint8_t *dstp = dst->pixels + row * dst->pitch;
// For each pixel in row:
for( int col = 0; col < src->w; ++col )
{
uint8_t colors[4];
std::uint8_t colors[4];
RageSurfaceUtils::GetRawRGBAV( srcp, src->fmt, colors );
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];
// Round:
colors[3] = uint8_t((out_intensity + 32767) >> 16);
colors[3] = std::uint8_t((out_intensity + 32767) >> 16);
}
RageSurfaceUtils::SetRawRGBAV( dstp, dst, colors );
@@ -235,7 +237,7 @@ void RageSurfaceUtils::ErrorDiffusionDither( const RageSurface *src, RageSurface
/*
* (c) 2002-2004 Glenn Maynard, Chris Danford
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -245,7 +247,7 @@ void RageSurfaceUtils::ErrorDiffusionDither( const RageSurface *src, RageSurface
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+19 -17
View File
@@ -6,8 +6,10 @@
#include "RageSurfaceUtils.h"
#include "RageUtil.h"
typedef uint8_t pixval;
typedef uint8_t apixel[4];
#include <cstdint>
typedef std::uint8_t pixval;
typedef std::uint8_t apixel[4];
#define PAM_GETR(p) ((p)[0])
#define PAM_GETG(p) ((p)[1])
@@ -18,7 +20,7 @@ typedef uint8_t apixel[4];
#define PAM_EQUAL(p,q) \
((p)[0] == (q)[0] && (p)[1] == (q)[1] && (p)[2] == (q)[2] && (p)[3] == (q)[3])
#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
{
@@ -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 void pam_addtoacolorhash( acolorhash_hash &acht, const uint8_t acolorP[4], int value );
static int pam_lookupacolor( const acolorhash_hash &acht, const uint8_t acolorP[4] );
static void pam_addtoacolorhash( acolorhash_hash &acht, const std::uint8_t acolorP[4], int value );
static int pam_lookupacolor( const acolorhash_hash &acht, const std::uint8_t acolorP[4] );
static void pam_freeacolorhist( acolorhist_item *achv );
struct pixerror_t
@@ -132,7 +134,7 @@ void RageSurfaceUtils::Palettize( RageSurface *&pImg, int iColors, bool bDither
int table[256];
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 )
{
@@ -201,25 +203,25 @@ void RageSurfaceUtils::Palettize( RageSurface *&pImg, int iColors, bool bDither
limitcol = -1;
}
const uint8_t *pIn = pImg->pixels + row*pImg->pitch;
uint8_t *pOut = pRet->pixels + row*pRet->pitch;
const std::uint8_t *pIn = pImg->pixels + row*pImg->pitch;
std::uint8_t *pOut = pRet->pixels + row*pRet->pitch;
pIn += col * 4;
pOut += col;
do
{
int32_t sc[4];
uint8_t pixel[4] = { pIn[0], pIn[1], pIn[2], pIn[3] };
std::int32_t sc[4];
std::uint8_t pixel[4] = { pIn[0], pIn[1], pIn[2], pIn[3] };
if( bDither )
{
// Use Floyd-Steinberg errors to adjust actual color.
for( int c = 0; c < 4; ++c )
{
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.
@@ -238,7 +240,7 @@ void RageSurfaceUtils::Palettize( RageSurface *&pImg, int iColors, bool bDither
long dist = 2000000000;
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;
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 )
{
@@ -478,7 +480,7 @@ static acolorhist_item *mediancut( acolorhist_item *achv, int colors, int sum, i
b = std::min( b, (long) maxval );
a = a / lSum;
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
}
@@ -577,7 +579,7 @@ static acolorhist_item *pam_computeacolorhist( const RageSurface *src, int maxac
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) );
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 );
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 <cmath>
#include <cstdint>
#include <vector>
/* 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
* 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 )
{
@@ -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
* pixels; find the percentage: */
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) );
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
* and the percentage of the first row and first column: */
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( esy0, esy1, ey0, src->h, dst->h );
// 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 width = dst->w;
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
* rows sampled for this row): */
const uint8_t *csp = sp + esy0[y] * src->pitch;
const uint8_t *ncsp = sp + esy1[y] * src->pitch;
const std::uint8_t *csp = sp + esy0[y] * src->pitch;
const std::uint8_t *ncsp = sp + esy1[y] * src->pitch;
for( int x = 0; x < width; x++ )
{
// Grab pointers to the sampled pixels:
const uint8_t *c00 = csp + esx0[x]*4;
const uint8_t *c01 = csp + esx1[x]*4;
const uint8_t *c10 = ncsp + esx0[x]*4;
const uint8_t *c11 = ncsp + esx1[x]*4;
const std::uint8_t *c00 = csp + esx0[x]*4;
const std::uint8_t *c01 = csp + esx1[x]*4;
const std::uint8_t *c10 = ncsp + esx0[x]*4;
const std::uint8_t *c11 = ncsp + esx1[x]*4;
for( int c = 0; c < 4; ++c )
{
uint32_t x0 = uint32_t(c00[c]) * ex0[x];
x0 += uint32_t(c01[c]) * (16777216 - ex0[x]);
std::uint32_t x0 = std::uint32_t(c00[c]) * ex0[x];
x0 += std::uint32_t(c01[c]) * (16777216 - ex0[x]);
x0 >>= 24;
uint32_t x1 = uint32_t(c10[c]) * ex0[x];
x1 += uint32_t(c11[c]) * (16777216 - ex0[x]);
std::uint32_t x1 = std::uint32_t(c10[c]) * ex0[x];
x1 += std::uint32_t(c11[c]) * (16777216 - ex0[x]);
x1 >>= 24;
const uint32_t res = ((x0 * ey0[y]) + (x1 * (16777216-ey0[y])) + 8388608) >> 24;
dp[c] = uint8_t(res);
const std::uint32_t res = ((x0 * ey0[y]) + (x1 * (16777216-ey0[y])) + 8388608) >> 24;
dp[c] = std::uint8_t(res);
}
// Advance destination pointer.
+7 -4
View File
@@ -4,6 +4,9 @@
#include "RageUtil.h"
#include "RageLog.h"
#include "RageSurface.h"
#include <cstdint>
using namespace FileReading;
/* 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 ); /* unused */
uint32_t iDataOffset = read_u32_le( f, sError );
uint32_t iHeaderSize = read_u32_le( f, sError );
std::uint32_t iDataOffset = 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 )
{
/* 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 )
{
uint8_t *pRow = img->pixels + img->pitch*y;
std::uint8_t *pRow = img->pixels + img->pitch*y;
RString buf;
f.Read( buf, iFilePitch );
+2 -1
View File
@@ -6,6 +6,7 @@
#include "RageSurface.h"
#include <cstddef>
#include <cstdint>
#include <setjmp.h>
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 )
{
RageSurfaceColor color;
color.r = color.g = color.b = (int8_t) i;
color.r = color.g = color.b = (std::int8_t) i;
color.a = 0xFF;
img->fmt.palette->colors[i] = color;
}
+5 -3
View File
@@ -1,13 +1,15 @@
#include "global.h"
#include <png.h>
#include "RageSurface_Load_PNG.h"
#include "RageUtil.h"
#include "RageLog.h"
#include "RageFile.h"
#include "RageSurface.h"
#include <cstdint>
#include <png.h>
#if defined(_MSC_VER)
#if defined(_BINARY_PNG)
#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. */
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;
}
+8 -6
View File
@@ -6,6 +6,8 @@
#include "RageUtil.h"
#include "RageLog.h"
#include "RageSurface.h"
#include <cstdint>
#include <map>
#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 )
continue;
RageSurfaceColor colorval;
colorval.r = (uint8_t) r;
colorval.g = (uint8_t) g;
colorval.b = (uint8_t) b;
colorval.r = (std::uint8_t) r;
colorval.g = (std::uint8_t) g;
colorval.b = (std::uint8_t) b;
colorval.a = 0xFF;
colors.push_back( colorval );
@@ -88,9 +90,9 @@ RageSurface *RageSurface_Load_XPM( char * const *xpm, RString &error )
return nullptr;
}
int8_t *p = (int8_t *) img->pixels;
std::int8_t *p = (std::int8_t *) img->pixels;
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 )
{
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 )
{
p[x] = (int8_t) it->second;
p[x] = (std::int8_t) it->second;
} else {
const RageSurfaceColor &color = colors[it->second];
p32[x] = (color.r << 24) + (color.g << 16) + (color.b << 8);
+11 -9
View File
@@ -5,6 +5,8 @@
#include "RageUtil.h"
#include "RageFile.h"
#include <cstdint>
static void WriteBytes( RageFile &f, RString &sError, const void *buf, int size )
{
if( sError.size() != 0 )
@@ -15,16 +17,16 @@ static void WriteBytes( RageFile &f, RString &sError, const void *buf, int size
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 );
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 );
WriteBytes( f, sError, &val, sizeof(uint32_t) );
WriteBytes( f, sError, &val, sizeof(std::uint32_t) );
}
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->h ); // height (offset 0x18)
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, iDataSize ); // bitmap size (offset 0x22)
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 )
{
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 );
/* 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 );
}
@@ -83,7 +85,7 @@ bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f )
/*
* (c) 2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -93,7 +95,7 @@ bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+2 -1
View File
@@ -7,6 +7,7 @@
#include "RageFile.h"
#include <cstddef>
#include <cstdint>
#undef FAR // fix for VC
/** @brief A helper to get the jpeg lib. */
@@ -24,7 +25,7 @@ typedef struct
struct jpeg::jpeg_destination_mgr pub;
RageFile *f;
uint8_t buffer[OUTPUT_BUFFER_SIZE];
std::uint8_t buffer[OUTPUT_BUFFER_SIZE];
} my_destination_mgr;
+3 -1
View File
@@ -6,6 +6,8 @@
#include "RageTypes.h"
#include "RageTextureID.h"
#include <cstdint>
struct lua_State;
class RageTexture
{
@@ -15,7 +17,7 @@ public:
virtual void Update( float /* fDeltaTime */ ) {}
virtual void Reload() {}
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
virtual void SetPosition( float /* fSeconds */ ) {} // seek
+8 -7
View File
@@ -17,7 +17,7 @@
* If a texture is loaded as DEFAULT that was already loaded as VOLATILE, DEFAULT
* overrides.
*/
#include "global.h"
#include "RageTextureManager.h"
#include "RageBitmapTexture.h"
@@ -27,6 +27,7 @@
#include "RageDisplay.h"
#include "ActorUtil.h"
#include <cstdint>
#include <map>
RageTextureManager* TEXTUREMAN = nullptr; // global and accessible from anywhere in our program
@@ -132,10 +133,10 @@ public:
m_iImageWidth = m_iImageHeight = 1;
CreateFrameRects();
}
uintptr_t GetTexHandle() const { return m_uTexHandle; }
std::uintptr_t GetTexHandle() const { return m_uTexHandle; }
private:
uintptr_t m_uTexHandle;
std::uintptr_t m_uTexHandle;
};
// Load and unload textures from disk.
@@ -224,7 +225,7 @@ void RageTextureManager::UnloadTexture( RageTexture *t )
/* Delete volatile textures after they've been used at least once. */
if( t->GetPolicy() == RageTextureID::TEX_VOLATILE && t->m_bWasUsed )
bDeleteThis = true;
if( bDeleteThis )
DeleteTexture( t );
}
@@ -281,7 +282,7 @@ void RageTextureManager::GarbageCollect( GCType type )
RageTextureID::TexPolicy policy = t->GetPolicy();
switch( policy )
{
case RageTextureID::TEX_DEFAULT:
case RageTextureID::TEX_DEFAULT:
/* If m_bDelayedDelete, wait until delayed_delete. If !m_bDelayedDelete,
* it should have been deleted when it reached no references, but we
* might have just changed the preference. */
@@ -299,7 +300,7 @@ void RageTextureManager::GarbageCollect( GCType type )
/* This happens when we change themes; free all textures. */
if( type==delayed_delete )
bDeleteThis = true;
if( bDeleteThis )
DeleteTexture( t );
}
@@ -344,7 +345,7 @@ bool RageTextureManager::SetPrefs( RageTextureManagerPrefs prefs )
bNeedReload = true;
m_Prefs = prefs;
ASSERT( m_Prefs.m_iTextureColorDepth==16 || m_Prefs.m_iTextureColorDepth==32 );
ASSERT( m_Prefs.m_iMovieColorDepth==16 || m_Prefs.m_iMovieColorDepth==32 );
return bNeedReload;
+5 -3
View File
@@ -7,6 +7,8 @@
#include "RageTextureID.h"
#include "RageDisplay.h" // for RenderTargetParam
#include <cstdint>
class RageTextureRenderTarget: public RageTexture
{
public:
@@ -14,7 +16,7 @@ public:
virtual ~RageTextureRenderTarget();
virtual void Invalidate() { m_iTexHandle = 0; /* don't Destroy() */ }
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 FinishRenderingTo();
@@ -26,8 +28,8 @@ private:
void Create();
void Destroy();
uintptr_t m_iTexHandle;
uintptr_t m_iPreviousRenderTarget;
std::uintptr_t m_iTexHandle;
std::uintptr_t m_iPreviousRenderTarget;
};
#endif
+29 -28
View File
@@ -1,5 +1,5 @@
/*
* If you're going to use threads, remember this:
* If you're going to use threads, remember this:
*
* Threads suck.
*
@@ -17,6 +17,7 @@
#include "RageUtil.h"
#include <cerrno>
#include <cstdint>
#include <set>
#include "arch/Threads/Threads.h"
@@ -45,7 +46,7 @@ struct ThreadSlot
char m_szThreadFormattedOutput[1024];
bool m_bUsed;
uint64_t m_iID;
std::uint64_t m_iID;
ThreadImpl *m_pImpl;
@@ -153,7 +154,7 @@ static int FindEmptyThreadSlot()
g_ThreadSlots[entry].m_bUsed = true;
return entry;
}
RageException::Throw( "Out of thread slots!" );
}
@@ -183,7 +184,7 @@ static void InitThreads()
}
static ThreadSlot *GetThreadSlotFromID( uint64_t iID )
static ThreadSlot *GetThreadSlotFromID( std::uint64_t iID )
{
InitThreads();
@@ -210,7 +211,7 @@ static ThreadSlot *GetUnknownThreadSlot()
RageThread::RageThread(): m_pSlot(nullptr), m_sName("unnamed") {}
/* Copying a thread does not start the copy. */
RageThread::RageThread( const RageThread &cpy ):
RageThread::RageThread( const RageThread &cpy ):
m_pSlot(nullptr), m_sName(cpy.m_sName) {}
RageThread::~RageThread()
@@ -240,7 +241,7 @@ void RageThread::Create( int (*fn)(void *), void *data )
int slotno = FindEmptyThreadSlot();
m_pSlot = &g_ThreadSlots[slotno];
strcpy( m_pSlot->m_szName, m_sName.c_str() );
if( LOG )
@@ -257,11 +258,11 @@ RageThreadRegister::RageThreadRegister( const RString &sName )
{
InitThreads();
LockMut( GetThreadSlotsLock() );
int iSlot = FindEmptyThreadSlot();
m_pSlot = &g_ThreadSlots[iSlot];
strcpy( m_pSlot->m_szName, sName );
sprintf( m_pSlot->m_szThreadFormattedOutput, "Thread: %s", sName.c_str() );
@@ -283,7 +284,7 @@ const char *RageThread::GetCurrentThreadName()
return GetThreadNameByID( GetCurrentThreadID() );
}
const char *RageThread::GetThreadNameByID( uint64_t iID )
const char *RageThread::GetThreadNameByID( std::uint64_t iID )
{
ThreadSlot *slot = GetThreadSlotFromID( iID );
if( slot == nullptr )
@@ -292,7 +293,7 @@ const char *RageThread::GetThreadNameByID( uint64_t iID )
return slot->GetThreadName();
}
bool RageThread::EnumThreadIDs( int n, uint64_t &iID )
bool RageThread::EnumThreadIDs( int n, std::uint64_t &iID )
{
if( n >= MAX_THREADS )
return false;
@@ -336,7 +337,7 @@ void RageThread::Resume() {
void RageThread::HaltAllThreads( bool Kill )
{
const uint64_t ThisThreadID = GetThisThreadId();
const std::uint64_t ThisThreadID = GetThisThreadId();
for( int entry = 0; entry < MAX_THREADS; ++entry )
{
if( !g_ThreadSlots[entry].m_bUsed )
@@ -349,7 +350,7 @@ void RageThread::HaltAllThreads( bool Kill )
void RageThread::ResumeAllThreads()
{
const uint64_t ThisThreadID = GetThisThreadId();
const std::uint64_t ThisThreadID = GetThisThreadId();
for( int entry = 0; entry < MAX_THREADS; ++entry )
{
if( !g_ThreadSlots[entry].m_bUsed )
@@ -361,11 +362,11 @@ void RageThread::ResumeAllThreads()
}
}
uint64_t RageThread::GetCurrentThreadID()
std::uint64_t RageThread::GetCurrentThreadID()
{
return GetThisThreadId();
}
uint64_t RageThread::GetInvalidThreadID()
std::uint64_t RageThread::GetInvalidThreadID()
{
return GetInvalidThreadId();
}
@@ -386,7 +387,7 @@ void Checkpoints::SetCheckpoint( const char *file, int line, const char *message
/* We can't ASSERT here, since that uses checkpoints. */
if( slot == nullptr )
sm_crash( "GetUnknownThreadSlot() returned nullptr" );
/* Ignore everything up to and including the first "src/". */
const char *temp = strstr( file, "src/" );
if( temp )
@@ -431,18 +432,18 @@ void Checkpoints::GetLogs( char *pBuf, int iSize, const char *delim )
continue;
strcat( pBuf, buf );
strcat( pBuf, delim );
for( int line = 1; (buf = GetCheckpointLog(slotno, line)) != nullptr; ++line )
{
strcat( pBuf, buf );
strcat( pBuf, delim );
}
}
}
}
/*
* "Safe" mutexes: locking the same mutex more than once from the same thread
* is refcounted and does not deadlock.
* is refcounted and does not deadlock.
*
* Only actually lock the mutex once; when we do so, remember which thread locked it.
* Then, when we lock in the future, only increment a counter, with no locks.
@@ -458,7 +459,7 @@ void Checkpoints::GetLogs( char *pBuf, int iSize, const char *delim )
#if 0
static const int MAX_MUTEXES = 256;
/* g_MutexesBefore[n] is a list of mutex IDs which must be locked before n (if at all).
/* g_MutexesBefore[n] is a list of mutex IDs which must be locked before n (if at all).
* The array g_MutexesBefore[n] is locked for writing by locking mutex n, so lock that
* mutex *before* calling MarkLockedMutex(). */
bool g_MutexesBefore[MAX_MUTEXES][MAX_MUTEXES];
@@ -480,7 +481,7 @@ void RageMutex::MarkLockedMutex()
for( unsigned i = 0; i < g_MutexList->size(); ++i )
{
const RageMutex *mutex = (*g_MutexList)[i];
if( mutex->m_UniqueID == this->m_UniqueID )
continue;
@@ -493,20 +494,20 @@ void RageMutex::MarkLockedMutex()
{
LOG->Warn( "Mutex lock inconsistency: mutex \"%s\" must be locked before \"%s\"",
this->GetName().c_str(), mutex->GetName().c_str() );
break;
}
/* Optimization: don't add it to the queue if it's already been done. */
if( !g_MutexesBefore[this->m_UniqueID][mutex->m_UniqueID] )
before.push_back( mutex );
}
while( before.size() )
{
const RageMutex *mutex = before.back();
before.pop_back();
g_MutexesBefore[this->m_UniqueID][mutex->m_UniqueID] = 1;
/* All IDs which must be locked before mutex must also be locked before
@@ -525,7 +526,7 @@ static std::set<int> *g_FreeMutexIDs = nullptr;
#endif
RageMutex::RageMutex( const RString &name ):
m_pMutex( MakeMutex (this ) ), m_sName(name),
m_pMutex( MakeMutex (this ) ), m_sName(name),
m_LockedBy(GetInvalidThreadId()), m_LockCnt(0)
{
@@ -582,7 +583,7 @@ RageMutex::~RageMutex()
void RageMutex::Lock()
{
uint64_t iThisThreadId = GetThisThreadId();
std::uint64_t iThisThreadId = GetThisThreadId();
if( m_LockedBy == iThisThreadId )
{
++m_LockCnt;
@@ -606,7 +607,7 @@ void RageMutex::Lock()
#if defined(CRASH_HANDLER)
/* Don't leave GetThreadSlotsLock() locked when we call ForceCrashHandlerDeadlock. */
GetThreadSlotsLock().Lock();
uint64_t CrashHandle = OtherSlot? OtherSlot->m_iID:0;
std::uint64_t CrashHandle = OtherSlot? OtherSlot->m_iID:0;
GetThreadSlotsLock().Unlock();
/* Pass the crash handle of the other thread, so it can backtrace that thread. */
+13 -11
View File
@@ -1,6 +1,8 @@
#ifndef RAGE_THREADS_H
#define RAGE_THREADS_H
#include <cstdint>
struct ThreadSlot;
class RageTimer;
/** @brief Thread, mutex, semaphore, and event classes. */
@@ -19,17 +21,17 @@ public:
void Resume();
/* For crash handlers: kill or suspend all threads (except for
* the running one) immediately. */
* the running one) immediately. */
static void HaltAllThreads( bool Kill=false );
/* If HaltAllThreads was called (with Kill==false), resume. */
static void ResumeAllThreads();
static uint64_t GetCurrentThreadID();
static std::uint64_t GetCurrentThreadID();
static const char *GetCurrentThreadName();
static const char *GetThreadNameByID( uint64_t iID );
static bool EnumThreadIDs( int n, uint64_t &iID );
static const char *GetThreadNameByID( std::uint64_t iID );
static bool EnumThreadIDs( int n, std::uint64_t &iID );
int Wait();
bool IsCreated() const { return m_pSlot != nullptr; }
@@ -41,7 +43,7 @@ public:
static bool GetIsShowingDialog() { return s_bIsShowingDialog; }
static void SetIsShowingDialog( bool b ) { s_bIsShowingDialog = b; }
static uint64_t GetInvalidThreadID();
static std::uint64_t GetInvalidThreadID();
private:
ThreadSlot *m_pSlot;
@@ -49,14 +51,14 @@ private:
static bool s_bSystemSupportsTLS;
static bool s_bIsShowingDialog;
// Swallow up warnings. If they must be used, define them.
RageThread& operator=(const RageThread& rhs);
};
/**
* @brief Register a thread created outside of RageThread.
*
*
* This gives it a name for RageThread::GetCurrentThreadName,
* and allocates a slot for checkpoints. */
class RageThreadRegister
@@ -105,8 +107,8 @@ protected:
RString m_sName;
int m_UniqueID;
uint64_t m_LockedBy;
std::uint64_t m_LockedBy;
int m_LockCnt;
void MarkLockedMutex();
@@ -156,7 +158,7 @@ public:
/*
* If pTimeout is non-nullptr, the event will be automatically signalled at the given
* time. Note that implementing this timeout is optional; not all archs support it.
* time. Note that implementing this timeout is optional; not all archs support it.
* If false is returned, the wait timed out (and the mutex is locked, as if the
* event had been signalled).
*/
@@ -188,7 +190,7 @@ public:
private:
SemaImpl *m_pSema;
RString m_sName;
// Swallow up warnings. If they must be used, define them.
RageSemaphore& operator=(const RageSemaphore& rhs);
RageSemaphore(const RageSemaphore& rhs);
+8 -7
View File
@@ -28,13 +28,14 @@
#include "arch/ArchHooks/ArchHooks.h"
#include <cmath>
#include <cstdint>
#define TIMESTAMP_RESOLUTION 1000000
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 );
@@ -43,7 +44,7 @@ static uint64_t GetTime( bool /* bAccurate */ )
#if 0
// if !bAccurate, then don't call ArchHooks to find the current time. Just return the
// last calculated time. GetMicrosecondsSinceStart is slow on some archs.
static uint64_t usecs = 0;
static std::uint64_t usecs = 0;
if( bAccurate )
usecs = ArchHooks::GetMicrosecondsSinceStart( true );
return usecs;
@@ -52,22 +53,22 @@ static uint64_t GetTime( bool /* bAccurate */ )
float RageTimer::GetTimeSinceStart( bool bAccurate )
{
uint64_t usecs = GetTime( bAccurate );
std::uint64_t usecs = GetTime( bAccurate );
usecs -= g_iStartTime;
/* Avoid using doubles for hardware that doesn't support them.
* This is writing usecs = high*2^32 + low and doing
* 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;
}
void RageTimer::Touch()
{
uint64_t usecs = GetTime( true );
std::uint64_t usecs = GetTime( true );
this->m_secs = unsigned(usecs / 1000000);
this->m_us = unsigned(usecs % 1000000);
+12 -10
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_TIMER_H
#define RAGE_TIMER_H
#include <cstdint>
class RageTimer
{
public:
@@ -23,7 +25,7 @@ public:
/* deprecated: */
static float GetTimeSinceStart( bool bAccurate = true ); // seconds since the program was started
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. */
RageTimer Half() const;
@@ -53,20 +55,20 @@ private:
extern const RageTimer RageZeroTimer;
// 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 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_ADD_TO(name) uint64_t name##_end_time= RageTimer::GetUsecsSinceStart(); name##_total += 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) 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 DECL_TOTAL_TIME(name) extern uint64_t name##_total;
#define DEF_TOTAL_TIME(name) uint64_t name##_total= 0;
#define DECL_TOTAL_TIME(name) extern std::uint64_t name##_total;
#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 DECL_TOT_CALL_PAIR(name) extern uint64_t name##_total; extern uint64_t name##_call_count;
#define DEF_TOT_CALL_PAIR(name) uint64_t name##_total= 0; uint64_t name##_call_count= 0;
#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) 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 DECL_TOT_CALL_END(name) DECL_TOT_CALL_PAIR(name); extern uint64_t name##_end_count;
#define DEF_TOT_CALL_END(name) DEF_TOT_CALL_PAIR(name); uint64_t name##_end_count= 0;
#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); 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));
#endif
+33 -32
View File
@@ -3,10 +3,11 @@
#ifndef RAGETYPES_H
#define RAGETYPES_H
#include <array>
#include "EnumHelper.h"
#include <array>
#include <cstdint>
enum BlendMode
{
BLEND_NORMAL,
@@ -106,25 +107,25 @@ public:
RageVector2(): x(0), y(0) {}
RageVector2( const float * f ): x(f[0]), y(f[1]) {}
RageVector2( float x1, float y1 ): x(x1), y(y1) {}
// casting
operator float* () { return &x; };
operator const float* () const { return &x; };
// assignment operators
RageVector2& operator += ( const RageVector2& other ) { x+=other.x; y+=other.y; return *this; }
RageVector2& operator -= ( const RageVector2& other ) { x-=other.x; y-=other.y; return *this; }
RageVector2& operator *= ( float f ) { x*=f; y*=f; return *this; }
RageVector2& operator /= ( float f ) { x/=f; y/=f; return *this; }
// binary operators
RageVector2 operator + ( const RageVector2& other ) const { return RageVector2( x+other.x, y+other.y ); }
RageVector2 operator - ( const RageVector2& other ) const { return RageVector2( x-other.x, y-other.y ); }
RageVector2 operator * ( float f ) const { return RageVector2( x*f, y*f ); }
RageVector2 operator / ( float f ) const { return RageVector2( x/f, y/f ); }
friend RageVector2 operator * ( float f, const RageVector2& other ) { return other*f; }
float x, y;
};
@@ -135,25 +136,25 @@ public:
RageVector3(): x(0), y(0), z(0) {}
RageVector3( const float * f ): x(f[0]), y(f[1]), z(f[2]) {}
RageVector3( float x1, float y1, float z1 ): x(x1), y(y1), z(z1) {}
// casting
operator float* () { return &x; };
operator const float* () const { return &x; };
// assignment operators
RageVector3& operator += ( const RageVector3& other ) { x+=other.x; y+=other.y; z+=other.z; return *this; }
RageVector3& operator -= ( const RageVector3& other ) { x-=other.x; y-=other.y; z-=other.z; return *this; }
RageVector3& operator *= ( float f ) { x*=f; y*=f; z*=f; return *this; }
RageVector3& operator /= ( float f ) { x/=f; y/=f; z/=f; return *this; }
// binary operators
RageVector3 operator + ( const RageVector3& other ) const { return RageVector3( x+other.x, y+other.y, z+other.z ); }
RageVector3 operator - ( const RageVector3& other ) const { return RageVector3( x-other.x, y-other.y, z-other.z ); }
RageVector3 operator * ( float f ) const { return RageVector3( x*f, y*f, z*f ); }
RageVector3 operator / ( float f ) const { return RageVector3( x/f, y/f, z/f ); }
friend RageVector3 operator * ( float f, const RageVector3& other ) { return other*f; }
float x, y, z;
};
@@ -164,25 +165,25 @@ public:
RageVector4(): x(0), y(0), z(0), w(0) {}
RageVector4( const float * f ): x(f[0]), y(f[1]), z(f[2]), w(f[3]) {}
RageVector4( float x1, float y1, float z1, float w1 ): x(x1), y(y1), z(z1), w(w1) {}
// casting
operator float* () { return &x; };
operator const float* () const { return &x; };
// assignment operators
RageVector4& operator += ( const RageVector4& other ) { x+=other.x; y+=other.y; z+=other.z; w+=other.w; return *this; }
RageVector4& operator -= ( const RageVector4& other ) { x-=other.x; y-=other.y; z-=other.z; w-=other.w; return *this; }
RageVector4& operator *= ( float f ) { x*=f; y*=f; z*=f; w*=f; return *this; }
RageVector4& operator /= ( float f ) { x/=f; y/=f; z/=f; w/=f; return *this; }
// binary operators
RageVector4 operator + ( const RageVector4& other ) const { return RageVector4( x+other.x, y+other.y, z+other.z, w+other.w ); }
RageVector4 operator - ( const RageVector4& other ) const { return RageVector4( x-other.x, y-other.y, z-other.z, w-other.w ); }
RageVector4 operator * ( float f ) const { return RageVector4( x*f, y*f, z*f, w*f ); }
RageVector4 operator / ( float f ) const { return RageVector4( x/f, y/f, z/f, w/f ); }
friend RageVector4 operator * ( float f, const RageVector4& other ) { return other*f; }
float x, y, z, w;
};
@@ -200,11 +201,11 @@ public:
a = rv4.w;
return *this;
}
// casting
operator float* () { return &r; };
operator const float* () const { return &r; };
// assignment operators
RageColor& operator += ( const RageColor& other ) { r+=other.r; g+=other.g; b+=other.b; a+=other.a; return *this; }
RageColor& operator -= ( const RageColor& other ) { r-=other.r; g-=other.g; b-=other.b; a-=other.a; return *this; }
@@ -213,7 +214,7 @@ public:
/* Divide is rarely useful: you can always use multiplication, and you don't have to
* worry about div/0. */
// RageColor& operator /= ( float f ) { r/=f; g/=f; b/=f; a/=f; return *this; }
// binary operators
RageColor operator + ( const RageColor& other ) const { return RageColor( r+other.r, g+other.g, b+other.b, a+other.a ); }
RageColor operator - ( const RageColor& other ) const { return RageColor( r-other.r, g-other.g, b-other.b, a-other.a ); }
@@ -221,12 +222,12 @@ public:
RageColor operator * ( float f ) const { return RageColor( r*f, g*f, b*f, a*f ); }
// Divide is useful for using with the SCALE macro
RageColor operator / ( float f ) const { return RageColor( r/f, g/f, b/f, a/f ); }
friend RageColor operator * ( float f, const RageColor& other ) { return other*f; } // What is this for? Did I add this? -Chris
bool operator == ( const RageColor& other ) const { return r==other.r && g==other.g && b==other.b && a==other.a; }
bool operator != ( const RageColor& other ) const { return !operator==(other); }
bool FromString( const RString &str )
{
int result = sscanf( str, "%f,%f,%f,%f", &r, &g, &b, &a );
@@ -237,7 +238,7 @@ public:
}
if( result == 4 )
return true;
unsigned int ir=255, ib=255, ig=255, ia=255;
result = sscanf( str, "#%2x%2x%2x%2x", &ir, &ig, &ib, &ia );
if( result >= 3 )
@@ -249,7 +250,7 @@ public:
a = 1;
return true;
}
r=1; b=1; g=1; a=1;
return false;
}
@@ -315,12 +316,12 @@ inline unsigned char FTOC(float a)
* r, g, b, a order, independent of endianness, so storing them this
* way avoids endianness problems. Don't try to manipulate this; only
* manip RageColors. */
/* Perhaps the math in RageColor could be moved to RageVColor. We don't need the
/* Perhaps the math in RageColor could be moved to RageVColor. We don't need the
* precision of a float for our calculations anyway. -Chris */
class RageVColor
{
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(const RageColor &rc): b(0), g(0), r(0), a(0) { *this = rc; }
@@ -339,12 +340,12 @@ namespace StepMania
public:
Rect(): left(0), top(0), right(0), bottom(0) {}
Rect(T l, T t, T r, T b): left(l), top(t), right(r), bottom(b) {}
T GetWidth() const { return right-left; };
T GetHeight() const { return bottom-top; };
T GetCenterX() const { return (left+right)/2; };
T GetCenterY() const { return (top+bottom)/2; };
bool operator==( const Rect &other ) const
{
#define COMPARE( x ) if( x != other.x ) return false
@@ -356,14 +357,14 @@ public:
return true;
}
bool operator!=( const Rect &other ) const { return !operator==(other); }
T left, top, right, bottom;
};
}
typedef StepMania::Rect<int> RectI;
typedef StepMania::Rect<float> RectF;
/* Structure for our custom vertex type. Note that these data structes
/* Structure for our custom vertex type. Note that these data structes
* have the same layout that D3D expects. */
struct RageSpriteVertex // has color
{
@@ -390,7 +391,7 @@ struct RageModelVertex // doesn't have color. Relies on material color
RageVector3 p; // position
RageVector3 n; // normal
RageVector2 t; // texture coordinates
int8_t bone;
std::int8_t bone;
RageVector2 TextureMatrixScale; // usually 1,1
};
+2 -1
View File
@@ -15,6 +15,7 @@
#include <cfloat>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <ctime>
#include <functional>
#include <map>
@@ -194,7 +195,7 @@ bool HexToBinary( const RString &s, unsigned char *stringOut )
break;
RString sByte = s.substr( i*2, 2 );
uint8_t val = 0;
std::uint8_t val = 0;
if( sscanf( sByte, "%hhx", &val ) != 1 )
return false;
stringOut[i] = val;
+11 -10
View File
@@ -8,10 +8,11 @@
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <map>
#include <random>
#include <vector>
#include <sstream>
#include <vector>
class RageFileDriver;
@@ -215,7 +216,7 @@ namespace Endian
#define Swap24 ArchSwap24
#define Swap16 ArchSwap16
#else
inline uint32_t Swap32( uint32_t n )
inline std::uint32_t Swap32( std::uint32_t n )
{
return (n >> 24) |
((n >> 8) & 0x0000FF00) |
@@ -223,23 +224,23 @@ inline uint32_t Swap32( uint32_t n )
(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
}
inline uint16_t Swap16( uint16_t n )
inline std::uint16_t Swap16( std::uint16_t n )
{
return (n >> 8) | (n << 8);
}
#endif
inline uint32_t Swap32LE( uint32_t n ) { return Endian::little ? n : Swap32( n ); }
inline uint32_t Swap24LE( uint32_t n ) { return Endian::little ? n : Swap24( n ); }
inline uint16_t Swap16LE( uint16_t n ) { return Endian::little ? n : Swap16( n ); }
inline uint32_t Swap32BE( uint32_t n ) { return Endian::big ? n : Swap32( n ); }
inline uint32_t Swap24BE( uint32_t n ) { return Endian::big ? n : Swap24( n ); }
inline uint16_t Swap16BE( uint16_t n ) { return Endian::big ? n : Swap16( n ); }
inline std::uint32_t Swap32LE( std::uint32_t n ) { return Endian::little ? n : Swap32( n ); }
inline std::uint32_t Swap24LE( std::uint32_t n ) { return Endian::little ? n : Swap24( n ); }
inline std::uint16_t Swap16LE( std::uint16_t n ) { return Endian::little ? n : Swap16( n ); }
inline std::uint32_t Swap32BE( std::uint32_t n ) { return Endian::big ? n : Swap32( n ); }
inline std::uint32_t Swap24BE( std::uint32_t n ) { return Endian::big ? n : Swap24( n ); }
inline std::uint16_t Swap16BE( std::uint16_t n ) { return Endian::big ? n : Swap16( n ); }
class MersenneTwister : public std::mt19937
{
+5 -4
View File
@@ -21,6 +21,7 @@
#include "NoteDataWithScoring.h"
#include <cstddef>
#include <cstdint>
static RString PercentScoreWeightName( std::size_t i ) { return "PercentScoreWeight" + 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);
}
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
* 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;
#elif 1
// 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
// 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));
@@ -279,8 +280,8 @@ void ScoreKeeperNormal::AddScoreInternal( TapNoteScore score )
m_iTapNotesHit++;
const int64_t N = uint64_t(m_iNumTapsAndHolds);
const int64_t sum = (N * (N + 1)) / 2;
const std::int64_t N = std::uint64_t(m_iNumTapsAndHolds);
const std::int64_t sum = (N * (N + 1)) / 2;
const int Z = m_iMaxPossiblePoints/10;
// Don't use a multiplier if the player has failed
+4 -3
View File
@@ -1,6 +1,7 @@
#ifndef ARCH_HOOKS_H
#define ARCH_HOOKS_H
#include <cstdint>
#include <ctime>
struct lua_State;
@@ -86,7 +87,7 @@ public:
* underlying timers may be 32-bit, but implementations should try to avoid
* wrapping if possible.
*/
static int64_t GetMicrosecondsSinceStart( bool bAccurate );
static std::int64_t GetMicrosecondsSinceStart( bool bAccurate );
/*
* Add file search paths, higher priority first.
@@ -130,8 +131,8 @@ public:
private:
/* This are helpers for GetMicrosecondsSinceStart on systems with a timer
* that may loop or move backwards. */
static int64_t FixupTimeIfLooped( int64_t usecs );
static int64_t FixupTimeIfBackwards( int64_t usecs );
static std::int64_t FixupTimeIfLooped( std::int64_t usecs );
static std::int64_t FixupTimeIfBackwards( std::int64_t usecs );
static bool g_bQuitting;
static bool g_bToggleWindowed;
+13 -11
View File
@@ -1,6 +1,8 @@
#include "global.h"
#include "ArchHooks.h"
#include <cstdint>
/*
* This is a helper for GetMicrosecondsSinceStart on systems with a system
* timer that may loop or move backwards.
@@ -25,15 +27,15 @@
* bAccurate == false.
*/
int64_t ArchHooks::FixupTimeIfLooped( int64_t usecs )
std::int64_t ArchHooks::FixupTimeIfLooped( std::int64_t usecs )
{
static int64_t last = 0;
static int64_t offset_us = 0;
static std::int64_t last = 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. */
const int64_t i32BitMaxMs = uint64_t(1) << 32;
const int64_t i32BitMaxUs = i32BitMaxMs*1000;
const int64_t one_day = uint64_t(24*60*60)*1000000;
const std::int64_t i32BitMaxMs = std::uint64_t(1) << 32;
const std::int64_t i32BitMaxUs = i32BitMaxMs*1000;
const std::int64_t one_day = std::uint64_t(24*60*60)*1000000;
if( last > (i32BitMaxUs-one_day) && usecs < one_day )
offset_us += i32BitMaxUs;
@@ -42,10 +44,10 @@ int64_t ArchHooks::FixupTimeIfLooped( int64_t usecs )
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 int64_t offset_us = 0;
static std::int64_t last = 0;
static std::int64_t offset_us = 0;
if( usecs < last )
{
@@ -61,7 +63,7 @@ int64_t ArchHooks::FixupTimeIfBackwards( int64_t usecs )
/*
* (c) 2003-2004 Glenn Maynard, Chris Danford
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -71,7 +73,7 @@ int64_t ArchHooks::FixupTimeIfBackwards( int64_t usecs )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+5 -4
View File
@@ -7,6 +7,7 @@
#include "ProductInfo.h"
#include <cstddef>
#include <cstdint>
#include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
@@ -160,7 +161,7 @@ void ArchHooks_MacOSX::DumpDebugInfo()
float fRam;
char ramPower;
{
uint64_t iRam = 0;
std::uint64_t iRam = 0;
GET_PARAM( "hw.memsize", iRam );
fRam = float( double(iRam) / 1073741824.0 );
@@ -175,7 +176,7 @@ void ArchHooks_MacOSX::DumpDebugInfo()
RString sModel("Unknown");
do {
char szModel[128];
uint64_t iFreq;
std::uint64_t iFreq;
GET_PARAM( "hw.logicalcpu_max", iMaxCPUs );
GET_PARAM( "hw.logicalcpu", iCPUs );
@@ -257,7 +258,7 @@ bool ArchHooks_MacOSX::GoToURL( RString sUrl )
return result == 0;
}
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
// http://developer.apple.com/qa/qa2004/qa1398.html
static double factor = 0.0;
@@ -269,7 +270,7 @@ int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
mach_timebase_info( &timeBase );
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"
+17 -14
View File
@@ -11,6 +11,9 @@
#include "archutils/Common/PthreadHelpers.h"
#include "archutils/Unix/EmergencyShutdown.h"
#include "archutils/Unix/AssertionHandler.h"
#include <cstdint>
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
@@ -86,7 +89,7 @@ static bool EmergencyShutdown( int signal, siginfo_t *si, const ucontext_t *uc )
/* We didn't run the crash handler. Run the default handler, so we can dump core. */
return false;
}
#if defined(HAVE_TLS)
static thread_local int g_iTestTLS = 0;
@@ -122,14 +125,14 @@ static void TestTLS()
namespace
{
clockid_t g_Clock = CLOCK_REALTIME;
void OpenGetTime()
{
static bool bInitialized = false;
if( bInitialized )
return;
bInitialized = true;
/* Check whether the clock is actually supported. */
timespec ts;
if( clock_getres(CLOCK_MONOTONIC, &ts) == -1 )
@@ -138,7 +141,7 @@ namespace
/* If the resolution is worse than a millisecond, fall back on CLOCK_REALTIME. */
if( ts.tv_sec > 0 || ts.tv_nsec > 1000000 )
return;
g_Clock = CLOCK_MONOTONIC;
}
};
@@ -149,25 +152,25 @@ clockid_t ArchHooks_Unix::GetClock()
return g_Clock;
}
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
OpenGetTime();
timespec 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 )
iRet = ArchHooks::FixupTimeIfBackwards( iRet );
return iRet;
}
#else
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
struct timeval tv;
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 );
return iRet;
}
@@ -220,7 +223,7 @@ void ArchHooks_Unix::Init()
SignalHandler::OnClose( EmergencyShutdown );
InstallExceptionHandler();
#if defined(HAVE_TLS) && !defined(BSD)
TestTLS();
#endif
@@ -256,7 +259,7 @@ bool ArchHooks_Unix::GoToURL( RString sUrl )
#endif
static RString LibcVersion()
{
{
char buf[1024] = "(error)";
int ret = confstr( _CS_GNU_LIBC_VERSION, buf, sizeof(buf) );
if( ret == -1 )
@@ -295,7 +298,7 @@ void ArchHooks_Unix::SetTime( tm newtime )
newtime.tm_year+1900,
newtime.tm_sec );
LOG->Trace( "executing '%s'", sCommand.c_str() );
LOG->Trace( "executing '%s'", sCommand.c_str() );
int ret = system( sCommand );
if( ret == -1 || ret == 127 || !WIFEXITED(ret) || WEXITSTATUS(ret) )
LOG->Trace( "'%s' failed", sCommand.c_str() );
@@ -341,7 +344,7 @@ RString ArchHooks_Unix::GetClipboard()
// property on YOUR window.
XConvertSelection( Dpy, XA_CLIPBOARD, XA_STRING, XA_PRIMARY, Win, CurrentTime );
// XXX: This seems to always return 1 even when it works. (Success == 0)
// Now we must wait for the clipboard owner to cough it up.
// HACK: What we SHOULD do is XSelectInput() for SelectionNotify before
// calling XConvertSelection and then block on XWindowEvent(), but that
@@ -432,7 +435,7 @@ void ArchHooks::MountUserFilesystems( const RString &sDirOfExecutable )
/*
* (c) 2003-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -442,7 +445,7 @@ void ArchHooks::MountUserFilesystems( const RString &sDirOfExecutable )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+6 -3
View File
@@ -2,6 +2,9 @@
#define ARCH_HOOKS_UNIX_H
#include "ArchHooks.h"
#include <cstdint>
class ArchHooks_Unix: public ArchHooks
{
public:
@@ -10,7 +13,7 @@ public:
void DumpDebugInfo();
void SetTime( tm newtime );
int64_t GetMicrosecondsSinceStart();
std::int64_t GetMicrosecondsSinceStart();
void MountInitialFilesystems( const RString &sDirOfExecutable );
float GetDisplayAspectRatio() { return 4.0f/3; }
@@ -31,7 +34,7 @@ public:
/*
* (c) 2003-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -41,7 +44,7 @@ public:
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+11 -9
View File
@@ -14,11 +14,13 @@
#include "VersionHelpers.h"
#include <cstdint>
static HANDLE g_hInstanceMutex;
static bool g_bIsMultipleInstance = false;
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
}
@@ -115,7 +117,7 @@ bool ArchHooks_Win32::CheckForMultipleInstances(int argc, char* argv[])
cds.dwData = 0;
cds.cbData = sAllArgs.size();
cds.lpData = (void*)sAllArgs.data();
SendMessage(
SendMessage(
(HWND)hWnd, // HWND hWnd = handle of destination window
WM_COPYDATA,
(WPARAM)nullptr, // HANDLE OF SENDING WINDOW
@@ -141,7 +143,7 @@ void ArchHooks_Win32::SetTime( tm newtime )
st.wMinute = (WORD)newtime.tm_min;
st.wSecond = (WORD)newtime.tm_sec;
st.wMilliseconds = 0;
SetLocalTime( &st );
SetLocalTime( &st );
}
void ArchHooks_Win32::BoostPriority()
@@ -197,12 +199,12 @@ RString ArchHooks_Win32::GetClipboard()
// First make sure that the clipboard actually contains a string
// (or something stringifiable)
if(unlikely( !IsClipboardFormatAvailable( CF_TEXT ) )) return "";
// Yes. All this mess just to gain access to the string stored by the clipboard.
// I'm having flashbacks to Berkeley sockets.
if(unlikely( !OpenClipboard( nullptr ) ))
{ LOG->Warn(werr_ssprintf( GetLastError(), "InputHandler_DirectInput: OpenClipboard() failed" )); return ""; }
hgl = GetClipboardData( CF_TEXT );
if(unlikely( hgl == nullptr ))
{ LOG->Warn(werr_ssprintf( GetLastError(), "InputHandler_DirectInput: GetClipboardData() failed" )); CloseClipboard(); return ""; }
@@ -220,18 +222,18 @@ RString ArchHooks_Win32::GetClipboard()
#else
ret = RString( lpstr );
#endif
// And now we clean up.
GlobalUnlock( hgl );
CloseClipboard();
return ret;
}
/*
* (c) 2003-2004 Glenn Maynard, Chris Danford
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -241,7 +243,7 @@ RString ArchHooks_Win32::GetClipboard()
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+7 -5
View File
@@ -6,6 +6,8 @@
#include "ProductInfo.h"
#include "RageFileManager.h"
#include <cstdint>
// for timeGetTime
#include <windows.h>
#include <mmsystem.h>
@@ -25,18 +27,18 @@ static void InitTimer()
timeBeginPeriod( 1 );
}
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
std::int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
if( !g_bTimerInitialized )
InitTimer();
int64_t ret = timeGetTime() * int64_t(1000);
std::int64_t ret = timeGetTime() * std::int64_t(1000);
if( bAccurate )
{
ret = FixupTimeIfLooped( ret );
ret = FixupTimeIfBackwards( ret );
}
return ret;
}
@@ -221,7 +223,7 @@ RString ArchHooks::GetPreferredLanguage()
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -231,7 +233,7 @@ RString ArchHooks::GetPreferredLanguage()
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -13,7 +13,8 @@
#include <fcntl.h>
#endif
#include <errno.h>
#include <cerrno>
#include <cstdint>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/input.h>
@@ -69,7 +70,7 @@ struct EventDevice
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)));
}
@@ -98,14 +99,14 @@ bool EventDevice::Open( RString sFile, InputDevice dev )
if( ioctl(m_iFD, EVIOCGVERSION, &iVersion) == -1 )
LOG->Warn( "ioctl(EVIOCGVERSION): %s", strerror(errno) );
else
LOG->Info( "Event driver: v%i.%i.%i", (iVersion >> 16) & 0xFF, (iVersion >> 8) & 0xFF, iVersion & 0xFF );
LOG->Info( "Event driver: v%i.%i.%i", (iVersion >> 16) & 0xFF, (iVersion >> 8) & 0xFF, iVersion & 0xFF );
}
char szName[1024];
if( ioctl(m_iFD, EVIOCGNAME(sizeof(szName)), szName) == -1 )
{
LOG->Warn( "ioctl(EVIOCGNAME): %s", strerror(errno) );
m_sName = "(unknown)";
}
else
@@ -125,7 +126,7 @@ bool EventDevice::Open( RString sFile, InputDevice dev )
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) );
if( ioctl(m_iFD, EVIOCGBIT(EV_ABS, sizeof(iABSMask)), iABSMask) < 0 )
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) );
if( ioctl(m_iFD, EVIOCGBIT(EV_KEY, sizeof(iKeyMask)), iKeyMask) < 0 )
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) );
if( ioctl(m_iFD, EVIOCGBIT(0, EV_MAX), iEventTypes) == -1 )
LOG->Warn( "ioctl(EV_MAX): %s", strerror(errno) );
@@ -170,7 +171,7 @@ bool EventDevice::Open( RString sFile, InputDevice dev )
LOG->Info( " Event types: %s", join(", ", setEventTypes).c_str() );
}
int iTotalKeys = 0;
for( int i = 0; i < KEY_MAX; ++i )
{
@@ -273,7 +274,7 @@ InputHandler_Linux_Event::InputHandler_Linux_Event()
if( ! g_apEventDevices.empty() ) // LinuxInputManager found at least one valid device for us
StartThread();
}
InputHandler_Linux_Event::~InputHandler_Linux_Event()
{
if( m_InputThread.IsCreated() ) StopThread();
@@ -310,7 +311,7 @@ bool InputHandler_Linux_Event::TryDevice(RString devfile)
g_apEventDevices.push_back( pDev );
}
if( hotplug ) StartThread();
m_NextDevice = enum_add2(m_NextDevice, 1);
m_bDevicesChanged = true;
return true;
@@ -339,7 +340,7 @@ void InputHandler_Linux_Event::InputThread()
fd_set fdset;
FD_ZERO( &fdset );
int iMaxFD = -1;
for( int i = 0; i < (int) g_apEventDevices.size(); ++i )
{
int iFD = g_apEventDevices[i]->m_iFD;
@@ -400,7 +401,7 @@ void InputHandler_Linux_Event::InputThread()
ButtonPressed( DeviceInput(g_apEventDevices[i]->m_Dev, enum_add2(JOY_BUTTON_1, iNum), event.value != 0, now) );
break;
}
case EV_ABS: {
ASSERT_M( event.code < ABS_MAX, ssprintf("%i", event.code) );
DeviceButton neg = g_apEventDevices[i]->aiAbsMappingLow[event.code];
@@ -435,7 +436,7 @@ void InputHandler_Linux_Event::GetDevicesAndDescriptions( std::vector<InputDevic
EventDevice *pDev = g_apEventDevices[i];
vDevicesOut.push_back( InputDeviceInfo(pDev->m_Dev, pDev->m_sName) );
}
m_bDevicesChanged = false;
}
@@ -443,7 +444,7 @@ void InputHandler_Linux_Event::GetDevicesAndDescriptions( std::vector<InputDevic
* (c) 2003-2008 Glenn Maynard
* (c) 2013 Ben "root" Anderson
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -453,7 +454,7 @@ void InputHandler_Linux_Event::GetDevicesAndDescriptions( std::vector<InputDevic
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -7,6 +7,7 @@
#include <cerrno>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
@@ -130,7 +131,7 @@ class InputHandler_SextetStream::Impl
handler->ButtonPressed(di);
}
uint8_t stateBuffer[STATE_BUFFER_SIZE];
std::uint8_t stateBuffer[STATE_BUFFER_SIZE];
std::size_t timeout_ms;
RageThread inputThread;
bool continueInputThread;
@@ -190,7 +191,7 @@ class InputHandler_SextetStream::Impl
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 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);
uint8_t changes[STATE_BUFFER_SIZE];
std::uint8_t changes[STATE_BUFFER_SIZE];
RageTimer now;
// XOR to find differences
@@ -274,7 +275,7 @@ class InputHandler_SextetStream::Impl
if(linereader->ReadLine(line)) {
LOG->Trace("Got line: '%s'", line.c_str());
if(line.length() > 0) {
uint8_t newStateBuffer[STATE_BUFFER_SIZE];
std::uint8_t newStateBuffer[STATE_BUFFER_SIZE];
GetNewState(newStateBuffer, line);
ReactToChanges(newStateBuffer);
}
@@ -4,12 +4,14 @@
#include "RageLog.h"
#include "RageUtil.h"
#include "RageInputDevice.h"
#include <windows.h>
#include <process.h>
#include "PrefsManager.h"
#include <cstdint>
#include <windows.h>
#include <process.h>
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_destroy_t)(int thread_id);
@@ -24,13 +26,13 @@ static DDRIO_IO_INIT ddrio_io_init;
typedef int (*DDRIO_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;
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;
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;
typedef int (*DDRIO_FINI)();
@@ -65,13 +67,13 @@ static unsigned int crt_thread_shim(void* outer_ctx)
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");
struct shim_ctx sctx;
uintptr_t thread_id;
std::uintptr_t thread_id;
sctx.barrier = CreateEvent(NULL, TRUE, FALSE, NULL);
sctx.proc = proc;
@@ -92,7 +94,7 @@ void crt_thread_destroy(int 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);
WaitForSingleObject((HANDLE)(uintptr_t)thread_id, INFINITE);
WaitForSingleObject((HANDLE)(std::uintptr_t)thread_id, INFINITE);
if (result)
{
GetExitCodeThread((HANDLE)(uintptr_t)thread_id, (DWORD*)result);
GetExitCodeThread((HANDLE)(std::uintptr_t)thread_id, (DWORD*)result);
}
}
@@ -195,14 +197,14 @@ InputHandler_Win32_ddrio::~InputHandler_Win32_ddrio()
InputThread.Wait();
LOG->Trace( "ddrio thread shut down." );
if (ddrio_fini != nullptr)
{
LOG->Trace("calling ddrio dll fini");
ddrio_fini();
LOG->Trace("ddrio dll complete");
}
}
}
@@ -261,7 +263,7 @@ int InputHandler_Win32_ddrio::InputThread_Start( void *p )
void InputHandler_Win32_ddrio::InputThreadMain()
{
uint32_t prevInput = 0, newInput = 0;
std::uint32_t prevInput = 0, newInput = 0;
LightsState prevLS = { 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++)
{
@@ -327,15 +329,15 @@ bool InputHandler_Win32_ddrio::IsLightChange(LightsState prevLS, LightsState new
}
}
}
return false;
}
void InputHandler_Win32_ddrio::PushLightState(LightsState newLS)
{
uint32_t p3io = 0;
uint32_t hdxs = 0;
uint32_t extio = 0;
std::uint32_t p3io = 0;
std::uint32_t hdxs = 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.
@@ -383,7 +385,7 @@ void InputHandler_Win32_ddrio::PushLightState(LightsState newLS)
/*
* (c) 2022 din
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -393,7 +395,7 @@ void InputHandler_Win32_ddrio::PushLightState(LightsState newLS)
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -5,9 +5,11 @@
#include "RageThreads.h"
#include "arch/Lights/LightsDriver_Export.h"
#include <cstdint>
static bool _ddriodll_loaded = false;
//we want to use a
//we want to use a
#define DDRIO_DEVICEID DEVICE_JOY1
enum p3io_light_bit {
@@ -77,7 +79,7 @@ private:
static int InputThread_Start( void *p );
void InputThreadMain();
void PushInputState(uint32_t newInput);
void PushInputState(std::uint32_t newInput);
bool IsLightChange(LightsState prevLS, LightsState newLS);
void PushLightState(LightsState newLS);
@@ -5,6 +5,8 @@
#include "RageLog.h"
#include "LightsDriver_LinuxPacDrive.h"
#include <cstdint>
extern "C" {
#include <usb.h>
}
@@ -77,7 +79,7 @@ void LightsDriver_LinuxPacDrive::Set( const LightsState *ls )
{
if ( !DeviceHandle ) return;
uint16_t outb = 0;
std::uint16_t outb = 0;
switch (iLightingOrder) {
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;
// output is within the first 16 bits - accept a
// 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 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 <cstdint>
extern "C" {
#include <usb.h>
}
@@ -20,7 +22,7 @@ private:
void FindDevice();
void OpenDevice();
void WriteDevice(uint16_t out);
void WriteDevice(std::uint16_t out);
void CloseDevice();
struct usb_device *Device;
+5 -3
View File
@@ -5,11 +5,13 @@
#include "arch/Lights/LightsDriver.h"
#include <cstdint>
class LightsDriver_Linux_Leds : public LightsDriver
{
private:
static const uint8_t LINUX_LED_STATE_ON = 255;
static const uint8_t LINUX_LED_STATE_OFF = 0;
static const std::uint8_t LINUX_LED_STATE_ON = 255;
static const std::uint8_t LINUX_LED_STATE_OFF = 0;
static const int LINUX_LED_MAX_DIRECTORY_LENGTH = PATH_MAX;
const InputScheme *pInput;
@@ -61,6 +63,6 @@ public:
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
*
* i love lamp
*/
+12 -10
View File
@@ -1,5 +1,13 @@
#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)
#include <unistd.h>
#endif
@@ -10,12 +18,6 @@
#include <fcntl.h>
#endif
#include <errno.h>
#include "LightsDriver_Linux_stac.h"
#include "GameState.h"
#include "Game.h"
#include "RageLog.h"
#include <libudev.h>
#include <fcntl.h>
#include <linux/hidraw.h>
@@ -23,7 +25,7 @@
REGISTER_LIGHTS_DRIVER_CLASS2(stac, Linux_stac);
StacDevice::StacDevice(uint8_t pn)
StacDevice::StacDevice(std::uint8_t pn)
{
memset(outputBuffer, 0x00, sizeof(outputBuffer));
@@ -175,11 +177,11 @@ void StacDevice::Close()
void StacDevice::SetInBuffer(int index, bool lightState)
{
//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,
//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.
if (index_offset < STAC_HIDREPORT_SIZE && outputBuffer[index_offset] != val)
+12 -10
View File
@@ -4,22 +4,24 @@
#define LightsDriver_Linux_stac_H
/*
* -------------------------- NOTE --------------------------
*
* -------------------------- NOTE --------------------------
*
* This driver needs user read/write access to the icedragon.io stac.
* This can be achieved by using a udev rule like this:
*
*
* (player 1 then player 2)
* SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="eb5b", OWNER="dance", GROUP="dance", MODE="0660"
* SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="eb5a", OWNER="dance", GROUP="dance", MODE="0660"
*
*
* Refer to your distrobution's documentation on how to properly apply a udev rule.
*
* -------------------------- NOTE --------------------------
*
* -------------------------- NOTE --------------------------
*/
#include "arch/Lights/LightsDriver.h"
#include <cstdint>
//static information about the device(s) in question.
#define STAC_VID "04d8"
#define STAC_PID_P1 "ea4b"
@@ -50,12 +52,12 @@ public:
const char *devicePath;
int fd = -1;
uint8_t playerNumber = 0;
std::uint8_t playerNumber = 0;
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 Connect();
@@ -117,4 +119,4 @@ public:
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
*/
+2 -2
View File
@@ -15,7 +15,7 @@ class LightsDriver_PacDrive : public LightsDriver
public:
LightsDriver_PacDrive();
virtual ~LightsDriver_PacDrive();
virtual void Set( const LightsState *ls );
};
@@ -25,4 +25,4 @@ class LightsDriver_PacDrive : public LightsDriver
* 2014 - twistedsymphony
* Created for use with Beware's StepMania 3.9 DDR Extreme Simulation
* feel free to reuse and distribute this code
*/
*/
@@ -5,6 +5,7 @@
#include "RageUtil.h"
#include "SextetUtils.h"
#include <cstdint>
#include <cstring>
// Private members/methods are kept out of the header using an opaque pointer `_impl`.
@@ -18,7 +19,7 @@ namespace
class Impl
{
protected:
uint8_t lastOutput[FULL_SEXTET_COUNT];
std::uint8_t lastOutput[FULL_SEXTET_COUNT];
RageFile * out;
public:
@@ -40,7 +41,7 @@ namespace
void Set(const LightsState * ls)
{
uint8_t buffer[FULL_SEXTET_COUNT];
std::uint8_t buffer[FULL_SEXTET_COUNT];
packLine(buffer, ls);
+3 -1
View File
@@ -3,6 +3,8 @@
#include "windows.h"
#include "RageUtil.h"
#include <cstdint>
REGISTER_LIGHTS_DRIVER_CLASS(Win32Serial);
static Preference<RString> g_sLightsComPort("LightsComPort", "COM54");
@@ -68,7 +70,7 @@ LightsDriver_Win32Serial::~LightsDriver_Win32Serial()
void LightsDriver_Win32Serial::Set(const LightsState* ls)
{
if (serialPort != INVALID_HANDLE_VALUE) {
uint8_t buffer[FULL_SEXTET_COUNT];
std::uint8_t buffer[FULL_SEXTET_COUNT];
packLine(buffer, ls);
+3 -1
View File
@@ -11,10 +11,12 @@
#include "LightsDriver.h"
#include "SextetUtils.h"
#include <cstdint>
class LightsDriver_Win32Serial : public LightsDriver
{
protected:
uint8_t lastOutput[FULL_SEXTET_COUNT];
std::uint8_t lastOutput[FULL_SEXTET_COUNT];
public:
LightsDriver_Win32Serial();
virtual ~LightsDriver_Win32Serial();
+9 -8
View File
@@ -4,6 +4,7 @@
#include "LightsDriver.h"
#include <cstddef>
#include <cstdint>
/*
* 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
// character (i.e., within the range 0x21-0x7E) such that the low 6 bits of
// 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
// 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:
// 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
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) |
(b1 ? 0x02 : 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
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));
}
// 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(
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
// 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
buffer[0] = packPrintableSextet(
@@ -126,7 +127,7 @@ inline std::size_t packControllerLights(const LightsState* ls, GameController gc
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;
+5 -3
View File
@@ -5,6 +5,8 @@
#include "RageSurface_Load.h"
#include "LoadingWindow_Gtk.h"
#include <cstdint>
#include <gtk/gtk.h>
static GtkWidget *label;
@@ -75,7 +77,7 @@ void LoadingWindow_Gtk::SetText( RString s )
static void DeletePixels( guchar *pixels, gpointer data )
{
delete[] (uint8_t *)pixels;
delete[] (std::uint8_t *)pixels;
}
static GdkPixbuf *MakePixbuf( const RageSurface *pSrc )
@@ -149,7 +151,7 @@ void LoadingWindow_Gtk::SetIndeterminate( bool indeterminate )
/*
* (c) 2003-2004 Glenn Maynard, Sean Burke
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -159,7 +161,7 @@ void LoadingWindow_Gtk::SetIndeterminate( bool indeterminate )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -3,10 +3,13 @@
#include "LowLevelWindow.h"
#include "RageDisplay.h"
#include <cstdint>
#include <objc/objc.h>
typedef const struct __CFDictionary *CFDictionaryRef;
typedef uint32_t CGDirectDisplayID;
typedef std::uint32_t CGDirectDisplayID;
class LowLevelWindow_MacOSX : public LowLevelWindow
{
@@ -21,7 +24,7 @@ public:
LowLevelWindow_MacOSX();
~LowLevelWindow_MacOSX();
void *GetProcAddress( RString s );
RString TryVideoMode( const VideoModeParams& p, bool& newDeviceOut );
RString TryVideoMode( const VideoModeParams& p, bool& newDeviceOut );
void GetDisplaySpecs( DisplaySpecs &specs ) const;
void SwapBuffers();
@@ -51,7 +54,7 @@ private:
/*
* (c) 2005-2006, 2008 Steve Checkoway
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -61,7 +64,7 @@ private:
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -7,6 +7,7 @@
#import "arch/ArchHooks/ArchHooks.h"
#include <cstddef>
#include <cstdint>
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
@@ -189,7 +190,7 @@ public:
RenderTarget_MacOSX( id shareContext );
~RenderTarget_MacOSX();
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 FinishRenderingTo();
@@ -325,11 +326,11 @@ void *LowLevelWindow_MacOSX::GetProcAddress( RString s )
// http://developer.apple.com/qa/qa2001/qa1188.html
// Both functions mentioned in there are deprecated in 10.4.
const RString& symbolName( '_' + s );
const uint32_t count = _dyld_image_count();
const std::uint32_t count = _dyld_image_count();
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 );
return symbol ? NSAddressOfSymbol( symbol ) : nil;
}
@@ -11,6 +11,8 @@
#include "RageDisplay_OGL_Helpers.h"
#include "RageDisplay_OGL.h"
#include <cstdint>
#include <GL/glew.h>
static PIXELFORMATDESCRIPTOR g_CurrentPixelFormat;
@@ -129,7 +131,7 @@ void DumpPixelFormat( const PIXELFORMATDESCRIPTOR &pfd )
RString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut )
{
//LOG->Warn( "LowLevelWindow_Win32::TryVideoMode" );
ASSERT_M( p.bpp == 16 || p.bpp == 32, ssprintf("%i", p.bpp) );
bNewDeviceOut = false;
@@ -323,10 +325,10 @@ public:
virtual ~RenderTarget_Win32();
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 FinishRenderingTo();
virtual bool InvertY() const { return true; }
private:
@@ -415,7 +417,7 @@ void RenderTarget_Win32::FinishRenderingTo()
BOOL successful = wglMakeCurrent(m_hOldDeviceContext, m_hOldRenderContext);
ASSERT_M( successful == TRUE, "wglMakeCurrent failed in RenderTarget_Win32::FinishRenderingTo()" );
m_hOldDeviceContext = 0;
m_hOldRenderContext = 0;
}
@@ -428,7 +430,7 @@ RenderTarget* LowLevelWindow_Win32::CreateRenderTarget()
/*
* (c) 2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -438,7 +440,7 @@ RenderTarget* LowLevelWindow_Win32::CreateRenderTarget()
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+11 -9
View File
@@ -13,7 +13,9 @@ using namespace RageDisplay_Legacy_Helpers;
using namespace X11Helper;
#include <cmath>
#include <cstdint>
#include <set>
#include <GL/glxew.h>
#define GLX_GLXEXT_PROTOTYPES
#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
RROutput targetOut = None;
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]);
std::string outName = std::string(outInfo->name, static_cast<unsigned int> (outInfo->nameLen));
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
// look for an output with a CRTC driving it
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]);
if (outInfo->connection == RR_Connected) { // Check for CONNECTED state: Connected == 0
connected = scrRes->outputs[i];
@@ -362,7 +364,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
RRCrtc tgtOutCrtc = tgtOutInfo->crtc;
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] );
if (crtcInfo->mode == None)
@@ -390,7 +392,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
const XRRModeInfo &thisMI = scrRes->modes[i];
const unsigned int modeWidth = bPortrait ? thisMI.height : thisMI.width;
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 fTempDiff = std::abs(p.rate - fTempRefresh);
if ((p.rate != REFRESH_DEFAULT && fTempDiff < fRefreshDiff) ||
@@ -660,11 +662,11 @@ void LowLevelWindow_X11::GetDisplaySpecs(DisplaySpecs &out) const {
int nsizes = 0;
XRRScreenSize *screenSizes = XRRSizes( Dpy, screenNum, &nsizes);
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];
int nrates = 0;
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])};
screenModes.insert(m);
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
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] );
if (outInfo->nmode > 0)
@@ -717,7 +719,7 @@ void LowLevelWindow_X11::GetDisplaySpecs(DisplaySpecs &out) const {
std::set<DisplayMode> outputSupported;
DisplayMode outputCurMode{};
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]];
unsigned int modeWidth = bPortrait ? mode.height : mode.width;
@@ -758,7 +760,7 @@ public:
~RenderTarget_X11();
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 FinishRenderingTo();
@@ -4,6 +4,7 @@
#include "RageLog.h"
#include <cstddef>
#include <cstdint>
#include <Carbon/Carbon.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 );
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.
usbd.iBus = GetIntProperty( device, CFSTR("USB Address") );

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