Formatted code

This commit is contained in:
Robert Beckebans 2012-12-04 12:11:14 +01:00
parent 5e582222cf
commit afaf66ef40
17 changed files with 237 additions and 200 deletions

View file

@ -1,4 +1,4 @@
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

View file

@ -63,10 +63,10 @@ bool SpursEmulationAssertFailed( const char* filename, int line, const char* exp
#endif
#else // not _WIN32
// DG: POSIX support
raise(SIGTRAP);
raise( SIGTRAP );
// DG: end
#endif // _WIN32
}
return true;
}

View file

@ -401,7 +401,7 @@ public:
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 );
/*
================================================================================================

View file

@ -698,8 +698,8 @@ ID_INLINE void idMath::SinCos( float a, float& s, float& c )
}
#else
// DG: non-MSVC version
s = sinf(a);
c = cosf(a);
s = sinf( a );
c = cosf( a );
// DG end
#endif
}

View file

@ -93,7 +93,7 @@ bool AssertFailed( const char* file, int line, const char* expression )
#endif
#else // not _WIN32
// DG: POSIX support
raise(SIGTRAP);
raise( SIGTRAP );
// DG: end
#endif // _WIN32
}

View file

@ -59,7 +59,7 @@ If you have questions concerning this license or the applicable additional terms
#ifdef _MSC_VER
#include <dsound.h>
#else
#else
// DG: MinGW is incompatible with the original dsound.h because it contains MSVC specific annotations
#include <wine-dsound.h>

View file

@ -64,14 +64,14 @@ static void Sys_SetThreadName( DWORD threadID, const char* name )
#ifdef _MSC_VER
// this ugly mess is the official way to set a thread name on windows..
// see http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
info.dwThreadID = threadID;
info.dwFlags = 0;
__try
{
RaiseException( MS_VC_EXCEPTION, 0, sizeof( info ) / sizeof( DWORD ), ( const ULONG_PTR* )&info );

View file

@ -55,7 +55,7 @@ Contains the DxtEncoder implementation for SSE2.
typedef uint16 word;
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_word_mask[4] ) = { 0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF };
ALIGN16( static dword SIMD_SSE2_dword_red_mask[4] ) = { 0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF };

View file

@ -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 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; )
{

View file

@ -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 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; )
{
@ -218,7 +218,7 @@ static void R_TracePointCullSkinned( byte* cullBits, byte& totalOr, const float
const __m128 p3Z = _mm_splat_ps( p3, 2 );
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; )
{

View file

@ -489,7 +489,7 @@ public:
sample( NULL ),
bufferNumber( 0 )
{ }
#ifdef _MSC_VER // XAudio backend
// DG: because the inheritance is kinda strange (idSoundVoice is derived
// from idSoundVoice_XAudio2), casting the latter to the former isn't possible
@ -501,7 +501,7 @@ public:
idSoundVoice* voice;
idSoundSample* sample;
#endif // _MSC_VER ; DG end
int bufferNumber;
};

View file

@ -73,14 +73,14 @@ idSoundSample::idSoundSample()
loaded = false;
neverPurge = false;
levelLoadReferenced = false;
memset( &format, 0, sizeof( format ) );
totalBufferSize = 0;
playBegin = 0;
playLength = 0;
lastPlayedTime = 0;
}
@ -131,11 +131,11 @@ void idSoundSample::WriteAllSamples( const idStr& sampleName )
inName.Append( ".msadpcm" );
idStrStatic< MAX_OSPATH > inName2 = sampleName;
inName2.Append( ".wav" );
idStrStatic< MAX_OSPATH > outName = "generated/";
outName.Append( sampleName );
outName.Append( ".idwav" );
if( samplePC->LoadWav( inName ) || samplePC->LoadWav( inName2 ) )
{
idFile* fileOut = fileSystem->OpenFileWrite( outName, "fs_basepath" );
@ -191,21 +191,21 @@ idSoundSample::Load
void idSoundSample::LoadResource()
{
FreeData();
if( idStr::Icmpn( GetName(), "_default", 8 ) == 0 )
{
MakeDefault();
return;
}
if( s_noSound.GetBool() )
{
MakeDefault();
return;
}
loaded = false;
for( int i = 0; i < 2; i++ )
{
idStrStatic< MAX_OSPATH > sampleName = GetName();
@ -215,7 +215,7 @@ void idSoundSample::LoadResource()
}
idStrStatic< MAX_OSPATH > generatedName = "generated/";
generatedName.Append( sampleName );
{
if( s_useCompression.GetBool() )
{
@ -228,20 +228,20 @@ void idSoundSample::LoadResource()
generatedName.Append( ".idwav" );
}
loaded = LoadGeneratedSample( generatedName ) || LoadWav( sampleName );
if( !loaded && s_useCompression.GetBool() )
{
sampleName.SetFileExtension( "wav" );
loaded = LoadWav( sampleName );
}
if( loaded )
{
if( cvarSystem->GetCVarBool( "fs_buildresources" ) )
{
fileSystem->AddSamplePreload( GetName() );
WriteAllSamples( GetName() );
if( sampleName.Find( "/vo/" ) >= 0 )
{
for( int i = 0; i < Sys_NumLangs(); i++ )
@ -260,7 +260,7 @@ void idSoundSample::LoadResource()
return;
}
}
if( !loaded )
{
// make it default if everything else fails
@ -283,11 +283,11 @@ bool idSoundSample::LoadWav( const idStr& filename )
{
return false;
}
idStrStatic< MAX_OSPATH > sampleName = filename;
sampleName.SetFileExtension( "amp" );
LoadAmplitude( sampleName );
const char* formatError = wave.ReadWaveFormat( format );
if( formatError != NULL )
{
@ -296,69 +296,69 @@ bool idSoundSample::LoadWav( const idStr& filename )
return false;
}
timestamp = wave.Timestamp();
totalBufferSize = wave.SeekToChunk( 'data' );
if( format.basic.formatTag == idWaveFile::FORMAT_PCM || format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE )
{
if( format.basic.bitsPerSample != 16 )
{
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "Not a 16 bit PCM wav file" );
MakeDefault();
return false;
}
playBegin = 0;
playLength = ( totalBufferSize ) / format.basic.blockSize;
buffers.SetNum( 1 );
buffers[0].bufferSize = totalBufferSize;
buffers[0].numSamples = playLength;
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
wave.Read( buffers[0].buffer, totalBufferSize );
if( format.basic.bitsPerSample == 16 )
{
idSwap::LittleArray( ( short* )buffers[0].buffer, totalBufferSize / sizeof( short ) );
}
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
}
else if( format.basic.formatTag == idWaveFile::FORMAT_ADPCM )
{
playBegin = 0;
playLength = ( ( totalBufferSize / format.basic.blockSize ) * format.extra.adpcm.samplesPerBlock );
buffers.SetNum( 1 );
buffers[0].bufferSize = totalBufferSize;
buffers[0].numSamples = playLength;
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
wave.Read( buffers[0].buffer, totalBufferSize );
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
}
else if( format.basic.formatTag == idWaveFile::FORMAT_XMA2 )
{
if( format.extra.xma2.blockCount == 0 )
{
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "No data blocks in file" );
MakeDefault();
return false;
}
int bytesPerBlock = format.extra.xma2.bytesPerBlock;
assert( format.extra.xma2.blockCount == ALIGN( totalBufferSize, bytesPerBlock ) / bytesPerBlock );
assert( format.extra.xma2.blockCount * bytesPerBlock >= totalBufferSize );
assert( format.extra.xma2.blockCount * bytesPerBlock < totalBufferSize + bytesPerBlock );
buffers.SetNum( format.extra.xma2.blockCount );
for( int i = 0; i < buffers.Num(); i++ )
{
@ -370,12 +370,12 @@ bool idSoundSample::LoadWav( const idStr& filename )
{
buffers[i].bufferSize = bytesPerBlock;
}
buffers[i].buffer = AllocBuffer( buffers[i].bufferSize, GetName() );
wave.Read( buffers[i].buffer, buffers[i].bufferSize );
buffers[i].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[i].buffer );
}
int seekTableSize = wave.SeekToChunk( 'seek' );
if( seekTableSize != 4 * buffers.Num() )
{
@ -383,16 +383,16 @@ bool idSoundSample::LoadWav( const idStr& filename )
MakeDefault();
return false;
}
for( int i = 0; i < buffers.Num(); i++ )
{
wave.Read( &buffers[i].numSamples, sizeof( buffers[i].numSamples ) );
idSwap::Big( buffers[i].numSamples );
}
playBegin = format.extra.xma2.loopBegin;
playLength = format.extra.xma2.loopLength;
if( buffers[buffers.Num() - 1].numSamples < playBegin + playLength )
{
// This shouldn't happen, but it's not fatal if it does
@ -417,7 +417,7 @@ bool idSoundSample::LoadWav( const idStr& filename )
}
}
}
}
else
{
@ -425,18 +425,18 @@ bool idSoundSample::LoadWav( const idStr& filename )
MakeDefault();
return false;
}
wave.Close();
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
format.basic.formatTag = format.extra.extensible.subFormat.data1;
}
// sanity check...
assert( buffers[buffers.Num() - 1].numSamples == playBegin + playLength );
return true;
}
@ -449,12 +449,12 @@ idSoundSample::MakeDefault
void idSoundSample::MakeDefault()
{
FreeData();
static const int DEFAULT_NUM_SAMPLES = 256;
timestamp = FILE_NOT_FOUND_TIMESTAMP;
loaded = true;
memset( &format, 0, sizeof( format ) );
format.basic.formatTag = idWaveFile::FORMAT_PCM;
format.basic.numChannels = 1;
@ -462,24 +462,24 @@ void idSoundSample::MakeDefault()
format.basic.samplesPerSec = MIN_SAMPLE_RATE;
format.basic.blockSize = format.basic.numChannels * format.basic.bitsPerSample / 8;
format.basic.avgBytesPerSec = format.basic.samplesPerSec * format.basic.blockSize;
assert( format.basic.blockSize == 2 );
totalBufferSize = DEFAULT_NUM_SAMPLES * 2;
short* defaultBuffer = ( short* )AllocBuffer( totalBufferSize, GetName() );
for( int i = 0; i < DEFAULT_NUM_SAMPLES; i += 2 )
{
defaultBuffer[i + 0] = SHRT_MIN;
defaultBuffer[i + 1] = SHRT_MAX;
}
buffers.SetNum( 1 );
buffers[0].buffer = defaultBuffer;
buffers[0].bufferSize = totalBufferSize;
buffers[0].numSamples = DEFAULT_NUM_SAMPLES;
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
playBegin = 0;
playLength = DEFAULT_NUM_SAMPLES;
}
@ -503,7 +503,7 @@ void idSoundSample::FreeData()
buffers.Clear();
}
amplitude.Clear();
timestamp = FILE_NOT_FOUND_TIMESTAMP;
memset( &format, 0, sizeof( format ) );
loaded = false;

View file

@ -47,35 +47,41 @@ class idSoundVoice : public idSoundVoice_Base
{
public:
void Create( const idSoundSample* leadinSample, const idSoundSample* loopingSample ) {}
// 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.
void Stop(){}
void Stop() {}
// Stop consuming buffers
void Pause(){}
void Pause() {}
// Start consuming buffers again
void UnPause(){}
void UnPause() {}
// Sends new position/volume/pitch information to the hardware
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
float GetAmplitude()
{ return 0.0f; }
{
return 0.0f;
}
// returns true if we can re-use this voice
bool CompatibleFormat( idSoundSample* s )
{ return false; }
{
return false;
}
uint32 GetSampleRate() const
{
return 0;
}
// callback function
void OnBufferStart( idSoundSample* sample, int bufferNumber ) {}
};
@ -83,28 +89,36 @@ public:
class idSoundHardware
{
public:
idSoundHardware(){}
void Init(){}
void Shutdown(){}
void Update(){}
idSoundHardware() {}
void Init() {}
void Shutdown() {}
void Update() {}
// 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
{ return NULL; }
{
return NULL;
}
idSoundVoice* AllocateVoice( const idSoundSample* leadinSample, const idSoundSample* loopingSample )
{ return NULL; }
void FreeVoice( idSoundVoice* voice ){}
{
return NULL;
}
void FreeVoice( idSoundVoice* voice ) {}
int GetNumZombieVoices() const
{ return 0; }
{
return 0;
}
int GetNumFreeVoices() const
{ return 0; }
{
return 0;
}
};
// ok, this one isn't really a stub, because it seems to be XAudio-independent,
@ -113,12 +127,12 @@ class idSoundSample
{
public:
idSoundSample();
~idSoundSample(); // destructor should be public so lists of soundsamples can be destroyed etc
// Loads and initializes the resource based on the name.
virtual void LoadResource();
void SetName( const char* n )
{
name = n;
@ -131,13 +145,13 @@ public:
{
return timestamp;
}
// turns it into a beep
void MakeDefault();
// frees all data
void FreeData();
int LengthInMsec() const
{
return SamplesToMsec( NumSamples(), SampleRate() );
@ -158,12 +172,12 @@ public:
{
return totalBufferSize;
}
bool IsCompressed() const
{
return ( format.basic.formatTag != idWaveFile::FORMAT_PCM );
}
bool IsDefault() const
{
return timestamp == FILE_NOT_FOUND_TIMESTAMP;
@ -172,7 +186,7 @@ public:
{
return loaded;
}
void SetNeverPurge()
{
neverPurge = true;
@ -181,7 +195,7 @@ public:
{
return neverPurge;
}
void SetLevelLoadReferenced()
{
levelLoadReferenced = true;
@ -194,7 +208,7 @@ public:
{
return levelLoadReferenced;
}
int GetLastPlayedTime() const
{
return lastPlayedTime;
@ -203,48 +217,48 @@ public:
{
lastPlayedTime = t;
}
float GetAmplitude( int timeMS ) const;
protected:
/*
friend class idSoundHardware_XAudio2;
friend class idSoundVoice_XAudio2;
*/
/*
friend class idSoundHardware_XAudio2;
friend class idSoundVoice_XAudio2;
*/
bool LoadWav( const idStr& name );
bool LoadAmplitude( const idStr& name );
void WriteAllSamples( const idStr& sampleName );
bool LoadGeneratedSample( const idStr& name );
void WriteGeneratedSample( idFile* fileOut );
struct sampleBuffer_t
{
void* buffer;
int bufferSize;
int numSamples;
};
idStr name;
ID_TIME_T timestamp;
bool loaded;
bool neverPurge;
bool levelLoadReferenced;
bool usesMapHeap;
uint32 lastPlayedTime;
int totalBufferSize; // total size of all the buffers
idList<sampleBuffer_t, TAG_AUDIO> buffers;
int playBegin;
int playLength;
idWaveFile::waveFmt_t format;
idList<byte, TAG_AMPLITUDE> amplitude;
};

View file

@ -993,7 +993,7 @@ bool R_GetModeListForDisplay( const int requestedDisplayNum, idList<vidMode_t>&
mode.displayHz = devmode.dmDisplayFrequency;
modeList.AddUnique( mode );
}
if( modeList.Num() > 0 )
{
// sort with lowest resolution first

View file

@ -686,7 +686,7 @@ int Sys_PollMouseInputEvents( int mouseEvents[MAX_MOUSE_EVENTS][2] )
{
// RB: replaced switch enum for MinGW
int diaction = polled_didod[i].dwOfs;
if( diaction == DIMOFS_X )
{
mouseEvents[i][0] = M_DELTAX;

View file

@ -2,9 +2,9 @@
===========================================================================
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
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
================
*/
int Sys_Milliseconds() {
int Sys_Milliseconds()
{
static DWORD sys_timeBase = timeGetTime();
return timeGetTime() - sys_timeBase;
}
@ -78,15 +79,17 @@ int Sys_Milliseconds() {
Sys_Microseconds
========================
*/
uint64 Sys_Microseconds() {
uint64 Sys_Microseconds()
{
static uint64 ticksPerMicrosecondTimes1024 = 0;
if ( ticksPerMicrosecondTimes1024 == 0 ) {
ticksPerMicrosecondTimes1024 = ( (uint64)Sys_ClockTicksPerSecond() << 10 ) / 1000000;
if( ticksPerMicrosecondTimes1024 == 0 )
{
ticksPerMicrosecondTimes1024 = ( ( uint64 )Sys_ClockTicksPerSecond() << 10 ) / 1000000;
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
================
*/
int Sys_GetSystemRam() {
int Sys_GetSystemRam()
{
MEMORYSTATUSEX statex;
statex.dwLength = sizeof ( statex );
GlobalMemoryStatusEx (&statex);
statex.dwLength = sizeof( statex );
GlobalMemoryStatusEx( &statex );
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
physRam = ( physRam + 8 ) & ~15;
@ -113,13 +117,15 @@ Sys_GetDriveFreeSpace
returns in megabytes
================
*/
int Sys_GetDriveFreeSpace( const char *path ) {
int Sys_GetDriveFreeSpace( const char* path )
{
DWORDLONG lpFreeBytesAvailable;
DWORDLONG lpTotalNumberOfBytes;
DWORDLONG lpTotalNumberOfFreeBytes;
int ret = 26;
//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 );
}
return ret;
@ -130,13 +136,15 @@ int Sys_GetDriveFreeSpace( const char *path ) {
Sys_GetDriveFreeSpaceInBytes
========================
*/
int64 Sys_GetDriveFreeSpaceInBytes( const char * path ) {
int64 Sys_GetDriveFreeSpaceInBytes( const char* path )
{
DWORDLONG lpFreeBytesAvailable;
DWORDLONG lpTotalNumberOfBytes;
DWORDLONG lpTotalNumberOfFreeBytes;
int64 ret = 1;
//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;
}
return ret;
@ -148,57 +156,65 @@ Sys_GetVideoRam
returns in megabytes
================
*/
int Sys_GetVideoRam() {
int Sys_GetVideoRam()
{
unsigned int retSize = 64;
// RB begin
#if !defined(__MINGW32__)
CComPtr<IWbemLocator> spLoc = NULL;
HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID * ) &spLoc );
if ( hr != S_OK || spLoc == NULL ) {
HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID* ) &spLoc );
if( hr != S_OK || spLoc == NULL )
{
return retSize;
}
CComBSTR bstrNamespace( _T( "\\\\.\\root\\CIMV2" ) );
CComPtr<IWbemServices> spServices;
// Connect to CIM
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;
}
// 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 );
if ( hr != S_OK ) {
if( hr != S_OK )
{
return retSize;
}
// Get the vid controller
CComPtr<IEnumWbemClassObject> spEnumInst = NULL;
hr = spServices->CreateInstanceEnum( CComBSTR( "Win32_VideoController" ), WBEM_FLAG_SHALLOW, NULL, &spEnumInst );
if ( hr != WBEM_S_NO_ERROR || spEnumInst == NULL ) {
hr = spServices->CreateInstanceEnum( CComBSTR( "Win32_VideoController" ), WBEM_FLAG_SHALLOW, NULL, &spEnumInst );
if( hr != WBEM_S_NO_ERROR || spEnumInst == NULL )
{
return retSize;
}
ULONG uNumOfInstances = 0;
CComPtr<IWbemClassObject> spInstance = NULL;
hr = spEnumInst->Next( 10000, 1, &spInstance, &uNumOfInstances );
if ( hr == S_OK && spInstance ) {
if( hr == S_OK && spInstance )
{
// Get properties from the object
CComVariant varSize;
hr = spInstance->Get( CComBSTR( _T( "AdapterRAM" ) ), 0, &varSize, 0, 0 );
if ( hr == S_OK ) {
if( hr == S_OK )
{
retSize = varSize.intVal / ( 1024 * 1024 );
if ( retSize == 0 ) {
if( retSize == 0 )
{
retSize = 64;
}
}
}
#endif
// RB end
return retSize;
}
@ -210,37 +226,38 @@ Sys_GetCurrentMemoryStatus
all values are in kB except the memoryload
================
*/
void Sys_GetCurrentMemoryStatus( sysMemoryStats_t &stats ) {
void Sys_GetCurrentMemoryStatus( sysMemoryStats_t& stats )
{
MEMORYSTATUSEX statex = {};
unsigned __int64 work;
statex.dwLength = sizeof( statex );
GlobalMemoryStatusEx( &statex );
memset( &stats, 0, sizeof( stats ) );
stats.memoryLoad = statex.dwMemoryLoad;
work = statex.ullTotalPhys >> 20;
stats.totalPhysical = *(int*)&work;
stats.totalPhysical = *( int* )&work;
work = statex.ullAvailPhys >> 20;
stats.availPhysical = *(int*)&work;
stats.availPhysical = *( int* )&work;
work = statex.ullAvailPageFile >> 20;
stats.availPageFile = *(int*)&work;
stats.availPageFile = *( int* )&work;
work = statex.ullTotalPageFile >> 20;
stats.totalPageFile = *(int*)&work;
stats.totalPageFile = *( int* )&work;
work = statex.ullTotalVirtual >> 20;
stats.totalVirtual = *(int*)&work;
stats.totalVirtual = *( int* )&work;
work = statex.ullAvailVirtual >> 20;
stats.availVirtual = *(int*)&work;
stats.availVirtual = *( int* )&work;
work = statex.ullAvailExtendedVirtual >> 20;
stats.availExtendedVirtual = *(int*)&work;
stats.availExtendedVirtual = *( int* )&work;
}
/*
@ -248,8 +265,9 @@ void Sys_GetCurrentMemoryStatus( sysMemoryStats_t &stats ) {
Sys_LockMemory
================
*/
bool Sys_LockMemory( void *ptr, int bytes ) {
return ( VirtualLock( ptr, (SIZE_T)bytes ) != FALSE );
bool Sys_LockMemory( void* ptr, int bytes )
{
return ( VirtualLock( ptr, ( SIZE_T )bytes ) != FALSE );
}
/*
@ -257,8 +275,9 @@ bool Sys_LockMemory( void *ptr, int bytes ) {
Sys_UnlockMemory
================
*/
bool Sys_UnlockMemory( void *ptr, int bytes ) {
return ( VirtualUnlock( ptr, (SIZE_T)bytes ) != FALSE );
bool Sys_UnlockMemory( void* ptr, int bytes )
{
return ( VirtualUnlock( ptr, ( SIZE_T )bytes ) != FALSE );
}
/*
@ -266,7 +285,8 @@ bool Sys_UnlockMemory( void *ptr, int bytes ) {
Sys_SetPhysicalWorkMemory
================
*/
void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes ) {
void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes )
{
::SetProcessWorkingSetSize( GetCurrentProcess(), minBytes, maxBytes );
}
@ -275,19 +295,22 @@ void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes ) {
Sys_GetCurrentUser
================
*/
char *Sys_GetCurrentUser() {
char* Sys_GetCurrentUser()
{
static char s_userName[1024];
unsigned long size = sizeof( s_userName );
if ( !GetUserName( s_userName, &size ) ) {
if( !GetUserName( s_userName, &size ) )
{
strcpy( s_userName, "player" );
}
if ( !s_userName[0] ) {
if( !s_userName[0] )
{
strcpy( s_userName, "player" );
}
return s_userName;
}
}

View file

@ -58,13 +58,13 @@ static void WIN_DisableAltTab()
{
BOOL old;
// RB begin
// RB begin
#if defined(__MINGW32__)
SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 );
#else
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
#endif
// RB end
// RB end
}
s_alttab_disabled = true;
}