mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2024-12-02 08:51:57 +00:00
Formatted code
This commit is contained in:
parent
5e582222cf
commit
afaf66ef40
17 changed files with 237 additions and 200 deletions
|
@ -1,4 +1,4 @@
|
||||||
astyle.exe -v --options=astyle-options.ini --exclude="libs" --recursive *.h
|
astyle.exe -v --options=astyle-options.ini --exclude="libs" --recursive *.h
|
||||||
astyle.exe -v --options=astyle-options.ini --exclude="libs" --exclude="idlib/math/Simd.cpp" --exclude="d3xp/gamesys/SysCvar.cpp" --exclude="d3xp/gamesys/Callbacks.cpp" --exclude="sys/win32/win_cpu.cpp" --exclude="sys/win32/win_main.cpp" --exclude="sys/win32/win_shared.cpp" --recursive *.cpp
|
astyle.exe -v --options=astyle-options.ini --exclude="libs" --exclude="idlib/math/Simd.cpp" --exclude="d3xp/gamesys/SysCvar.cpp" --exclude="d3xp/gamesys/Callbacks.cpp" --exclude="sys/win32/win_cpu.cpp" --exclude="sys/win32/win_main.cpp" --recursive *.cpp
|
||||||
|
|
||||||
pause
|
pause
|
|
@ -63,10 +63,10 @@ bool SpursEmulationAssertFailed( const char* filename, int line, const char* exp
|
||||||
#endif
|
#endif
|
||||||
#else // not _WIN32
|
#else // not _WIN32
|
||||||
// DG: POSIX support
|
// DG: POSIX support
|
||||||
raise(SIGTRAP);
|
raise( SIGTRAP );
|
||||||
// DG: end
|
// DG: end
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,7 +401,7 @@ public:
|
||||||
static const int INVALID_POSITION = -1;
|
static const int INVALID_POSITION = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
char* va( VERIFY_FORMAT_STRING const char* fmt, ... ) ATTRIBUTE_PRINTF(1, 2);
|
char* va( VERIFY_FORMAT_STRING const char* fmt, ... ) ATTRIBUTE_PRINTF( 1, 2 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
================================================================================================
|
================================================================================================
|
||||||
|
|
|
@ -698,8 +698,8 @@ ID_INLINE void idMath::SinCos( float a, float& s, float& c )
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// DG: non-MSVC version
|
// DG: non-MSVC version
|
||||||
s = sinf(a);
|
s = sinf( a );
|
||||||
c = cosf(a);
|
c = cosf( a );
|
||||||
// DG end
|
// DG end
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ bool AssertFailed( const char* file, int line, const char* expression )
|
||||||
#endif
|
#endif
|
||||||
#else // not _WIN32
|
#else // not _WIN32
|
||||||
// DG: POSIX support
|
// DG: POSIX support
|
||||||
raise(SIGTRAP);
|
raise( SIGTRAP );
|
||||||
// DG: end
|
// DG: end
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ If you have questions concerning this license or the applicable additional terms
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <dsound.h>
|
#include <dsound.h>
|
||||||
#else
|
#else
|
||||||
// DG: MinGW is incompatible with the original dsound.h because it contains MSVC specific annotations
|
// DG: MinGW is incompatible with the original dsound.h because it contains MSVC specific annotations
|
||||||
#include <wine-dsound.h>
|
#include <wine-dsound.h>
|
||||||
|
|
||||||
|
|
|
@ -64,14 +64,14 @@ static void Sys_SetThreadName( DWORD threadID, const char* name )
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// this ugly mess is the official way to set a thread name on windows..
|
// this ugly mess is the official way to set a thread name on windows..
|
||||||
// see http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
|
// see http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
|
||||||
|
|
||||||
|
|
||||||
THREADNAME_INFO info;
|
THREADNAME_INFO info;
|
||||||
info.dwType = 0x1000;
|
info.dwType = 0x1000;
|
||||||
info.szName = name;
|
info.szName = name;
|
||||||
info.dwThreadID = threadID;
|
info.dwThreadID = threadID;
|
||||||
info.dwFlags = 0;
|
info.dwFlags = 0;
|
||||||
|
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
RaiseException( MS_VC_EXCEPTION, 0, sizeof( info ) / sizeof( DWORD ), ( const ULONG_PTR* )&info );
|
RaiseException( MS_VC_EXCEPTION, 0, sizeof( info ) / sizeof( DWORD ), ( const ULONG_PTR* )&info );
|
||||||
|
|
|
@ -55,7 +55,7 @@ Contains the DxtEncoder implementation for SSE2.
|
||||||
typedef uint16 word;
|
typedef uint16 word;
|
||||||
typedef uint32 dword;
|
typedef uint32 dword;
|
||||||
|
|
||||||
ALIGN16( static __m128i SIMD_SSE2_zero ) = _mm_set_epi32(0, 0, 0, 0);
|
ALIGN16( static __m128i SIMD_SSE2_zero ) = _mm_set_epi32( 0, 0, 0, 0 );
|
||||||
ALIGN16( static dword SIMD_SSE2_dword_byte_mask[4] ) = { 0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF };
|
ALIGN16( static dword SIMD_SSE2_dword_byte_mask[4] ) = { 0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF };
|
||||||
ALIGN16( static dword SIMD_SSE2_dword_word_mask[4] ) = { 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF };
|
ALIGN16( static dword SIMD_SSE2_dword_word_mask[4] ) = { 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF };
|
||||||
ALIGN16( static dword SIMD_SSE2_dword_red_mask[4] ) = { 0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF };
|
ALIGN16( static dword SIMD_SSE2_dword_red_mask[4] ) = { 0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF };
|
||||||
|
|
|
@ -131,7 +131,7 @@ static void R_ShadowVolumeCullBits( byte* cullBits, byte& totalOr, const float r
|
||||||
const __m128 p3Z = _mm_splat_ps( p3, 2 );
|
const __m128 p3Z = _mm_splat_ps( p3, 2 );
|
||||||
const __m128 p3W = _mm_splat_ps( p3, 3 );
|
const __m128 p3W = _mm_splat_ps( p3, 3 );
|
||||||
|
|
||||||
__m128i vecTotalOrInt = _mm_set_epi32(0, 0, 0, 0);
|
__m128i vecTotalOrInt = _mm_set_epi32( 0, 0, 0, 0 );
|
||||||
|
|
||||||
for( int i = 0; i < numVerts; )
|
for( int i = 0; i < numVerts; )
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,7 +83,7 @@ static void R_TracePointCullStatic( byte* cullBits, byte& totalOr, const float r
|
||||||
const __m128 p3Z = _mm_splat_ps( p3, 2 );
|
const __m128 p3Z = _mm_splat_ps( p3, 2 );
|
||||||
const __m128 p3W = _mm_splat_ps( p3, 3 );
|
const __m128 p3W = _mm_splat_ps( p3, 3 );
|
||||||
|
|
||||||
__m128i vecTotalOrInt = _mm_set_epi32(0, 0, 0, 0);
|
__m128i vecTotalOrInt = _mm_set_epi32( 0, 0, 0, 0 );
|
||||||
|
|
||||||
for( int i = 0; i < numVerts; )
|
for( int i = 0; i < numVerts; )
|
||||||
{
|
{
|
||||||
|
@ -218,7 +218,7 @@ static void R_TracePointCullSkinned( byte* cullBits, byte& totalOr, const float
|
||||||
const __m128 p3Z = _mm_splat_ps( p3, 2 );
|
const __m128 p3Z = _mm_splat_ps( p3, 2 );
|
||||||
const __m128 p3W = _mm_splat_ps( p3, 3 );
|
const __m128 p3W = _mm_splat_ps( p3, 3 );
|
||||||
|
|
||||||
__m128i vecTotalOrInt = _mm_set_epi32(0, 0, 0, 0);
|
__m128i vecTotalOrInt = _mm_set_epi32( 0, 0, 0, 0 );
|
||||||
|
|
||||||
for( int i = 0; i < numVerts; )
|
for( int i = 0; i < numVerts; )
|
||||||
{
|
{
|
||||||
|
|
|
@ -489,7 +489,7 @@ public:
|
||||||
sample( NULL ),
|
sample( NULL ),
|
||||||
bufferNumber( 0 )
|
bufferNumber( 0 )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
#ifdef _MSC_VER // XAudio backend
|
#ifdef _MSC_VER // XAudio backend
|
||||||
// DG: because the inheritance is kinda strange (idSoundVoice is derived
|
// DG: because the inheritance is kinda strange (idSoundVoice is derived
|
||||||
// from idSoundVoice_XAudio2), casting the latter to the former isn't possible
|
// from idSoundVoice_XAudio2), casting the latter to the former isn't possible
|
||||||
|
@ -501,7 +501,7 @@ public:
|
||||||
idSoundVoice* voice;
|
idSoundVoice* voice;
|
||||||
idSoundSample* sample;
|
idSoundSample* sample;
|
||||||
#endif // _MSC_VER ; DG end
|
#endif // _MSC_VER ; DG end
|
||||||
|
|
||||||
int bufferNumber;
|
int bufferNumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,14 +73,14 @@ idSoundSample::idSoundSample()
|
||||||
loaded = false;
|
loaded = false;
|
||||||
neverPurge = false;
|
neverPurge = false;
|
||||||
levelLoadReferenced = false;
|
levelLoadReferenced = false;
|
||||||
|
|
||||||
memset( &format, 0, sizeof( format ) );
|
memset( &format, 0, sizeof( format ) );
|
||||||
|
|
||||||
totalBufferSize = 0;
|
totalBufferSize = 0;
|
||||||
|
|
||||||
playBegin = 0;
|
playBegin = 0;
|
||||||
playLength = 0;
|
playLength = 0;
|
||||||
|
|
||||||
lastPlayedTime = 0;
|
lastPlayedTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +131,11 @@ void idSoundSample::WriteAllSamples( const idStr& sampleName )
|
||||||
inName.Append( ".msadpcm" );
|
inName.Append( ".msadpcm" );
|
||||||
idStrStatic< MAX_OSPATH > inName2 = sampleName;
|
idStrStatic< MAX_OSPATH > inName2 = sampleName;
|
||||||
inName2.Append( ".wav" );
|
inName2.Append( ".wav" );
|
||||||
|
|
||||||
idStrStatic< MAX_OSPATH > outName = "generated/";
|
idStrStatic< MAX_OSPATH > outName = "generated/";
|
||||||
outName.Append( sampleName );
|
outName.Append( sampleName );
|
||||||
outName.Append( ".idwav" );
|
outName.Append( ".idwav" );
|
||||||
|
|
||||||
if( samplePC->LoadWav( inName ) || samplePC->LoadWav( inName2 ) )
|
if( samplePC->LoadWav( inName ) || samplePC->LoadWav( inName2 ) )
|
||||||
{
|
{
|
||||||
idFile* fileOut = fileSystem->OpenFileWrite( outName, "fs_basepath" );
|
idFile* fileOut = fileSystem->OpenFileWrite( outName, "fs_basepath" );
|
||||||
|
@ -191,21 +191,21 @@ idSoundSample::Load
|
||||||
void idSoundSample::LoadResource()
|
void idSoundSample::LoadResource()
|
||||||
{
|
{
|
||||||
FreeData();
|
FreeData();
|
||||||
|
|
||||||
if( idStr::Icmpn( GetName(), "_default", 8 ) == 0 )
|
if( idStr::Icmpn( GetName(), "_default", 8 ) == 0 )
|
||||||
{
|
{
|
||||||
MakeDefault();
|
MakeDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( s_noSound.GetBool() )
|
if( s_noSound.GetBool() )
|
||||||
{
|
{
|
||||||
MakeDefault();
|
MakeDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded = false;
|
loaded = false;
|
||||||
|
|
||||||
for( int i = 0; i < 2; i++ )
|
for( int i = 0; i < 2; i++ )
|
||||||
{
|
{
|
||||||
idStrStatic< MAX_OSPATH > sampleName = GetName();
|
idStrStatic< MAX_OSPATH > sampleName = GetName();
|
||||||
|
@ -215,7 +215,7 @@ void idSoundSample::LoadResource()
|
||||||
}
|
}
|
||||||
idStrStatic< MAX_OSPATH > generatedName = "generated/";
|
idStrStatic< MAX_OSPATH > generatedName = "generated/";
|
||||||
generatedName.Append( sampleName );
|
generatedName.Append( sampleName );
|
||||||
|
|
||||||
{
|
{
|
||||||
if( s_useCompression.GetBool() )
|
if( s_useCompression.GetBool() )
|
||||||
{
|
{
|
||||||
|
@ -228,20 +228,20 @@ void idSoundSample::LoadResource()
|
||||||
generatedName.Append( ".idwav" );
|
generatedName.Append( ".idwav" );
|
||||||
}
|
}
|
||||||
loaded = LoadGeneratedSample( generatedName ) || LoadWav( sampleName );
|
loaded = LoadGeneratedSample( generatedName ) || LoadWav( sampleName );
|
||||||
|
|
||||||
if( !loaded && s_useCompression.GetBool() )
|
if( !loaded && s_useCompression.GetBool() )
|
||||||
{
|
{
|
||||||
sampleName.SetFileExtension( "wav" );
|
sampleName.SetFileExtension( "wav" );
|
||||||
loaded = LoadWav( sampleName );
|
loaded = LoadWav( sampleName );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( loaded )
|
if( loaded )
|
||||||
{
|
{
|
||||||
if( cvarSystem->GetCVarBool( "fs_buildresources" ) )
|
if( cvarSystem->GetCVarBool( "fs_buildresources" ) )
|
||||||
{
|
{
|
||||||
fileSystem->AddSamplePreload( GetName() );
|
fileSystem->AddSamplePreload( GetName() );
|
||||||
WriteAllSamples( GetName() );
|
WriteAllSamples( GetName() );
|
||||||
|
|
||||||
if( sampleName.Find( "/vo/" ) >= 0 )
|
if( sampleName.Find( "/vo/" ) >= 0 )
|
||||||
{
|
{
|
||||||
for( int i = 0; i < Sys_NumLangs(); i++ )
|
for( int i = 0; i < Sys_NumLangs(); i++ )
|
||||||
|
@ -260,7 +260,7 @@ void idSoundSample::LoadResource()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !loaded )
|
if( !loaded )
|
||||||
{
|
{
|
||||||
// make it default if everything else fails
|
// make it default if everything else fails
|
||||||
|
@ -283,11 +283,11 @@ bool idSoundSample::LoadWav( const idStr& filename )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
idStrStatic< MAX_OSPATH > sampleName = filename;
|
idStrStatic< MAX_OSPATH > sampleName = filename;
|
||||||
sampleName.SetFileExtension( "amp" );
|
sampleName.SetFileExtension( "amp" );
|
||||||
LoadAmplitude( sampleName );
|
LoadAmplitude( sampleName );
|
||||||
|
|
||||||
const char* formatError = wave.ReadWaveFormat( format );
|
const char* formatError = wave.ReadWaveFormat( format );
|
||||||
if( formatError != NULL )
|
if( formatError != NULL )
|
||||||
{
|
{
|
||||||
|
@ -296,69 +296,69 @@ bool idSoundSample::LoadWav( const idStr& filename )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
timestamp = wave.Timestamp();
|
timestamp = wave.Timestamp();
|
||||||
|
|
||||||
totalBufferSize = wave.SeekToChunk( 'data' );
|
totalBufferSize = wave.SeekToChunk( 'data' );
|
||||||
|
|
||||||
if( format.basic.formatTag == idWaveFile::FORMAT_PCM || format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE )
|
if( format.basic.formatTag == idWaveFile::FORMAT_PCM || format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( format.basic.bitsPerSample != 16 )
|
if( format.basic.bitsPerSample != 16 )
|
||||||
{
|
{
|
||||||
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "Not a 16 bit PCM wav file" );
|
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "Not a 16 bit PCM wav file" );
|
||||||
MakeDefault();
|
MakeDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
playBegin = 0;
|
playBegin = 0;
|
||||||
playLength = ( totalBufferSize ) / format.basic.blockSize;
|
playLength = ( totalBufferSize ) / format.basic.blockSize;
|
||||||
|
|
||||||
buffers.SetNum( 1 );
|
buffers.SetNum( 1 );
|
||||||
buffers[0].bufferSize = totalBufferSize;
|
buffers[0].bufferSize = totalBufferSize;
|
||||||
buffers[0].numSamples = playLength;
|
buffers[0].numSamples = playLength;
|
||||||
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
|
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
|
||||||
|
|
||||||
|
|
||||||
wave.Read( buffers[0].buffer, totalBufferSize );
|
wave.Read( buffers[0].buffer, totalBufferSize );
|
||||||
|
|
||||||
if( format.basic.bitsPerSample == 16 )
|
if( format.basic.bitsPerSample == 16 )
|
||||||
{
|
{
|
||||||
idSwap::LittleArray( ( short* )buffers[0].buffer, totalBufferSize / sizeof( short ) );
|
idSwap::LittleArray( ( short* )buffers[0].buffer, totalBufferSize / sizeof( short ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
||||||
|
|
||||||
}
|
}
|
||||||
else if( format.basic.formatTag == idWaveFile::FORMAT_ADPCM )
|
else if( format.basic.formatTag == idWaveFile::FORMAT_ADPCM )
|
||||||
{
|
{
|
||||||
|
|
||||||
playBegin = 0;
|
playBegin = 0;
|
||||||
playLength = ( ( totalBufferSize / format.basic.blockSize ) * format.extra.adpcm.samplesPerBlock );
|
playLength = ( ( totalBufferSize / format.basic.blockSize ) * format.extra.adpcm.samplesPerBlock );
|
||||||
|
|
||||||
buffers.SetNum( 1 );
|
buffers.SetNum( 1 );
|
||||||
buffers[0].bufferSize = totalBufferSize;
|
buffers[0].bufferSize = totalBufferSize;
|
||||||
buffers[0].numSamples = playLength;
|
buffers[0].numSamples = playLength;
|
||||||
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
|
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
|
||||||
|
|
||||||
wave.Read( buffers[0].buffer, totalBufferSize );
|
wave.Read( buffers[0].buffer, totalBufferSize );
|
||||||
|
|
||||||
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
||||||
|
|
||||||
}
|
}
|
||||||
else if( format.basic.formatTag == idWaveFile::FORMAT_XMA2 )
|
else if( format.basic.formatTag == idWaveFile::FORMAT_XMA2 )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( format.extra.xma2.blockCount == 0 )
|
if( format.extra.xma2.blockCount == 0 )
|
||||||
{
|
{
|
||||||
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "No data blocks in file" );
|
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "No data blocks in file" );
|
||||||
MakeDefault();
|
MakeDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytesPerBlock = format.extra.xma2.bytesPerBlock;
|
int bytesPerBlock = format.extra.xma2.bytesPerBlock;
|
||||||
assert( format.extra.xma2.blockCount == ALIGN( totalBufferSize, bytesPerBlock ) / bytesPerBlock );
|
assert( format.extra.xma2.blockCount == ALIGN( totalBufferSize, bytesPerBlock ) / bytesPerBlock );
|
||||||
assert( format.extra.xma2.blockCount * bytesPerBlock >= totalBufferSize );
|
assert( format.extra.xma2.blockCount * bytesPerBlock >= totalBufferSize );
|
||||||
assert( format.extra.xma2.blockCount * bytesPerBlock < totalBufferSize + bytesPerBlock );
|
assert( format.extra.xma2.blockCount * bytesPerBlock < totalBufferSize + bytesPerBlock );
|
||||||
|
|
||||||
buffers.SetNum( format.extra.xma2.blockCount );
|
buffers.SetNum( format.extra.xma2.blockCount );
|
||||||
for( int i = 0; i < buffers.Num(); i++ )
|
for( int i = 0; i < buffers.Num(); i++ )
|
||||||
{
|
{
|
||||||
|
@ -370,12 +370,12 @@ bool idSoundSample::LoadWav( const idStr& filename )
|
||||||
{
|
{
|
||||||
buffers[i].bufferSize = bytesPerBlock;
|
buffers[i].bufferSize = bytesPerBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffers[i].buffer = AllocBuffer( buffers[i].bufferSize, GetName() );
|
buffers[i].buffer = AllocBuffer( buffers[i].bufferSize, GetName() );
|
||||||
wave.Read( buffers[i].buffer, buffers[i].bufferSize );
|
wave.Read( buffers[i].buffer, buffers[i].bufferSize );
|
||||||
buffers[i].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[i].buffer );
|
buffers[i].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[i].buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
int seekTableSize = wave.SeekToChunk( 'seek' );
|
int seekTableSize = wave.SeekToChunk( 'seek' );
|
||||||
if( seekTableSize != 4 * buffers.Num() )
|
if( seekTableSize != 4 * buffers.Num() )
|
||||||
{
|
{
|
||||||
|
@ -383,16 +383,16 @@ bool idSoundSample::LoadWav( const idStr& filename )
|
||||||
MakeDefault();
|
MakeDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < buffers.Num(); i++ )
|
for( int i = 0; i < buffers.Num(); i++ )
|
||||||
{
|
{
|
||||||
wave.Read( &buffers[i].numSamples, sizeof( buffers[i].numSamples ) );
|
wave.Read( &buffers[i].numSamples, sizeof( buffers[i].numSamples ) );
|
||||||
idSwap::Big( buffers[i].numSamples );
|
idSwap::Big( buffers[i].numSamples );
|
||||||
}
|
}
|
||||||
|
|
||||||
playBegin = format.extra.xma2.loopBegin;
|
playBegin = format.extra.xma2.loopBegin;
|
||||||
playLength = format.extra.xma2.loopLength;
|
playLength = format.extra.xma2.loopLength;
|
||||||
|
|
||||||
if( buffers[buffers.Num() - 1].numSamples < playBegin + playLength )
|
if( buffers[buffers.Num() - 1].numSamples < playBegin + playLength )
|
||||||
{
|
{
|
||||||
// This shouldn't happen, but it's not fatal if it does
|
// This shouldn't happen, but it's not fatal if it does
|
||||||
|
@ -417,7 +417,7 @@ bool idSoundSample::LoadWav( const idStr& filename )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -425,18 +425,18 @@ bool idSoundSample::LoadWav( const idStr& filename )
|
||||||
MakeDefault();
|
MakeDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wave.Close();
|
wave.Close();
|
||||||
|
|
||||||
if( format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE )
|
if( format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE )
|
||||||
{
|
{
|
||||||
// HACK: XAudio2 doesn't really support FORMAT_EXTENSIBLE so we convert it to a basic format after extracting the channel mask
|
// HACK: XAudio2 doesn't really support FORMAT_EXTENSIBLE so we convert it to a basic format after extracting the channel mask
|
||||||
format.basic.formatTag = format.extra.extensible.subFormat.data1;
|
format.basic.formatTag = format.extra.extensible.subFormat.data1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanity check...
|
// sanity check...
|
||||||
assert( buffers[buffers.Num() - 1].numSamples == playBegin + playLength );
|
assert( buffers[buffers.Num() - 1].numSamples == playBegin + playLength );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,12 +449,12 @@ idSoundSample::MakeDefault
|
||||||
void idSoundSample::MakeDefault()
|
void idSoundSample::MakeDefault()
|
||||||
{
|
{
|
||||||
FreeData();
|
FreeData();
|
||||||
|
|
||||||
static const int DEFAULT_NUM_SAMPLES = 256;
|
static const int DEFAULT_NUM_SAMPLES = 256;
|
||||||
|
|
||||||
timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
|
||||||
memset( &format, 0, sizeof( format ) );
|
memset( &format, 0, sizeof( format ) );
|
||||||
format.basic.formatTag = idWaveFile::FORMAT_PCM;
|
format.basic.formatTag = idWaveFile::FORMAT_PCM;
|
||||||
format.basic.numChannels = 1;
|
format.basic.numChannels = 1;
|
||||||
|
@ -462,24 +462,24 @@ void idSoundSample::MakeDefault()
|
||||||
format.basic.samplesPerSec = MIN_SAMPLE_RATE;
|
format.basic.samplesPerSec = MIN_SAMPLE_RATE;
|
||||||
format.basic.blockSize = format.basic.numChannels * format.basic.bitsPerSample / 8;
|
format.basic.blockSize = format.basic.numChannels * format.basic.bitsPerSample / 8;
|
||||||
format.basic.avgBytesPerSec = format.basic.samplesPerSec * format.basic.blockSize;
|
format.basic.avgBytesPerSec = format.basic.samplesPerSec * format.basic.blockSize;
|
||||||
|
|
||||||
assert( format.basic.blockSize == 2 );
|
assert( format.basic.blockSize == 2 );
|
||||||
|
|
||||||
totalBufferSize = DEFAULT_NUM_SAMPLES * 2;
|
totalBufferSize = DEFAULT_NUM_SAMPLES * 2;
|
||||||
|
|
||||||
short* defaultBuffer = ( short* )AllocBuffer( totalBufferSize, GetName() );
|
short* defaultBuffer = ( short* )AllocBuffer( totalBufferSize, GetName() );
|
||||||
for( int i = 0; i < DEFAULT_NUM_SAMPLES; i += 2 )
|
for( int i = 0; i < DEFAULT_NUM_SAMPLES; i += 2 )
|
||||||
{
|
{
|
||||||
defaultBuffer[i + 0] = SHRT_MIN;
|
defaultBuffer[i + 0] = SHRT_MIN;
|
||||||
defaultBuffer[i + 1] = SHRT_MAX;
|
defaultBuffer[i + 1] = SHRT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffers.SetNum( 1 );
|
buffers.SetNum( 1 );
|
||||||
buffers[0].buffer = defaultBuffer;
|
buffers[0].buffer = defaultBuffer;
|
||||||
buffers[0].bufferSize = totalBufferSize;
|
buffers[0].bufferSize = totalBufferSize;
|
||||||
buffers[0].numSamples = DEFAULT_NUM_SAMPLES;
|
buffers[0].numSamples = DEFAULT_NUM_SAMPLES;
|
||||||
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
||||||
|
|
||||||
playBegin = 0;
|
playBegin = 0;
|
||||||
playLength = DEFAULT_NUM_SAMPLES;
|
playLength = DEFAULT_NUM_SAMPLES;
|
||||||
}
|
}
|
||||||
|
@ -503,7 +503,7 @@ void idSoundSample::FreeData()
|
||||||
buffers.Clear();
|
buffers.Clear();
|
||||||
}
|
}
|
||||||
amplitude.Clear();
|
amplitude.Clear();
|
||||||
|
|
||||||
timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||||
memset( &format, 0, sizeof( format ) );
|
memset( &format, 0, sizeof( format ) );
|
||||||
loaded = false;
|
loaded = false;
|
||||||
|
|
|
@ -47,35 +47,41 @@ class idSoundVoice : public idSoundVoice_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Create( const idSoundSample* leadinSample, const idSoundSample* loopingSample ) {}
|
void Create( const idSoundSample* leadinSample, const idSoundSample* loopingSample ) {}
|
||||||
|
|
||||||
// Start playing at a particular point in the buffer. Does an Update() too
|
// Start playing at a particular point in the buffer. Does an Update() too
|
||||||
void Start( int offsetMS, int ssFlags ){}
|
void Start( int offsetMS, int ssFlags ) {}
|
||||||
|
|
||||||
// Stop playing.
|
// Stop playing.
|
||||||
void Stop(){}
|
void Stop() {}
|
||||||
|
|
||||||
// Stop consuming buffers
|
// Stop consuming buffers
|
||||||
void Pause(){}
|
void Pause() {}
|
||||||
// Start consuming buffers again
|
// Start consuming buffers again
|
||||||
void UnPause(){}
|
void UnPause() {}
|
||||||
|
|
||||||
// Sends new position/volume/pitch information to the hardware
|
// Sends new position/volume/pitch information to the hardware
|
||||||
bool Update()
|
bool Update()
|
||||||
{ return false; }
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// returns the RMS levels of the most recently processed block of audio, SSF_FLICKER must have been passed to Start
|
// returns the RMS levels of the most recently processed block of audio, SSF_FLICKER must have been passed to Start
|
||||||
float GetAmplitude()
|
float GetAmplitude()
|
||||||
{ return 0.0f; }
|
{
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
// returns true if we can re-use this voice
|
// returns true if we can re-use this voice
|
||||||
bool CompatibleFormat( idSoundSample* s )
|
bool CompatibleFormat( idSoundSample* s )
|
||||||
{ return false; }
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
uint32 GetSampleRate() const
|
uint32 GetSampleRate() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback function
|
// callback function
|
||||||
void OnBufferStart( idSoundSample* sample, int bufferNumber ) {}
|
void OnBufferStart( idSoundSample* sample, int bufferNumber ) {}
|
||||||
};
|
};
|
||||||
|
@ -83,28 +89,36 @@ public:
|
||||||
class idSoundHardware
|
class idSoundHardware
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
idSoundHardware(){}
|
idSoundHardware() {}
|
||||||
|
|
||||||
void Init(){}
|
void Init() {}
|
||||||
void Shutdown(){}
|
void Shutdown() {}
|
||||||
|
|
||||||
void Update(){}
|
void Update() {}
|
||||||
|
|
||||||
// FIXME: this is a bad name when having multiple sound backends... and maybe it's not even needed
|
// FIXME: this is a bad name when having multiple sound backends... and maybe it's not even needed
|
||||||
void* GetIXAudio2() const // NOTE: originally this returned IXAudio2*, but that was casted to void later anyway
|
void* GetIXAudio2() const // NOTE: originally this returned IXAudio2*, but that was casted to void later anyway
|
||||||
{ return NULL; }
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
idSoundVoice* AllocateVoice( const idSoundSample* leadinSample, const idSoundSample* loopingSample )
|
idSoundVoice* AllocateVoice( const idSoundSample* leadinSample, const idSoundSample* loopingSample )
|
||||||
{ return NULL; }
|
{
|
||||||
|
return NULL;
|
||||||
void FreeVoice( idSoundVoice* voice ){}
|
}
|
||||||
|
|
||||||
|
void FreeVoice( idSoundVoice* voice ) {}
|
||||||
|
|
||||||
int GetNumZombieVoices() const
|
int GetNumZombieVoices() const
|
||||||
{ return 0; }
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int GetNumFreeVoices() const
|
int GetNumFreeVoices() const
|
||||||
{ return 0; }
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ok, this one isn't really a stub, because it seems to be XAudio-independent,
|
// ok, this one isn't really a stub, because it seems to be XAudio-independent,
|
||||||
|
@ -113,12 +127,12 @@ class idSoundSample
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
idSoundSample();
|
idSoundSample();
|
||||||
|
|
||||||
~idSoundSample(); // destructor should be public so lists of soundsamples can be destroyed etc
|
~idSoundSample(); // destructor should be public so lists of soundsamples can be destroyed etc
|
||||||
|
|
||||||
// Loads and initializes the resource based on the name.
|
// Loads and initializes the resource based on the name.
|
||||||
virtual void LoadResource();
|
virtual void LoadResource();
|
||||||
|
|
||||||
void SetName( const char* n )
|
void SetName( const char* n )
|
||||||
{
|
{
|
||||||
name = n;
|
name = n;
|
||||||
|
@ -131,13 +145,13 @@ public:
|
||||||
{
|
{
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// turns it into a beep
|
// turns it into a beep
|
||||||
void MakeDefault();
|
void MakeDefault();
|
||||||
|
|
||||||
// frees all data
|
// frees all data
|
||||||
void FreeData();
|
void FreeData();
|
||||||
|
|
||||||
int LengthInMsec() const
|
int LengthInMsec() const
|
||||||
{
|
{
|
||||||
return SamplesToMsec( NumSamples(), SampleRate() );
|
return SamplesToMsec( NumSamples(), SampleRate() );
|
||||||
|
@ -158,12 +172,12 @@ public:
|
||||||
{
|
{
|
||||||
return totalBufferSize;
|
return totalBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCompressed() const
|
bool IsCompressed() const
|
||||||
{
|
{
|
||||||
return ( format.basic.formatTag != idWaveFile::FORMAT_PCM );
|
return ( format.basic.formatTag != idWaveFile::FORMAT_PCM );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const
|
bool IsDefault() const
|
||||||
{
|
{
|
||||||
return timestamp == FILE_NOT_FOUND_TIMESTAMP;
|
return timestamp == FILE_NOT_FOUND_TIMESTAMP;
|
||||||
|
@ -172,7 +186,7 @@ public:
|
||||||
{
|
{
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNeverPurge()
|
void SetNeverPurge()
|
||||||
{
|
{
|
||||||
neverPurge = true;
|
neverPurge = true;
|
||||||
|
@ -181,7 +195,7 @@ public:
|
||||||
{
|
{
|
||||||
return neverPurge;
|
return neverPurge;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetLevelLoadReferenced()
|
void SetLevelLoadReferenced()
|
||||||
{
|
{
|
||||||
levelLoadReferenced = true;
|
levelLoadReferenced = true;
|
||||||
|
@ -194,7 +208,7 @@ public:
|
||||||
{
|
{
|
||||||
return levelLoadReferenced;
|
return levelLoadReferenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetLastPlayedTime() const
|
int GetLastPlayedTime() const
|
||||||
{
|
{
|
||||||
return lastPlayedTime;
|
return lastPlayedTime;
|
||||||
|
@ -203,48 +217,48 @@ public:
|
||||||
{
|
{
|
||||||
lastPlayedTime = t;
|
lastPlayedTime = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetAmplitude( int timeMS ) const;
|
float GetAmplitude( int timeMS ) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
friend class idSoundHardware_XAudio2;
|
friend class idSoundHardware_XAudio2;
|
||||||
friend class idSoundVoice_XAudio2;
|
friend class idSoundVoice_XAudio2;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool LoadWav( const idStr& name );
|
bool LoadWav( const idStr& name );
|
||||||
bool LoadAmplitude( const idStr& name );
|
bool LoadAmplitude( const idStr& name );
|
||||||
void WriteAllSamples( const idStr& sampleName );
|
void WriteAllSamples( const idStr& sampleName );
|
||||||
bool LoadGeneratedSample( const idStr& name );
|
bool LoadGeneratedSample( const idStr& name );
|
||||||
void WriteGeneratedSample( idFile* fileOut );
|
void WriteGeneratedSample( idFile* fileOut );
|
||||||
|
|
||||||
struct sampleBuffer_t
|
struct sampleBuffer_t
|
||||||
{
|
{
|
||||||
void* buffer;
|
void* buffer;
|
||||||
int bufferSize;
|
int bufferSize;
|
||||||
int numSamples;
|
int numSamples;
|
||||||
};
|
};
|
||||||
|
|
||||||
idStr name;
|
idStr name;
|
||||||
|
|
||||||
ID_TIME_T timestamp;
|
ID_TIME_T timestamp;
|
||||||
bool loaded;
|
bool loaded;
|
||||||
|
|
||||||
bool neverPurge;
|
bool neverPurge;
|
||||||
bool levelLoadReferenced;
|
bool levelLoadReferenced;
|
||||||
bool usesMapHeap;
|
bool usesMapHeap;
|
||||||
|
|
||||||
uint32 lastPlayedTime;
|
uint32 lastPlayedTime;
|
||||||
|
|
||||||
int totalBufferSize; // total size of all the buffers
|
int totalBufferSize; // total size of all the buffers
|
||||||
idList<sampleBuffer_t, TAG_AUDIO> buffers;
|
idList<sampleBuffer_t, TAG_AUDIO> buffers;
|
||||||
|
|
||||||
int playBegin;
|
int playBegin;
|
||||||
int playLength;
|
int playLength;
|
||||||
|
|
||||||
idWaveFile::waveFmt_t format;
|
idWaveFile::waveFmt_t format;
|
||||||
|
|
||||||
idList<byte, TAG_AMPLITUDE> amplitude;
|
idList<byte, TAG_AMPLITUDE> amplitude;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -993,7 +993,7 @@ bool R_GetModeListForDisplay( const int requestedDisplayNum, idList<vidMode_t>&
|
||||||
mode.displayHz = devmode.dmDisplayFrequency;
|
mode.displayHz = devmode.dmDisplayFrequency;
|
||||||
modeList.AddUnique( mode );
|
modeList.AddUnique( mode );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( modeList.Num() > 0 )
|
if( modeList.Num() > 0 )
|
||||||
{
|
{
|
||||||
// sort with lowest resolution first
|
// sort with lowest resolution first
|
||||||
|
|
|
@ -686,7 +686,7 @@ int Sys_PollMouseInputEvents( int mouseEvents[MAX_MOUSE_EVENTS][2] )
|
||||||
{
|
{
|
||||||
// RB: replaced switch enum for MinGW
|
// RB: replaced switch enum for MinGW
|
||||||
int diaction = polled_didod[i].dwOfs;
|
int diaction = polled_didod[i].dwOfs;
|
||||||
|
|
||||||
if( diaction == DIMOFS_X )
|
if( diaction == DIMOFS_X )
|
||||||
{
|
{
|
||||||
mouseEvents[i][0] = M_DELTAX;
|
mouseEvents[i][0] = M_DELTAX;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
===========================================================================
|
===========================================================================
|
||||||
|
|
||||||
Doom 3 BFG Edition GPL Source Code
|
Doom 3 BFG Edition GPL Source Code
|
||||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||||
|
|
||||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||||
|
|
||||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -68,7 +68,8 @@ If you have questions concerning this license or the applicable additional terms
|
||||||
Sys_Milliseconds
|
Sys_Milliseconds
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
int Sys_Milliseconds() {
|
int Sys_Milliseconds()
|
||||||
|
{
|
||||||
static DWORD sys_timeBase = timeGetTime();
|
static DWORD sys_timeBase = timeGetTime();
|
||||||
return timeGetTime() - sys_timeBase;
|
return timeGetTime() - sys_timeBase;
|
||||||
}
|
}
|
||||||
|
@ -78,15 +79,17 @@ int Sys_Milliseconds() {
|
||||||
Sys_Microseconds
|
Sys_Microseconds
|
||||||
========================
|
========================
|
||||||
*/
|
*/
|
||||||
uint64 Sys_Microseconds() {
|
uint64 Sys_Microseconds()
|
||||||
|
{
|
||||||
static uint64 ticksPerMicrosecondTimes1024 = 0;
|
static uint64 ticksPerMicrosecondTimes1024 = 0;
|
||||||
|
|
||||||
if ( ticksPerMicrosecondTimes1024 == 0 ) {
|
if( ticksPerMicrosecondTimes1024 == 0 )
|
||||||
ticksPerMicrosecondTimes1024 = ( (uint64)Sys_ClockTicksPerSecond() << 10 ) / 1000000;
|
{
|
||||||
|
ticksPerMicrosecondTimes1024 = ( ( uint64 )Sys_ClockTicksPerSecond() << 10 ) / 1000000;
|
||||||
assert( ticksPerMicrosecondTimes1024 > 0 );
|
assert( ticksPerMicrosecondTimes1024 > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((uint64)( (int64)Sys_GetClockTicks() << 10 )) / ticksPerMicrosecondTimes1024;
|
return ( ( uint64 )( ( int64 )Sys_GetClockTicks() << 10 ) ) / ticksPerMicrosecondTimes1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -96,10 +99,11 @@ Sys_GetSystemRam
|
||||||
returns amount of physical memory in MB
|
returns amount of physical memory in MB
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
int Sys_GetSystemRam() {
|
int Sys_GetSystemRam()
|
||||||
|
{
|
||||||
MEMORYSTATUSEX statex;
|
MEMORYSTATUSEX statex;
|
||||||
statex.dwLength = sizeof ( statex );
|
statex.dwLength = sizeof( statex );
|
||||||
GlobalMemoryStatusEx (&statex);
|
GlobalMemoryStatusEx( &statex );
|
||||||
int physRam = statex.ullTotalPhys / ( 1024 * 1024 );
|
int physRam = statex.ullTotalPhys / ( 1024 * 1024 );
|
||||||
// HACK: For some reason, ullTotalPhys is sometimes off by a meg or two, so we round up to the nearest 16 megs
|
// HACK: For some reason, ullTotalPhys is sometimes off by a meg or two, so we round up to the nearest 16 megs
|
||||||
physRam = ( physRam + 8 ) & ~15;
|
physRam = ( physRam + 8 ) & ~15;
|
||||||
|
@ -113,13 +117,15 @@ Sys_GetDriveFreeSpace
|
||||||
returns in megabytes
|
returns in megabytes
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
int Sys_GetDriveFreeSpace( const char *path ) {
|
int Sys_GetDriveFreeSpace( const char* path )
|
||||||
|
{
|
||||||
DWORDLONG lpFreeBytesAvailable;
|
DWORDLONG lpFreeBytesAvailable;
|
||||||
DWORDLONG lpTotalNumberOfBytes;
|
DWORDLONG lpTotalNumberOfBytes;
|
||||||
DWORDLONG lpTotalNumberOfFreeBytes;
|
DWORDLONG lpTotalNumberOfFreeBytes;
|
||||||
int ret = 26;
|
int ret = 26;
|
||||||
//FIXME: see why this is failing on some machines
|
//FIXME: see why this is failing on some machines
|
||||||
if ( ::GetDiskFreeSpaceEx( path, (PULARGE_INTEGER)&lpFreeBytesAvailable, (PULARGE_INTEGER)&lpTotalNumberOfBytes, (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes ) ) {
|
if( ::GetDiskFreeSpaceEx( path, ( PULARGE_INTEGER )&lpFreeBytesAvailable, ( PULARGE_INTEGER )&lpTotalNumberOfBytes, ( PULARGE_INTEGER )&lpTotalNumberOfFreeBytes ) )
|
||||||
|
{
|
||||||
ret = ( double )( lpFreeBytesAvailable ) / ( 1024.0 * 1024.0 );
|
ret = ( double )( lpFreeBytesAvailable ) / ( 1024.0 * 1024.0 );
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -130,13 +136,15 @@ int Sys_GetDriveFreeSpace( const char *path ) {
|
||||||
Sys_GetDriveFreeSpaceInBytes
|
Sys_GetDriveFreeSpaceInBytes
|
||||||
========================
|
========================
|
||||||
*/
|
*/
|
||||||
int64 Sys_GetDriveFreeSpaceInBytes( const char * path ) {
|
int64 Sys_GetDriveFreeSpaceInBytes( const char* path )
|
||||||
|
{
|
||||||
DWORDLONG lpFreeBytesAvailable;
|
DWORDLONG lpFreeBytesAvailable;
|
||||||
DWORDLONG lpTotalNumberOfBytes;
|
DWORDLONG lpTotalNumberOfBytes;
|
||||||
DWORDLONG lpTotalNumberOfFreeBytes;
|
DWORDLONG lpTotalNumberOfFreeBytes;
|
||||||
int64 ret = 1;
|
int64 ret = 1;
|
||||||
//FIXME: see why this is failing on some machines
|
//FIXME: see why this is failing on some machines
|
||||||
if ( ::GetDiskFreeSpaceEx( path, (PULARGE_INTEGER)&lpFreeBytesAvailable, (PULARGE_INTEGER)&lpTotalNumberOfBytes, (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes ) ) {
|
if( ::GetDiskFreeSpaceEx( path, ( PULARGE_INTEGER )&lpFreeBytesAvailable, ( PULARGE_INTEGER )&lpTotalNumberOfBytes, ( PULARGE_INTEGER )&lpTotalNumberOfFreeBytes ) )
|
||||||
|
{
|
||||||
ret = lpFreeBytesAvailable;
|
ret = lpFreeBytesAvailable;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -148,57 +156,65 @@ Sys_GetVideoRam
|
||||||
returns in megabytes
|
returns in megabytes
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
int Sys_GetVideoRam() {
|
int Sys_GetVideoRam()
|
||||||
|
{
|
||||||
unsigned int retSize = 64;
|
unsigned int retSize = 64;
|
||||||
|
|
||||||
// RB begin
|
// RB begin
|
||||||
#if !defined(__MINGW32__)
|
#if !defined(__MINGW32__)
|
||||||
CComPtr<IWbemLocator> spLoc = NULL;
|
CComPtr<IWbemLocator> spLoc = NULL;
|
||||||
HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID * ) &spLoc );
|
HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID* ) &spLoc );
|
||||||
if ( hr != S_OK || spLoc == NULL ) {
|
if( hr != S_OK || spLoc == NULL )
|
||||||
|
{
|
||||||
return retSize;
|
return retSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
CComBSTR bstrNamespace( _T( "\\\\.\\root\\CIMV2" ) );
|
CComBSTR bstrNamespace( _T( "\\\\.\\root\\CIMV2" ) );
|
||||||
CComPtr<IWbemServices> spServices;
|
CComPtr<IWbemServices> spServices;
|
||||||
|
|
||||||
// Connect to CIM
|
// Connect to CIM
|
||||||
hr = spLoc->ConnectServer( bstrNamespace, NULL, NULL, 0, NULL, 0, 0, &spServices );
|
hr = spLoc->ConnectServer( bstrNamespace, NULL, NULL, 0, NULL, 0, 0, &spServices );
|
||||||
if ( hr != WBEM_S_NO_ERROR ) {
|
if( hr != WBEM_S_NO_ERROR )
|
||||||
|
{
|
||||||
return retSize;
|
return retSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch the security level to IMPERSONATE so that provider will grant access to system-level objects.
|
// Switch the security level to IMPERSONATE so that provider will grant access to system-level objects.
|
||||||
hr = CoSetProxyBlanket( spServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
|
hr = CoSetProxyBlanket( spServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
|
||||||
if ( hr != S_OK ) {
|
if( hr != S_OK )
|
||||||
|
{
|
||||||
return retSize;
|
return retSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the vid controller
|
// Get the vid controller
|
||||||
CComPtr<IEnumWbemClassObject> spEnumInst = NULL;
|
CComPtr<IEnumWbemClassObject> spEnumInst = NULL;
|
||||||
hr = spServices->CreateInstanceEnum( CComBSTR( "Win32_VideoController" ), WBEM_FLAG_SHALLOW, NULL, &spEnumInst );
|
hr = spServices->CreateInstanceEnum( CComBSTR( "Win32_VideoController" ), WBEM_FLAG_SHALLOW, NULL, &spEnumInst );
|
||||||
if ( hr != WBEM_S_NO_ERROR || spEnumInst == NULL ) {
|
if( hr != WBEM_S_NO_ERROR || spEnumInst == NULL )
|
||||||
|
{
|
||||||
return retSize;
|
return retSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG uNumOfInstances = 0;
|
ULONG uNumOfInstances = 0;
|
||||||
CComPtr<IWbemClassObject> spInstance = NULL;
|
CComPtr<IWbemClassObject> spInstance = NULL;
|
||||||
hr = spEnumInst->Next( 10000, 1, &spInstance, &uNumOfInstances );
|
hr = spEnumInst->Next( 10000, 1, &spInstance, &uNumOfInstances );
|
||||||
|
|
||||||
if ( hr == S_OK && spInstance ) {
|
if( hr == S_OK && spInstance )
|
||||||
|
{
|
||||||
// Get properties from the object
|
// Get properties from the object
|
||||||
CComVariant varSize;
|
CComVariant varSize;
|
||||||
hr = spInstance->Get( CComBSTR( _T( "AdapterRAM" ) ), 0, &varSize, 0, 0 );
|
hr = spInstance->Get( CComBSTR( _T( "AdapterRAM" ) ), 0, &varSize, 0, 0 );
|
||||||
if ( hr == S_OK ) {
|
if( hr == S_OK )
|
||||||
|
{
|
||||||
retSize = varSize.intVal / ( 1024 * 1024 );
|
retSize = varSize.intVal / ( 1024 * 1024 );
|
||||||
if ( retSize == 0 ) {
|
if( retSize == 0 )
|
||||||
|
{
|
||||||
retSize = 64;
|
retSize = 64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// RB end
|
// RB end
|
||||||
|
|
||||||
return retSize;
|
return retSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,37 +226,38 @@ Sys_GetCurrentMemoryStatus
|
||||||
all values are in kB except the memoryload
|
all values are in kB except the memoryload
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
void Sys_GetCurrentMemoryStatus( sysMemoryStats_t &stats ) {
|
void Sys_GetCurrentMemoryStatus( sysMemoryStats_t& stats )
|
||||||
|
{
|
||||||
MEMORYSTATUSEX statex = {};
|
MEMORYSTATUSEX statex = {};
|
||||||
unsigned __int64 work;
|
unsigned __int64 work;
|
||||||
|
|
||||||
statex.dwLength = sizeof( statex );
|
statex.dwLength = sizeof( statex );
|
||||||
GlobalMemoryStatusEx( &statex );
|
GlobalMemoryStatusEx( &statex );
|
||||||
|
|
||||||
memset( &stats, 0, sizeof( stats ) );
|
memset( &stats, 0, sizeof( stats ) );
|
||||||
|
|
||||||
stats.memoryLoad = statex.dwMemoryLoad;
|
stats.memoryLoad = statex.dwMemoryLoad;
|
||||||
|
|
||||||
work = statex.ullTotalPhys >> 20;
|
work = statex.ullTotalPhys >> 20;
|
||||||
stats.totalPhysical = *(int*)&work;
|
stats.totalPhysical = *( int* )&work;
|
||||||
|
|
||||||
work = statex.ullAvailPhys >> 20;
|
work = statex.ullAvailPhys >> 20;
|
||||||
stats.availPhysical = *(int*)&work;
|
stats.availPhysical = *( int* )&work;
|
||||||
|
|
||||||
work = statex.ullAvailPageFile >> 20;
|
work = statex.ullAvailPageFile >> 20;
|
||||||
stats.availPageFile = *(int*)&work;
|
stats.availPageFile = *( int* )&work;
|
||||||
|
|
||||||
work = statex.ullTotalPageFile >> 20;
|
work = statex.ullTotalPageFile >> 20;
|
||||||
stats.totalPageFile = *(int*)&work;
|
stats.totalPageFile = *( int* )&work;
|
||||||
|
|
||||||
work = statex.ullTotalVirtual >> 20;
|
work = statex.ullTotalVirtual >> 20;
|
||||||
stats.totalVirtual = *(int*)&work;
|
stats.totalVirtual = *( int* )&work;
|
||||||
|
|
||||||
work = statex.ullAvailVirtual >> 20;
|
work = statex.ullAvailVirtual >> 20;
|
||||||
stats.availVirtual = *(int*)&work;
|
stats.availVirtual = *( int* )&work;
|
||||||
|
|
||||||
work = statex.ullAvailExtendedVirtual >> 20;
|
work = statex.ullAvailExtendedVirtual >> 20;
|
||||||
stats.availExtendedVirtual = *(int*)&work;
|
stats.availExtendedVirtual = *( int* )&work;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -248,8 +265,9 @@ void Sys_GetCurrentMemoryStatus( sysMemoryStats_t &stats ) {
|
||||||
Sys_LockMemory
|
Sys_LockMemory
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
bool Sys_LockMemory( void *ptr, int bytes ) {
|
bool Sys_LockMemory( void* ptr, int bytes )
|
||||||
return ( VirtualLock( ptr, (SIZE_T)bytes ) != FALSE );
|
{
|
||||||
|
return ( VirtualLock( ptr, ( SIZE_T )bytes ) != FALSE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -257,8 +275,9 @@ bool Sys_LockMemory( void *ptr, int bytes ) {
|
||||||
Sys_UnlockMemory
|
Sys_UnlockMemory
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
bool Sys_UnlockMemory( void *ptr, int bytes ) {
|
bool Sys_UnlockMemory( void* ptr, int bytes )
|
||||||
return ( VirtualUnlock( ptr, (SIZE_T)bytes ) != FALSE );
|
{
|
||||||
|
return ( VirtualUnlock( ptr, ( SIZE_T )bytes ) != FALSE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -266,7 +285,8 @@ bool Sys_UnlockMemory( void *ptr, int bytes ) {
|
||||||
Sys_SetPhysicalWorkMemory
|
Sys_SetPhysicalWorkMemory
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes ) {
|
void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes )
|
||||||
|
{
|
||||||
::SetProcessWorkingSetSize( GetCurrentProcess(), minBytes, maxBytes );
|
::SetProcessWorkingSetSize( GetCurrentProcess(), minBytes, maxBytes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,19 +295,22 @@ void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes ) {
|
||||||
Sys_GetCurrentUser
|
Sys_GetCurrentUser
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
char *Sys_GetCurrentUser() {
|
char* Sys_GetCurrentUser()
|
||||||
|
{
|
||||||
static char s_userName[1024];
|
static char s_userName[1024];
|
||||||
unsigned long size = sizeof( s_userName );
|
unsigned long size = sizeof( s_userName );
|
||||||
|
|
||||||
|
|
||||||
if ( !GetUserName( s_userName, &size ) ) {
|
if( !GetUserName( s_userName, &size ) )
|
||||||
|
{
|
||||||
strcpy( s_userName, "player" );
|
strcpy( s_userName, "player" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !s_userName[0] ) {
|
if( !s_userName[0] )
|
||||||
|
{
|
||||||
strcpy( s_userName, "player" );
|
strcpy( s_userName, "player" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return s_userName;
|
return s_userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,13 +58,13 @@ static void WIN_DisableAltTab()
|
||||||
{
|
{
|
||||||
BOOL old;
|
BOOL old;
|
||||||
|
|
||||||
// RB begin
|
// RB begin
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 );
|
SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 );
|
||||||
#else
|
#else
|
||||||
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
|
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
|
||||||
#endif
|
#endif
|
||||||
// RB end
|
// RB end
|
||||||
}
|
}
|
||||||
s_alttab_disabled = true;
|
s_alttab_disabled = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue