Game Development Reference
In-Depth Information
private void AsynchronousPolling()
{
while (_context.Created)
{
The AutoResetEvent.WaitOne() method is used to pause thread execution until it
receives a notification event (in this case the mouse state changing).
_eventTrigger.WaitOne(-1, false);
try
{
if (_device == null)
{
continue;
}
The next line retrieves the current mouse state.
_device.Poll();
}
catch (InputException)
{
continue;
}
The next two lines are used to asynchronously execute the trigger method that
routes mouse state information back to the client through a registered callback.
if (_context.Created && !_context.Disposing)
_context.BeginInvoke(new PollTriggerDelegate(PollTrigger));
}
}
The following code shows the trigger logic that gets the current mouse informa-
tion and sends it to the user event.
private void PollTrigger()
{
if (MouseMovement != null)
{
MouseState stateData = _device.CurrentMouseState;
_buttons = stateData.GetMouseButtons();
Search Nedrilad ::




Custom Search