1 
2 #include "SharedMemoryInProcessPhysicsC_API.h"
3 #include "../Utils/b3Clock.h"
4 
5 #include "PhysicsClientSharedMemory.h"
6 #include "../ExampleBrowser/InProcessExampleBrowser.h"
7 #include <stdio.h>
8 #include <string.h>
9 #include "PhysicsServerExampleBullet2.h"
10 #include "../CommonInterfaces/CommonGUIHelperInterface.h"
11 #include "../CommonInterfaces/CommonExampleInterface.h"
12 #include "InProcessMemory.h"
13 #include "RemoteGUIHelper.h"
14 
15 #include "Bullet3Common/b3Logging.h"
16 class InProcessPhysicsClientSharedMemoryMainThread : public PhysicsClientSharedMemory
17 {
18 	btInProcessExampleBrowserMainThreadInternalData* m_data;
19 	b3Clock m_clock;
20 
21 public:
InProcessPhysicsClientSharedMemoryMainThread(int argc,char * argv[],bool useInProcessMemory)22 	InProcessPhysicsClientSharedMemoryMainThread(int argc, char* argv[], bool useInProcessMemory)
23 	{
24 		int newargc = argc + 3;
25 		char** newargv = (char**)malloc(sizeof(void*) * newargc);
26 		char* t0 = (char*)"--unused";
27 		newargv[0] = t0;
28 		for (int i = 0; i < argc; i++)
29 			newargv[i + 1] = argv[i];
30 		newargv[argc + 1] = (char*)"--logtostderr";
31 		newargv[argc + 2] = (char*)"--start_demo_name=Physics Server";
32 
33 		m_data = btCreateInProcessExampleBrowserMainThread(newargc, newargv, useInProcessMemory);
34 		SharedMemoryInterface* shMem = btGetSharedMemoryInterfaceMainThread(m_data);
35 
36 		setSharedMemoryInterface(shMem);
37 	}
38 
~InProcessPhysicsClientSharedMemoryMainThread()39 	virtual ~InProcessPhysicsClientSharedMemoryMainThread()
40 	{
41 		setSharedMemoryInterface(0);
42 		btShutDownExampleBrowserMainThread(m_data);
43 	}
44 
45 	// return non-null if there is a status, nullptr otherwise
processServerStatus()46 	virtual const struct SharedMemoryStatus* processServerStatus()
47 	{
48 		{
49 			if (btIsExampleBrowserMainThreadTerminated(m_data))
50 			{
51 				PhysicsClientSharedMemory::disconnectSharedMemory();
52 			}
53 		}
54 		{
55 			unsigned long int ms = m_clock.getTimeMilliseconds();
56 			if (ms > 2)
57 			{
58 				B3_PROFILE("m_clock.reset()");
59 
60 				btUpdateInProcessExampleBrowserMainThread(m_data);
61 				m_clock.reset();
62 			}
63 		}
64 		{
65 			b3Clock::usleep(0);
66 		}
67 		const SharedMemoryStatus* stat = 0;
68 
69 		{
70 			stat = PhysicsClientSharedMemory::processServerStatus();
71 		}
72 
73 		return stat;
74 	}
75 
submitClientCommand(const struct SharedMemoryCommand & command)76 	virtual bool submitClientCommand(const struct SharedMemoryCommand& command)
77 	{
78 		//        btUpdateInProcessExampleBrowserMainThread(m_data);
79 		return PhysicsClientSharedMemory::submitClientCommand(command);
80 	}
81 };
82 
b3CreateInProcessPhysicsServerAndConnectMainThread(int argc,char * argv[])83 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThread(int argc, char* argv[])
84 {
85 	InProcessPhysicsClientSharedMemoryMainThread* cl = new InProcessPhysicsClientSharedMemoryMainThread(argc, argv, 1);
86 	cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
87 	cl->connect();
88 	return (b3PhysicsClientHandle)cl;
89 }
90 
b3CreateInProcessPhysicsServerAndConnectMainThreadSharedMemory(int argc,char * argv[])91 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThreadSharedMemory(int argc, char* argv[])
92 {
93 	InProcessPhysicsClientSharedMemoryMainThread* cl = new InProcessPhysicsClientSharedMemoryMainThread(argc, argv, 0);
94 	cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
95 	cl->connect();
96 	return (b3PhysicsClientHandle)cl;
97 }
98 
99 
100 
101 class InProcessPhysicsClientSharedMemory : public PhysicsClientSharedMemory
102 {
103 	btInProcessExampleBrowserInternalData* m_data;
104 	char** m_newargv;
105 
106 public:
InProcessPhysicsClientSharedMemory(int argc,char * argv[],bool useInProcessMemory)107 	InProcessPhysicsClientSharedMemory(int argc, char* argv[], bool useInProcessMemory)
108 	{
109 		int newargc = argc + 2;
110 		m_newargv = (char**)malloc(sizeof(void*) * newargc);
111 		char* t0 = (char*)"--unused";
112 		m_newargv[0] = t0;
113 
114 		for (int i = 0; i < argc; i++)
115 			m_newargv[i + 1] = argv[i];
116 
117 		char* t1 = (char*)"--start_demo_name=Physics Server";
118 		m_newargv[argc + 1] = t1;
119 		m_data = btCreateInProcessExampleBrowser(newargc, m_newargv, useInProcessMemory);
120 		SharedMemoryInterface* shMem = btGetSharedMemoryInterface(m_data);
121 		setSharedMemoryInterface(shMem);
122 	}
123 
~InProcessPhysicsClientSharedMemory()124 	virtual ~InProcessPhysicsClientSharedMemory()
125 	{
126 		setSharedMemoryInterface(0);
127 		btShutDownExampleBrowser(m_data);
128 		free(m_newargv);
129 	}
130 };
131 
132 
133 
b3CreateInProcessPhysicsServerAndConnect(int argc,char * argv[])134 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnect(int argc, char* argv[])
135 {
136 	InProcessPhysicsClientSharedMemory* cl = new InProcessPhysicsClientSharedMemory(argc, argv, 1);
137 	cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
138 	cl->connect();
139 	return (b3PhysicsClientHandle)cl;
140 }
b3CreateInProcessPhysicsServerAndConnectSharedMemory(int argc,char * argv[])141 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectSharedMemory(int argc, char* argv[])
142 {
143 	InProcessPhysicsClientSharedMemory* cl = new InProcessPhysicsClientSharedMemory(argc, argv, 0);
144 	cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
145 	cl->connect();
146 	return (b3PhysicsClientHandle)cl;
147 }
148 
149 class InProcessPhysicsClientExistingExampleBrowser : public PhysicsClientSharedMemory
150 {
151 	CommonExampleInterface* m_physicsServerExample;
152 	SharedMemoryInterface* m_sharedMem;
153 	b3Clock m_clock;
154 	unsigned long long int m_prevTime;
155 	struct GUIHelperInterface* m_guiHelper;
156 
157 public:
InProcessPhysicsClientExistingExampleBrowser(struct GUIHelperInterface * guiHelper,bool useInProcessMemory,bool skipGraphicsUpdate,bool ownsGuiHelper)158 	InProcessPhysicsClientExistingExampleBrowser(struct GUIHelperInterface* guiHelper, bool useInProcessMemory, bool skipGraphicsUpdate, bool ownsGuiHelper)
159 	{
160 		m_guiHelper = 0;
161 		if (ownsGuiHelper)
162 		{
163 			m_guiHelper = guiHelper;
164 		}
165 
166 		m_sharedMem = 0;
167 		CommonExampleOptions options(guiHelper);
168 
169 		if (useInProcessMemory)
170 		{
171 			m_sharedMem = new InProcessMemory;
172 			options.m_sharedMem = m_sharedMem;
173 		}
174 
175 		options.m_skipGraphicsUpdate = skipGraphicsUpdate;
176 		m_physicsServerExample = PhysicsServerCreateFuncBullet2(options);
177 		m_physicsServerExample->initPhysics();
178 		//m_physicsServerExample->resetCamera();
179 		setSharedMemoryInterface(m_sharedMem);
180 		m_clock.reset();
181 		m_prevTime = m_clock.getTimeMicroseconds();
182 	}
~InProcessPhysicsClientExistingExampleBrowser()183 	virtual ~InProcessPhysicsClientExistingExampleBrowser()
184 	{
185 		m_physicsServerExample->exitPhysics();
186 		//s_instancingRenderer->removeAllInstances();
187 		delete m_physicsServerExample;
188 		delete m_sharedMem;
189 		delete m_guiHelper;
190 	}
191 
192 	// return non-null if there is a status, nullptr otherwise
processServerStatus()193 	virtual const struct SharedMemoryStatus* processServerStatus()
194 	{
195 		m_physicsServerExample->updateGraphics();
196 
197 		unsigned long long int curTime = m_clock.getTimeMicroseconds();
198 		unsigned long long int dtMicro = curTime - m_prevTime;
199 		m_prevTime = curTime;
200 
201 		double dt = double(dtMicro) / 1000000.;
202 
203 		m_physicsServerExample->stepSimulation(dt);
204 		{
205 			b3Clock::usleep(0);
206 		}
207 		const SharedMemoryStatus* stat = 0;
208 
209 		{
210 			stat = PhysicsClientSharedMemory::processServerStatus();
211 		}
212 
213 		return stat;
214 	}
215 
renderScene()216 	virtual void renderScene()
217 	{
218 		m_physicsServerExample->renderScene();
219 	}
debugDraw(int debugDrawMode)220 	virtual void debugDraw(int debugDrawMode)
221 	{
222 		m_physicsServerExample->physicsDebugDraw(debugDrawMode);
223 	}
mouseMoveCallback(float x,float y)224 	virtual bool mouseMoveCallback(float x, float y)
225 	{
226 		return m_physicsServerExample->mouseMoveCallback(x, y);
227 	}
mouseButtonCallback(int button,int state,float x,float y)228 	virtual bool mouseButtonCallback(int button, int state, float x, float y)
229 	{
230 		return m_physicsServerExample->mouseButtonCallback(button, state, x, y);
231 	}
232 };
233 
b3InProcessDebugDrawInternal(b3PhysicsClientHandle clientHandle,int debugDrawMode)234 void b3InProcessDebugDrawInternal(b3PhysicsClientHandle clientHandle, int debugDrawMode)
235 {
236 	InProcessPhysicsClientExistingExampleBrowser* cl = (InProcessPhysicsClientExistingExampleBrowser*)clientHandle;
237 	cl->debugDraw(debugDrawMode);
238 }
b3InProcessRenderSceneInternal(b3PhysicsClientHandle clientHandle)239 void b3InProcessRenderSceneInternal(b3PhysicsClientHandle clientHandle)
240 {
241 	InProcessPhysicsClientExistingExampleBrowser* cl = (InProcessPhysicsClientExistingExampleBrowser*)clientHandle;
242 	cl->renderScene();
243 }
244 
b3InProcessMouseMoveCallback(b3PhysicsClientHandle clientHandle,float x,float y)245 int b3InProcessMouseMoveCallback(b3PhysicsClientHandle clientHandle, float x, float y)
246 {
247 	InProcessPhysicsClientExistingExampleBrowser* cl = (InProcessPhysicsClientExistingExampleBrowser*)clientHandle;
248 	return cl->mouseMoveCallback(x, y);
249 }
b3InProcessMouseButtonCallback(b3PhysicsClientHandle clientHandle,int button,int state,float x,float y)250 int b3InProcessMouseButtonCallback(b3PhysicsClientHandle clientHandle, int button, int state, float x, float y)
251 {
252 	InProcessPhysicsClientExistingExampleBrowser* cl = (InProcessPhysicsClientExistingExampleBrowser*)clientHandle;
253 	return cl->mouseButtonCallback(button, state, x, y);
254 }
255 
b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(void * guiHelperPtr)256 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(void* guiHelperPtr)
257 {
258 	static DummyGUIHelper noGfx;
259 
260 	GUIHelperInterface* guiHelper = (GUIHelperInterface*)guiHelperPtr;
261 	if (!guiHelper)
262 	{
263 		guiHelper = &noGfx;
264 	}
265 	bool useInprocessMemory = true;
266 	bool skipGraphicsUpdate = false;
267 
268 	InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper, useInprocessMemory, skipGraphicsUpdate, false);
269 
270 	cl->connect();
271 	return (b3PhysicsClientHandle)cl;
272 }
273 
274 extern int gSharedMemoryKey;
275 
b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect3(void * guiHelperPtr,int sharedMemoryKey)276 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect3(void* guiHelperPtr, int sharedMemoryKey)
277 {
278 	static DummyGUIHelper noGfx;
279 
280 	gSharedMemoryKey = sharedMemoryKey;
281 	GUIHelperInterface* guiHelper = (GUIHelperInterface*)guiHelperPtr;
282 	if (!guiHelper)
283 	{
284 		guiHelper = &noGfx;
285 	}
286 	bool useInprocessMemory = false;
287 	bool skipGraphicsUpdate = true;
288 	InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper, useInprocessMemory, skipGraphicsUpdate, false);
289 
290 	cl->setSharedMemoryKey(sharedMemoryKey + 1);
291 	cl->connect();
292 	//backward compatiblity
293 	gSharedMemoryKey = SHARED_MEMORY_KEY;
294 	return (b3PhysicsClientHandle)cl;
295 }
296 
b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect4(void * guiHelperPtr,int sharedMemoryKey)297 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect4(void* guiHelperPtr, int sharedMemoryKey)
298 {
299 	gSharedMemoryKey = sharedMemoryKey;
300 	GUIHelperInterface* guiHelper = (GUIHelperInterface*)guiHelperPtr;
301 	bool ownsGuiHelper = false;
302 	if (!guiHelper)
303 	{
304 		guiHelper = new RemoteGUIHelper();
305 		ownsGuiHelper = true;
306 	}
307 	bool useInprocessMemory = false;
308 	bool skipGraphicsUpdate = false;
309 	InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper, useInprocessMemory, skipGraphicsUpdate, ownsGuiHelper);
310 
311 	cl->setSharedMemoryKey(sharedMemoryKey + 1);
312 	cl->connect();
313 	//backward compatiblity
314 	gSharedMemoryKey = SHARED_MEMORY_KEY;
315 	return (b3PhysicsClientHandle)cl;
316 }
317 
318 #ifdef BT_ENABLE_CLSOCKET
319 #include "RemoteGUIHelperTCP.h"
320 
b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnectTCP(const char * hostName,int port)321 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnectTCP(const char* hostName, int port)
322 {
323 	bool ownsGuiHelper = true;
324 	GUIHelperInterface* guiHelper = new RemoteGUIHelperTCP(hostName, port);
325 
326 	bool useInprocessMemory = true;
327 	bool skipGraphicsUpdate = false;
328 	InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper, useInprocessMemory, skipGraphicsUpdate, ownsGuiHelper);
329 
330 	//cl->setSharedMemoryKey(sharedMemoryKey + 1);
331 	cl->connect();
332 	//backward compatiblity
333 	gSharedMemoryKey = SHARED_MEMORY_KEY;
334 	return (b3PhysicsClientHandle)cl;
335 }
336 
337 
338 
339 //backward compatiblity
b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect2(void * guiHelperPtr)340 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect2(void* guiHelperPtr)
341 {
342 	return b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect3(guiHelperPtr, SHARED_MEMORY_KEY);
343 }
344 
345 
346 
347 #include "SharedMemoryCommands.h"
348 #include "PhysicsClientSharedMemory.h"
349 #include "GraphicsSharedMemoryBlock.h"
350 #include "PosixSharedMemory.h"
351 #include "Win32SharedMemory.h"
352 class InProcessGraphicsServerSharedMemory : public PhysicsClientSharedMemory
353 {
354 	btInProcessExampleBrowserInternalData* m_data2;
355 	char** m_newargv;
356 	SharedMemoryCommand m_command;
357 
358 	GraphicsSharedMemoryBlock* m_testBlock1;
359 	SharedMemoryInterface* m_sharedMemory;
360 
361 public:
InProcessGraphicsServerSharedMemory(int port)362 	InProcessGraphicsServerSharedMemory(int port)
363 	{
364 		int newargc = 3;
365 		m_newargv = (char**)malloc(sizeof(void*) * newargc);
366 		char* t0 = (char*)"--unused";
367 		m_newargv[0] = t0;
368 
369 		char* t1 = (char*)"--start_demo_name=Graphics Server";
370 		char portArg[1024];
371 		sprintf(portArg, "--port=%d", port);
372 
373 		m_newargv[1] = t1;
374 		m_newargv[2] = portArg;
375 		bool useInProcessMemory = false;
376 		m_data2 = btCreateInProcessExampleBrowser(newargc, m_newargv, useInProcessMemory);
377 		SharedMemoryInterface* shMem = btGetSharedMemoryInterface(m_data2);
378 
379 		setSharedMemoryInterface(shMem);
380 		///////////////////
381 
382 #ifdef _WIN32
383 		m_sharedMemory = new Win32SharedMemoryServer();
384 #else
385 		m_sharedMemory = new PosixSharedMemory();
386 #endif
387 
388 			/// server always has to create and initialize shared memory
389 		bool allowCreation = false;
390 		m_testBlock1 = (GraphicsSharedMemoryBlock*)m_sharedMemory->allocateSharedMemory(
391 			GRAPHICS_SHARED_MEMORY_KEY, GRAPHICS_SHARED_MEMORY_SIZE, allowCreation);
392 
393 	}
394 
~InProcessGraphicsServerSharedMemory()395 	virtual ~InProcessGraphicsServerSharedMemory()
396 	{
397 		m_sharedMemory->releaseSharedMemory(GRAPHICS_SHARED_MEMORY_KEY, GRAPHICS_SHARED_MEMORY_SIZE);
398 		delete m_sharedMemory;
399 
400 		setSharedMemoryInterface(0);
401 		btShutDownExampleBrowser(m_data2);
402 		free(m_newargv);
403 	}
canSubmitCommand() const404 	virtual bool canSubmitCommand() const
405 	{
406 		if (m_testBlock1)
407 		{
408 			if (m_testBlock1->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
409 			{
410 				return false;
411 			}
412 		}
413 		return true;
414 	}
415 
getAvailableSharedMemoryCommand()416 	virtual struct SharedMemoryCommand* getAvailableSharedMemoryCommand()
417 	{
418 		return &m_command;
419 	}
420 
submitClientCommand(const struct SharedMemoryCommand & command)421 	virtual bool submitClientCommand(const struct SharedMemoryCommand& command)
422 	{
423 		switch (command.m_type)
424 		{
425 		default:
426 		{
427 		}
428 		}
429 		return true;
430 	}
431 
432 
433 };
434 
435 
436 class InProcessGraphicsServerSharedMemoryMainThread : public PhysicsClientSharedMemory
437 {
438 
439 	btInProcessExampleBrowserMainThreadInternalData* m_data2;
440 	char** m_newargv;
441 	SharedMemoryCommand m_command;
442 
443 	GraphicsSharedMemoryBlock* m_testBlock1;
444 	SharedMemoryInterface* m_sharedMemory;
445 	b3Clock m_clock;
446 
447 public:
InProcessGraphicsServerSharedMemoryMainThread(int port)448 	InProcessGraphicsServerSharedMemoryMainThread(int port)
449 	{
450 		int newargc = 3;
451 		m_newargv = (char**)malloc(sizeof(void*) * newargc);
452 		char* t0 = (char*)"--unused";
453 		m_newargv[0] = t0;
454 
455 
456 		char* t1 = (char*)"--start_demo_name=Graphics Server";
457 		m_newargv[1] = t1;
458 		char portArg[1024];
459 		sprintf(portArg, "--port=%d", port);
460 		m_newargv[2] = portArg;
461 
462 		bool useInProcessMemory = false;
463 		m_data2 = btCreateInProcessExampleBrowserMainThread(newargc, m_newargv, useInProcessMemory);
464 		SharedMemoryInterface* shMem = btGetSharedMemoryInterfaceMainThread(m_data2);
465 
466 		setSharedMemoryInterface(shMem);
467 		///////////////////
468 
469 #ifdef _WIN32
470 		m_sharedMemory = new Win32SharedMemoryServer();
471 #else
472 		m_sharedMemory = new PosixSharedMemory();
473 #endif
474 
475 		/// server always has to create and initialize shared memory
476 		bool allowCreation = false;
477 		m_testBlock1 = (GraphicsSharedMemoryBlock*)m_sharedMemory->allocateSharedMemory(
478 			GRAPHICS_SHARED_MEMORY_KEY, GRAPHICS_SHARED_MEMORY_SIZE, allowCreation);
479 		m_clock.reset();
480 	}
481 
~InProcessGraphicsServerSharedMemoryMainThread()482 	virtual ~InProcessGraphicsServerSharedMemoryMainThread()
483 	{
484 		m_sharedMemory->releaseSharedMemory(GRAPHICS_SHARED_MEMORY_KEY, GRAPHICS_SHARED_MEMORY_SIZE);
485 		delete m_sharedMemory;
486 
487 		setSharedMemoryInterface(0);
488 		btShutDownExampleBrowserMainThread(m_data2);
489 		free(m_newargv);
490 	}
canSubmitCommand() const491 	virtual bool canSubmitCommand() const
492 	{
493 		btUpdateInProcessExampleBrowserMainThread(m_data2);
494 		if (m_testBlock1)
495 		{
496 			if (m_testBlock1->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
497 			{
498 				return false;
499 			}
500 		}
501 		return true;
502 	}
503 
getAvailableSharedMemoryCommand()504 	virtual struct SharedMemoryCommand* getAvailableSharedMemoryCommand()
505 	{
506 		return &m_command;
507 	}
508 
submitClientCommand(const struct SharedMemoryCommand & command)509 	virtual bool submitClientCommand(const struct SharedMemoryCommand& command)
510 	{
511 		switch (command.m_type)
512 		{
513 		default:
514 		{
515 		}
516 		}
517 		return true;
518 	}
519 
520 	// return non-null if there is a status, nullptr otherwise
processServerStatus()521 	virtual const struct SharedMemoryStatus* processServerStatus()
522 	{
523 		{
524 			if (btIsExampleBrowserMainThreadTerminated(m_data2))
525 			{
526 				PhysicsClientSharedMemory::disconnectSharedMemory();
527 			}
528 		}
529 		{
530 			unsigned long int ms = m_clock.getTimeMilliseconds();
531 			if (ms > 2)
532 			{
533 				B3_PROFILE("m_clock.reset()");
534 
535 				btUpdateInProcessExampleBrowserMainThread(m_data2);
536 				m_clock.reset();
537 			}
538 		}
539 		{
540 			b3Clock::usleep(0);
541 		}
542 		const SharedMemoryStatus* stat = 0;
543 
544 		{
545 			stat = PhysicsClientSharedMemory::processServerStatus();
546 		}
547 
548 		return stat;
549 	}
550 
551 };
552 
553 
554 
b3CreateInProcessGraphicsServerAndConnectSharedMemory(int port)555 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessGraphicsServerAndConnectSharedMemory(int port)
556 {
557 	InProcessGraphicsServerSharedMemory* cl = new InProcessGraphicsServerSharedMemory(port);
558 	cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
559 	cl->connect();
560 	return (b3PhysicsClientHandle)cl;
561 }
562 
b3CreateInProcessGraphicsServerAndConnectMainThreadSharedMemory(int port)563 B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessGraphicsServerAndConnectMainThreadSharedMemory(int port)
564 {
565 	InProcessGraphicsServerSharedMemoryMainThread* cl = new InProcessGraphicsServerSharedMemoryMainThread(port);
566 	cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
567 	cl->connect();
568 	return (b3PhysicsClientHandle)cl;
569 }
570 
571 #endif
572