- initialize native bullet classes on every object creation

- remove initialization from java physicsspace

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7431 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
nor..67 2011-05-04 03:45:31 +00:00
parent dd67011809
commit 3c45cc6e97
24 changed files with 26 additions and 2 deletions

View File

@ -142,7 +142,6 @@ public class PhysicsSpace {
this.worldMax.set(worldMax);
this.broadphaseType = broadphaseType;
create();
initNativePhysics();
}
/**
@ -150,7 +149,6 @@ public class PhysicsSpace {
*/
public void create() {
//TODO: boroadphase!
initNativePhysics();
physicsSpaceId = createPhysicsSpace(worldMin.x, worldMin.y, worldMin.z, worldMax.x, worldMax.y, worldMax.z, 3, false);
pQueueTL.set(pQueue);
physicsSpaceTL.set(this);

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_PhysicsSpace_createPhysicsSpace
(JNIEnv * env, jobject object, jfloat minX, jfloat minY, jfloat minZ, jfloat maxX, jfloat maxY, jfloat maxZ, jint broadphase, jboolean threading) {
jmeClasses::initJavaClasses(env);
jmePhysicsSpace* space = new jmePhysicsSpace(env, object);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/IllegalStateException");

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_BoxCollisionShape_createShape
(JNIEnv *env, jobject object, jobject halfExtents) {
jmeClasses::initJavaClasses(env);
btVector3* extents = &btVector3();
jmeBulletUtil::convert(env, halfExtents, extents);
btBoxShape* shape = new btBoxShape(*extents);

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CapsuleCollisionShape_createShape
(JNIEnv * env, jobject object, jint axis, jfloat radius, jfloat height) {
jmeClasses::initJavaClasses(env);
btCollisionShape* shape;
switch(axis){
case 0:

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CompoundCollisionShape_createShape
(JNIEnv *env, jobject object) {
jmeClasses::initJavaClasses(env);
btCompoundShape* shape = new btCompoundShape();
return (long) shape;
}

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_ConeCollisionShape_createShape
(JNIEnv * env, jobject object, jint axis, jfloat radius, jfloat height) {
jmeClasses::initJavaClasses(env);
btCollisionShape* shape;
switch (axis) {
case 0:

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CylinderCollisionShape_createShape
(JNIEnv * env, jobject object, jint axis, jobject halfExtents) {
jmeClasses::initJavaClasses(env);
btVector3* extents = &btVector3();
jmeBulletUtil::convert(env, halfExtents, extents);
btCollisionShape* shape;

View File

@ -48,6 +48,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_GImpactCollisionShape_createShape
(JNIEnv * env, jobject object, jlong meshId) {
jmeClasses::initJavaClasses(env);
btTriangleIndexVertexArray* array = (btTriangleIndexVertexArray*) meshId;
btGImpactMeshShape* shape = new btGImpactMeshShape(array);
return (long) shape;

View File

@ -48,6 +48,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_HeightfieldCollisionShape_createShape
(JNIEnv * env, jobject object, jint heightStickWidth, jint heightStickLength, jobject heightfieldData, jfloat heightScale, jfloat minHeight, jfloat maxHeight, jint upAxis, jboolean flipQuadEdges) {
jmeClasses::initJavaClasses(env);
void* data = env->GetDirectBufferAddress(heightfieldData);
btHeightfieldTerrainShape* shape=new btHeightfieldTerrainShape(heightStickWidth, heightStickLength, data, heightScale, minHeight, maxHeight, upAxis, PHY_FLOAT, flipQuadEdges);
return (long)shape;

View File

@ -48,6 +48,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_HullCollisionShape_createShape
(JNIEnv *env, jobject object, jobject array) {
jmeClasses::initJavaClasses(env);
float* data = (float*) env->GetDirectBufferAddress(array);
//TODO: capacity will not always be length!
int length = env->GetDirectBufferCapacity(array)/4;

View File

@ -48,6 +48,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_MeshCollisionShape_createShape
(JNIEnv * env, jobject object, jlong arrayId) {
jmeClasses::initJavaClasses(env);
btTriangleIndexVertexArray* array = (btTriangleIndexVertexArray*) arrayId;
btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(array, true, true);
return (long) shape;

View File

@ -48,6 +48,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_PlaneCollisionShape_createShape
(JNIEnv * env, jobject object, jobject normal, jfloat constant) {
jmeClasses::initJavaClasses(env);
btVector3* norm = &btVector3();
jmeBulletUtil::convert(env, normal, norm);
btStaticPlaneShape* shape = new btStaticPlaneShape(*norm, constant);

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2
(JNIEnv *env, jobject object, jobject vector1) {
jmeClasses::initJavaClasses(env);
btVector3* vec1 = &btVector3();
jmeBulletUtil::convert(env, vector1, vec1);
btBU_Simplex1to4* simplexShape = new btBU_Simplex1to4(*vec1);
@ -60,6 +61,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2
(JNIEnv *env, jobject object, jobject vector1, jobject vector2) {
jmeClasses::initJavaClasses(env);
btVector3* vec1 = &btVector3();
jmeBulletUtil::convert(env, vector1, vec1);
btVector3* vec2 = &btVector3();
@ -74,6 +76,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2
(JNIEnv * env, jobject object, jobject vector1, jobject vector2, jobject vector3) {
jmeClasses::initJavaClasses(env);
btVector3* vec1 = &btVector3();
jmeBulletUtil::convert(env, vector1, vec1);
btVector3* vec2 = &btVector3();
@ -90,6 +93,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2
(JNIEnv * env, jobject object, jobject vector1, jobject vector2, jobject vector3, jobject vector4) {
jmeClasses::initJavaClasses(env);
btVector3* vec1 = &btVector3();
jmeBulletUtil::convert(env, vector1, vec1);
btVector3* vec2 = &btVector3();

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SphereCollisionShape_createShape
(JNIEnv *env, jobject object, jfloat radius) {
jmeClasses::initJavaClasses(env);
btSphereShape* shape=new btSphereShape(radius);
return (long)shape;
}

View File

@ -70,6 +70,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_ConeJoint_createJoint
(JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB) {
jmeClasses::initJavaClasses(env);
btRigidBody* bodyA = (btRigidBody*) bodyIdA;
btRigidBody* bodyB = (btRigidBody*) bodyIdB;
btMatrix3x3* mtx1 = &btMatrix3x3();

View File

@ -157,6 +157,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_HingeJoint_createJoint
(JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject axisA, jobject pivotB, jobject axisB) {
jmeClasses::initJavaClasses(env);
btRigidBody* bodyA = (btRigidBody*) bodyIdA;
btRigidBody* bodyB = (btRigidBody*) bodyIdB;
btVector3* vec1 = &btVector3();

View File

@ -113,6 +113,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_createJoint
(JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject pivotB) {
jmeClasses::initJavaClasses(env);
btRigidBody* bodyA = (btRigidBody*) bodyIdA;
btRigidBody* bodyB = (btRigidBody*) bodyIdB;
//TODO: matrix not needed?

View File

@ -121,6 +121,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofJoint_createJoint
(JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB, jboolean useLinearReferenceFrameA) {
jmeClasses::initJavaClasses(env);
btRigidBody* bodyA = (btRigidBody*) bodyIdA;
btRigidBody* bodyB = (btRigidBody*) bodyIdB;
btMatrix3x3* mtx1 = &btMatrix3x3();

View File

@ -663,6 +663,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SliderJoint_createJoint
(JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB, jboolean useLinearReferenceFrameA) {
jmeClasses::initJavaClasses(env);
btRigidBody* bodyA = (btRigidBody*) bodyIdA;
btRigidBody* bodyB = (btRigidBody*) bodyIdB;
btMatrix3x3* mtx1=&btMatrix3x3();

View File

@ -50,6 +50,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_createGhostObject
(JNIEnv * env, jobject object) {
jmeClasses::initJavaClasses(env);
btPairCachingGhostObject* ghost = new btPairCachingGhostObject();
return (long) ghost;
}

View File

@ -50,6 +50,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_createGhostObject
(JNIEnv * env, jobject object) {
jmeClasses::initJavaClasses(env);
btPairCachingGhostObject* ghost = new btPairCachingGhostObject();
return (long) ghost;
}

View File

@ -48,6 +48,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_createRigidBody
(JNIEnv *env, jobject object, jfloat mass, jlong motionstatId, jlong shapeId) {
jmeClasses::initJavaClasses(env);
btMotionState* motionState = (btMotionState*) motionstatId;
btCollisionShape* shape = (btCollisionShape*) shapeId;
btVector3* localInertia = &btVector3();

View File

@ -48,6 +48,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_infos_RigidBodyMotionState_createMotionState
(JNIEnv *env, jobject object) {
jmeClasses::initJavaClasses(env);
jmeMotionState* motionState = new jmeMotionState();
return (long) motionState;
}

View File

@ -47,6 +47,7 @@ extern "C" {
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_util_NativeMeshUtil_createTriangleIndexVertexArray
(JNIEnv * env, jclass cls, jobject triangleIndexBase, jobject vertexIndexBase, jint numTriangles, jint numVertices, jint vertexStride, jint triangleIndexStride) {
jmeClasses::initJavaClasses(env);
int* triangles = (int*) env->GetDirectBufferAddress(triangleIndexBase);
float* vertices = (float*) env->GetDirectBufferAddress(vertexIndexBase);
btTriangleIndexVertexArray* array = new btTriangleIndexVertexArray(numTriangles, triangles, triangleIndexStride, numVertices, vertices, vertexStride);