void DeleteEntityNotificationHandler(simengine.DeleteSimulationEntity del)
 {
     _entity = null;
 }
        /// <summary>
        /// Called the first time the simulation engine tells us about our entity.  Activate
        /// the other handlers and insert ourselves into the service directory.
        /// </summary>
        /// <param name="ins"></param>
        void InsertEntityNotificationHandlerFirstTime(simengine.InsertSimulationEntity ins)
        {
            InsertEntityNotificationHandler(ins);

            base.Start();

            MainPortInterleave.CombineWith(
                new Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive<simengine.InsertSimulationEntity>(true, _notificationTarget, InsertEntityNotificationHandler),
                        Arbiter.Receive<simengine.DeleteSimulationEntity>(true, _notificationTarget, DeleteEntityNotificationHandler)
                    ),
                    new ConcurrentReceiverGroup()
                )
            );
        }
        void InsertEntityNotificationHandler(simengine.InsertSimulationEntity ins)
        {
            _entity = (PioneerGPSEntity)ins.Body;
            _entity.ServiceContract = Contract.Identifier;

            CreateDefaultState();
        }
        void InsertEntityNotificationHandler(simengine.InsertSimulationEntity ins)
        {
            // _entity = (simengine.BumperArrayEntity)ins.Body;
            _entity = (PioneerBumperEntity)ins.Body;
            _entity.ServiceContract = Contract.Identifier;

            // reinitialize the state
            CreateDefaultState();

            pxContactSensor.ContactSensor cs = null;

            // The simulation bumper service uses a simple heuristic to assign contact sensors, to physics shapes:
            // Half the sensors go infront, the other half in the rear. Assume front sensors are first in the list
            // In the for loop below we create a lookup table that matches simulation shapes with sensors. When
            // the physics engine notifies us with a contact, it provides the shape that came into contact. We need to
            // translate that to sensor. In the future we might add an object Context field to shapes to make this easier
            for (int i = 0; i < _entity.Shapes.Length; i++)
            {
                cs = new pxContactSensor.ContactSensor();
                cs.Name = _entity.Shapes[i].State.Name;
                cs.HardwareIdentifier = i;
                _state.Sensors.Add(cs);
                _bumperShapeToSensorTable.Add((physics.BoxShape)_entity.Shapes[i], cs);
            }

            // subscribe to bumper simulation entity for contact notifications
            _entity.Subscribe(_contactNotificationPort);
            // Activate a handler on the notification port, it will run when contacts occur in simulation
            Activate(Arbiter.Receive(false, _contactNotificationPort, PhysicsContactNotificationHandler));
        }