mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
beginning port to osx
This commit is contained in:
parent
c36c100def
commit
e10d398afd
@ -38,7 +38,7 @@
|
|||||||
interrogatedb:c dconfig:c dtoolconfig:m \
|
interrogatedb:c dconfig:c dtoolconfig:m \
|
||||||
express:c pandaexpress:m \
|
express:c pandaexpress:m \
|
||||||
prc:c pstatclient:c pandabase:c linmath:c putil:c \
|
prc:c pstatclient:c pandabase:c linmath:c putil:c \
|
||||||
pipeline:c panda:m
|
pipeline:c event:c nativenet:c panda:m
|
||||||
|
|
||||||
#define SOURCES \
|
#define SOURCES \
|
||||||
handleStream.cxx handleStream.h handleStream.I \
|
handleStream.cxx handleStream.h handleStream.I \
|
||||||
@ -57,7 +57,7 @@
|
|||||||
#define OTHER_LIBS \
|
#define OTHER_LIBS \
|
||||||
prc:c dtoolutil:c dtoolbase:c dtool:m \
|
prc:c dtoolutil:c dtoolbase:c dtool:m \
|
||||||
interrogatedb:c dconfig:c dtoolconfig: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 \
|
pstatclient:c pandabase:c linmath:c putil:c \
|
||||||
pipeline:c panda:m \
|
pipeline:c panda:m \
|
||||||
pystub
|
pystub
|
||||||
|
@ -31,6 +31,9 @@ P3DInstanceManager() {
|
|||||||
_request_seq = 0;
|
_request_seq = 0;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
_request_ready = CreateEvent(NULL, false, false, NULL);
|
_request_ready = CreateEvent(NULL, false, false, NULL);
|
||||||
|
#else
|
||||||
|
INIT_LOCK(_request_ready_lock);
|
||||||
|
pthread_cond_init(&_request_ready_cvar, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +44,13 @@ P3DInstanceManager() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
P3DInstanceManager::
|
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.
|
// No pending requests; go to sleep.
|
||||||
if (seq == _request_seq) {
|
if (seq == _request_seq) {
|
||||||
|
#ifdef _WIN32
|
||||||
WaitForSingleObject(_request_ready, INFINITE);
|
WaitForSingleObject(_request_ready, INFINITE);
|
||||||
|
#else
|
||||||
|
pthread_cond_wait(&_request_ready_cvar, &_request_ready_lock);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
seq = _request_seq;
|
seq = _request_seq;
|
||||||
}
|
}
|
||||||
@ -194,6 +208,10 @@ signal_request_ready() {
|
|||||||
++_request_seq;
|
++_request_seq;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
SetEvent(_request_ready);
|
SetEvent(_request_ready);
|
||||||
|
#else
|
||||||
|
ACQUIRE_LOCK(_request_ready_lock);
|
||||||
|
pthread_cond_signal(&_request_ready_cvar);
|
||||||
|
RELEASE_LOCK(_request_ready_lock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +73,10 @@ private:
|
|||||||
volatile int _request_seq;
|
volatile int _request_seq;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE _request_ready;
|
HANDLE _request_ready;
|
||||||
|
#else
|
||||||
|
LOCK _request_ready_lock;
|
||||||
|
pthread_cond_t _request_ready_cvar;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static P3DInstanceManager *_global_ptr;
|
static P3DInstanceManager *_global_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -234,6 +234,12 @@ spawn_read_thread() {
|
|||||||
_read_thread_continue = true;
|
_read_thread_continue = true;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
_read_thread = CreateThread(NULL, 0, &win_rt_thread_run, this, 0, NULL);
|
_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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +259,9 @@ join_read_thread() {
|
|||||||
WaitForSingleObject(_read_thread, INFINITE);
|
WaitForSingleObject(_read_thread, INFINITE);
|
||||||
CloseHandle(_read_thread);
|
CloseHandle(_read_thread);
|
||||||
_read_thread = NULL;
|
_read_thread = NULL;
|
||||||
|
#else
|
||||||
|
void *return_val;
|
||||||
|
pthread_join(_read_thread, &return_val);
|
||||||
#endif
|
#endif
|
||||||
cerr << "done waiting for thread\n";
|
cerr << "done waiting for thread\n";
|
||||||
}
|
}
|
||||||
@ -289,7 +298,10 @@ start_instance(P3DCInstance *inst) {
|
|||||||
inst->_win_x, inst->_win_y,
|
inst->_win_x, inst->_win_y,
|
||||||
inst->_win_width, inst->_win_height,
|
inst->_win_width, inst->_win_height,
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
(int)(inst->_parent_window._hwnd)
|
(long)(inst->_parent_window._hwnd)
|
||||||
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
(long)(inst->_parent_window._nswindow)
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
@ -405,6 +417,19 @@ win_rt_thread_run(LPVOID data) {
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
// Function: main
|
||||||
|
@ -79,6 +79,8 @@ private:
|
|||||||
void rt_thread_run();
|
void rt_thread_run();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static DWORD WINAPI win_rt_thread_run(LPVOID data);
|
static DWORD WINAPI win_rt_thread_run(LPVOID data);
|
||||||
|
#else
|
||||||
|
static void *posix_rt_thread_run(void *data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -111,6 +113,8 @@ private:
|
|||||||
bool _program_continue;
|
bool _program_continue;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE _read_thread;
|
HANDLE _read_thread;
|
||||||
|
#else
|
||||||
|
pthread_t _thread;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
#include "p3dInstanceManager.h"
|
#include "p3dInstanceManager.h"
|
||||||
#include <tinyxml.h>
|
#include <tinyxml.h>
|
||||||
|
|
||||||
#include <malloc.h>
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: P3DSession::Constructor
|
// Function: P3DSession::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -19,12 +19,32 @@
|
|||||||
// mutex locks.
|
// mutex locks.
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
// Windows case
|
||||||
#define LOCK CRITICAL_SECTION
|
#define LOCK CRITICAL_SECTION
|
||||||
#define INIT_LOCK(lock) InitializeCriticalSection(&(lock))
|
#define INIT_LOCK(lock) InitializeCriticalSection(&(lock))
|
||||||
#define ACQUIRE_LOCK(lock) EnterCriticalSection(&(lock))
|
#define ACQUIRE_LOCK(lock) EnterCriticalSection(&(lock))
|
||||||
#define RELEASE_LOCK(lock) LeaveCriticalSection(&(lock))
|
#define RELEASE_LOCK(lock) LeaveCriticalSection(&(lock))
|
||||||
#define DESTROY_LOCK(lock) DeleteCriticalSection(&(lock))
|
#define DESTROY_LOCK(lock) DeleteCriticalSection(&(lock))
|
||||||
#endif
|
|
||||||
|
#else // _WIN32
|
||||||
|
|
||||||
|
// Posix case
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#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
|
#endif
|
||||||
|
|
||||||
|
@ -111,6 +111,9 @@ typedef struct {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HWND _hwnd;
|
HWND _hwnd;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __APPLE__
|
||||||
|
void *_nswindow;
|
||||||
|
#endif
|
||||||
} P3D_window_handle;
|
} P3D_window_handle;
|
||||||
|
|
||||||
/* This enum lists the different kinds of window types that may be
|
/* This enum lists the different kinds of window types that may be
|
||||||
|
@ -298,6 +298,17 @@ make_parent_window(P3D_window_handle &parent_window,
|
|||||||
}
|
}
|
||||||
#endif // _WIN32
|
#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
|
void
|
||||||
usage() {
|
usage() {
|
||||||
cerr
|
cerr
|
||||||
@ -426,6 +437,7 @@ main(int argc, char *argv[]) {
|
|||||||
make_parent_window(parent_window, win_width, win_height);
|
make_parent_window(parent_window, win_width, win_height);
|
||||||
|
|
||||||
// Center the child window(s) within the parent window.
|
// Center the child window(s) within the parent window.
|
||||||
|
#ifdef _WIN32
|
||||||
RECT rect;
|
RECT rect;
|
||||||
GetClientRect(parent_window._hwnd, &rect);
|
GetClientRect(parent_window._hwnd, &rect);
|
||||||
|
|
||||||
@ -433,6 +445,7 @@ main(int argc, char *argv[]) {
|
|||||||
win_y = (int)(rect.bottom * 0.1);
|
win_y = (int)(rect.bottom * 0.1);
|
||||||
win_width = (int)(rect.right * 0.8);
|
win_width = (int)(rect.right * 0.8);
|
||||||
win_height = (int)(rect.bottom * 0.8);
|
win_height = (int)(rect.bottom * 0.8);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Subdivide the window into num_x_spans * num_y_spans sub-windows.
|
// Subdivide the window into num_x_spans * num_y_spans sub-windows.
|
||||||
int num_y_spans = int(sqrt((double)num_instances));
|
int num_y_spans = int(sqrt((double)num_instances));
|
||||||
|
@ -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"
|
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"
|
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:
|
else:
|
||||||
# Linux
|
# Linux
|
||||||
|
Loading…
x
Reference in New Issue
Block a user