UE4 Twitch 2016 05-05: Unreal Message Bus Overview
Click here to load reader
-
Upload
gerke-max-preussner -
Category
Software
-
view
471 -
download
15
Transcript of UE4 Twitch 2016 05-05: Unreal Message Bus Overview
Process
MessageEndpoints
Message Bus
Message Bus:Framework for exchanging commands, events, documents, or any other data
inside UStructs between endpoints
USTRUCT()struct FHelloMessage{ GENERATED_BODY()
UPROPERTY(EditAnywhere, Category=“Message”) FString HelloText;
FHelloMessage(const FString& InText) : HelloText(InText) { }};
Declare a message type (you can also use any existing UStruct, such as FVector or FColor)
Process
SenderEndpoint = FMessageEndpoint::Builder(“FMySender”, MessageBus);
ReceiverEndpoint = FMessageEndpoint::Builder(“FMyReceiver”, MessageBus) .Handling<FHelloMessage>(this, &FMyReceiver::HandleHelloMessage);
Create a sender endpoint
Create a receiver endpoint
Message Endpoints:Helper classes for sending and receiving
messages on the message bus
Process
Subscribers
Publisher
SenderEndpoint = FMessageEndpoint::Builder(“FMySender”, MessageBus);
ReceiverEndpoint = FMessageEndpoint::Builder(“FMyReceiver”, MessageBus) .Handling<FHelloMessage>(this, &FMyReceiver::HandleHelloMessage);
if (ReceiverEndpoint.IsValid()){ ReceiverEndpoint->Subscribe<FHelloMessage>();}
SenderEndpoint.Publish(new FHelloMessage(TEXT(“Hey there!”)));
void FMyReceiver::HandleHelloMessage(const FHelloMessage& Message, const TSharedRef<IMessageContextRef>& Context){ GLog->Log(*Message.HelloText); // prints “Hey there!” }
Subscribe receiver to FHelloMessage messages
Publish a message to all subscribers
Handle received FHelloMessage
Publish-Subscribe:Messages are sent to all endpoints that
subscribed to that message type
Process
Responder
Requester
SenderEndpoint = FMessageEndpoint::Builder(“FMySender”, MessageBus);
ReceiverEndpoint = FMessageEndpoint::Builder(“FMyReceiver”, MessageBus) .Handling<FHelloMessage>(this, &FMyReceiver::HandleHelloMessage);
if (ReceiverEndpoint.IsValid()){ ReeiverEndpoint->Subscribe<FHelloMessage>();}
SenderEndpoint.Publish(new FHelloMessage(TEXT(“Hey there!”)));
void FMyReceiver::HandleHelloMessage(const FHelloMessage& Message, const TSharedRef<IMessageContextRef>& Context){ SenderEndpoint->Send(new FReplyMessage(TEXT(“O hai!”)), Context->GetSender());}
Send back a response
Request-Response:Messages are sent directly to one or more
recipients using their message address
Process Process
Message Bridge
Message Bridges:Connect two message buses in separate processes via some transport technology
Process Process
UDPTCP
HTTPNamed PipesShared Mem
ZeroMQRabbitMQ
etc.
Message Bridges:Connect two message buses in separate processes via some transport technology
Computer
Computer
Computer
Process Process Process
Process
Internet(via Message Tunnel)
UE4 Instance3DStudio MaxMayaBuild FarmHardware I/Oetc.
The following slides explain UE4’s layered architecture for device managementas a more complex example use case for how the Messaging system can be usedto simplify the process of writing distributed applications.
The diagrams show how the same code architecture is being used to support anumber of different hardware configurations.
The last slide shows how the function calls flow through the various layers. Notethat some of this code has changed over the course of the last year. The intent isto demonstrate how interprocess communication can be implemented, and howfunction calls change to messages and back to function calls.
Use
r PC
Host
PC
ITargetDevice
ITargetDeviceService
ITargetDeviceProxy
Devi
ce
Application
Platform specific interfaces
Platform agnostic interfaces
Physical Tier
Legend:
Target Device ManagementUses a multi-layered multi-tier
architecture instead of having the application talk directly to the devices
MessageBus
Platform SDK
Devi
ce Daemon
Use
r PC
Host
PC
ITargetDevice
ITargetDeviceService
ITargetDeviceProxy
MessageBus
IPP
Application
Message Bus
Use
r PC
Host
PC
ITargetDevice
ITargetDeviceService
ITargetDeviceProxy
Devi
ce
Application
Platform specific interfaces
Platform agnostic interfaces
Physical Tier
Legend:
• Target devices are usually connectedto some host computer and communicatevia some platform SDK
Example: XBoxOne, PS4
• Some target devices can be deployed towithout a host computer if they have anetwork connection
Example: Windows, Mac, iPad, iPhone
MessageBus
Platform SDK
Use
r / H
ost P
C
ITargetDevice
ITargetDeviceService
ITargetDeviceProxy
Devi
ce
MessageBus
Platform SDK
Application
Use
r PC
Host
PC
/ Dev
ice
ITargetDevice
ITargetDeviceService
ITargetDeviceProxy
MessageBus
Application
Use
r PC
/ Hos
t PC
/ Dev
ice
ITargetDevice
ITargetDeviceService
ITargetDeviceProxy
MessageBus
Application
Use
r PC
Host
PC
ITargetDevice
ITargetDeviceService
ITargetDeviceProxy
Devi
ce
MessageBus
Platform SDK
Application
• Target device is another computer
Example: Deploying to another PC
• Target device is the local computer
Example: Deploying to your own PC
• Target device is another deviceconnected to the local PC
Example: iPhone, iPad on yourown computer
• Target device is another deviceconnected to another PC
Example: iPhone, iPad on someoneelse’s computer
Application ILauncher
Launch()
FLauncherWorker
Run()
ITargetDeviceProxy
PerformTask()
FLauncherDeployToDeviceTask
DeployApp(TransactionId)
ITargetDeviceService
targetdevice.deploy.file
targetdevice.deploy.commit
ITargetDevice
LocalFile
Cache
Deploy(Directory)
IPP iOS Device
Copy FilesDeploy Files
targetdevice.deploy.finished (AppId)
OnDeployCommitted(TransactionId, AppId)
Deploy
Launch
FLauncherLaunchTask
PerformTask()LaunchApp(AppId)
targetdevice.launchLaunch(AppId)
Launch Daemon
iosdaemon.launch [Url]
iosdaemon.launch .successtargetdevice.launch.finished
return AppId DeviceFile
System
Message Bus
Function Call
Vendor Specific
Legend: