• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision707 (tree)
Zeit2011-04-11 01:26:24
Autorwilfrem

Log Message

物理演算用スレッドシステム設計途中

Ändern Zusammenfassung

Diff

--- branches/XNA4/MikuMikuDanceXNA/MMDXCore.cs (revision 706)
+++ branches/XNA4/MikuMikuDanceXNA/MMDXCore.cs (revision 707)
@@ -14,6 +14,7 @@
1414 using BulletX.BulletCollision.BroadphaseCollision;
1515 using BulletX.BulletDynamics.ConstraintSolver;
1616 using BulletX.LinerMath;
17+using MikuMikuDance.XNA.MultiThreads;
1718 #endif
1819
1920 namespace MikuMikuDance.XNA
@@ -23,11 +24,16 @@
2324 /// </summary>
2425 public class MMDXCore
2526 {
27+ //シングルトン
2628 static MMDXCore m_inst;
29+ //物理エンジンの設定データ
2730 ICollisionConfiguration config = null;
2831 CollisionDispatcher dispatcher = null;
2932 IBroadphaseInterface pairCache = null;
3033 IConstraintSolver solver = null;
34+ //物理エンジン用
35+ PhysicsThreadManager pthread = null;
36+
3137 /// <summary>
3238 /// Singletonインスタンス
3339 /// </summary>
@@ -59,7 +65,8 @@
5965 /// <summary>
6066 /// 物理演算のワールド
6167 /// </summary>
62- /// <remarks>差し替える場合は他の処理の前に差し替えること</remarks>
68+ /// <remarks>差し替える場合は他の処理の前に差し替えること。
69+ /// また、これの処理はマルチスレッドで行われるため、同期処理はUpdate関数を使用すること</remarks>
6370 public DiscreteDynamicsWorld Physics { get; set; }
6471 #if XNA
6572 /// <summary>
@@ -101,7 +108,8 @@
101108 solver = new SequentialImpulseConstraintSolver();
102109 Physics = new DiscreteDynamicsWorld(dispatcher, pairCache, solver, config);
103110 Physics.Gravity = new btVector3(0, -9.81f * 5.0f, 0);
104-
111+ //物理エンジン用スレッドマネージャの作成
112+ pthread = new PhysicsThreadManager();
105113 }
106114
107115 #if XNA
@@ -147,10 +155,8 @@
147155 /// <param name="timeStep">経過時間</param>
148156 public void Update(float timeStep)
149157 {
150- if (timeStep != 0.0f)
151- {
152- Physics.stepSimulation(timeStep);
153- }
158+ pthread.Update(timeStep);
159+
154160 }
155161 }
156162 }
--- branches/XNA4/MikuMikuDanceXNA/MultiThreads/PhysicsThreadManager.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/MultiThreads/PhysicsThreadManager.cs (revision 707)
@@ -0,0 +1,77 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using System.Threading;
6+
7+namespace MikuMikuDance.XNA.MultiThreads
8+{
9+ class PhysicsThreadManager
10+ {
11+ //XBOX用ハードウェアスレッド番号
12+ const int XboxCoreNum = 3;
13+ //スレッドオブジェクト
14+ Thread thread;
15+ //マルチスレッドモード
16+ bool bMultiThread = false;
17+ //シグナル
18+ AutoResetEvent CalcStart;
19+ AutoResetEvent CalcFinished;
20+ //スレッド受け渡し変数
21+ float m_timeStep;
22+
23+
24+ public PhysicsThreadManager()
25+ {
26+ thread = new Thread(new ThreadStart(threadFunc));
27+ CalcFinished = new AutoResetEvent(true);
28+ CalcStart = new AutoResetEvent(false);
29+ }
30+
31+ public void Update(float timeStep)
32+ {
33+ if (bMultiThread)
34+ {
35+ CalcFinished.WaitOne();
36+ Sync(timeStep);
37+ CalcStart.Set();
38+ }
39+ else
40+ {
41+ if (timeStep > 0.0f)
42+ {
43+ MMDXCore.Instance.Physics.stepSimulation(timeStep);
44+ }
45+ }
46+ }
47+
48+ private void Sync(float timeStep)
49+ {
50+ m_timeStep = timeStep;
51+ throw new NotImplementedException();
52+ }
53+
54+ private void threadFunc()
55+ {
56+#if XBOX360
57+ Thread.SetProcessorAffinity(XboxCoreNum);
58+#endif
59+ try
60+ {
61+ while (true)
62+ {
63+ CalcStart.WaitOne();
64+ if (bMultiThread)
65+ {
66+ if (m_timeStep > 0.0f)
67+ {
68+ MMDXCore.Instance.Physics.stepSimulation(m_timeStep);
69+ }
70+ }
71+ CalcFinished.Set();
72+ }
73+ }
74+ catch (ThreadAbortException) { }
75+ }
76+ }
77+}
Show on old repository browser