Permalink
Browse files

Cleanup space geom list

This commit includes the following changes:
- remo _geoms ArrayList from DxSpace
- deprecate getGeom() and add getGeoms() to DxSpace
- reduce visibility of _next field in DxGeom
- add corresponding test - Test_DxSpace
  • Loading branch information...
1 parent b4d755c commit 84fefd29785a475e2ba738f5ac10db53758db111 piotr committed with Piotr Piastucki Jan 10, 2016
Showing with 242 additions and 202 deletions.
  1. +7 −1 core-cpp/src/main/java/org/ode4j/cpp/internal/ApiCppCollisionSpace.java
  2. +4 −0 core/src/main/java/org/ode4j/ode/DSpace.java
  3. +3 −8 core/src/main/java/org/ode4j/ode/internal/DxGeom.java
  4. +4 −8 core/src/main/java/org/ode4j/ode/internal/DxHashSpace.java
  5. +0 −77 core/src/main/java/org/ode4j/ode/internal/DxQuadTreeSpace.java
  6. +2 −14 core/src/main/java/org/ode4j/ode/internal/DxSAPSpace.java
  7. +4 −10 core/src/main/java/org/ode4j/ode/internal/DxSimpleSpace.java
  8. +61 −42 core/src/main/java/org/ode4j/ode/internal/DxSpace.java
  9. +3 −5 demo-cpp/src/main/java/org/ode4j/democpp/DemoCollision.java
  10. +2 −3 demo-cpp/src/main/java/org/ode4j/democpp/DemoMovingConvex.java
  11. +2 −4 demo/src/main/java/org/ode4j/demo/DemoCollision.java
  12. +1 −3 demo/src/main/java/org/ode4j/demo/DemoDBall.java
  13. +1 −3 demo/src/main/java/org/ode4j/demo/DemoDHinge.java
  14. +1 −3 demo/src/main/java/org/ode4j/demo/DemoJointConstrainedBall.java
  15. +1 −3 demo/src/main/java/org/ode4j/demo/DemoMovingConvex.java
  16. +1 −3 demo/src/main/java/org/ode4j/demo/DemoMovingTrimesh.java
  17. +1 −3 demo/src/main/java/org/ode4j/demo/DemoTracks.java
  18. +1 −3 demo/src/main/java/org/ode4j/demo/DemoTransmission.java
  19. +1 −3 demo/src/main/java/org/ode4j/demo/ragdoll/DemoRagdoll.java
  20. +3 −2 demo/src/test/java/org/ode4j/tests/SpacePerformanceTest.java
  21. +1 −4 demo/src/test/java/org/ode4j/tests/TestIssue0018_NpeInQuickstep.java
  22. +138 −0 demo/src/test/java/org/ode4j/tests/Test_DxSpace.java
@@ -194,10 +194,16 @@ public static void dSpaceClean (DSpace s) {
public static int dSpaceGetNumGeoms (DSpace s) {
return s.getNumGeoms();
}
- //ODE_API
+ //ODE_API
+ /** @deprecated Use dSpaceGetGeoms() instead */
+ @Deprecated
public static DGeom dSpaceGetGeom (DSpace s, int i) {
return s.getGeom(i);
}
+
+ public static Iterable<? extends DGeom> dSpaceGetGeoms (DSpace s) {
+ return s.getGeoms();
+ }
/**
* Given a space, this returns its class.
@@ -24,6 +24,7 @@
*************************************************************************/
package org.ode4j.ode;
+import org.ode4j.ode.internal.DxGeom;
/**
* collision space.
@@ -45,7 +46,10 @@
boolean query (DGeom x);
int getNumGeoms();
+ /** @deprecated Use getGeoms() instead */
+ @Deprecated
DGeom getGeom (int i);
+ Iterable<DxGeom> getGeoms();
/** This is equivalent to OdeHelper.spaceCollide(...) */
void collide (Object data, DNearCallback callback);
@@ -24,8 +24,6 @@
*************************************************************************/
package org.ode4j.ode.internal;
-import java.util.List;
-
import static org.ode4j.ode.OdeMath.*;
import static org.ode4j.ode.internal.Rotation.dQfromR;
@@ -164,7 +162,7 @@
* For the first element, it is a pointer to (container.first).
*/
// private final Ref<dxGeom> tome = new Ref<dxGeom>();
- DxGeom _next = null;// next geom in linked list of geoms
+ private DxGeom _next = null;// next geom in linked list of geoms
private DxGeom _prev = null;
//dxGeom tome; // linked list backpointer
private DxGeom _next_ex; // next geom in extra linked list of geoms (for higher level structures)
@@ -351,7 +349,7 @@ final void unsetFlagCustom(int customFlag) {
// tome.set(next);
// }
- void spaceAdd (DxGeom next, DxSpace parent, List<DxGeom> geoms) {
+ void spaceAdd (DxGeom next, DxSpace parent) {
// next = *first_ptr;
// tome = first_ptr;
// if (*first_ptr) (*first_ptr).tome = &next;
@@ -371,10 +369,9 @@ void spaceAdd (DxGeom next, DxSpace parent, List<DxGeom> geoms) {
parent.setFirst(this);
// parent_space = parent;
- geoms.add(0, this);
}
- void spaceRemove(DxSpace parent, List<DxGeom> geoms) {
+ void spaceRemove(DxSpace parent) {
// if (next) next->tome = tome;
// *tome = next;
// if (next != null) next.tome = tome;
@@ -388,8 +385,6 @@ void spaceRemove(DxSpace parent, List<DxGeom> geoms) {
parent.setFirst(_next);
}
- //TODO use HashSet or IdentitySet or ArrayList? Check call hierarchy for type of usage!
- geoms.remove(this);
}
@@ -183,9 +183,7 @@ public void cleanGeoms()
{
// compute the AABBs of all dirty geoms, and clear the dirty flags
lock_count++;
- //for (dxGeom g=_first; (g!= null) && (g.gflags & GEOM_DIRTY) != 0;
- //g=g.getNext()) {
- for (DxGeom g: _geoms) {
+ for (DxGeom g : getGeoms()) {
//if ((g._gflags & GEOM_DIRTY)==0) break;
if (!g.hasFlagDirty()) break;
if (g instanceof DxSpace) {
@@ -206,7 +204,7 @@ public void collide (Object data, DNearCallback callback)
int i,maxlevel;
// 0 or 1 geoms can't collide with anything
- if (count < 2) return;
+ if (getNumGeoms() < 2) return;
lock_count++;
cleanGeoms();
@@ -220,8 +218,7 @@ public void collide (Object data, DNearCallback callback)
ArrayList<dxAABB> hash_boxes = new ArrayList<dxAABB>(); // list of AABBs in hash table
ArrayList<dxAABB> big_boxes = new ArrayList<dxAABB>(); // list of AABBs too big for hash table
maxlevel = global_minlevel - 1;
- //for (geom = _first; geom != null; geom=geom.getNext()) {
- for (DxGeom geom: _geoms) {
+ for (DxGeom geom : getGeoms()) {
if (!GEOM_ENABLED(geom)){
continue;
}
@@ -393,8 +390,7 @@ void collide2 (Object data, DxGeom geom,
geom.recomputeAABB();
// intersect bounding boxes
-// for (dxGeom g=_first; g != null; g=g.getNext()) {
- for (DxGeom g: _geoms) {
+ for (DxGeom g : getGeoms()) {
if (GEOM_ENABLED(g)) collideAABBs (g,geom,data,callback);
}
@@ -28,8 +28,6 @@
import static org.ode4j.ode.internal.Common.dAASSERT;
import static org.ode4j.ode.internal.Common.dIASSERT;
import static org.ode4j.ode.internal.Common.dNextAfter;
-import static org.ode4j.ode.internal.Common.dUASSERT;
-import static org.ode4j.ode.internal.ErrorHandler.dDebug;
import java.util.ArrayList;
import java.util.List;
@@ -478,81 +476,6 @@ public void DESTRUCTOR(){
super.DESTRUCTOR();
}
- //dxGeom* dxQuadTreeSpace::getGeom(int Index){
- @Override
- public DxGeom getGeom(int Index) {
- dUASSERT(Index >= 0 && Index < count, "index out of range");
-
- //@@@
- dDebug (0,"dxQuadTreeSpace::getGeom() not yet implemented");
-
- return null;
-
- // This doesnt work
-
- /*if (CurrentIndex == Index){
- // Loop through all objects in the local list
-CHILDRECURSE:
- if (CurrentObject){
- dGeom g = CurrentObject;
- CurrentObject = CurrentObject->next;
- CurrentIndex++;
-
-#ifdef DRAWBLOCKS
- DrawBlock(CurrentBlock);
-#endif //DRAWBLOCKS
- return g;
- }
- else{
- // Now lets loop through our children. Starting at index 0.
- if (CurrentBlock->Children){
- CurrentChild[CurrentLevel] = 0;
-PARENTRECURSE:
- for (int& i = CurrentChild[CurrentLevel]; i < SPLITS; i++){
- if (CurrentBlock->Children[i].GeomCount == 0){
- continue;
- }
- CurrentBlock = &CurrentBlock->Children[i];
- CurrentObject = CurrentBlock->First;
-
- i++;
-
- CurrentLevel++;
- goto CHILDRECURSE;
- }
- }
- }
-
- // Now lets go back to the parent so it can continue processing its other children.
- if (CurrentBlock->Parent){
- CurrentBlock = CurrentBlock->Parent;
- CurrentLevel--;
- goto PARENTRECURSE;
- }
- }
- else{
- CurrentBlock = &Blocks[0];
- CurrentLevel = 0;
- CurrentObject = CurrentObject;
- CurrentIndex = 0;
-
- // Other states are already set
- CurrentObject = CurrentBlock->First;
- }
-
-
- if (current_geom && current_index == Index - 1){
- //current_geom = current_geom->next; // next
- current_index = Index;
- return current_geom;
- }
- else for (int i = 0; i < Index; i++){ // this will be verrrrrrry slow
- getGeom(i);
- }*/
-
- //TODO return null;
- }
-
//void dxQuadTreeSpace::add(dxGeom* g){
@Override
void add(DxGeom g){
@@ -205,25 +205,13 @@ public void DESTRUCTOR()
super.DESTRUCTOR();
}
- //dxGeom* dxSAPSpace::getGeom( int i )
- @Override
- public DxGeom getGeom( int i )
- {
- dUASSERT( i >= 0 && i < count, "index out of range" );
- int dirtySize = DirtyList.size();
- if( i < dirtySize )
- return DirtyList.get(i);
- else
- return GeomList.get(i-dirtySize);
- }
-
//void dxSAPSpace::add( dxGeom* g )
@Override
void add( DxGeom g )
{
CHECK_NOT_LOCKED (this);
//dAASSERT(g);
- dUASSERT(g.parent_space == null && g.getNext() == null, "geom is already in a space");
+ dUASSERT(g.parent_space == null, "geom is already in a space");
// add to dirty list
GEOM_SET_DIRTY_IDX( g, DirtyList.size() );
@@ -344,7 +332,7 @@ public void collide( Object data, DNearCallback callback )
// by now all geoms are in GeomList, and DirtyList must be empty
int geom_count = GeomList.size();
- dUASSERT( geom_count == count, "geom counts messed up" );
+ dUASSERT( geom_count == getNumGeoms(), "geom counts messed up" );
// separate all ENABLED geoms into infinite AABBs and normal AABBs
TmpGeomList.clear();//setSize(0);
@@ -59,8 +59,7 @@ public void cleanGeoms()
{
// compute the AABBs of all dirty geoms, and clear the dirty flags
lock_count++;
- //for (dxGeom g=_first; g!=null && (g.gflags & GEOM_DIRTY) != 0; g=g.getNext()) {
- for (DxGeom g: _geoms) {
+ for (DxGeom g : getGeoms()) {
//if ((g._gflags & GEOM_DIRTY) == 0) break;
if (!g.hasFlagDirty()) break;
if (g instanceof DxSpace) {
@@ -82,13 +81,9 @@ public void collide (Object data, DNearCallback callback)
cleanGeoms();
// intersect all bounding boxes
- //for (dxGeom g1=_first; g1!=null; g1=g1.getNext()) {
- for (int i = 0; i < _geoms.size(); i++) {
- DxGeom g1 = _geoms.get(i);
+ for (DxGeom g1 : getGeoms()) {
if (GEOM_ENABLED(g1)){
- //for (dxGeom g2=g1.getNext(); g2!=null; g2=g2.getNext()) {
- for (int j = i+1; j< _geoms.size(); j++ ) {
- DxGeom g2 = _geoms.get(j);
+ for (DxGeom g2=g1.getNext(); g2!=null; g2=g2.getNext()) {
if (GEOM_ENABLED(g2)){
collideAABBs (g1,g2,data,callback);
}
@@ -110,8 +105,7 @@ void collide2 (Object data, DxGeom geom,
geom.recomputeAABB();
// intersect bounding boxes
- //for (dxGeom g=_first; g!=null; g=g.getNext()) {
- for (DxGeom g: _geoms) {
+ for (DxGeom g : getGeoms()) {
if (GEOM_ENABLED(g)){
collideAABBs (g,geom,data,callback);
}
Oops, something went wrong.

0 comments on commit 84fefd2

Please sign in to comment.