Changes for Linux.

This commit is contained in:
LuisAntonRebollo 2015-01-18 21:35:11 +01:00
parent aa35157eef
commit 3336bffad2
30 changed files with 99 additions and 173 deletions

View file

@ -465,7 +465,7 @@ bool GameConnection::readConnectRequest(BitStream *stream, const char **errorStr
connectArgv[i + 3] = mConnectArgv[i];
}
connectArgv[0] = "onConnectRequest";
connectArgv[1] = NULL;
connectArgv[1] = 0;
char buffer[256];
Net::addressToString(getNetAddress(), buffer);
connectArgv[2] = buffer;

View file

@ -1647,7 +1647,7 @@ StringStackConsoleWrapper::~StringStackConsoleWrapper()
{
for (int i=0; i<argc; i++)
{
argv[i] = NULL;
argv[i] = 0;
}
delete[] argv;
}

View file

@ -579,7 +579,7 @@ AbstractClassRep* ConsoleObject::getClassRep() const
return NULL;
}
String ConsoleObject::_getLogMessage(const char* fmt, void* args) const
String ConsoleObject::_getLogMessage(const char* fmt, va_list args) const
{
String objClass = "UnknownClass";
if(getClassRep())

View file

@ -863,7 +863,7 @@ public:
/// @param fmt A printf style format string.
/// @param args A va_list containing the args passed ot a log function.
/// @note It is suggested that you use String::VToString.
virtual String _getLogMessage(const char* fmt, void* args) const;
virtual String _getLogMessage(const char* fmt, va_list args) const;
/// @}

View file

@ -1833,7 +1833,7 @@ void SimObject::inspectPostApply()
//-----------------------------------------------------------------------------
String SimObject::_getLogMessage(const char* fmt, void* args) const
String SimObject::_getLogMessage(const char* fmt, va_list args) const
{
String objClass = "UnknownClass";
if(getClassRep())

View file

@ -411,7 +411,7 @@ class SimObject: public ConsoleObject
virtual void _onUnselected() {}
/// We can provide more detail, like object name and id.
virtual String _getLogMessage(const char* fmt, void* args) const;
virtual String _getLogMessage(const char* fmt, va_list args) const;
DEFINE_CREATE_METHOD
{

View file

@ -391,9 +391,9 @@ void dPrintf(const char *format, ...)
vprintf(format, args);
}
S32 dVprintf(const char *format, void *arglist)
S32 dVprintf(const char *format, va_list arglist)
{
return vprintf(format, (char*)arglist);
return (S32)vprintf(format, arglist);
}
S32 dSprintf(char *buffer, U32 bufferSize, const char *format, ...)
@ -409,9 +409,9 @@ S32 dSprintf(char *buffer, U32 bufferSize, const char *format, ...)
}
S32 dVsprintf(char *buffer, U32 bufferSize, const char *format, void *arglist)
S32 dVsprintf(char *buffer, U32 bufferSize, const char *format, va_list arglist)
{
S32 len = vsnprintf(buffer, bufferSize, format, (char*)arglist);
S32 len = vsnprintf(buffer, bufferSize, format, arglist);
AssertWarn( len < bufferSize, "Buffer too small in call to dVsprintf!" );

View file

@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <cstdarg>
#ifndef _TORQUE_TYPES_H_
#include "platform/types.h"
@ -229,9 +230,9 @@ int dItoa(int n, char s[]);
// standard I/O functions [defined in platformString.cpp]
extern void dPrintf(const char *format, ...);
extern S32 dVprintf(const char *format, void *arglist);
extern S32 dVprintf(const char *format, va_list arglist);
extern S32 dSprintf(char *buffer, U32 bufferSize, const char *format, ...);
extern S32 dVsprintf(char *buffer, U32 bufferSize, const char *format, void *arglist);
extern S32 dVsprintf(char *buffer, U32 bufferSize, const char *format, va_list arglist);
extern S32 dSscanf(const char *buffer, const char *format, ...);
#endif

View file

@ -1434,19 +1434,19 @@ String::StrFormat::~StrFormat()
dFree( _dynamicBuffer );
}
S32 String::StrFormat::format( const char *format, void *args )
S32 String::StrFormat::format( const char *format, va_list args )
{
_len=0;
return formatAppend(format,args);
}
S32 String::StrFormat::formatAppend( const char *format, void *args )
S32 String::StrFormat::formatAppend( const char *format, va_list args )
{
// Format into the fixed buffer first.
S32 startLen = _len;
if (_dynamicBuffer == NULL)
{
_len += vsnprintf(_fixedBuffer + _len, sizeof(_fixedBuffer) - _len, format, *(va_list*)args);
_len += vsnprintf(_fixedBuffer + _len, sizeof(_fixedBuffer) - _len, format, args);
if (_len >= 0 && _len < sizeof(_fixedBuffer))
return _len;
@ -1535,9 +1535,9 @@ String String::ToString(const char *str, ...)
return ret;
}
String String::VToString(const char* str, void* args)
String String::VToString(const char* str, va_list args)
{
StrFormat format(str,&args);
StrFormat format(str,args);
// Copy it into a string
U32 len = format.length();

View file

@ -176,7 +176,7 @@ public:
/// @{
static String ToString(const char *format, ...);
static String VToString(const char* format, void* args);
static String VToString(const char* format, va_list args);
static String ToString( bool v );
static inline String ToString( U32 v ) { return ToString( "%u", v ); }
@ -245,7 +245,7 @@ public:
_fixedBuffer[0] = '\0';
}
StrFormat(const char *formatStr, void *args)
StrFormat(const char *formatStr, va_list args)
: _dynamicBuffer( NULL ),
_dynamicSize( 0 ),
_len( 0 )
@ -255,8 +255,8 @@ public:
~StrFormat();
S32 format( const char *format, void *args );
S32 formatAppend( const char *format, void *args );
S32 format( const char *format, va_list args );
S32 formatAppend( const char *format, va_list args );
S32 append(const char * str, S32 len);
S32 append(const char * str);
@ -357,7 +357,7 @@ class StringBuilder
{
va_list args;
va_start(args, fmt);
return mFormat.formatAppend(fmt, &args);
return mFormat.formatAppend(fmt, args);
}
};

View file

@ -78,6 +78,14 @@ public:
{ if ((x)==0) \
::PlatformAssert::processAssert(::PlatformAssert::Warning, __FILE__, __LINE__, y); }
/*!
Helper macro called when AssertFatal failed.
Used for help static code analyzers.
*/
#ifndef ON_FAIL_ASSERTFATAL
#define ON_FAIL_ASSERTFATAL
#endif
/*!
Assert that the statement x is true, otherwise halt.

View file

@ -21,6 +21,12 @@
// must ensure BIOS settings is not configured to restrict CPUID functionalities.
//-------------------------------------------------------------------------------------------------
#if defined(TORQUE_OS_LINUX) || defined(LINUX)
// TODO GCC code don't compile on Release with optimizations, mover code to platform layer
#else
#include "platform/platform.h"
#include "platform/platformCPUCount.h"
@ -666,3 +672,5 @@ next:
#endif
#endif
#endif

View file

@ -68,7 +68,7 @@ inline bool dCompareAndSwap( volatile U32& ref, U32 oldVal, U32 newVal )
#if defined(TORQUE_OS_PS3)
return ( cellAtomicCompareAndSwap32( (std::uint32_t *)&ref, newVal, oldVal ) == oldVal );
#elif !defined(TORQUE_OS_MAC)
return ( __sync_val_compare_and_swap( ( volatile long* ) &ref, oldVal, newVal ) == oldVal );
return ( __sync_val_compare_and_swap( &ref, oldVal, newVal ) == oldVal );
#else
return OSAtomicCompareAndSwap32(oldVal, newVal, (int32_t *) &ref);
#endif
@ -79,7 +79,7 @@ inline bool dCompareAndSwap( volatile U64& ref, U64 oldVal, U64 newVal )
#if defined(TORQUE_OS_PS3)
return ( cellAtomicCompareAndSwap32( (std::uint32_t *)&ref, newVal, oldVal ) == oldVal );
#elif !defined(TORQUE_OS_MAC)
return ( __sync_val_compare_and_swap( ( volatile long long* ) &ref, oldVal, newVal ) == oldVal );
return ( __sync_val_compare_and_swap( &ref, oldVal, newVal ) == oldVal );
#else
return OSAtomicCompareAndSwap64(oldVal, newVal, (int64_t *) &ref);
#endif

View file

@ -30,8 +30,13 @@
//--------------------------------------
// Types
#if TORQUE_X86
typedef signed long long S64;
typedef unsigned long long U64;
#else
typedef signed long S64;
typedef unsigned long U64;
#endif
//--------------------------------------
@ -73,11 +78,11 @@ typedef unsigned long long U64;
# define TORQUE_OS_PS3
# include "platform/types.posix.h"
#elif defined(linux)
#elif defined(linux) || defined(LINUX)
# define TORQUE_OS_STRING "Linux"
# define TORQUE_OS_LINUX
# define TORQUE_SUPPORTS_NASM
# define TORQUE_SUPPORTS_GCC_INLINE_X86_ASM
//# define TORQUE_SUPPORTS_NASM
//# define TORQUE_SUPPORTS_GCC_INLINE_X86_ASM
# include "platform/types.posix.h"
#elif defined(__OpenBSD__)
@ -115,6 +120,11 @@ typedef unsigned long long U64;
# define TORQUE_CPU_X86
# define TORQUE_LITTLE_ENDIAN
#elif defined(__x86_64__)
# define TORQUE_CPU_STRING "Intel x64"
# define TORQUE_CPU_X64
# define TORQUE_LITTLE_ENDIAN
#elif defined(__ppc__)
# define TORQUE_CPU_STRING "PowerPC"
# define TORQUE_CPU_PPC

View file

@ -29,7 +29,8 @@
// size_t is needed to overload new
// size_t tends to be OS and compiler specific and may need to
// be if/def'ed in the future
typedef unsigned int dsize_t;
#include <stddef.h>
typedef size_t dsize_t;
/** Platform dependent file date-time structure. The defination of this structure

View file

@ -27,130 +27,21 @@
#include "core/strings/stringFunctions.h"
#include <math.h>
#include "platform/platformCPUCount.h"
#include <unistd.h>
Platform::SystemInfo_struct Platform::SystemInfo;
extern void PlatformBlitInit();
extern void SetProcessorInfo(Platform::SystemInfo_struct::Processor& pInfo,
char* vendor, U32 processor, U32 properties, U32 properties2); // platform/platformCPU.cc
void Processor::init() {}
// asm cpu detection routine from platform code
extern "C"
// TODO LINUX CPUInfo::CPUCount better support
namespace CPUInfo
{
void detectX86CPUInfo(char *vendor, U32 *processor, U32 *properties);
}
EConfig CPUCount(U32& TotAvailLogical, U32& TotAvailCore, U32& PhysicalNum)
{
PhysicalNum = TotAvailCore = 0;
TotAvailLogical = (int)sysconf(_SC_NPROCESSORS_ONLN);
/* used in the asm */
static U32 time[2];
static char vendor[13] = {0,};
static U32 properties = 0;
static U32 processor = 0;
U32 clockticks = 0;
U32 timeHi = 0;
U32 timeLo = 0;
void Processor::init()
{
// Reference:
// www.cyrix.com
// www.amd.com
// www.intel.com
// http://developer.intel.com/design/PentiumII/manuals/24512701.pdf
Platform::SystemInfo.processor.type = CPU_X86Compatible;
Platform::SystemInfo.processor.name = StringTable->insert("Unknown x86 Compatible");
Platform::SystemInfo.processor.mhz = 0;
Platform::SystemInfo.processor.properties = CPU_PROP_C;
clockticks = properties = processor = time[0] = 0;
dStrcpy(vendor, "");
detectX86CPUInfo(vendor, &processor, &properties);
SetProcessorInfo(Platform::SystemInfo.processor,
vendor, processor, properties, 0);
//--------------------------------------
// if RDTSC support calculate the aproximate Mhz of the CPU
if (Platform::SystemInfo.processor.properties & CPU_PROP_RDTSC &&
Platform::SystemInfo.processor.properties & CPU_PROP_FPU)
{
const U32 MS_INTERVAL = 750;
#if defined(TORQUE_COMPILER_GCC) && ((__GNUC__ >= 3) && (__GNUC_MINOR__ >=4)) || ((__GNUC__ >= 4) && (__GNUC_MINOR__ >=0))
asm("rdtsc" : "=a" (timeLo), "=d" (timeHi));
#else
__asm__(
"pushl %eax\n"
"pushl %edx\n"
"rdtsc\n"
"movl %eax, (time)\n"
"movl %edx, (time+4)\n"
"popl %edx\n"
"popl %eax\n"
);
#endif
U32 ms = Platform::getRealMilliseconds();
while ( Platform::getRealMilliseconds() < ms+MS_INTERVAL )
{ /* empty */ }
ms = Platform::getRealMilliseconds()-ms;
#if defined(TORQUE_COMPILER_GCC) && ((__GNUC__ >= 3) && (__GNUC_MINOR__ >= 4)) || ((__GNUC__ >= 4) && (__GNUC_MINOR__ >=0))
asm(
"pushl %eax\n"
"pushl %edx\n"
"rdtsc\n"
"sub (timeHi), %edx\n"
"sbb (timeLo), %eax\n"
"mov %eax, (clockticks)\n"
"popl %edx\n"
"popl %eax\n"
);
#else
asm(
"pushl %eax\n"
"pushl %edx\n"
"rdtsc\n"
"sub (time+4), %edx\n"
"sbb (time), %eax\n"
"mov %eax, (clockticks)\n"
"popl %edx\n"
"popl %eax\n"
);
#endif
U32 mhz = static_cast<U32>(F32(clockticks) / F32(ms) / 1000.0f);
// catch-22 the timing method used above to calc Mhz is generally
// wrong by a few percent so we want to round to the nearest clock
// multiple but we also want to be careful to not touch overclocked
// results
// measure how close the Raw Mhz number is to the center of each clock
// bucket
U32 bucket25 = mhz % 25;
U32 bucket33 = mhz % 33;
U32 bucket50 = mhz % 50;
if (bucket50 < 8 || bucket50 > 42)
Platform::SystemInfo.processor.mhz =
U32((mhz+(50.0f/2.0f))/50.0f) * 50;
else if (bucket25 < 5 || bucket25 > 20)
Platform::SystemInfo.processor.mhz =
U32((mhz+(25.0f/2.0f))/25.0f) * 25;
else if (bucket33 < 5 || bucket33 > 28)
Platform::SystemInfo.processor.mhz =
U32((mhz+(33.0f/2.0f))/33.0f) * 33;
else
Platform::SystemInfo.processor.mhz = U32(mhz);
}
Con::printf("Processor Init:");
Con::printf(" %s, %d Mhz", Platform::SystemInfo.processor.name, Platform::SystemInfo.processor.mhz);
if (Platform::SystemInfo.processor.properties & CPU_PROP_FPU)
Con::printf(" FPU detected");
if (Platform::SystemInfo.processor.properties & CPU_PROP_MMX)
Con::printf(" MMX detected");
if (Platform::SystemInfo.processor.properties & CPU_PROP_3DNOW)
Con::printf(" 3DNow detected");
if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE)
Con::printf(" SSE detected");
Con::printf(" ");
PlatformBlitInit();
}
return CONFIG_SingleCoreHTDisabled;
}
}; // namespace CPUInfo

View file

@ -30,6 +30,9 @@
#if defined(TORQUE_OS_MAC)
# include <OpenAL/al.h>
# include <OpenAL/alc.h>
#elif defined(TORQUE_OS_LINUX)
# include <AL/al.h>
# include <AL/alc.h>
#else
# include <al/al.h>
# include <al/alc.h>

View file

@ -27,6 +27,8 @@
#include "aldlist.h"
#if defined(TORQUE_OS_MAC)
#include <OpenAL/alc.h>
#elif defined(TORQUE_OS_LINUX)
#include <AL/alc.h>
#else
#include <al/alc.h>
#endif

View file

@ -60,7 +60,7 @@ SFXALDevice::SFXALDevice( SFXProvider *provider,
AssertFatal( mDevice != NULL && mContext != NULL, "Failed to create OpenAL device and/or context!" );
// Start the update thread.
#ifndef TORQUE_OS_LINUX
if( !Con::getBoolVariable( "$_forceAllMainThread" ) )
{
SFXInternal::gUpdateThread = new AsyncPeriodicUpdateThread
@ -68,6 +68,7 @@ SFXALDevice::SFXALDevice( SFXProvider *provider,
Con::getIntVariable( "$pref::SFX::updateInterval", SFXInternal::DEFAULT_UPDATE_INTERVAL ) );
SFXInternal::gUpdateThread->start();
}
#endif
}
//-----------------------------------------------------------------------------

View file

@ -24,6 +24,7 @@
#include "sfx/sfxProvider.h"
#include "sfx/openal/sfxALDevice.h"
#include "sfx/openal/aldlist.h"
#include "sfx/openal/LoadOAL.h"
#include "core/strings/stringFunctions.h"
#include "console/console.h"

View file

@ -28,8 +28,8 @@ void PlatformCursorController::pushCursor( S32 cursorID )
// Place the new cursor shape onto the stack
mCursors.increment();
CursorShape &shape = mCursors.last();
shape.mCursorType = CursorShape::TYPE_RESOURCE;
Cursor_Shape &shape = mCursors.last();
shape.mCursorType = Cursor_Shape::TYPE_RESOURCE;
shape.mCursorID = cursorID;
// Now Change the Cursor Shape.
@ -42,8 +42,8 @@ void PlatformCursorController::pushCursor( const UTF8 *fileName )
mCursors.increment();
// Store the Details.
CursorShape &shape = mCursors.last();
shape.mCursorType = CursorShape::TYPE_FILE;
Cursor_Shape &shape = mCursors.last();
shape.mCursorType = Cursor_Shape::TYPE_FILE;
shape.mCursorFile = String::ToString( "%s", fileName );
// Now Change the Cursor Shape.
@ -71,11 +71,11 @@ void PlatformCursorController::refreshCursor()
setCursorShape( mCursors.last(), false );
}
void PlatformCursorController::setCursorShape( const CursorShape &shape, bool reload )
void PlatformCursorController::setCursorShape( const Cursor_Shape &shape, bool reload )
{
switch( shape.mCursorType )
{
case CursorShape::TYPE_RESOURCE :
case Cursor_Shape::TYPE_RESOURCE :
{
// Set Resource.
@ -83,7 +83,7 @@ void PlatformCursorController::setCursorShape( const CursorShape &shape, bool re
} break;
case CursorShape::TYPE_FILE :
case Cursor_Shape::TYPE_FILE :
{
// Set File.
@ -91,4 +91,4 @@ void PlatformCursorController::setCursorShape( const CursorShape &shape, bool re
} break;
}
}
}

View file

@ -33,7 +33,7 @@ class PlatformCursorController
{
protected:
struct CursorShape
struct Cursor_Shape
{
enum Type
{
@ -46,7 +46,7 @@ protected:
String mCursorFile; // Points to a custom cursor file
};
Vector<CursorShape> mCursors;
Vector<Cursor_Shape> mCursors;
/// The PlatformWindow that owns this Cursor Controller
PlatformWindow *mOwner;
@ -85,7 +85,7 @@ public:
virtual void setCursorVisible( bool visible ) = 0;
virtual bool isCursorVisible() = 0;
virtual void setCursorShape( const CursorShape &shape, bool reload );
virtual void setCursorShape( const Cursor_Shape &shape, bool reload );
virtual void setCursorShape( U32 cursorID ) = 0;
virtual void setCursorShape( const UTF8 *filename, bool reload ) = 0;
@ -99,4 +99,4 @@ public:
virtual S32 getDoubleClickHeight() = 0;
};
#endif
#endif

View file

@ -23,7 +23,7 @@
// Based on 'Cubic Lens Distortion HLSL Shader' by François Tarlier
// www.francois-tarlier.com/blog/index.php/2009/11/cubic-lens-distortion-shader
#include "./postFx.glsl"
#include "./postFX.glsl"
#include "../../gl/torque.glsl"
#include "../../gl/hlslCompat.glsl"
@ -59,4 +59,4 @@ void main()
}
OUT_col = vec4( outColor.rgb, 1 );
}
}

View file

@ -20,7 +20,7 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "./postFx.glsl"
#include "./postFX.glsl"
#include "../../gl/torque.glsl"
#include "../../gl/hlslCompat.glsl"

View file

@ -22,7 +22,7 @@
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/postFx.glsl"
#include "../../gl/postFX.glsl"
uniform sampler2D backBuffer; // The original backbuffer.
uniform sampler2D prepassTex; // The pre-pass depth and normals.

View file

@ -21,7 +21,7 @@
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "../../gl/postFx.glsl"
#include "../../gl/postFX.glsl"
uniform sampler2D frameSampler;
uniform sampler2D backBuffer;

View file

@ -23,7 +23,7 @@
// Based on 'Cubic Lens Distortion HLSL Shader' by François Tarlier
// www.francois-tarlier.com/blog/index.php/2009/11/cubic-lens-distortion-shader
#include "./postFx.glsl"
#include "./postFX.glsl"
#include "../../gl/torque.glsl"
#include "../../gl/hlslCompat.glsl"
@ -59,4 +59,4 @@ void main()
}
OUT_col = vec4( outColor.rgb, 1 );
}
}

View file

@ -20,7 +20,7 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "./postFx.glsl"
#include "./postFX.glsl"
#include "../../gl/torque.glsl"
#include "../../gl/hlslCompat.glsl"

View file

@ -22,7 +22,7 @@
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/postFx.glsl"
#include "../../gl/postFX.glsl"
uniform sampler2D backBuffer; // The original backbuffer.
uniform sampler2D prepassTex; // The pre-pass depth and normals.

View file

@ -21,7 +21,7 @@
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "../../gl/postFx.glsl"
#include "../../gl/postFX.glsl"
uniform sampler2D frameSampler;
uniform sampler2D backBuffer;