Title: The Input Interface of the Engine
1The Input Interface of the Engine
- Speaker 5JJ, Landon,
- ??, ??,
- Stephen,
- Akira, Roy
2Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
3Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
4Lead in
5Lead in
- As Einstein said, we really should be ashamed if
we are just going to use a technical miracle
without understanding it at all - we are the ones developing this tool, so we
should indeed understand the inner workings of
the tool - This chapter introduces you to DirectInput and
explains how to encapsulate it to abstract the
ZFXEngines input device away from DirectX.
6- This chapter covers the following topics
- Initializing DirectInput
- Implementing a DLL to encapsulate input issues
- Querying the keyboard, mouse, and joystick for
input - Adding a new component to the ZFXEngine
7QA
8Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
9Good Old Interface Design
9
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
10Good Old Interface Design
- In this chapter, we will add another component to
the ZFXEngine. - the static library is called ZFXInput,
- the DLL is called ZFXDI, where DI stands for
DirectInput.
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
10
11Files used for ZFXInput
- ZFXInput.h and ZFXInput.cpp
- ZFXInputDevice.h
- ZFX.h
- ZFX3D.h
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
11
12Files used for ZFXDI
- ZFXDI.def, ZFXDI.h, and ZFXDI.cpp
- ZFXKeyboard.cpp
- ZFXMouse.cpp
- ZFXJoystick.cpp
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
12
13QA
14Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
15Interface Definition for an Input Class
16(No Transcript)
17GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
17
18GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
18
19(No Transcript)
20(No Transcript)
21QA
22Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
23Base Class for Input Devices
24Overview
- The Class ZFXDIDevice
- Creating and Destroying an Input Device
- Making It Run
- Querying the Input
- Q A
25The Class ZFXDIDevice
- The base class of any concrete input devices
- See ZFXDI.h, lines 65 93
26Creating and Destroying an Input Device
- void ZFXDIDeviceCreate( LPDIRECTINPUT8, HWND,
FILE) - ZFXDI.cpp, lines 340 345
- No more than memberwise initialization
- Called by the subclasses constructors
- Why not use the constructor to do this job?
- void ZFXDIDeviceRelease()
- ZFXDI.cpp, lines 352 259
- Release the devices
27Making It Run
- HRESULT ZFXDIDeviceCrankUp( REFGUID,
LPCDIDATAFORMAT) - ZFXDI.cpp, lines 366 395
- 3 steps
- IDirectInput8CreateDevice
- IDirectInputDevice8SetDataFormat
- IDirectInputDevice8SetCooperativeLevel
28Querying the Input
- HRESULT ZFXDIDeviceGetData( ZFXINPUTDEV,
void, DWORD) - ZFXDI.cpp, lines 405 449
- Related functions
- IDirectInputDevice8GetDeviceData
- For mouse
- IDirectInputDevice8GetDeviceState
- For keyboard / joystick
- IDirectInputDevice8Acquire
- While the device is lost or not acquired
29Q A
30Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
31Getting Down to the Keys
31
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
32class ZFXKeyboard public ZFXDIDevice
-
- public
- ZFXKeyboard(LPDIRECTINPUT8, HWND, FILE)
- virtual ZFXKeyboard(void)
- HRESULT Init(void)
- HRESULT Update(void)
- bool IsPressed(UINT nID)
- bool IsReleased(UINT nID)
- private
- char m_Keys256
- char m_KeysOld256
- // class
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
32
33Constructor and Destructor
- ZFXKeyboardZFXKeyboard(LPDIRECTINPUT8 pDI, HWND
hWnd, FILE pLog) - Create(pDI, hWnd, pLog)
- ZFXKeyboardZFXKeyboard(void) Release()
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
33
34HRESULT ZFXKeyboardInit(void)
-
- if (FAILED(CrankUp(GUID_SysKeyboard,
c_dfDIKeyboard))) - return ZFX_FAIL
- // clear memory
- memset(m_Keys, 0, sizeof(m_Keys))
- memset(m_KeysOld, 0, sizeof(m_KeysOld))
- // acquire the device
- m_pDevice-gtAcquire()
- return ZFX_OK
- // Init
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
34
35HRESULT ZFXKeyboardUpdate(void)
-
- memcpy(m_KeysOld, m_Keys, sizeof(m_Keys))
- // query status
- if (FAILED(GetData(IDV_KEYBOARD, m_Keys0,
NULL))) - return ZFX_FAIL
- return ZFX_OK
- // Update
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
35
36Scan Codes
- The DirectInput header dinput.h from the DirectX
SDK defines several hexadecimal values that are
the scan codes used in Windows to check for the
keys. - --EX--
- define ZVK_ESCAPE 0x01
- define ZVK_TAB 0x0F
- define ZVK_SPACE 0x39
- define ZVK_RETURN 0x1C
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
36
37IsPressed IsReleased
- bool ZFXKeyboardIsPressed(UINT nID)
-
- if (m_KeysnID 0x80)
- return true
- return false
- // IsPressed
- bool ZFXKeyboardIsReleased(UINT nID)
-
- if ( (m_KeysOldnID0x80) !(m_KeysnID0x80)
) - return true
- return false
- // IsPressed
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
37
38QA
39Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
40No Joy Without a Joystick
41No Joy Without a Joystick
- ZFXJoystick Class
- Initializing and Releasing
- Updating
42ZFXJoystick Class
- Enumerate all attached devices
- EnumJoyCallback()
43ZFXJoystick Class (cont.)
44Initializing and Releasing
void ZFXDIDeviceCreate(LPDIRECTINPUT8 pDI, HWND
hWnd, FILE pLog) m_pLog pLog
m_hWnd hWnd m_pDI pDI
m_pDevice NULL
void ZFXDIDeviceRelease(void) if
(m_pDevice) m_pDevice-gtUnacquire()
m_pDevice-gtRelease() m_pDevice NULL
Log("input device offline (ok)") //
Release
45Initializing and Releasing (cont.)
- DirectInput enumeration function
- IDirectInput8EnumDevices
- Get a list of all attached joysticks
46Initializing and Releasing (cont.)
47Initializing and Releasing (cont.)
48Initializing and Releasing (cont.)
49Updating
- Get the data from the hardware device
- IDirectInputDevice8Poll
- retrieves data from polled objects on a
DirectInput device - IDirectInputDevice8Acquire
- obtains access to the input device
- IDirectInputDevice8GetDeviceData
- retrieves buffered data from the device
GetData()
50Updating (cont.)
51Updating (cont.)
52Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
53Implementing the Interface
54Implementing the Interface
55QA
56Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
57Demo Application
57
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
58QA
59Agenda
- Lead in(5JJ)
- Good Old Interface Design(Landon)
- Interface Definition for an Input Class(??)
- Base Class for Input Devices(??)
- Getting Down to the Keys(Landon)
- The Pied Piper of Redmond(Stephen)
- No Joy Without a Joystick(Akira)
- Implementing the Interface(Roy)
- Demo Application(??)
- One Look Back, Two Steps Forward(Akira)
60One Look Back, Two Steps Forward
61One Look Back, Two Steps Forward
- Initialize a render device?initialize the input
device and vice versa - Force-feedback device
- Simulated turbulence for a flight simulator
- A bumpy road for a racing game
- Action-mapping
- Map certain user commands to arbitrary keys or
buttons - ActionMapper Sample Code in DirectX 8.1 SDK until
Summer 2004 - XInput.h -- This module defines XBOX controller
APIs