• R/O
  • SSH
  • HTTPS

mikumikudroid: Commit


Commit MetaInfo

Revisión107 (tree)
Tiempo2011-07-11 00:31:57
Autorohsawa

Log Message

bugs that stall physics simulation for long-time-no-motion objects is fixed.
bugs that fails reading model with zero rigid body or joint is fixed.
fix physics stability when physics on/off.

Cambiar Resumen

Diferencia incremental

--- trunk/MikuMikuDroid/jni/bullet-jni.cpp (revision 106)
+++ trunk/MikuMikuDroid/jni/bullet-jni.cpp (revision 107)
@@ -1,10 +1,23 @@
11 #include <string.h>
22 #include <jni.h>
3+#include <android/log.h>
34
45 #include <btBulletDynamicsCommon.h>
56 #include <btBulletCollisionCommon.h>
7+#include "BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
8+#include "BulletMultiThreaded/btParallelConstraintSolver.h"
9+#include "BulletMultiThreaded/SequentialThreadSupport.h"
10+#include "BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
11+#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
612
13+
14+//#define USE_PARALLEL_COLLISION
15+//#define USE_PARALLEL_CONSTRAINT
16+//#define USZE_AS3_BROADPHASE
17+
18+
719 btDiscreteDynamicsWorld *g_DynamicsWorld;
20+
821 btRigidBody *g_rb[4096];
922 btDefaultMotionState *g_ms[4096];
1023 btTransform *g_pos[4096];
@@ -47,11 +60,48 @@
4760 extern "C" void Java_jp_gauzau_MikuMikuDroid_CoreLogic_btMakeWorld(JNIEnv* env, jobject thiz)
4861 {
4962 // make world
50- btCollisionConfiguration *collisionConfiguration = new btDefaultCollisionConfiguration();
63+ ////// Collision Configuration
64+ btDefaultCollisionConstructionInfo cci;
65+ cci.m_defaultMaxPersistentManifoldPoolSize = 32768;
66+ btCollisionConfiguration *collisionConfiguration = new btDefaultCollisionConfiguration(cci);
67+
68+ ////// Collision Dispatcher
69+#ifdef USE_PARALLEL_COLLISION
70+ SequentialThreadSupport::SequentialThreadConstructionInfo colCI("collision", processCollisionTask, createCollisionLocalStoreMemory);
71+ SequentialThreadSupport* threadSupportCollision = new SequentialThreadSupport(colCI);
72+ SpuGatheringCollisionDispatcher *dispatcher = new SpuGatheringCollisionDispatcher(threadSupportCollision, 4, collisionConfiguration);
73+#else
5174 btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConfiguration);
75+#endif
76+
77+ ////// Broadphase
78+#ifdef USZE_AS3_BROADPHASE
79+ btVector3 worldAabbMin(-1000,-1000,-1000);
80+ btVector3 worldAabbMax(1000,1000,1000);
81+ btAxisSweep3 *broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax);
82+#else
5283 btDbvtBroadphase *broadphase = new btDbvtBroadphase();
84+#endif
85+
86+ ////// Constraint Solver
87+#ifdef USE_PARALLEL_CONSTRAINT
88+ SequentialThreadSupport :: SequentialThreadConstructionInfo tci("solverThreads", SolverThreadFunc, SolverlsMemoryFunc);
89+ SequentialThreadSupport* threadSupport = new SequentialThreadSupport(tci);
90+ threadSupport->startSPU();
91+ btParallelConstraintSolver *solver = new btParallelConstraintSolver(threadSupport);
92+ dispatcher->setDispatcherFlags(btCollisionDispatcher::CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
93+#else
5394 btSequentialImpulseConstraintSolver *solver = new btSequentialImpulseConstraintSolver();
95+#endif
96+
97+
98+ ////// Create Dynamics World
5499 g_DynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
100+
101+ g_DynamicsWorld->getSimulationIslandManager()->setSplitIslands(false);
102+ g_DynamicsWorld->getSolverInfo().m_numIterations = 4;
103+ g_DynamicsWorld->getSolverInfo().m_solverMode = SOLVER_SIMD + SOLVER_USE_WARMSTARTING;
104+ g_DynamicsWorld->getDispatchInfo().m_enableSPU = true;
55105
56106 btVector3 *g = new btVector3(0, -9.8 * 5, 0);
57107 g_DynamicsWorld->setGravity(*g);
@@ -131,7 +181,9 @@
131181
132182 // inertia
133183 btVector3 inertia(0, 0, 0);
134- cs->calculateLocalInertia(type == 0 ? 0 : mass, inertia);
184+ if(type != 0) {
185+ cs->calculateLocalInertia(mass, inertia);
186+ }
135187
136188 // create rigid body with default motion state
137189 g_ms[g_ptr] = new btDefaultMotionState(transf);
@@ -141,6 +193,9 @@
141193 rbi->m_angularDamping = r_dim;
142194 rbi->m_restitution = recoil;
143195 rbi->m_friction = friction;
196+ rbi->m_linearSleepingThreshold = 0;
197+ rbi->m_angularSleepingThreshold = 0;
198+
144199 g_rb[g_ptr] = new btRigidBody(*rbi);
145200
146201 if(type == 0) {
@@ -158,8 +213,6 @@
158213 {
159214 btTransform jt = createBtTransform(env, pos, rot);
160215
161-// btTransform tr1 = g_rb[rb1]->getCenterOfMassTransform().inverse() * jt;
162-// btTransform tr2 = g_rb[rb2]->getCenterOfMassTransform().inverse() * jt;
163216 btTransform tr1 = g_pos[rb1]->inverse() * jt;
164217 btTransform tr2 = g_pos[rb2]->inverse() * jt;
165218 btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(*g_rb[rb1], *g_rb[rb2], tr1, tr2, true);
@@ -172,11 +225,20 @@
172225 float *sp_n = env->GetFloatArrayElements(sp, 0);
173226 float *sr_n = env->GetFloatArrayElements(sr, 0);
174227 for(int i = 0; i < 3; i++) {
175- dof->enableSpring(i, true);
176- dof->setStiffness(i, sp_n[i]);
228+ if(sp_n[i] > 0) {
229+ dof->enableSpring(i, true);
230+ dof->setStiffness(i, sp_n[i]);
231+ } else {
232+ dof->enableSpring(i, false);
233+ }
177234
178- dof->enableSpring(i + 3, true);
179- dof->setStiffness(i + 3, sr_n[i]);
235+ if(sr_n[i] > 0) {
236+ dof->enableSpring(i + 3, true);
237+ dof->setStiffness(i + 3, sr_n[i]);
238+ } else {
239+ dof->enableSpring(i + 3, false);
240+ }
241+
180242 }
181243 env->ReleaseFloatArrayElements(sp, sp_n, 0);
182244 env->ReleaseFloatArrayElements(sr, sr_n, 0);
@@ -248,3 +310,9 @@
248310 }
249311 }
250312
313+extern "C" void Java_jp_gauzau_MikuMikuDroid_CoreLogic_btDumpAll(JNIEnv* env, jobject thiz)
314+{
315+#ifndef BT_NO_PROFILE
316+ CProfileManager::dumpAll();
317+#endif
318+}
--- trunk/MikuMikuDroid/jni/bullet/LinearMath/btQuickprof.cpp (revision 106)
+++ trunk/MikuMikuDroid/jni/bullet/LinearMath/btQuickprof.cpp (revision 107)
@@ -50,6 +50,11 @@
5050
5151 #else //_WIN32
5252 #include <sys/time.h>
53+
54+#include <android/log.h>
55+#define LOG_TAG "bullet"
56+#define printf(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
57+
5358 #endif //_WIN32
5459
5560 #define mymin(a,b) (a > b ? a : b)
--- trunk/MikuMikuDroid/AndroidManifest.xml (revision 106)
+++ trunk/MikuMikuDroid/AndroidManifest.xml (revision 107)
@@ -1,7 +1,7 @@
11 <?xml version="1.0" encoding="utf-8"?>
22 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
33 package="jp.gauzau.MikuMikuDroid"
4- android:versionName="0.24" android:versionCode="24">
4+ android:versionCode="25" android:versionName="0.25">
55 <application android:icon="@drawable/icon" android:label="@string/app_name"
66 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:debuggable="false">
77 <activity android:name=".MikuMikuDroid"
@@ -31,4 +31,5 @@
3131
3232
3333
34+
3435 </manifest>
\ No newline at end of file
--- trunk/MikuMikuDroid/src/jp/gauzau/MikuMikuDroid/PMDParser.java (revision 106)
+++ trunk/MikuMikuDroid/src/jp/gauzau/MikuMikuDroid/PMDParser.java (revision 107)
@@ -84,31 +84,33 @@
8484 private void parsePMDJoint() {
8585 int num = getInt();
8686 Log.d("PMDParser", "Joint: " + String.valueOf(num));
87- mJoint = new ArrayList<Joint>(num);
88- for(int i = 0; i < num; i++) {
89- Joint j = new Joint();
90- j.name = getString(20);
91- j.rigidbody_a = getInt();
92- j.rigidbody_b = getInt();
93- j.position = new float[3];
94- j.rotation = new float[3];
95- j.const_position_1 = new float[3];
96- j.const_position_2 = new float[3];
97- j.const_rotation_1 = new float[3];
98- j.const_rotation_2 = new float[3];
99- j.spring_position = new float[3];
100- j.spring_rotation = new float[3];
101-
102- getFloat(j.position);
103- getFloat(j.rotation);
104- getFloat(j.const_position_1);
105- getFloat(j.const_position_2);
106- getFloat(j.const_rotation_1);
107- getFloat(j.const_rotation_2);
108- getFloat(j.spring_position);
109- getFloat(j.spring_rotation);
110-
111- mJoint.add(j);
87+ if(num > 0) {
88+ mJoint = new ArrayList<Joint>(num);
89+ for(int i = 0; i < num; i++) {
90+ Joint j = new Joint();
91+ j.name = getString(20);
92+ j.rigidbody_a = getInt();
93+ j.rigidbody_b = getInt();
94+ j.position = new float[3];
95+ j.rotation = new float[3];
96+ j.const_position_1 = new float[3];
97+ j.const_position_2 = new float[3];
98+ j.const_rotation_1 = new float[3];
99+ j.const_rotation_2 = new float[3];
100+ j.spring_position = new float[3];
101+ j.spring_rotation = new float[3];
102+
103+ getFloat(j.position);
104+ getFloat(j.rotation);
105+ getFloat(j.const_position_1);
106+ getFloat(j.const_position_2);
107+ getFloat(j.const_rotation_1);
108+ getFloat(j.const_rotation_2);
109+ getFloat(j.spring_position);
110+ getFloat(j.spring_rotation);
111+
112+ mJoint.add(j);
113+ }
112114 }
113115 }
114116
@@ -115,33 +117,34 @@
115117 private void parsePMDRigidBody() {
116118 int num = getInt();
117119 Log.d("PMDParser", "RigidBody: " + String.valueOf(num));
118- mRigidBody = new ArrayList<RigidBody>(num);
119- for(int i = 0; i < num; i++) {
120- RigidBody rb = new RigidBody();
121-
122- rb.name = getString(20);
123- rb.bone_index = getShort();
124- rb.group_index = getByte();
125- rb.group_target = getShort();
126- rb.shape = getByte();
127- rb.size = new float[3]; // w, h, d
128- rb.location = new float[3]; // x, y, z
129- rb.rotation = new float[3];
130- getFloat(rb.size);
131- getFloat(rb.location);
132- getFloat(rb.rotation);
133- rb.weight = getFloat();
134- rb.v_dim = getFloat();
135- rb.r_dim = getFloat();
136- rb.recoil = getFloat();
137- rb.friction = getFloat();
138- rb.type = getByte();
139-
140- rb.btrb = -1; // physics is not initialized yet
141-
142- mRigidBody.add(rb);
120+ if(num > 0) {
121+ mRigidBody = new ArrayList<RigidBody>(num);
122+ for(int i = 0; i < num; i++) {
123+ RigidBody rb = new RigidBody();
124+
125+ rb.name = getString(20);
126+ rb.bone_index = getShort();
127+ rb.group_index = getByte();
128+ rb.group_target = getShort();
129+ rb.shape = getByte();
130+ rb.size = new float[3]; // w, h, d
131+ rb.location = new float[3]; // x, y, z
132+ rb.rotation = new float[3];
133+ getFloat(rb.size);
134+ getFloat(rb.location);
135+ getFloat(rb.rotation);
136+ rb.weight = getFloat();
137+ rb.v_dim = getFloat();
138+ rb.r_dim = getFloat();
139+ rb.recoil = getFloat();
140+ rb.friction = getFloat();
141+ rb.type = getByte();
142+
143+ rb.btrb = -1; // physics is not initialized yet
144+
145+ mRigidBody.add(rb);
146+ }
143147 }
144-
145148 }
146149
147150 private void parsePMDEnglish() throws IOException {
@@ -158,10 +161,12 @@
158161
159162 private void parsePMDEnglishBoneDispName() throws IOException {
160163 int num = mBoneDispName.size();
161- mEnglishBoneDispName = new ArrayList<String>(num);
162- for (int i = 0; i < num; i++) {
163- String str = getString(50);
164- mEnglishBoneDispName.add(i, str);
164+ if(num > 0) {
165+ mEnglishBoneDispName = new ArrayList<String>(num);
166+ for (int i = 0; i < num; i++) {
167+ String str = getString(50);
168+ mEnglishBoneDispName.add(i, str);
169+ }
165170 }
166171 }
167172
@@ -187,10 +192,12 @@
187192 private void parsePMDEnglishSkinList() throws IOException {
188193 int num = mSkinDisp.size();
189194 Log.d("PMDParser", "EnglishSkinName: " + String.valueOf(num));
190- mEnglishSkinName = new ArrayList<String>(num);
191- for (int i = 0; i < num; i++) {
192- String str = getString(20);
193- mEnglishSkinName.add(i, str);
195+ if(num > 0) {
196+ mEnglishSkinName = new ArrayList<String>(num);
197+ for (int i = 0; i < num; i++) {
198+ String str = getString(20);
199+ mEnglishSkinName.add(i, str);
200+ }
194201 }
195202 }
196203
@@ -197,10 +204,12 @@
197204 private void parsePMDEnglishBoneList() throws IOException {
198205 int num = mBone.size();
199206 Log.d("PMDParser", "EnglishBoneName: " + String.valueOf(num));
200- mEnglishBoneName = new ArrayList<String>(num);
201- for (int i = 0; i < num; i++) {
202- String str = getString(20);
203- mEnglishBoneName.add(i, str);
207+ if(num > 0) {
208+ mEnglishBoneName = new ArrayList<String>(num);
209+ for (int i = 0; i < num; i++) {
210+ String str = getString(20);
211+ mEnglishBoneName.add(i, str);
212+ }
204213 }
205214 }
206215
--- trunk/MikuMikuDroid/src/jp/gauzau/MikuMikuDroid/CoreLogic.java (revision 106)
+++ trunk/MikuMikuDroid/src/jp/gauzau/MikuMikuDroid/CoreLogic.java (revision 107)
@@ -47,6 +47,7 @@
4747 private int mHeight;
4848 private int mAngle;
4949 private boolean mPhysics = false;
50+ private boolean mPrevPhysics = false;
5051
5152 // temporary data
5253 private CameraIndex mCameraIndex = new CameraIndex();
@@ -151,7 +152,10 @@
151152 }
152153
153154 native private void btMakeWorld();
155+
156+ native private void btDumpAll();
154157
158+
155159 static {
156160 if(isArm()) {
157161 System.loadLibrary("bullet-jni");
@@ -374,6 +378,9 @@
374378
375379 public synchronized void togglePhysics() {
376380 mPhysics = !mPhysics;
381+ if(!mPhysics) { // Dump Physics profile
382+ btDumpAll();
383+ }
377384 }
378385
379386 native private void btClearAllData();
@@ -426,8 +433,9 @@
426433 native private void btStepSimulation(float step, int max);
427434
428435 public synchronized int applyCurrentMotion() {
429- boolean initializePhysics = false;
430-
436+ boolean initializePhysics = !mPrevPhysics && mPhysics;
437+ mPrevPhysics = mPhysics;
438+
431439 calcCurrentTime();
432440 double frame = getCurrentFrames(32767);
433441 float step = (float) (getDeltaTimeMills() / 1000.0);
@@ -434,9 +442,12 @@
434442 if(step >= 1 || step < 0) {
435443 step = 0;
436444 initializePhysics = true;
437- btClearAllData();
438445 }
439446
447+ if(initializePhysics) {
448+ btClearAllData();
449+ }
450+
440451 double prev_frame = calcPrevFrame(frame, step);
441452
442453 int max_step = 4;
Show on old repository browser