Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE3AGT Paul Taylor 2010. Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT.

Similar presentations


Presentation on theme: "CSE3AGT Paul Taylor 2010. Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT."— Presentation transcript:

1 CSE3AGT Paul Taylor 2010

2 Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT (windows error message value)

3 Some Short Examples ID3D10Texture2D* pBackBuffer; HWND g_hWnd = NULL; HRESULT hr; hr = g_pSwapChain->GetBuffer(...) if( FAILED( hr) )

4 The Windows Message Pump What do messages do? – Handles Window Messages (Maximise, Minimise, etc) – Handles basic Keyboard and Mouse commands How do you send a message? – SendMessage() or – PostMessage()

5 What does a message look like? typedef struct { HWND hwnd; // Handle to the procedure that receives the message. UINT message; // Specifies the message identifier. WPARAM wParam; // Specifies additional information about the message. LPARAM lParam; // Specifies additional information about the message. DWORD time; // time at which the message was posted. POINT pt; // Specifies the cursor position when the message was posted. } MSG, *PMSG; Declaration: MSG myMsg; MSDN: http://msdn.microsoft.com/en-us/library/ms644958%28VS.85%29.aspxhttp://msdn.microsoft.com/en-us/library/ms644958%28VS.85%29.aspx

6 The WM_MOUSEMOVE Message UINT Message = WM_MOUSEMOVE wParam: MK_CONTROL The CTRL key is down. MK_LBUTTON The left mouse button is down. MK_MBUTTON The middle mouse button is down. MK_RBUTTON The right mouse button is down. MK_SHIFT The SHIFT key is down. lParam: The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper- left corner of the client area. The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper- left corner of the client area. xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam);

7 The Basic Windows Message Loop // Program Init while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); Game Code! } // Program Shutdown

8 Issues for Games GetMessage() will wait until it receives a message to return http://msdn.microsoft.com/en-us/library/ms644936%28VS.85%29.aspx Messages happen regularly, but not regularly enough for us The solution is PeekMessage() http://msdn.microsoft.com/en-us/library/ms644943%28VS.85%29.aspx

9 A Better Message Loop PeekMessage( &mssg, NULL, 0, 0, PM_NOREMOVE); while (mssg.message!=WM_QUIT) { if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&mssg); DispatchMessage(&mssg); } else { // Game Code! }

10 The Best Message Loop PeekMessage( &mssg, NULL, 0, 0, PM_NOREMOVE); while (mssg.message!=WM_QUIT) { if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&mssg); DispatchMessage(&mssg); } // Game Code! }

11 >>A Nice Program Flow<< http://www.directxtutorial.com/tutorial9/A- Win32/dx9A4.aspx

12 XInput = Simple! Comprises only two extra sources – XInput.h – Xinput.lib Main Functions: – XInputGetState – XInputSetState – XInputGetDSoundAudioDeviceGuids

13 All we can get is the current state How do we detect button presses? Avoiding Multiple Trigger situations?

14 We store the previous state typedef struct _XINPUT_GAMEPAD { WORD wButtons; BYTE bLeftTrigger; BYTE bRightTrigger; SHORT sThumbLX; SHORT sThumbLY; SHORT sThumbRX; SHORT sThumbRY; } XINPUT_GAMEPAD, *PXINPUT_GAMEPAD;

15 Direct Input Uses The Common Object Model (COM) – Input Devices – Keyboard, Mouse, Joystick, Force-Feedback Consists of two types of objects: – IDirectInput8 Interface – DirectInputDevice (one for each device) LPDIRECTINPUTDEVICE8 lpdiSomeDevice;

16 DirectInput Process Overview 1)Create the DirectInput Object 2)Enumerate DirectInput Devices 3)Create Device Object(s) 4)Set up the Device(s) 5)Acquire the Device (Get access to it) 6)Retrieve Data (using access) 7)Use the Data! 8)Release Devices (Un-Acquire then Release) 9)Release DirectInput

17 Action Mapping Instead of using the specific axis or buttons Abstract the input to a set of ‘Actions’ #define INPUT_LEFTRIGHT_AXIS 1L DIINPUT structures: // Genre Specific Bindings {INPUT_LEFTRIGHT_AXIS, DIAXIS_SPACESIM_LATERAL, 0, "Turn",}, // Programmer Created Mapping {INPUT_TURNLEFT, DIKEYBOARD_LEFT, 0, "Turn left", }, {INPUT_LEFTRIGHT_AXIS, DIMOUSE_XAXIS, 0, "Turn", }, SpaceSim Genre: http://msdn.microsoft.com/en-us/library/ee418804%28VS.85%29.aspx

18 Is Action Mapping useful? Pros – Makes multi-device programming more manageable Cons – Takes Effort to set up – Has many Predefined Mappings you may not like Best used only on multi-device games – Otherwise complexity > reward

19 Descriptors Structures used by API calls for initialisation – You’ve seen a few already. Why are they used? Is there any way to make them easier / quicker to fill out?

20 MSG example: typedef struct { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG, *PMSG; BOOL PeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg ); But we still have to fill out all those values 

21 Cheating with DESCRIPTORS Most Descriptors require a LOT of NULL values – This takes ages to fill in by hand. It’s standard to use a block format to set the whole descriptor to null before. Declare the structure: DXGI_SWAP_CHAIN_DESC swapDesc; Wipe it!: ZeroMemory( & swapDesc, sizeof(swapDesc));

22 News Time! OpenGL 4.0 Spec Released http://www.opengl.org/news/permalink/khronos-unleashes-cutting-edge-cross- platform-graphics-acceleration-with-op/ Wii Death http://www.telegraph.co.uk/news/worldnews/northamerica/usa/7407373/Girl-3- thought-loaded-gun-was-Wii-controller-in-fatal-accident.html

23 Resources http://www.winprog.org/tutorial/message_loop.html http://www.mvps.org/directx/articles/writing_t he_game_loop.htm


Download ppt "CSE3AGT Paul Taylor 2010. Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT."

Similar presentations


Ads by Google