Skip to main content
GameDev.net gamedev.net
🔒 Locked

direct Input Question

Started by gamedream Jul 13, 2003 at 8:33 PM 0 replies 250+ views
Original Post
gamedream
gamedream
Here is the some source code from books while (msg!=wm_quit) { if (peekmessage(&msg, Null, Null, Remove)) { translatemessage(); dispatchmessage(); else { if (Frame() == false) } Frame() { m_Keyboard->getkeyboardStatus(Key_UP); } The source code is come from my mind, so, it may have syntas error, but you can think this is psuedocode. The m_keyBoard is the direct input device. Here is my question: As my knolwedge, when a user input from keyboard, it will produce message from message Q in window process. At the same time, it also produce a key_XX from the buffer of direct input. Am I Correct first? Using direct input instead of window is because the speed is faster than window. Therfore, when the user input from keyboard, which function will call first? Is Frame() function or dispatchmessage() first? If the dispatchmessage() first, so, I place the action to msgproc is better than place it in the Frame function? Therefore, the Frame() function become no meaningful because it cannot have the fastest action to do the specific event. Do you understand what I mean? Here is my idea: 1. User input(keyboard) --> peekmessage(true) --> call dispatchmessage() --> peekmessage(false) --> call frame() Or 2. User input(keyboard) --> peekmessage(false) --> call Frame() --> peekmessage(true) --> dispatchmessage() I hope you can understand what I mean. So, which approach is correct, or All I wrong, pls help me and tell me the answer, thx
theZapper
theZapper
If you''re using DirectInput, you don''t really need to bother about the windows messaging stuff, you simply get all the data from your DirectInput devices just before you render a new frame, Try somthing similar to this message loop:

while(1)
{
if(PeekMessage(&msg,hwnd,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
GetInput();
RenderFrame();
}
}

Use the GetInput() function to access all your DI devices and process thier input, then draw the new frame using the new data.

---
"When I''m in command, every mission''s a suicide mission" - Zapp Branigan
---When I'm in command, every mission's a suicide mission!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.