deltaluca / nape

Haxe/AS3 Physics Engine
http://napephys.com
Other
542 stars 77 forks source link

Duplicates is not allowed for BodyList #99

Closed T1mL3arn closed 8 years ago

T1mL3arn commented 8 years ago
var body = function(r:Float, x:Float):Body
{
    return new Circle(r).body = new Body(null, Vec2.weak(x, 0));
}

var list = new BodyList();
var b1 = body(5, 0);
var b2 = body(5, 10);
var b3 = body(5, 20);
list.push(b1);
// for NAPE_ASSERT 
// assert(o!=null&&!has(o)) ::  [ListMixin(ZPP_Body] cur -> [object ZNPNode_ZPP_Body] -> [object ZPP_Body]
list.push(b1); 
list.push(b2);
list.push(b3);

trace(list.length);     // 4, duplicates allowed, good!
list.clear();

var space = new Space();
b1.space = space;
b2.space = space;
b3.space = space;

space.bodiesUnderPoint(Vec2.weak(0, 0), null, list);
space.bodiesUnderPoint(Vec2.weak(10, 0), null, list);
space.bodiesUnderPoint(Vec2.weak(12, 0), null, list);   // same body as above
space.bodiesUnderPoint(Vec2.weak(20, 0), null, list);   

trace(list.length);     // 3, WHY ?! :(

Why it is not allowed with assert flag? And why then duplicates are allowed for the release builds?

deltaluca commented 8 years ago

the lists are defined as not allowing duplicates (or should be if not already), but in a release build all assertions are removed to get better performance.

T1mL3arn commented 8 years ago

If duplicates are not allowed, it will be good to find some info about it in the documentation.