From 2cbfeb9590027d9927d6adffee6dfd6e0dbd8476 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 14 Apr 2016 08:51:20 -0700 Subject: [PATCH 1/2] run GUI on main thread for Mac OSX/__APPLE__, due to OS limitation add b3CreateInProcessPhysicsServerAndConnectMainThread to test.c --- build3/premake4.lua | 38 +++--- .../InProcessExampleBrowser.cpp | 43 +++++++ .../ExampleBrowser/InProcessExampleBrowser.h | 18 +++ examples/ExampleBrowser/main.cpp | 21 ++++ examples/ExampleBrowser/premake4.lua | 117 +++++++++--------- .../SharedMemoryInProcessPhysicsC_API.cpp | 54 ++++++++ .../SharedMemoryInProcessPhysicsC_API.h | 5 + test/SharedMemory/test.c | 7 +- 8 files changed, 225 insertions(+), 78 deletions(-) diff --git a/build3/premake4.lua b/build3/premake4.lua index 2cf1046ad..7f60a1d0e 100644 --- a/build3/premake4.lua +++ b/build3/premake4.lua @@ -176,25 +176,6 @@ language "C++" - if _OPTIONS["no-bullet3"] then - print "--no-bullet3 implies --no-demos" - _OPTIONS["no-demos"] = "1" - else - include "../src/Bullet3Common" - include "../src/Bullet3Geometry" - include "../src/Bullet3Collision" - include "../src/Bullet3Dynamics" - include "../src/Bullet3OpenCL" - include "../src/Bullet3Serialize/Bullet2FileLoader" - end - - if _OPTIONS["no-extras"] then - print "--no-extras implies --no-demos" - _OPTIONS["no-demos"] = "1" - else - include "../Extras" - end - if not _OPTIONS["no-demos"] then include "../examples/ExampleBrowser" include "../examples/OpenGLWindow" @@ -221,6 +202,25 @@ end end + if _OPTIONS["no-bullet3"] then + print "--no-bullet3 implies --no-demos" + _OPTIONS["no-demos"] = "1" + else + include "../src/Bullet3Common" + include "../src/Bullet3Geometry" + include "../src/Bullet3Collision" + include "../src/Bullet3Dynamics" + include "../src/Bullet3OpenCL" + include "../src/Bullet3Serialize/Bullet2FileLoader" + end + + if _OPTIONS["no-extras"] then + print "--no-extras implies --no-demos" + _OPTIONS["no-demos"] = "1" + else + include "../Extras" + end + if not _OPTIONS["no-test"] then include "../test/Bullet2" diff --git a/examples/ExampleBrowser/InProcessExampleBrowser.cpp b/examples/ExampleBrowser/InProcessExampleBrowser.cpp index 047f8d3b7..d9be45726 100644 --- a/examples/ExampleBrowser/InProcessExampleBrowser.cpp +++ b/examples/ExampleBrowser/InProcessExampleBrowser.cpp @@ -229,3 +229,46 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data) delete data; } +struct btInProcessExampleBrowserMainThreadInternalData +{ + ExampleEntries m_examples; + DefaultBrowser* m_exampleBrowser; + SharedMemoryInterface* m_sharedMem; + b3Clock m_clock; +}; + +btInProcessExampleBrowserMainThreadInternalData* btCreateInProcessExampleBrowserMainThread(int argc,char** argv) +{ + btInProcessExampleBrowserMainThreadInternalData* data = new btInProcessExampleBrowserMainThreadInternalData; + data->m_examples.initExampleEntries(); + data->m_exampleBrowser = new DefaultBrowser(&data->m_examples); + data->m_sharedMem = new InProcessMemory; + data->m_exampleBrowser->setSharedMemoryInterface(data->m_sharedMem ); + bool init = data->m_exampleBrowser->init(argc,argv); + data->m_clock.reset(); + return data; +} + +bool btIsExampleBrowserMainThreadTerminated(btInProcessExampleBrowserMainThreadInternalData* data) +{ + return data->m_exampleBrowser->requestedExit(); +} + +void btUpdateInProcessExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data) +{ + float deltaTimeInSeconds = data->m_clock.getTimeMicroseconds()/1000000.f; + data->m_clock.reset(); + data->m_exampleBrowser->update(deltaTimeInSeconds); +} +void btShutDownExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data) +{ + + data->m_exampleBrowser->setSharedMemoryInterface(0); + delete data->m_exampleBrowser; + delete data; +} + +class SharedMemoryInterface* btGetSharedMemoryInterfaceMainThread(btInProcessExampleBrowserMainThreadInternalData* data) +{ + return data->m_sharedMem; +} diff --git a/examples/ExampleBrowser/InProcessExampleBrowser.h b/examples/ExampleBrowser/InProcessExampleBrowser.h index c294f6873..e01d3fd91 100644 --- a/examples/ExampleBrowser/InProcessExampleBrowser.h +++ b/examples/ExampleBrowser/InProcessExampleBrowser.h @@ -12,4 +12,22 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data); class SharedMemoryInterface* btGetSharedMemoryInterface(btInProcessExampleBrowserInternalData* data); +/////////////////////// + + +struct btInProcessExampleBrowserMainThreadInternalData; + +btInProcessExampleBrowserMainThreadInternalData* btCreateInProcessExampleBrowserMainThread(int argc,char** argv2); + +bool btIsExampleBrowserMainThreadTerminated(btInProcessExampleBrowserMainThreadInternalData* data); + +void btUpdateInProcessExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data); + +void btShutDownExampleBrowserMainThread(btInProcessExampleBrowserMainThreadInternalData* data); + +class SharedMemoryInterface* btGetSharedMemoryInterfaceMainThread(btInProcessExampleBrowserMainThreadInternalData* data); + + +////////////////////// + #endif //IN_PROCESS_EXAMPLE_BROWSER_H diff --git a/examples/ExampleBrowser/main.cpp b/examples/ExampleBrowser/main.cpp index c3442de73..f8a8836f4 100644 --- a/examples/ExampleBrowser/main.cpp +++ b/examples/ExampleBrowser/main.cpp @@ -1,4 +1,24 @@ + +#include "InProcessExampleBrowserMainThread.h" + +int main(int argc, char* argv[]) +{ + + btInProcessExampleBrowserMainThreadInternalData* data = btCreateInProcessExampleBrowserMainThread(argc,argv); + + while (!btIsExampleBrowserMainThreadTerminated(data)) + { + btUpdateInProcessExampleBrowserMainThread(data, 1./60.); + } + btShutDownExampleBrowserMainThread(data); + + + return 0; +} + + +#if 0 //#define EXAMPLE_CONSOLE_ONLY #ifdef EXAMPLE_CONSOLE_ONLY #include "EmptyBrowser.h" @@ -43,3 +63,4 @@ int main(int argc, char* argv[]) return 0; } +#endif \ No newline at end of file diff --git a/examples/ExampleBrowser/premake4.lua b/examples/ExampleBrowser/premake4.lua index 90c61cfc2..d13b30228 100644 --- a/examples/ExampleBrowser/premake4.lua +++ b/examples/ExampleBrowser/premake4.lua @@ -1,5 +1,63 @@ +project "App_BulletExampleBrowser" + + language "C++" + + kind "ConsoleApp" + + hasCL = findOpenCL("clew") + + if (hasCL) then + + -- project ("App_Bullet3_OpenCL_Demos_" .. vendor) + + initOpenCL("clew") + + end + + links{"BulletExampleBrowserLib","gwen", "OpenGL_Window","BulletSoftBody", "BulletInverseDynamicsUtils", "BulletInverseDynamics", "BulletDynamics","BulletCollision","LinearMath","Bullet3Common"} + initOpenGL() + initGlew() + + includedirs { + ".", + "../../src", + "../ThirdPartyLibs", + } + + + if os.is("MacOSX") then + links{"Cocoa.framework"} + end + + if (hasCL) then + links { + "Bullet3OpenCL_clew", + "Bullet3Dynamics", + "Bullet3Collision", + "Bullet3Geometry", + "Bullet3Common", + } + end + + if _OPTIONS["lua"] then + includedirs{"../ThirdPartyLibs/lua-5.2.3/src"} + links {"lua-5.2.3"} + defines {"ENABLE_LUA"} + files {"../LuaDemo/LuaPhysicsSetup.cpp"} + end + + files { + "main.cpp", + "ExampleEntries.cpp", + } + +if os.is("Linux") then + initX11() +end + + - project "BulletExampleBrowserLib" +project "BulletExampleBrowserLib" hasCL = findOpenCL("clew") @@ -145,61 +203,4 @@ if os.is("Linux") then end -project "App_BulletExampleBrowser" - - language "C++" - - kind "ConsoleApp" - - hasCL = findOpenCL("clew") - - if (hasCL) then - - -- project ("App_Bullet3_OpenCL_Demos_" .. vendor) - - initOpenCL("clew") - - end - - links{"BulletExampleBrowserLib","gwen", "OpenGL_Window","BulletSoftBody", "BulletInverseDynamicsUtils", "BulletInverseDynamics", "BulletDynamics","BulletCollision","LinearMath","Bullet3Common"} - initOpenGL() - initGlew() - - includedirs { - ".", - "../../src", - "../ThirdPartyLibs", - } - - - if os.is("MacOSX") then - links{"Cocoa.framework"} - end - - if (hasCL) then - links { - "Bullet3OpenCL_clew", - "Bullet3Dynamics", - "Bullet3Collision", - "Bullet3Geometry", - "Bullet3Common", - } - end - - if _OPTIONS["lua"] then - includedirs{"../ThirdPartyLibs/lua-5.2.3/src"} - links {"lua-5.2.3"} - defines {"ENABLE_LUA"} - files {"../LuaDemo/LuaPhysicsSetup.cpp"} - end - - files { - "main.cpp", - "ExampleEntries.cpp", - } - -if os.is("Linux") then - initX11() -end - diff --git a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp index 58c161ee4..e34011faa 100644 --- a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp +++ b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp @@ -1,9 +1,63 @@ #include "SharedMemoryInProcessPhysicsC_API.h" + #include "PhysicsClientSharedMemory.h" #include"../ExampleBrowser/InProcessExampleBrowser.h" +#include"../ExampleBrowser/InProcessExampleBrowserMainThread.h" + +class InProcessPhysicsClientSharedMemoryMainThread : public PhysicsClientSharedMemory +{ + btInProcessExampleBrowserMainThreadInternalData* m_data; +public: + + InProcessPhysicsClientSharedMemoryMainThread(int argc, char* argv[]) + { + int newargc = argc+2; + char** newargv = (char**)malloc(sizeof(void*)*newargc); + for (int i=0;isetSharedMemoryKey(SHARED_MEMORY_KEY); + cl->connect(); + return (b3PhysicsClientHandle ) cl; +} + class InProcessPhysicsClientSharedMemory : public PhysicsClientSharedMemory { btInProcessExampleBrowserInternalData* m_data; diff --git a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.h b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.h index f405e7fc5..7e68a64f8 100644 --- a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.h +++ b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.h @@ -11,6 +11,11 @@ extern "C" { ///think more about naming. The b3ConnectPhysicsLoopback b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnect(int argc, char* argv[]); + +b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThread(int argc, char* argv[]); + + + #ifdef __cplusplus } diff --git a/test/SharedMemory/test.c b/test/SharedMemory/test.c index a37efc3ce..4d9557fc3 100644 --- a/test/SharedMemory/test.c +++ b/test/SharedMemory/test.c @@ -241,7 +241,12 @@ int main(int argc, char* argv[]) #endif #ifdef PHYSICS_IN_PROCESS_EXAMPLE_BROWSER - b3PhysicsClientHandle sm = b3CreateInProcessPhysicsServerAndConnect(argc,argv); + +#ifdef __APPLE__ + b3PhysicsClientHandle sm = b3CreateInProcessPhysicsServerAndConnectMainThread(argc,argv); +#else + b3PhysicsClientHandle sm = b3CreateInProcessPhysicsServerAndConnect(argc,argv); +#endif //__APPLE__ #endif #ifdef PHYSICS_SHARED_MEMORY b3PhysicsClientHandle sm = b3ConnectSharedMemory(SHARED_MEMORY_KEY); From 59e0bef9887d90b658477cb4a2f21f88eb1940b9 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 14 Apr 2016 12:19:55 -0700 Subject: [PATCH 2/2] remove compile errors and some debug code in ExampleBrowser. --- examples/ExampleBrowser/main.cpp | 21 ------------------- .../SharedMemoryInProcessPhysicsC_API.cpp | 1 - 2 files changed, 22 deletions(-) diff --git a/examples/ExampleBrowser/main.cpp b/examples/ExampleBrowser/main.cpp index f8a8836f4..c3442de73 100644 --- a/examples/ExampleBrowser/main.cpp +++ b/examples/ExampleBrowser/main.cpp @@ -1,24 +1,4 @@ - -#include "InProcessExampleBrowserMainThread.h" - -int main(int argc, char* argv[]) -{ - - btInProcessExampleBrowserMainThreadInternalData* data = btCreateInProcessExampleBrowserMainThread(argc,argv); - - while (!btIsExampleBrowserMainThreadTerminated(data)) - { - btUpdateInProcessExampleBrowserMainThread(data, 1./60.); - } - btShutDownExampleBrowserMainThread(data); - - - return 0; -} - - -#if 0 //#define EXAMPLE_CONSOLE_ONLY #ifdef EXAMPLE_CONSOLE_ONLY #include "EmptyBrowser.h" @@ -63,4 +43,3 @@ int main(int argc, char* argv[]) return 0; } -#endif \ No newline at end of file diff --git a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp index e34011faa..01f66410d 100644 --- a/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp +++ b/examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp @@ -3,7 +3,6 @@ #include "PhysicsClientSharedMemory.h" #include"../ExampleBrowser/InProcessExampleBrowser.h" -#include"../ExampleBrowser/InProcessExampleBrowserMainThread.h"