TX/Tutorials and Guides/TX UserGuide/Event System
From TDN
|
[edit] OverviewTorque X defines it's own event system, complete with it's own event manager (TorqueEventManger) and event class (TorqueEvent). You might be wondering why we created our own event system when .NET has a quite powerful event system built in. The answer is that we couldn't find a way to drive the .NET event system without a fair amount of memory churn (and we trigger events for every time update and every input event). We also liked the idea of having finer control over the event stream, allowing us to implement journaling for debug purposes. The Torque event system let's you listen to the events of your choice in a manner very similar to .NET events. For example, to receive a callback for every mouse input event, you'd add the following lines of code: TorqueEventManager.ListenEvents(TorqueInputDevice.MouseEvent, processMouseEvent); where processMouseEvent is your delegate for processing the event and TorqueInputDevice.MouseEvent is a static property which exposes an event. In most case, you will not be listening to events. The one event that might be of interest is the TorqueEngineComponent.Instance.PumpEvent. This is an event which is triggered every time through the time loop. If you add a system to your game which needs processing resources on a regular basis, instead of modifying the main loop you can simply subscribe to the pump event. |



