Example #1
0
        public void AddController(Controller controller)
        {
            Debug.Assert(!ControllerList.Contains(controller), "You are adding the same controller more than once.");

            controller.World = this;
            ControllerList.Add(controller);

            ControllerAdded?.Invoke(controller);
        }
Example #2
0
        private void ProcessAddedItems()
        {
            //Add any new geometries
            for (int i = 0; i < geomAddList.Count; i++)
            {
                if (!geomList.Contains(geomAddList[i]))
                {
                    geomAddList[i].isRemoved = false;
                    geomList.Add(geomAddList[i]);

                    //Add the new geometry to the broad phase collider.
                    _broadPhaseCollider.Add(geomAddList[i]);
                }
            }
            geomAddList.Clear();

            //Add any new bodies
            for (int i = 0; i < bodyAddList.Count; i++)
            {
                if (!bodyList.Contains(bodyAddList[i]))
                {
                    bodyList.Add(bodyAddList[i]);
                }
            }
            bodyAddList.Clear();

            //Add any new controllers
            for (int i = 0; i < controllerAddList.Count; i++)
            {
                if (!controllerList.Contains(controllerAddList[i]))
                {
                    controllerList.Add(controllerAddList[i]);
                }
            }
            controllerAddList.Clear();

            //Add any new joints
            for (int i = 0; i < jointAddList.Count; i++)
            {
                if (!jointList.Contains(jointAddList[i]))
                {
                    jointList.Add(jointAddList[i]);
                }
            }
            jointAddList.Clear();

            //Add any new springs
            for (int i = 0; i < springAddList.Count; i++)
            {
                if (!springList.Contains(springAddList[i]))
                {
                    springList.Add(springAddList[i]);
                }
            }
            springAddList.Clear();
        }
Example #3
0
        public void RemoveController(Controller controller)
        {
            Debug.Assert(ControllerList.Contains(controller),
                         "You are removing a controller that is not in the simulation.");

            if (ControllerList.Contains(controller))
            {
                ControllerList.Remove(controller);

                ControllerRemoved?.Invoke(controller);
            }
        }
        /// <summary>
        /// Processes the added geometries, springs, joints, bodies and controllers.
        /// </summary>
        private void ProcessAddedItems()
        {
            //Add any new geometries
            _tempCount = _geomAddList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                if (!GeomList.Contains(_geomAddList[i]))
                {
                    _geomAddList[i].InSimulation = true;
                    GeomList.Add(_geomAddList[i]);

                    //Add the new geometry to the broad phase collider.
                    _broadPhaseCollider.Add(_geomAddList[i]);
                }
            }
            _geomAddList.Clear();

            //Add any new bodies
            _tempCount = _bodyAddList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                if (!BodyList.Contains(_bodyAddList[i]))
                {
                    BodyList.Add(_bodyAddList[i]);
                }
            }
            _bodyAddList.Clear();

            //Add any new controllers
            _tempCount = _controllerAddList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                if (!ControllerList.Contains(_controllerAddList[i]))
                {
                    ControllerList.Add(_controllerAddList[i]);
                }
            }
            _controllerAddList.Clear();

            //Add any new joints
            _tempCount = _jointAddList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                if (!JointList.Contains(_jointAddList[i]))
                {
                    JointList.Add(_jointAddList[i]);
                }
            }
            _jointAddList.Clear();

            //Add any new springs
            _tempCount = _springAddList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                if (!SpringList.Contains(_springAddList[i]))
                {
                    SpringList.Add(_springAddList[i]);
                }
            }
            _springAddList.Clear();
        }