From e10d398afdf2a6027696cbdf21708887ec8629b7 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 11 Jun 2009 16:36:55 +0000 Subject: [PATCH] beginning port to osx --- direct/src/plugin/Sources.pp | 4 ++-- direct/src/plugin/p3dInstanceManager.cxx | 18 ++++++++++++++++ direct/src/plugin/p3dInstanceManager.h | 4 +++- direct/src/plugin/p3dPythonRun.cxx | 27 +++++++++++++++++++++++- direct/src/plugin/p3dPythonRun.h | 4 ++++ direct/src/plugin/p3dSession.cxx | 2 -- direct/src/plugin/p3d_lock.h | 22 ++++++++++++++++++- direct/src/plugin/p3d_plugin.h | 3 +++ direct/src/plugin/panda3d.cxx | 13 ++++++++++++ direct/src/showutil/FreezeTool.py | 2 +- 10 files changed, 91 insertions(+), 8 deletions(-) diff --git a/direct/src/plugin/Sources.pp b/direct/src/plugin/Sources.pp index 528005e581..f3cd0d436e 100644 --- a/direct/src/plugin/Sources.pp +++ b/direct/src/plugin/Sources.pp @@ -38,7 +38,7 @@ interrogatedb:c dconfig:c dtoolconfig:m \ express:c pandaexpress:m \ prc:c pstatclient:c pandabase:c linmath:c putil:c \ - pipeline:c panda:m + pipeline:c event:c nativenet:c panda:m #define SOURCES \ handleStream.cxx handleStream.h handleStream.I \ @@ -57,7 +57,7 @@ #define OTHER_LIBS \ prc:c dtoolutil:c dtoolbase:c dtool:m \ interrogatedb:c dconfig:c dtoolconfig:m \ - express:c pandaexpress:m \ + express:c downloader:c pandaexpress:m \ pstatclient:c pandabase:c linmath:c putil:c \ pipeline:c panda:m \ pystub diff --git a/direct/src/plugin/p3dInstanceManager.cxx b/direct/src/plugin/p3dInstanceManager.cxx index 7f64635087..06fb68a408 100644 --- a/direct/src/plugin/p3dInstanceManager.cxx +++ b/direct/src/plugin/p3dInstanceManager.cxx @@ -31,6 +31,9 @@ P3DInstanceManager() { _request_seq = 0; #ifdef _WIN32 _request_ready = CreateEvent(NULL, false, false, NULL); +#else + INIT_LOCK(_request_ready_lock); + pthread_cond_init(&_request_ready_cvar, NULL); #endif } @@ -41,6 +44,13 @@ P3DInstanceManager() { //////////////////////////////////////////////////////////////////// P3DInstanceManager:: ~P3DInstanceManager() { + // Actually, the destructor is never called. +#ifdef _WIN32 + CloseHandle(_request_ready); +#else + DESTROY_LOCK(_request_ready_lock); + pthread_cond_destroy(&_request_ready_cvar); +#endif } //////////////////////////////////////////////////////////////////// @@ -163,7 +173,11 @@ wait_request() { // No pending requests; go to sleep. if (seq == _request_seq) { +#ifdef _WIN32 WaitForSingleObject(_request_ready, INFINITE); +#else + pthread_cond_wait(&_request_ready_cvar, &_request_ready_lock); +#endif } seq = _request_seq; } @@ -194,6 +208,10 @@ signal_request_ready() { ++_request_seq; #ifdef _WIN32 SetEvent(_request_ready); +#else + ACQUIRE_LOCK(_request_ready_lock); + pthread_cond_signal(&_request_ready_cvar); + RELEASE_LOCK(_request_ready_lock); #endif } diff --git a/direct/src/plugin/p3dInstanceManager.h b/direct/src/plugin/p3dInstanceManager.h index 00ea869361..9c0d93b004 100644 --- a/direct/src/plugin/p3dInstanceManager.h +++ b/direct/src/plugin/p3dInstanceManager.h @@ -73,8 +73,10 @@ private: volatile int _request_seq; #ifdef _WIN32 HANDLE _request_ready; +#else + LOCK _request_ready_lock; + pthread_cond_t _request_ready_cvar; #endif - static P3DInstanceManager *_global_ptr; }; diff --git a/direct/src/plugin/p3dPythonRun.cxx b/direct/src/plugin/p3dPythonRun.cxx index 63c027a34d..1ba3a0e143 100755 --- a/direct/src/plugin/p3dPythonRun.cxx +++ b/direct/src/plugin/p3dPythonRun.cxx @@ -234,6 +234,12 @@ spawn_read_thread() { _read_thread_continue = true; #ifdef _WIN32 _read_thread = CreateThread(NULL, 0, &win_rt_thread_run, this, 0, NULL); +#else + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); + pthread_create(&_read_thread, &attr, &posix_rt_thread_run, (void *)this); + pthread_attr_destroy(&attr); #endif } @@ -253,6 +259,9 @@ join_read_thread() { WaitForSingleObject(_read_thread, INFINITE); CloseHandle(_read_thread); _read_thread = NULL; +#else + void *return_val; + pthread_join(_read_thread, &return_val); #endif cerr << "done waiting for thread\n"; } @@ -289,7 +298,10 @@ start_instance(P3DCInstance *inst) { inst->_win_x, inst->_win_y, inst->_win_width, inst->_win_height, #ifdef _WIN32 - (int)(inst->_parent_window._hwnd) + (long)(inst->_parent_window._hwnd) +#endif +#ifdef __APPLE__ + (long)(inst->_parent_window._nswindow) #endif ); if (result == NULL) { @@ -405,6 +417,19 @@ win_rt_thread_run(LPVOID data) { } #endif +#ifndef _WIN32 +//////////////////////////////////////////////////////////////////// +// Function: P3DPython::win_rt_thread_run +// Access: Private, Static +// Description: The Posix flavor of the thread callback function. +//////////////////////////////////////////////////////////////////// +void *P3DPythonRun:: +posix_rt_thread_run(void *data) { + ((P3DPythonRun *)data)->rt_thread_run(); + return NULL; +} +#endif + //////////////////////////////////////////////////////////////////// // Function: main diff --git a/direct/src/plugin/p3dPythonRun.h b/direct/src/plugin/p3dPythonRun.h index 74d9863068..b39f67ca3f 100755 --- a/direct/src/plugin/p3dPythonRun.h +++ b/direct/src/plugin/p3dPythonRun.h @@ -79,6 +79,8 @@ private: void rt_thread_run(); #ifdef _WIN32 static DWORD WINAPI win_rt_thread_run(LPVOID data); +#else + static void *posix_rt_thread_run(void *data); #endif private: @@ -111,6 +113,8 @@ private: bool _program_continue; #ifdef _WIN32 HANDLE _read_thread; +#else + pthread_t _thread; #endif }; diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index 634accd3ab..e222751124 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -17,8 +17,6 @@ #include "p3dInstanceManager.h" #include -#include - //////////////////////////////////////////////////////////////////// // Function: P3DSession::Constructor // Access: Public diff --git a/direct/src/plugin/p3d_lock.h b/direct/src/plugin/p3d_lock.h index ddf58a6837..c8eac2d7be 100755 --- a/direct/src/plugin/p3d_lock.h +++ b/direct/src/plugin/p3d_lock.h @@ -19,12 +19,32 @@ // mutex locks. #ifdef _WIN32 + +// Windows case #define LOCK CRITICAL_SECTION #define INIT_LOCK(lock) InitializeCriticalSection(&(lock)) #define ACQUIRE_LOCK(lock) EnterCriticalSection(&(lock)) #define RELEASE_LOCK(lock) LeaveCriticalSection(&(lock)) #define DESTROY_LOCK(lock) DeleteCriticalSection(&(lock)) -#endif + +#else // _WIN32 + +// Posix case +#include + +#define LOCK pthread_mutex_t +#define INIT_LOCK(lock) { \ + pthread_mutexattr_t attr; \ + pthread_mutexattr_init(&attr); \ + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); \ + int result = pthread_mutex_init(&(lock), &attr); \ + pthread_mutexattr_destroy(&attr); \ + } +#define ACQUIRE_LOCK(lock) pthread_mutex_lock(&(lock)) +#define RELEASE_LOCK(lock) pthread_mutex_unlock(&(lock)) +#define DESTROY_LOCK(lock) pthread_mutex_destroy(&(lock)) + +#endif // _WIN32 #endif diff --git a/direct/src/plugin/p3d_plugin.h b/direct/src/plugin/p3d_plugin.h index 373f0450d1..a88c964c36 100644 --- a/direct/src/plugin/p3d_plugin.h +++ b/direct/src/plugin/p3d_plugin.h @@ -111,6 +111,9 @@ typedef struct { #ifdef _WIN32 HWND _hwnd; #endif +#ifdef __APPLE__ + void *_nswindow; +#endif } P3D_window_handle; /* This enum lists the different kinds of window types that may be diff --git a/direct/src/plugin/panda3d.cxx b/direct/src/plugin/panda3d.cxx index 4d2eb18cce..c2411bf184 100644 --- a/direct/src/plugin/panda3d.cxx +++ b/direct/src/plugin/panda3d.cxx @@ -298,6 +298,17 @@ make_parent_window(P3D_window_handle &parent_window, } #endif // _WIN32 +#ifdef __APPLE__ + +void +make_parent_window(P3D_window_handle &parent_window, + int win_width, int win_height) { + // TODO. + assert(false); +} + +#endif // __APPLE__ + void usage() { cerr @@ -426,6 +437,7 @@ main(int argc, char *argv[]) { make_parent_window(parent_window, win_width, win_height); // Center the child window(s) within the parent window. +#ifdef _WIN32 RECT rect; GetClientRect(parent_window._hwnd, &rect); @@ -433,6 +445,7 @@ main(int argc, char *argv[]) { win_y = (int)(rect.bottom * 0.1); win_width = (int)(rect.right * 0.8); win_height = (int)(rect.bottom * 0.8); +#endif // Subdivide the window into num_x_spans * num_y_spans sub-windows. int num_y_spans = int(sqrt((double)num_instances)); diff --git a/direct/src/showutil/FreezeTool.py b/direct/src/showutil/FreezeTool.py index c2d00b4b5a..9bb4d5d713 100644 --- a/direct/src/showutil/FreezeTool.py +++ b/direct/src/showutil/FreezeTool.py @@ -57,7 +57,7 @@ elif sys.platform == 'darwin': compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 -arch i386 -arch ppc -I %(pythonIPath)s %(filename)s" linkExe = "gcc -o %(basename)s %(basename)s.o -framework Python" - linkDll = "gcc -shared -o %(basename)s.so %(basename)s.o -framework Python" + linkDll = "gcc -dynamiclib -o %(basename)s.so %(basename)s.o -framework Python" else: # Linux