/* Bullet Continuous Collision Detection and Physics Library Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/ This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "BasicDemo.h" #include "GLDebugDrawer.h" #include "btBulletDynamicsCommon.h" #include "LinearMath/btHashMap.h" #include #include #include #include #include #include #include #include #include #include #include #include "Agent.h" #include "Sensor.h" #define WIDTH 10 #define HEIGHT 3 #define MAXPROCS (WIDTH * HEIGHT) BasicDemo vworld; GLDebugDrawer gDebugDrawer; btDynamicsWorld* m_dynamicWorld; using namespace java::lang; using namespace java::util; enum { LEFT=0, RIGHT=1, UP=2, DOWN=3 }; int rank, nprocs = MAXPROCS; MPI_Comm everyone; void init() { if(JvCreateJavaVM(NULL) < 0) { printf("Error creating the JVM!!!\n"); exit(1); } JvAttachCurrentThread(NULL, NULL); JvInitClass(&Agent::class$); } /* int getRight(int i, int j) { return (4 * HEIGHT - 2) * i + 4 * j + 0; } int getLeft(int i, int j) { return getRight(i-1, j) + 1; } int getDown(int i, int j) { int down = (4 * HEIGHT - 2) * i + 4 * j + 2; if(i == WIDTH - 1) down -= 2 + j * 2; return down; } int getUp(int i, int j) { int up = getDown(i, j-1) + 1; return up; } */ static void master() { int i, j; printf("Master process here!\n"); /// Initialize the scene of the simulation vworld.initPhysics(); vworld.createSimulation2D(WIDTH, HEIGHT); // vworld.createSimulation3D(3, 3, 3); vworld.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer); m_dynamicWorld = vworld.getDynamicsWorld(); init(); for(i = 0; i < WIDTH; i++) { for(j = 0; j < HEIGHT; j++) { List *sensors = (List *) new ArrayList(); // int right = getRight(i, j); // int left = getLeft(i, j); // int up = getUp(i, j); // int down = getDown(i, j); int idx; if(i < WIDTH - 1) { idx = vworld.m_matrix[i * HEIGHT + j][RIGHT]; // printf("RIGHT: (%d, %d) - %d\n", i, j, idx); btHingeConstraint *joint = (btHingeConstraint*)vworld.m_joints[idx]; Sensor *s = new Sensor(joint->getHingeAngle(),joint->getLowerLimit(),joint->getUpperLimit(), RIGHT); sensors->add(s); vworld.m_sensors.push_back(make_pair(idx, s)); } if(i > 0) { idx = vworld.m_matrix[i * HEIGHT + j][LEFT]; // printf("LEFT: (%d, %d) - %d\n", i, j, idx); btHingeConstraint *joint = (btHingeConstraint*)vworld.m_joints[idx]; Sensor *s = new Sensor(joint->getHingeAngle(),joint->getLowerLimit(),joint->getUpperLimit(), LEFT); sensors->add(s); vworld.m_sensors.push_back(make_pair(idx, s)); } if(j < HEIGHT - 1) { idx = vworld.m_matrix[i * HEIGHT + j][DOWN]; // printf("DOWN: (%d, %d) - %d\n", i, j, idx); btHingeConstraint *joint = (btHingeConstraint*)vworld.m_joints[idx]; Sensor *s = new Sensor(joint->getHingeAngle(),joint->getLowerLimit(),joint->getUpperLimit(), DOWN); sensors->add(s); vworld.m_sensors.push_back(make_pair(idx, s)); } if(j > 0) { idx = vworld.m_matrix[i * HEIGHT + j][UP]; // printf("UP: (%d, %d) - %d\n", i, j, idx); btHingeConstraint *joint = (btHingeConstraint*)vworld.m_joints[idx]; Sensor *s = new Sensor(joint->getHingeAngle(),joint->getLowerLimit(),joint->getUpperLimit(), UP); sensors->add(s); vworld.m_sensors.push_back(make_pair(idx, s)); } Agent *agent = new Agent(sensors, i, j); vworld.m_agents.push_back(agent); } } } static void slave() { MPI_Comm_rank(MPI_COMM_WORLD, &rank); printf("Process slave number %d executing...\n", rank); while(1) { sleep(1000); } } int main(int argc,char** argv) { MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); printf("%d\n", rank); if(nprocs != MAXPROCS + 1) { // return 0; } if(rank == 0) { master(); } else { slave(); } if(rank == 0) { #ifdef CHECK_MEMORY_LEAKS vworld.exitPhysics(); #else int ret; try { ret = glutmain(argc, argv, 640, 480, "SIMEO", &vworld); } catch (Throwable *t) { System::err->println(JvNewStringLatin1("Unhandled Java exception:")); t->printStackTrace(); } MPI_Finalize(); return ret; #endif } //default glut doesn't return from mainloop return 0; }