network UDP: transmit structural DNA to deal with version/platform differences.

pybullet: allow to specify shared memory key and hostname/port for UDP.
This commit is contained in:
erwincoumans
2016-11-04 17:06:55 -07:00
parent 0ffd68ac32
commit 5d66ce20e0
5 changed files with 135 additions and 10 deletions

View File

@@ -61,12 +61,45 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args) {
{
int method = eCONNECT_GUI;
if (!PyArg_ParseTuple(args, "i", &method)) {
PyErr_SetString(SpamError,
"connectPhysicsServer expected argument GUI, "
"DIRECT, SHARED_MEMORY or UDP");
return NULL;
}
int key = SHARED_MEMORY_KEY;
int port = 1234;
const char* hostName = "localhost";
int size = PySequence_Size(args);
if (size == 1)
{
if (!PyArg_ParseTuple(args, "i", &method)) {
PyErr_SetString(SpamError,
"connectPhysicsServer expected argument GUI, "
"DIRECT, SHARED_MEMORY or UDP");
return NULL;
}
}
if (size == 2)
{
if (!PyArg_ParseTuple(args, "ii", &method, &key))
{
if (!PyArg_ParseTuple(args, "is", &method, &hostName))
{
PyErr_SetString(SpamError,
"connectPhysicsServer cannot parse second argument (either integer or string)");
return NULL;
}
}
}
if (size == 3)
{
if (!PyArg_ParseTuple(args, "isi", &method, &hostName, &port))
{
PyErr_SetString(SpamError,
"connectPhysicsServer 3 arguments: method, hostname, port");
return NULL;
}
}
switch (method) {
case eCONNECT_GUI: {
@@ -85,14 +118,14 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args) {
break;
}
case eCONNECT_SHARED_MEMORY: {
sm = b3ConnectSharedMemory(SHARED_MEMORY_KEY);
sm = b3ConnectSharedMemory(key);
break;
}
case eCONNECT_UDP:
{
#ifdef BT_ENABLE_ENET
sm = b3ConnectPhysicsUDP("localhost", 1234);
sm = b3ConnectPhysicsUDP(hostName, port);
#else
PyErr_SetString(SpamError, "UDP is not enabled in this pybullet build");
return NULL;