bw logo

Chapter 5. Asynchronous and Ghost Cell Considerations

5.1. Entering the world

When using the board / alight vehicle mechanism, the passenger's position is defined in terms of the vehicle. As a result, passengers will always enter the world after the vehicle. To allow the vehicle to correctly handle this, we require some form of notification of the passenger's entry into the world.

The excerpt below illustrates how to achieve this:

# This function is called by avatar when it enters the world.
def passengerEnterWorld( self, pilot ):
    pilot.model.visible = False
    pilot.model.motors[0].entityCollision = False
    if self.model.mount == None:
        pilotModel = pilot.model
        pilotModel.tracker = None
        pilot.model = makeModel( pilot.modelNumber, None )
        pilot.model.visible = False
        self.model.mount = pilotModel
        self.model.mount.RipperPilotIdle()
        self.model.mount.visible = True
        pilot.targetCaps = []

client/Ripper.py

5.2. Observing avatars interacting with vehicles

Communication with third parties is done via the vehicle's cell. To do this, have the vehicle cell broadcast any state-changing responses to self.allClients, with the ID of the affected avatar as a parameter.

def passengerBoarded( self, sourceAvatarID ):
    # Notify all clients about the Ripper being mounted.
    self.allClients.mountVehicle( True, sourceAvatarID )

client/Ripper.py

Remember that third parties might not have both the vehicle and its passengers in their area of interest, and so the ID might not be immediately resolvable into an entity. To handle this situation, the avatar should notify vehicles they are riding when they themselves enter the world. The passenger will never enter the world before their vehicle, as its position is known only relative to the former.