From 5a65e6dfd23d8c6181e276fdc9967ff290e36a6b Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Fri, 28 Oct 2016 07:29:25 +0300 Subject: [PATCH] arbiter is a struct now --- b2dlite.d | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/b2dlite.d b/b2dlite.d index 3b49c66..fa47d94 100644 --- a/b2dlite.d +++ b/b2dlite.d @@ -89,9 +89,8 @@ private Vec2 fcross() (VFloat s, in auto ref Vec2 a) { pragma(inline, true); ret public final class World { private: static struct ArbiterKey { - // pointers, actually - BodyBase body0; - BodyBase body1; + BodyBase body0, body1; + this (BodyBase b0, BodyBase b1) { if (b0 < b1) { body0 = b0; body1 = b1; } else { body0 = b1; body1 = b0; } } bool opEquals() (in auto ref ArbiterKey b) const { @@ -147,14 +146,6 @@ public: static bool positionCorrection = true; public: - void drawBVH (scope void delegate (Vec2 min, Vec2 max) dg) { - version(b2dlite_use_bvh) { - bvh.forEachLeaf((int nodeId, in ref AABB aabb) { - dg(aabb.mMin, aabb.mMax); - }); - } - } - this() (in auto ref Vec2 agravity, int aiterations) { gravity = agravity; iterations = aiterations; @@ -196,13 +187,13 @@ public: b.angularVelocity += dt*b.invI*b.torque; } // perform pre-steps - foreach (Arbiter arb; arbiters.byValue) { + foreach (ref Arbiter arb; arbiters.byValue) { if (arb.frameNum == frameNum && arb.active) arb.preStep(invDt); } foreach (Joint j; joints) j.preStep(invDt); // perform iterations foreach (immutable itnum; 0..iterations) { - foreach (Arbiter arb; arbiters.byValue) { + foreach (ref Arbiter arb; arbiters.byValue) { if (arb.frameNum == frameNum && arb.active) arb.applyImpulse(); } foreach (Joint j; joints) j.applyImpulse(); @@ -230,7 +221,7 @@ public: if (auto arb = ak in arbiters) { if (arb.frameNum != frameNum) arb.setup(bi, bj, frameNum); } else { - arbiters[ak] = new Arbiter(bi, bj, frameNum); + arbiters[ak] = Arbiter(bi, bj, frameNum); } }); } @@ -242,12 +233,20 @@ public: if (auto arb = ArbiterKey(bi, bj) in arbiters) { arb.setup(bi, bj, frameNum); } else { - arbiters[ArbiterKey(bi, bj)] = new Arbiter(bi, bj, frameNum); + arbiters[ArbiterKey(bi, bj)] = Arbiter(bi, bj, frameNum); } } } } } + + void drawBVH (scope void delegate (Vec2 min, Vec2 max) dg) { + version(b2dlite_use_bvh) { + bvh.forEachLeaf((int nodeId, in ref AABB aabb) { + dg(aabb.mMin, aabb.mMax); + }); + } + } } @@ -669,7 +668,7 @@ public: // ////////////////////////////////////////////////////////////////////////// // -private final class Arbiter { +private struct Arbiter { public: enum MaxContactPoints = 2; @@ -679,18 +678,15 @@ public: Contact[MaxContactPoints] contacts; int numContacts; - BodyBase body0; - BodyBase body1; - - // combined friction - VFloat friction; - + BodyBase body0, body1; + VFloat friction; // combined friction uint frameNum; // used to track "frame touch" public: - this () {} this (BodyBase b0, BodyBase b1, int aFrameNum) { setup(b0, b1, frameNum); } + @disable this (this); + void clear () { numContacts = 0; } @property bool active () { return (numContacts > 0); } -- 2.11.4.GIT