Fix x64 problems for WIN64.

This commit is contained in:
LuisAntonRebollo 2014-09-14 20:44:07 +02:00
parent 6bfb7d8186
commit fcf7bee64a
12 changed files with 52 additions and 22 deletions

View file

@ -70,11 +70,42 @@ namespace Compiler
//------------------------------------------------------------ //------------------------------------------------------------
#ifdef TORQUE_CPU_X64
// Fixed unsafe conversion from pointer to U32. @todo x64 revise
U32 u32toSTEId = 0;
typedef Map< U32, StringTableEntry > U32toSteMap;
U32toSteMap u32toSTEMap;
StringTableEntry U32toSTE( U32 u )
{
// @todo x64 Added thread-safe convertion.
const U32toSteMap::Iterator result = u32toSTEMap.find( u );
AssertFatal( result != u32toSTEMap.end( ),
"Don't converted U32 to STE. See evalSTEtoU32()." );
return result->value;
}
U32 evalSTEtoU32( StringTableEntry ste, U32 )
{
// @todo x64 Added thread-safe convertion.
u32toSTEMap.insert( u32toSTEId++, ste );
return (u32toSTEId - 1); // pointer to inserted
}
#else
StringTableEntry U32toSTE(U32 u)
{
return *((StringTableEntry *) &u);
}
U32 evalSTEtoU32(StringTableEntry ste, U32) U32 evalSTEtoU32(StringTableEntry ste, U32)
{ {
return *((U32 *) &ste); return *((U32 *) &ste);
} }
#endif
U32 compileSTEtoU32(StringTableEntry ste, U32 ip) U32 compileSTEtoU32(StringTableEntry ste, U32 ip)
{ {
if(ste) if(ste)

View file

@ -218,10 +218,7 @@ namespace Compiler
//------------------------------------------------------------ //------------------------------------------------------------
inline StringTableEntry U32toSTE(U32 u) StringTableEntry U32toSTE(U32 u);
{
return *((StringTableEntry *) &u);
}
extern U32 (*STEtoU32)(StringTableEntry ste, U32 ip); extern U32 (*STEtoU32)(StringTableEntry ste, U32 ip);

View file

@ -696,7 +696,7 @@ namespace Con
extern void expandEscape(char *dest, const char *src); extern void expandEscape(char *dest, const char *src);
extern bool collapseEscape(char *buf); extern bool collapseEscape(char *buf);
extern S32 HashPointer(StringTableEntry ptr); extern U32 HashPointer(StringTableEntry ptr);
/// Extended information about a console function. /// Extended information about a console function.

View file

@ -262,9 +262,9 @@ void Dictionary::deleteVariables(const char *varString)
} }
} }
S32 HashPointer(StringTableEntry ptr) U32 HashPointer(StringTableEntry ptr)
{ {
return (S32)(((dsize_t)ptr) >> 2); return (U32)(((dsize_t)ptr) >> 2);
} }
Dictionary::Entry *Dictionary::lookup(StringTableEntry name) Dictionary::Entry *Dictionary::lookup(StringTableEntry name)

View file

@ -25,7 +25,7 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
extern S32 HashPointer(StringTableEntry e); extern U32 HashPointer(StringTableEntry e);
SimNameDictionary::SimNameDictionary() SimNameDictionary::SimNameDictionary()
{ {

View file

@ -59,7 +59,7 @@ U32 _StringTable::hashString(const char* str)
char c; char c;
while((c = *str++) != 0) { while((c = *str++) != 0) {
ret <<= 1; ret <<= 1;
ret ^= sgHashTable[static_cast<U32>(c)]; ret ^= sgHashTable[static_cast<U8>(c)];
} }
return ret; return ret;
} }
@ -73,7 +73,7 @@ U32 _StringTable::hashStringn(const char* str, S32 len)
char c; char c;
while((c = *str++) != 0 && len--) { while((c = *str++) != 0 && len--) {
ret <<= 1; ret <<= 1;
ret ^= sgHashTable[static_cast<U32>(c)]; ret ^= sgHashTable[static_cast<U8>(c)];
} }
return ret; return ret;
} }

View file

@ -40,7 +40,7 @@
template< typename T > template< typename T >
inline bool dCompareAndSwap( T* volatile& refPtr, T* oldPtr, T* newPtr ) inline bool dCompareAndSwap( T* volatile& refPtr, T* oldPtr, T* newPtr )
{ {
return dCompareAndSwap( *reinterpret_cast< volatile U32* >( &refPtr ), ( U32 ) oldPtr, ( U32 ) newPtr ); return dCompareAndSwap( *reinterpret_cast< volatile size_t* >( &refPtr ), ( size_t ) oldPtr, ( size_t ) newPtr );
} }
// Test-And-Set // Test-And-Set

View file

@ -222,11 +222,11 @@ struct _TypeTraits< T* >
typedef _DestructPtr Destruct; typedef _DestructPtr Destruct;
template< typename A > template< typename A >
static bool isTaggedPtr( A* ptr ) { return ( U32( ptr ) & 0x1 ); } //TODO: 64bits static bool isTaggedPtr( A* ptr ) { return ( size_t( ptr ) & 0x1 ); } //TODO: 64bits
template< typename A > template< typename A >
static A* getTaggedPtr( A* ptr ) { return ( A* ) ( U32( ptr ) | 0x1 ); } //TODO: 64bits static A* getTaggedPtr( A* ptr ) { return ( A* ) ( size_t( ptr ) | 0x1 ); } //TODO: 64bits
template< typename A > template< typename A >
static A* getUntaggedPtr( A* ptr ) { return ( A* ) ( U32( ptr ) & 0xFFFFFFFE ); } //TODO: 64bit static A* getUntaggedPtr( A* ptr ) { return ( A* ) ( size_t( ptr ) & (~0x1) ); } //TODO: 64bit
}; };
template< typename T > template< typename T >

View file

@ -1170,7 +1170,10 @@ void TSShape::assembleShape()
skip = true; skip = true;
TSMesh * mesh = TSMesh::assembleMesh(meshType,skip); TSMesh * mesh = TSMesh::assembleMesh(meshType,skip);
if (ptr32) if (ptr32)
{
ptr32[i] = skip ? 0 : (S32)mesh; ptr32[i] = skip ? 0 : (S32)mesh;
meshes.push_back(skip ? 0 : mesh);
}
// fill in location of verts, tverts, and normals for detail levels // fill in location of verts, tverts, and normals for detail levels
if (mesh && meshType!=TSMesh::DecalMeshType) if (mesh && meshType!=TSMesh::DecalMeshType)
@ -1198,7 +1201,6 @@ void TSShape::assembleShape()
} }
} }
} }
meshes.set(ptr32,numMeshes);
tsalloc.checkGuard(); tsalloc.checkGuard();

View file

@ -661,7 +661,7 @@ void Win32Window::_unregisterWindowClass()
LRESULT PASCAL Win32Window::WindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) LRESULT PASCAL Win32Window::WindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{ {
// CodeReview [tom, 4/30/2007] The two casts here seem somewhat silly and redundant ? // CodeReview [tom, 4/30/2007] The two casts here seem somewhat silly and redundant ?
Win32Window* window = (Win32Window*)((PlatformWindow*)GetWindowLong(hWnd, GWLP_USERDATA)); Win32Window* window = (Win32Window*)((PlatformWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA));
const WindowId devId = window ? window->getWindowId() : 0; const WindowId devId = window ? window->getWindowId() : 0;
if (window && window->getOffscreenRender()) if (window && window->getOffscreenRender())
@ -712,8 +712,8 @@ LRESULT PASCAL Win32Window::WindowProc( HWND hWnd, UINT message, WPARAM wParam,
case WM_CREATE: case WM_CREATE:
// CodeReview [tom, 4/30/2007] Why don't we just cast this to a LONG // CodeReview [tom, 4/30/2007] Why don't we just cast this to a LONG
// instead of having a ton of essentially pointless casts ? // instead of having a ton of essentially pointless casts ?
SetWindowLong(hWnd, GWLP_USERDATA, SetWindowLongPtr(hWnd, GWLP_USERDATA,
(LONG)((PlatformWindow*)((CREATESTRUCT*)lParam)->lpCreateParams)); (LONG_PTR)((PlatformWindow*)((CREATESTRUCT*)lParam)->lpCreateParams));
break; break;
case WM_SETFOCUS: case WM_SETFOCUS:

View file

@ -136,7 +136,7 @@ void Win32WindowManager::buildMonitorsList()
mMonitors.clear(); mMonitors.clear();
// Enumerate all monitors // Enumerate all monitors
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (U32)(void*)&mMonitors); EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (size_t)(void*)&mMonitors);
} }
S32 Win32WindowManager::findFirstMatchingMonitor(const char* name) S32 Win32WindowManager::findFirstMatchingMonitor(const char* name)
@ -252,7 +252,7 @@ PlatformWindow *Win32WindowManager::createWindow(GFXDevice *device, const GFXVid
w32w->setVideoMode(mode); w32w->setVideoMode(mode);
// Associate our window struct with the HWND. // Associate our window struct with the HWND.
SetWindowLongPtrW(w32w->mWindowHandle, GWLP_USERDATA, (LONG)w32w); SetWindowLongPtr(w32w->mWindowHandle, GWLP_USERDATA, (LONG_PTR)w32w);
// Do some error checking. // Do some error checking.
AssertFatal(w32w->mWindowHandle != NULL, "Win32WindowManager::createWindow - Could not create window!"); AssertFatal(w32w->mWindowHandle != NULL, "Win32WindowManager::createWindow - Could not create window!");
@ -358,7 +358,7 @@ void Win32WindowManager::_process()
// [tom, 4/30/2007] I think this should work, but leaving the above commented // [tom, 4/30/2007] I think this should work, but leaving the above commented
// out just in case this is actually fubared with multiple windows. // out just in case this is actually fubared with multiple windows.
Win32Window* window = (Win32Window*)(GetWindowLong(msg.hwnd, GWLP_USERDATA)); Win32Window* window = (Win32Window*)(GetWindowLongPtr(msg.hwnd, GWLP_USERDATA));
if(window) if(window)
translated = window->translateMessage(msg); translated = window->translateMessage(msg);

View file

@ -176,7 +176,7 @@ static bool _dispatch(HWND hWnd,UINT message,WPARAM wParam,WPARAM lParam)
static S32 mouseNCState = -1; // -1 denotes unchanged, static S32 mouseNCState = -1; // -1 denotes unchanged,
// 0 denotes changed but was hidden // 0 denotes changed but was hidden
// 1 denotes changed but was visible // 1 denotes changed but was visible
Win32Window* window = hWnd?(Win32Window*)GetWindowLong(hWnd, GWLP_USERDATA): 0; Win32Window* window = hWnd?(Win32Window*)GetWindowLongPtr(hWnd, GWLP_USERDATA): 0;
const WindowId devId = window ? window->getWindowId() : 0; const WindowId devId = window ? window->getWindowId() : 0;
// State tracking for focus/lose focus cursor management // State tracking for focus/lose focus cursor management