Emesary: Difference between revisions

Jump to navigation Jump to search
1,921 bytes added ,  11 May 2016
Line 62: Line 62:


The multiplayer bridge allows notifications to be routed over MP. The model creates an incoming bridge specifying the notifications that are to be received and the bridge will messages from multiplayer models. The elegance of the bridge is that neither the sender nor the receiver need to know about each other; all notifications just appear in the recipient method where they can be handled. Each aircraft would have one (or more recipients) and just handle the incoming message.
The multiplayer bridge allows notifications to be routed over MP. The model creates an incoming bridge specifying the notifications that are to be received and the bridge will messages from multiplayer models. The elegance of the bridge is that neither the sender nor the receiver need to know about each other; all notifications just appear in the recipient method where they can be handled. Each aircraft would have one (or more recipients) and just handle the incoming message.
Create an incoming and outgoing in a model with the following lines.
<syntaxhighlight lang="nasal">
var routedNotifications = [notifications.GeoEventNotification.new(nil)];
var outgoingBridge =
emesary_mp_bridge.OutgoingMPBridge.new("F-15mp",routedNotifications);
var incomingBridge =
emesary_mp_bridge.IncomingMPBridge.startMPBridge(routedNotifications);
</syntaxhighlight>
then any GeoEventNotification will arrive via MP and the transmitter in
any registered recipients, ready for handling like this
<syntaxhighlight lang="nasal">
var EmesaryRecipient =
{
    new: func(_ident)
    {
        var new_class = emesary.Recipient.new(_ident);
        new_class.Receive = func(notification)
        {
            if (notification.NotificationType == "GeoEventNotification")
            {
                print("received GeoNotification from
",notification.Callsign);
                print ("
pos=",notification.Position.lat(),notification.Position.lon(),notification.Position.alt());
                print ("  kind=",notification.Kind, "
skind=",notification.SecondaryKind);
                if(notification.FromIncomingBridge)
                {
                    if(notification.Kind == 1)# created
                    {
                        if(notification.SecondaryKind >= 48 and
notification.SecondaryKind <= 63)
                        {
                            # TBD: animate drop tanks
                        }
                    }
                }
                return emesary.Transmitter.ReceiptStatus_OK;
            }
            return emesary.Transmitter.ReceiptStatus_NotProcessed;
        };
        new_class.Response =
ANSPN46ActiveResponseNotification.new("ARA-63");
        return new_class;
    },
};
#
#
# Instantiate receiver.
var recipient = EmesaryRecipient.new("F-15-recipient");
emesary.GlobalTransmitter.Register(recipient);</syntaxhighlight>


<references/>
<references/>

Navigation menu