|
Class dxInput wraps the mouse, keyboard and joystick functionality of DirectInput. It also provides for input capture and replay, and has a slightly better random number generator than the standard C one. It should be used to generate ALL of the input information that goes into a unique game session - when you use dxInput to capture a game session, it will store to file the mouse and key states for every update, as well as the current random generator seed, so everything can be reproduced exactly (so long as the game itself remembers the original positions and states of all the objects). IMPORTANT: dxInput extends the Singleton class. The Singleton class ensures that only a single instance of dxInput ever gets used. This imposes some restrictions on how to obtain a pointer to the input object --
|
|
|
| For the mouse button functions, 0 is the left mouse button, 1 the right, 2 usually the middle.. |
|
///////////////////////////////////////////////////////////////////////// BOOL KeyDown( BYTE key ) { return m_keyDown[key]; } BOOL IsKeyboardAcquired() { return m_bKeyboardAcquired; }
INT MouseDX() { return m_mouseDX; } BOOL MouseButtonDown( INT button ) { return m_bMouseButDown[button]; } BOOL IsMouseAcquired() { return m_bMouseAcquired; } |
|
Capture and replay... When replaying a capture file, the dxInput::Update() function just takes input states from the file instead of polling the mouse and keyboard. When you're capturing, AppendInputState should be called every tick. |
|
///////////////////////////////////////////////////////////////////////// BOOL AppendInputState(); // add state to current capture VOID StartCapture(); BOOL SaveCaptureFile( LPSTR filename );
BOOL LoadCaptureFile( LPSTR filename );
|
|
GetLapTimerInstance returns a "lap timer" on the main game timer. Take a look at the dxLapTimer class - all it does is give elapsed times, based on the value of its "parent" timer. When possible, use a lap timer instead of a regular one, since they don't need to poll the performance timer on the motherboard. GetLastFrameTime returns the, umm, last frame time. The main game loop handles the updating of this value, so never pass TRUE to it. |
|
///////////////////////////////////////////////////////////////////////// VOID StartGameTimer() { m_gameTimer.Start(); } dxLapTimer* GetLapTimerInstance(){ return new dxLapTimer( &m_gameTimer ); } DOUBLE GetLastFrameTime( BOOL bUpdate = FALSE ) { |
|
GetRand returns a random number between 0.0 and 1.0, inclusive. GetRandInt returns a random integer between min and max, inclusive. dxInput will seed itself. |
|
///////////////////////////////////////////////////////////////////////// DOUBLE GetRand(); |