コード例 #1
0
        public cpPostStepCallback GetPostStepCallback(object key)
        {
            List <cpPostStepCallback> arr = postStepCallbacks;

            for (int i = 0; i < arr.Count; i++)
            {
                cpPostStepCallback callback = arr[i];
                if (callback != null && callback.key == key)
                {
                    return(callback);
                }
            }

            return(null);
        }
コード例 #2
0
        public void Unlock(bool runPostStep)
        {
            this.locked--;
            cp.AssertHard(this.locked >= 0, "Internal Error: Space lock underflow.");

            if (this.locked == 0)
            {
                List <cpBody> waking = this.rousedBodies;

                for (int i = 0, count = waking.Count; i < count; i++)
                {
                    this.ActivateBody(waking[i]);
                    waking[i] = null;
                }

                waking.Clear();
                this.rousedBodies.Clear();

                if (this.locked == 0 && runPostStep && !this.skipPostStep)
                {
                    this.skipPostStep = true;

                    List <cpPostStepCallback> arr = this.postStepCallbacks;
                    for (int i = 0; i < arr.Count; i++)
                    {
                        cpPostStepCallback callback = (cpPostStepCallback)arr[i];
                        var func = callback.func;

                        // Mark the func as NULL in case calling it calls cpSpaceRunPostStepCallbacks() again.
                        // TODO: need more tests around this case I think.
                        callback.func = null;
                        if (func != null)
                        {
                            func(this, callback.key, callback.data);
                        }

                        arr[i] = null;
                    }
                    this.postStepCallbacks.Clear();
                    this.skipPostStep = false;
                }
            }
        }
コード例 #3
0
        public bool AddPostStepCallback(cpPostStepFunc func, object key, object data)
        {
            //cpPostStepCallback func
            cp.AssertSoft(this.IsLocked,
                          "Adding a post-step callback when the space is not locked is unnecessary. " +
                          "Post-step callbacks will not called until the end of the next call to cpSpaceStep() or the next query.");


            if (GetPostStepCallback(key) == null)
            {
                cpPostStepCallback callback = new cpPostStepCallback();                // (cpPostStepCallback*)cpcalloc(1, sizeof(cpPostStepCallback));
                callback.func = (func != null ? func : PostStepDoNothing);
                callback.key  = key;
                callback.data = data;
                this.postStepCallbacks.Add(callback);
                return(true);
            }
            else
            {
                return(false);
            }
        }