Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix bug in removed_shape of zpp_space for when shape arbiter

was present in more than one callbackset, but it's 'present' counter
only decremented once.
  • Loading branch information...
commit 104e30912ab73b4f2356799b91c59cc09593148e 1 parent bd41c04
Luca Deltodesco authored
Showing with 57 additions and 71 deletions.
  1. +56 −70 cx-src/DummyNapeMain.cx
  2. +1 −1  cx-src/zpp_nape/space/Space.cx
View
126 cx-src/DummyNapeMain.cx
@@ -1,86 +1,72 @@
package;
$(import);
import flash.Lib;
+import flash.events.Event;
class DummyNapeMain
{
- static function mains() {
- var s = new Space();
- var b = new Body();
- b.shapes.add(new Polygon(Polygon.box(10, 10, true)));
- b.space = s;
-
- s.step(1/60);
+ static function main()
+ {
+ var space = new Space(new Vec2(0, 400), Broadphase.SWEEP_AND_PRUNE);
+ var debug = new ShapeDebug(1,1);
+ flash.Lib.current.addChild(debug.display);
- var graph = new Graph([b, s]);
- graph.populate(function() {
- var t1 = graph.toString();
- s.clear();
- var p = b.shapes.at(0).castPolygon;
- b.clear();
- p.localVerts.clear();
- Debug.clearObjectPools();
- graph.populate(function () {
- var t2 = graph.toString();
+ var abysst = new CbType();
+ var skele = new CbType();
- throw t1 + "\n\n" + t2;
- });
- });
- }
+ var skeleton = new Body();
+ skeleton.position.setxy(300, 300);
+ var skeletonShape = new Polygon(Polygon.box(50, 50));
+ skeleton.shapes.add(skeletonShape);
+ skeletonShape.cbTypes.add(skele);
+ skeleton.space = space;
- static function main()
- {
- var gp = new GeomPolyList();
- gp.add(new GeomPoly([new Vec2(0, 10), new Vec2(10, 20), new Vec2(30, 40)]));
- gp.add(new GeomPoly([new Vec2(0, 10), new Vec2(10, 20)]));
- trace(gp);
+ var abyss = new Body(BodyType.STATIC, new Vec2(300, 500));
+ abyss.shapes.add(new Polygon(Polygon.box(100, 100), null, new InteractionFilter(0, 0, 1, 1)));
+ abyss.cbTypes.add(abysst);
+ abyss.space = space;
- var str = gp.toString();
- function geomPolyListStringToObject(str:String) {
- var ret = new GeomPolyList();
- str = str.substr(1, str.length - 3);
- var subs = str.split("],");
- for (i in 0...subs.length) {
- var sub = subs[i];
- sub = sub.substr(9, sub.length-10);
- var gp = new GeomPoly();
- var vecs = sub.split("},");
- for (j in 0...vecs.length) {
- var vec = vecs[j];
- vec = vec.substr(1);
- var cmps = vec.split(",");
- gp.push(Vec2.weak(Std.parseFloat(cmps[0]), Std.parseFloat(cmps[1])));
- }
- ret.add(gp);
+ var destroy:Array<Body> = [];
+ function destroyer(_)
+ {
+ while (destroy.length > 0)
+ {
+ destroy.pop().space = null;
}
- return ret;
+ flash.Lib.current.removeEventListener(Event.ENTER_FRAME, destroyer);
}
- trace(geomPolyListStringToObject(gp.toString()));
- return;
- (new haxe.Timer(10)).run = function() {
- var s = new Space();
- for (i in 0...3) {
- var b = new Body();
- for (j in 0...2) {
- b.shapes.add(new Polygon(Polygon.box(10, 10, true)));
- b.translateShapes(Vec2.weak(5, 0));
- }
- b.position.x = i;
- b.position.y = i;
- b.space = s;
- }
- s.step(1/60);
- s.step(1/60);
- s.step(1/60);
- s.step(1/60);
+ function abyssHandler(cb:InteractionCallback)
+ {
+ trace("abyss");
+ destroy.push(cb.int2.castBody);
+ flash.Lib.current.addEventListener(Event.ENTER_FRAME, destroyer);
+ }
- while(s.bodies.length > 0)
- {
- var b = s.bodies.pop();
- b.shapes.at(0).castPolygon.localVerts.clear();
- b.clear();
- }
- s.clear();
+ function skeleHandler(cb)
+ {
+ trace("skele");
+ }
+
+
+ space.listeners.add(new InteractionListener(
+ CbEvent.BEGIN,
+ InteractionType.SENSOR,
+ abysst, CbType.ANY_BODY,
+ abyssHandler
+ ));
+
+ space.listeners.add(new InteractionListener(
+ CbEvent.BEGIN,
+ InteractionType.COLLISION,
+ skele, CbType.ANY_BODY,
+ skeleHandler
+ ));
+
+ (new haxe.Timer(10)).run = function () {
+ space.step(1/30);
+ debug.clear();
+ debug.draw(space);
+ debug.flush();
}
}
}
View
2  cx-src/zpp_nape/space/Space.cx
@@ -668,6 +668,7 @@ class PR(Space) {
var callbackset = PR(Interactor).get(i1,i2);
assert(callbackset!=null,"null callbackset on arbiter deletion?");
callbackset.remove_arb(xarb);
+ xarb.present--;
PR(CbSet).find_all(cb1,cb2,Flag(CbEvent,END),function(listener:PR(InteractionListener)) {
if((listener.itype&xarb.type)!=0 && callbackset.empty_arb(listener.itype)) {
@@ -686,7 +687,6 @@ class PR(Space) {
}
});
});
- xarb.present--;
assert(xarb.present>=0, "xarb present < 0?");
}
Please sign in to comment.
Something went wrong with that request. Please try again.