コード例 #1
0
ファイル: cpSpaceComponent.cs プロジェクト: tarnas14/AgarIo
        public void DeactivateBody(cpBody body)
        {
            cp.AssertHard(body.bodyType == cpBodyType.DYNAMIC, "Internal error: Attempting to deactivate a non-dynamic body.");

            this.dynamicBodies.Remove(body);

            body.eachShape((shape, o) =>
            {
                this.dynamicShapes.Remove(shape.hashid);
                this.staticShapes.Insert(shape.hashid, shape);
            }, null);


            body.eachArbiter((arb, o) =>
            {
                var bodyA = arb.body_a;

                if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                {
                    this.UncacheArbiter(arb);
                }
            }, null);


            body.eachConstraint((constraint, o) =>
            {
                var bodyA = constraint.a;
                if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                {
                    this.constraints.Remove(constraint);
                }
            }, null);
        }
コード例 #2
0
ファイル: cpSpaceComponent.cs プロジェクト: tarnas14/AgarIo
        public void ActivateBody(cpBody body)
        {
            cp.AssertHard(body.bodyType == cpBodyType.DYNAMIC, "Internal error: Attempting to deactivate a non-dynamic body.");

            if (this.IsLocked)
            {
                // cpSpaceActivateBody() is called again once the space is unlocked
                if (!this.rousedBodies.Contains(body))
                {
                    this.rousedBodies.Add(body);
                }
            }
            else
            {
                cp.AssertSoft(body.nodeRoot == null &&
                              body.nodeNext == null, "Internal error: Activating body non-NULL node pointers.");


                this.dynamicBodies.Add(body);

                body.eachShape((s, o) =>
                {
                    this.staticShapes.Remove(s.hashid);
                    this.dynamicShapes.Insert(s.hashid, s);
                }, null);


                body.eachArbiter((arb, o) =>
                {
                    cpBody bodyA = arb.body_a;

                    // Arbiters are shared between two bodies that are always woken up together.
                    // You only want to restore the arbiter once, so bodyA is arbitrarily chosen to own the arbiter.
                    // The edge case is when static bodies are involved as the static bodies never actually sleep.
                    // If the static body is bodyB then all is good. If the static body is bodyA, that can easily be checked.
                    if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                    {
                        cpShape a = arb.a, b = arb.b;
                        this.cachedArbiters.Add(cp.CP_HASH_PAIR(a.hashid, b.hashid), arb);

                        // Update the arbiter's state
                        arb.stamp   = this.stamp;
                        arb.handler = this.LookupHandler(a.type, b.type, defaultHandler);
                        this.arbiters.Add(arb);
                    }
                }, null);

                body.eachConstraint((constraint, o) =>
                {
                    var bodyA = constraint.a;
                    if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                    {
                        this.constraints.Add(constraint);
                    }
                }, null);
            }
        }
コード例 #3
0
ファイル: cpSpaceComponent.cs プロジェクト: kfazi/AgarIo
        public void ActivateBody(cpBody body)
        {
            cp.AssertHard(body.bodyType == cpBodyType.DYNAMIC, "Internal error: Attempting to deactivate a non-dynamic body.");

            if (this.IsLocked)
            {
                // cpSpaceActivateBody() is called again once the space is unlocked
                if (!this.rousedBodies.Contains(body))
                    this.rousedBodies.Add(body);
            }
            else
            {

                cp.AssertSoft(body.nodeRoot == null &&
                    body.nodeNext == null, "Internal error: Activating body non-NULL node pointers.");

                this.dynamicBodies.Add(body);

                body.eachShape((s, o) =>
                {
                    this.staticShapes.Remove(s.hashid);
                    this.dynamicShapes.Insert(s.hashid, s);
                }, null);

                body.eachArbiter((arb, o) =>
                {
                    cpBody bodyA = arb.body_a;

                    // Arbiters are shared between two bodies that are always woken up together.
                    // You only want to restore the arbiter once, so bodyA is arbitrarily chosen to own the arbiter.
                    // The edge case is when static bodies are involved as the static bodies never actually sleep.
                    // If the static body is bodyB then all is good. If the static body is bodyA, that can easily be checked.
                    if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                    {
                        cpShape a = arb.a, b = arb.b;
                        this.cachedArbiters.Add(cp.CP_HASH_PAIR(a.hashid, b.hashid), arb);

                        // Update the arbiter's state
                        arb.stamp = this.stamp;
                        arb.handler = this.LookupHandler(a.type, b.type, defaultHandler);
                        this.arbiters.Add(arb);
                    }

                }, null);

                body.eachConstraint((constraint, o) =>
                {
                    var bodyA = constraint.a;
                    if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                        this.constraints.Add(constraint);

                }, null);

            }
        }
コード例 #4
0
ファイル: cpSpaceComponent.cs プロジェクト: kfazi/AgarIo
        public void DeactivateBody(cpBody body)
        {
            cp.AssertHard(body.bodyType == cpBodyType.DYNAMIC, "Internal error: Attempting to deactivate a non-dynamic body.");

            this.dynamicBodies.Remove(body);

            body.eachShape((shape, o) =>
                {
                    this.dynamicShapes.Remove(shape.hashid);
                    this.staticShapes.Insert(shape.hashid, shape);
                }, null);

            body.eachArbiter((arb, o) =>
            {

                var bodyA = arb.body_a;

                if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                {
                    this.UncacheArbiter(arb);
                }

            }, null);

            body.eachConstraint((constraint, o) =>
            {
                var bodyA = constraint.a;
                if (body == bodyA || bodyA.bodyType == cpBodyType.STATIC)
                    this.constraints.Remove(constraint);

            }, null);
        }