pbox2d 0.6.0-java → 0.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +8 -0
  3. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  4. data/.travis.yml +23 -0
  5. data/CHANGELOG.md +8 -0
  6. data/README.md +7 -7
  7. data/Rakefile +1 -2
  8. data/lib/box2d.jar +0 -0
  9. data/lib/pbox2d/version.rb +1 -1
  10. data/lib/pbox2d.rb +1 -0
  11. data/pbox2d.gemspec +6 -11
  12. data/pom.rb +59 -0
  13. data/pom.xml +82 -73
  14. data/src/org/jbox2d/JBox2D.gwt.xml +12 -0
  15. data/src/org/jbox2d/callbacks/ContactAdaptor.java +27 -0
  16. data/src/org/jbox2d/callbacks/ContactFilter.java +59 -0
  17. data/src/org/jbox2d/callbacks/ContactImpulse.java +42 -0
  18. data/src/org/jbox2d/callbacks/ContactListener.java +87 -0
  19. data/src/org/jbox2d/callbacks/DebugDraw.java +297 -0
  20. data/src/org/jbox2d/callbacks/DestructionListener.java +53 -0
  21. data/src/org/jbox2d/callbacks/PairCallback.java +29 -0
  22. data/src/org/jbox2d/callbacks/ParticleDestructionListener.java +20 -0
  23. data/src/org/jbox2d/callbacks/ParticleQueryCallback.java +19 -0
  24. data/src/org/jbox2d/callbacks/ParticleRaycastCallback.java +19 -0
  25. data/src/org/jbox2d/callbacks/QueryCallback.java +45 -0
  26. data/src/org/jbox2d/callbacks/RayCastCallback.java +55 -0
  27. data/src/org/jbox2d/callbacks/TreeCallback.java +42 -0
  28. data/src/org/jbox2d/callbacks/TreeRayCastCallback.java +44 -0
  29. data/src/org/jbox2d/collision/AABB.java +338 -0
  30. data/src/org/jbox2d/collision/Collision.java +1444 -0
  31. data/src/org/jbox2d/collision/ContactID.java +106 -0
  32. data/src/org/jbox2d/collision/Distance.java +773 -0
  33. data/src/org/jbox2d/collision/DistanceInput.java +41 -0
  34. data/src/org/jbox2d/collision/DistanceOutput.java +43 -0
  35. data/src/org/jbox2d/collision/Manifold.java +116 -0
  36. data/src/org/jbox2d/collision/ManifoldPoint.java +104 -0
  37. data/src/org/jbox2d/collision/RayCastInput.java +47 -0
  38. data/src/org/jbox2d/collision/RayCastOutput.java +46 -0
  39. data/src/org/jbox2d/collision/TimeOfImpact.java +526 -0
  40. data/src/org/jbox2d/collision/WorldManifold.java +200 -0
  41. data/src/org/jbox2d/collision/broadphase/BroadPhase.java +92 -0
  42. data/src/org/jbox2d/collision/broadphase/BroadPhaseStrategy.java +88 -0
  43. data/src/org/jbox2d/collision/broadphase/DefaultBroadPhaseBuffer.java +268 -0
  44. data/src/org/jbox2d/collision/broadphase/DynamicTree.java +883 -0
  45. data/src/org/jbox2d/collision/broadphase/DynamicTreeFlatNodes.java +873 -0
  46. data/src/org/jbox2d/collision/broadphase/DynamicTreeNode.java +54 -0
  47. data/src/org/jbox2d/collision/broadphase/Pair.java +46 -0
  48. data/src/org/jbox2d/collision/shapes/ChainShape.java +264 -0
  49. data/src/org/jbox2d/collision/shapes/CircleShape.java +207 -0
  50. data/src/org/jbox2d/collision/shapes/EdgeShape.java +254 -0
  51. data/src/org/jbox2d/collision/shapes/MassData.java +105 -0
  52. data/src/org/jbox2d/collision/shapes/PolygonShape.java +718 -0
  53. data/src/org/jbox2d/collision/shapes/Shape.java +136 -0
  54. data/src/org/jbox2d/collision/shapes/ShapeType.java +32 -0
  55. data/src/org/jbox2d/common/BufferUtils.java +209 -0
  56. data/src/org/jbox2d/common/Color3f.java +88 -0
  57. data/src/org/jbox2d/common/IViewportTransform.java +133 -0
  58. data/src/org/jbox2d/common/Mat22.java +609 -0
  59. data/src/org/jbox2d/common/Mat33.java +290 -0
  60. data/src/org/jbox2d/common/MathUtils.java +335 -0
  61. data/src/org/jbox2d/common/OBBViewportTransform.java +174 -0
  62. data/src/org/jbox2d/common/PlatformMathUtils.java +46 -0
  63. data/src/org/jbox2d/common/RaycastResult.java +37 -0
  64. data/src/org/jbox2d/common/Rot.java +150 -0
  65. data/src/org/jbox2d/common/Settings.java +246 -0
  66. data/src/org/jbox2d/common/Sweep.java +116 -0
  67. data/src/org/jbox2d/common/Timer.java +46 -0
  68. data/src/org/jbox2d/common/Transform.java +203 -0
  69. data/src/org/jbox2d/common/Vec2.java +388 -0
  70. data/src/org/jbox2d/common/Vec3.java +170 -0
  71. data/src/org/jbox2d/dynamics/Body.java +1246 -0
  72. data/src/org/jbox2d/dynamics/BodyDef.java +382 -0
  73. data/src/org/jbox2d/dynamics/BodyType.java +41 -0
  74. data/src/org/jbox2d/dynamics/ContactManager.java +293 -0
  75. data/src/org/jbox2d/dynamics/Filter.java +62 -0
  76. data/src/org/jbox2d/dynamics/Fixture.java +454 -0
  77. data/src/org/jbox2d/dynamics/FixtureDef.java +214 -0
  78. data/src/org/jbox2d/dynamics/FixtureProxy.java +38 -0
  79. data/src/org/jbox2d/dynamics/Island.java +602 -0
  80. data/src/org/jbox2d/dynamics/Profile.java +97 -0
  81. data/src/org/jbox2d/dynamics/SolverData.java +33 -0
  82. data/src/org/jbox2d/dynamics/TimeStep.java +46 -0
  83. data/src/org/jbox2d/dynamics/World.java +2075 -0
  84. data/src/org/jbox2d/dynamics/contacts/ChainAndCircleContact.java +57 -0
  85. data/src/org/jbox2d/dynamics/contacts/ChainAndPolygonContact.java +57 -0
  86. data/src/org/jbox2d/dynamics/contacts/CircleContact.java +50 -0
  87. data/src/org/jbox2d/dynamics/contacts/Contact.java +365 -0
  88. data/src/org/jbox2d/dynamics/contacts/ContactCreator.java +35 -0
  89. data/src/org/jbox2d/dynamics/contacts/ContactEdge.java +56 -0
  90. data/src/org/jbox2d/dynamics/contacts/ContactPositionConstraint.java +49 -0
  91. data/src/org/jbox2d/dynamics/contacts/ContactRegister.java +31 -0
  92. data/src/org/jbox2d/dynamics/contacts/ContactSolver.java +1104 -0
  93. data/src/org/jbox2d/dynamics/contacts/ContactVelocityConstraint.java +60 -0
  94. data/src/org/jbox2d/dynamics/contacts/EdgeAndCircleContact.java +52 -0
  95. data/src/org/jbox2d/dynamics/contacts/EdgeAndPolygonContact.java +52 -0
  96. data/src/org/jbox2d/dynamics/contacts/PolygonAndCircleContact.java +51 -0
  97. data/src/org/jbox2d/dynamics/contacts/PolygonContact.java +50 -0
  98. data/src/org/jbox2d/dynamics/contacts/Position.java +31 -0
  99. data/src/org/jbox2d/dynamics/contacts/Velocity.java +31 -0
  100. data/src/org/jbox2d/dynamics/joints/ConstantVolumeJoint.java +258 -0
  101. data/src/org/jbox2d/dynamics/joints/ConstantVolumeJointDef.java +75 -0
  102. data/src/org/jbox2d/dynamics/joints/DistanceJoint.java +356 -0
  103. data/src/org/jbox2d/dynamics/joints/DistanceJointDef.java +106 -0
  104. data/src/org/jbox2d/dynamics/joints/FrictionJoint.java +294 -0
  105. data/src/org/jbox2d/dynamics/joints/FrictionJointDef.java +78 -0
  106. data/src/org/jbox2d/dynamics/joints/GearJoint.java +520 -0
  107. data/src/org/jbox2d/dynamics/joints/GearJointDef.java +58 -0
  108. data/src/org/jbox2d/dynamics/joints/Jacobian.java +32 -0
  109. data/src/org/jbox2d/dynamics/joints/Joint.java +235 -0
  110. data/src/org/jbox2d/dynamics/joints/JointDef.java +65 -0
  111. data/src/org/jbox2d/dynamics/joints/JointEdge.java +57 -0
  112. data/src/org/jbox2d/dynamics/joints/JointType.java +28 -0
  113. data/src/org/jbox2d/dynamics/joints/LimitState.java +28 -0
  114. data/src/org/jbox2d/dynamics/joints/MotorJoint.java +339 -0
  115. data/src/org/jbox2d/dynamics/joints/MotorJointDef.java +55 -0
  116. data/src/org/jbox2d/dynamics/joints/MouseJoint.java +262 -0
  117. data/src/org/jbox2d/dynamics/joints/MouseJointDef.java +62 -0
  118. data/src/org/jbox2d/dynamics/joints/PrismaticJoint.java +808 -0
  119. data/src/org/jbox2d/dynamics/joints/PrismaticJointDef.java +120 -0
  120. data/src/org/jbox2d/dynamics/joints/PulleyJoint.java +393 -0
  121. data/src/org/jbox2d/dynamics/joints/PulleyJointDef.java +105 -0
  122. data/src/org/jbox2d/dynamics/joints/RevoluteJoint.java +554 -0
  123. data/src/org/jbox2d/dynamics/joints/RevoluteJointDef.java +137 -0
  124. data/src/org/jbox2d/dynamics/joints/RopeJoint.java +276 -0
  125. data/src/org/jbox2d/dynamics/joints/RopeJointDef.java +34 -0
  126. data/src/org/jbox2d/dynamics/joints/WeldJoint.java +424 -0
  127. data/src/org/jbox2d/dynamics/joints/WeldJointDef.java +85 -0
  128. data/src/org/jbox2d/dynamics/joints/WheelJoint.java +498 -0
  129. data/src/org/jbox2d/dynamics/joints/WheelJointDef.java +98 -0
  130. data/src/org/jbox2d/particle/ParticleBodyContact.java +17 -0
  131. data/src/org/jbox2d/particle/ParticleColor.java +52 -0
  132. data/src/org/jbox2d/particle/ParticleContact.java +14 -0
  133. data/src/org/jbox2d/particle/ParticleDef.java +24 -0
  134. data/src/org/jbox2d/particle/ParticleGroup.java +154 -0
  135. data/src/org/jbox2d/particle/ParticleGroupDef.java +62 -0
  136. data/src/org/jbox2d/particle/ParticleGroupType.java +8 -0
  137. data/src/org/jbox2d/particle/ParticleSystem.java +2172 -0
  138. data/src/org/jbox2d/particle/ParticleType.java +28 -0
  139. data/src/org/jbox2d/particle/StackQueue.java +44 -0
  140. data/src/org/jbox2d/particle/VoronoiDiagram.java +209 -0
  141. data/src/org/jbox2d/pooling/IDynamicStack.java +47 -0
  142. data/src/org/jbox2d/pooling/IOrderedStack.java +57 -0
  143. data/src/org/jbox2d/pooling/IWorldPool.java +101 -0
  144. data/src/org/jbox2d/pooling/arrays/FloatArray.java +50 -0
  145. data/src/org/jbox2d/pooling/arrays/GeneratorArray.java +33 -0
  146. data/src/org/jbox2d/pooling/arrays/IntArray.java +53 -0
  147. data/src/org/jbox2d/pooling/arrays/Vec2Array.java +57 -0
  148. data/src/org/jbox2d/pooling/normal/CircleStack.java +77 -0
  149. data/src/org/jbox2d/pooling/normal/DefaultWorldPool.java +331 -0
  150. data/src/org/jbox2d/pooling/normal/MutableStack.java +72 -0
  151. data/src/org/jbox2d/pooling/normal/OrderedStack.java +73 -0
  152. data/src/org/jbox2d/pooling/stacks/DynamicIntStack.java +60 -0
  153. metadata +161 -14
  154. data/lib/jbox2d-library-2.3.1-SNAPSHOT.jar +0 -0
@@ -0,0 +1,77 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.pooling.normal;
25
+
26
+ import org.jbox2d.pooling.IOrderedStack;
27
+
28
+ public abstract class CircleStack<E> implements IOrderedStack<E>{
29
+
30
+ private final Object[] pool;
31
+ private int index;
32
+ private final int size;
33
+ private final Object[] container;
34
+
35
+ public CircleStack(int argStackSize, int argContainerSize) {
36
+ size = argStackSize;
37
+ pool = new Object[argStackSize];
38
+ for (int i = 0; i < argStackSize; i++) {
39
+ pool[i] = newInstance();
40
+ }
41
+ index = 0;
42
+ container = new Object[argContainerSize];
43
+ }
44
+
45
+ @SuppressWarnings("unchecked")
46
+ @Override
47
+ public final E pop() {
48
+ index++;
49
+ if(index >= size){
50
+ index = 0;
51
+ }
52
+ return (E) pool[index];
53
+ }
54
+
55
+ @SuppressWarnings("unchecked")
56
+ @Override
57
+ public final E[] pop(int argNum) {
58
+ assert (argNum <= container.length) : "Container array is too small";
59
+ if(index + argNum < size){
60
+ System.arraycopy(pool, index, container, 0, argNum);
61
+ index += argNum;
62
+ }else{
63
+ int overlap = (index + argNum) - size;
64
+ System.arraycopy(pool, index, container, 0, argNum - overlap);
65
+ System.arraycopy(pool, 0, container, argNum - overlap, overlap);
66
+ index = overlap;
67
+ }
68
+ return (E[]) container;
69
+ }
70
+
71
+ @Override
72
+ public void push(int argNum) {}
73
+
74
+ /** Creates a new instance of the object contained by this stack.
75
+ * @return */
76
+ protected abstract E newInstance();
77
+ }
@@ -0,0 +1,331 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ /**
25
+ * Created at 3:26:14 AM Jan 11, 2011
26
+ */
27
+ package org.jbox2d.pooling.normal;
28
+
29
+ import java.util.HashMap;
30
+
31
+ import org.jbox2d.collision.AABB;
32
+ import org.jbox2d.collision.Collision;
33
+ import org.jbox2d.collision.Distance;
34
+ import org.jbox2d.collision.TimeOfImpact;
35
+ import org.jbox2d.common.Mat22;
36
+ import org.jbox2d.common.Mat33;
37
+ import org.jbox2d.common.Rot;
38
+ import org.jbox2d.common.Settings;
39
+ import org.jbox2d.common.Vec2;
40
+ import org.jbox2d.common.Vec3;
41
+ import org.jbox2d.dynamics.contacts.ChainAndCircleContact;
42
+ import org.jbox2d.dynamics.contacts.ChainAndPolygonContact;
43
+ import org.jbox2d.dynamics.contacts.CircleContact;
44
+ import org.jbox2d.dynamics.contacts.Contact;
45
+ import org.jbox2d.dynamics.contacts.EdgeAndCircleContact;
46
+ import org.jbox2d.dynamics.contacts.EdgeAndPolygonContact;
47
+ import org.jbox2d.dynamics.contacts.PolygonAndCircleContact;
48
+ import org.jbox2d.dynamics.contacts.PolygonContact;
49
+ import org.jbox2d.pooling.IDynamicStack;
50
+ import org.jbox2d.pooling.IWorldPool;
51
+
52
+ /**
53
+ * Provides object pooling for all objects used in the engine. Objects retrieved from here should
54
+ * only be used temporarily, and then pushed back (with the exception of arrays).
55
+ *
56
+ * @author Daniel Murphy
57
+ */
58
+ public class DefaultWorldPool implements IWorldPool {
59
+
60
+ private final OrderedStack<Vec2> vecs;
61
+ private final OrderedStack<Vec3> vec3s;
62
+ private final OrderedStack<Mat22> mats;
63
+ private final OrderedStack<Mat33> mat33s;
64
+ private final OrderedStack<AABB> aabbs;
65
+ private final OrderedStack<Rot> rots;
66
+
67
+ private final HashMap<Integer, float[]> afloats = new HashMap<>();
68
+ private final HashMap<Integer, int[]> aints = new HashMap<>();
69
+ private final HashMap<Integer, Vec2[]> avecs = new HashMap<>();
70
+
71
+ private final IWorldPool world = this;
72
+
73
+ private final MutableStack<Contact> pcstack =
74
+ new MutableStack<Contact>(Settings.CONTACT_STACK_INIT_SIZE) {
75
+ @Override
76
+ protected Contact newInstance () { return new PolygonContact(world); }
77
+ @Override
78
+ protected Contact[] newArray(int size) { return new PolygonContact[size]; }
79
+ };
80
+
81
+ private final MutableStack<Contact> ccstack =
82
+ new MutableStack<Contact>(Settings.CONTACT_STACK_INIT_SIZE) {
83
+ @Override
84
+ protected Contact newInstance () { return new CircleContact(world); }
85
+ @Override
86
+ protected Contact[] newArray(int size) { return new CircleContact[size]; }
87
+ };
88
+
89
+ private final MutableStack<Contact> cpstack =
90
+ new MutableStack<Contact>(Settings.CONTACT_STACK_INIT_SIZE) {
91
+ @Override
92
+ protected Contact newInstance () { return new PolygonAndCircleContact(world); }
93
+ @Override
94
+ protected Contact[] newArray(int size) { return new PolygonAndCircleContact[size]; }
95
+ };
96
+
97
+ private final MutableStack<Contact> ecstack;
98
+
99
+ private final MutableStack<Contact> epstack;
100
+
101
+ private final MutableStack<Contact> chcstack;
102
+
103
+ private final MutableStack<Contact> chpstack;
104
+
105
+ private final Collision collision;
106
+ private final TimeOfImpact toi;
107
+ private final Distance dist;
108
+
109
+ public DefaultWorldPool(int argSize, int argContainerSize) {
110
+ this.chpstack = new MutableStack<Contact>(Settings.CONTACT_STACK_INIT_SIZE) {
111
+ @Override
112
+ protected Contact newInstance () { return new ChainAndPolygonContact(world); }
113
+ @Override
114
+ protected Contact[] newArray(int size) { return new ChainAndPolygonContact[size]; }
115
+ };
116
+ this.chcstack = new MutableStack<Contact>(Settings.CONTACT_STACK_INIT_SIZE) {
117
+ @Override
118
+ protected Contact newInstance () { return new ChainAndCircleContact(world); }
119
+ @Override
120
+ protected Contact[] newArray(int size) { return new ChainAndCircleContact[size]; }
121
+ };
122
+ this.epstack = new MutableStack<Contact>(Settings.CONTACT_STACK_INIT_SIZE) {
123
+ @Override
124
+ protected Contact newInstance () { return new EdgeAndPolygonContact(world); }
125
+ @Override
126
+ protected Contact[] newArray(int size) { return new EdgeAndPolygonContact[size]; }
127
+ };
128
+ this.ecstack = new MutableStack<Contact>(Settings.CONTACT_STACK_INIT_SIZE) {
129
+ @Override
130
+ protected Contact newInstance () { return new EdgeAndCircleContact(world); }
131
+ @Override
132
+ protected Contact[] newArray(int size) { return new EdgeAndCircleContact[size]; }
133
+ };
134
+ vecs = new OrderedStack<Vec2>(argSize, argContainerSize) {
135
+ @Override
136
+ protected Vec2 newInstance() { return new Vec2(); }
137
+ };
138
+ vec3s = new OrderedStack<Vec3>(argSize, argContainerSize) {
139
+ @Override
140
+ protected Vec3 newInstance() { return new Vec3(); }
141
+ };
142
+ mats = new OrderedStack<Mat22>(argSize, argContainerSize) {
143
+ @Override
144
+ protected Mat22 newInstance() { return new Mat22(); }
145
+ };
146
+ aabbs = new OrderedStack<AABB>(argSize, argContainerSize) {
147
+ @Override
148
+ protected AABB newInstance() { return new AABB(); }
149
+ };
150
+ rots = new OrderedStack<Rot>(argSize, argContainerSize) {
151
+ @Override
152
+ protected Rot newInstance() { return new Rot(); }
153
+ };
154
+ mat33s = new OrderedStack<Mat33>(argSize, argContainerSize) {
155
+ @Override
156
+ protected Mat33 newInstance() { return new Mat33(); }
157
+ };
158
+
159
+ dist = new Distance();
160
+ collision = new Collision(this);
161
+ toi = new TimeOfImpact(this);
162
+ }
163
+
164
+ @Override
165
+ public final IDynamicStack<Contact> getPolyContactStack() {
166
+ return pcstack;
167
+ }
168
+
169
+ @Override
170
+ public final IDynamicStack<Contact> getCircleContactStack() {
171
+ return ccstack;
172
+ }
173
+
174
+ @Override
175
+ public final IDynamicStack<Contact> getPolyCircleContactStack() {
176
+ return cpstack;
177
+ }
178
+
179
+ @Override
180
+ public IDynamicStack<Contact> getEdgeCircleContactStack() {
181
+ return ecstack;
182
+ }
183
+
184
+ @Override
185
+ public IDynamicStack<Contact> getEdgePolyContactStack() {
186
+ return epstack;
187
+ }
188
+
189
+ @Override
190
+ public IDynamicStack<Contact> getChainCircleContactStack() {
191
+ return chcstack;
192
+ }
193
+
194
+ @Override
195
+ public IDynamicStack<Contact> getChainPolyContactStack() {
196
+ return chpstack;
197
+ }
198
+
199
+ @Override
200
+ public final Vec2 popVec2() {
201
+ return vecs.pop();
202
+ }
203
+
204
+ @Override
205
+ public final Vec2[] popVec2(int argNum) {
206
+ return vecs.pop(argNum);
207
+ }
208
+
209
+ @Override
210
+ public final void pushVec2(int argNum) {
211
+ vecs.push(argNum);
212
+ }
213
+
214
+ @Override
215
+ public final Vec3 popVec3() {
216
+ return vec3s.pop();
217
+ }
218
+
219
+ @Override
220
+ public final Vec3[] popVec3(int argNum) {
221
+ return vec3s.pop(argNum);
222
+ }
223
+
224
+ @Override
225
+ public final void pushVec3(int argNum) {
226
+ vec3s.push(argNum);
227
+ }
228
+
229
+ /**
230
+ *
231
+ * @return
232
+ */
233
+ @Override
234
+ public final Mat22 popMat22() {
235
+ return mats.pop();
236
+ }
237
+
238
+ @Override
239
+ public final Mat22[] popMat22(int argNum) {
240
+ return mats.pop(argNum);
241
+ }
242
+
243
+ @Override
244
+ public final void pushMat22(int argNum) {
245
+ mats.push(argNum);
246
+ }
247
+
248
+ @Override
249
+ public final Mat33 popMat33() {
250
+ return mat33s.pop();
251
+ }
252
+
253
+ @Override
254
+ public final void pushMat33(int argNum) {
255
+ mat33s.push(argNum);
256
+ }
257
+
258
+ @Override
259
+ public final AABB popAABB() {
260
+ return aabbs.pop();
261
+ }
262
+
263
+ @Override
264
+ public final AABB[] popAABB(int argNum) {
265
+ return aabbs.pop(argNum);
266
+ }
267
+
268
+ @Override
269
+ public final void pushAABB(int argNum) {
270
+ aabbs.push(argNum);
271
+ }
272
+
273
+ @Override
274
+ public final Rot popRot() {
275
+ return rots.pop();
276
+ }
277
+
278
+ @Override
279
+ public final void pushRot(int num) {
280
+ rots.push(num);
281
+ }
282
+
283
+ @Override
284
+ public final Collision getCollision() {
285
+ return collision;
286
+ }
287
+
288
+ @Override
289
+ public final TimeOfImpact getTimeOfImpact() {
290
+ return toi;
291
+ }
292
+
293
+ @Override
294
+ public final Distance getDistance() {
295
+ return dist;
296
+ }
297
+
298
+ @Override
299
+ public final float[] getFloatArray(int argLength) {
300
+ if (!afloats.containsKey(argLength)) {
301
+ afloats.put(argLength, new float[argLength]);
302
+ }
303
+
304
+ assert (afloats.get(argLength).length == argLength) : "Array not built with correct length";
305
+ return afloats.get(argLength);
306
+ }
307
+
308
+ @Override
309
+ public final int[] getIntArray(int argLength) {
310
+ if (!aints.containsKey(argLength)) {
311
+ aints.put(argLength, new int[argLength]);
312
+ }
313
+
314
+ assert (aints.get(argLength).length == argLength) : "Array not built with correct length";
315
+ return aints.get(argLength);
316
+ }
317
+
318
+ @Override
319
+ public final Vec2[] getVec2Array(int argLength) {
320
+ if (!avecs.containsKey(argLength)) {
321
+ Vec2[] ray = new Vec2[argLength];
322
+ for (int i = 0; i < argLength; i++) {
323
+ ray[i] = new Vec2();
324
+ }
325
+ avecs.put(argLength, ray);
326
+ }
327
+
328
+ assert (avecs.get(argLength).length == argLength) : "Array not built with correct length";
329
+ return avecs.get(argLength);
330
+ }
331
+ }
@@ -0,0 +1,72 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.pooling.normal;
25
+
26
+ import org.jbox2d.pooling.IDynamicStack;
27
+
28
+ public abstract class MutableStack<E> implements IDynamicStack<E> {
29
+
30
+ private E[] stack;
31
+ private int index;
32
+ private int size;
33
+
34
+ public MutableStack(int argInitSize) {
35
+ index = 0;
36
+ stack = null;
37
+ index = 0;
38
+ extendStack(argInitSize);
39
+ }
40
+
41
+ private void extendStack(int argSize) {
42
+ E[] newStack = newArray(argSize);
43
+ if (stack != null) {
44
+ System.arraycopy(stack, 0, newStack, 0, size);
45
+ }
46
+ for (int i = 0; i < newStack.length; i++) {
47
+ newStack[i] = newInstance();
48
+ }
49
+ stack = newStack;
50
+ size = newStack.length;
51
+ }
52
+
53
+ @Override
54
+ public final E pop() {
55
+ if (index >= size) {
56
+ extendStack(size * 2);
57
+ }
58
+ return stack[index++];
59
+ }
60
+
61
+ @Override
62
+ public final void push(E argObject) {
63
+ assert (index > 0);
64
+ stack[--index] = argObject;
65
+ }
66
+
67
+ /** Creates a new instance of the object contained by this stack.
68
+ * @return */
69
+ protected abstract E newInstance();
70
+
71
+ protected abstract E[] newArray(int size);
72
+ }
@@ -0,0 +1,73 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ /**
25
+ * Created at 12:52:04 AM Jan 20, 2011
26
+ */
27
+ package org.jbox2d.pooling.normal;
28
+
29
+ /**
30
+ * @author Daniel Murphy
31
+ * @param <E>
32
+ */
33
+ public abstract class OrderedStack<E> {
34
+
35
+ private final Object[] pool;
36
+ private int index;
37
+ private final int size;
38
+ private final Object[] container;
39
+
40
+ public OrderedStack(int argStackSize, int argContainerSize) {
41
+ size = argStackSize;
42
+ pool = new Object[argStackSize];
43
+ for (int i = 0; i < argStackSize; i++) {
44
+ pool[i] = newInstance();
45
+ }
46
+ index = 0;
47
+ container = new Object[argContainerSize];
48
+ }
49
+
50
+ @SuppressWarnings("unchecked")
51
+ public final E pop() {
52
+ assert (index < size) : "End of stack reached, there is probably a leak somewhere";
53
+ return (E) pool[index++];
54
+ }
55
+
56
+ @SuppressWarnings("unchecked")
57
+ public final E[] pop(int argNum) {
58
+ assert (index + argNum < size) : "End of stack reached, there is probably a leak somewhere";
59
+ assert (argNum <= container.length) : "Container array is too small";
60
+ System.arraycopy(pool, index, container, 0, argNum);
61
+ index += argNum;
62
+ return (E[]) container;
63
+ }
64
+
65
+ public final void push(int argNum) {
66
+ index -= argNum;
67
+ assert (index >= 0) : "Beginning of stack reached, push/pops are unmatched";
68
+ }
69
+
70
+ /** Creates a new instance of the object contained by this stack.
71
+ * @return */
72
+ protected abstract E newInstance();
73
+ }
@@ -0,0 +1,60 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.pooling.stacks;
25
+
26
+ public class DynamicIntStack {
27
+
28
+ private int[] stack;
29
+ private int size;
30
+ private int position;
31
+
32
+ public DynamicIntStack(int initialSize) {
33
+ stack = new int[initialSize];
34
+ position = 0;
35
+ size = initialSize;
36
+ }
37
+
38
+ public void reset() {
39
+ position = 0;
40
+ }
41
+
42
+ public int pop() {
43
+ assert (position > 0);
44
+ return stack[--position];
45
+ }
46
+
47
+ public void push(int i) {
48
+ if (position == size) {
49
+ int[] old = stack;
50
+ stack = new int[size * 2];
51
+ size = stack.length;
52
+ System.arraycopy(old, 0, stack, 0, old.length);
53
+ }
54
+ stack[position++] = i;
55
+ }
56
+
57
+ public int getCount() {
58
+ return position;
59
+ }
60
+ }