Beispiel #1
0
        /// <summary>
        /// Initialize the input devices
        /// </summary>
        private void InitializeInput()
        {
            #region Step 3: Enumerate Devices.
            // ************************************************************************
            // Step 3: Enumerate Devices.
            //
            // Enumerate through devices according to the desired action map.
            // Devices are enumerated in a prioritized order, such that devices which
            // can best be mapped to the provided action map are returned first.
            // ************************************************************************
            #endregion

            // Setup the action format for actual gameplay
            DIActionFormat.ActionMapGuid = AppGuid;
            DIActionFormat.Genre         = (int)FightingHandToHand.FightingHandToHand;
            DIActionFormat.AxisMin       = -99;
            DIActionFormat.AxisMax       = 99;
            DIActionFormat.BufferSize    = 16;
            CreateActionMap(DIActionFormat.Actions);

            try
            {
                // Enumerate devices according to the action format
                DeviceList DevList = Manager.GetDevices(DIActionFormat, EnumDevicesBySemanticsFlags.AttachedOnly);
                foreach (SemanticsInstance instance in DevList)
                {
                    SetupDevice(instance.Device);
                }
            }
            catch (DirectXException ex)
            {
                UserInterface.ShowException(ex, "EnumDevicesBySemantics");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public ActionBasicApp()
        {
            // Instantiate the user interface object. The UI is given the
            // list of game actions and a reference to the DeviceStates array,
            // which the chart will use to display user input.
            UserInterface = new ActionBasicUI(this, ActionNames, DeviceStates);
            UserInterface.Show();

            #region Step 3: Enumerate Devices.
            // ************************************************************************
            // Step 3: Enumerate Devices.
            //
            // Enumerate through devices according to the desired action map.
            // Devices are enumerated in a prioritized order, such that devices which
            // can best be mapped to the provided action map are returned first.
            // ************************************************************************
            #endregion

            // Setup the action format for actual gameplay
            DIActionFormat.ActionMapGuid = AppGuid;
            DIActionFormat.Genre         = (int)FightingHandToHand.FightingHandToHand;
            DIActionFormat.AxisMin       = -99;
            DIActionFormat.AxisMax       = 99;
            DIActionFormat.BufferSize    = 16;
            CreateActionMap(DIActionFormat.Actions);

            try
            {
                // Enumerate devices according to the action format
                DeviceList DevList = Manager.GetDevices(DIActionFormat, EnumDevicesBySemanticsFlags.AttachedOnly);
                foreach (SemanticsInstance instance in DevList)
                {
                    SetupDevice(instance.Device);
                }
            }
            catch (DirectXException ex)
            {
                UserInterface.ShowException(ex, "EnumDevicesBySemantics");
            }

            // Start the input loop
            InputThread = new Thread(new ThreadStart(RunInputLoop));
            InputThread.Start();
        }
Beispiel #3
0
        /// <summary>
        /// Handles device setup
        /// </summary>
        /// <param name="device">DirectInput Device</param>
        private void SetupDevice(Device device)
        {
            // Create a temporary DeviceState object and store device information.
            DeviceState state = new DeviceState();

            device = device;

            #region Step 4: Build the action map against the device
            // ********************************************************************
            // Step 4: Build the action map against the device, inspect the
            //         results, and set the action map.
            //
            // It's a good idea to inspect the results after building the action
            // map against the current device. The contents of the action map
            // structure indicate how and to what object the action was mapped.
            // This sample simply verifies the action was mapped to an object on
            // the current device, and stores the result. Note that not all actions
            // will necessarily be mapped to an object on all devices. For instance,
            // this sample did not request that QUIT be mapped to any device other
            // than the keyboard.
            // ********************************************************************
            #endregion
            try
            {
                // Build the action map against the device
                device.BuildActionMap(DIActionFormat, ActionMapControl.Default);
            }
            catch (DirectXException ex)
            {
                UserInterface.ShowException(ex, "BuildActionMap");
                return;
            }

            // Inspect the results
            foreach (Action action in DIActionFormat.Actions)
            {
                if ((int)action.How != (int)ActionMechanism.Error &&
                    (int)action.How != (int)ActionMechanism.Unmapped)
                {
                    state.IsMapped[(int)action.ApplicationData] = true;
                }
            }

            // Set the action map
            try
            {
                device.SetActionMap(DIActionFormat, ApplyActionMap.Default);
            }
            catch (DirectXException ex)
            {
                UserInterface.ShowException(ex, "SetActionMap");
                return;
            }

            state.Device = device;

            // Store the device's friendly name for display on the chart
            state.Name = device.DeviceInformation.InstanceName;

            // Store axis absolute/relative flag
            state.IsAxisAbsolute = device.Properties.AxisModeAbsolute;

            DeviceStates.Add(state);
            UserInterface.UpdateChart();
            return;
        }