From 2d698c4397851f226dc6d49a47f2dc7b17fe59df Mon Sep 17 00:00:00 2001 From: bitplane Date: Fri, 4 Jan 2008 17:52:39 +0000 Subject: [PATCH] Added RogerBorg's better fix for hires timers on dual core machines. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1155 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 20 +++++++++------- source/Irrlicht/os.cpp | 53 ++++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/changes.txt b/changes.txt index fd9d4106..7d6fdc36 100644 --- a/changes.txt +++ b/changes.txt @@ -1,17 +1,19 @@ -30.12.2006 TA - added Initial Windows Mobile 6 Version. - - Windows Mobile 6 SDK - - Visual Studio 2005 - - Minor: - - Burningvideo: MipMap Selection repaired - - renamed private Driver function getTextureSizeFromImageSize to getTextureSizeFromSurfaceSize ------------------------------------------- Changes in version 1.5 (... 2008) + - Better fix for hires timers on dual core machines by RogerBorg + + - added Initial Windows Mobile 6 Version. (30.12.2006 TA) + - Windows Mobile 6 SDK + - Visual Studio 2005 + + - Burningvideo: MipMap Selection repaired + + - renamed private Driver function getTextureSizeFromImageSize to getTextureSizeFromSurfaceSize + - Added collision manager speedup patch by RogerBorg. - - Hardware accelerated Vertex and Index Buffer support finally integrated into Irrlicht. Thanks to a ressource handling idea by Klasker and the almost immediate implementation by Luke, Irrlicht now supports VBOs under OpenGL. D3D will follow soon. + - Hardware accelerated Vertex and Index Buffer support finally integrated into Irrlicht. Thanks to a resource handling idea by Klasker and the almost immediate implementation by Luke, Irrlicht now supports VBOs under OpenGL. D3D will follow soon. Hardware buffers make rendering the same vertices much faster. In some cases this can be more than 10x faster. To use this feature with a mesh simple set a usage type, e.g. via MeshBuffer->setHardwareMappingHint(scene::EHM_STATIC). The driver will upload the vertices and indices on the next draw and reuse this information without the need to upload it each frame. - MeshBuffers can now access the elements of the S3DVertex base class in all vertex types directly, instead of using the getVertices() pointer access. This simplifies simple mesh manipulations as it does not require a switch statement over all vertex types. diff --git a/source/Irrlicht/os.cpp b/source/Irrlicht/os.cpp index 1d7535ce..5bd3e861 100644 --- a/source/Irrlicht/os.cpp +++ b/source/Irrlicht/os.cpp @@ -77,39 +77,19 @@ namespace os #endif } - LARGE_INTEGER HighPerformanceFreq; - BOOL HighPerformanceTimerSupport = FALSE; + static LARGE_INTEGER HighPerformanceFreq; + static BOOL HighPerformanceTimerSupport = FALSE; + static BOOL MultiCore = FALSE; void Timer::initTimer() { -#if !defined (_WIN32_WCE ) +#if !defined(_WIN32_WCE) // disable hires timer on multiple core systems, bios bugs result in bad hires timers. SYSTEM_INFO sysinfo; - DWORD affinity, sysaffinity; GetSystemInfo(&sysinfo); - s32 affinityCount = 0; - - // count the processors that can be used by this process - if (GetProcessAffinityMask( GetCurrentProcess(), &affinity, &sysaffinity )) - { - for (u32 i=0; i<32; ++i) - { - if ((1< 1); #endif + HighPerformanceTimerSupport = QueryPerformanceFrequency(&HighPerformanceFreq); initVirtualTimer(); } @@ -117,10 +97,26 @@ namespace os { if (HighPerformanceTimerSupport) { +#if !defined(_WIN32_WCE) + // Avoid potential timing inaccuracies across multiple cores by + // temporarily setting the affinity of this process to one core. + DWORD affinityMask; + if(MultiCore) + affinityMask = SetThreadAffinityMask(GetCurrentThread(), 1); +#endif LARGE_INTEGER nTime; - QueryPerformanceCounter(&nTime); - return u32((nTime.QuadPart) * 1000 / HighPerformanceFreq.QuadPart); + BOOL queriedOK = QueryPerformanceCounter(&nTime); + +#if !defined(_WIN32_WCE) + // Restore the true affinity. + if(MultiCore) + (void)SetThreadAffinityMask(GetCurrentThread(), affinityMask); +#endif + if(queriedOK) + return u32((nTime.QuadPart) * 1000 / HighPerformanceFreq.QuadPart); + } + return GetTickCount(); } @@ -304,3 +300,4 @@ namespace os } // end namespace os } // end namespace irr +