#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_INPUT_DEVICES_DIRECTINPUTGAMEPAD_H #define NUCLEX_INPUT_DEVICES_DIRECTINPUTGAMEPAD_H #include "Nuclex/Input/Devices/GamePad.h" #include "../../ConcurrentQueue.h" #include #define DIRECTINPUT_VERSION 0x800 #include // --------------------------------------------------------------------------------------------- // /// Smart pointer for the main DirectInput8 interface _COM_SMARTPTR_TYPEDEF(IDirectInput8, IID_IDirectInput8); /// Smart pointer for a DirectInputDevice8 _COM_SMARTPTR_TYPEDEF(IDirectInputDevice8, IID_IDirectInputDevice8); // --------------------------------------------------------------------------------------------- // namespace Nuclex { namespace Input { namespace Devices { // ------------------------------------------------------------------------------------------- // /// Implements a game pad on top of the DirectInput API class DirectInputGamePad : public GamePad { /// Initializes a new DirectInput game pad for the specified player /// /// DirectInput interface the game pad will be constructed with /// /// Device this game pad will query data from public: DirectInputGamePad( const IDirectInput8Ptr &directInput, const DIDEVICEINSTANCE &deviceInstance ); /// Releases all resources owned by the instance public: virtual ~DirectInputGamePad(); /// Whether the input device is currently attached /// True if the input device is attached, otherwise false public: bool IsAttached() const { return true; } /// Retrieves the human-readable name of the input device /// The human-readable name of the input device public: const std::string &GetName() const { return this->name; } /// Retrieves the current state of the input device /// The input device's current state public: const GamePadState &GetState() const { return *this->currentState; } /// Updates the state of the input device protected: void Update(); /// Takes a snapshot of the input device's current state protected: void TakeSnapshot(); /// Removes all snapshots the device has taken protected: void ClearSnapshots(); /// Builds the mappers from device objects to the game pad state private: void buildMappers(); private: DirectInputGamePad(const DirectInputGamePad &); private: DirectInputGamePad &operator =(const DirectInputGamePad &); /// Current state of the game pad in our own structure private: GamePadState *currentState; /// Snapshots that have been recorded for the game pad private: ConcurrentQueue snapshots; /// Pool containing already allocated snapshots private: ConcurrentQueue pool; /// The name of this game pad private: std::string name; /// DirectInput interface the device was constructed by private: IDirectInput8Ptr directInput; /// Direct input device this game pad is querying private: IDirectInputDevice8Ptr directInputDevice; /// Whether the device is currently acquired private: bool isAcquired; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Input::Devices #endif // NUCLEX_INPUT_DEVICES_DIRECTINPUTGAMEPAD_H