box2d-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +1 -0
  6. data/box2d-rails.gemspec +20 -0
  7. data/lib/box2d-rails.rb +8 -0
  8. data/lib/box2d-rails/version.rb +5 -0
  9. data/vendor/assets/javascripts/box2d/collision/ClipVertex.js +35 -0
  10. data/vendor/assets/javascripts/box2d/collision/Features.js +61 -0
  11. data/vendor/assets/javascripts/box2d/collision/b2AABB.js +45 -0
  12. data/vendor/assets/javascripts/box2d/collision/b2Bound.js +43 -0
  13. data/vendor/assets/javascripts/box2d/collision/b2BoundValues.js +31 -0
  14. data/vendor/assets/javascripts/box2d/collision/b2BroadPhase.js +898 -0
  15. data/vendor/assets/javascripts/box2d/collision/b2BufferedPair.js +26 -0
  16. data/vendor/assets/javascripts/box2d/collision/b2Collision.js +738 -0
  17. data/vendor/assets/javascripts/box2d/collision/b2ContactID.js +52 -0
  18. data/vendor/assets/javascripts/box2d/collision/b2ContactPoint.js +35 -0
  19. data/vendor/assets/javascripts/box2d/collision/b2Distance.js +333 -0
  20. data/vendor/assets/javascripts/box2d/collision/b2Manifold.js +34 -0
  21. data/vendor/assets/javascripts/box2d/collision/b2OBB.js +34 -0
  22. data/vendor/assets/javascripts/box2d/collision/b2Pair.js +60 -0
  23. data/vendor/assets/javascripts/box2d/collision/b2PairCallback.js +34 -0
  24. data/vendor/assets/javascripts/box2d/collision/b2PairManager.js +386 -0
  25. data/vendor/assets/javascripts/box2d/collision/b2Proxy.js +40 -0
  26. data/vendor/assets/javascripts/box2d/collision/shapes/b2BoxDef.js +49 -0
  27. data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleDef.js +49 -0
  28. data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleShape.js +198 -0
  29. data/vendor/assets/javascripts/box2d/collision/shapes/b2MassData.js +36 -0
  30. data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyDef.js +58 -0
  31. data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyShape.js +492 -0
  32. data/vendor/assets/javascripts/box2d/collision/shapes/b2Shape.js +339 -0
  33. data/vendor/assets/javascripts/box2d/collision/shapes/b2ShapeDef.js +109 -0
  34. data/vendor/assets/javascripts/box2d/common/b2Settings.js +72 -0
  35. data/vendor/assets/javascripts/box2d/common/math/b2Mat22.js +130 -0
  36. data/vendor/assets/javascripts/box2d/common/math/b2Math.js +218 -0
  37. data/vendor/assets/javascripts/box2d/common/math/b2Vec2.js +131 -0
  38. data/vendor/assets/javascripts/box2d/dynamics/b2Body.js +469 -0
  39. data/vendor/assets/javascripts/box2d/dynamics/b2BodyDef.js +69 -0
  40. data/vendor/assets/javascripts/box2d/dynamics/b2CollisionFilter.js +42 -0
  41. data/vendor/assets/javascripts/box2d/dynamics/b2ContactManager.js +337 -0
  42. data/vendor/assets/javascripts/box2d/dynamics/b2Island.js +331 -0
  43. data/vendor/assets/javascripts/box2d/dynamics/b2TimeStep.js +27 -0
  44. data/vendor/assets/javascripts/box2d/dynamics/b2World.js +522 -0
  45. data/vendor/assets/javascripts/box2d/dynamics/b2WorldListener.js +52 -0
  46. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2CircleContact.js +102 -0
  47. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Conservative.js +228 -0
  48. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Contact.js +201 -0
  49. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraint.js +45 -0
  50. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraintPoint.js +40 -0
  51. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactNode.js +33 -0
  52. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactRegister.js +30 -0
  53. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactSolver.js +537 -0
  54. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2NullContact.js +65 -0
  55. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyAndCircleContact.js +103 -0
  56. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyContact.js +163 -0
  57. data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJoint.js +264 -0
  58. data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJointDef.js +49 -0
  59. data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJoint.js +307 -0
  60. data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJointDef.js +50 -0
  61. data/vendor/assets/javascripts/box2d/dynamics/joints/b2Jacobian.js +49 -0
  62. data/vendor/assets/javascripts/box2d/dynamics/joints/b2Joint.js +200 -0
  63. data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointDef.js +40 -0
  64. data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointNode.js +33 -0
  65. data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJoint.js +234 -0
  66. data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJointDef.js +53 -0
  67. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJoint.js +676 -0
  68. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJointDef.js +56 -0
  69. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJoint.js +618 -0
  70. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJointDef.js +70 -0
  71. data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJoint.js +491 -0
  72. data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJointDef.js +55 -0
  73. metadata +133 -0
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) 2006-2007 Erin Catto http:
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked, and must not be
15
+ * misrepresented the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+
20
+
21
+ // A manifold for two touching convex shapes.
22
+ var b2OBB = Class.create();
23
+ b2OBB.prototype =
24
+ {
25
+ R: new b2Mat22(),
26
+ center: new b2Vec2(),
27
+ extents: new b2Vec2(),
28
+ initialize: function() {
29
+ // initialize instance variables for references
30
+ this.R = new b2Mat22();
31
+ this.center = new b2Vec2();
32
+ this.extents = new b2Vec2();
33
+ //
34
+ }};
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright (c) 2006-2007 Erin Catto http:
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked, and must not be
15
+ * misrepresented the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+ // The pair manager is used by the broad-phase to quickly add/remove/find pairs
20
+ // of overlapping proxies. It is based closely on code provided by Pierre Terdiman.
21
+ // http:
22
+
23
+
24
+
25
+
26
+
27
+ var b2Pair = Class.create();
28
+ b2Pair.prototype =
29
+ {
30
+
31
+
32
+ SetBuffered: function() { this.status |= b2Pair.e_pairBuffered; },
33
+ ClearBuffered: function() { this.status &= ~b2Pair.e_pairBuffered; },
34
+ IsBuffered: function(){ return (this.status & b2Pair.e_pairBuffered) == b2Pair.e_pairBuffered; },
35
+
36
+ SetRemoved: function() { this.status |= b2Pair.e_pairRemoved; },
37
+ ClearRemoved: function() { this.status &= ~b2Pair.e_pairRemoved; },
38
+ IsRemoved: function(){ return (this.status & b2Pair.e_pairRemoved) == b2Pair.e_pairRemoved; },
39
+
40
+ SetFinal: function() { this.status |= b2Pair.e_pairFinal; },
41
+ IsFinal: function(){ return (this.status & b2Pair.e_pairFinal) == b2Pair.e_pairFinal; },
42
+
43
+ userData: null,
44
+ proxyId1: 0,
45
+ proxyId2: 0,
46
+ next: 0,
47
+ status: 0,
48
+
49
+ // STATIC
50
+
51
+ // enum
52
+
53
+ initialize: function() {}};
54
+ b2Pair.b2_nullPair = b2Settings.USHRT_MAX;
55
+ b2Pair.b2_nullProxy = b2Settings.USHRT_MAX;
56
+ b2Pair.b2_tableCapacity = b2Settings.b2_maxPairs;
57
+ b2Pair.b2_tableMask = b2Pair.b2_tableCapacity - 1;
58
+ b2Pair.e_pairBuffered = 0x0001;
59
+ b2Pair.e_pairRemoved = 0x0002;
60
+ b2Pair.e_pairFinal = 0x0004;
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) 2006-2007 Erin Catto http:
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked, and must not be
15
+ * misrepresented the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+
20
+
21
+ var b2PairCallback = Class.create();
22
+ b2PairCallback.prototype =
23
+ {
24
+ //virtual ~b2PairCallback() {}
25
+
26
+ // This returns the new pair user data.
27
+ PairAdded: function(proxyUserData1, proxyUserData2){return null},
28
+
29
+ // This should free the pair's user data. In extreme circumstances, it is possible
30
+ // this will be called with null pairUserData because the pair never existed.
31
+ PairRemoved: function(proxyUserData1, proxyUserData2, pairUserData){},
32
+ initialize: function() {}};
33
+
34
+
@@ -0,0 +1,386 @@
1
+ /*
2
+ * Copyright (c) 2006-2007 Erin Catto http:
3
+ *
4
+ * This software is provided 'as-is', without any express or implied
5
+ * warranty. In no event will the authors be held liable for any damages
6
+ * arising from the use of this software.
7
+ * Permission is granted to anyone to use this software for any purpose,
8
+ * including commercial applications, and to alter it and redistribute it
9
+ * freely, subject to the following restrictions:
10
+ * 1. The origin of this software must not be misrepresented; you must not
11
+ * claim that you wrote the original software. If you use this software
12
+ * in a product, an acknowledgment in the product documentation would be
13
+ * appreciated but is not required.
14
+ * 2. Altered source versions must be plainly marked, and must not be
15
+ * misrepresented the original software.
16
+ * 3. This notice may not be removed or altered from any source distribution.
17
+ */
18
+
19
+ // The pair manager is used by the broad-phase to quickly add/remove/find pairs
20
+ // of overlapping proxies. It is based closely on code provided by Pierre Terdiman.
21
+ // http:
22
+
23
+
24
+
25
+
26
+
27
+ var b2PairManager = Class.create();
28
+ b2PairManager.prototype =
29
+ {
30
+ //public:
31
+ initialize: function(){
32
+ var i = 0;
33
+ //b2Settings.b2Assert(b2Math.b2IsPowerOfTwo(b2Pair.b2_tableCapacity) == true);
34
+ //b2Settings.b2Assert(b2Pair.b2_tableCapacity >= b2Settings.b2_maxPairs);
35
+ this.m_hashTable = new Array(b2Pair.b2_tableCapacity);
36
+ for (i = 0; i < b2Pair.b2_tableCapacity; ++i)
37
+ {
38
+ this.m_hashTable[i] = b2Pair.b2_nullPair;
39
+ }
40
+ this.m_pairs = new Array(b2Settings.b2_maxPairs);
41
+ for (i = 0; i < b2Settings.b2_maxPairs; ++i)
42
+ {
43
+ this.m_pairs[i] = new b2Pair();
44
+ }
45
+ this.m_pairBuffer = new Array(b2Settings.b2_maxPairs);
46
+ for (i = 0; i < b2Settings.b2_maxPairs; ++i)
47
+ {
48
+ this.m_pairBuffer[i] = new b2BufferedPair();
49
+ }
50
+
51
+ for (i = 0; i < b2Settings.b2_maxPairs; ++i)
52
+ {
53
+ this.m_pairs[i].proxyId1 = b2Pair.b2_nullProxy;
54
+ this.m_pairs[i].proxyId2 = b2Pair.b2_nullProxy;
55
+ this.m_pairs[i].userData = null;
56
+ this.m_pairs[i].status = 0;
57
+ this.m_pairs[i].next = (i + 1);
58
+ }
59
+ this.m_pairs[b2Settings.b2_maxPairs-1].next = b2Pair.b2_nullPair;
60
+ this.m_pairCount = 0;
61
+ },
62
+ //~b2PairManager();
63
+
64
+ Initialize: function(broadPhase, callback){
65
+ this.m_broadPhase = broadPhase;
66
+ this.m_callback = callback;
67
+ },
68
+
69
+ /*
70
+ As proxies are created and moved, many pairs are created and destroyed. Even worse, the same
71
+ pair may be added and removed multiple times in a single time step of the physics engine. To reduce
72
+ traffic in the pair manager, we try to avoid destroying pairs in the pair manager until the
73
+ end of the physics step. This is done by buffering all the this.RemovePair requests. this.AddPair
74
+ requests are processed immediately because we need the hash table entry for quick lookup.
75
+
76
+ All user user callbacks are delayed until the buffered pairs are confirmed in this.Commit.
77
+ This is very important because the user callbacks may be very expensive and client logic
78
+ may be harmed if pairs are added and removed within the same time step.
79
+
80
+ Buffer a pair for addition.
81
+ We may add a pair that is not in the pair manager or pair buffer.
82
+ We may add a pair that is already in the pair manager and pair buffer.
83
+ If the added pair is not a new pair, then it must be in the pair buffer (because this.RemovePair was called).
84
+ */
85
+ AddBufferedPair: function(proxyId1, proxyId2){
86
+ //b2Settings.b2Assert(id1 != b2_nullProxy && id2 != b2_nullProxy);
87
+ //b2Settings.b2Assert(this.m_pairBufferCount < b2_maxPairs);
88
+
89
+ var pair = this.AddPair(proxyId1, proxyId2);
90
+
91
+ // If this pair is not in the pair buffer ...
92
+ if (pair.IsBuffered() == false)
93
+ {
94
+ // This must be a newly added pair.
95
+ //b2Settings.b2Assert(pair.IsFinal() == false);
96
+
97
+ // Add it to the pair buffer.
98
+ pair.SetBuffered();
99
+ this.m_pairBuffer[this.m_pairBufferCount].proxyId1 = pair.proxyId1;
100
+ this.m_pairBuffer[this.m_pairBufferCount].proxyId2 = pair.proxyId2;
101
+ ++this.m_pairBufferCount;
102
+
103
+ //b2Settings.b2Assert(this.m_pairBufferCount <= this.m_pairCount);
104
+ }
105
+
106
+ // Confirm this pair for the subsequent call to this.Commit.
107
+ pair.ClearRemoved();
108
+
109
+ if (b2BroadPhase.s_validate)
110
+ {
111
+ this.ValidateBuffer();
112
+ }
113
+ },
114
+
115
+ // Buffer a pair for removal.
116
+ RemoveBufferedPair: function(proxyId1, proxyId2){
117
+ //b2Settings.b2Assert(id1 != b2_nullProxy && id2 != b2_nullProxy);
118
+ //b2Settings.b2Assert(this.m_pairBufferCount < b2_maxPairs);
119
+
120
+ var pair = this.Find(proxyId1, proxyId2);
121
+
122
+ if (pair == null)
123
+ {
124
+ // The pair never existed. This is legal (due to collision filtering).
125
+ return;
126
+ }
127
+
128
+ // If this pair is not in the pair buffer ...
129
+ if (pair.IsBuffered() == false)
130
+ {
131
+ // This must be an old pair.
132
+ //b2Settings.b2Assert(pair.IsFinal() == true);
133
+
134
+ pair.SetBuffered();
135
+ this.m_pairBuffer[this.m_pairBufferCount].proxyId1 = pair.proxyId1;
136
+ this.m_pairBuffer[this.m_pairBufferCount].proxyId2 = pair.proxyId2;
137
+ ++this.m_pairBufferCount;
138
+
139
+ //b2Settings.b2Assert(this.m_pairBufferCount <= this.m_pairCount);
140
+ }
141
+
142
+ pair.SetRemoved();
143
+
144
+ if (b2BroadPhase.s_validate)
145
+ {
146
+ this.ValidateBuffer();
147
+ }
148
+ },
149
+
150
+ Commit: function(){
151
+ var i = 0;
152
+
153
+ var removeCount = 0;
154
+
155
+ var proxies = this.m_broadPhase.m_proxyPool;
156
+
157
+ for (i = 0; i < this.m_pairBufferCount; ++i)
158
+ {
159
+ var pair = this.Find(this.m_pairBuffer[i].proxyId1, this.m_pairBuffer[i].proxyId2);
160
+ //b2Settings.b2Assert(pair.IsBuffered());
161
+ pair.ClearBuffered();
162
+
163
+ //b2Settings.b2Assert(pair.proxyId1 < b2Settings.b2_maxProxies && pair.proxyId2 < b2Settings.b2_maxProxies);
164
+
165
+ var proxy1 = proxies[ pair.proxyId1 ];
166
+ var proxy2 = proxies[ pair.proxyId2 ];
167
+
168
+ //b2Settings.b2Assert(proxy1.IsValid());
169
+ //b2Settings.b2Assert(proxy2.IsValid());
170
+
171
+ if (pair.IsRemoved())
172
+ {
173
+ // It is possible a pair was added then removed before a commit. Therefore,
174
+ // we should be careful not to tell the user the pair was removed when the
175
+ // the user didn't receive a matching add.
176
+ if (pair.IsFinal() == true)
177
+ {
178
+ this.m_callback.PairRemoved(proxy1.userData, proxy2.userData, pair.userData);
179
+ }
180
+
181
+ // Store the ids so we can actually remove the pair below.
182
+ this.m_pairBuffer[removeCount].proxyId1 = pair.proxyId1;
183
+ this.m_pairBuffer[removeCount].proxyId2 = pair.proxyId2;
184
+ ++removeCount;
185
+ }
186
+ else
187
+ {
188
+ //b2Settings.b2Assert(this.m_broadPhase.TestOverlap(proxy1, proxy2) == true);
189
+
190
+ if (pair.IsFinal() == false)
191
+ {
192
+ pair.userData = this.m_callback.PairAdded(proxy1.userData, proxy2.userData);
193
+ pair.SetFinal();
194
+ }
195
+ }
196
+ }
197
+
198
+ for (i = 0; i < removeCount; ++i)
199
+ {
200
+ this.RemovePair(this.m_pairBuffer[i].proxyId1, this.m_pairBuffer[i].proxyId2);
201
+ }
202
+
203
+ this.m_pairBufferCount = 0;
204
+
205
+ if (b2BroadPhase.s_validate)
206
+ {
207
+ this.ValidateTable();
208
+ }
209
+ },
210
+
211
+ //private:
212
+
213
+ // Add a pair and return the new pair. If the pair already exists,
214
+ // no new pair is created and the old one is returned.
215
+ AddPair: function(proxyId1, proxyId2){
216
+
217
+ if (proxyId1 > proxyId2){
218
+ var temp = proxyId1;
219
+ proxyId1 = proxyId2;
220
+ proxyId2 = temp;
221
+ //b2Math.b2Swap(p1, p2);
222
+ }
223
+
224
+ var hash = b2PairManager.Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask;
225
+
226
+ //var pairIndex = this.FindHash(proxyId1, proxyId2, hash);
227
+ var pair = pair = this.FindHash(proxyId1, proxyId2, hash);
228
+
229
+ if (pair != null)
230
+ {
231
+ return pair;
232
+ }
233
+
234
+ //b2Settings.b2Assert(this.m_pairCount < b2Settings.b2_maxPairs && this.m_freePair != b2_nullPair);
235
+
236
+ var pIndex = this.m_freePair;
237
+ pair = this.m_pairs[pIndex];
238
+ this.m_freePair = pair.next;
239
+
240
+ pair.proxyId1 = proxyId1;
241
+ pair.proxyId2 = proxyId2;
242
+ pair.status = 0;
243
+ pair.userData = null;
244
+ pair.next = this.m_hashTable[hash];
245
+
246
+ this.m_hashTable[hash] = pIndex;
247
+
248
+ ++this.m_pairCount;
249
+
250
+ return pair;
251
+ },
252
+
253
+ // Remove a pair, return the pair's userData.
254
+ RemovePair: function(proxyId1, proxyId2){
255
+
256
+ //b2Settings.b2Assert(this.m_pairCount > 0);
257
+
258
+ if (proxyId1 > proxyId2){
259
+ var temp = proxyId1;
260
+ proxyId1 = proxyId2;
261
+ proxyId2 = temp;
262
+ //b2Math.b2Swap(proxyId1, proxyId2);
263
+ }
264
+
265
+ var hash = b2PairManager.Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask;
266
+
267
+ var node = this.m_hashTable[hash];
268
+ var pNode = null;
269
+
270
+ while (node != b2Pair.b2_nullPair)
271
+ {
272
+ if (b2PairManager.Equals(this.m_pairs[node], proxyId1, proxyId2))
273
+ {
274
+ var index = node;
275
+
276
+ //*node = this.m_pairs[*node].next;
277
+ if (pNode){
278
+ pNode.next = this.m_pairs[node].next;
279
+ }
280
+ else{
281
+ this.m_hashTable[hash] = this.m_pairs[node].next;
282
+ }
283
+
284
+ var pair = this.m_pairs[ index ];
285
+ var userData = pair.userData;
286
+
287
+ // Scrub
288
+ pair.next = this.m_freePair;
289
+ pair.proxyId1 = b2Pair.b2_nullProxy;
290
+ pair.proxyId2 = b2Pair.b2_nullProxy;
291
+ pair.userData = null;
292
+ pair.status = 0;
293
+
294
+ this.m_freePair = index;
295
+ --this.m_pairCount;
296
+ return userData;
297
+ }
298
+ else
299
+ {
300
+ //node = &this.m_pairs[*node].next;
301
+ pNode = this.m_pairs[node];
302
+ node = pNode.next;
303
+ }
304
+ }
305
+
306
+ //b2Settings.b2Assert(false);
307
+ return null;
308
+ },
309
+
310
+ Find: function(proxyId1, proxyId2){
311
+
312
+ if (proxyId1 > proxyId2){
313
+ var temp = proxyId1;
314
+ proxyId1 = proxyId2;
315
+ proxyId2 = temp;
316
+ //b2Math.b2Swap(proxyId1, proxyId2);
317
+ }
318
+
319
+ var hash = b2PairManager.Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask;
320
+
321
+ return this.FindHash(proxyId1, proxyId2, hash);
322
+ },
323
+ FindHash: function(proxyId1, proxyId2, hash){
324
+ var index = this.m_hashTable[hash];
325
+
326
+ while( index != b2Pair.b2_nullPair && b2PairManager.Equals(this.m_pairs[index], proxyId1, proxyId2) == false)
327
+ {
328
+ index = this.m_pairs[index].next;
329
+ }
330
+
331
+ if ( index == b2Pair.b2_nullPair )
332
+ {
333
+ return null;
334
+ }
335
+
336
+ //b2Settings.b2Assert(index < b2_maxPairs);
337
+
338
+ return this.m_pairs[ index ];
339
+ },
340
+
341
+ ValidateBuffer: function(){
342
+ // DEBUG
343
+ },
344
+
345
+ ValidateTable: function(){
346
+ // DEBUG
347
+ },
348
+
349
+ //public:
350
+ m_broadPhase: null,
351
+ m_callback: null,
352
+ m_pairs: null,
353
+ m_freePair: 0,
354
+ m_pairCount: 0,
355
+
356
+ m_pairBuffer: null,
357
+ m_pairBufferCount: 0,
358
+
359
+ m_hashTable: null
360
+
361
+
362
+ // static
363
+ // Thomas Wang's hash, see: http:
364
+
365
+
366
+
367
+ };
368
+ b2PairManager.Hash = function(proxyId1, proxyId2)
369
+ {
370
+ var key = ((proxyId2 << 16) & 0xffff0000) | proxyId1;
371
+ key = ~key + ((key << 15) & 0xFFFF8000);
372
+ key = key ^ ((key >> 12) & 0x000fffff);
373
+ key = key + ((key << 2) & 0xFFFFFFFC);
374
+ key = key ^ ((key >> 4) & 0x0fffffff);
375
+ key = key * 2057;
376
+ key = key ^ ((key >> 16) & 0x0000ffff);
377
+ return key;
378
+ };
379
+ b2PairManager.Equals = function(pair, proxyId1, proxyId2)
380
+ {
381
+ return (pair.proxyId1 == proxyId1 && pair.proxyId2 == proxyId2);
382
+ };
383
+ b2PairManager.EqualsPair = function(pair1, pair2)
384
+ {
385
+ return pair1.proxyId1 == pair2.proxyId1 && pair1.proxyId2 == pair2.proxyId2;
386
+ };