Skip to content

Commit 3f544f3

Browse files
author
minggo
committed
Merge pull request #146 from MSOpenTech/v3-winrt-bullet
V3: Windows 8.1 Universal App version of Bullet 3D physics lib
2 parents 0456810 + a72e494 commit 3f544f3

File tree

12 files changed

+2126
-9
lines changed

12 files changed

+2126
-9
lines changed

bullet/BulletMultiThreaded/SequentialThreadSupport.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ class btDummyBarrier : public btBarrier
116116
virtual int getMaxCount() {return 1;}
117117
};
118118

119+
#ifdef WINRT
120+
__declspec(align(16)) class btDummyCriticalSection : public btCriticalSection
121+
#else
119122
class btDummyCriticalSection : public btCriticalSection
123+
#endif
120124
{
121125

122126
public:
@@ -128,6 +132,18 @@ class btDummyCriticalSection : public btCriticalSection
128132
{
129133
}
130134

135+
#ifdef WINRT
136+
void* operator new(size_t i)
137+
{
138+
return _aligned_malloc(i, 16);
139+
}
140+
141+
void operator delete(void* p)
142+
{
143+
_aligned_free(p);
144+
}
145+
#endif
146+
131147
unsigned int getSharedParam(int i)
132148
{
133149
btAssert(i>=0&&i<31);

bullet/BulletMultiThreaded/SpuSampleTask/SpuSampleTask.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,26 @@ subject to the following restrictions:
2929

3030
#define MAX_NUM_BODIES 8192
3131

32+
#ifdef WINRT
33+
__declspec(align(16)) struct SampleTask_LocalStoreMemory
34+
#else
3235
struct SampleTask_LocalStoreMemory
36+
#endif
3337
{
3438
ATTRIBUTE_ALIGNED16(char gLocalRigidBody [sizeof(btRigidBody)+16]);
3539
ATTRIBUTE_ALIGNED16(void* gPointerArray[MAX_NUM_BODIES]);
3640

41+
#ifdef WINRT
42+
void* operator new(size_t i)
43+
{
44+
return _aligned_malloc(i, 16);
45+
}
46+
47+
void operator delete(void* p)
48+
{
49+
_aligned_free(p);
50+
}
51+
#endif
3752
};
3853

3954

bullet/BulletMultiThreaded/Win32ThreadSupport.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ subject to the following restrictions:
2323

2424
#include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
2525

26-
26+
#ifdef WINRT
27+
#include <atlstr.h>
28+
#define InitializeCriticalSection(arg0) InitializeCriticalSectionEx(arg0, 0, 0)
29+
#define WaitForSingleObject(arg0, arg1) WaitForSingleObjectEx(arg0, arg1, false);
30+
#define WaitForMultipleObjects(arg0, arg1, arg2, arg3) WaitForMultipleObjectsEx(arg0, arg1, arg2, arg3, false);
31+
#endif
2732

2833
///The number of threads should be equal to the number of available cores
2934
///@todo: each worker should be linked to a single core, using SetThreadIdealProcessor.
@@ -223,7 +228,6 @@ bool Win32ThreadSupport::isTaskCompleted(unsigned int *puiArgument0, unsigned in
223228
return false;
224229
}
225230

226-
227231
void Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threadConstructionInfo)
228232
{
229233

@@ -248,19 +252,28 @@ void Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threadC
248252
spuStatus.m_userPtr=0;
249253

250254
sprintf(spuStatus.m_eventStartHandleName,"eventStart%s%d",threadConstructionInfo.m_uniqueName,i);
255+
#ifdef WINRT
256+
spuStatus.m_eventStartHandle = CreateEventEx(NULL, CString(spuStatus.m_eventStartHandleName), 0, EVENT_ALL_ACCESS);
257+
#else
251258
spuStatus.m_eventStartHandle = CreateEventA (0,false,false,spuStatus.m_eventStartHandleName);
259+
#endif
252260

253261
sprintf(spuStatus.m_eventCompletetHandleName,"eventComplete%s%d",threadConstructionInfo.m_uniqueName,i);
254-
spuStatus.m_eventCompletetHandle = CreateEventA (0,false,false,spuStatus.m_eventCompletetHandleName);
262+
#ifdef WINRT
263+
spuStatus.m_eventCompletetHandle = CreateEventEx(NULL, CString(spuStatus.m_eventStartHandleName), 0, EVENT_ALL_ACCESS);
264+
#else
265+
spuStatus.m_eventCompletetHandle = CreateEventA (0,false,false,spuStatus.m_eventCompletetHandleName);
266+
#endif
255267

256268
m_completeHandles[i] = spuStatus.m_eventCompletetHandle;
257269

258270
HANDLE handle = CreateThread(lpThreadAttributes,dwStackSize,lpStartAddress,lpParameter, dwCreationFlags,lpThreadId);
259271
SetThreadPriority(handle,THREAD_PRIORITY_HIGHEST);
260272
//SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL);
261273

262-
SetThreadAffinityMask(handle, 1<<i);
263-
274+
#ifndef WINRT
275+
SetThreadAffinityMask(handle, 1<<i);
276+
#endif
264277
spuStatus.m_taskId = i;
265278
spuStatus.m_commandId = 0;
266279
spuStatus.m_status = 0;
@@ -326,8 +339,13 @@ class btWin32Barrier : public btBarrier
326339
mEnableCounter = 0;
327340
InitializeCriticalSection(&mExternalCriticalSection);
328341
InitializeCriticalSection(&mLocalCriticalSection);
329-
mRunEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
330-
mNotifyEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
342+
#ifdef WINRT
343+
mRunEvent = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
344+
mNotifyEvent = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
345+
#else
346+
mRunEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
347+
mNotifyEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
348+
#endif
331349
}
332350

333351
virtual ~btWin32Barrier()

bullet/BulletMultiThreaded/btParallelConstraintSolver.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,28 @@ ATTRIBUTE_ALIGNED16(struct) btConstraintSolverIO {
251251
uint32_t barrierAddr2;
252252
uint32_t criticalsectionAddr2;
253253
uint32_t maxTasks1;
254+
255+
#ifdef WINRT
256+
void* operator new(size_t i)
257+
{
258+
return _aligned_malloc(i, 16);
259+
}
260+
261+
void operator delete(void* p)
262+
{
263+
_aligned_free(p);
264+
}
265+
266+
void* operator new[](size_t i)
267+
{
268+
return _aligned_malloc(i, 16);
269+
}
270+
271+
void operator delete[](void* p)
272+
{
273+
_aligned_free(p);
274+
}
275+
#endif
254276
};
255277

256278

bullet/LinearMath/btQuickprof.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ static btClock gProfileClock;
3939
#define NOMCX
4040
#define NOIME
4141

42+
#ifdef WINRT
43+
#define GetTickCount GetTickCount64
44+
#endif
45+
4246
#ifdef _XBOX
4347
#include <Xtl.h>
4448
#else //_XBOX
@@ -59,7 +63,11 @@ struct btClockData
5963

6064
#ifdef BT_USE_WINDOWS_TIMERS
6165
LARGE_INTEGER mClockFrequency;
66+
#ifdef WINRT
67+
LONGLONG mStartTick;
68+
#else
6269
DWORD mStartTick;
70+
#endif
6371
LONGLONG mPrevElapsedTime;
6472
LARGE_INTEGER mStartTime;
6573
#else
@@ -136,7 +144,7 @@ unsigned long int btClock::getTimeMilliseconds()
136144
// Check for unexpected leaps in the Win32 performance counter.
137145
// (This is caused by unexpected data across the PCI to ISA
138146
// bridge, aka south bridge. See Microsoft KB274323.)
139-
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
147+
unsigned long elapsedTicks = static_cast<unsigned long>(GetTickCount() - m_data->mStartTick);
140148
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
141149
if (msecOff < -100 || msecOff > 100)
142150
{
@@ -194,7 +202,7 @@ unsigned long int btClock::getTimeMicroseconds()
194202
// Check for unexpected leaps in the Win32 performance counter.
195203
// (This is caused by unexpected data across the PCI to ISA
196204
// bridge, aka south bridge. See Microsoft KB274323.)
197-
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
205+
unsigned long elapsedTicks = static_cast<unsigned long>(GetTickCount() - m_data->mStartTick);
198206
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
199207
if (msecOff < -100 || msecOff > 100)
200208
{

bullet/LinearMath/btScalar.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ inline int btGetVersion()
4848
#define ATTRIBUTE_ALIGNED16(a) a
4949
#define ATTRIBUTE_ALIGNED64(a) a
5050
#define ATTRIBUTE_ALIGNED128(a) a
51+
#elif (_M_ARM)
52+
#define SIMD_FORCE_INLINE __forceinline
53+
#define ATTRIBUTE_ALIGNED16(a) __declspec() a
54+
#define ATTRIBUTE_ALIGNED64(a) __declspec() a
55+
#define ATTRIBUTE_ALIGNED128(a) __declspec () a
5156
#else
5257
//#define BT_HAS_ALIGNED_ALLOCATOR
5358
#pragma warning(disable : 4324) // disable padding warning

0 commit comments

Comments
 (0)