Skip to content

Commit a72e494

Browse files
committed
added winrt support
1 parent ad0acef commit a72e494

File tree

10 files changed

+128
-23
lines changed

10 files changed

+128
-23
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

bullet/proj.win8.1-universal/libbullet.Shared/libbullet.Shared.vcxitems

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@
262262
</ItemGroup>
263263
<ItemGroup>
264264
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btAxisSweep3.cpp" />
265-
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btBroadphaseProxy.cpp" />
266265
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btCollisionAlgorithm.cpp" />
267266
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btDbvt.cpp" />
268267
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btDbvtBroadphase.cpp" />

bullet/proj.win8.1-universal/libbullet.Shared/libbullet.Shared.vcxitems.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,6 @@
785785
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btAxisSweep3.cpp">
786786
<Filter>BulletCollision\BroadphaseCollision</Filter>
787787
</ClCompile>
788-
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btBroadphaseProxy.cpp">
789-
<Filter>BulletCollision\BroadphaseCollision</Filter>
790-
</ClCompile>
791788
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\BulletCollision\BroadphaseCollision\btCollisionAlgorithm.cpp">
792789
<Filter>BulletCollision\BroadphaseCollision</Filter>
793790
</ClCompile>

bullet/proj.win8.1-universal/libbullet.Windows/libbullet.Windows.vcxproj

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<CompileAsWinRT>false</CompileAsWinRT>
116116
<SDLCheck>true</SDLCheck>
117117
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
118-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
119119
</ClCompile>
120120
<Link>
121121
<SubSystem>Console</SubSystem>
@@ -129,21 +129,26 @@
129129
<CompileAsWinRT>false</CompileAsWinRT>
130130
<SDLCheck>true</SDLCheck>
131131
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
132-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
133+
<WholeProgramOptimization>false</WholeProgramOptimization>
134+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
133135
</ClCompile>
134136
<Link>
135137
<SubSystem>Console</SubSystem>
136138
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
137139
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
138140
</Link>
141+
<Lib>
142+
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
143+
</Lib>
139144
</ItemDefinitionGroup>
140145
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'">
141146
<ClCompile>
142147
<PrecompiledHeader>NotUsing</PrecompiledHeader>
143148
<CompileAsWinRT>false</CompileAsWinRT>
144149
<SDLCheck>true</SDLCheck>
145150
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
146-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
151+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
147152
</ClCompile>
148153
<Link>
149154
<SubSystem>Console</SubSystem>
@@ -157,21 +162,26 @@
157162
<CompileAsWinRT>false</CompileAsWinRT>
158163
<SDLCheck>true</SDLCheck>
159164
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
160-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
165+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
166+
<WholeProgramOptimization>false</WholeProgramOptimization>
167+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
161168
</ClCompile>
162169
<Link>
163170
<SubSystem>Console</SubSystem>
164171
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
165172
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
166173
</Link>
174+
<Lib>
175+
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
176+
</Lib>
167177
</ItemDefinitionGroup>
168178
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
169179
<ClCompile>
170180
<PrecompiledHeader>NotUsing</PrecompiledHeader>
171181
<CompileAsWinRT>false</CompileAsWinRT>
172182
<SDLCheck>true</SDLCheck>
173183
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
174-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
184+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
175185
</ClCompile>
176186
<Link>
177187
<SubSystem>Console</SubSystem>
@@ -185,13 +195,18 @@
185195
<CompileAsWinRT>false</CompileAsWinRT>
186196
<SDLCheck>true</SDLCheck>
187197
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
188-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
198+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
199+
<WholeProgramOptimization>false</WholeProgramOptimization>
200+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
189201
</ClCompile>
190202
<Link>
191203
<SubSystem>Console</SubSystem>
192204
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
193205
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
194206
</Link>
207+
<Lib>
208+
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
209+
</Lib>
195210
</ItemDefinitionGroup>
196211
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
197212
<ImportGroup Label="ExtensionTargets">

bullet/proj.win8.1-universal/libbullet.WindowsPhone/libbullet.WindowsPhone.vcxproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<CompileAsWinRT>false</CompileAsWinRT>
8585
<SDLCheck>true</SDLCheck>
8686
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
87-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
87+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
8888
</ClCompile>
8989
<Link>
9090
<SubSystem>Console</SubSystem>
@@ -98,21 +98,26 @@
9898
<CompileAsWinRT>false</CompileAsWinRT>
9999
<SDLCheck>true</SDLCheck>
100100
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
101-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
101+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102+
<WholeProgramOptimization>false</WholeProgramOptimization>
103+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
102104
</ClCompile>
103105
<Link>
104106
<SubSystem>Console</SubSystem>
105107
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
106108
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
107109
</Link>
110+
<Lib>
111+
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
112+
</Lib>
108113
</ItemDefinitionGroup>
109114
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'">
110115
<ClCompile>
111116
<PrecompiledHeader>NotUsing</PrecompiledHeader>
112117
<CompileAsWinRT>false</CompileAsWinRT>
113118
<SDLCheck>true</SDLCheck>
114119
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
115-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
116121
</ClCompile>
117122
<Link>
118123
<SubSystem>Console</SubSystem>
@@ -126,13 +131,18 @@
126131
<CompileAsWinRT>false</CompileAsWinRT>
127132
<SDLCheck>true</SDLCheck>
128133
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
129-
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
134+
<PreprocessorDefinitions>WINRT;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;BT_HAS_ALIGNED_ALLOCATOR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
135+
<WholeProgramOptimization>false</WholeProgramOptimization>
136+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
130137
</ClCompile>
131138
<Link>
132139
<SubSystem>Console</SubSystem>
133140
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
134141
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
135142
</Link>
143+
<Lib>
144+
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
145+
</Lib>
136146
</ItemDefinitionGroup>
137147
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
138148
<ImportGroup Label="ExtensionTargets">

0 commit comments

Comments
 (0)