Right now we haven't abstracted messages out into the sample project. Basically all the current messages are engine-specific.
For now you just modify the engine directly. This will be very quick and easy, but when you integrate with future versions of the engine you will have to make sure to merge your stuff in properly. There should be a message enum in MessageType.cs in the messaging folder. Just add a new enum value for each message you'd like to make.
The messages are processed by QSGame, in QSGame.cs. This is the lowest level of the engine, it sits right on top of XNA's 'Game' class.
Making a message 'work' is easy enough, you just create an instance of a message, with the template type of whatever you'd like (e.g. Vector3), and then make sure to set the MessageType to your enum value. Then wherever that message is received you'll know to look for the same template type. For example, in the code below you can see that the template type is 'GameTime', and message's type is MessageType.BeginPhysicsFrame. Now wherever I listen for BeginPhysicsFrame I know I'll be receiving GameTime as my messages 'Data'.
- Code: Select all
// *** Here is the message being sent ***
Message<GameTime> msgBeginFrame = ObjectPool.Aquire<Message<GameTime>>();
msgBeginFrame.Type = MessageType.BeginPhysicsFrame;
msgBeginFrame.Data = gameTime;
this.game.SendInterfaceMessage(msgBeginFrame, InterfaceType.Physics);
- Code: Select all
// *** Here is the message being received ***
case MessageType.BeginPhysicsFrame:
{
Message<GameTime> msgBeginFrame = message as Message<GameTime>;
if (msgBeginFrame == null)
{
throw new ArgumentException("Passed message was not a Message<GameTime> message");
}
// Begin next physics frame.
this.physicsScene.BeginFrame(msgBeginFrame.Data); // <--- Data is of the type 'GameTime'
}
return true;